From eb1953485e4e377df53f43d83e88f0bdb72053ec Mon Sep 17 00:00:00 2001 From: Pithlit Date: Mon, 2 Sep 2024 18:54:42 +0200 Subject: [PATCH] scenario wormhole: lots of fixes on comms code --- scripts-piglit/border_defend_station.lua | 4 +- scripts-piglit/comms_station_sandbox.lua | 93 +++++++++++-------- scripts-piglit/plots/wh_kraylor.lua | 12 +-- scripts-piglit/plots/wh_stations.lua | 18 ++-- scripts-piglit/plots/wh_turns.lua | 4 +- .../scenario_99_wormhole_expedition.lua | 2 + scripts-piglit/script_formation.lua | 4 +- scripts-piglit/xansta_mods.lua | 5 + 8 files changed, 80 insertions(+), 62 deletions(-) diff --git a/scripts-piglit/border_defend_station.lua b/scripts-piglit/border_defend_station.lua index 66f72f6e65..8d5fef99eb 100755 --- a/scripts-piglit/border_defend_station.lua +++ b/scripts-piglit/border_defend_station.lua @@ -87,7 +87,9 @@ function update(delta) end else if my_station:areEnemiesInRange(10000) then - my_ship:orderDefendTarget(my_station) + if my_ship:getOrder() ~= "Defend Target" then + my_ship:orderDefendTarget(my_station) + end else if not ship_healthy then my_ship:orderDock(my_station) diff --git a/scripts-piglit/comms_station_sandbox.lua b/scripts-piglit/comms_station_sandbox.lua index 6da8dc2b9b..261cf8d931 100644 --- a/scripts-piglit/comms_station_sandbox.lua +++ b/scripts-piglit/comms_station_sandbox.lua @@ -2,7 +2,14 @@ require "utils.lua" require "luax.lua" + require "xansta_mods.lua" +init_constants_xansta() + +require("serpent.lua") +function table.dump(...) + print(serpent.block(...)) +end local system_list = {"reactor","beamweapons","missilesystem","maneuver","impulse","warp","jumpdrive","frontshield","rearshield"} @@ -150,11 +157,14 @@ function commsStation(comms_source, comms_target) If it returns nil, the next function will be called. If it returns a string, the next function will be called with that string as oMsg. --]] - docked_comms_functions = {addStationToDatabase, commsPanic, dockedGreeting, androidDockedStationComms, dockedLightPanic}, - undocked_comms_functions = {commsPanic, undockedGreeting, androidUndockedStationComms, undockedLightPanic}, - enemy_comms_functions = {intimidateStationComms}, + panic_range = getPanicRange(comms_target) }) + -- FIXME: issue - if this is defined in comms data, the functions get deleted when the script gets deleted, but the reference remains. + -- if it is defined like below, noone can add a function + comms_target.comms_data.docked_comms_functions = {addStationToDatabase, commsPanic, dockedGreeting, androidDockedStationComms, dockedLightPanic} + comms_target.comms_data.undocked_comms_functions = {commsPanic, undockedGreeting, androidUndockedStationComms, undockedLightPanic} + comms_target.comms_data.enemy_comms_functions = {intimidateStationComms} comms_data = comms_target.comms_data -- enemy stations @@ -594,8 +604,8 @@ function stationDefenseFleet(calling_function) script:setVariable("station_name",station_name) script:setVariable("name",name) script:setVariable("template",template) - script:setVariable("faction_id",comms_target:getFactionId()) - script:run("border_defend_station.lua") -- TODO test; espec. comms function! + script:setVariable("faction_id",comms_source:getFactionId()) + script:run("border_defend_station.lua") comms_target.comms_data.idle_defense_fleet[name] = nil end local launched_responses = { @@ -712,7 +722,8 @@ function undockedLightPanic(comms_source, comms_target, oMsg) end end - oMsg = string.format("(DEBUG: friendlyness: %f)\n%s", comms_target.comms_data.friendlyness, oMsg) -- TODO remove (debug) +-- oMsg = string.format("(DEBUG: friendlyness: %f)\n%s", comms_target.comms_data.friendlyness, oMsg) -- TODO remove (debug) +-- table.dump(comms_target.comms_data)-- TODO remove (debug) setCommsMessage(oMsg) if interactive then addCommsReply("Interact with station relay officer on duty",interactiveUndockedStationCommsMeat) @@ -720,10 +731,12 @@ function undockedLightPanic(comms_source, comms_target, oMsg) end function androidUndockedStationComms() + print("in androidUndockedStationComms") addCommsReply(_("station-comms","Automated station communication"),androidUndockedStationCommsMeat) end function androidUndockedStationCommsMeat() + print("in androidUndockedStationCommsMeat") setCommsMessage(_("station-comms","Select:")) stationStatusReport({identifier=androidUndockedStationCommsMeat,name="automated station communication"}) if isAllowedTo(comms_target.comms_data.services.activatedefensefleet) then @@ -923,7 +936,7 @@ function improveStationService(improvements) print("Unable to show improvements. Improvement value:",improvement) else addCommsReply(tableSelectRandom(improvement_prompt[improvement]),function() - local needed_good = comms_target.mission_good[improvement] + local needed_good = comms_target.mission_goods[improvement] setCommsMessage(string.format(_("situationReport-comms","%s could be improved with %s. You may be able to get %s from stations or transports."),tableSelectRandom(improvement_prompt[improvement]),needed_good,needed_good)) if comms_source.goods ~= nil then if comms_source.goods[needed_good] ~= nil and comms_source.goods[needed_good] > 0 and comms_source:isDocked(comms_target) then @@ -1167,7 +1180,7 @@ function requestSupplyDrop(calling_function) local script = Script() script:setVariable("position_x", position_x):setVariable("position_y", position_y) script:setVariable("target_x", target_x):setVariable("target_y", target_y) - script:setVariable("faction_id", comms_target:getFactionId()):run("supply_drop.lua") + script:setVariable("faction_id", comms_source:getFactionId()):run("supply_drop.lua") local supply_ship_en_route = { string.format("We have dispatched a supply ship toward waypoint %d",n), string.format("We sent a supply ship to waypoint %i",n), @@ -1224,7 +1237,7 @@ function requestSupplyDrop(calling_function) script:setVariable("position_x", position_x):setVariable("position_y", position_y) script:setVariable("target_x", target_x):setVariable("target_y", target_y) script:setVariable("jump_freighter","yes") - script:setVariable("faction_id", comms_target:getFactionId()):run("supply_drop.lua") + script:setVariable("faction_id", comms_source:getFactionId()):run("supply_drop.lua") local supply_ship_en_route = { string.format("We have dispatched a supply ship toward waypoint %d",n), string.format("We sent a supply ship to waypoint %i",n), @@ -1290,7 +1303,6 @@ function requestSupplyDrop(calling_function) for n=1,comms_source:getWaypointCount() do addCommsReply(string.format(_("stationAssist-comms","Waypoint %i"),n), function() if comms_source:takeReputationPoints(getServiceCost("flingsupplydrop")) then - -- TODO local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) @@ -1340,7 +1352,7 @@ function requestSupplyDrop(calling_function) local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) - local landing_x, landing_y = vectorFromAngleNorth(target_angle,flinger_miss) + local landing_x, landing_y = vectorFromAngle(target_angle,flinger_miss) local sd = SupplyDrop():setFactionId(comms_target:getFactionId()):setPosition(target_x + landing_x, target_y + landing_y):setEnergy(500):setWeaponStorage("HVLI",5):setWeaponStorage("Nuke", 1):setWeaponStorage("Homing", 4):setWeaponStorage("Mine", 2):setWeaponStorage("EMP", 1) local supply_location = { string.format("Supplies delivered %.1f units from waypoint, bearing %.1f.",flinger_miss/1000,target_angle), @@ -1386,7 +1398,7 @@ function requestSupplyDrop(calling_function) local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) - local landing_x, landing_y = vectorFromAngleNorth(target_angle,flinger_miss) + local landing_x, landing_y = vectorFromAngle(target_angle,flinger_miss) local sd = SupplyDrop():setFactionId(comms_target:getFactionId()):setPosition(target_x + landing_x, target_y + landing_y):setEnergy(500):setWeaponStorage("Nuke", 1):setWeaponStorage("Homing", 4):setWeaponStorage("Mine", 2):setWeaponStorage("EMP", 1) sd:onPickUp(function(self,player) string.format("") @@ -1436,7 +1448,7 @@ function requestSupplyDrop(calling_function) local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) - local landing_x, landing_y = vectorFromAngleNorth(target_angle,flinger_miss) + local landing_x, landing_y = vectorFromAngle(target_angle,flinger_miss) local sd = SupplyDrop():setFactionId(comms_target:getFactionId()):setPosition(target_x + landing_x, target_y + landing_y):setEnergy(500):setWeaponStorage("Nuke", 1):setWeaponStorage("Homing", 4):setWeaponStorage("Mine", 2):setWeaponStorage("EMP", 1) sd:onPickUp(function(self,player) string.format("") @@ -1518,7 +1530,7 @@ function requestSupplyDrop(calling_function) local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) - local landing_x, landing_y = vectorFromAngleNorth(target_angle,flinger_miss) + local landing_x, landing_y = vectorFromAngle(target_angle,flinger_miss) local sd = SupplyDrop():setFactionId(comms_target:getFactionId()):setPosition(target_x + landing_x, target_y + landing_y):setEnergy(500):setWeaponStorage("Nuke", 1):setWeaponStorage("Homing", 4):setWeaponStorage("Mine", 2):setWeaponStorage("EMP", 1) comms_target.comms_data.available_repair_crew = comms_target.comms_data.available_repair_crew - 1 sd:onPickUp(function(self,player) @@ -1602,7 +1614,7 @@ function requestSupplyDrop(calling_function) local target_x, target_y = comms_source:getWaypoint(n) local target_angle = random(0,360) local flinger_miss = random(100,5000) - local landing_x, landing_y = vectorFromAngleNorth(target_angle,flinger_miss) + local landing_x, landing_y = vectorFromAngle(target_angle,flinger_miss) local sd = SupplyDrop():setFactionId(comms_target:getFactionId()):setPosition(target_x + landing_x, target_y + landing_y):setEnergy(500):setWeaponStorage("Nuke", 1):setWeaponStorage("Homing", 4):setWeaponStorage("Mine", 2):setWeaponStorage("EMP", 1) comms_target.comms_data.coolant_inventory = comms_target.comms_data.coolant_inventory - 2 sd:onPickUp(function(self,player) @@ -2696,7 +2708,7 @@ function commercialOptions(calling_function) transport_mission_available = true end end - if transport_mission_available and #characters > 0 then + if transport_mission_available and #comms_target.characters > 0 then if out == "" then out = _("station-comms","We have potential passengers.") else @@ -3528,7 +3540,7 @@ function dockedLightPanic(comms_source, comms_target, oMsg) end end - oMsg = string.format("(DEBUG: friendlyness: %f)\n%s", comms_target.comms_data.friendlyness, oMsg) -- TODO remove (debug) +-- oMsg = string.format("(DEBUG: friendlyness: %f)\n%s", comms_target.comms_data.friendlyness, oMsg) -- TODO remove (debug) setCommsMessage(oMsg) if interactive then interactiveDockedStationComms() @@ -6996,29 +7008,30 @@ end function intimidateStationComms(comms_source, comms_target) if (comms_source.special_intimidate_stations or comms_source:getResourceAmount("Station Boarding Pod") > 0) and comms_target:getFaction() ~= "Human Navy" then - local current_faction = comms_target:getFaction() - setCommsMessage(_("special-comms", "You are our declared enemy. What do you want?")) - local cost = special_buy_cost(comms_target, comms_source) - addCommsReply(string.format(_("special-comms", "Surrender now! [Cost: %s Rep.]"), cost), function() + local current_faction = comms_target:getFaction() + setCommsMessage(_("special-comms", "You are our declared enemy. What do you want?")) + local cost = special_buy_cost(comms_target, comms_source) + addCommsReply(string.format(_("special-comms", "Surrender now! [Cost: %s Rep.]"), cost), function() - if not comms_target:areEnemiesInRange(5000) then - setCommsMessage(_("needRep-comms", "We will not surrender unless threatened.")) - elseif not (comms_target:getHull() < comms_target:getHullMax()) then - setCommsMessage(_("needRep-comms", "We will not surrender until our hull is damaged.")) - else - comms_target:setFaction("Human Navy") - if comms_target:areEnemiesInRange(5000) then - comms_target:setFaction(current_faction) - setCommsMessage(_("needRep-comms", "We will not surrender as long as enemies of the Human Navy are still near.")) - elseif not comms_source:takeReputationPoints(cost) then - comms_target:setFaction(current_faction) - setCommsMessage(_("needRep-comms", "Insufficient reputation")) - else - comms_target:setFaction("Independent") - setCommsMessage(_("special-comms", "Station surrendered.")) - end - end - end) + if not comms_target:areEnemiesInRange(5000) then + setCommsMessage(_("needRep-comms", "We will not surrender unless threatened.")) + elseif not (comms_target:getHull() < comms_target:getHullMax()) then + setCommsMessage(_("needRep-comms", "We will not surrender until our hull is damaged.")) + else + comms_target:setFaction("Human Navy") + if comms_target:areEnemiesInRange(5000) then + comms_target:setFaction(current_faction) + setCommsMessage(_("needRep-comms", "We will not surrender as long as enemies of the Human Navy are still near.")) + elseif not comms_source:takeReputationPoints(cost) then + comms_target:setFaction(current_faction) + setCommsMessage(_("needRep-comms", "Insufficient reputation")) + else + comms_target:setFaction("Independent") + setCommsMessage(_("special-comms", "Station surrendered.")) + end + end + end) + end end function buyStationComms(comms_source, comms_target) if (comms_source.special_buy_stations or comms_source:getResourceAmount("Station Command Team") > 0) and comms_target:getFaction() ~= "Human Navy" then @@ -7029,7 +7042,7 @@ function buyStationComms(comms_source, comms_target) else comms_target:setFaction(comms_source:getFaction()) local gain = comms_target:getHullMax() * 4 / 60 - setCommsMessage(string.format(_("special-comms", "This station now belongs to the Human Navy, Sir.\n\nAs long as the Human Navy keeps the station alive, your reputation will rise by %d per minute."), math.floor(gain))) -- TODO make this sentence not a lie + setCommsMessage(string.format(_("special-comms", "This station now belongs to the Human Navy, Sir.\n\nAs long as the Human Navy keeps the station alive, your reputation will rise by %d per minute."), math.floor(gain))) end end) end diff --git a/scripts-piglit/plots/wh_kraylor.lua b/scripts-piglit/plots/wh_kraylor.lua index 291c7dde29..757360cb1d 100644 --- a/scripts-piglit/plots/wh_kraylor.lua +++ b/scripts-piglit/plots/wh_kraylor.lua @@ -105,7 +105,7 @@ function wh_kraylor:spawn_enemies_kraylor(xOrigin, yOrigin, enemyStrength) local enemyList = {} local enemyPosition = 0 - local sp = irandom(300,500) --random spacing of spawned group + local sp = irandom(500,700) --random spacing of spawned group local formationLeader = nil local formationSecond = nil @@ -132,7 +132,7 @@ function wh_kraylor:spawn_enemies_kraylor(xOrigin, yOrigin, enemyStrength) enemyPosition = enemyPosition + 1 ship:setPosition(xOrigin+sp*enemyPosition, yOrigin+sp*enemyPosition) formationLeader, formationSecond = script_formation.buildFormationIncremental(ship, enemyPosition, formationLeader, formationSecond) - ship:setCommsScript(""):setCommsFunction(commsShip) + ship:setCommsScript(""):setCommsFunction(commsShip) --TODO commsShip is not defined! table.insert(enemyList, ship) end @@ -314,13 +314,13 @@ function wh_kraylor:update(delta) end end if threatened and not defended then - if station:getHull() < station.surrender_hull_threshold then + if 100*station:getHull()/station:getHullMax() < station.surrender_hull_threshold then -- reduce threshold station.surrender_hull_threshold = station.surrender_hull_threshold / 2 - if comms_target.comms_data == nil then - comms_target.comms_data = {} + if station.comms_data == nil then + station.comms_data = {} end - mergeTables(comms_target.comms_data, { + mergeTables(station.comms_data, { surrender_hull_threshold = station.surrender_hull_threshold }) -- change faction diff --git a/scripts-piglit/plots/wh_stations.lua b/scripts-piglit/plots/wh_stations.lua index b920f0a6e1..e3d2211b51 100644 --- a/scripts-piglit/plots/wh_stations.lua +++ b/scripts-piglit/plots/wh_stations.lua @@ -85,8 +85,12 @@ function wh_stations:init() end function wh_stations:initTest() - PlayerSpaceship():setTemplate("Adder MK7"):setCallSign("Station Visitor"):setPosition(-20000,0):setRotation(90):commandTargetRotation(90) - placeStation(-20000, -500):setCommsScript("comms_station_sandbox.lua") + local x,y = self.stations[1]:getPosition() + local ship = PlayerSpaceship():setTemplate("Adder MK7"):setCallSign("Station Visitor"):setPosition(x,y):setRotation(90):commandTargetRotation(90) + ship:setResourceAmount("Station Command Team", 1) + ship:setResourceAmount("Station Boarding Pod", 1) + ship:setResourceAmount("Diplomatic Crew", 1) + ship:setResourceAmount("Xenolinguistic Team", 1) end function wh_stations:setRepairMissions() @@ -141,12 +145,9 @@ function wh_stations:setRepairMissions() for i,station in ipairs(mission_stations) do station.mission_goods = {} for j,m_type in ipairs(ordnance_missions) do - if not station.comms_data.weapon_available then - station.mission_goods[m_type] = tableSelectRandom(mission_goods[m_type]) - end + station.mission_goods[m_type] = tableSelectRandom(mission_goods[m_type]) end if not station:getRestocksScanProbes() then - if station.probe_fail_reason == nil then local reason_list = { _("situationReport-comms", "Cannot replenish scan probes due to fabrication unit failure."), _("situationReport-comms", "Parts shortage prevents scan probe replenishment."), @@ -154,10 +155,8 @@ function wh_stations:setRepairMissions() } station.probe_fail_reason = reason_list[math.random(1,#reason_list)] station.mission_goods["restock_probes"] = tableSelectRandom(mission_reasons["restock_probes"][station.probe_fail_reason]) - end end if not station:getRepairDocked() then - if station.repair_fail_reason == nil then reason_list = { _("situationReport-comms", "We're out of the necessary materials and supplies for hull repair."), _("situationReport-comms", "Hull repair automation unavailable while it is undergoing maintenance."), @@ -165,10 +164,8 @@ function wh_stations:setRepairMissions() } station.repair_fail_reason = reason_list[math.random(1,#reason_list)] station.mission_goods["hull"] = tableSelectRandom(mission_reasons["hull"][station.repair_fail_reason]) - end end if not station:getSharesEnergyWithDocked() then - if station.energy_fail_reason == nil then reason_list = { _("situationReport-comms", "A recent reactor failure has put us on auxiliary power, so we cannot recharge ships."), _("situationReport-comms", "A damaged power coupling makes it too dangerous to recharge ships."), @@ -176,7 +173,6 @@ function wh_stations:setRepairMissions() } station.energy_fail_reason = reason_list[math.random(1,#reason_list)] station.mission_goods["energy"] = tableSelectRandom(mission_reasons["energy"][station.energy_fail_reason]) - end end --remove what is sold here diff --git a/scripts-piglit/plots/wh_turns.lua b/scripts-piglit/plots/wh_turns.lua index 5c6f8b285c..d2e52ed7ab 100644 --- a/scripts-piglit/plots/wh_turns.lua +++ b/scripts-piglit/plots/wh_turns.lua @@ -64,8 +64,8 @@ function wh_turns:startPause() slowGame() setScanningComplexity('none') setHackingDifficulty(3) - local endTime = os.date("%H:%M", os.time() + self.pauseTime) -- TODO test - globalMessage('Flottenbesprechung bis '..endTime) + --local endTime = os.date("%H:%M", os.time() + self.pauseTime) -- FIXME: os not avail + --globalMessage('Flottenbesprechung bis '..endTime) for id, script in pairs(self.onPause) do script() end diff --git a/scripts-piglit/scenario_99_wormhole_expedition.lua b/scripts-piglit/scenario_99_wormhole_expedition.lua index 96fa69c4ef..549711258e 100644 --- a/scripts-piglit/scenario_99_wormhole_expedition.lua +++ b/scripts-piglit/scenario_99_wormhole_expedition.lua @@ -16,6 +16,7 @@ require "plots/wh_wormhole.lua" --require "sandbox_error.lua" require "xansta_mods.lua" +require "script_hangar.lua" require("serpent.lua") function table.dump(...) @@ -66,6 +67,7 @@ function update(delta) plot:updateTest() end end + script_hangar.update(delta) end diff --git a/scripts-piglit/script_formation.lua b/scripts-piglit/script_formation.lua index 665af009b6..4d161af214 100644 --- a/scripts-piglit/script_formation.lua +++ b/scripts-piglit/script_formation.lua @@ -31,8 +31,8 @@ function factionalOffsets(faction, pos) local x,y -- x - to the front, y - to starport if faction == "Kraylor" then - x = 300 - y = 300 + x = 400 + y = 400 elseif faction == "Exuari" then x = -300 y = 300 diff --git a/scripts-piglit/xansta_mods.lua b/scripts-piglit/xansta_mods.lua index 798d0cbb31..59eb85d425 100644 --- a/scripts-piglit/xansta_mods.lua +++ b/scripts-piglit/xansta_mods.lua @@ -193,6 +193,11 @@ function init_constants_xansta() {"software",0}, {"circuit",0}, {"battery",0} } + good_desc = {} + for i,good in ipairs(goodsList) do + local g = good[1] + good_desc[g] = g + end 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"}