Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <TranscendenceModule>
- <Globals>
- (block Nil
- ; MODIFICATION:
- ; - changed two instances of 'can' into 'could'
- ; - Added 'itemToRemove' to the returned data
- ; -----------------------------------------
- (setq rpgInstallDevicePrep (lambda (data)
- ; Data must have the following fields
- ;
- ; item: The item to install
- ;
- ; In addition, the following optional fields are supported
- ;
- ; buyAndInstall: If True, we're installing as part of purchase
- ; checkMilitaryID: If True, we check for military ID, if necessary
- ; checkTotalPower: If True, we fail unless the total power of all devices matches reactor output
- ; currencyUsed: The currency used
- ; installerObj: Object installing the device (if Nil, we assume a station)
- ; installPriceAdj: Installation price (only if totalPrice is Nil)
- ; itemInCargo: If True, item is in player's cargo hold
- ; maxTechLevel: The maximum tech level we will install (unless we match techCriteriaOverride)
- ; noCargoCheck: If True, then we don't check to see if the old device fits in cargo
- ; targetObj: Object on which to install (if Nil, we assume player ship)
- ; techCriteria: If not Nil, the item must match this criteria
- ; techCriteriaOverride: If not Nil, and item matches this criteria, install even if above maxTechLevel
- ; totalPrice: The total price to install (may include purchase price)
- ;
- ; We return a struct with the following elements:
- ;
- ; canInstall: True if installation can proceed
- ; price: Total installation cost
- ; desc: Description of installation attempt
- ; itemToRemove: The item to be replaced
- (block (thisItem totalCost canInstall desc itemName currencyUsed targetObj installerObj textYourShip textWe textYour itemToRemove)
- (setq thisItem (@ data 'item))
- (setq currencyUsed (@ data 'currencyUsed))
- (setq targetObj (if (@ data 'targetObj) (@ data 'targetObj) gPlayerShip))
- (setq installerObj (if (@ data 'installerObj) (@ data 'installerObj) gSource))
- (if (not currencyUsed) (setq currencyUsed (objGetDefaultCurrency targetObj)))
- (setq itemName (itmGetName thisItem (if (@ data 'buyAndInstall) 0x40 0x04)))
- (setq canInstall Nil)
- ; If the target object is not the player's ship, then we need to modify
- ; some text
- (setq textYourShip
- (if (eq targetObj gPlayerShip)
- "your ship"
- (cat "the " (objGetName targetObj 0x00))
- )
- )
- (setq textWe
- (if (eq installerObj gPlayerShip)
- "you"
- "we"
- )
- )
- (setq textYour
- (if (eq targetObj gPlayerShip)
- "your"
- "the"
- )
- )
- (if thisItem
- (block (
- (installDevicePrice (objGetItemProperty installerObj thisItem 'installDevicePrice))
- (itemPrice
- (if (or (@ data 'upgrade) (@ data 'buyAndInstall))
- (objGetSellPrice installerObj thisItem)
- 0
- )
- )
- cargoNeeded itemToReplace resultMessage resultCode returnValue stationCannotInstall
- )
- ; Compute the cost to install
- (switch
- (@ data 'totalPrice)
- (setq totalCost (@ data 'totalPrice))
- (@ data 'installPriceAdj)
- (setq totalCost (rpgAdjustInstallPrice Nil thisItem (@ data 'installPriceAdj) currencyUsed))
- (setq totalCost (add itemPrice installDevicePrice))
- )
- ; Ask the object is we can install the item
- (setq returnValue (objCanInstallItem targetObj thisItem))
- (setq resultCode (@ returnValue 1))
- (setq resultMessage (@ returnValue 2))
- (setq itemToRemove (@ returnValue 3))
- (switch
- ; If we don't match the tech criteria then we don't have the
- ; technology to install.
- (and (@ data 'techCriteria)
- (not (itmMatches thisItem (@ data 'techCriteria)))
- )
- (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
- ; If our max tech level is too low for the item, then we can't install
- ; (except for specific items that we know about)
- (and (gr (itmGetLevel thisItem) (if (@ data 'maxTechLevel) (@ data 'maxTechLevel) 30))
- (or (not (@ data 'techCriteriaOverride))
- (not (itmMatches thisItem (@ data 'techCriteriaOverride)))
- )
- )
- (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
- (and (not totalCost)
- (gr (itmGetLevel thisItem) (objGetProperty installerObj 'installDeviceMaxLevel))
- )
- (setq desc (cat (strCapitalize textWe) " do not have the technology to install " itemName " on " textYourShip "."))
- (not totalCost)
- (setq desc (cat (strCapitalize textWe) " cannot install " itemName " on " textYourShip "."))
- (and (@ data 'checkMilitaryID)
- (itmHasModifier thisItem "Military")
- (not (objGetItems targetObj "*+MilitaryID"))
- )
- (setq desc (cat "You must have a military ID to use " itemName "."))
- (and (@ data 'checkMilitaryID)
- (itmHasModifier thisItem "Illegal")
- )
- (setq desc "We do not install illegal items.")
- (eq resultCode 'cannotInstall)
- (setq desc resultMessage)
- (eq resultCode 'noDeviceSlotsLeft)
- (setq desc (cat (strCapitalize textYourShip) " cannot support any more devices."))
- (eq resultCode 'reactorTooWeak)
- (setq desc (cat (strCapitalize textYourShip) "'s reactor is not powerful enough for this device."))
- (eq resultCode 'reactorIncompatible)
- (setq desc (cat "The power output of " itemName " is too high for " textYourShip "."))
- (eq resultCode 'noWeaponSlotsLeft)
- (setq desc (cat (strCapitalize textYourShip) " cannot support any more weapons."))
- (eq resultCode 'noNonWeaponSlotsLeft)
- (setq desc (cat (strCapitalize textYourShip) " cannot support any more non-weapon devices."))
- (and (eq resultCode 'replacementRequired)
- (eq (itmGetType thisItem) (itmGetType itemToRemove))
- (eq (itmIsEnhanced thisItem) (itmIsEnhanced itemToRemove))
- (eq (itmGetProperty thisItem 'damaged) (itmGetProperty itemToRemove 'damaged))
- (geq (itmGetProperty thisItem 'charges) (itmGetProperty itemToRemove 'charges))
- )
- (setq desc (cat (strCapitalize textYourShip) " already has " itemName " (and cannot support more devices unless you remove one first)."))
- (eq resultCode 'replacementRequired)
- (block Nil
- (setq desc (cat (strCapitalize textWe) " could remove " textYour " " (itmGetName itemToRemove 0x80) " and install " itemName))
- (setq canInstall True)
- )
- (not (eq resultCode 'ok))
- (setq desc "This device cannot be installed.")
- (block Nil
- (setq desc (cat (strCapitalize textWe) " could install " itemName " on " textYourShip))
- (setq canInstall True)
- )
- )
- ; If we need to remove a device, then it will cost more
- (setq cargoNeeded 0)
- (if (and canInstall itemToRemove)
- (block Nil
- (if (not (@ data 'totalPrice))
- (setq totalCost
- (add totalCost
- ; Remove cost is 1/2 of install cost
- (divide (multiply gMargin (itmGetInstallCost itemToRemove currencyUsed)) 200)
- )
- )
- )
- ; See how much cargo space we need to store the old item
- (setq cargoNeeded (itmGetMass itemToRemove))
- (if (@ data 'itemInCargo)
- (setq cargoNeeded (subtract cargoNeeded (itmGetMass thisItem)))
- )
- )
- )
- ; See if the item fits
- (if (and canInstall
- (gr cargoNeeded (objGetCargoSpaceLeft targetObj))
- (not (@ data 'noCargoCheck))
- )
- (block Nil
- (setq desc (cat desc ". Unfortunately, there isn't enough room in your cargo hold to do the swap."))
- (setq canInstall Nil)
- )
- )
- ; See if we can afford the installation
- (if canInstall
- (if (gr totalCost 0)
- (if (gr totalCost (objGetBalance targetObj currencyUsed))
- (block Nil
- (setq desc (cat desc " for " (fmtCurrency currencyUsed totalCost) ". Unfortunately, you cannot afford the cost."))
- (setq canInstall Nil)
- )
- (setq desc (cat desc " for " (if (@ data 'buyAndInstall) "an additional " "") (fmtCurrency currencyUsed totalCost) "."))
- )
- (if (not (eq installerObj gPlayerShip))
- (setq desc (cat desc " at no charge."))
- (setq desc (cat desc "."))
- )
- )
- )
- ; See if we are downgrading
- (if (and canInstall
- itemToRemove
- (ls (itmGetLevel thisItem) (itmGetLevel itemToRemove))
- )
- (setq desc (cat desc " (However, the " (itmGetName itemToRemove 0x00) " is higher level.)"))
- )
- )
- (setq desc "You do not have any devices that can be installed.")
- )
- ; Return variables
- {
- canInstall: canInstall
- price: totalCost
- desc: desc
- itemToRemove: itemToRemove
- }
- )
- ))
- )
- </Globals>
- </TranscendenceModule>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement