From f26b79b973c7eb8f511cafe4c70dff05f323fbbf Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Wed, 19 Mar 2025 14:28:21 -0500 Subject: [PATCH 1/2] Planet Devourer Scenario Updates Make scenario run in pre-ECS environment as well as post-ECS environment --- scripts/scenario_32_devour.lua | 83 +++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/scripts/scenario_32_devour.lua b/scripts/scenario_32_devour.lua index 223d18d82c..4f3e263013 100644 --- a/scripts/scenario_32_devour.lua +++ b/scripts/scenario_32_devour.lua @@ -35,12 +35,16 @@ require("cpu_ship_diversification_scenario_utility.lua") -- Initialization -- -------------------- function init() - scenario_version = "1.0.3" + scenario_version = "1.0.4" ee_version = "2024.12.08" print(string.format(" ---- Scenario: Planet Devourer ---- Version %s ---- Tested with EE version %s ----",scenario_version,ee_version)) if _VERSION ~= nil then print("Lua version:",_VERSION) end + ECS = false + if createEntity then + ECS = true + end spawn_enemy_diagnostic = false setVariations() --numeric difficulty, Kraylor fortress size setConstants() --missle type names, template names and scores, deployment directions, player ship names, etc. @@ -49,6 +53,73 @@ function init() mainGMButtons() onNewPlayerShip(setPlayers) end +function isObjectType(obj,typ,qualifier) + if obj ~= nil and obj:isValid() then + if typ ~= nil then + if ECS then + if typ == "SpaceStation" then + return obj.components.docking_bay and obj.components.physics and obj.components.physics.type == "static" + elseif typ == "PlayerSpaceship" then + return obj.components.player_control + elseif typ == "ScanProbe" then + return obj.components.allow_radar_link + elseif typ == "CpuShip" then + return obj.ai_controller + elseif typ == "Asteroid" then + return obj.components.mesh_render and string.sub(obj.components.mesh_render.mesh, 7) == "Astroid" + elseif typ == "Nebula" then + return obj.components.nebula_renderer + elseif typ == "Planet" then + return obj.components.planet_render + elseif typ == "SupplyDrop" then + return obj.components.pickup and obj.components.radar_trace.icon == "radar/blip.png" and obj.components.radar_trace.color_by_faction + elseif typ == "BlackHole" then + return obj.components.gravity and obj.components.billboard_render.texture == "blackHole3d.png" + elseif typ == "WarpJammer" then + return obj.components.warp_jammer + elseif typ == "Mine" then + return obj.components.delayed_explode_on_touch and obj.components.constant_particle_emitter + elseif typ == "EMPMissile" then + return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explode_on_touch.damage_type == "emp" + elseif typ == "Nuke" then + return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explosion_sfx == "sfx/nuke_explosion.wav" + elseif typ == "Zone" then + return obj.components.zone + else + if qualifier == "MovingMissile" then + if typ == "HomingMissile" or typ == "HVLI" or typ == "Nuke" or typ == "EMPMissile" then + return obj.components.radar_trace.icon == "radar/missile.png" + else + return false + end + elseif qualifier == "SplashMissile" then + if typ == "Nuke" or typ == "EMPMissile" then + if obj.components.radar_trace.icon == "radar/missile.png" then + if typ == "Nuke" then + return obj.components.explosion_sfx == "sfx/nuke_explosion.wav" + else --EMP + return obj.components.explode_on_touch.damage_type == "emp" + end + else + return false + end + else + return false + end + else + return false + end + end + else + return obj.typeName == typ + end + else + return false + end + else + return false + end +end function setVariations() if getScenarioSetting == nil then enemy_power = 1 @@ -3918,7 +3989,7 @@ function friendlyComms(comms_data) addCommsReply(_("Back"), commsShip) end) for index, obj in ipairs(comms_target:getObjectsInRange(5000)) do - if obj.typeName == "SpaceStation" and not comms_target:isEnemy(obj) then + if isObjectType(obj,"SpaceStation") and not comms_target:isEnemy(obj) then if comms_target:getTypeName() ~= "Defense platform" then addCommsReply(string.format(_("shipAssist-comms", "Dock at %s"), obj:getCallSign()), function() setCommsMessage(string.format(_("shipAssist-comms", "Docking at %s."), obj:getCallSign())); @@ -4840,7 +4911,7 @@ function friendlyServiceJonqueComms(comms_data) addCommsReply(_("Back"), commsServiceJonque) end) for index, obj in ipairs(comms_target:getObjectsInRange(5000)) do - if obj.typeName == "SpaceStation" and not comms_target:isEnemy(obj) then + if isObjectType(obj,"SpaceStation") and not comms_target:isEnemy(obj) then if comms_target:getTypeName() ~= "Defense platform" then addCommsReply(string.format(_("shipAssist-comms","Dock at %s"),obj:getCallSign()), function() setCommsMessage(string.format(_("shipAssist-comms","Docking at %s."),obj:getCallSign())) @@ -5575,7 +5646,7 @@ function devourPlanets() local object_list = devourer:getObjectsInRange(300000) local planets = {} for i, obj in ipairs(object_list) do - if obj.typeName == "Planet" then + if isObjectType(obj,"Planet") then table.insert(planets,obj) end end @@ -5718,7 +5789,7 @@ function formerPlanetExplosion(px,py) ej.obj = nil ej.del = true elseif ej.action == "explode" then - if obj.typeName == "Artifact" then + if isObjectType(obj,"Artifact") then obj:explode() else local ex, ey = obj:getPosition() @@ -6026,7 +6097,7 @@ function explodeDevourer() local object_list = getObjectsInRadius(center_x, center_y, 300000) local planet_count = 0 for i, obj in ipairs(object_list) do - if obj.typeName == "Planet" then + if isObjectType(obj,"Planet") then planet_count = planet_count + 1 end end From 5485274877c18ad4182d3e325743bd8fc66fba42 Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Thu, 17 Apr 2025 09:18:46 -0500 Subject: [PATCH 2/2] Rely on function in utils.lua in #2331 --- scripts/scenario_32_devour.lua | 71 ---------------------------------- 1 file changed, 71 deletions(-) diff --git a/scripts/scenario_32_devour.lua b/scripts/scenario_32_devour.lua index 4f3e263013..460bf9ce14 100644 --- a/scripts/scenario_32_devour.lua +++ b/scripts/scenario_32_devour.lua @@ -41,10 +41,6 @@ function init() if _VERSION ~= nil then print("Lua version:",_VERSION) end - ECS = false - if createEntity then - ECS = true - end spawn_enemy_diagnostic = false setVariations() --numeric difficulty, Kraylor fortress size setConstants() --missle type names, template names and scores, deployment directions, player ship names, etc. @@ -53,73 +49,6 @@ function init() mainGMButtons() onNewPlayerShip(setPlayers) end -function isObjectType(obj,typ,qualifier) - if obj ~= nil and obj:isValid() then - if typ ~= nil then - if ECS then - if typ == "SpaceStation" then - return obj.components.docking_bay and obj.components.physics and obj.components.physics.type == "static" - elseif typ == "PlayerSpaceship" then - return obj.components.player_control - elseif typ == "ScanProbe" then - return obj.components.allow_radar_link - elseif typ == "CpuShip" then - return obj.ai_controller - elseif typ == "Asteroid" then - return obj.components.mesh_render and string.sub(obj.components.mesh_render.mesh, 7) == "Astroid" - elseif typ == "Nebula" then - return obj.components.nebula_renderer - elseif typ == "Planet" then - return obj.components.planet_render - elseif typ == "SupplyDrop" then - return obj.components.pickup and obj.components.radar_trace.icon == "radar/blip.png" and obj.components.radar_trace.color_by_faction - elseif typ == "BlackHole" then - return obj.components.gravity and obj.components.billboard_render.texture == "blackHole3d.png" - elseif typ == "WarpJammer" then - return obj.components.warp_jammer - elseif typ == "Mine" then - return obj.components.delayed_explode_on_touch and obj.components.constant_particle_emitter - elseif typ == "EMPMissile" then - return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explode_on_touch.damage_type == "emp" - elseif typ == "Nuke" then - return obj.components.radar_trace.icon == "radar/missile.png" and obj.components.explosion_sfx == "sfx/nuke_explosion.wav" - elseif typ == "Zone" then - return obj.components.zone - else - if qualifier == "MovingMissile" then - if typ == "HomingMissile" or typ == "HVLI" or typ == "Nuke" or typ == "EMPMissile" then - return obj.components.radar_trace.icon == "radar/missile.png" - else - return false - end - elseif qualifier == "SplashMissile" then - if typ == "Nuke" or typ == "EMPMissile" then - if obj.components.radar_trace.icon == "radar/missile.png" then - if typ == "Nuke" then - return obj.components.explosion_sfx == "sfx/nuke_explosion.wav" - else --EMP - return obj.components.explode_on_touch.damage_type == "emp" - end - else - return false - end - else - return false - end - else - return false - end - end - else - return obj.typeName == typ - end - else - return false - end - else - return false - end -end function setVariations() if getScenarioSetting == nil then enemy_power = 1