Advertisement
EditorRUS

ModRPGCode.xml

Jan 7th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 9.66 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <TranscendenceModule>
  4.     <Globals>
  5.         (block Nil
  6.        
  7.             ; MODIFICATION:
  8.             ;   - changed two instances of 'can' into 'could'
  9.             ;   - Added 'itemToRemove' to the returned data
  10.             ; -----------------------------------------
  11.             (setq rpgInstallDevicePrep (lambda (data)
  12.  
  13.                 ; Data must have the following fields
  14.                 ;
  15.                 ;   item:                   The item to install
  16.                 ;
  17.                 ; In addition, the following optional fields are supported
  18.                 ;
  19.                 ;   buyAndInstall:          If True, we're installing as part of purchase
  20.                 ;   checkMilitaryID:        If True, we check for military ID, if necessary
  21.                 ;   checkTotalPower:        If True, we fail unless the total power of all devices matches reactor output
  22.                 ;   currencyUsed:           The currency used
  23.                 ;   installerObj:           Object installing the device (if Nil, we assume a station)
  24.                 ;   installPriceAdj:        Installation price (only if totalPrice is Nil)
  25.                 ;   itemInCargo:            If True, item is in player's cargo hold
  26.                 ;   maxTechLevel:           The maximum tech level we will install (unless we match techCriteriaOverride)
  27.                 ;   noCargoCheck:           If True, then we don't check to see if the old device fits in cargo
  28.                 ;   targetObj:              Object on which to install (if Nil, we assume player ship)
  29.                 ;   techCriteria:           If not Nil, the item must match this criteria
  30.                 ;   techCriteriaOverride:   If not Nil, and item matches this criteria, install even if above maxTechLevel
  31.                 ;   totalPrice:             The total price to install (may include purchase price)
  32.                 ;
  33.                 ; We return a struct with the following elements:
  34.                 ;
  35.                 ;   canInstall:             True if installation can proceed
  36.                 ;   price:                  Total installation cost
  37.                 ;   desc:                   Description of installation attempt
  38.                 ;   itemToRemove:           The item to be replaced
  39.  
  40.                 (block (thisItem totalCost canInstall desc itemName currencyUsed targetObj installerObj textYourShip textWe textYour itemToRemove)
  41.                
  42.                     (setq thisItem (@ data 'item))
  43.                     (setq currencyUsed (@ data 'currencyUsed))
  44.                     (setq targetObj (if (@ data 'targetObj) (@ data 'targetObj) gPlayerShip))
  45.                     (setq installerObj (if (@ data 'installerObj) (@ data 'installerObj) gSource))
  46.                     (if (not currencyUsed) (setq currencyUsed (objGetDefaultCurrency targetObj)))
  47.                     (setq itemName (itmGetName thisItem (if (@ data 'buyAndInstall) 0x40 0x04)))
  48.                     (setq canInstall Nil)
  49.                    
  50.                     ;   If the target object is not the player's ship, then we need to modify
  51.                     ;   some text
  52.                    
  53.                     (setq textYourShip
  54.                         (if (eq targetObj gPlayerShip)
  55.                             "your ship"
  56.                             (cat "the " (objGetName targetObj 0x00))
  57.                             )
  58.                         )
  59.                        
  60.                     (setq textWe
  61.                         (if (eq installerObj gPlayerShip)
  62.                             "you"
  63.                             "we"
  64.                             )
  65.                         )
  66.                        
  67.                     (setq textYour
  68.                         (if (eq targetObj gPlayerShip)
  69.                             "your"
  70.                             "the"
  71.                             )
  72.                         )
  73.                        
  74.                     (if thisItem
  75.                         (block (
  76.                             (installDevicePrice (objGetItemProperty installerObj thisItem 'installDevicePrice))
  77.                             (itemPrice
  78.                                 (if (or (@ data 'upgrade) (@ data 'buyAndInstall))
  79.                                     (objGetSellPrice installerObj thisItem)
  80.                                     0
  81.                                     )
  82.                                 )
  83.                            
  84.                             cargoNeeded itemToReplace resultMessage resultCode returnValue stationCannotInstall
  85.                             )
  86.                        
  87.                             ;   Compute the cost to install
  88.                            
  89.                             (switch
  90.                                 (@ data 'totalPrice)
  91.                                     (setq totalCost (@ data 'totalPrice))
  92.  
  93.                                 (@ data 'installPriceAdj)
  94.                                     (setq totalCost (rpgAdjustInstallPrice Nil thisItem (@ data 'installPriceAdj) currencyUsed))
  95.  
  96.                                 (setq totalCost (add itemPrice installDevicePrice))
  97.                             )
  98.                                
  99.                             ;   Ask the object is we can install the item
  100.  
  101.                             (setq returnValue (objCanInstallItem targetObj thisItem))
  102.                             (setq resultCode (@ returnValue 1))
  103.                             (setq resultMessage (@ returnValue 2))
  104.                             (setq itemToRemove (@ returnValue 3))
  105.                            
  106.                             (switch
  107.                                 ;   If we don't match the tech criteria then we don't have the
  108.                                 ;   technology to install.
  109.                                
  110.                                 (and (@ data 'techCriteria)
  111.                                         (not (itmMatches thisItem (@ data 'techCriteria)))
  112.                                         )
  113.                                     (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
  114.                                
  115.                                 ;   If our max tech level is too low for the item, then we can't install
  116.                                 ;   (except for specific items that we know about)
  117.                                
  118.                                 (and (gr (itmGetLevel thisItem) (if (@ data 'maxTechLevel) (@ data 'maxTechLevel) 30))
  119.                                         (or (not (@ data 'techCriteriaOverride))
  120.                                             (not (itmMatches thisItem (@ data 'techCriteriaOverride)))
  121.                                             )
  122.                                         )
  123.                                     (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
  124.                                
  125.                                 (and (not totalCost)
  126.                                      (gr (itmGetLevel thisItem) (objGetProperty installerObj 'installDeviceMaxLevel))
  127.                                      )
  128.                                     (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
  129.                                
  130.                                 (not totalCost)
  131.                                     (setq desc (cat (strCapitalize textWe) " cannot install " itemName " on " textYourShip "."))
  132.                                
  133.                                 (and (@ data 'checkMilitaryID)
  134.                                         (itmHasModifier thisItem "Military")
  135.                                         (not (objGetItems targetObj "*+MilitaryID"))
  136.                                         )
  137.                                     (setq desc (cat "You must have a military ID to use " itemName "."))
  138.                                
  139.                                 (and (@ data 'checkMilitaryID)
  140.                                         (itmHasModifier thisItem "Illegal")
  141.                                         )
  142.                                     (setq desc "We do not install illegal items.")
  143.  
  144.                                 (eq resultCode 'cannotInstall)
  145.                                     (setq desc resultMessage)
  146.  
  147.                                 (eq resultCode 'noDeviceSlotsLeft)
  148.                                     (setq desc (cat (strCapitalize textYourShip) " cannot support any more devices."))
  149.  
  150.                                 (eq resultCode 'reactorTooWeak)
  151.                                     (setq desc (cat (strCapitalize textYourShip) "'s reactor is not powerful enough for this device."))
  152.  
  153.                                 (eq resultCode 'reactorIncompatible)
  154.                                     (setq desc (cat "The power output of " itemName " is too high for " textYourShip "."))
  155.  
  156.                                 (eq resultCode 'noWeaponSlotsLeft)
  157.                                     (setq desc (cat (strCapitalize textYourShip) " cannot support any more weapons."))
  158.  
  159.                                 (eq resultCode 'noNonWeaponSlotsLeft)
  160.                                     (setq desc (cat (strCapitalize textYourShip) " cannot support any more non-weapon devices."))
  161.                                    
  162.                                 (and (eq resultCode 'replacementRequired)
  163.                                         (eq (itmGetType thisItem) (itmGetType itemToRemove))
  164.                                         (eq (itmIsEnhanced thisItem) (itmIsEnhanced itemToRemove))
  165.                                         (eq (itmGetProperty thisItem 'damaged) (itmGetProperty itemToRemove 'damaged))
  166.                                         (geq (itmGetProperty thisItem 'charges) (itmGetProperty itemToRemove 'charges))
  167.                                         )
  168.                                     (setq desc (cat (strCapitalize textYourShip) " already has " itemName " (and cannot support more devices unless you remove one first)."))
  169.                                    
  170.                                 (eq resultCode 'replacementRequired)
  171.                                     (block Nil
  172.                                         (setq desc (cat (strCapitalize textWe) " could remove " textYour " " (itmGetName itemToRemove 0x80) " and install " itemName))
  173.                                         (setq canInstall True)
  174.                                         )
  175.                                    
  176.                                 (not (eq resultCode 'ok))
  177.                                     (setq desc "This device cannot be installed.")
  178.  
  179.                                 (block Nil
  180.                                     (setq desc (cat (strCapitalize textWe) " could install " itemName " on " textYourShip))
  181.                                     (setq canInstall True)
  182.                                     )
  183.                                 )
  184.  
  185.                             ; If we need to remove a device, then it will cost more
  186.  
  187.                             (setq cargoNeeded 0)
  188.                             (if (and canInstall itemToRemove)
  189.                                 (block Nil
  190.                                     (if (not (@ data 'totalPrice))
  191.                                         (setq totalCost
  192.                                             (add totalCost
  193.                                                 ; Remove cost is 1/2 of install cost
  194.                                                 (divide (multiply gMargin (itmGetInstallCost itemToRemove currencyUsed)) 200)
  195.                                                 )
  196.                                             )
  197.                                         )
  198.  
  199.                                     ; See how much cargo space we need to store the old item
  200.  
  201.                                     (setq cargoNeeded (itmGetMass itemToRemove))
  202.                                     (if (@ data 'itemInCargo)
  203.                                         (setq cargoNeeded (subtract cargoNeeded (itmGetMass thisItem)))
  204.                                         )
  205.                                     )
  206.                                 )
  207.  
  208.                             ; See if the item fits
  209.  
  210.                             (if (and canInstall
  211.                                     (gr cargoNeeded (objGetCargoSpaceLeft targetObj))
  212.                                     (not (@ data 'noCargoCheck))
  213.                                     )
  214.                                 (block Nil
  215.                                     (setq desc (cat desc ". Unfortunately, there isn't enough room in your cargo hold to do the swap."))
  216.                                     (setq canInstall Nil)
  217.                                     )
  218.                                 )
  219.  
  220.                             ; See if we can afford the installation
  221.  
  222.                             (if canInstall
  223.                                 (if (gr totalCost 0)
  224.                                     (if (gr totalCost (objGetBalance targetObj currencyUsed))
  225.                                         (block Nil
  226.                                             (setq desc (cat desc " for " (fmtCurrency currencyUsed totalCost) ". Unfortunately, you cannot afford the cost."))
  227.                                             (setq canInstall Nil)
  228.                                             )
  229.                                         (setq desc (cat desc " for " (if (@ data 'buyAndInstall) "an additional " "") (fmtCurrency currencyUsed totalCost) "."))
  230.                                         )
  231.                                        
  232.                                     (if (not (eq installerObj gPlayerShip))
  233.                                         (setq desc (cat desc " at no charge."))
  234.                                         (setq desc (cat desc "."))
  235.                                         )
  236.                                     )
  237.                                 )
  238.                                
  239.                             ;   See if we are downgrading
  240.                            
  241.                             (if (and canInstall
  242.                                     itemToRemove
  243.                                     (ls (itmGetLevel thisItem) (itmGetLevel itemToRemove))
  244.                                     )
  245.                                 (setq desc (cat desc "  (However, the " (itmGetName itemToRemove 0x00) " is higher level.)"))
  246.                                 )
  247.                             )
  248.                            
  249.                         (setq desc "You do not have any devices that can be installed.")
  250.                         )
  251.  
  252.                     ; Return variables
  253.                     {
  254.                         canInstall: canInstall
  255.                         price: totalCost
  256.                         desc: desc
  257.                         itemToRemove: itemToRemove
  258.                         }
  259.                     )
  260.                 ))
  261.             )
  262.     </Globals>
  263.  
  264. </TranscendenceModule>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement