From 68ecfc115bca3025a276845373db9f455093d121 Mon Sep 17 00:00:00 2001 From: Pithlit Date: Fri, 19 Jul 2024 17:46:06 +0200 Subject: [PATCH] scenario: stations --- scripts-piglit/comms_station.lua | 82 +++++++++---------- scripts-piglit/plots/wh_stations.lua | 27 ++++++ scripts-piglit/plots/wh_terrain.lua | 14 ++-- .../scenario_99_wormhole_expedition.lua | 2 + 4 files changed, 76 insertions(+), 49 deletions(-) create mode 100644 scripts-piglit/plots/wh_stations.lua diff --git a/scripts-piglit/comms_station.lua b/scripts-piglit/comms_station.lua index 839e90e941..23dc970628 100755 --- a/scripts-piglit/comms_station.lua +++ b/scripts-piglit/comms_station.lua @@ -88,7 +88,7 @@ function commsStationMainMenu(comms_source, comms_target) end if comms_target:areEnemiesInRange(5000) then - setCommsMessage(_("commsStation", "We are under attack! No time for chatting!")) + setCommsMessage(_("station-comms", "We are under attack! No time for chatting!")) return true end if not comms_source:isDocked(comms_target) then @@ -119,27 +119,26 @@ end -- @tparam PlayerSpaceship comms_source -- @tparam SpaceStation comms_target function commsStationDocked(comms_source, comms_target) - print(_ENV) local message if comms_source:isFriendly(comms_target) then - message = string.format(_("commsStation", "Good day, officer! Welcome to %s.\nWhat can we do for you today?"), comms_target:getCallSign()) + message = string.format(_("station-comms", "Good day, officer! Welcome to %s.\nWhat can we do for you today?"), comms_target:getCallSign()) else - message = string.format(_("commsStation", "Welcome to our lovely station %s."), comms_target:getCallSign()) + message = string.format(_("station-comms", "Welcome to our lovely station %s."), comms_target:getCallSign()) end setCommsMessage(message) local reply_messages = { - ["Homing"] = _("commsStation", "Do you have spare homing missiles for us?"), - ["HVLI"] = _("commsStation", "Can you restock us with HVLI?"), - ["Mine"] = _("commsStation", "Please re-stock our mines."), - ["Nuke"] = _("commsStation", "Can you supply us with some nukes?"), - ["EMP"] = _("commsStation", "Please re-stock our EMP missiles.") + ["Homing"] = _("ammo-comms", "Do you have spare homing missiles for us?"), + ["HVLI"] = _("ammo-comms", "Can you restock us with HVLI?"), + ["Mine"] = _("ammo-comms", "Please re-stock our mines."), + ["Nuke"] = _("ammo-comms", "Can you supply us with some nukes?"), + ["EMP"] = _("ammo-comms", "Please re-stock our EMP missiles.") } for idx, missile_type in ipairs(MISSILE_TYPES) do if comms_source:getWeaponStorageMax(missile_type) > 0 then addCommsReply( - string.format(_("commsStation", "%s (%d rep each)"), reply_messages[missile_type], getWeaponCost(comms_source, comms_target, missile_type)), + string.format(_("ammo-comms", "%s (%d rep each)"), reply_messages[missile_type], getWeaponCost(comms_source, comms_target, missile_type)), function(comms_source, comms_target) handleWeaponRestock(comms_source, comms_target, missile_type) end @@ -245,18 +244,18 @@ end -- @tparam string weapon the missile type function handleWeaponRestock(comms_source, comms_target, weapon) if not comms_source:isDocked(comms_target) then - setCommsMessage(_("commsStation", "You need to stay docked for that action.")) + setCommsMessage(_("station-comms", "You need to stay docked for that action.")) return end if not isAllowedTo(comms_source, comms_target, comms_target.comms_data.weapons[weapon]) then local message if weapon == "Nuke" then - message = _("commsStation", "We do not deal in weapons of mass destruction.") + message = _("ammo-comms", "We do not deal in weapons of mass destruction.") elseif weapon == "EMP" then - message = _("commsStation", "We do not deal in weapons of mass disruption.") + message = _("ammo-comms", "We do not deal in weapons of mass disruption.") else - message = _("commsStation", "We do not deal in those weapons.") + message = _("ammo-comms", "We do not deal in those weapons.") end setCommsMessage(message) return @@ -267,26 +266,26 @@ function handleWeaponRestock(comms_source, comms_target, weapon) if item_amount <= 0 then local message if weapon == "Nuke" then - message = _("commsStation", "All nukes are charged and primed for destruction.") + message = _("ammo-comms", "All nukes are charged and primed for destruction.") else - message = _("commsStation", "Sorry, sir, but you are as fully stocked as I can allow.") + message = _("ammo-comms", "Sorry, sir, but you are as fully stocked as I can allow.") end setCommsMessage(message) - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) else if not comms_source:takeReputationPoints(points_per_item * item_amount) then - setCommsMessage(_("commsStation", "Not enough reputation.")) + setCommsMessage(_("needRep-comms", "Not enough reputation.")) return end comms_source:setWeaponStorage(weapon, comms_source:getWeaponStorage(weapon) + item_amount) local message if comms_source:getWeaponStorage(weapon) == comms_source:getWeaponStorageMax(weapon) then - message = _("commsStation", "You are fully loaded and ready to explode things.") + message = _("ammo-comms", "You are fully loaded and ready to explode things.") else - message = _("commsStation", "We generously resupplied you with some weapon charges.\nPut them to good use.") + message = _("ammo-comms", "We generously resupplied you with some weapon charges.\nPut them to good use.") end setCommsMessage(message) - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) end end @@ -295,19 +294,18 @@ end -- @tparam PlayerSpaceship comms_source -- @tparam SpaceStation comms_target function commsStationUndocked(comms_source, comms_target) - print(_ENV) local message if comms_source:isFriendly(comms_target) then - message = string.format(_("commsStation", "This is %s. Good day, officer.\nIf you need supplies, please dock with us first."), comms_target:getCallSign()) + message = string.format(_("station-comms", "This is %s. Good day, officer.\nIf you need supplies, please dock with us first."), comms_target:getCallSign()) else - message = string.format(_("commsStation", "This is %s. Greetings.\nIf you want to do business, please dock with us first."), comms_target:getCallSign()) + message = string.format(_("station-comms", "This is %s. Greetings.\nIf you want to do business, please dock with us first."), comms_target:getCallSign()) end setCommsMessage(message) -- supply drop if isAllowedTo(comms_source, comms_target, comms_target.comms_data.services.supplydrop) then addCommsReply( - string.format(_("commsStation", "Can you send a supply drop? (%d rep)"), getServiceCost(comms_source, comms_target, "supplydrop")), + string.format(_("stationAssist-comms", "Can you send a supply drop? (%d rep)"), getServiceCost(comms_source, comms_target, "supplydrop")), -- commsStationSupplyDrop ) @@ -316,7 +314,7 @@ function commsStationUndocked(comms_source, comms_target) -- reinforcements if isAllowedTo(comms_source, comms_target, comms_target.comms_data.services.reinforcements) then addCommsReply( - string.format(_("commsStation", "Please send reinforcements! (%d rep)"), getServiceCost(comms_source, comms_target, "reinforcements")), + string.format(_("stationAssist-comms", "Please send reinforcements! (%d rep)"), getServiceCost(comms_source, comms_target, "reinforcements")), -- commsStationReinforcements ) @@ -330,11 +328,10 @@ end -- @tparam PlayerSpaceship comms_source -- @tparam SpaceStation comms_target function commsStationSupplyDrop(comms_source, comms_target) - print(_ENV) if comms_source:getWaypointCount() < 1 then - setCommsMessage(_("commsStation", "You need to set a waypoint before you can request backup.")) + setCommsMessage(_("stationAssist-comms", "You need to set a waypoint before you can request backup.")) else - setCommsMessage(_("commsStation", "To which waypoint should we deliver your supplies?")) + setCommsMessage(_("stationAssist-comms", "To which waypoint should we deliver your supplies?")) for n = 1, comms_source:getWaypointCount() do addCommsReply( formatWaypoint(n), @@ -347,17 +344,17 @@ function commsStationSupplyDrop(comms_source, comms_target) 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") - message = string.format(_("commsStation", "We have dispatched a supply ship toward %s."), formatWaypoint(n)) + message = string.format(_("stationAssist-comms", "We have dispatched a supply ship toward %s."), formatWaypoint(n)) else - message = _("commsStation", "Not enough reputation!") + message = _("needRep-comms", "Not enough reputation!") end setCommsMessage(message) - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) end ) end end - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) end --- Ask for a waypoint and send reinforcements to defend it. @@ -365,7 +362,6 @@ end -- @tparam PlayerSpaceship comms_source -- @tparam SpaceStation comms_target function commsStationReinforcements(comms_source, comms_target) - print(_ENV) setCommsMessage(_("commsStation", "What kind of reinforcement ship would you like?")) addCommsReply(string.format(_("commsStation", "MT52 Hornet (%d rep)"), getServiceCost(comms_source, comms_target, "hornet_reinforcement")), function() string.format("") @@ -387,9 +383,9 @@ function commsStationReinforcements(comms_source, comms_target) end function commsStationSpecificReinforcement(comms_source, comms_target, reinforcement_type) if comms_source:getWaypointCount() < 1 then - setCommsMessage(_("commsStation", "You need to set a waypoint before you can request reinforcements.")) + setCommsMessage(_("stationAssist-comms", "You need to set a waypoint before you can request reinforcements.")) else - setCommsMessage(_("commsStation", "To which waypoint should we dispatch the reinforcements?")) + setCommsMessage(_("stationAssist-comms", "To which waypoint should we dispatch the reinforcements?")) for n = 1, comms_source:getWaypointCount() do addCommsReply( formatWaypoint(n), @@ -403,17 +399,17 @@ function commsStationSpecificReinforcement(comms_source, comms_target, reinforce ["phobos_reinforcement"] = "Phobos T3", } local ship = CpuShip():setFactionId(comms_target:getFactionId()):setPosition(comms_target:getPosition()):setTemplate(reinforcement_template[reinforcement_type]):setScanned(true):orderDefendLocation(comms_source:getWaypoint(n)) - message = string.format(_("commsStation", "We have dispatched %s to assist at %s."), ship:getCallSign(), formatWaypoint(n)) + message = string.format(_("stationAssist-comms", "We have dispatched %s to assist at %s."), ship:getCallSign(), formatWaypoint(n)) else - message = _("commsStation", "Not enough reputation!") + message = _("needRep-comms", "Not enough reputation!") end setCommsMessage(message) - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) end ) end end - addCommsReply(_("button", "Back"), commsStationMainMenu) + addCommsReply(_("Back"), commsStationMainMenu) end --- isAllowedTo @@ -461,8 +457,8 @@ end -- @tparam PlayerSpaceship comms_source -- @tparam SpaceStation comms_target -- @treturn string the status -function getFriendStatus() - if player:isFriendly(comms_target) then +function getFriendStatus(comms_source, comms_target) + if comms_source:isFriendly(comms_target) then return "friend" else return "neutral" @@ -474,7 +470,7 @@ end -- @tparam integer i the index of the waypoint -- @treturn string "WP i" function formatWaypoint(i) - return string.format(_("commsStation", "WP %d"), i) + return string.format(_("stationAssist-comms", "WP %d"), i) end -- `comms_source` and `comms_target` are global in comms script. diff --git a/scripts-piglit/plots/wh_stations.lua b/scripts-piglit/plots/wh_stations.lua new file mode 100644 index 0000000000..51022cdbce --- /dev/null +++ b/scripts-piglit/plots/wh_stations.lua @@ -0,0 +1,27 @@ +--[[ Places stations in the area +Before: wh_terrain (otherwise there is no space for the stations anymore) +--]] +wh_stations = {} + +require "place_station_scenario_utility.lua" + +function wh_stations:init() + local center_x, center_y = 100000,0 + local placement_attempt_count = 0 + self.stations = {} + repeat + local ox, oy = vectorFromAngle(random(0,360),random(40000,100000)) + ox = ox + center_x + oy = oy + center_y + local obj_list = getObjectsInRadius(ox, oy, 20000) + if #obj_list == 0 then + local station = placeStation(ox, oy, "RandomHumanNeutral") -- Independent of random size + if station ~= nil then + table.insert(self.stations, station) + else + break + end + end + placement_attempt_count = placement_attempt_count + 1 + until(placement_attempt_count > 500) +end diff --git a/scripts-piglit/plots/wh_terrain.lua b/scripts-piglit/plots/wh_terrain.lua index 94b629ec26..aa657baed6 100644 --- a/scripts-piglit/plots/wh_terrain.lua +++ b/scripts-piglit/plots/wh_terrain.lua @@ -13,13 +13,8 @@ require "plots/wh_util_rota.lua" function wh_terrain:init() local center_x, center_y = 100000,0 - -- create rotating system + -- create rotating system center self.blackhole = BlackHole():setPosition(center_x, center_y) - self.nebulae = placeRandomAroundPoint(Nebula,50,10000,100000,center_x,center_y) - for _,o in ipairs(self.nebulae) do - wh_rota:add_object(o, random(400, 2000), self.blackhole) - o.speed = o.speed / o.distance - end -- Artifacts (will be used 'last item first') local arts_mines = { @@ -91,6 +86,13 @@ function wh_terrain:init() end until(common_scattered_objects > 100) + -- rotating Nebulae + self.nebulae = placeRandomAroundPoint(Nebula,50,10000,100000,center_x,center_y) + for _,o in ipairs(self.nebulae) do + wh_rota:add_object(o, random(400, 2000), self.blackhole) + o.speed = o.speed / o.distance + end + print("Terrain: "..wh_artifacts.artifacts_total.." Artifacts placed") getScriptStorage().wh_terrain = self end diff --git a/scripts-piglit/scenario_99_wormhole_expedition.lua b/scripts-piglit/scenario_99_wormhole_expedition.lua index e8a36082d7..9be460af6b 100644 --- a/scripts-piglit/scenario_99_wormhole_expedition.lua +++ b/scripts-piglit/scenario_99_wormhole_expedition.lua @@ -3,6 +3,7 @@ require "plots/wh_util_rota.lua" require "plots/wh_artifacts.lua" +require "plots/wh_stations.lua" require "plots/wh_terrain.lua" require "plots/wh_fleetcommand.lua" require "plots/wh_wormhole.lua" @@ -13,6 +14,7 @@ function init() plots = { wh_rota, wh_artifacts, + wh_stations, wh_terrain, wh_fleetcommand, wh_wormhole,