(FILECREATED "27-JUN-83 00:24:23" {INDIGO}<LOOPS>TRUCKIN>TRUCKINR.;9 62631  

      changes to:  (FNS Commodity.Display)

      previous date: "14-JUN-83 18:05:57" {INDIGO}<LOOPS>TRUCKIN>TRUCKINR.;8)


(PRETTYCOMPRINT TRUCKINRCOMS)

(RPAQQ TRUCKINRCOMS ((* Copyright (c)
			1983 Xerox Corp)
		     (* TRUCKIN Domain for Expert Systems. Created by Loops Design Team - Danny 
			Bobrow, Sanjay Mittal, and Mark Stefik)
		     (* Objects and associated methods for Commodity and RoadStop classes)
		     (CLASSES * TRUCKINRCLASSES)
		     (FNS * TRUCKINRFNS)))



(* Copyright (c) 1983 Xerox Corp)




(* TRUCKIN Domain for Expert Systems. Created by Loops Design Team - Danny Bobrow, Sanjay 
Mittal, and Mark Stefik)




(* Objects and associated methods for Commodity and RoadStop classes)


(RPAQQ TRUCKINRCLASSES (Commodity CommodityTransportability Consumer FragileCommodity OtherRoadStop 
				  PerishableCommodity Producer RoadStop SystemTruck Truck))
(DEFCLASSES Commodity CommodityTransportability Consumer FragileCommodity OtherRoadStop 
	    PerishableCommodity Producer RoadStop SystemTruck Truck)
[DEFCLASS Commodity
   (MetaClass CommodityClassMeta Edited:                     (* sm: " 9-FEB-83 11:01"))
   (Supers GameObject)
   (ClassVariables (VolPerQty 1 doc                          (* volume occupied by unit quantity))
		   (WtPerQty 1 doc                           (* weight per unit qty))
		   (AvgPrice 1 doc                           (* avg unit price for buying or selling by truckers)
			     )
		   (Icon defaultIcon doc                     (* name of a variable which is bound to a Bitmap)
			 )
		   (CopyCV (VolPerQty WtPerQty AvgPrice Icon)))
   (InstanceVariables (qty 0 doc                             (* actual qty on hand for truck))
		      (pr .9 doc                             (* this is the actual price RATIO paid by a trucker)
			  )
		      (owner ? doc                           (* truck object which owns this commodity)
			     )
		      (status T doc                          (* whether the commodity is alright or not.
							     NIL would mean the commodity has been destroyed)
			      ))
   (Methods (CanTransfer Commodity.CanTransfer args (newOwner pr qty prevOwner)
			 doc                                 (* Checks if ownership can be transferred)
			 )
	    (CheckFragility Commodity.CheckFragility args (rs speed)
			    doc                              (* dummy method for checking fragility)
			    )
	    (TransferOwner Commodity.TransferOwner args (newOwner priceRatio qty)
			   doc                               (* transfers the commodity from one owner to another)
			   )
	    (UpdateStatus Commodity.UpdateStatus args (newStop oldStop)
			  doc                                (* dummy for Updating status of commodities as they 
							     move)
			  ))]

[DEFCLASS CommodityTransportability
   (MetaClass GameClass Edited:                              (* sm: "26-JAN-83 17:34"))
   (Supers GameObject)
   (ClassVariables (CopyCV NIL))
   (InstanceVariables)
   (Methods)]

[DEFCLASS Consumer
   (MetaClass GameClass doc 

          (* * RoadStops that buy goods from Truckers.)


	      Edited:                                        (* mjs: "20-FEB-83 12:51")
	      )
   (Supers RoadStop)
   (ClassVariables (Pr 1.3)
		   (Commodity #$Commodity doc                (* The commodity to be purchased from truckers, that is,
							     a generic Loops class descriptive of the goods.)
			      )
		   (CopyCV (Pr Qty Commodity))
		   (Qty 500)
		   (Shade ConsumerShade))
   (InstanceVariables (qty #(#((GenConsumerQty self)
			       FirstFetch NIL) NIL UpdateConsumerDisplay) doc 
                                                             (* quantity of goods to be purchased.
							     Decreases as goods are purchased.))
		      (pr #(#((GenConsumerPr self)
			      FirstFetch NIL) NIL UpdateConsumerDisplay) doc 
                                                             (* price ratio. This is multiplied times the 
							     AvgBuyingPrice for Commodities to determine the price 
							     paid to truckers.)))
   (Methods (Buy Consumer.Buy args (commodity prevOwner)
		 doc                                         (* perform BUY for a consumer)
		 )
	    (BuyFuel Consumer.Buy args (commodity prevOwner))
	    (CanBuy Consumer.CanBuy args (commodity pr qty seller)
		    doc                                      (* checks if consumer will buy this commodity)
		    )
	    (DisplayData Consumer.DisplayData args NIL doc 

          (* * Display the Qty and PR for the Consumer at a RoadStop.)

)
	    (DisplayIcon Consumer.DisplayIcon args NIL doc 

          (* * Display the Icon for a RoadStop that is a Consumer..)

)
	    (Show Consumer.Show args NIL))]

[DEFCLASS FragileCommodity
   (MetaClass CommodityClassMeta Edited:                     (* sm: "28-JAN-83 21:31"))
   (Supers CommodityTransportability)
   (ClassVariables (FragilityLevel 20 doc                    (* breakability on a scale of 1 to 20))
		   (CopyCV (FragilityLevel)))
   (InstanceVariables (fragility #((RAND 1 (@@ FragilityLevel))
				   FirstFetch NIL)))
   (Methods (CheckFragility FragileCommodity.CheckFragility args (hazard dist)
			    doc                              (* checks if fragile commodities have broken for 
							     currentPlayer's truck)
			    )
	    (PartialTransfer FragileCommodity.PartialTransfer args (copyFrom)
			     doc                             (* copies ivs when commodities have to be split up for 
							     partial buys)
			     ))]

[DEFCLASS OtherRoadStop
   (MetaClass GameClass Edited:                              (* sm: "10-FEB-83 16:37"))
   (Supers RoadStop)
   (ClassVariables (Icon ?)
		   (Shade OtherRoadStopShade))
   (InstanceVariables)
   (Methods (DisplayData OtherRoadStop.DisplayData args NIL doc 

          (* * Dummy routine for displaying no data in an OtherRoadStop.)

)
	    (DisplayIcon OtherRoadStop.DisplayIcon args NIL doc 

          (* * Display the Icon for an OtherRoadStop.)

)
	    (Initialize OtherRoadStop.Initialize args NIL doc 
                                                             (* does nothing))
	    (Show OtherRoadStop.Show args NIL doc            (* prints a message)))]

[DEFCLASS PerishableCommodity
   (MetaClass CommodityClassMeta Edited:                     (* mjs: "25-JAN-83 13:23"))
   (Supers CommodityTransportability)
   (ClassVariables (MinLifetime 2 doc                        (* min number of turns before commodity perishes)
				)
		   (MaxLifetime 20 doc                       (* max number of turns by when commodity perishes)
				)
		   (CopyCV (MinLifetime MaxLifetime)))
   (InstanceVariables (lifetime #(NIL SmashRandomPerishable NIL)))
   (Methods (PartialTransfer PerishableCommodity.PartialTransfer args (copyFrom)
			     doc                             (* copies IVs specific to this class to transferred 
							     commodity)
			     )
	    (UpdateStatus PerishableCommodity.UpdateStatus args (newStop oldStop)
			  doc                                (* updates the status of the Commodity after each move)
			  ))]

[DEFCLASS Producer
   (MetaClass GameClass doc 

          (* * RoadStops that sell goods to Truckers.)


	      Edited:                                        (* mjs: "20-FEB-83 12:51")
	      )
   (Supers RoadStop)
   (ClassVariables (Commodity #$Commodity doc                (* class of commodity sold by this producer)
			      )
		   (Pr .9 doc                                (* price ratio at which this producer typically sells.
							     used to generate ACTUAL pr))
		   (Qty 50 doc                               (* quantity typically sold by this producer.
							     used to generate ACTUAL qty))
		   (CopyCV (Pr Qty Commodity))
		   (Shade ProducerShade))
   (InstanceVariables (qty #(#((GenConsumerQty self)
			       FirstFetch NIL) NIL UpdateConsumerDisplay) doc 
                                                             (* actual qty available))
		      (pr #(#((GenConsumerPr self)
			      FirstFetch NIL) NIL UpdateConsumerDisplay) doc 
                                                             (* actual price ratio at which sold)))
   (Methods (DisplayData Producer.DisplayData args NIL doc 
                                                             (* Display the Qty and PR for the Producer at a 
							     RoadStop.))
	    (DisplayIcon Producer.DisplayIcon args NIL doc 
                                                             (* Display the Icon for a RoadStop that is a Producer.)
			 )
	    (Sell Producer.Sell args (commodity pr qty)
		  doc                                        (* perform SELL for consumer)
		  )
	    (SellFuel Producer.Sell args (commodity pr qty))
	    (Show Producer.Show args NIL doc                 (* shows the producer roadstop data)))]

[DEFCLASS RoadStop
   (MetaClass AbstractClass doc 

          (* * A RoadStop on the game board for TRUCKIN. Subclasses of this class are saved on the global list RoadStops.
	  Instances of these subclasses can be included on the game board by the gameMaster when a simulation is set up.)


	      Edited:                                        (* sm: "14-JUN-83 15:01")
	      )
   (Supers GameObject)
   (ClassVariables (RoadSign "RoadSign" doc                  (* String name to appear in the display.)
			     )
		   (Width 75 doc                             (* width of RoadStop in pixels.))
		   (Height 75 doc                            (* height of RoadStop in pixels.))
		   (CopyCV (RoadSign)))
   (InstanceVariables (milePost 0 doc                        (* index of this RoadStop on the road.
							     Assigned by Place message.))
		      (prev NIL doc                          (* previous RoadStop on the board.
							     NIL if this is the beginning of the road.)
			    )
		      (next NIL doc                          (* next RoadStop on the board.
							     NIL if this is the end of the road.))
		      (parkingPlace1 NIL howLong 0 timeParked 0 timeUsed 0 doc 
                                                             (* First parking place at RoadStop.)
				     pdoc                    (* timeParked -
							     time when first parked at Alice.
							     timeUsed -
							     time used computing at Alice)
				     )
		      (parkingPlace2 NIL howLong 0 timeParked 0 timeUsed 0 doc 
                                                             (* Second parking place at this RoadStop.)
				     )
		      (x 0 doc                               (* xOrigin on display in pixels.
							     Assigned by Place message.))
		      (y 0 doc                               (* yOrigin on display in pixels.
							     Assigned by Place message.))
		      (roadOrientation NIL doc               (* Left or Right. Right means that next RoadStop is down
							     the road to the right in the display.)))
   (Methods (AnyVictim RoadStop.AnyVictim args NIL doc       (* checks and returns the name of any non-bandit player 
							     at this loc))
	    (Bandit? RoadStop.Bandit? args NIL doc           (* checks if there is a bandit here))
	    (BanditReady RoadStop.BanditReady args NIL doc 
                                                             (* checks if Bandit is ready to catch passing trucks)
			 )
	    (BwPlace RoadStop.BwPlace args NIL doc           (* New method template))
	    (ColorPlace RoadStop.ColorPlace args NIL doc     (* New method template))
	    (Crash RoadStop.Crash args (player)
		   doc                                       (* Crashes player at this RoadStop if already parked.
							     Else parks player in crashed state.)
		   )
	    (Flash RoadStop.Flash args (player)
		   doc                                       (* flashes currentPlayer)
		   )
	    (GoingPast RoadStop.GoingPast args (player dist)
		       doc                                   (* Message sent when a player wats to go past this 
							     roadstop.)
		       )
	    (Initialize RoadStop.Initialize args NIL doc     (* sets qty and pr to ? to enable new values to be 
							     calculated))
	    (Park RoadStop.Park args (player tempFlg)
		  doc                                        (* Park the current player at this RoadStop.)
		  )
	    (Parked? RoadStop.Parked? args (player)
		     doc

          (* * Returns T if the currentPlayer is parked at this RoadStop, and NIL otherwise.)


		     )
	    (Place RoadStop.Place args (x y milePost roadOrientation)
		   doc

          (* * Draws the fixed frame for a RoadStop.)


		   )
	    (RoomToPark? RoadStop.RoomToPark? args NIL doc 

          (* * Returns T if there is room to park at this RoadStop and NIL otherwise.)

)
	    (TimeSpent RoadStop.TimeSpent args (player)
		       doc                                   (* returns the time spent by player at this stop, if 
							     parked here)
		       )
	    (TurnsStayed RoadStop.TurnsStayed args (player)
			 doc                                 (* If player is parked here, returns how long he has 
							     been here)
			 )
	    (Unpark RoadStop.Unpark args (player)
		    doc                                      (* Removes the current player from his parking place at 
							     a RoadStop.)
		    )
	    (Visit RoadStop.Visit args (player reason)
		   doc                                       (* player is visiting this stop)
		   )
	    (BanditP RoadStop.Bandit? args NIL doc           (* checks if there is a bandit here)))]

[DEFCLASS SystemTruck
   (MetaClass GameAbstractClass doc                          (* System trucks -- includes ones that cannot be used by
							     User-defined Players.)
	      Edited:                                        (* sm: " 7-JUN-83 14:16")
	      )
   (Supers GameObject)
   (ClassVariables (InitCash 10000)
		   (Gpm 1 doc                                (* units of fuel used per moved location)
			)
		   (Icon ? doc                               (* name of LISP variable bound to Bitmap)
			 )
		   (MaxDamage 10 doc                         (* maximum damage))
		   (MaxDist 15 doc                           (* max moves allowed in each turn))
		   (MaxFuel 30 doc                           (* max units of fuel truck can carry))
		   (MaxVolume 200 doc                        (* max volume))
		   (MaxWeight 200 doc                        (* max weight in commodity units))
		   (CopyCV (InitCash MaxFuel MaxVolume MaxWeight MaxDamage MaxDist Gpm Icon)))
   (InstanceVariables (driver NIL doc                        (* player driving this truck.))
		      (location NIL reason NIL doc           (* current location on the road.
							     A RoadStop.))
		      (cargo NIL doc                         (* cargo on the truck as a list of Commodity instances)
			     )
		      (cashBox #((@@ InitCash)
				 FirstFetch NIL) DefaultGauge LCD GaugeLimit (0 1000000)
			       doc                           (* money carried on the truck.)
			       )
		      (damage 0 DefaultGauge NIL doc         (* current damage to truck))
		      (fuel #((@@ MaxFuel)
			      FirstFetch NIL) DefaultGauge Dial GaugeLimit #((LIST 0 (@@ MaxFuel))
									     FirstFetch NIL) doc 
                                                             (* fuel left in truck))
		      (volume 0 DefaultGauge NIL GaugeLimit #((LIST 0 (@@ MaxVolume))
							      FirstFetch NIL) doc 
                                                             (* volume used))
		      (weight 0 DefaultGauge NIL GaugeLimit #((LIST 0 (@@ MaxWeight))
							      FirstFetch NIL) doc 
                                                             (* weight on truck)))
   (Methods (Buy SystemTruck.Buy args (commodity prevOwner)
		 doc                                         (* sm: " 8-FEB-83 14:20")
		 )
	    (CanBuy SystemTruck.CanBuy args (commodity pr qty seller)
		    doc                                      (* sm: " 8-FEB-83 14:16")
		    )
	    (Sell SystemTruck.Sell args (commodity pr qty)
		  doc                                        (* sm: " 9-FEB-83 15:51")
		  ))]

[DEFCLASS Truck
   (MetaClass GameAbstractClass Edited:                      (* mjs: "16-MAR-83 14:43"))
   (Supers SystemTruck)
   (ClassVariables)
   (InstanceVariables)
   (Methods (BuyFuel Truck.BuyFuel args (fuelInst prevOwner)
		     doc                                     (* buys Fuel and puts in fuel tank)
		     )
	    (CanBuyFuel Truck.CanBuyFuel args (commodity pr qty seller)
			doc                                  (* check if the truck can buy fuel)
			)
	    (FillTank Truck.FillTank args (fuelInst)
		      doc                                    (* sm: "20-JAN-83 16:12")
		      )
	    (Initialize Truck.Initialize args NIL)
	    (SellFuel Truck.SellFuel args (commodity pr qty)
		      doc                                    (* perform the SELL fuel transaction for truck)
		      )
	    (VisitUnionHall Truck.VisitUnionHall args NIL doc 
                                                             (* initialize truck data for going to UnionHall)
			    ))]


(RPAQQ TRUCKINRFNS (Commodity.CanTransfer Commodity.CheckFragility Commodity.Display 
					  Commodity.TransferOwner Commodity.UpdateStatus 
					  CommodityTransportability.CheckFragility 
					  CommodityTransportability.UpdateStatus Consumer.Buy 
					  Consumer.CanBuy Consumer.DisplayData Consumer.DisplayIcon 
					  Consumer.Show FragileCommodity.CheckFragility 
					  FragileCommodity.PartialTransfer Gasoline.TransferOwner 
					  OtherRoadStop.DisplayData OtherRoadStop.DisplayIcon 
					  OtherRoadStop.Initialize OtherRoadStop.Show 
					  PerishableCommodity.PartialTransfer 
					  PerishableCommodity.UpdateStatus Producer.DisplayData 
					  Producer.DisplayIcon Producer.Sell Producer.Show 
					  RoadStop.AnyVictim RoadStop.Bandit? RoadStop.BanditReady 
					  RoadStop.BwPlace RoadStop.ColorPlace RoadStop.Crash 
					  RoadStop.DisplayIcon RoadStop.Flash RoadStop.GoingPast 
					  RoadStop.Initialize RoadStop.Park RoadStop.Parked? 
					  RoadStop.Place RoadStop.RoomToPark? RoadStop.TimeSpent 
					  RoadStop.TurnsStayed RoadStop.Unpark RoadStop.Visit 
					  SystemTruck.Buy SystemTruck.CanBuy SystemTruck.Sell 
					  Truck.BuyFuel Truck.CanBuyFuel Truck.FillTank 
					  Truck.Initialize Truck.SellFuel Truck.VisitUnionHall))
(DEFINEQ

(Commodity.CanTransfer
  [LAMBDA (self newOwner pr qty prevOwner)                   (* sm: " 6-JUN-83 16:03")
                                                             (* Checks if ownership can be transferred)

          (* Complete protocol. Not needed yet. (AND (COND ((%@ owner) (* can current owner sell?) (← 
	  (%@ owner) CanSell self (COND ((NULL pr) (%@ pr)) (T pr)) (COND ((NULL qty) (%@ qty)) (T qty)))) 
	  (T T)) (← newOwner CanBuy self (COND ((NULL pr) (%@ pr)) (T pr)) (COND ((NULL qty) (%@ qty)) 
	  (T qty)) prevOwner)))


    (← newOwner CanBuy self (COND
	 ((NULL pr)
	   (%@ pr))
	 (T pr))
       (COND
	 ((NULL qty)
	   (%@ qty))
	 (T qty))
       prevOwner])

(Commodity.CheckFragility
  [LAMBDA (self rs speed)                                    (* sm: "26-JAN-83 17:18")
                                                             (* dummy method for checking fragility)
    T])

(Commodity.Display
  [LAMBDA (self)                                             (* dgb: "23-JUN-83 08:29")
                                                             (* Displays the small icon from Truckin in its own 
							     window)
    (MOVEW (OPENW (CREATEWFROMIMAGE (BITMAPCOPY (EVALV (GetClassValue self (QUOTE Icon])

(Commodity.TransferOwner
  [LAMBDA (self newOwner priceRatio qty)                     (* sm: "13-JUN-83 08:15")
                                                             (* transfers the commodity from one owner to another)
                                                             (* If qty is not specified, all is transferred, else 
							     only qty is transferred by creating a new instance)
                                                             (* If priceRatio is not specified, then uses one 
							     currently in self)
    (PROG (transfer (prevOwner (@ owner))
		    (tpr priceRatio)
		    (tqty qty))
          [COND
	    ((NULL tpr)
	      (SETQ tpr (@ pr]
          [COND
	    ((NULL tqty)
	      (SETQ tqty (@ qty]                             (* ask the previous owner to sell the specified qty)
          (← prevOwner Sell self tpr tqty)
          (COND
	    ((OR (NULL qty)
		 (EQUAL qty (@ qty)))                        (* transfer completely)
	      (SETQ transfer self))
	    (T                                               (* create a new instance to only transfer specified qty)
	       (SETQ transfer (← (Class self)
				 New
				 (COND
				   ((NULL priceRatio)
				     (@ pr))
				   (T priceRatio))
				 qty
				 (QUOTE *SPECIAL*)))
	       (PutValue self (QUOTE qty)
			 (DIFFERENCE (@ qty)
				     qty))                   (* PartialTransfer message copies those aspects of self 
							     which have to be copied over but may depend on the 
							     actual classification of self)
	       (DoFringeMethods transfer (QUOTE PartialTransfer)
				self)))                      (* write the new owner's name)
          (PutValue transfer (QUOTE owner)
		    newOwner)                                (* ask new owner to update accounts and stock for BUY)
          (← newOwner Buy transfer prevOwner)
          (RETURN transfer])

(Commodity.UpdateStatus
  [LAMBDA (self newStop oldStop)                             (* sm: "26-JAN-83 17:18")
                                                             (* dummy for Updateing status of commodities as they 
							     move)
    T])

(CommodityTransportability.CheckFragility
  [LAMBDA (self rs speed)                                    (* sm: "26-JAN-83 17:18")
                                                             (* dummy method for checking fragility)
    T])

(CommodityTransportability.UpdateStatus
  [LAMBDA (self newStop oldStop)                             (* sm: "26-JAN-83 17:18")
                                                             (* dummy for Updateing status of commodities as they 
							     move)
    T])

(Consumer.Buy
  [LAMBDA (self commodity prevOwner)                         (* sm: " 8-FEB-83 14:13")
                                                             (* perform BUY for a consumer)
    (PROG NIL                                                (* update qty to be bought)
          [←%@
	    qty
	    (IMAX 0 (IDIFFERENCE (%@ qty)
				 (GetValue commodity (QUOTE qty]
          (RETURN self])

(Consumer.CanBuy
  [LAMBDA (self commodity pr qty seller)                     (* dgb: " 9-JUN-83 14:30")
                                                             (* checks if consumer will buy this commodity)
                                                             (* Returns self if can, else NIL)
    (PROG NIL                                                (* check that commodity is not perished)
          (COND
	    ((NULL (%@ commodity status))
	      (SETQ FCTReason (QUOTE PerishedGoods))
	      (SETQ FCTPenalty .2)
	      (RETURN NIL)))                                 (* check if want to buy this commodity)
          (COND
	    ((← commodity InstOf!(%@%@ Commodity)))
	    (T (SETQ FCTReason (QUOTE InvalidCommodity))
	       (SETQ FCTPenalty .2)
	       (RETURN NIL)))                                (* check qty)
          (COND
	    ((GREATERP qty (%@ qty))
	      (SETQ FCTReason (QUOTE TooMuchQty))
	      (SETQ FCTPenalty .1)
	      (RETURN NIL)))                                 (* check pr)
          (COND
	    ((GREATERP pr (%@ pr))
	      (SETQ FCTReason (QUOTE PriceHigh))
	      (SETQ FCTPenalty .1)
	      (RETURN NIL)))
          (RETURN self])

(Consumer.DisplayData
  [LAMBDA (self)                                             (* agb: "12-FEB-83 20:32")

          (* * Display the Qty and PR for the Consumer at a RoadStop.)


    (PROG (x y str)

          (* * Erase old string.)


          (DSPCOLOR consumerIconColor gameWindow)
          (DSPBACKCOLOR roadStopColor gameWindow)
          (BITBLT blankDataIcon NIL NIL gameWindow (IPLUS (%@ x)
							  lineSize)
		  (IPLUS (%@ y)
			 yData)))                            (* Compute New String.)
    [SETQ str (COND
	((ZEROP (%@ qty))
	  "ENOUGH!!")
	(T (CONCAT (%@ qty)
		   " @ "
		   (STRINGNUM (%@ pr)
			      4]

          (* * Compute Coordinates to center the string.)


    [SETQ x (IPLUS (%@ x)
		   (MAX 0 (IQUOTIENT (IDIFFERENCE (%@%@ Width)
						  (STRINGWIDTH str dataFont))
				     2]
    (SETQ y (IPLUS (%@ y)
		   yData 1))

          (* * Print the string.)


    (DSPXPOSITION x gameWindow)
    (DSPYPOSITION y gameWindow)
    (DSPFONT dataFont gameWindow)
    (PRIN1 str gameWindow])

(Consumer.DisplayIcon
  [LAMBDA (self)                                             (* agb: "12-FEB-83 20:15")

          (* * Display the Icon for a RoadStop that is a Consumer.)


    (PROG ((commodityName (ClassName (%@%@ Commodity)))
	   (yOffset 5)
	   xIcon yIcon)

          (* * Print the name of the commodity, rather than displaying an Icon.)


          (SETQ yIcon (IPLUS (%@ y)
			     yData
			     (FONTPROP commodityFont (QUOTE HEIGHT))
			     yOffset))
          (SETQ xIcon (IPLUS (%@ x)
			     (IQUOTIENT (IDIFFERENCE (%@%@ Width)
						     (STRINGWIDTH commodityName commodityFont))
					2)))
          (DSPXPOSITION xIcon gameWindow)
          (DSPYPOSITION yIcon gameWindow)
          (DSPCOLOR consumerIconColor gameWindow)
          (DSPBACKCOLOR roadStopColor gameWindow)
          (DSPFONT commodityFont gameWindow)
          (PRIN2 commodityName gameWindow])

(Consumer.Show
  [LAMBDA (self)                                             (* sm: " 9-FEB-83 16:02")
                                                             (* shows the consumer roadstop data)
    (PROG ((file PPDefault)
	   (commodity (%@%@ Commodity)))
          (printout file T "*****************" T)
          (printout file "RoadStop: " (ClassName self)
		    T)
          (printout file "Consumer of: " .FONT BOLDFONT (GetObjectName commodity)
		    .FONT DEFAULTFONT T)
          (printout file "Data for: " (GetObjectName commodity)
		    T)
          (for cv in (QUOTE (VolPerQty WtPerQty AvgPrice)) do (printout file cv 17 (GetClassValue
									  commodity cv)
									T))
          (RETURN T])

(FragileCommodity.CheckFragility
  [LAMBDA (self hazard dist)                                 (* sm: " 7-JUN-83 14:21")
                                                             (* checks if fragile commodities have broken for 
							     currentPlayer's truck)
    (PROG ((player (%@(%@ owner)
		     driver))
	   (truck (%@ owner)))
          (RETURN (COND
		    [(LESSP (TIMES (%@ hazard roughness)
				   dist
				   (%@ fragility))
			    (TIMES 25 (%@%@ truck MaxDist]
		    (T                                       (* OOps -
							     tough luck!!)
		       [COND
			 ((%@ status)
			   (← gameMaster BreakCargo player (FindLocIndex self (%@ truck cargo)))

          (* (←%@ status NIL) (WriteGameStatus (CONCAT (%@ currentPlayer driver) "'s Cargo of: ") (CONCAT 
	  (%@ qty) " " (ClassName self) " units") " destroyed by RoughRoad"))


			   ]
		       NIL])

(FragileCommodity.PartialTransfer
  [LAMBDA (self copyFrom)                                    (* sm: "26-JAN-83 17:20")
                                                             (* copies ivs when commodities have to be split up for 
							     partial buys)
    (←%@
      fragility
      (%@ copyFrom fragility])

(Gasoline.TransferOwner
  [LAMBDA (self newOwner priceRatio qty)                     (* sm: "13-JUN-83 08:18")
                                                             (* transfers gasoline from one owner to another)
                                                             (* If qty is not specified, all is transferred, else 
							     only qty is transferred by creating a new instance)
                                                             (* If priceRatio is not specified, then uses one 
							     currently in self)
    (PROG (transfer (prevOwner (@ owner))
		    (tpr priceRatio)
		    (tqty qty))
          [COND
	    ((NULL tpr)
	      (SETQ tpr (@ pr]
          [COND
	    ((NULL tqty)
	      (SETQ tqty (@ qty]                             (* ask the newOwner if he can buy)
                                                             (* ask the previous owner to sell the specified qty)
          (← prevOwner Sell self tpr tqty)
          (COND
	    ((OR (NULL qty)
		 (EQUAL qty (@ qty)))                        (* transfer completely)
	      (SETQ transfer self))
	    (T                                               (* create a new instance to only transfer specified qty)
	       (SETQ transfer (← (Class self)
				 New
				 (COND
				   ((NULL priceRatio)
				     (@ pr))
				   (T priceRatio))
				 qty
				 (QUOTE *SPECIAL*)))
	       (PutValue self (QUOTE qty)
			 (DIFFERENCE (@ qty)
				     qty))                   (* PartialTransfer message copies those aspects of self 
							     which have to be copied over but may depend on the 
							     actual classification of self)
	       (DoFringeMethods transfer (QUOTE PartialTransfer)
				self)))                      (* write the new owner's name)
          (PutValue transfer (QUOTE owner)
		    newOwner)                                (* ask new owner to update accounts and stock for BUY)
          (← newOwner BuyFuel transfer prevOwner)
          (RETURN transfer])

(OtherRoadStop.DisplayData
  [LAMBDA (self)                                             (* dgb: "25-JAN-83 09:15")

          (* * Dummy routine for displaying no data in an OtherRoadStop.)


    NIL])

(OtherRoadStop.DisplayIcon
  [LAMBDA (self)                                             (* sm: " 8-JUN-83 16:40")

          (* * Display the Icon for an OtherRoadStop.)


    (PROG ((iconName (%@%@ Icon))
	   (yOffset 2)
	   xIcon yIcon)

          (* * Display the Icon associated with the commodity.)


          (SETQ yIcon (IPLUS (%@ y)
			     yData
			     (FONTPROP dataFont (QUOTE HEIGHT))
			     yOffset))
          (SETQ xIcon (IPLUS (%@ x)
			     (IQUOTIENT (IDIFFERENCE (%@%@ Width)
						     iconSide)
					2)))
          (DSPCOLOR otherRoadStopIconColor gameWindow (DSPBACKCOLOR roadStopColor gameWindow))
          (BITBLT (EVALV iconName)
		  NIL NIL gameWindow xIcon yIcon])

(OtherRoadStop.Initialize
  [LAMBDA (self)                                             (* sm: "16-FEB-83 15:51")
                                                             (* does nothing)
    (←%@
      parkingPlace1 NIL)
    (←%@
      parkingPlace2 NIL)
    self])

(OtherRoadStop.Show
  [LAMBDA (self)                                             (* edited: "31-JAN-83 21:54")
                                                             (* prints a message)
    (printout PPDefault T "**********" T)
    (printout PPDefault (ClassName self)
	      " is neither a producer nor a consumer" T])

(PerishableCommodity.PartialTransfer
  [LAMBDA (self copyFrom)                                    (* sm: "24-JAN-83 15:34")
                                                             (* copies IVs specific to this class to transferred 
							     commodity)
    (←%@
      lifetime
      (%@ copyFrom lifetime])

(PerishableCommodity.UpdateStatus
  [LAMBDA (self newStop oldStop)                             (* sm: " 7-JUN-83 14:26")
                                                             (* updates the status of the Commodity after each move)
    (PROG ((player (%@(%@ owner)
		     driver))
	   (truck (%@ owner)))
          (←%@
	    lifetime
	    (SUB1 (%@ lifetime)))
          [COND
	    ((AND (%@ status)
		  (ZEROP (%@ lifetime)))
	      (← gameMaster SpoilCargo player (FindLocIndex self (%@ truck cargo)))
                                                             (* (WriteGameStatus (CONCAT driver "'s Cargo of: ") 
							     (CONCAT (%@ qty) " " (ClassName self) " units") 
							     " just perished") (←%@ status NIL))
	      ]
          (RETURN (%@ lifetime])

(Producer.DisplayData
  [LAMBDA (self)                                             (* agb: "12-FEB-83 20:33")
                                                             (* Display the Qty and PR for the Producer at a 
							     RoadStop.)
    (PROG (x y str)                                          (* Erase old string.)
          (DSPCOLOR producerIconColor gameWindow)
          (DSPBACKCOLOR roadStopColor gameWindow)
          (BITBLT blankDataIcon NIL NIL gameWindow (IPLUS (%@ x)
							  lineSize)
		  (IPLUS (%@ y)
			 yData))                             (* Compute New String.)
          [SETQ str (COND
	      ((ZEROP (%@ qty))
		"SOLD OUT")
	      (T (CONCAT (FIX (%@ qty))
			 " @ "
			 (STRINGNUM (%@ pr)
				    4]                       (* Compute Coordinates to center the string.)
          [SETQ x (IPLUS (%@ x)
			 (MAX 0 (IQUOTIENT (IDIFFERENCE (%@%@ Width)
							(STRINGWIDTH str dataFont))
					   2]
          (SETQ y (IPLUS (%@ y)
			 yData 1))                           (* Print the string.)
          (DSPXPOSITION x gameWindow)
          (DSPYPOSITION y gameWindow)
          (DSPFONT dataFont gameWindow)
          (PRIN1 str gameWindow])

(Producer.DisplayIcon
  [LAMBDA (self)                                             (* agb: "12-FEB-83 20:14")

          (* * Display the Icon for a RoadStop that is a Producer.)


    (PROG (iconName (commodity (%@%@ Commodity))
		    (yOffset 2)
		    xIcon yIcon)
          [SETQ iconName (COND
	      (commodity (%@%@ commodity Icon))
	      (T (QUOTE defaultIcon]

          (* * Display the Icon associated with the commodity.)


          (SETQ yIcon (IPLUS (%@ y)
			     yData
			     (FONTPROP dataFont (QUOTE HEIGHT))
			     yOffset))
          (SETQ xIcon (IPLUS (%@ x)
			     (IQUOTIENT (IDIFFERENCE (%@%@ Width)
						     iconSide)
					2)))
          (DSPCOLOR producerIconColor gameWindow)
          (DSPBACKCOLOR roadStopColor gameWindow)
          (BITBLT (EVALV iconName)
		  NIL NIL gameWindow xIcon yIcon])

(Producer.Sell
  [LAMBDA (self commodity pr qty)                            (* sm: " 8-FEB-83 14:11")
                                                             (* perform SELL for consumer)
    (PROG NIL                                                (* update stock)
          (←%@
	    qty
	    (IMAX 0 (IDIFFERENCE (%@ qty)
				 qty)))
          (RETURN self])

(Producer.Show
  [LAMBDA (self)                                             (* sm: " 9-FEB-83 16:02")
                                                             (* shows the producer roadstop data)
    (PROG ((file PPDefault)
	   (commodity (%@%@ Commodity)))
          (printout file T "*****************" T)
          (printout file "RoadStop: " (ClassName self)
		    T)
          (printout file "Producer of: " .FONT BOLDFONT (GetObjectName commodity)
		    .FONT DEFAULTFONT T)
          (printout file "Data for: " (GetObjectName commodity)
		    T)
          (for cv in (QUOTE (VolPerQty WtPerQty AvgPrice)) do (printout file cv 17 (GetClassValue
									  commodity cv)
									T))
          (RETURN T])

(RoadStop.AnyVictim
  [LAMBDA (self)                                             (* sm: "26-JAN-83 15:36")
                                                             (* checks and returns the name of any non-bandit player 
							     at this loc)
    (PROG (loc)
          [SETQ loc (for x in (QUOTE (parkingPlace1 parkingPlace2))
		       thereis (AND (GetValue self x)
				    (NOT (← (GetValue self x)
					    InstOf!(QUOTE Bandit]
          (RETURN (COND
		    (loc (GetValue self loc))
		    (T NIL])

(RoadStop.Bandit?
  [LAMBDA (self)                                             (* sm: "27-JAN-83 18:24")
                                                             (* checks if there is a bandit here)

          (* * RETURNS: Bandit instance if one is parked, else NIL)


    (PROG (banditLoc)
          (RETURN (COND
		    ([SETQ banditLoc (for x in (QUOTE (parkingPlace1 parkingPlace2))
					thereis (AND (GetObjectRec (GetValue self x))
						     (← (GetValue self x)
							InstOf!(QUOTE Bandit]
		      (GetValue self banditLoc))
		    (T NIL])

(RoadStop.BanditReady
  [LAMBDA (self)                                             (* sm: "27-JAN-83 18:26")
                                                             (* checks if Bandit is ready to catch passing trucks)

          (* * RETURNS: Bandit instance if ready, else NIL)


    (AND (← self RoomToPark?)
	 (← self Bandit?])

(RoadStop.BwPlace
  [LAMBDA (self x y milePost roadOrientation)                (* sm: "10-FEB-83 14:24")

          (* * Draws the fixed frame for a RoadStop.)


    (PROG ((width (%@%@ Width))
	   (height (%@%@ Height))
	   (roadSign (%@%@ RoadSign))
	   (fontHeight (FONTPROP roadSignFont (QUOTE HEIGHT)))
	   xOffset yOffset)

          (* * Save the RoadStop position information in instance variables.)


          [COND
	    (x                                               (* Here if x y & milePost are given as args.)
	       (←%@
		 x x)
	       (←%@
		 y y)
	       (←%@
		 milePost milePost)
	       (←%@
		 roadOrientation roadOrientation))
	    (T                                               (* Here if OLD x y & milePost are used.)
	       (SETQ x (%@ x))
	       (SETQ y (%@ y))
	       (SETQ milePost (%@ milePost))
	       (SETQ roadOrientation (%@ roadOrientation]

          (* * Draw the surrounding outline.)


          (BITBLT NIL NIL NIL gameWindow x y width height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  (EVALV (%@%@ Shade)))
          (BITBLT NIL NIL NIL gameWindow x y width lineSize (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKSHADE)
          (BITBLT NIL NIL NIL gameWindow x y lineSize height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKSHADE)
          (BITBLT NIL NIL NIL gameWindow x (IPLUS y height (IMINUS lineSize))
		  width lineSize (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKSHADE)
          (BITBLT NIL NIL NIL gameWindow (IPLUS x width (IMINUS lineSize))
		  y lineSize height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKSHADE)

          (* * Label the display with the RoadSign in an inverted bar.)


          (DSPFONT roadSignFont gameWindow)
          (SETQ xOffset (MAX lineSize (IQUOTIENT (IDIFFERENCE width (STRINGWIDTH roadSign 
										 roadSignFont))
						 2)))
          (SETQ xOffset (IPLUS xOffset x))
          [SETQ yOffset (IPLUS y height (IMINUS (FONTPROP roadSignFont (QUOTE HEIGHT]
          (BITBLT NIL NIL NIL gameWindow x yOffset width fontHeight (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKSHADE)
          (DSPTEXTURE BLACKSHADE gameWindow)
          (DSPOPERATION (QUOTE INVERT)
			gameWindow)
          (DSPXPOSITION xOffset gameWindow)
          (DSPYPOSITION (IPLUS yOffset 2)
			gameWindow)
          (PRIN1 roadSign gameWindow)
          (DSPTEXTURE WHITESHADE gameWindow)
          (DSPOPERATION (QUOTE REPLACE)
			gameWindow)

          (* * Display the Icon,qty, and pr.)


          (← self DisplayIcon)
          (← self DisplayData])

(RoadStop.ColorPlace
  [LAMBDA (self x y milePost roadOrientation)                (* agb: "12-FEB-83 20:03")

          (* * Draws the fixed frame for a RoadStop.)


    (PROG ((width (%@%@ Width))
	   (height (%@%@ Height))
	   (roadSign (%@%@ RoadSign))
	   (fontHeight (FONTPROP roadSignFont (QUOTE HEIGHT)))
	   xOffset yOffset)

          (* * Save the RoadStop position information in instance variables.)


          [COND
	    (x                                               (* Here if x y & milePost are given as args.)
	       (←%@
		 x x)
	       (←%@
		 y y)
	       (←%@
		 milePost milePost)
	       (←%@
		 roadOrientation roadOrientation))
	    (T                                               (* Here if OLD x y & milePost are used.)
	       (SETQ x (%@ x))
	       (SETQ y (%@ y))
	       (SETQ milePost (%@ milePost))
	       (SETQ roadOrientation (%@ roadOrientation]

          (* * Draw the surrounding outline.)


          (BITBLT NIL NIL NIL gameWindow x y width height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  roadStopColor)
          (BITBLT NIL NIL NIL gameWindow x y width lineSize (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKCOLOR)
          (BITBLT NIL NIL NIL gameWindow x y lineSize height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKCOLOR)
          (BITBLT NIL NIL NIL gameWindow x (IPLUS y height (IMINUS lineSize))
		  width lineSize (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKCOLOR)
          (BITBLT NIL NIL NIL gameWindow (IPLUS x width (IMINUS lineSize))
		  y lineSize height (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKCOLOR)

          (* * Label the display with the RoadSign in an inverted bar.)


          (DSPFONT roadSignFont gameWindow)
          (SETQ xOffset (MAX lineSize (IQUOTIENT (IDIFFERENCE width (STRINGWIDTH roadSign 
										 roadSignFont))
						 2)))
          (SETQ xOffset (IPLUS xOffset x))
          [SETQ yOffset (IPLUS y height (IMINUS (FONTPROP roadSignFont (QUOTE HEIGHT]
          (BITBLT NIL NIL NIL gameWindow x yOffset width fontHeight (QUOTE TEXTURE)
		  (QUOTE REPLACE)
		  BLACKCOLOR)
          (DSPCOLOR roadStopNameColor gameWindow)
          (DSPBACKCOLOR BLACKCOLOR gameWindow)
          (DSPXPOSITION xOffset gameWindow)
          (DSPYPOSITION (IPLUS yOffset 2)
			gameWindow)
          (PRIN1 roadSign gameWindow)

          (* * Display the Icon,qty, and pr.)


          (← self DisplayIcon)
          (← self DisplayData])

(RoadStop.Crash
  [LAMBDA (self player)                                      (* sm: " 3-JUN-83 13:15")
                                                             (* Crashes player at this RoadStop if already parked.
							     Else parks player in crashed state.)
    (PROG (xPos yPos icon (xMargin (CONSTANT 2)))
          (SETQ player (OR player currentPlayer))
          [SETQ icon (InvertIcon (COND
				   ((EQ (%@ roadOrientation)
					(QUOTE Right))
				     (%@ player icon))
				   (T (%@ player reverseIcon]
          (COND
	    ((← self Parked? player)
	      (← self Unpark player)
	      (DISMISS 5)))
          (COND
	    ((NULL (%@ parkingPlace1))

          (* * Here if there is room in the first space.)


	      (←%@
		parkingPlace1 player)
	      (SETQ xPos (IPLUS (%@ x)
				xMargin))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT icon NIL NIL gameWindow xPos yPos))
	    ((NULL (%@ parkingPlace2))

          (* * Here if there is room in the 2nd space.)


	      (←%@
		parkingPlace2 player)
	      (SETQ xPos (IPLUS (%@ x)
				(%@%@ Width)
				(IMINUS (%@%@ player Width))
				(IMINUS xMargin)))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT icon NIL NIL gameWindow xPos yPos))
	    (T (TruckinError "Attempt to Park when there is no room."])

(RoadStop.DisplayIcon
  [LAMBDA (self)                                             (* mjs: "12-JAN-83 10:29")

          (* * Display the Icon for the Commodity or Hazard in the RoadStop.)


    (PROG (icon (commodityName (%@ commodity))
		(commodity (GetClassRec (%@ commodity)))
		(yOffset 5)
		xIcon yIcon)

          (* * Compute y coordinate for icon.)


          (SETQ yIcon (IPLUS (%@ y)
			     yPr
			     (FONTPROP dataFont (QUOTE HEIGHT))
			     yOffset))

          (* * Handle Producers, Consumers, and Hazards differently.)


          (COND
	    ((← self InstOf (%$ Consumer))                   (* If a Consumer, just print the name of the commodity.)
	      (SETQ xIcon (IPLUS (%@ x)
				 (IQUOTIENT (IDIFFERENCE (%@%@ Width)
							 (STRINGWIDTH commodityName dataFont))
					    2)))
	      (DSPXPOSITION xIcon gameWindow)
	      (DSPYPOSITION yIcon gameWindow)
	      (DSPFONT dataFont gameWindow)
	      (PRIN2 commodityName gameWindow))
	    (T                                               (* Otherwise, if a Producer or a Hazard, use an icon if 
							     available.)
	       (SETQ xIcon (IPLUS (%@ x)
				  (IQUOTIENT (IDIFFERENCE (%@%@ Width)
							  iconSide)
					     2])

(RoadStop.Flash
  [LAMBDA (self player)                                      (* sm: " 3-JUN-83 13:12")
                                                             (* flashes currentPlayer)
                                                             (* assumes currentPlayer is already parked there)
    (SETQ player (OR player currentPlayer))
    (for i from 1 to 3
       do (← self Crash player)
	  (DISMISS 100)
	  (← self Unpark player)
	  (DISMISS 5)
	  (← self Park player T)
	  (DISMISS 100])

(RoadStop.GoingPast
  [LAMBDA (self player dist)                                 (* sm: " 7-JUN-83 11:59")
                                                             (* Message sent when a player wats to go past this 
							     roadstop.)
                                                             (* Returns: Reason if this RoadStop intercepts player.
							     NIL otherwise)
                                                             (* Any specialization must call this first before doing 
							     anything else)
                                                             (* This one, i.e., in class RoadStop only checks for 
							     Bandits)
    (COND
      ((AND (← self BanditReady)
	    (BanditGotYou? player self dist))
	(QUOTE Bandit))
      (T NIL])

(RoadStop.Initialize
  [LAMBDA (self)                                             (* sm: "14-JUN-83 17:11")
                                                             (* sets qty and pr to ? to enable new values to be 
							     calculated)
    (←@
      parkingPlace1 NIL)
    (←@
      parkingPlace2 NIL)
    (PutValueOnly self (QUOTE qty)
		  NotSetValue)
    (PutValueOnly self (QUOTE pr)
		  NotSetValue)
    self])

(RoadStop.Park
  [LAMBDA (self player tempFlg)                              (* sm: " 3-JUN-83 12:57")
                                                             (* Park the current player at this RoadStop.)
                                                             (* tempFlg if T means howLong and timeUsed props are not
							     changed)
    (PROG (xPos yPos icon (xMargin (CONSTANT 2)))
          (SETQ player (OR player currentPlayer))
          [SETQ icon (COND
	      ((EQ (QUOTE Right)
		   (%@ roadOrientation))
		(%@ player icon))
	      (T (%@ player reverseIcon]
          (COND
	    ((NULL (%@ parkingPlace1))

          (* * Here if there is room in the first space.)


	      (←%@
		parkingPlace1 player)
	      (COND
		((NOT tempFlg)
		  (←%@
		    self parkingPlace1 howLong 0)
		  (←%@
		    self parkingPlace1 timeUsed 0)))
	      (SETQ xPos (IPLUS (%@ x)
				xMargin))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT icon NIL NIL gameWindow xPos yPos))
	    ((NULL (%@ parkingPlace2))

          (* * Here if there is room in the 2nd space.)


	      (←%@
		parkingPlace2 player)
	      (COND
		((NOT tempFlg)
		  (←%@
		    self parkingPlace2 howLong 0)
		  (←%@
		    self parkingPlace2 timeUsed 0)))
	      (SETQ xPos (IPLUS (%@ x)
				(%@%@ Width)
				(IMINUS (%@%@ player Width))
				(IMINUS xMargin)))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT icon NIL NIL gameWindow xPos yPos))
	    (T (TruckinError "Attempt to Park when there is no room."])

(RoadStop.Parked?
  [LAMBDA (self player)                                      (* sm: " 3-JUN-83 12:55")

          (* * Returns T if the currentPlayer is parked at this RoadStop, and NIL otherwise.)


    (SETQ player (OR player currentPlayer))
    (OR (EQ player (%@ parkingPlace1))
	(EQ player (%@ parkingPlace2])

(RoadStop.Place
  [LAMBDA (self x y milePost roadOrientation)                (* sm: "12-MAY-83 16:06")

          (* * Draws the fixed frame for a RoadStop.)


    (COND
      ((%@%@ gameBoard colorP)
	(← self ColorPlace x y milePost roadOrientation))
      (T (← self BwPlace x y milePost roadOrientation])

(RoadStop.RoomToPark?
  [LAMBDA (self)                                             (* mjs: "18-JAN-83 14:28")

          (* * Returns T if there is room to park at this RoadStop and NIL otherwise.)


    (OR (NULL (%@ parkingPlace1))
	(NULL (%@ parkingPlace2])

(RoadStop.TimeSpent
  [LAMBDA (self player)                                      (* sm: "14-JUN-83 16:47")
                                                             (* returns the time spent by player at this stop, if 
							     parked here)
    (COND
      ((EQ player (@ parkingPlace1))
	(IDIFFERENCE (@ self parkingPlace1 timeParked)
		     (@ gameMaster timeRemaining)))
      ((EQ player (@ parkingPlace2))
	(IDIFFERENCE (@ self parkingPlace2 timeParked)
		     (@ gameMaster timeRemaining)))
      (T 0])

(RoadStop.TurnsStayed
  [LAMBDA (self player)                                      (* sm: "19-MAY-83 15:15")
                                                             (* If player is parked here, returns how long he has 
							     been here)
    (COND
      ((EQ player (%@ parkingPlace1))
	(%@ self parkingPlace1 howLong))
      ((EQ player (%@ parkingPlace2))
	(%@ self parkingPlace2 howLong))
      (T 0])

(RoadStop.Unpark
  [LAMBDA (self player)                                      (* sm: " 3-JUN-83 12:54")
                                                             (* Removes the current player from his parking place at 
							     a RoadStop.)
    (PROG (xPos yPos (gb (%@ gameMaster gameBoard))
		(xMargin (CONSTANT 2)))
          (SETQ player (OR player currentPlayer))
          (COND
	    [(EQ player (%@ parkingPlace1))

          (* * Here if player is in the first space.)


	      (←%@
		parkingPlace1 NIL)
	      (SETQ xPos (IPLUS (%@ x)
				xMargin))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT NIL NIL NIL gameWindow xPos yPos (%@%@ player Width)
		      (%@%@ player Height)
		      (QUOTE TEXTURE)
		      (QUOTE REPLACE)
		      (COND
			((%@%@ gb colorP)
			  roadStopColor)
			(T (EVALV (%@%@ Shade]
	    [(EQ player (%@ parkingPlace2))

          (* * Here if player is in the 2nd space.)


	      (←%@
		parkingPlace2 NIL)
	      (SETQ xPos (IPLUS (%@ x)
				(%@%@ Width)
				(IMINUS (%@%@ player Width))
				(IMINUS xMargin)))
	      (SETQ yPos (IPLUS (%@ y)
				lineSize))
	      (BITBLT NIL NIL NIL gameWindow xPos yPos (%@%@ player Width)
		      (%@%@ player Height)
		      (QUOTE TEXTURE)
		      (QUOTE REPLACE)
		      (COND
			((%@%@ gb colorP)
			  roadStopColor)
			(T (EVALV (%@%@ Shade]
	    (T (TruckinError (CONCAT "Cannot Unpark " player " Not parked here"])

(RoadStop.Visit
  [LAMBDA (self player reason)                               (* sm: "13-JUN-83 18:24")
                                                             (* player is visiting this stop)
                                                             (* IMPORTANT!! Any specialization of this must first do 
							     a ←Super)
                                                             (* reason -
							     if NIL, then requested by player, else reason for forced
							     move)
    (PROG ((truck (@ player truck))
	   victim vtruck loss bandit)
          (← self Park player NIL)
          (←@
	    truck location reason reason)
          (←@
	    truck location self)
          [COND
	    ((EQ reason (QUOTE LowFuel))                     (* Moved here because of LowFuel)
	      (WriteGameStatus (@ player driver)
			       (CONCAT " Towed to " (@@ RoadSign))
			       (CONCAT " - " reason]
          (COND
	    ((← player InstOf!(QUOTE Bandit))                (* visitor is Bandit. Check if anyone to rob)
	      [COND
		((SETQ victim (← self AnyVictim))
		  (← self Flash victim)
		  (WriteGameStatus "BANDIDOS robbed you!! " (@ victim driver))
		  (SETQ vtruck (@ victim truck))
		  (SETQ loss (FIX (TIMES (@ vtruck cashBox)
					 .2)))
		  (ChangeValue vtruck (QUOTE cashBox)
			       (IDIFFERENCE (@ vtruck cashBox)
					    loss))
		  (WriteGameStatus "Cash lost: $" loss)
		  (for x in (@ vtruck cargo) when (← x InstOf!(QUOTE LuxuryGoods))
		     do (COND
			  ((← x TransferOwner player (@ player pr))
			    (WriteGameStatus "Bandits stole: " (CONCAT (@ x qty)
								       " "
								       (ClassName x))
					     " units"]
	      (RETURN player))
	    (T                                               (* visitor is regular player.
							     see if bandits already here to rob him)
	       [COND
		 ((SETQ bandit (← self Bandit?))
		   (← self Flash player)
		   [COND
		     [(EQ reason (QUOTE Bandit))
		       (WriteGameStatus "BANDITS stopped you!! " (@ player driver)
					(CONCAT " at " (@@ RoadSign]
		     (T (WriteGameStatus "BANDITS robbed you!! " (@ player driver]
		   (SETQ loss (FIX (TIMES (@ truck cashBox)
					  .2)))
		   (ChangeValue truck (QUOTE cashBox)
				(IDIFFERENCE (@ truck cashBox)
					     loss))
		   (WriteGameStatus "Cash lost: $" loss)
		   (for x in (@ truck cargo) when (← x InstOf!(QUOTE LuxuryGoods))
		      do (COND
			   ((← x TransferOwner bandit (@ bandit pr))
			     (WriteGameStatus "Bandits stole: " (CONCAT (@ x qty)
									" "
									(ClassName x))
					      " units"]      (* if visiting involuntarily, crash)
	       (COND
		 (reason (← self Crash player)))
	       (RETURN player])

(SystemTruck.Buy
  [LAMBDA (self commodity prevOwner)                         (* sm: "19-MAY-83 15:25")
                                                             (* sm: " 8-FEB-83 14:20")
                                                             (* perform the BUY transaction for a trucker)
    (PROG (qty pr)
          (SETQ qty (GetValue commodity (QUOTE qty)))
          (SETQ pr (GetValue commodity (QUOTE pr)))          (* update cashBox)
          [ChangeValue self (QUOTE cashBox)
		       (FIX (DIFFERENCE (%@ cashBox)
					(TIMES qty pr (GetClassValue commodity (QUOTE AvgPrice]
                                                             (* update volume on truck)
          [←%@
	    volume
	    (PLUS (%@ volume)
		  (TIMES qty (%@%@ commodity VolPerQty]      (* update weight)
          [←%@
	    weight
	    (PLUS (%@ weight)
		  (TIMES qty (%@%@ commodity WtPerQty]       (* add this to cargo)
          (←%@
	    cargo
	    (CONS commodity (%@ cargo)))
          (RETURN self])

(SystemTruck.CanBuy
  [LAMBDA (self commodity pr qty seller)                     (* sm: " 6-JUN-83 18:14")
                                                             (* sm: " 8-FEB-83 14:16")
                                                             (* check if the truck can buy the commodity)
                                                             (* Returns self if can, else NIL)
    (PROG NIL                                                (* check cashBox)
          (COND
	    ((LESSP [DIFFERENCE (%@ cashBox)
				(TIMES qty pr (GetClassValue commodity (QUOTE AvgPrice]
		    0)
	      (SETQ FCTPenalty -1)
	      (SETQ FCTReason (QUOTE NoCash))
	      (RETURN NIL)))                                 (* check volume on truck)
          (COND
	    ((GREATERP (PLUS (%@ volume)
			     (TIMES qty (%@%@ commodity VolPerQty)))
		       (%@%@ MaxVolume))
	      (SETQ FCTPenalty .05)
	      (SETQ FCTReason (QUOTE NoVolume))
	      (RETURN NIL)))                                 (* check weight)
          (COND
	    ((GREATERP (PLUS (%@ weight)
			     (TIMES qty (%@%@ commodity WtPerQty)))
		       (%@%@ MaxWeight))
	      (SETQ FCTPenalty .05)
	      (SETQ FCTReason (QUOTE NoWeight))
	      (RETURN NIL)))
          (RETURN self])

(SystemTruck.Sell
  [LAMBDA (self commodity pr qty)                            (* sm: "19-MAY-83 15:26")
                                                             (* sm: " 9-FEB-83 15:51")
                                                             (* perform the SELL transaction for truck)
    (PROG NIL
          [COND
	    ((NULL qty)
	      (SETQ qty (GetValue commodity (QUOTE qty]
          [COND
	    ((NULL pr)
	      (SETQ pr (GetValue commodity (QUOTE pr]        (* update cashBox)
          [ChangeValue self (QUOTE cashBox)
		       (FIX (PLUS (%@ cashBox)
				  (TIMES qty pr (GetClassValue commodity (QUOTE AvgPrice]
                                                             (* update volume)
          [←%@
	    volume
	    (DIFFERENCE (%@ volume)
			(TIMES qty (%@%@ commodity VolPerQty]
                                                             (* update weight)
          [←%@
	    weight
	    (DIFFERENCE (%@ weight)
			(TIMES qty (%@%@ commodity WtPerQty]
                                                             (* update cargo)
          [COND
	    ((EQUAL qty (GetValue commodity (QUOTE qty)))
	      (←%@
		cargo
		(REMOVE commodity (%@ cargo]
          (RETURN self])

(Truck.BuyFuel
  [LAMBDA (self fuelInst prevOwner)                          (* sm: "19-MAY-83 15:24")
                                                             (* buys Fuel and puts in fuel tank)
    (PROG NIL
          (←%@
	    fuel
	    (PLUS (%@ fuel)
		  (%@ fuelInst qty)))
          [ChangeValue self (QUOTE cashBox)
		       (FIX (DIFFERENCE (%@ cashBox)
					(TIMES (%@ fuelInst qty)
					       (%@ fuelInst pr)
					       (%@%@ fuelInst AvgPrice]
          (RETURN self])

(Truck.CanBuyFuel
  [LAMBDA (self commodity pr qty seller)                     (* sm: " 6-JUN-83 18:11")
                                                             (* check if the truck can buy fuel)
                                                             (* Returns self if can, else NIL)
    (PROG NIL                                                (* check cashBox)
          (COND
	    ((LESSP [DIFFERENCE (%@ cashBox)
				(TIMES qty pr (GetClassValue commodity (QUOTE AvgPrice]
		    0)
	      (SETQ FCTPenalty -1)
	      (SETQ FCTReason (QUOTE NoCash))
	      (RETURN NIL)))                                 (* check fuel tank capacity)
          (COND
	    ((GREATERP qty (DIFFERENCE (%@%@ MaxFuel)
				       (%@ fuel)))
	      (SETQ FCTPenalty .01)
	      (SETQ FCTReason (QUOTE NoCapacity))
	      (RETURN NIL)))
          (RETURN self])

(Truck.FillTank
  [LAMBDA (self fuelInst)                                    (* sm: "20-JAN-83 16:16")
                                                             (* sm: "20-JAN-83 16:12")
                                                             (* sm: "20-JAN-83 15:27")
                                                             (* transfers fuel from cargo to fuel tank)
    (PROG (availVol transVol)
          (SETQ availVol (DIFFERENCE (%@%@ MaxFuel)
				     (%@ fuel)))
          (COND
	    ((GREATERP (%@ fuelInst qty)
		       availVol)
	      (SETQ transVol (DIFFERENCE (%@ fuelInst qty)
					 availVol)))
	    (T transVol (%@ fuelInst qty)))
          (←%@
	    fuel
	    (PLUS (%@ fuel)
		  transVol))
          [←%@
	    volume
	    (PLUS (%@ volume)
		  (TIMES transVol (%@%@ fuelInst VolPerQty]
          (←%@
	    weight
	    (PLUS (%@ weight)
		  transVol))
          [COND
	    [(EQUAL transVol (%@ fuelInst qty))
	      (←%@
		cargo
		(REMOVE fuelInst (%@ cargo]
	    (T (←%@
		 fuelInst qty (DIFFERENCE (%@ fuelInst qty)
					  transVol]
          (RETURN self])

(Truck.Initialize
  [LAMBDA (self)                                             (* sm: "10-FEB-83 10:33")
                                                             (* initialize truck to initial state)
    (←%@
      cargo NIL)
    (ChangeValue self (QUOTE cashBox)
		 (%@%@ InitCash))
    (←%@
      fuel
      (%@%@ MaxFuel))
    (←%@
      volume 0)
    (←%@
      weight 0)
    (←%@
      damage 0])

(Truck.SellFuel
  [LAMBDA (self commodity pr qty)                            (* sm: "20-JAN-83 16:11")
                                                             (* perform the SELL fuel transaction for truck)
    (PROG NIL

          (* (COND ((NULL qty) (SETQ qty (GetValue commodity (QUOTE qty))))) (COND ((NULL pr) (SETQ pr 
	  (GetValue commodity (QUOTE pr))))) (* update cashBox) (←%@ cashBox (PLUS (%@ cashBox) (TIMES qty pr 
	  (GetClassValue commodity (QUOTE AvgBuyingPrice))))) (* update volume) (←%@ volume (PLUS (%@ volume) 
	  (TIMES qty (GetClassValue commodity (QUOTE VolPerQty))))) (* update weight) (←%@ weight (PLUS 
	  (%@ weight) qty)) (* update cargo) (COND ((EQUAL qty (GetValue commodity (QUOTE qty))) (←%@ cargo 
	  (REMOVE self (%@ cargo))))))


          (printout T "Truckers cannot sell fuel!" T)
          (RETURN NIL])

(Truck.VisitUnionHall
  [LAMBDA (self)                                             (* sm: "10-FEB-83 10:32")
                                                             (* initialize truck data for going to UnionHall)
    (← self Initialize)
    (WriteGameStatus "Union Hall just gave " (%@(%@ driver)
		       driver)
		     " a new start.")
    self])
)
(DECLARE: DONTCOPY
  (FILEMAP (NIL (18828 62609 (Commodity.CanTransfer 18838 . 19549) (Commodity.CheckFragility 19551 . 
19784) (Commodity.Display 19786 . 20130) (Commodity.TransferOwner 20132 . 22068) (
Commodity.UpdateStatus 22070 . 22337) (CommodityTransportability.CheckFragility 22339 . 22588) (
CommodityTransportability.UpdateStatus 22590 . 22873) (Consumer.Buy 22875 . 23293) (Consumer.CanBuy 
23295 . 24508) (Consumer.DisplayData 24510 . 25554) (Consumer.DisplayIcon 25556 . 26459) (
Consumer.Show 26461 . 27220) (FragileCommodity.CheckFragility 27222 . 28127) (
FragileCommodity.PartialTransfer 28129 . 28464) (Gasoline.TransferOwner 28466 . 30500) (
OtherRoadStop.DisplayData 30502 . 30715) (OtherRoadStop.DisplayIcon 30717 . 31428) (
OtherRoadStop.Initialize 31430 . 31711) (OtherRoadStop.Show 31713 . 32059) (
PerishableCommodity.PartialTransfer 32061 . 32391) (PerishableCommodity.UpdateStatus 32393 . 33191) (
Producer.DisplayData 33193 . 34396) (Producer.DisplayIcon 34398 . 35244) (Producer.Sell 35246 . 35628)
 (Producer.Show 35630 . 36389) (RoadStop.AnyVictim 36391 . 36928) (RoadStop.Bandit? 36930 . 37510) (
RoadStop.BanditReady 37512 . 37864) (RoadStop.BwPlace 37866 . 40425) (RoadStop.ColorPlace 40427 . 
42881) (RoadStop.Crash 42883 . 44207) (RoadStop.DisplayIcon 44209 . 45445) (RoadStop.Flash 45447 . 
45980) (RoadStop.GoingPast 45982 . 46802) (RoadStop.Initialize 46804 . 47244) (RoadStop.Park 47246 . 
48785) (RoadStop.Parked? 48787 . 49115) (RoadStop.Place 49117 . 49436) (RoadStop.RoomToPark? 49438 . 
49710) (RoadStop.TimeSpent 49712 . 50243) (RoadStop.TurnsStayed 50245 . 50674) (RoadStop.Unpark 50676
 . 52114) (RoadStop.Visit 52116 . 54878) (SystemTruck.Buy 54880 . 55913) (SystemTruck.CanBuy 55915 . 
57197) (SystemTruck.Sell 57199 . 58438) (Truck.BuyFuel 58440 . 58938) (Truck.CanBuyFuel 58940 . 59817)
 (Truck.FillTank 59819 . 60928) (Truck.Initialize 60930 . 61347) (Truck.SellFuel 61349 . 62239) (
Truck.VisitUnionHall 62241 . 62607)))))
STOP