From 81a041ed9a84cd1410982d83377e4b61275f13e2 Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Wed, 19 Mar 2025 17:06:54 -0500 Subject: [PATCH 1/2] Scurvy Scavenger Scenario Updates Enable scenario for ECS and pre-ECS. Edd translation tags and contexts for goods and other messages. Update goods handling and other comms routines. Add jettison cargo function for overly enthusiastic relay officers. --- scripts/scenario_47_scavenger.lua | 675 ++++++++++++++++++------------ 1 file changed, 405 insertions(+), 270 deletions(-) diff --git a/scripts/scenario_47_scavenger.lua b/scripts/scenario_47_scavenger.lua index bf17bf40be..d27e24574e 100644 --- a/scripts/scenario_47_scavenger.lua +++ b/scripts/scenario_47_scavenger.lua @@ -20,10 +20,16 @@ require("generate_call_sign_scenario_utility.lua") require("spawn_ships_scenario_utility.lua") function init() - scenario_version = "1.1.2" - ee_version = "2023.06.17" + scenario_version = "1.1.6" + ee_version = "2024.12.08" print(string.format(" ---- Scenario: Scurvy Scavenger ---- Version %s ---- Tested with EE version %s ----",scenario_version,ee_version)) - print(_VERSION) + if _VERSION ~= nil then + print("Lua version:",_VERSION) + end + ECS = false + if createEntity then + ECS = true + end stationCommsDiagnostic = false exuari_harass_diagnostic = false spawn_enemy_diagnostic = false @@ -187,6 +193,74 @@ function init() -- print("end of init") allowNewPlayerShips(false) end +function isObjectType(obj,typ,qualifier) + if obj ~= nil and obj:isValid() then + if typ ~= nil then + if ECS then + if typ == "SpaceStation" then + return obj.components.docking_bay and obj.components.physics and obj.components.physics.type == "static" + elseif typ == "PlayerSpaceship" then + return obj.components.player_control + elseif typ == "ScanProbe" then + return obj.components.allow_radar_link + elseif typ == "CpuShip" then + return obj.ai_controller + elseif typ == "Asteroid" then + return obj.components.mesh_render and string.sub(obj.components.mesh_render.mesh, 7) == "Astroid" + elseif typ == "Nebula" then + return obj.components.nebula_renderer + elseif typ == "Planet" then + return obj.components.planet_render + elseif typ == "SupplyDrop" then + return obj.components.pickup and obj.components.radar_trace.icon == "radar/blip.png" and obj.components.radar_trace.color_by_faction + elseif typ == "BlackHole" then + return obj.components.gravity and obj.components.billboard_render.texture == "blackHole3d.png" + elseif typ == "WarpJammer" then + return obj.components.warp_jammer + elseif typ == "Mine" then + return obj.components.delayed_explode_on_touch and obj.components.constant_particle_emitter + elseif typ == "EMPMissile" then + return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explode_on_touch.damage_type == "emp" + elseif typ == "Nuke" then + return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explosion_sfx == "sfx/nuke_explosion.wav" + elseif typ == "Zone" then + return obj.components.zone + else + if qualifier == "MovingMissile" then + if typ == "HomingMissile" or typ == "HVLI" or typ == "Nuke" or typ == "EMPMissile" then + return obj.components.radar_trace.icon == "radar/missile.png" + else + return false + end + elseif qualifier == "SplashMissile" then + if typ == "Nuke" or typ == "EMPMissile" then + if obj.components.radar_trace.icon == "radar/missile.png" then + if typ == "Nuke" then + return obj.components.explosion_sfx == "sfx/nuke_explosion.wav" + else --EMP + return obj.components.explode_on_touch.damage_type == "emp" + end + else + return false + end + else + return false + end + else + return false + end + end + else + return obj.typeName == typ + end + else + return false + end + else + return false + end +end + -- Initialization function setVariations() local enemy_config = { @@ -487,6 +561,40 @@ function setConstants() commonGoods = {"food","medicine","nickel","platinum","gold","dilithium","tritanium","luxury","cobalt","impulse","warp","shield","tractor","repulsor","beam","optic","robotic","filament","transporter","sensor","communication","autodoc","lifter","android","nanites","software","circuit","battery"} componentGoods = {"impulse","warp","shield","tractor","repulsor","beam","optic","robotic","filament","transporter","sensor","communication","autodoc","lifter","android","nanites","software","circuit","battery"} mineralGoods = {"nickel","platinum","gold","dilithium","tritanium","cobalt"} + good_desc = { + ["food"] = _("trade-comms","food"), + ["medicine"] = _("trade-comms","medicine"), + ["luxury"] = _("trade-comms","luxury"), + ["cobalt"] = _("trade-comms","cobalt"), + ["dilithium"] = _("trade-comms","dilithium"), + ["gold"] = _("trade-comms","gold"), + ["nickel"] = _("trade-comms","nickel"), + ["platinum"] = _("trade-comms","platinum"), + ["tritanium"] = _("trade-comms","tritanium"), + ["autodoc"] = _("trade-comms","autodoc"), + ["android"] = _("trade-comms","android"), + ["battery"] = _("trade-comms","battery"), + ["beam"] = _("trade-comms","beam"), + ["circuit"] = _("trade-comms","circuit"), + ["communication"] = _("trade-comms","communication"), + ["filament"] = _("trade-comms","filament"), + ["impulse"] = _("trade-comms","impulse"), + ["lifter"] = _("trade-comms","lifter"), + ["nanites"] = _("trade-comms","nanites"), + ["optic"] = _("trade-comms","optic"), + ["repulsor"] = _("trade-comms","repulsor"), + ["robotic"] = _("trade-comms","robotic"), + ["sensor"] = _("trade-comms","sensor"), + ["shield"] = _("trade-comms","shield"), + ["software"] = _("trade-comms","software"), + ["tractor"] = _("trade-comms","tractor"), + ["transporter"] = _("trade-comms","transporter"), + ["warp"] = _("trade-comms","warp"), + ["gold pressed latinum"] = _("trade-comms","gold pressed latinum"), + ["unobtanium"] = _("trade-comms","unobtanium"), + ["eludium"] = _("trade-comms","eludium"), + ["impossibrium"] = _("trade-comms","impossibrium"), + } characterNames = {"Frank Brown", "Joyce Miller", "Harry Jones", @@ -585,32 +693,32 @@ function setInitialContractDetails() first_station.comms_data.contract = {} first_station.comms_data.contract["one_to_two"] = { type = "start", - prompt = string.format(_("contract-comms", "Deliver three %s to %s. Upon delivery, they will increase your hull strength"),independent_station[2].comms_data.characterGood,independent_station[2]:getCallSign()), - short_prompt = string.format(_("contract-comms", "Three %s to %s"),independent_station[2].comms_data.characterGood,independent_station[2]:getCallSign()), + prompt = string.format(_("contract-comms", "Deliver three %s to %s. Upon delivery, they will increase your hull strength"),good_desc[independent_station[2].comms_data.characterGood],independent_station[2]:getCallSign()), + short_prompt = string.format(_("contract-comms", "Three %s to %s"),good_desc[independent_station[2].comms_data.characterGood],independent_station[2]:getCallSign()), accepted = false, func = start1to2delivery, } independent_station[2].comms_data.contract = {} independent_station[2].comms_data.contract["one_to_two"] = { type = "fulfill", - prompt = string.format(_("contract-comms", "Fulfill %s 3 %s %s contract"),first_station:getCallSign(),independent_station[2].comms_data.characterGood,independent_station[2]:getCallSign()), - short_prompt = string.format(_("contract-comms", "Three %s from %s"),independent_station[2].comms_data.characterGood,first_station:getCallSign()), + prompt = string.format(_("contract-comms", "Fulfill %s 3 %s %s contract"),first_station:getCallSign(),good_desc[independent_station[2].comms_data.characterGood],independent_station[2]:getCallSign()), + short_prompt = string.format(_("contract-comms", "Three %s from %s"),good_desc[independent_station[2].comms_data.characterGood],first_station:getCallSign()), fulfilled = false, func = complete1to2delivery, } --contract details: second to third station independent_station[2].comms_data.contract["two_to_three"] = { type = "start", - prompt = string.format(_("contract-comms", "Deliver two %s to %s. Upon delivery, they will increase your shield strength"),independent_station[3].comms_data.characterGood,independent_station[3]:getCallSign()), - short_prompt = string.format(_("contract-comms", "Two %s to %s"),independent_station[3].comms_data.characterGood,independent_station[3]:getCallSign()), + prompt = string.format(_("contract-comms", "Deliver two %s to %s. Upon delivery, they will increase your shield strength"),good_desc[independent_station[3].comms_data.characterGood],independent_station[3]:getCallSign()), + short_prompt = string.format(_("contract-comms", "Two %s to %s"),good_desc[independent_station[3].comms_data.characterGood],independent_station[3]:getCallSign()), accepted = false, func = start2to3delivery, } independent_station[3].comms_data.contract = {} independent_station[3].comms_data.contract["two_to_three"] = { type = "fulfill", - prompt = string.format(_("contract-comms", "Fulfill %s 2 %s %s contract"),independent_station[2]:getCallSign(),independent_station[3].comms_data.characterGood,independent_station[3]:getCallSign()), - short_prompt = string.format(_("contract-comms", "Two %s from %s"),independent_station[3].comms_data.characterGood,independent_station[2]:getCallSign()), + prompt = string.format(_("contract-comms", "Fulfill %s 2 %s %s contract"),independent_station[2]:getCallSign(),good_desc[independent_station[3].comms_data.characterGood],independent_station[3]:getCallSign()), + short_prompt = string.format(_("contract-comms", "Two %s from %s"),good_desc[independent_station[3].comms_data.characterGood],independent_station[2]:getCallSign()), fulfilled = false, func = complete2to3delivery, } @@ -1004,7 +1112,7 @@ function createRandomAlongArc(object_type, amount, x, y, distance, startArc, end local radialPoint = startArc+ndex local pointDist = distance + random(-randomize,randomize) last_object = object_type():setPosition(x + math.cos(radialPoint / 180 * math.pi) * pointDist, y + math.sin(radialPoint / 180 * math.pi) * pointDist) - if last_object.typeName == "Asteroid" then + if isObjectType(last_object,"Asteroid") then last_object:setSize(asteroidSize()) end table.insert(object_list,last_object) @@ -1013,7 +1121,7 @@ function createRandomAlongArc(object_type, amount, x, y, distance, startArc, end radialPoint = random(startArc,endArcClockwise) pointDist = distance + random(-randomize,randomize) last_object = object_type():setPosition(x + math.cos(radialPoint / 180 * math.pi) * pointDist, y + math.sin(radialPoint / 180 * math.pi) * pointDist) - if last_object.typeName == "Asteroid" then + if isObjectType(last_object,"Asteroid") then last_object:setSize(asteroidSize()) end table.insert(object_list,last_object) @@ -1023,7 +1131,7 @@ function createRandomAlongArc(object_type, amount, x, y, distance, startArc, end radialPoint = random(startArc,endArcClockwise) pointDist = distance + random(-randomize,randomize) last_object = object_type():setPosition(x + math.cos(radialPoint / 180 * math.pi) * pointDist, y + math.sin(radialPoint / 180 * math.pi) * pointDist) - if last_object.typeName == "Asteroid" then + if isObjectType(last_object,"Asteroid") then last_object:setSize(asteroidSize()) end table.insert(object_list,last_object) @@ -1227,7 +1335,7 @@ function curvaceousAsteroids1(fsx, fsy, player_to_station_distance) scanned_description = string.format(_("scienceDescription-asteroid", "%s, %srock:remainder"),unscanned_description, scanned_description) target_asteroid = selected_asteroid target_asteroid_x, target_asteroid_y = target_asteroid:getPosition() - print(string.format("Target Asteroid: Sector:%s X:%i Y:%i Osmium:%.1f, Iridium:%.1f, Olivine:%.1f, Nickel:%.1f",target_asteroid:getSectorName(),math.floor(target_asteroid_x),math.floor(target_asteroid_y),target_asteroid.osmium,target_asteroid.iridium,target_asteroid.olivine,target_asteroid.nickel)) +-- print(string.format("Target Asteroid: Sector:%s X:%i Y:%i Osmium:%.1f, Iridium:%.1f, Olivine:%.1f, Nickel:%.1f",target_asteroid:getSectorName(),math.floor(target_asteroid_x),math.floor(target_asteroid_y),target_asteroid.osmium,target_asteroid.iridium,target_asteroid.olivine,target_asteroid.nickel)) else if random(0,100) < 2 and selected_asteroid.composition < 100 then selected_asteroid.osmium = math.random(1,20)/10 @@ -1448,7 +1556,7 @@ function playerShipCargoInventory(p) if p.goods ~= nil then for good, goodQuantity in pairs(p.goods) do goodCount = goodCount + 1 - p:addToShipLog(string.format(_("inventory-shipLog", " %s: %i"),good,goodQuantity),"Yellow") + p:addToShipLog(string.format(_("inventory-shipLog", " %s: %i"),good_desc[good],goodQuantity),"Yellow") end end if goodCount < 1 then @@ -1579,7 +1687,7 @@ function start1to2delivery() comms_source.goods[good] = 0 end comms_source.goods[good] = comms_source.goods[good] + 3 - setCommsMessage(string.format(_("contract-comms", "Cargo of three %s has been loaded onto your ship. Deliver to %s in %s"),good,independent_station[2]:getCallSign(),independent_station[2]:getSectorName())) + setCommsMessage(string.format(_("contract-comms", "Cargo of three %s has been loaded onto your ship. Deliver to %s in %s"),good_desc[good],independent_station[2]:getCallSign(),independent_station[2]:getSectorName())) first_station.comms_data.contract["one_to_two"].accepted = true table.insert(contract_station,independent_station[2]) end @@ -1604,9 +1712,9 @@ function complete1to2delivery() end end comms_source:addReputationPoints(50) - setCommsMessage(string.format(_("contract-comms", "Thanks for the %s, %s. We increased your hull strength by 50%%"),good,comms_source:getCallSign())) + setCommsMessage(string.format(_("contract-comms", "Thanks for the %s, %s. We increased your hull strength by 50%%"),good_desc[good],comms_source:getCallSign())) else - setCommsMessage(string.format(_("contract-comms", "The terms of the contract require the delivery of three %s. This has not been met"),good)) + setCommsMessage(string.format(_("contract-comms", "The terms of the contract require the delivery of three %s. This has not been met"),good_desc[good])) end addCommsReply(_("Back"),commsStation) end @@ -1624,7 +1732,7 @@ function start2to3delivery() comms_source.goods[good] = 0 end comms_source.goods[good] = comms_source.goods[good] + 2 - setCommsMessage(string.format(_("contract-comms", "Cargo of two %s has been loaded onto your ship. Deliver to %s in %s"),good,independent_station[3]:getCallSign(),independent_station[3]:getSectorName())) + setCommsMessage(string.format(_("contract-comms", "Cargo of two %s has been loaded onto your ship. Deliver to %s in %s"),good_desc[good],independent_station[3]:getCallSign(),independent_station[3]:getSectorName())) independent_station[2].comms_data.contract["two_to_three"].accepted = true table.insert(contract_station,independent_station[3]) end @@ -1652,9 +1760,9 @@ function complete2to3delivery() end end comms_source:addReputationPoints(50) - setCommsMessage(string.format(_("contract-comms", "Thanks for the %s, %s. We increased your shield strength by 25%%"),good,comms_source:getCallSign())) + setCommsMessage(string.format(_("contract-comms", "Thanks for the %s, %s. We increased your shield strength by 25%%"),good_desc[good],comms_source:getCallSign())) else - setCommsMessage(string.format(_("contract-comms", "The terms of the contract require the delivery of two %s. This has not been met"),good)) + setCommsMessage(string.format(_("contract-comms", "The terms of the contract require the delivery of two %s. This has not been met"),good_desc[good])) end addCommsReply(_("Back"),commsStation) end @@ -1674,18 +1782,18 @@ function setOptionalAddBeamMission(beam_station) --add clue station here end function stationMineralGood(mineral_station) - if mineral_station == nil then + if mineral_station == nil or not mineral_station:isValid() then return "gold pressed latinum" - end - local ctd = mineral_station.comms_data - for good, goodData in pairs(ctd.goods) do - if mineralGoods[good] ~= nil then - return good + else + for good, goodData in pairs(mineral_station.comms_data.goods) do + if mineralGoods[good] ~= nil then + return good + end end + local mineral = mineralGoods[math.random(1,#mineralGoods)] + mineral_station.comms_data.goods[mineral] = {quantity = math.random(5,10), cost = math.random(25,60)} + return mineral end - local mineral = mineralGoods[math.random(1,#mineralGoods)] - mineral_station.comms_data.goods[mineral] = {quantity = math.random(5,10), cost = math.random(25,60)} - return mineral end function setOptionalEfficientBatteriesMisison(battery_station) if efficient_battery_diagnostic then print("top of setOptionalEfficientBatteriesMisison") end @@ -1705,12 +1813,11 @@ function setOptionalEfficientBatteriesMisison(battery_station) end function stationComponentGood(component_station,preferred_good) if efficient_battery_diagnostic then print("top of stationComponentGood") end - if component_station == nil then + if component_station == nil or not component_station:isValid() then return end if efficient_battery_diagnostic then print(string.format("component station: %s",component_station:getCallSign())) end - local ctd = component_station.comms_data - for good, goodData in pairs(ctd.goods) do + for good, goodData in pairs(component_station.comms_data.goods) do if componentGoods[good] ~= nil then if efficient_battery_diagnostic then print("determined good from station: " .. good) end return good @@ -1856,7 +1963,6 @@ function commsStation() neutral = 0.5 } }) - comms_data = comms_target.comms_data if stationCommsDiagnostic then print("set player") end setPlayer() if stationCommsDiagnostic then print("set local variable player from comms source") end @@ -1884,12 +1990,11 @@ function add_to_list(from_list,to_list) end function handleDockedState() local playerCallSign = comms_source:getCallSign() - local ctd = comms_target.comms_data if stationCommsDiagnostic then print(string.format("handleDockedState derived name: %s",playerCallSign)) end if comms_source:isFriendly(comms_target) then - if ctd.friendlyness > 66 then + if comms_target.comms_data.friendlyness > 66 then oMsg = string.format(_("station-comms", "Greetings %s!\nHow may we help you today?"),comms_source:getCallSign()) - elseif ctd.friendlyness > 33 then + elseif comms_target.comms_data.friendlyness > 33 then oMsg = _("station-comms", "Good day, officer!\nWhat can we do for you today?") else oMsg = _("station-comms", "Hello, may I help you?") @@ -1902,7 +2007,7 @@ function handleDockedState() end setCommsMessage(oMsg) local goodCount = 0 - for good, goodData in pairs(ctd.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do goodCount = goodCount + 1 end local missilePresence = 0 @@ -1911,19 +2016,18 @@ function handleDockedState() missilePresence = missilePresence + comms_source:getWeaponStorageMax(missile_type) end if missilePresence > 0 then - if (ctd.weapon_available.Nuke and comms_source:getWeaponStorageMax("Nuke") > 0) or - (ctd.weapon_available.EMP and comms_source:getWeaponStorageMax("EMP") > 0) or - (ctd.weapon_available.Homing and comms_source:getWeaponStorageMax("Homing") > 0) or - (ctd.weapon_available.Mine and comms_source:getWeaponStorageMax("Mine") > 0) or - (ctd.weapon_available.HVLI and comms_source:getWeaponStorageMax("HVLI") > 0) then + if (comms_target.comms_data.weapon_available.Nuke and comms_source:getWeaponStorageMax("Nuke") > 0) or + (comms_target.comms_data.weapon_available.EMP and comms_source:getWeaponStorageMax("EMP") > 0) or + (comms_target.comms_data.weapon_available.Homing and comms_source:getWeaponStorageMax("Homing") > 0) or + (comms_target.comms_data.weapon_available.Mine and comms_source:getWeaponStorageMax("Mine") > 0) or + (comms_target.comms_data.weapon_available.HVLI and comms_source:getWeaponStorageMax("HVLI") > 0) then addCommsReply(_("ammo-comms", "I need ordnance restocked"), function() - local ctd = comms_target.comms_data if stationCommsDiagnostic then print("in restock function") end setCommsMessage(_("ammo-comms", "What type of ordnance?")) if stationCommsDiagnostic then print(string.format("player nuke weapon storage max: %.1f",comms_source:getWeaponStorageMax("Nuke"))) end if comms_source:getWeaponStorageMax("Nuke") > 0 then if stationCommsDiagnostic then print("player can fire nukes") end - if ctd.weapon_available.Nuke then + if comms_target.comms_data.weapon_available.Nuke then if stationCommsDiagnostic then print("station has nukes available") end if math.random(1,10) <= 5 then nukePrompt = _("ammo-comms", "Can you supply us with some nukes? (") @@ -1938,7 +2042,7 @@ function handleDockedState() end --end station has nuke available if branch end --end player can accept nuke if branch if comms_source:getWeaponStorageMax("EMP") > 0 then - if ctd.weapon_available.EMP then + if comms_target.comms_data.weapon_available.EMP then if math.random(1,10) <= 5 then empPrompt = _("ammo-comms", "Please re-stock our EMP missiles. (") else @@ -1950,7 +2054,7 @@ function handleDockedState() end --end station has EMP available if branch end --end player can accept EMP if branch if comms_source:getWeaponStorageMax("Homing") > 0 then - if ctd.weapon_available.Homing then + if comms_target.comms_data.weapon_available.Homing then if math.random(1,10) <= 5 then homePrompt = _("ammo-comms", "Do you have spare homing missiles for us? (") else @@ -1962,7 +2066,7 @@ function handleDockedState() end --end station has homing for player if branch end --end player can accept homing if branch if comms_source:getWeaponStorageMax("Mine") > 0 then - if ctd.weapon_available.Mine then + if comms_target.comms_data.weapon_available.Mine then if math.random(1,10) <= 5 then minePrompt = _("ammo-comms", "We could use some mines. (") else @@ -1974,7 +2078,7 @@ function handleDockedState() end --end station has mine for player if branch end --end player can accept mine if branch if comms_source:getWeaponStorageMax("HVLI") > 0 then - if ctd.weapon_available.HVLI then + if comms_target.comms_data.weapon_available.HVLI then if math.random(1,10) <= 5 then hvliPrompt = _("ammo-comms", "What about HVLI? (") else @@ -2060,21 +2164,21 @@ function handleDockedState() setCommsMessage(_("station-comms", "What would you like to know?")) if comms_target.comms_data.general ~= nil and comms_target.comms_data.general ~= "" then addCommsReply(_("stationGeneralInfo-comms","General information"), function() - setCommsMessage(ctd.general) + setCommsMessage(comms_target.comms_data.general) addCommsReply(_("Back"), commsStation) end) end - if ctd.history ~= nil and comms_target.comms_data.history ~= "" then + if comms_target.comms_data.history ~= nil and comms_target.comms_data.history ~= "" then addCommsReply(_("stationStory-comms", "Station history"), function() - setCommsMessage(ctd.history) + setCommsMessage(comms_target.comms_data.history) addCommsReply(_("Back"), commsStation) end) end if comms_source:isFriendly(comms_target) then - if ctd.gossip ~= nil then + if comms_target.comms_data.gossip ~= nil then if random(1,100) < (100 - (30 * (difficulty - .5))) then addCommsReply(_("gossip-comms", "Gossip"), function() - setCommsMessage(ctd.gossip) + setCommsMessage(comms_target.comms_data.gossip) addCommsReply(_("Back"), commsStation) end) end @@ -2083,62 +2187,62 @@ function handleDockedState() addCommsReply(_("Back"),commsStation) end) --end station info comms reply branch end --end public relations if branch - if stationCommsDiagnostic then print(ctd.character) end - if ctd.character ~= nil then - addCommsReply(string.format(_("characterInfo-comms", "Tell me about %s"),ctd.character), function() - if ctd.characterDescription ~= nil then - setCommsMessage(ctd.characterDescription) + if stationCommsDiagnostic then print(comms_target.comms_data.character) end + if comms_target.comms_data.character ~= nil then + addCommsReply(string.format(_("characterInfo-comms", "Tell me about %s"),comms_target.comms_data.character), function() + if comms_target.comms_data.characterDescription ~= nil then + setCommsMessage(comms_target.comms_data.characterDescription) else - if ctd.characterDeadEnd == nil then + if comms_target.comms_data.characterDeadEnd == nil then local deadEndChoice = math.random(1,5) if deadEndChoice == 1 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "Never heard of %s"), ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "Never heard of %s"), comms_target.comms_data.character) elseif deadEndChoice == 2 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "%s died last week. The funeral was yesterday"), ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "%s died last week. The funeral was yesterday"), comms_target.comms_data.character) elseif deadEndChoice == 3 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "%s? Who's %s? There's nobody here named %s"),ctd.character,ctd.character,ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "%s? Who's %s? There's nobody here named %s"),comms_target.comms_data.character,comms_target.comms_data.character,comms_target.comms_data.character) elseif deadEndChoice == 4 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "We don't talk about %s. They are gone and good riddance"),ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "We don't talk about %s. They are gone and good riddance"),comms_target.comms_data.character) else - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "I think %s moved away"),ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "I think %s moved away"),comms_target.comms_data.character) end end - setCommsMessage(ctd.characterDeadEnd) + setCommsMessage(comms_target.comms_data.characterDeadEnd) end - if ctd.characterFunction == "addForwardBeam" then + if comms_target.comms_data.characterFunction == "addForwardBeam" then addForwardBeam() end - if ctd.characterFunction == "shrinkBeamCycle" then + if comms_target.comms_data.characterFunction == "shrinkBeamCycle" then shrinkBeamCycle() end - if ctd.characterFunction == "increaseSpin" then + if comms_target.comms_data.characterFunction == "increaseSpin" then increaseSpin() end - if ctd.characterFunction == "addAuxTube" then + if comms_target.comms_data.characterFunction == "addAuxTube" then addAuxTube() end - if ctd.characterFunction == "coolBeam" then + if comms_target.comms_data.characterFunction == "coolBeam" then coolBeam() end - if ctd.characterFunction == "longerBeam" then + if comms_target.comms_data.characterFunction == "longerBeam" then longerBeam() end - if ctd.characterFunction == "damageBeam" then + if comms_target.comms_data.characterFunction == "damageBeam" then damageBeam() end - if ctd.characterFunction == "moreMissiles" then + if comms_target.comms_data.characterFunction == "moreMissiles" then moreMissiles() end - if ctd.characterFunction == "fasterImpulse" then + if comms_target.comms_data.characterFunction == "fasterImpulse" then fasterImpulse() end - if ctd.characterFunction == "strongerHull" then + if comms_target.comms_data.characterFunction == "strongerHull" then strongerHull() end - if ctd.characterFunction == "efficientBatteries" then + if comms_target.comms_data.characterFunction == "efficientBatteries" then efficientBatteries() end - if ctd.characterFunction == "strongerShields" then + if comms_target.comms_data.characterFunction == "strongerShields" then strongerShields() end addCommsReply(_("Back"), commsStation) @@ -2171,11 +2275,29 @@ function handleDockedState() end if comms_source:getJumpDriveCharge() >= max_charge then addCommsReply(_("stationServices-comms", "Overcharge Jump Drive (10 Rep)"),function() - if comms_source:takeReputationPoints(10) then - comms_source:setJumpDriveCharge(comms_source:getJumpDriveCharge() + max_charge) - setCommsMessage(string.format(_("stationServices-comms", "Your jump drive has been overcharged to %ik"),math.floor(comms_source:getJumpDriveCharge()/1000))) + if comms_source:getJumpDriveCharge()/1000 > 300 then + setCommsMessage(_("stationServices-comms","Overcharging your jump drive further would exceed the safety protocol established by commisioner Muerte.")) + addCommsReply(_("stationServices-comms","Overcharge Jump Drive anyway (10 Rep)"),function() + if comms_source:takeReputationPoints(10) then + comms_source:setJumpDriveCharge(comms_source:getJumpDriveCharge() + max_charge) + setCommsMessage(string.format(_("stationServices-comms", "Your jump drive has been overcharged to %ik"),math.floor(comms_source:getJumpDriveCharge()/1000))) + comms_source:setSystemHealth("jumpdrive",-1) + else + setCommsMessage(_("needRep-comms", "Insufficient reputation")) + end + addCommsReply(_("Back"), commsStation) + end) + addCommsReply(_("stationServices-comms","What happens if we overcharge past the Muerte limit?"),function() + setCommsMessage(_("stationServices-comms","Unknown. A teenager on his staff wrote a cautionary document that Muerte took to heart. From that information, Muerte established the safety protocol.")) + addCommsReply(_("Back"), commsStation) + end) else - setCommsMessage(_("needRep-comms", "Insufficient reputation")) + if comms_source:takeReputationPoints(10) then + comms_source:setJumpDriveCharge(comms_source:getJumpDriveCharge() + max_charge) + setCommsMessage(string.format(_("stationServices-comms", "Your jump drive has been overcharged to %ik"),math.floor(comms_source:getJumpDriveCharge()/1000))) + else + setCommsMessage(_("needRep-comms", "Insufficient reputation")) + end end addCommsReply(_("Back"), commsStation) end) @@ -2274,7 +2396,7 @@ function handleDockedState() addCommsReply(_("contract-comms", "Check long distance contract"),function() createHumanNavySystem() setCommsMessage(string.format(_("contract-comms", "Contract Details:\nTravel to %s system to deliver cargo to supply station %s. Distance to system: %i units. Upon delivery, %s technicians will upgrade your battery efficiency and beam cycle time."),planet_star:getCallSign(),supply_depot_station:getCallSign(),math.floor(distance(comms_target,planet_star)/1000),supply_depot_station:getCallSign())) - addCommsReply("Accept",function() + addCommsReply(_("contract-comms","Accept"),function() local p = getPlayerShip(-1) addMineTube(p) local acceptance_message = string.format(_("contract-comms", "The Human Navy requires all armed ships be equipped with the ability to drop mines. We have modified %s with a rear facing mining tube. Due to ship size constraints, we were only able to provide you with two mines."),comms_source:getCallSign()) @@ -2285,14 +2407,14 @@ function handleDockedState() if good_quantity > 0 then comms_source.goods[good] = 0 if remove_list == "" then - remove_list = remove_list .. _("contract-comms", "\n\nYour current cargo (") .. good + remove_list = string.format(_("contract-comms", "%s\n\nYour current cargo (%s"),remove_list,good_desc[good]) else - remove_list = remove_list .. _("contract-comms", ", ") .. good + remove_list = string.format(_("contract-comms", "%s, %s"),remove_list,good_desc[good]) end end end - remove_list = remove_list .. _("contract-comms", ") has been removed to make room for your contract cargo and to help defray the cost of upgrading your ship to Human Navy standards.") - acceptance_message = acceptance_message .. remove_list + remove_list = string.format(_("contract-comms", ") has been removed to make room for your contract cargo and to help defray the cost of upgrading your ship to Human Navy standards."),remove_list) + acceptance_message = string.format(_("contract-comms","%s%s"),acceptance_message,remove_list) end if comms_source.goods == nil then comms_source.goods = {} @@ -2441,10 +2563,9 @@ function handleDockedState() end end if contract_eligible then - local ctd = comms_target.comms_data - if ctd.contract ~= nil then + if comms_target.comms_data.contract ~= nil then local contract_available = false - for contract, details in pairs(ctd.contract) do + for contract, details in pairs(comms_target.comms_data.contract) do if details.type == "start" then if not details.accepted then contract_available = true @@ -2459,7 +2580,7 @@ function handleDockedState() local contract_report = string.format(_("contract-comms", "Contract report from station %s:"),comms_target:getCallSign()) if contract_available then addCommsReply(_("contract-comms", "Browse Contracts"), function() - for contract, details in pairs(ctd.contract) do + for contract, details in pairs(comms_target.comms_data.contract) do if details.type == "start" then if details.accepted ~= nil and not details.accepted and details.prompt ~= nil then contract_report = contract_report .. _("contract-comms", "\nTo Accept: ") .. details.prompt @@ -2516,40 +2637,39 @@ function handleDockedState() end --end friendly/neutral if goodCount > 0 then addCommsReply(_("trade-comms", "Buy, sell, trade"), function() - local ctd = comms_target.comms_data - local goodsReport = string.format(_("trade-comms", "Station %s:\nGoods or components available for sale: quantity, cost in reputation\n"),comms_target:getCallSign()) - for good, goodData in pairs(ctd.goods) do - goodsReport = goodsReport .. string.format(_("trade-comms", " %s: %i, %i\n"),good,goodData["quantity"],goodData["cost"]) + local goodsReport = string.format(_("forSaleTrade-comms", "Station %s:\nGoods or components available for sale: quantity, cost in reputation\n"),comms_target:getCallSign()) + for good, goodData in pairs(comms_target.comms_data.goods) do + goodsReport = string.format(_("forSaleTrade-comms", "%s %s: %i, %i\n"),goodsReport,good_desc[good],goodData["quantity"],goodData["cost"]) end - if ctd.buy ~= nil then - goodsReport = goodsReport .. _("trade-comms", "Goods or components station will buy: price in reputation\n") - for good, price in pairs(ctd.buy) do - goodsReport = goodsReport .. string.format(_("trade-comms", " %s: %i\n"),good,price) + if comms_target.comms_data.buy ~= nil then + goodsReport = string.format(_("willBuyTrade-comms", "%sGoods or components station will buy: price in reputation\n"),goodsReport) + for good, price in pairs(comms_target.comms_data.buy) do + goodsReport = string.format(_("willBuyTrade-comms", "%s %s: %i\n"),goodsReport,good_desc[good],price) end end - goodsReport = goodsReport .. string.format(_("trade-comms", "Current cargo aboard %s:\n"),comms_source:getCallSign()) + goodsReport = string.format(_("onBoardTrade-comms", "%sCurrent cargo aboard %s:\n"),goodsReport,comms_source:getCallSign()) local cargoHoldEmpty = true local goodCount = 0 if comms_source.goods ~= nil then for good, goodQuantity in pairs(comms_source.goods) do goodCount = goodCount + 1 - goodsReport = goodsReport .. string.format(_("trade-comms", " %s: %i\n"),good,goodQuantity) + goodsReport = string.format(_("onBoardTrade-comms", "%s %s: %i\n"),goodsReport,good_desc[good],goodQuantity) end end if goodCount < 1 then - goodsReport = goodsReport .. _("trade-comms", " Empty\n") + goodsReport = string.format(_("onBoardTrade-comms", "%s Empty\n"),goodsReport) end - goodsReport = goodsReport .. string.format(_("trade-comms", "Available Space: %i, Available Reputation: %i\n"),comms_source.cargo,math.floor(comms_source:getReputationPoints())) + goodsReport = string.format(_("trade-comms", "%sAvailable Space: %i, Available Reputation: %i\n"),goodsReport,comms_source.cargo,math.floor(comms_source:getReputationPoints())) setCommsMessage(goodsReport) - for good, goodData in pairs(ctd.goods) do - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,goodData["cost"]), function() - local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i, Rep: %i"),good,goodData["quantity"],goodData["cost"]) + for good, goodData in pairs(comms_target.comms_data.goods) do + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],goodData["cost"]), function() + local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i, Rep: %i"),good_desc[good],goodData["quantity"],goodData["cost"]) if comms_source.cargo < 1 then - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nInsufficient cargo space for purchase") + goodTransactionMessage = string.format(_("trade-comms", "%s\nInsufficient cargo space for purchase"),goodTransactionMessage) elseif goodData["cost"] > math.floor(comms_source:getReputationPoints()) then - goodTransactionMessage = goodTransactionMessage .. _("needRep-comms", "\nInsufficient reputation for purchase") + goodTransactionMessage = string.format(_("needRep-comms", "%s\nInsufficient reputation for purchase"),goodTransactionMessage) elseif goodData["quantity"] < 1 then - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nInsufficient station inventory") + goodTransactionMessage = string.format(_("trade-comms", "%s\nInsufficient station inventory"),goodTransactionMessage) else if comms_source:takeReputationPoints(goodData["cost"]) then comms_source.cargo = comms_source.cargo - 1 @@ -2561,21 +2681,21 @@ function handleDockedState() comms_source.goods[good] = 0 end comms_source.goods[good] = comms_source.goods[good] + 1 - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\npurchased") + goodTransactionMessage = string.format(_("trade-comms", "%s\npurchased"),goodTransactionMessage) else - goodTransactionMessage = goodTransactionMessage .. _("needRep-comms", "\nInsufficient reputation for purchase") + goodTransactionMessage = string.format(_("needRep-comms", "%s\nInsufficient reputation for purchase"),goodTransactionMessage) end end setCommsMessage(goodTransactionMessage) addCommsReply(_("Back"), commsStation) end) end - if ctd.trade.food ~= nil and ctd.trade.food and comms_source.goods ~= nil and comms_source.goods.food ~= nil and comms_source.goods.food.quantity > 0 then - for good, goodData in pairs(ctd.goods) do - addCommsReply(string.format(_("trade-comms", "Trade food for %s"),good), function() - local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good,goodData["quantity"]) + if comms_target.comms_data.trade.food ~= nil and comms_target.comms_data.trade.food and comms_source.goods ~= nil and comms_source.goods.food ~= nil and comms_source.goods.food.quantity > 0 then + for good, goodData in pairs(comms_target.comms_data.goods) do + addCommsReply(string.format(_("trade-comms", "Trade food for %s"),good_desc[good]), function() + local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good_desc[good],goodData["quantity"]) if goodData["quantity"] < 1 then - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nInsufficient station inventory") + goodTransactionMessage = string.format(_("trade-comms", "%s\nInsufficient station inventory"),goodTransactionMessage) else goodData["quantity"] = goodData["quantity"] - 1 if comms_source.goods == nil then @@ -2586,19 +2706,19 @@ function handleDockedState() end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.goods["food"] = comms_source.goods["food"] - 1 - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nTraded") + goodTransactionMessage = string.format(_("trade-comms", "%s\nTraded"),goodTransactionMessage) end setCommsMessage(goodTransactionMessage) addCommsReply(_("Back"), commsStation) end) end end - if ctd.trade.medicine ~= nil and ctd.trade.medicine and comms_source.goods ~= nil and comms_source.goods.medicine ~= nil and comms_source.goods.medicine.quantity > 0 then - for good, goodData in pairs(ctd.goods) do - addCommsReply(string.format(_("trade-comms", "Trade medicine for %s"),good), function() - local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good,goodData["quantity"]) + if comms_target.comms_data.trade.medicine ~= nil and comms_target.comms_data.trade.medicine and comms_source.goods ~= nil and comms_source.goods.medicine ~= nil and comms_source.goods.medicine.quantity > 0 then + for good, goodData in pairs(comms_target.comms_data.goods) do + addCommsReply(string.format(_("trade-comms", "Trade medicine for %s"),good_desc[good]), function() + local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good_desc[good],goodData["quantity"]) if goodData["quantity"] < 1 then - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nInsufficient station inventory") + goodTransactionMessage = string.format(_("trade-comms", "%s\nInsufficient station inventory"),goodTransactionMessage) else goodData["quantity"] = goodData["quantity"] - 1 if comms_source.goods == nil then @@ -2609,19 +2729,19 @@ function handleDockedState() end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.goods["medicine"] = comms_source.goods["medicine"] - 1 - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nTraded") + goodTransactionMessage = string.format(_("trade-comms", "%s\nTraded"),goodTransactionMessage) end setCommsMessage(goodTransactionMessage) addCommsReply(_("Back"), commsStation) end) end end - if ctd.trade.luxury ~= nil and ctd.trade.luxury and comms_source.goods ~= nil and comms_source.goods.luxury ~= nil and comms_source.goods.luxury.quantity > 0 then - for good, goodData in pairs(ctd.goods) do - addCommsReply(string.format(_("trade-comms", "Trade luxury for %s"),good), function() - local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good,goodData["quantity"]) + if comms_target.comms_data.trade.luxury ~= nil and comms_target.comms_data.trade.luxury and comms_source.goods ~= nil and comms_source.goods.luxury ~= nil and comms_source.goods.luxury.quantity > 0 then + for good, goodData in pairs(comms_target.comms_data.goods) do + addCommsReply(string.format(_("trade-comms", "Trade luxury for %s"),good_desc[good]), function() + local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Quantity: %i"),good_desc[good],goodData["quantity"]) if goodData[quantity] < 1 then - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nInsufficient station inventory") + goodTransactionMessage = string.format(_("trade-comms", "%s\nInsufficient station inventory"),goodTransactionMessage) else goodData["quantity"] = goodData["quantity"] - 1 if comms_source.goods == nil then @@ -2632,22 +2752,21 @@ function handleDockedState() end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.goods["luxury"] = comms_source.goods["luxury"] - 1 - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nTraded") + goodTransactionMessage = string.format(_("trade-comms", "%s\nTraded"),goodTransactionMessage) end setCommsMessage(goodTransactionMessage) addCommsReply(_("Back"), commsStation) end) end end - --[[ - if ctd.buy ~= nil then - for good, price in pairs(ctd.buy) do - if comms_source.goods[good] ~= nil and comms_source.goods[good] > 0 then - addCommsReply(string.format(_("trade-comms", "Sell one %s for %i reputation"),good,price), function() - local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Reputation price: %i"),good,price) + if comms_target.comms_data.buy ~= nil then + for good, price in pairs(comms_target.comms_data.buy) do + if comms_source.goods ~= nil and comms_source.goods[good] ~= nil and comms_source.goods[good] > 0 then + addCommsReply(string.format(_("trade-comms", "Sell one %s for %i reputation"),good_desc[good],price), function() + local goodTransactionMessage = string.format(_("trade-comms", "Type: %s, Reputation price: %i"),good_desc[good],price) comms_source.goods[good] = comms_source.goods[good] - 1 comms_source:addReputationPoints(price) - goodTransactionMessage = goodTransactionMessage .. _("trade-comms", "\nOne sold") + goodTransactionMessage = string.format(_("trade-comms", "%s\nOne sold"),goodTransactionMessage) comms_source.cargo = comms_source.cargo + 1 setCommsMessage(goodTransactionMessage) addCommsReply(_("Back"), commsStation) @@ -2655,7 +2774,31 @@ function handleDockedState() end end end - --]] + local player_good_count = 0 + if comms_source.goods ~= nil then + for good, goodQuantity in pairs(comms_source.goods) do + if goodQuantity > 0 then + player_good_count = player_good_count + 1 + end + end + end + if player_good_count > 0 then + addCommsReply(_("trade-comms", "Jettison cargo"), function() + setCommsMessage(string.format(_("trade-comms", "Available space: %i\nWhat would you like to jettison?"),comms_source.cargo)) + for good, good_quantity in pairs(comms_source.goods) do + if good_quantity > 0 then + addCommsReply(good_desc[good], function() + comms_source.goods[good] = comms_source.goods[good] - 1 + comms_source.cargo = comms_source.cargo + 1 + setCommsMessage(string.format(_("trade-comms", "One %s jettisoned"),good_desc[good])) + addCommsReply(_("Back"), commsStation) + end) + end + end + addCommsReply(_("Back"), commsStation) + end) + end + addCommsReply(_("Back"), commsStation) end) end @@ -3000,14 +3143,14 @@ function handleWeaponRestock(weapon) setCommsMessage(_("station-comms", "You need to stay docked for that action.")) return end - if not isAllowedTo(comms_data.weapons[weapon]) then + if not isAllowedTo(comms_target.comms_data.weapons[weapon]) then if weapon == "Nuke" then setCommsMessage(_("ammo-comms", "We do not deal in weapons of mass destruction.")) elseif weapon == "EMP" then setCommsMessage(_("ammo-comms", "We do not deal in weapons of mass disruption.")) else setCommsMessage(_("ammo-comms", "We do not deal in those weapons.")) end return end local points_per_item = getWeaponCost(weapon) - local item_amount = math.floor(comms_source:getWeaponStorageMax(weapon) * comms_data.max_weapon_refill_amount[getFriendStatus()]) - comms_source:getWeaponStorage(weapon) + local item_amount = math.floor(comms_source:getWeaponStorageMax(weapon) * comms_target.comms_data.max_weapon_refill_amount[getFriendStatus()]) - comms_source:getWeaponStorage(weapon) if item_amount <= 0 then if weapon == "Nuke" then setCommsMessage(_("ammo-comms", "All nukes are charged and primed for destruction.")); @@ -3053,13 +3196,12 @@ function handleWeaponRestock(weapon) end end function getWeaponCost(weapon) - return math.ceil(comms_data.weapon_cost[weapon] * comms_data.reputation_cost_multipliers[getFriendStatus()]) + return math.ceil(comms_target.comms_data.weapon_cost[weapon] * comms_target.comms_data.reputation_cost_multipliers[getFriendStatus()]) end function handleUndockedState() --Handle communications when we are not docked with the station. if stationCommsDiagnostic then print("handleUndockedState") end local player = comms_source - local ctd = comms_target.comms_data if comms_source:isFriendly(comms_target) then oMsg = _("station-comms", "Good day, officer.\nIf you need supplies, please dock with us first.") else @@ -3081,28 +3223,27 @@ function handleUndockedState() addCommsReply(_("station-comms", "I need information"), function() setCommsMessage(_("station-comms", "What kind of information do you need?")) if stationCommsDiagnostic then print("requesting information") end - local ctd = comms_target.comms_data - if stationCommsDiagnostic then print(ctd.character) end - if ctd.character ~= nil then - addCommsReply(string.format(_("characterInfo-comms", "Tell me about %s"),ctd.character), function() - if ctd.characterDescription ~= nil then - setCommsMessage(ctd.characterDescription) + if stationCommsDiagnostic then print(comms_target.comms_data.character) end + if comms_target.comms_data.character ~= nil then + addCommsReply(string.format(_("characterInfo-comms", "Tell me about %s"),comms_target.comms_data.character), function() + if comms_target.comms_data.characterDescription ~= nil then + setCommsMessage(comms_target.comms_data.characterDescription) else - if ctd.characterDeadEnd == nil then + if comms_target.comms_data.characterDeadEnd == nil then local deadEndChoice = math.random(1,5) if deadEndChoice == 1 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "Never heard of %s"), ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "Never heard of %s"), comms_target.comms_data.character) elseif deadEndChoice == 2 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "%s died last week. The funeral was yesterday"), ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "%s died last week. The funeral was yesterday"), comms_target.comms_data.character) elseif deadEndChoice == 3 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "%s? Who's %s? There's nobody here named %s"),ctd.character,ctd.character,ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "%s? Who's %s? There's nobody here named %s"),comms_target.comms_data.character,comms_target.comms_data.character,comms_target.comms_data.character) elseif deadEndChoice == 4 then - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "We don't talk about %s. They are gone and good riddance"),ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "We don't talk about %s. They are gone and good riddance"),comms_target.comms_data.character) else - ctd.characterDeadEnd = string.format(_("characterInfo-comms", "I think %s moved away"),ctd.character) + comms_target.comms_data.characterDeadEnd = string.format(_("characterInfo-comms", "I think %s moved away"),comms_target.comms_data.character) end end - setCommsMessage(ctd.characterDeadEnd) + setCommsMessage(comms_target.comms_data.characterDeadEnd) end addCommsReply(_("Back"), commsStation) end) @@ -3120,26 +3261,25 @@ function handleUndockedState() end) end addCommsReply(_("ammo-comms", "What ordnance do you have available for restock?"), function() - local ctd = comms_target.comms_data local missileTypeAvailableCount = 0 local ordnanceListMsg = "" - if ctd.weapon_available.Nuke then + if comms_target.comms_data.weapon_available.Nuke then missileTypeAvailableCount = missileTypeAvailableCount + 1 ordnanceListMsg = ordnanceListMsg .. _("ammo-comms", "\n Nuke") end - if ctd.weapon_available.EMP then + if comms_target.comms_data.weapon_available.EMP then missileTypeAvailableCount = missileTypeAvailableCount + 1 ordnanceListMsg = ordnanceListMsg .. _("ammo-comms", "\n EMP") end - if ctd.weapon_available.Homing then + if comms_target.comms_data.weapon_available.Homing then missileTypeAvailableCount = missileTypeAvailableCount + 1 ordnanceListMsg = ordnanceListMsg .. _("ammo-comms", "\n Homing") end - if ctd.weapon_available.Mine then + if comms_target.comms_data.weapon_available.Mine then missileTypeAvailableCount = missileTypeAvailableCount + 1 ordnanceListMsg = ordnanceListMsg .. _("ammo-comms", "\n Mine") end - if ctd.weapon_available.HVLI then + if comms_target.comms_data.weapon_available.HVLI then missileTypeAvailableCount = missileTypeAvailableCount + 1 ordnanceListMsg = ordnanceListMsg .. _("ammo-comms", "\n HVLI") end @@ -3154,7 +3294,6 @@ function handleUndockedState() addCommsReply(_("Back"), commsStation) end) addCommsReply(_("stationServices-comms", "Docking services status"), function() - local ctd = comms_target.comms_data local service_status = string.format(_("stationServices-comms", "Station %s docking services status:"),comms_target:getCallSign()) if comms_target:getRestocksScanProbes() then service_status = string.format(_("stationServices-comms", "%s\nReplenish scan probes."),service_status) @@ -3175,7 +3314,7 @@ function handleUndockedState() if comms_target.repair_fail_reason == nil then reason_list = { _("stationServices-comms", "We're out of the necessary materials and supplies for hull repair."), - _("stationServices-comms", "Hull repair automation unavailable whie it is undergoing maintenance."), + _("stationServices-comms", "Hull repair automation unavailable while it is undergoing maintenance."), _("stationServices-comms", "All hull repair technicians quarantined to quarters due to illness."), } comms_target.repair_fail_reason = reason_list[math.random(1,#reason_list)] @@ -3217,8 +3356,8 @@ function handleUndockedState() addCommsReply(_("Back"), commsStation) end) local goodsAvailable = false - if ctd.goods ~= nil then - for good, goodData in pairs(ctd.goods) do + if comms_target.comms_data.goods ~= nil then + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData["quantity"] > 0 then goodsAvailable = true end @@ -3226,10 +3365,9 @@ function handleUndockedState() end if goodsAvailable then addCommsReply(_("trade-comms", "What goods do you have available for sale or trade?"), function() - local ctd = comms_target.comms_data local goodsAvailableMsg = string.format(_("trade-comms", "Station %s:\nGoods or components available: quantity, cost in reputation"),comms_target:getCallSign()) - for good, goodData in pairs(ctd.goods) do - goodsAvailableMsg = goodsAvailableMsg .. string.format(_("trade-comms", "\n %14s: %2i, %3i"),good,goodData["quantity"],goodData["cost"]) + for good, goodData in pairs(comms_target.comms_data.goods) do + goodsAvailableMsg = string.format(_("trade-comms", "%s\n %14s: %2i, %3i"),goodsAvailableMsg,good_desc[good],goodData["quantity"],goodData["cost"]) end setCommsMessage(goodsAvailableMsg) addCommsReply(_("Back"), commsStation) @@ -3240,28 +3378,28 @@ function handleUndockedState() (comms_target.comms_data.history ~= nil and comms_target.comms_data.history ~= "") or (comms_source:isFriendly(comms_target) and comms_target.comms_data.gossip ~= nil and comms_target.comms_data.gossip ~= "" and has_gossip) then addCommsReply(_("station-comms", "Tell me more about your station"), function() - local ctd = comms_target.comms_data setCommsMessage(_("station-comms", "What would you like to know?")) if comms_target.comms_data.general ~= nil and comms_target.comms_data.general ~= "" then addCommsReply(_("stationGeneralInfo-comms", "General information"), function() - setCommsMessage(ctd.general) + setCommsMessage(comms_target.comms_data.general) addCommsReply(_("Back"), commsStation) end) end - if ctd.history ~= nil and ctd.history ~= "" then + if comms_target.comms_data.history ~= nil and comms_target.comms_data.history ~= "" then addCommsReply(_("stationStory-comms", "Station history"), function() - setCommsMessage(ctd.history) + setCommsMessage(comms_target.comms_data.history) addCommsReply(_("Back"), commsStation) end) end - if ctd.gossip ~= nil then + if comms_target.comms_data.gossip ~= nil then if random(1,100) < 80 then addCommsReply(_("gossip-comms", "Gossip"), function() - setCommsMessage(ctd.gossip) + setCommsMessage(comms_target.comms_data.gossip) addCommsReply(_("Back"), commsStation) end) end end + addCommsReply(_("Back"), commsStation) end) --end station info comms reply branch end --end public relations if branch addCommsReply(_("stationAssist-comms", "Report status"), function() @@ -3277,6 +3415,7 @@ function handleUndockedState() setCommsMessage(msg); addCommsReply(_("Back"), commsStation) end) + addCommsReply(_("Back"), commsStation) end) if isAllowedTo(comms_target.comms_data.services.supplydrop) then addCommsReply(string.format(_("stationAssist-comms", "Can you send a supply drop? (%d rep)"), getServiceCost("supplydrop")), function() @@ -3369,7 +3508,7 @@ function handleUndockedState() end function getServiceCost(service) -- Return the number of reputation points that a specified service costs for the current player. - return math.ceil(comms_data.service_cost[service]) + return math.ceil(comms_target.comms_data.service_cost[service]) end function getFriendStatus() if comms_source:isFriendly(comms_target) then @@ -3385,17 +3524,16 @@ function commsShip() if comms_target.comms_data == nil then comms_target.comms_data = {friendlyness = random(0.0, 100.0)} end - comms_data = comms_target.comms_data - if comms_data.goods == nil then - comms_data.goods = {} - comms_data.goods[commonGoods[math.random(1,#commonGoods)]] = {quantity = 1, cost = random(20,80)} + if comms_target.comms_data.goods == nil then + comms_target.comms_data.goods = {} + comms_target.comms_data.goods[commonGoods[math.random(1,#commonGoods)]] = {quantity = 1, cost = random(20,80)} local shipType = comms_target:getTypeName() if shipType:find("Freighter") ~= nil then if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then repeat - comms_data.goods[commonGoods[math.random(1,#commonGoods)]] = {quantity = 1, cost = random(20,80)} + comms_target.comms_data.goods[commonGoods[math.random(1,#commonGoods)]] = {quantity = 1, cost = random(20,80)} local goodCount = 0 - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do goodCount = goodCount + 1 end until(goodCount >= 3) @@ -3404,15 +3542,15 @@ function commsShip() end setPlayer() if comms_source:isFriendly(comms_target) then - return friendlyComms(comms_data) + return friendlyComms() end if comms_source:isEnemy(comms_target) and comms_target:isFriendOrFoeIdentifiedBy(comms_source) then - return enemyComms(comms_data) + return enemyComms() end - return neutralComms(comms_data) + return neutralComms() end -function friendlyComms(comms_data) - if comms_data.friendlyness < 20 then +function friendlyComms() + if comms_target.comms_data.friendlyness < 20 then setCommsMessage(_("shipAssist-comms", "What do you want?")); else setCommsMessage(_("shipAssist-comms", "Sir, how can we assist?")); @@ -3420,7 +3558,7 @@ function friendlyComms(comms_data) local nearby_enemy_ships = {} local obj_list = comms_target:getObjectsInRange(6000) for i,obj in ipairs(obj_list) do - if obj.components.ai_controller then + if isObjectType(obj,"CpuShip") then if obj:isEnemy(comms_target) then local ship = {ship = ship, name = obj:getCallSign()} if obj:isFullyScannedBy(comms_source) then @@ -3487,7 +3625,7 @@ function friendlyComms(comms_data) end end end) - if comms_data.friendlyness > 0.2 then + if comms_target.comms_data.friendlyness > 0.2 then addCommsReply(_("shipAssist-comms", "Assist me"), function() setCommsMessage(_("shipAssist-comms", "Heading toward you to assist.")); comms_target:orderDefendTarget(comms_source) @@ -3518,7 +3656,7 @@ function friendlyComms(comms_data) addCommsReply(_("Back"), commsShip) end) for i, obj in ipairs(comms_target:getObjectsInRange(5000)) do - if obj.typeName == "SpaceStation" and not comms_target:isEnemy(obj) then + if isObjectType(obj,"SpaceStation") and not comms_target:isEnemy(obj) then addCommsReply(string.format(_("shipAssist-comms", "Dock at %s"), obj:getCallSign()), function() setCommsMessage(string.format(_("shipAssist-comms", "Docking at %s."), obj:getCallSign())); comms_target:orderDock(obj) @@ -3610,17 +3748,17 @@ function friendlyComms(comms_data) if shipCommsDiagnostic then print("it's a freighter") end if distance(comms_source, comms_target) < 5000 then if shipCommsDiagnostic then print("close enough to trade or sell") end - if comms_data.friendlyness > 66 then + if comms_target.comms_data.friendlyness > 66 then if shipCommsDiagnostic then print("friendliest branch") end if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then if shipCommsDiagnostic then print("goods or equipment freighter") end if comms_source.goods ~= nil and comms_source.goods.luxury ~= nil and comms_source.goods.luxury > 0 then if shipCommsDiagnostic then print("player has luxury to trade") end - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if shipCommsDiagnostic then print("in freighter goods loop") end if goodData.quantity > 0 and good ~= "luxury" then if shipCommsDiagnostic then print("has something other than luxury") end - addCommsReply(string.format(_("trade-comms", "Trade luxury for %s"),good), function() + addCommsReply(string.format(_("trade-comms", "Trade luxury for %s"),good_desc[good]), function() goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then comms_source.goods = {} @@ -3630,7 +3768,7 @@ function friendlyComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.goods.luxury = comms_source.goods.luxury - 1 - setCommsMessage(string.format(_("trade-comms", "Traded your luxury for %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Traded your luxury for %s from %s"),good_desc[good],comms_target:getCallSign())) addCommsReply(_("Back"), commsShip) end) end @@ -3639,11 +3777,11 @@ function friendlyComms(comms_data) end --goods or equipment freighter if comms_source.cargo > 0 then if shipCommsDiagnostic then print("player has room to purchase") end - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if shipCommsDiagnostic then print("in freighter goods loop") end if goodData.quantity > 0 then if shipCommsDiagnostic then print("found something to sell") end - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost)), function() if comms_source:takeReputationPoints(goodData.cost) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3654,7 +3792,7 @@ function friendlyComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3663,17 +3801,17 @@ function friendlyComms(comms_data) end end --freighter goods loop end --player has cargo space branch - elseif comms_data.friendlyness > 33 then + elseif comms_target.comms_data.friendlyness > 33 then if shipCommsDiagnostic then print("average frienliness branch") end if comms_source.cargo > 0 then if shipCommsDiagnostic then print("player has room to purchase") end if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then if shipCommsDiagnostic then print("goods or equipment type freighter") end - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if shipCommsDiagnostic then print("in freighter cargo loop") end if goodData.quantity > 0 then if shipCommsDiagnostic then print("Found something to sell") end - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost)), function() if comms_source:takeReputationPoints(goodData.cost) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3684,7 +3822,7 @@ function friendlyComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3694,11 +3832,11 @@ function friendlyComms(comms_data) end --freighter goods loop else --not goods or equipment freighter if shipCommsDiagnostic then print("not a goods or equipment freighter") end - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if shipCommsDiagnostic then print("in freighter cargo loop") end if goodData.quantity > 0 then if shipCommsDiagnostic then print("found something to sell") end - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*2)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*2)), function() if comms_source:takeReputationPoints(goodData.cost*2) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3709,7 +3847,7 @@ function friendlyComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3725,11 +3863,11 @@ function friendlyComms(comms_data) if shipCommsDiagnostic then print("player has room for purchase") end if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then if shipCommsDiagnostic then print("goods or equipment freighter") end - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if shipCommsDiagnostic then print("in freighter cargo loop") end if goodData.quantity > 0 then if shipCommsDiagnostic then print("found something to sell") end - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*2)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*2)), function() if comms_source:takeReputationPoints(goodData.cost*2) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3740,7 +3878,7 @@ function friendlyComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3755,18 +3893,18 @@ function friendlyComms(comms_data) addCommsReply(_("trade-comms", "Do you have cargo you might sell?"), function() local goodCount = 0 local cargoMsg = _("trade-comms", "We've got ") - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then if goodCount > 0 then - cargoMsg = cargoMsg .. _("trade-comms", ", ") .. good + cargoMsg = string.format(_("trade-comms", "%s, %s"),cargoMsg,good_desc[good]) else - cargoMsg = cargoMsg .. good + cargoMsg = string.format(_("trade-comms","%s%s"),cargoMsg,good_desc[good]) end end goodCount = goodCount + goodData.quantity end if goodCount == 0 then - cargoMsg = cargoMsg .. _("trade-comms", "nothing") + cargoMsg = string.format(_("trade-comms", "%snothing"),cargoMsg) end setCommsMessage(cargoMsg) addCommsReply(_("Back"), commsShip) @@ -3775,8 +3913,8 @@ function friendlyComms(comms_data) end return true end -function enemyComms(comms_data) - if comms_data.friendlyness > 50 then +function enemyComms() + if comms_target.comms_data.friendlyness > 50 then local faction = comms_target:getFaction() local taunt_option = _("shipEnemy-comms", "We will see to your destruction!") local taunt_success_reply = _("shipEnemy-comms", "Your bloodline will end here!") @@ -3813,7 +3951,7 @@ function enemyComms(comms_data) else setCommsMessage(_("shipEnemy-comms", "Mind your own business!")); end - comms_data.friendlyness = comms_data.friendlyness - random(0, 10) + comms_target.comms_data.friendlyness = comms_target.comms_data.friendlyness - random(0, 10) addCommsReply(taunt_option, function() if random(0, 100) < 30 then comms_target:orderAttack(comms_source) @@ -3826,35 +3964,35 @@ function enemyComms(comms_data) end return false end -function neutralComms(comms_data) +function neutralComms() local shipType = comms_target:getTypeName() if shipType:find("Freighter") ~= nil then setCommsMessage(_("trade-comms", "Yes?")) addCommsReply(_("trade-comms", "Do you have cargo you might sell?"), function() local goodCount = 0 local cargoMsg = _("trade-comms", "We've got ") - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then if goodCount > 0 then - cargoMsg = cargoMsg .. _("trade-comms", ", ") .. good + cargoMsg = string.format(_("trade-comms", "%s, %s"),cargoMsg,good_desc[good]) else - cargoMsg = cargoMsg .. good + cargoMsg = string.format(_("trade-comms","%s%s"),cargoMsg,good_desc[good]) end end goodCount = goodCount + goodData.quantity end if goodCount == 0 then - cargoMsg = cargoMsg .. _("trade-comms", "nothing") + cargoMsg = string.format(_("trade-comms", "%snothing"),cargoMsg) end setCommsMessage(cargoMsg) end) if distance(comms_source,comms_target) < 5000 then if comms_source.cargo > 0 then - if comms_data.friendlyness > 66 then + if comms_target.comms_data.friendlyness > 66 then if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost)), function() if comms_source:takeReputationPoints(goodData.cost) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3865,7 +4003,7 @@ function neutralComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3874,9 +4012,9 @@ function neutralComms(comms_data) end end --freighter goods loop else - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*2)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*2)), function() if comms_source:takeReputationPoints(goodData.cost*2) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3887,7 +4025,7 @@ function neutralComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3896,11 +4034,11 @@ function neutralComms(comms_data) end end --freighter goods loop end - elseif comms_data.friendlyness > 33 then + elseif comms_target.comms_data.friendlyness > 33 then if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*2)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*2)), function() if comms_source:takeReputationPoints(goodData.cost*2) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3911,7 +4049,7 @@ function neutralComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3920,9 +4058,9 @@ function neutralComms(comms_data) end end --freighter goods loop else - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*3)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*3)), function() if comms_source:takeReputationPoints(goodData.cost*3) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3933,7 +4071,7 @@ function neutralComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3944,9 +4082,9 @@ function neutralComms(comms_data) end else --least friendly if shipType:find("Goods") ~= nil or shipType:find("Equipment") ~= nil then - for good, goodData in pairs(comms_data.goods) do + for good, goodData in pairs(comms_target.comms_data.goods) do if goodData.quantity > 0 then - addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good,math.floor(goodData.cost*3)), function() + addCommsReply(string.format(_("trade-comms", "Buy one %s for %i reputation"),good_desc[good],math.floor(goodData.cost*3)), function() if comms_source:takeReputationPoints(goodData.cost*3) then goodData.quantity = goodData.quantity - 1 if comms_source.goods == nil then @@ -3957,7 +4095,7 @@ function neutralComms(comms_data) end comms_source.goods[good] = comms_source.goods[good] + 1 comms_source.cargo = comms_source.cargo - 1 - setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good,comms_target:getCallSign())) + setCommsMessage(string.format(_("trade-comms", "Purchased %s from %s"),good_desc[good],comms_target:getCallSign())) else setCommsMessage(_("needRep-comms", "Insufficient reputation for purchase")) end @@ -3970,7 +4108,7 @@ function neutralComms(comms_data) end --player has room for cargo end --close enough to sell else --not a freighter - if comms_data.friendlyness > 50 then + if comms_target.comms_data.friendlyness > 50 then setCommsMessage(_("ship-comms", "Sorry, we have no time to chat with you.\nWe are on an important mission.")); else setCommsMessage(_("ship-comms", "We have nothing for you.\nGood day.")); @@ -3982,14 +4120,13 @@ end --end neutral communications function function addForwardBeam() if comms_source.add_forward_beam == nil then addCommsReply(_("upgrade-comms", "Add beam weapon"), function() - local ctd = comms_target.comms_data local part_quantity = 0 - if comms_source.goods ~= nil and comms_source.goods[ctd.characterGood] ~= nil and comms_source.goods[ctd.characterGood] > 0 then - part_quantity = comms_source.goods[ctd.characterGood] + if comms_source.goods ~= nil and comms_source.goods[comms_target.comms_data.characterGood] ~= nil and comms_source.goods[comms_target.comms_data.characterGood] > 0 then + part_quantity = comms_source.goods[comms_target.comms_data.characterGood] end if part_quantity > 0 then comms_source.add_forward_beam = "done" - comms_source.goods[ctd.characterGood] = comms_source.goods[ctd.characterGood] - 1 + comms_source.goods[comms_target.comms_data.characterGood] = comms_source.goods[comms_target.comms_data.characterGood] - 1 comms_source.cargo = comms_source.cargo + 1 local beam_index = 0 repeat @@ -3998,7 +4135,7 @@ function addForwardBeam() comms_source:setBeamWeapon(beam_index,20,0,1200,6,5) setCommsMessage(_("upgrade-comms", "A beam wepon has been added to your ship")) else - setCommsMessage(string.format(_("upgrade-comms", "%s cannot add a beam weapon to your ship unless you provide %s"),ctd.character,ctd.characterGood)) + setCommsMessage(string.format(_("upgrade-comms", "%s cannot add a beam weapon to your ship unless you provide %s"),comms_target.comms_data.character,good_desc[comms_target.comms_data.characterGood])) end addCommsReply(_("Back"), commsStation) end) @@ -4007,25 +4144,24 @@ end function efficientBatteries() if comms_source.efficientBatteriesUpgrade == nil then addCommsReply(_("upgrade-comms", "Increase battery efficiency"), function() - local ctd = comms_target.comms_data local partQuantity = 0 local partQuantity2 = 0 - if comms_source.goods ~= nil and comms_source.goods[ctd.characterGood] ~= nil and comms_source.goods[ctd.characterGood] > 0 then - partQuantity = comms_source.goods[ctd.characterGood] + if comms_source.goods ~= nil and comms_source.goods[comms_target.comms_data.characterGood] ~= nil and comms_source.goods[comms_target.comms_data.characterGood] > 0 then + partQuantity = comms_source.goods[comms_target.comms_data.characterGood] end - if comms_source.goods ~= nil and comms_source.goods[ctd.characterGood2] ~= nil and comms_source.goods[ctd.characterGood2] > 0 then - partQuantity2 = comms_source.goods[ctd.characterGood2] + if comms_source.goods ~= nil and comms_source.goods[comms_target.comms_data.characterGood2] ~= nil and comms_source.goods[comms_target.comms_data.characterGood2] > 0 then + partQuantity2 = comms_source.goods[comms_target.comms_data.characterGood2] end if partQuantity > 0 and partQuantity2 > 0 then comms_source.efficientBatteriesUpgrade = "done" - comms_source.goods[ctd.characterGood] = comms_source.goods[ctd.characterGood] - 1 - comms_source.goods[ctd.characterGood2] = comms_source.goods[ctd.characterGood2] - 1 + comms_source.goods[comms_target.comms_data.characterGood] = comms_source.goods[comms_target.comms_data.characterGood] - 1 + comms_source.goods[comms_target.comms_data.characterGood2] = comms_source.goods[comms_target.comms_data.characterGood2] - 1 comms_source.cargo = comms_source.cargo + 2 comms_source:setMaxEnergy(comms_source:getMaxEnergy()*1.5) comms_source:setEnergy(comms_source:getMaxEnergy()) - setCommsMessage(string.format(_("upgrade-comms", "%s: I appreciate the %s and %s. You have a 50%% greater energy capacity due to increased battery efficiency"),ctd.character,ctd.characterGood,ctd.characterGood2)) + setCommsMessage(string.format(_("upgrade-comms", "%s: I appreciate the %s and %s. You have a 50%% greater energy capacity due to increased battery efficiency"),comms_target.comms_data.character,good_desc[comms_target.comms_data.characterGood],good_desc[comms_target.comms_data.characterGood2])) else - setCommsMessage(string.format(_("upgrade-comms", "%s: You need to bring me some %s and %s before I can increase your battery efficiency"),ctd.character,ctd.characterGood,ctd.characterGood2)) + setCommsMessage(string.format(_("upgrade-comms", "%s: You need to bring me some %s and %s before I can increase your battery efficiency"),comms_target.comms_data.character,good_desc[comms_target.comms_data.characterGood],good_desc[comms_target.comms_data.characterGood2])) end addCommsReply(_("Back"), commsStation) end) @@ -4034,28 +4170,27 @@ end function shrinkBeamCycle() if comms_source.shrinkBeamCycleUpgrade == nil then addCommsReply(_("upgrade-comms", "Reduce beam cycle time"), function() - local ctd = comms_target.comms_data if comms_source:getBeamWeaponRange(0) > 0 then if payForUpgrade() then local partQuantity = 0 - if comms_source.goods ~= nil and comms_source.goods[ctd.characterGood] ~= nil and comms_source.goods[ctd.characterGood] > 0 then - partQuantity = comms_source.goods[ctd.characterGood] + if comms_source.goods ~= nil and comms_source.goods[comms_target.comms_data.characterGood] ~= nil and comms_source.goods[comms_target.comms_data.characterGood] > 0 then + partQuantity = comms_source.goods[comms_target.comms_data.characterGood] end if partQuantity > 0 then comms_source.shrinkBeamCycleUpgrade = "done" - comms_source.goods[ctd.characterGood] = comms_source.goods[ctd.characterGood] - 1 + comms_source.goods[comms_target.comms_data.characterGood] = comms_source.goods[comms_target.comms_data.characterGood] - 1 comms_source.cargo = comms_source.cargo + 1 beamUpgrade(nil,true) -- beamUpgrade(damage,cycle_time,power_use,heat_generated,artifact_scanned) setCommsMessage(_("upgrade-comms", "After accepting your gift, he reduced your Beam cycle time.")) else - setCommsMessage(string.format(_("upgrade-comms", "%s requires %s for the upgrade"),ctd.character,ctd.characterGood)) + setCommsMessage(string.format(_("upgrade-comms", "%s requires %s for the upgrade"),comms_target.comms_data.character,good_desc[comms_target.comms_data.characterGood])) end else comms_source.shrinkBeamCycleUpgrade = "done" beamUpgrade(nil,true) -- beamUpgrade(damage,cycle_time,power_use,heat_generated,artifact_scanned) - setCommsMessage(string.format(_("upgrade-comms", "%s reduced your Beam cycle time at no cost in trade with the message, 'Go get those Kraylors.'"),ctd.character)) + setCommsMessage(string.format(_("upgrade-comms", "%s reduced your Beam cycle time at no cost in trade with the message, 'Go get those Kraylors.'"),comms_target.comms_data.character)) end else setCommsMessage(_("upgrade-comms", "Your ship type does not support a beam weapon upgrade.")) @@ -4492,7 +4627,7 @@ function exuariHarassment(delta) local evaluate_objects = enemy:getObjectsInRange(7500) local enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4505,7 +4640,7 @@ function exuariHarassment(delta) evaluate_objects = enemy:getObjectsInRange(5000) enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4521,7 +4656,7 @@ function exuariHarassment(delta) evaluate_objects = enemy:getObjectsInRange(7500) enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4603,7 +4738,7 @@ function exuariHarassment(delta) evaluate_objects = enemy:getObjectsInRange(7500) enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4616,7 +4751,7 @@ function exuariHarassment(delta) evaluate_objects = enemy:getObjectsInRange(5000) enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4632,7 +4767,7 @@ function exuariHarassment(delta) evaluate_objects = enemy:getObjectsInRange(7500) enemy_in_range = false for j, obj in pairs(evaluate_objects) do - if obj.components.player_control ~= nil then + if isObjectType(obj,"PlayerSpaceship") then if obj:getFactionId() ~= enemy:getFactionId() then enemy_in_range = true break @@ -4935,7 +5070,7 @@ function kraylorDiversionarySabotage(delta) local enemy_close_to_supply = 0 local obj_list = supply_depot_station:getObjectsInRadius(target_x, target_y, 7500) for i,obj in ipairs(obj_list) do - if obj.components.ai_controller then + if isObjectType(obj,"CpuShip") then if obj:getFaction() == "Kraylor" then enemy_close_to_supply = enemy_close_to_supply + 1 if distance(ship,supply_depot_station) < 1500 then @@ -5100,7 +5235,7 @@ function kraylorPlanetBuster(delta) local enemy_close_to_planet_count = 0 local obj_list = target_planet:getObjectsInRadius(target_x, target_y, 1500 + target_planet_radius) for i,obj in ipairs(obj_list) do - if obj.components.ai_controller then + if isObjectType(obj,"CpuShip") then if obj:getFaction() == "Kraylor" then enemy_close_to_planet_count = enemy_close_to_planet_count + 1 end @@ -5496,13 +5631,13 @@ function explodingPlanetDebris() for i,ej in ipairs(ejecta) do local obj = ej.obj if ej.action == "dissipate" then - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:explode() else obj:destroy() end else - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:onCollision(function(self,collider) string.format("") collider:takeDamage(100) @@ -5540,10 +5675,10 @@ function explodingPlanetDebris() end local obj = ejecta_kind() obj:setPosition(exploding_planet_x,exploding_planet_y) - if obj.typeName == "Asteroid" or obj.typeName == "VisualAsteroid" then + if isObjectType(obj,"Asteroid") or isObjectType(obj,"VisualAsteroid") then obj:setSize(random(5,50) + random(5,50) + random(5,200)) end - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:setRadarTraceColor(math.random(1,255),math.random(1,255),math.random(1,255)) if unscanned_descriptions == nil or #unscanned_descriptions == 0 then unscanned_descriptions = { @@ -5579,7 +5714,7 @@ function explodingPlanetDebris() ej.iterations = ej.iterations - 1 if ej.iterations <= 0 then if ej.action == "dissipate" then - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:explode() else obj:destroy() @@ -5587,7 +5722,7 @@ function explodingPlanetDebris() ej.obj = nil ej.del = true elseif ej.action == "stop" then - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:onCollision(function(self,collider) string.format("") collider:takeDamage(100) From 186c59926ccdb95b3adb2fe8e4289eb32839f39b Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Thu, 17 Apr 2025 09:08:54 -0500 Subject: [PATCH 2/2] Rely on function in utils.lua in #2331 --- scripts/scenario_47_scavenger.lua | 72 ------------------------------- 1 file changed, 72 deletions(-) diff --git a/scripts/scenario_47_scavenger.lua b/scripts/scenario_47_scavenger.lua index d27e24574e..d8a84a2c35 100644 --- a/scripts/scenario_47_scavenger.lua +++ b/scripts/scenario_47_scavenger.lua @@ -26,10 +26,6 @@ function init() if _VERSION ~= nil then print("Lua version:",_VERSION) end - ECS = false - if createEntity then - ECS = true - end stationCommsDiagnostic = false exuari_harass_diagnostic = false spawn_enemy_diagnostic = false @@ -193,74 +189,6 @@ function init() -- print("end of init") allowNewPlayerShips(false) end -function isObjectType(obj,typ,qualifier) - if obj ~= nil and obj:isValid() then - if typ ~= nil then - if ECS then - if typ == "SpaceStation" then - return obj.components.docking_bay and obj.components.physics and obj.components.physics.type == "static" - elseif typ == "PlayerSpaceship" then - return obj.components.player_control - elseif typ == "ScanProbe" then - return obj.components.allow_radar_link - elseif typ == "CpuShip" then - return obj.ai_controller - elseif typ == "Asteroid" then - return obj.components.mesh_render and string.sub(obj.components.mesh_render.mesh, 7) == "Astroid" - elseif typ == "Nebula" then - return obj.components.nebula_renderer - elseif typ == "Planet" then - return obj.components.planet_render - elseif typ == "SupplyDrop" then - return obj.components.pickup and obj.components.radar_trace.icon == "radar/blip.png" and obj.components.radar_trace.color_by_faction - elseif typ == "BlackHole" then - return obj.components.gravity and obj.components.billboard_render.texture == "blackHole3d.png" - elseif typ == "WarpJammer" then - return obj.components.warp_jammer - elseif typ == "Mine" then - return obj.components.delayed_explode_on_touch and obj.components.constant_particle_emitter - elseif typ == "EMPMissile" then - return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explode_on_touch.damage_type == "emp" - elseif typ == "Nuke" then - return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explosion_sfx == "sfx/nuke_explosion.wav" - elseif typ == "Zone" then - return obj.components.zone - else - if qualifier == "MovingMissile" then - if typ == "HomingMissile" or typ == "HVLI" or typ == "Nuke" or typ == "EMPMissile" then - return obj.components.radar_trace.icon == "radar/missile.png" - else - return false - end - elseif qualifier == "SplashMissile" then - if typ == "Nuke" or typ == "EMPMissile" then - if obj.components.radar_trace.icon == "radar/missile.png" then - if typ == "Nuke" then - return obj.components.explosion_sfx == "sfx/nuke_explosion.wav" - else --EMP - return obj.components.explode_on_touch.damage_type == "emp" - end - else - return false - end - else - return false - end - else - return false - end - end - else - return obj.typeName == typ - end - else - return false - end - else - return false - end -end - -- Initialization function setVariations() local enemy_config = {