diff --git a/scripts/api/entity/cpuship.lua b/scripts/api/entity/cpuship.lua index 957128b695..e2594bc7a6 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 57f7a1b08e..e64ecf264b 100644 --- a/scripts/api/entity/playerspaceship.lua +++ b/scripts/api/entity/playerspaceship.lua @@ -21,6 +21,9 @@ function PlayerSpaceship() transform = {rotation=random(0, 360)}, callsign = {callsign=generateRandomCallSign()}, scan_state = scan_state, + comms_transmitter = {}, + radar_link = {}, + waypoints = {}, } e:setFaction(__default_player_ship_faction) return e diff --git a/scripts/api/entity/shiptemplatebasedobject.lua b/scripts/api/entity/shiptemplatebasedobject.lua index a4c7caf866..419c81ad7a 100644 --- a/scripts/api/entity/shiptemplatebasedobject.lua +++ b/scripts/api/entity/shiptemplatebasedobject.lua @@ -27,9 +27,18 @@ function Entity:setTemplate(template_name) end end if template.__type == "station" then + -- stations have static physics comp.physics.type = "static" - elseif template.__type == "playership" then - if comp.shields then comp.shields.active = false end + elseif comp.shields then + -- 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 + 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 5262e30248..3ef43a57fb 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. @@ -111,12 +112,6 @@ function ShipTemplate:setType(template_type) self.science_scanner = {} self.scan_probe_launcher = {} self.hacking_device = {} - self.long_range_radar = {} - self.radar_link = {} - self.waypoints = {} - self.comms_transmitter = {} - self.comms_receiver = nil - self.ai_controller = nil if self.docking_port then self.docking_port.auto_reload_missiles = false end @@ -129,7 +124,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 @@ -150,7 +144,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. @@ -534,7 +528,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. @@ -544,7 +538,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.