Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 31.00 KB | None | 0 0
  1. <?xml version="1.0" ?>
  2. <!DOCTYPE TranscendenceExtension
  3. [
  4.     <!ENTITY modGT_TrafficBehaviour         "0xDCBA0200">
  5.     <!ENTITY tbGT_TrafficEscorts            "0xDCBA0201">
  6. ]>
  7.  
  8. <TranscendenceExtension UNID="&modGT_TrafficBehaviour;" version="1.0">
  9.  
  10. <!--
  11.     NOTES:
  12.  
  13.  
  14.     TODO
  15.         --  Limit buying to freighters, except for equipment upgrades
  16.         --  Limit selling to a random amount of items. This should avoid
  17.             freighters just dumping their entire inventory in one go
  18.             (question: should this be avoided at all?)
  19.         --  playtest InitialItem criteria to ensure no bugs or wildly
  20.             inapproriate items
  21.         -- 
  22.  
  23.  
  24.     OBSERVATIONS:
  25.         scEI500 does not have the attribute freighter set :/
  26.         possibly there are others that suffer from the same
  27.         --  because of this I have changed the way we acertain
  28.             if the current ship is a freighter from objHasAttribute
  29.             to a lookup in a list
  30. -->
  31.  
  32.     <Globals>
  33.         (block Nil
  34.  
  35.             (setq gt_TrafficDebug Nil)
  36.  
  37.             (setq gt_TrafficCredit (lambda (source credit)
  38.                 (block (current)
  39.                     (if (not (setq current (objGetData source "gt_Credits")))
  40.                         (setq current 0)
  41.                     )
  42.                     (setq current (add (int current) credit))
  43.                     (objSetData source "gt_Credits" current)
  44.                     current
  45.                 )
  46.             ))
  47.  
  48.             (setq gt_TrafficCharge (lambda (source credit)
  49.                 (block (current)
  50.                     (if (not (setq current (objGetData source "gt_Credits")))
  51.                         (setq current 0)
  52.                     )
  53.                     (if (ls (setq current (subtract (int current) credit)) 0)
  54.                         (setq current 0)
  55.                     )
  56.                     (objSetData source "gt_Credits" current)
  57.                     current
  58.                 )
  59.             ))
  60.  
  61.             (setq gt_TrafficGetBalance (lambda (source)
  62.                 (block (current)
  63.                     (if (not (setq current (objGetData source "gt_Credits")))
  64.                         (setq current 0)
  65.                     )
  66.                     (int current)
  67.                 )
  68.             ))
  69.  
  70.             (setq gt_TrafficFreighterTypes (list
  71.                 &scAntaresI; &scEI100; &scAntaresII; &scEI200;
  72.                 &scEI500; &scAntaresV; &scEI7000; &scScarabFreighter;
  73.             ))
  74.  
  75.             (setq gt_TrafficBuggyStations (list
  76.                 &stSistersOfDomina; &stCommonwealthResidentials;
  77.                 &stCommonwealthSlums; &stContainerHabitat; &stBeringStation;
  78.             ))
  79.  
  80.             ;; If we're docked at an object, sell any loot we can
  81.             ;; if we are a freighter, buy commodities, and perhaps
  82.             ;; a reactor upgrade, shield upgrade, armor upgrade.
  83.             ;; If we are not a freighter, only buy device upgrades
  84.             ;; and potentially install it.
  85.             ;; No ship can hold more than it's cargoSpace allows.
  86.             (setq gt_TrafficConductTrade (lambda (dockObj)
  87.                 ;; don't trade with buggy stations at all!
  88.                 (if (not (find gt_TrafficBuggyStations (staGetType dockObj)))
  89.                     (block (sellCriteria sellItems buyItems transactions)
  90.  
  91.                         (if gt_trafficdebug (dbgLog (objGetName gSource 1) " [" gSource "] trading with " (objGetName dockObj) " [" dockObj "] [credits] " (gt_TrafficGetBalance gSource)))
  92.  
  93.                         ;; first we build a list of items to sell
  94.                         (if (objGetItems gSource "lI")
  95.                             (setq sellCriteria "*~m U")
  96.                             (setq sellCriteria "* U")
  97.                         )
  98.                         ;; XXX: do we really need to check if price is greater than 0?
  99.                         (setq sellItems (filter (objGetItems gSource sellCriteria) theItem (gr (objGetBuyPrice dockObj theItem) 0)))
  100.  
  101.                         ;; check if any of our items can be used to restock 'sell only' items
  102.                         (enum (objGetItems gSource sellCriteria) theItem
  103.                             (if (and (objGetSellPrice dockObj theItem) (not (objGetBuyPrice dockObj theItem))
  104.                                 (leq (objHasItem dockObj theItem) (multiply 2 (itmGetAverageAppearing theItem))))
  105.                                 ;; we found an item that the station sells but won't buy
  106.                                 ;; we will not transfer any credits, and assume the freighter was
  107.                                 ;; contracted for this transport
  108.                                 (block Nil
  109.                                     (objRemoveItem gSource theItem)
  110.                                     (objAddItem dockObj theItem)
  111.                                     (if gt_TrafficDebug (dbgLog "  ---] Restocking "(itmGetName theItem 8)))
  112.                                 )
  113.                             )
  114.                         )
  115.                         ;; loop over all sellItems, and either calculate total or weed out item
  116.                         (enum sellItems theItem
  117.                             (if (or
  118.                                     (gr (objHasItem dockObj theItem) (multiply (itmGetAverageAppearing theItem) 3))
  119.                                     (leq (objGetBalance dockObj) 5000)
  120.                                 )
  121.                                 ;; dockObj not interested - remove item from sale list
  122.                                 (setq sellItems (lnkRemove sellItems (find sellItems theItem) Nil))
  123.                                 ;; dockObj will buy - calculate saleTotal and remove item from gSource + transfer credits
  124.                                 (block (cost)
  125.                                     (setq cost (multiply (objGetBuyPrice dockObj theItem) (itmGetCount theItem)))
  126.                                     (objRemoveItem gSource theItem)
  127.                                     (gt_TrafficCredit gSource cost)
  128.                                     (objCharge dockObj cost)
  129.                                     (if gt_TrafficDebug (dbgLog "  ---] Selling " (itmGetCount theItem) " " (itmGetName theItem 0) " for " cost))
  130.                                 )
  131.                             )
  132.                         )
  133.  
  134.                         ;; now build a list of items that we can/want to buy
  135.                         (setq buyItems (filter (objGetItems dockObj "* U") theItem (and
  136.                             (gr (objGetSellPrice dockObj theItem) 0)
  137.                             (or
  138.                                 (ls (objGetSellPrice dockObj theItem) (itmGetActualPrice theItem)) ;; item is a good deal
  139.                                 (gr (itmGetCount theItem) (multiply (itmGetAverageAppearing theItem) 3)) ;; dockedAt is overflowing
  140.                                 (ls (random 1 100) 50) ;; random chance
  141.                             )
  142.                         )))
  143.  
  144.                         ;; now we do the actual shopping. We only buy if the station has sufficient to offer
  145.                         ;; to avoid completely emptying stations
  146.                         (if (gr (count buyItems) 5) (block Nil
  147.                             (setq transactions 0)
  148.                             (enumWhile (shuffle buyItems) (leq transactions (random 1 4 1)) theItem
  149.                                 (block (quantity cost affordQuantity buyQuantity fitQuantity)
  150.  
  151.                                     ;; calculate how many we can afford and have cargo space for
  152.                                     (setq quantity (itmGetCount theItem))
  153.                                     (setq cost (int (objGetSellPrice dockObj theItem)))
  154.                                     (setq affordQuantity (divide (gt_TrafficGetBalance gSource) cost))
  155.                                     (if (gr (itmGetMass theItem) 0)
  156.                                         (setq fitQuantity (divide (objGetCargoSpaceLeft gSource) (itmGetMass theItem)))
  157.                                         (setq fitQuantity quantity)
  158.                                     )
  159.                                     (if (and (gr affordQuantity 0) (gr fitQuantity 0)) (block Nil
  160.                                         (setq buyQuantity (if (gr affordQuantity quantity) quantity affordQuantity))
  161.                                         (setq buyQuantity (if (gr buyQuantity fitQuantity) fitQuantity buyQuantity))
  162.  
  163.                                         ;; now we actually buy a random quantity between 1 and buyQuantity
  164.                                         (setq buyQuantity (random 1 buyQuantity))
  165.  
  166.                                         (if (gr buyQuantity 0) (block Nil
  167.                                             (setq cost (multiply cost buyQuantity))
  168.                                             (objCredit dockObj cost)
  169.                                             (gt_TrafficCharge gSource cost)
  170.                                             (objRemoveItem dockObj theItem buyQuantity)
  171.                                             (objAddItem gSource theItem buyQuantity)
  172.                                             (setq transactions (add transactions 1))
  173.                                             (if gt_TrafficDebug (dbgLog "  [--- Buying " buyQuantity " " (itmGetName theItem 0) " for " cost))
  174.                                         ))
  175.                                     ))
  176.                                 )
  177.                             )
  178.                         ))
  179.                         ;; transfer sellgoods to dockObj. We do this so late
  180.                         ;; to avoid buying items we just sold to the station
  181.                         (enum sellItems theItem
  182.                             (objAddItem dockObj theItem)
  183.                         )
  184.  
  185.                         (if gt_TrafficDebug (dbgLog "  Balance After Transaction: " (gt_TrafficGetBalance gSource)))
  186.  
  187.                         ;; remove any no-sale overstocked items from the station
  188.                         ;; this is considered part of the freighters contract
  189.                         (enum (objGetItems dockObj "*U") theItem
  190.                             (if (and (gr (objGetBuyPrice dockObj theItem) 0)
  191.                                     (eq (objGetSellPrice dockObj theItem) 0)
  192.                                     (gr (itmGetCount theItem) (itmGetMaxAppearing theItem))
  193.                                 )
  194.                                 (block (quantity fitQuantity)
  195.                                     ;; calculate how many we can fit
  196.                                     (setq quantity (itmGetCount theItem))
  197.                                     (if (gr (itmGetMass theItem) 0)
  198.                                         (setq fitQuantity (divide (objGetCargoSpaceLeft gSource) (itmGetMass theItem)))
  199.                                         (setq fitQuantity quantity)
  200.                                     )
  201.                                     (setq quantity (if (gr (quantity fitQuantity) fitQuantity quantity)))
  202.  
  203.                                     ;; select a random amount up to the fit limit
  204.                                     (setq quantity (random (divide quantity 5) (divide quantity 3)))
  205.                                     (if (ls quantity 1) (setq quantity 1))
  206.                                     (objRemoveItem dockObj theItem quantity)
  207.                                     (objAddItem gSource theItem quantity)
  208.                                     (if gt_TrafficDebug (dbgLog "  [--- Removing " quantity " overstocked " (itmGetName i 4)))
  209.                                 )
  210.                             )
  211.                         )
  212.                     )
  213.                 )
  214.             ))
  215.  
  216.             ;; we need to rewrite this to handle the looting manually,
  217.             ;; at least if we want to limit to actual cargo
  218.             (setq gt_TrafficLootWreck (lambda (wreck)
  219.                 (block Nil
  220.                     (if gt_TrafficDebug (dbgLog (objGetName gSource 1) " [" gSource "] looting " (objGetName wreck) " [" wreck "]"))
  221.                     (shpOrder gSource 'loot wreck)
  222.                     (objSetData wreck "0010300c_marked" True)
  223.                     (objSetData gSource "behavior" 'looting)
  224.                 )
  225.             ))
  226.  
  227.             ;;
  228.             ;; generates an appropriate amount of cargo for a freighter
  229.             ;; without overloading the ship
  230.             ;;
  231.             ;; @param target    - the ship having cargo added
  232.             ;; @param curve     - the formatted level curve string used
  233.             ;;                      example:    "--ucu -----"
  234.             ;; @param quantity  - the number of calls
  235.             ;;          NOTE: the quantity does not directly reference
  236.             ;;              how many items will be created as the function
  237.             ;;              will generate a random amount as per averageAppearing
  238.             ;;
  239.             ;;  **optional parameter**
  240.             ;; @param itemList  - a list of itemStructs
  241.             ;;          This provides an alternative method of generating cargo
  242.             ;;          if you want to specify exactly what will be in the ship.
  243.             ;;
  244.             (setq gt_TrafficAddInitialItems (lambda (target curve quantity itemList)
  245.                 (block (criteria (sysLevel (sysGetLevel)) (value 0))
  246.                     (setq curve (dsf_CalcLevelCurve (item curve 0) (item curve 1)))
  247.                     (switch
  248.  
  249.                         itemList
  250.                             True ;; we already have our item list
  251.  
  252.                         (leq sysLevel 3)
  253.                             (setq criteria (lambda Nil (block ((chance (random 1 100)))
  254.                                 (switch
  255.                                     (leq chance 5) ;; 5% of medicine
  256.                                         "t +Meds; -Illegal; <=$200"
  257.                                     (leq chance 10) ;; 5% of luxury goods
  258.                                         "t +Lux; -Illegal; <=$200"
  259.                                     (leq chance 15) ;; 5% chance of drugs
  260.                                         "t +Illegal; +Consumable; -ID; <=$200"
  261.                                     (leq chance 35) ;; 20% chance of food
  262.                                         "t +Food; <=$200"
  263.                                     (leq chance 80) ;; 45% chance of random stuff
  264.                                         "tu~m f:cu -Food; -Lux; -Meds; -Illegal; -Military; <=$200"
  265.                                     (leq chance 85) ;; 5% chance of a common weapon
  266.                                         "wlm f:cu -Illegal; -Military;"
  267.                                     (leq chance 90) ;; 5% chance of a shield or armor
  268.                                         "sa f:cu -Illegal; -Military;"
  269.                                     (leq chance 95) ;; 5% chance of a misc device
  270.                                         "bdrv f:cu -Illegal; -Military;"
  271.                                     "wsad +MajorItem; +Military" ;; 5% chance for military equipment
  272.                                 )
  273.                             )))
  274.  
  275.                         (leq sysLevel 5)
  276.                             (setq criteria (lambda Nil (block ((chance (random 1 100)))
  277.                                 (switch
  278.                                     (leq chance 5) ;; 5% of medicine
  279.                                         "t +Meds; -Illegal; <=$500"
  280.                                     (leq chance 10) ;; 5% of luxury goods
  281.                                         "t +Lux; -Illegal; <=$500"
  282.                                     (leq chance 15) ;; 5% chance of drugs
  283.                                         "t +Illegal; +Consumable; -ID; <=$500"
  284.                                     (leq chance 30) ;; 15% chance of food
  285.                                         "t +Food; <=$500"
  286.                                     (leq chance 65) ;; 35% chance of random stuff
  287.                                         "tu~m f:cu -Food; -Lux; -Meds; -Illegal; -Military; <=$500"
  288.                                     (leq chance 75) ;; 10% chance of a common weapon
  289.                                         (switch
  290.                                             (eq (modulo chance 2) 0) ;; 5% chance for common, 5% for specialty
  291.                                                 "wlm f:cu -Illegal; -Military;"
  292.                                             "wlm +Specialty;"
  293.                                         )
  294.                                     (leq chance 85) ;; 10% chance of a shield or armor
  295.                                         (switch
  296.                                             (eq (modulo chance 2) 0) ;; 5% chance for common, 5% for specialty
  297.                                                 "sa f:cu -Illegal; -Military;"
  298.                                             "sa +Specialty"
  299.                                         )
  300.                                     (leq chance 95) ;; 10% chance of a misc device
  301.                                         "bdrv f:cu -Illegal; -Military;"
  302.                                     "wsad +MajorItem; +Military" ;; 5% chance for military equipment
  303.                                 )
  304.                             )))
  305.  
  306.                         (leq sysLevel 7)
  307.                             (setq criteria (lambda Nil (block ((chance (random 1 100)))
  308.                                 (switch
  309.                                     (leq chance 5) ;; 5% of medicine
  310.                                         "t +Meds; -Illegal;"
  311.                                     (leq chance 10) ;; 5% of luxury goods
  312.                                         "t +Lux; -Illegal;"
  313.                                     (leq chance 20) ;; 10% chance of food
  314.                                         "t +Food;"
  315.                                     (leq chance 45) ;; 25% chance of random stuff
  316.                                         "tu~m -Illegal; -Military; <=$800"
  317.                                     (leq chance 60) ;; 15% chance of a common weapon
  318.                                         (switch
  319.                                             (eq (modulo chance 2) 0) ;; 7% chance for common, 8% for specialty
  320.                                                 "wlm f:cu -Illegal;"
  321.                                             "wlm +Specialty;"
  322.                                         )
  323.                                     (leq chance 75) ;; 15% chance of a shield or armor
  324.                                         (switch
  325.                                             (eq (modulo chance 2) 0) ;; 5% chance for common, 5% for specialty
  326.                                                 "sa f:cu -Illegal;"
  327.                                             "sa +Specialty"
  328.                                         )
  329.                                     (leq chance 85) ;; 10% chance of a misc device
  330.                                         "bdrv f:cu -Illegal; -Military;"
  331.                                     (leq chance 90) ;; 5% chance of alien items
  332.                                         "* +Alien;"
  333.                                     "wsad +MajorItem; +Military" ;; 5% chance for military equipment
  334.                                 )
  335.                             )))
  336.  
  337.                         (geq sysLevel 8)
  338.                             (setq criteria (lambda Nil (block ((chance (random 1 100)))
  339.                                 (switch
  340.                                     (leq chance 5) ;; 5% of medicine
  341.                                         "t +Meds; -Illegal;"
  342.                                     (leq chance 10) ;; 5% of luxury goods
  343.                                         "t +Lux; -Illegal;"
  344.                                     (leq chance 20) ;; 10% chance of food
  345.                                         "t +Food;"
  346.                                     (leq chance 45) ;; 25% chance of random stuff
  347.                                         "tu~m -Illegal; -Military; <=$800"
  348.                                     (leq chance 60) ;; 15% chance of a common weapon
  349.                                         (switch
  350.                                             (eq (modulo chance 2) 0) ;; 7% chance for common, 8% for specialty
  351.                                                 "wlm f:cu -Illegal;"
  352.                                             "wlm +Specialty;"
  353.                                         )
  354.                                     (leq chance 75) ;; 15% chance of a shield or armor
  355.                                         (switch
  356.                                             (eq (modulo chance 2) 0) ;; 5% chance for common, 5% for specialty
  357.                                                 "sa f:cu -Illegal;"
  358.                                             "sa +Specialty"
  359.                                         )
  360.                                     (leq chance 85) ;; 10% chance of a misc device
  361.                                         "bdrv f:cu -Illegal; -Military;"
  362.                                     (leq chance 90) ;; 5% chance of alien items
  363.                                         "* +Alien;"
  364.                                     "wsad +MajorItem; +Military" ;; 5% chance for military equipment
  365.                                 )
  366.                             )))
  367.                     )
  368.                     ;; if we don't have an item list, we generate one ourselves
  369.                     (if (not itemList) (block ((itemList (list)))
  370.                         (for i 1 quantity (lnkAppend itemList (itmCreateRandom (criteria) curve)))
  371.                     ))
  372.                     ;; now we enumerate over a shuffled itemList and add the items if they fit
  373.                     (enum (shuffle itemList) theItem (block (fitQuantity transfer)
  374.                         (setq transfer (itmGetCount theItem))
  375.                         (if (gr (itmGetMass theItem) 0)
  376.                             (setq fitQuantity (divide (objGetCargoSpaceLeft gSource) (itmGetMass theItem)))
  377.                             (setq fitQuantity transfer)
  378.                         )
  379.                         (setq transfer (if (gr transfer fitQuantity) fitQuantity transfer))
  380.                         (if (gr transfer 0) (block Nil
  381.                             (if gt_TrafficDebug (dbgLog "  --  Adding " transfer " " (itmGetName theItem 0) " worth " (multiply transfer (itmGetActualPrice theItem))))
  382.                             (setq value (add value (multiply transfer (itmGetActualPrice theItem))))
  383.                             (objAddItem gSource theItem transfer)
  384.                         ))
  385.                     ))
  386.                     ;; return value
  387.                     value
  388.                 )
  389.             ))
  390.  
  391.             ;;
  392.             ;; Creates escorts for freighters appropriate for the system level
  393.             ;;
  394.             ;; @param target - the freighter to be escorted
  395.             ;; @param quantity - how many escorts will be created
  396.             ;;
  397.             (setq gt_TrafficSpawnEscort (lambda (target quantity) (block Nil
  398.                 (if (leq quantity 0) (setq quantity 0))
  399.                 (if gt_TrafficDebug (dbgLog "  Adding " quantity " escorts"))
  400.                 (for i 1 quantity (block (theShip)
  401.                     (setq theShip (sysCreateShip &tbGT_TrafficEscorts; (objGetPos target) &svCommonwealth; "fleet"))
  402.                     (if gt_TrafficDebug (dbgLog "  --  Adding " (objGetName theShip 1) " as escort"))
  403.                     (shpCancelOrders theShip)
  404.                     (shpOrderEscort theShip target)
  405.                 ))
  406.             )))
  407.  
  408.         )
  409.     </Globals>
  410.  
  411.     <ShipClass UNID="&evCommTrafficBehavior;"
  412.         class=          "(commonwealth traffic behavior)"
  413.         virtual=        "true"
  414.         attributes=     "behaviorClass"
  415.         >
  416.  
  417.         <Events>
  418.             <OrderBeginTraffic>
  419.                 (block Nil
  420.                     ;; If the home station is not set, set it now
  421.                     (if (not (objGetObjRefData gSource "home"))
  422.                         (block (homeObj)
  423.                             (setq homeObj (sysFindObject gSource "TAFN +commonwealth; +primary;"))
  424.                             (if (not homeObj)
  425.                                 (setq homeObj (sysFindObject gSource "TAFN +populated; -occupation;"))
  426.                             )
  427.                             (objSetObjRefData gSource "home" homeObj)
  428.                         )
  429.                     )
  430.  
  431.                     (if gt_TrafficDebug (dbgLog "Spawning Traffic: " (objGetName gSource 1) " [" gSource "] [destiny] " (objGetDestiny gSource) " [cargo] " (shpGetDataField gSource "cargoSpace")))
  432.  
  433.                     ;; add starting credits to gSource.
  434.                     (block (credit)
  435.                         (if (find gt_TrafficFreighterTypes (shpGetClass gSource))
  436.                             (setq credit (multiply (shpGetDataField gSource "cargoSpace") (rollDice 2 10)))
  437.                             (setq credit (multiply (shpGetDataField gSource "cargoSpace") (rollDice 10 20)))
  438.                         )
  439.                         (setq credit (add credit (multiply (sysGetLevel) (sysGetLevel) 50)))
  440.                         (gt_TrafficCredit gSource credit)
  441.                         (if gt_TrafficDebug (dbgLog "  Added Credits: " credit))
  442.                     )
  443.  
  444.                     ;; if gSource is a freighter, add some starting cargo
  445.                     (if (find gt_TrafficFreighterTypes (shpGetClass gSource))
  446.                         (block (quantity value)
  447.                             ;; no less than 1 and no more than 20 items
  448.                             (setq quantity (dsf_Constrain (divide (objGetDestiny gSource) 20) 1 20))
  449.                             (setq value (gt_TrafficAddInitialItems gSource (list (sysGetLevel) 2) quantity))
  450.                             (if gt_TrafficDebug (dbgLog "  Added " quantity " items to initial cargo with a value of " value " credits."))
  451.  
  452.                             ;; some freighters with high value get escorts
  453.                             ;; we also allow for a random element, since the player should not
  454.                             ;; be able to rely on valuable freighters having escorts
  455.                             (if (or
  456.                                     (and (gr value (multiply (sysGetLevel) 2000)) (gr (objGetDestiny gSource 180)))
  457.                                     (and (ls (random 1 100) 33) (setq value (gt_TrafficGetBalance gSource)))
  458.                                 )
  459.                                 (gt_TrafficSpawnEscort gSource (min (divide value (multiply (sysGetLevel) 2000)) 4))
  460.                             )
  461.                         )
  462.                     )
  463.  
  464.                     ;; Save behaviour
  465.                     (objSetData gSource "0010300C_traffic" True)
  466.                     (objSetData gSource "behavior" 'enteredSystem)
  467.                 )
  468.             </OrderBeginTraffic>
  469.  
  470.             <OnOrdersCompleted>
  471.                 (block (behavior newBehavior allDests dockObj allWrecks allLoot)
  472.                     (setq behavior (objGetData gSource "behavior"))
  473.                     (setq dockObj (shpGetDockObj gSource))
  474.  
  475.                     ;; if we are docked at a populated station, try a trade
  476.                     (if (and dockObj (objHasAttribute dockObj "populated"))
  477.                         (gt_TrafficConductTrade dockObj)
  478.                     )
  479.  
  480.                     ;; Figure out what to do next
  481.                     (switch
  482.  
  483.                         ;; 50% chance of looting any nearby wrecks.
  484.                         ;; If we are a freighter or our destiny is too
  485.                         ;; high, then skip looting
  486.                         (and
  487.                             (leq (objGetDestiny gSource) 180)
  488.                             (not (find gt_TrafficFreighterTypes (shpGetClass gSource)))
  489.                             (leq (random 1 100) 50)
  490.                             (setq allWrecks (filter (sysFindObject gSource "TK N:100; +shipwreck; -uncharted; -locked;") theObj
  491.                                 (not (objGetData theObj "0010300c_marked"))
  492.                             ))
  493.                         )
  494.                             (gt_TrafficLootWreck (random allWrecks))
  495.  
  496.                         ;; 20% chance of gating out if we have no destination
  497.                         (or (and (not (eq behavior 'enteredSystem)) (leq (random 1 100) 20))
  498.                             (not
  499.                                 ;; Find potential destinations. Exclude current station and stations without docking space
  500.                                 (setq allDests (filter (sysFindObject gSource "TAF +populated; -korolovShipping; -occupation;") theObj
  501.                                     (and (gr (objGetOpenDockingPortCount theObj) 1)
  502.                                         (or (not dockObj) (not (eq dockObj theObj)))
  503.                                     )
  504.                                 ))
  505.                             )
  506.                         )
  507.                             (block (gateObj)
  508.                                 (setq gateObj (random (sysFindObject gSource "G -uncharted;")))
  509.                                 (shpOrder gSource 'gate gateObj)
  510.                                 (objSetData gSource "behavior" 'leavingSystem)
  511.                                 (if gt_TrafficDebug (dbgLog (objGetName gSource 1) " [" gSource "] gating out"))
  512.                             )
  513.  
  514.                         ;; Otherwise, we go to another station
  515.                         (block (destObj)
  516.                             ;; don't dock at residentials (if we are a freighter?)
  517.                             (setq destObj (random allDests))
  518.                             (shpOrder gSource 'dock destObj)
  519.                             (shpOrder gSource 'wait (random 10 60))
  520.                             (objSetData gSource "behavior" 'docked)
  521.                             (if gt_TrafficDebug (dbgLog (objGetName gSource 1) " [" gSource "] docking with " (objGetName destObj) " [" destObj "]"))
  522.                         )
  523.                     )
  524.  
  525.                     ;; If we were docked at an object that we just looted,
  526.                     ;; and the object is empty, then destroy the object
  527.                     (if (and (objGetData dockObj "0010300c_marked") (not (objGetItems dockObj "*U")))
  528.                         (objDestroy dockObj gSource)
  529.                     )
  530.                 )
  531.             </OnOrdersCompleted>
  532.         </Events>
  533.     </ShipClass>
  534.  
  535.     <ShipTable unid="&tbGT_TrafficEscorts;">
  536.         <LevelTable>
  537.             <Ship levelFrequency="cccr- -----" count="1" class="&scRoninA;"/>
  538.             <Ship levelFrequency="cccrr -----" count="1" class="&scIAVLight;"/>
  539.             <Ship levelFrequency="ruucc cr---" count="1" class="&scRoninB;"/>
  540.             <Ship levelFrequency="uuucc cur--" count="1" class="&scWolfen;"/>
  541.             <Ship levelFrequency="---uu ccccu" count="1" class="&scRoninC;"/>
  542.             <Ship levelFrequency="-rrcc crr--" count="1" class="&scIAVMedium;"/>
  543.             <Ship levelFrequency="uuucc ccccc" count="1" class="&scCenturion;"/>
  544.             <Ship levelFrequency="--ruu ucccc" count="1" class="&scIAVHeavy;"/>
  545.             <Ship levelFrequency="--ruc cuuuu" count="1" class="&scManticore;"/>
  546.             <Ship levelFrequency="----- -uuuu" count="1" class="&scBritannia;"/>
  547.         </LevelTable>
  548.     </ShipTable>
  549.  
  550. </TranscendenceExtension>
  551. <!--
  552. vim:enc=utf-8:nu:ai:si:et:ts=4:sw=4:ft=tscript:
  553. -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement