From 64a60224a44bc61f72c0948a943888db71e67b6e Mon Sep 17 00:00:00 2001 From: GinjaNinja32 Date: Wed, 9 Jul 2025 19:46:16 +0100 Subject: [PATCH 1/3] Make cross-type templates behave more sensibly, like legacy --- scripts/api/entity/cpuship.lua | 1 + scripts/api/entity/playerspaceship.lua | 8 ++++++++ .../api/entity/shiptemplatebasedobject.lua | 18 +++++++++++------ scripts/api/entity/spacestation.lua | 1 + scripts/api/shipTemplate.lua | 20 +++++-------------- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/scripts/api/entity/cpuship.lua b/scripts/api/entity/cpuship.lua index 42ac8d090c..638a3b5b38 100644 --- a/scripts/api/entity/cpuship.lua +++ b/scripts/api/entity/cpuship.lua @@ -18,6 +18,7 @@ function CpuShip() ai_controller = {new_name="default", orders="roaming"}, scan_state = {allow_simple_scan=true}, callsign = {callsign=generateRandomCallSign()}, + comms_receiver = {script="comms_ship.lua"}, } e:setFaction(__default_cpu_ship_faction) return e diff --git a/scripts/api/entity/playerspaceship.lua b/scripts/api/entity/playerspaceship.lua index 7f3e26e69f..b0f4358d32 100644 --- a/scripts/api/entity/playerspaceship.lua +++ b/scripts/api/entity/playerspaceship.lua @@ -21,6 +21,14 @@ function PlayerSpaceship() transform = {rotation=random(0, 360)}, callsign = {callsign=generateRandomCallSign()}, scan_state = scan_state, + reactor = {}, + coolant = {}, + self_destruct = {}, + science_scanner = {}, + scan_probe_launcher = {}, + hacking_device = {}, + long_range_radar = {}, + comms_transmitter = {}, } e:setFaction(__default_player_ship_faction) return e diff --git a/scripts/api/entity/shiptemplatebasedobject.lua b/scripts/api/entity/shiptemplatebasedobject.lua index 2e3306f2ee..d760eda28f 100644 --- a/scripts/api/entity/shiptemplatebasedobject.lua +++ b/scripts/api/entity/shiptemplatebasedobject.lua @@ -26,10 +26,19 @@ function Entity:setTemplate(template_name) comp[key] = value end end - if template.__type == "station" then + if not comp.ai_controller and not comp.player_control then + -- no AI or player control, this is a station comp.physics.type = "static" - elseif template.__type == "playership" then - if comp.shields then comp.shields.active = false end + elseif comp.shields then + -- otherwise, set a shield frequency and turn player shields off by default + comp.shields.frequency = irandom(0, 20) + if comp.player_control then + comp.shields.active = false + end + end + + if comp.ai_controller then + comp.ai_controller.new_name = template.__default_ai end if comp.reactor then @@ -53,9 +62,6 @@ function Entity:setTemplate(template_name) crew.components.internal_repair_crew = {} end end - if comp.shields and template.__type ~= "station" then - comp.shields.frequency = irandom(0, 20) - end if comp.internal_rooms == nil then -- No internal rooms, so auto-repair if comp.beam_weapons then comp.beam_weapons.auto_repair_per_second = 0.005; end if comp.missile_tubes then comp.missile_tubes.auto_repair_per_second = 0.005 end diff --git a/scripts/api/entity/spacestation.lua b/scripts/api/entity/spacestation.lua index f382925f79..6892d02521 100644 --- a/scripts/api/entity/spacestation.lua +++ b/scripts/api/entity/spacestation.lua @@ -13,6 +13,7 @@ function SpaceStation() e.components = { transform = {rotation=random(0, 360)}, callsign = {callsign=generateRandomCallSign("DS")}, + comms_receiver = {script="comms_station.lua"}, } e:setFaction(__default_station_faction) return e diff --git a/scripts/api/shipTemplate.lua b/scripts/api/shipTemplate.lua index ff9372a169..417ec4ccb5 100644 --- a/scripts/api/shipTemplate.lua +++ b/scripts/api/shipTemplate.lua @@ -48,9 +48,10 @@ function ShipTemplate:__init__() color_by_faction=true, arrow_if_not_scanned=true, } + self.__default_ai = "default" self.__repair_crew_count = 3 + self.long_range_radar = {} self.share_short_range_radar = {} - self.comms_receiver = {script="comms_ship.lua"} end --- Sets this ShipTemplate's unique reference name. @@ -105,16 +106,6 @@ function ShipTemplate:setType(template_type) if template_type == "playership" then __player_ship_templates[#__player_ship_templates + 1] = self --Add some default player ship components. - self.reactor = {} - self.coolant = {} - self.self_destruct = {} - self.science_scanner = {} - self.scan_probe_launcher = {} - self.hacking_device = {} - self.long_range_radar = {} - self.comms_transmitter = {} - self.comms_receiver = nil - self.ai_controller = nil if self.docking_port then self.docking_port.auto_reload_missiles = false end @@ -126,7 +117,6 @@ function ShipTemplate:setType(template_type) if self.radar_trace.icon == "radar/ship.png" then self.radar_trace.icon = "radar/blip.png" end - self.comms_receiver = {script="comms_station.lua"} end return self end @@ -147,7 +137,7 @@ end --- - "missilevolley" prefers lining up missile attacks from long range --- Example: template:setAI("fighter") -- default to the "fighter" combat AI state function ShipTemplate:setDefaultAI(default_ai) - self.ai_controller = {new_name=default_ai} + self.__default_ai = default_ai return self end --- Sets the 3D appearance, by ModelData name, of ShipTemplateBasedObjects created from this ShipTemplate. @@ -531,7 +521,7 @@ end --- Defaults to 30000.0 (30U). --- Example: template:setLongRangeRadarRange(20000) -- sets the long-range radar range to 20U function ShipTemplate:setLongRangeRadarRange(range) - if self.long_range_radar then self.long_range_radar.long_range = range end + self.long_range_radar.long_range = range return self end --- Sets the short-range radar range of SpaceShips created from this ShipTemplate. @@ -541,7 +531,7 @@ end --- Defaults to 5000.0 (5U). --- Example: template:setShortRangeRadarRange(4000) -- sets the short-range radar range to 4U function ShipTemplate:setShortRangeRadarRange(range) - if self.long_range_radar then self.long_range_radar.short_range = range end + self.long_range_radar.short_range = range return self end --- Sets the sound file used for the impulse drive sounds on SpaceShips created from this ShipTemplate. From 518a58c21cf5fcdfede9b9809417f9eb7a1d09e9 Mon Sep 17 00:00:00 2001 From: GinjaNinja32 Date: Wed, 9 Jul 2025 20:08:46 +0100 Subject: [PATCH 2/3] Don't add a reactor from ship templates --- scripts/api/entity/shiptemplatebasedobject.lua | 5 +++++ scripts/api/shipTemplate.lua | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/api/entity/shiptemplatebasedobject.lua b/scripts/api/entity/shiptemplatebasedobject.lua index d760eda28f..a7be4fbfb7 100644 --- a/scripts/api/entity/shiptemplatebasedobject.lua +++ b/scripts/api/entity/shiptemplatebasedobject.lua @@ -42,6 +42,11 @@ function Entity:setTemplate(template_name) end if comp.reactor then + if template.__energy_storage then + comp.reactor.max_energy = template.__energy_storage + comp.reactor.energy = template.__energy_storage + end + local reactor_power_factor = 0 if comp.beam_weapons then comp.beam_weapons.power_factor = 3.0; reactor_power_factor = reactor_power_factor - 3.0 end if comp.missile_tubes then comp.missile_tubes.power_factor = 1.0; reactor_power_factor = reactor_power_factor - 1.0 end diff --git a/scripts/api/shipTemplate.lua b/scripts/api/shipTemplate.lua index 417ec4ccb5..70b131c70a 100644 --- a/scripts/api/shipTemplate.lua +++ b/scripts/api/shipTemplate.lua @@ -191,7 +191,7 @@ end --- Defaults to 1000. --- Example: template:setEnergyStorage(500) function ShipTemplate:setEnergyStorage(amount) - self.reactor = {max_energy=amount, energy=amount} + self.__energy_storage = amount return self end --- Sets the default number of repair crew for PlayerSpaceships created from this ShipTemplate. From 89da148ec265305c561abdb32ae223a416646513 Mon Sep 17 00:00:00 2001 From: GinjaNinja32 Date: Thu, 17 Jul 2025 00:17:33 +0100 Subject: [PATCH 3/3] Always use ship capabilities from template, rather than target type --- scripts/api/entity/playerspaceship.lua | 6 ------ scripts/api/entity/shiptemplatebasedobject.lua | 11 +++-------- scripts/api/shipTemplate.lua | 8 +++++++- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/scripts/api/entity/playerspaceship.lua b/scripts/api/entity/playerspaceship.lua index b0f4358d32..e3578c8c33 100644 --- a/scripts/api/entity/playerspaceship.lua +++ b/scripts/api/entity/playerspaceship.lua @@ -21,12 +21,6 @@ function PlayerSpaceship() transform = {rotation=random(0, 360)}, callsign = {callsign=generateRandomCallSign()}, scan_state = scan_state, - reactor = {}, - coolant = {}, - self_destruct = {}, - science_scanner = {}, - scan_probe_launcher = {}, - hacking_device = {}, long_range_radar = {}, comms_transmitter = {}, } diff --git a/scripts/api/entity/shiptemplatebasedobject.lua b/scripts/api/entity/shiptemplatebasedobject.lua index a7be4fbfb7..361cae3943 100644 --- a/scripts/api/entity/shiptemplatebasedobject.lua +++ b/scripts/api/entity/shiptemplatebasedobject.lua @@ -26,11 +26,11 @@ function Entity:setTemplate(template_name) comp[key] = value end end - if not comp.ai_controller and not comp.player_control then - -- no AI or player control, this is a station + if template.__type == "station" then + -- stations have static physics comp.physics.type = "static" elseif comp.shields then - -- otherwise, set a shield frequency and turn player shields off by default + -- ships have shield frequencies, player shields are off by default comp.shields.frequency = irandom(0, 20) if comp.player_control then comp.shields.active = false @@ -42,11 +42,6 @@ function Entity:setTemplate(template_name) end if comp.reactor then - if template.__energy_storage then - comp.reactor.max_energy = template.__energy_storage - comp.reactor.energy = template.__energy_storage - end - local reactor_power_factor = 0 if comp.beam_weapons then comp.beam_weapons.power_factor = 3.0; reactor_power_factor = reactor_power_factor - 3.0 end if comp.missile_tubes then comp.missile_tubes.power_factor = 1.0; reactor_power_factor = reactor_power_factor - 1.0 end diff --git a/scripts/api/shipTemplate.lua b/scripts/api/shipTemplate.lua index 70b131c70a..43eb0b5328 100644 --- a/scripts/api/shipTemplate.lua +++ b/scripts/api/shipTemplate.lua @@ -106,6 +106,12 @@ function ShipTemplate:setType(template_type) if template_type == "playership" then __player_ship_templates[#__player_ship_templates + 1] = self --Add some default player ship components. + self.reactor = {} + self.coolant = {} + self.self_destruct = {} + self.science_scanner = {} + self.scan_probe_launcher = {} + self.hacking_device = {} if self.docking_port then self.docking_port.auto_reload_missiles = false end @@ -191,7 +197,7 @@ end --- Defaults to 1000. --- Example: template:setEnergyStorage(500) function ShipTemplate:setEnergyStorage(amount) - self.__energy_storage = amount + self.reactor = {max_energy=amount, energy=amount} return self end --- Sets the default number of repair crew for PlayerSpaceships created from this ShipTemplate.