Skip to content

Commit

Permalink
scenario: stations
Browse files Browse the repository at this point in the history
  • Loading branch information
Pithlit committed Jul 19, 2024
1 parent 80cad77 commit 68ecfc1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 49 deletions.
82 changes: 39 additions & 43 deletions scripts-piglit/comms_station.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
)
Expand All @@ -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
)
Expand All @@ -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),
Expand All @@ -347,25 +344,24 @@ 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.
--
-- @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("")
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions scripts-piglit/plots/wh_stations.lua
Original file line number Diff line number Diff line change
@@ -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
14 changes: 8 additions & 6 deletions scripts-piglit/plots/wh_terrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions scripts-piglit/scenario_99_wormhole_expedition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,6 +14,7 @@ function init()
plots = {
wh_rota,
wh_artifacts,
wh_stations,
wh_terrain,
wh_fleetcommand,
wh_wormhole,
Expand Down

0 comments on commit 68ecfc1

Please sign in to comment.