Traffic, What is it good for ?

General discussion about anything related to Transcendence.
Post Reply
shanejfilomena
Fleet Officer
Fleet Officer
Posts: 1533
Joined: Tue Mar 22, 2011 8:43 pm
Location: Alaska
Contact:

As most that are familiar with me, I am very interested in Traffic and the moving of supplies to stations to keep the economic system as real and moving as I think I can get it.

IF you use any Mods in your game, the stuff I have below can simply be added to a extension or module without any fanfare.
These lines are single lines, mostly so be sure the line is spaced to read in one go.
I once had an issue with code in a mod ( which is one of my favorites these days ) where the spacing of the lines made me very upset things did not work.

Code: Select all

 
	<!-- Commonwealth Traffic Behavior
	
		USAGE NOTES
		
		This controls random ships that travel between Commonwealth stations.
		To use:
		
		1. Create the ship at a stargate
		2. Set the event handler
		3. Set the home station
		4. Call "OrderBeginTraffic"
	
		EXTRA DATA
		
		behavior:			Ship's current behavior
								'enteredSystem			= Ship just entered the system
								'docked					= Ship is docked somewhere
								'leavingSystem			= Ship is heading out of the system
								
		home:				Ship's home station

	-->

	<ShipClass UNID="&evCommTrafficBehavior;"
			class=				"(commonwealth traffic behavior)"
			virtual=			"true"
			noFriendlyFire=		"true"
			
			attributes=			"behaviorClass"
			>
	<StaticData>
				<Trade currency="credit" max="50000" replenish="25000">
			    <Sell	criteria="*~f U -ID;"/>
				<Buy	criteria="*t~f U  -NotForSale;"/>
		       </Trade>
		</StaticData>
		<Events>
			<OrderBeginTraffic>
				(block (homeObj)
					; If the home station is not set, set it now
					(if (not (setq homeObj (objGetObjRefData gSource "home")))
						(block Nil
	(setq homeObj (sysFindObject gSource "TAFN +commonwealth; +primary; -centauriWarlords; "))
							(if (not homeObj)
	(setq homeObj (sysFindObject gSource "TAFN +populated; -korolovShipping; -centauriWarlords; -occupation;"))
								)

							(objSetObjRefData gSource "home" homeObj)
							)
						)

					; Set data so we know we are traffic
					(objSetData gSource "0010300C_traffic" True)

					; Set state
					(objSetData gSource "behavior" 'enteredSystem)
					
					)
			</OrderBeginTraffic>
			
			<OnOrdersCompleted>
				(block (behavior newBehavior allDests dockedAt allWrecks allLoot allBits)
					(setq behavior (objGetData gSource "behavior"))
					(setq dockedAt (shpGetDockObj gSource))
					
					; If we're docked at an object, dump any loot that we found
					(if (and dockedAt
							(objHasAttribute dockedAt "populated")
							
							; Compose a list of all loot on board that the station
							; might want to buy from us.
							
							(setq allLoot (filter (objGetItems gSource "*~f U") theItem
								(objGetBuyPrice dockedAt theItem)
								))
							)
						(block Nil
							(enum allLoot theItem (objRemoveItem gSource theItem))
							(enum allLoot theItem (objAddItem dockedAt theItem))
							)
						)
					
						
					(if (and dockedAt
							(objHasAttribute dockedAt "populated;")
							
							; Compose a list of all loot on board that the station
							; might want to sell to us.
							
							(setq allBits (filter (objGetItems dockedAt "*t~fU") theItem
								(objGetSellPrice dockedAt theItem)
								))
							)
						(block Nil
							(enum allBits theItem (objRemoveItem dockedAt theItem))
							(enum allBits theItem (objAddItem gSource theItem))
							)
						
						)
						
					; Figure out what to do next
					(switch

						; Check for wrecks in the area; if we find some, then loot them
						(and (leq (objGetDestiny gSource) 180)
								(not (objHasAttribute gSource "freighter"))
								(leq (random 1 100) 50)
								
								; Compose a list of all wrecks in the area
								
			(setq allWrecks (filter (sysFindObject gSource "TK N:100; +shipwreck; -uncharted; -locked;") theObj
									(and 
										(not (objIsRadioactive theObj))
										(not (objGetData theObj "0010300c_marked"))
										)
									))
								)
							(block (destObj)
								(setq destObj (random allWrecks))
								(shpOrder gSource 'loot destObj)
								(objSetData destObj "0010300c_marked" True)
								(objSetData gSource "behavior" 'looting)
								)
					
						; If we have no destinations or randomly, we gate out
						(or (and (not (eq behavior 'enteredSystem)) (leq (random 1 100) 20))
								(not 
									; Compose a list of stations that we could go to.
									; We exclude the station that we're docked with and any
									; stations that don't have too many dock ports open.

									(setq allDests (filter (sysFindObject gSource "TAF +populated; -centauriWarlords; -korolovShipping; -occupation;") theObj 
										(and (gr (objGetOpenDockingPortCount theObj) 2)
											(or (not dockedAt) (not (eq dockedAt theObj)))
											)
										))
									)
								)
							(block (gateObj)
								(setq gateObj (random (sysFindObject gSource "G -uncharted;")))
								(shpOrder gSource 'gate gateObj)
								(objSetData gSource "behavior" 'leavingSystem)
								)
								
						; Otherwise, we go to another station
						(block (destObj)
							(setq destObj (random allDests))
							(shpOrder gSource 'dock destObj)
							(shpOrder gSource 'wait (random 10 60))
							(objSetData gSource "behavior" 'docked)
							)
						)
						
					; If we were docked at an object that we just looted, then destroy the object
					(if (objGetData dockedAt "0010300c_marked")
						(objDestroy dockedAt gSource)
						)
					)
			</OnOrdersCompleted>
			
          <OnAttacked>
		  (if (and aOrderGiver
						(objCanAttack aOrderGiver)
						(not (eq (objGetDisposition gSource aOrderGiver) 'friend))
						(not (eq (objGetSovereign aOrderGiver) Nil))	
						)
		      ;we can not go out like a wimp
          (block Nil
				(shpOrder gSource 'attack aAttacker) 
				
                           (shpOrder gSource 'gate)
			))		
              </OnAttacked>
			<OnDestroy>
				(block Nil
			; remove everything from the ship
						(objEnumItems gSource "*U" theItem
							(objRemoveItem gSource theItem)
							)
				)
			</OnDestroy>
		</Events>
	</ShipClass>
 
 
Now, in the Globals, you can add this or just do <Globals> (block Nil ( add stuff - make sure you get all your "(" closed up with " )" ) </Globals> to over write and let the game do the work.

Code: Select all


			(setq comTrafficControl (lambda (homeObj maxTraffic)
				(if (ls (count (sysFindObject homeObj "s D:0010300C_traffic;")) maxTraffic)
					(block (theShip)
						(setq theShip (sysCreateShip
							&tbCommTraffic;
							(random (sysFindObject Nil "G -uncharted;"))
							&svCommonwealth;
							&evCommTrafficBehavior;
							))
						(objSetObjRefData theShip "home" homeObj)
						
							; Add some items to the transport
							(not (objHasAttribute gSource "freighter"))
								(objAddRandomItems theShip &trStdTreasureLevel3; (random 1 3))
								
							;scarabs get res
					          (if (objHasAttribute gSource "freighter")
								(objAddRandomItems theShip &trStdTreasure; (random 1 3))
					             )
								 
						(objFireEvent theShip "OrderBeginTraffic")
						)
					)
				))

				
Now the result is Traffic with stuff & credits to buy / sell - they will not take anything important ( I fought with them over missiles once :) ) but they will move Ore pretty well around the system, so stations you dumped ore on can sell it off and buy more from you later ( usually, but the treasures they carry vary so there is no sure game play to believe they will buy enough junk while you are in a system to let you sell junk again )
Flying Irresponsibly In Eridani......

I don't like to kill pirates in cold blood ..I do it.. but I don't like it..
Post Reply