From f96fa5f9bc4fda79182e435fd700eeab05c663eb Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Thu, 20 Mar 2025 11:31:38 -0500 Subject: [PATCH 1/2] Delta Quadrant Patrol Duty Scenario Updates Make scenario work in ECS and pre-ECS environments. --- scripts/scenario_54_PatrolDuty.lua | 94 +++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 8 deletions(-) mode change 100755 => 100644 scripts/scenario_54_PatrolDuty.lua diff --git a/scripts/scenario_54_PatrolDuty.lua b/scripts/scenario_54_PatrolDuty.lua old mode 100755 new mode 100644 index 04ce449b77..e435a43023 --- a/scripts/scenario_54_PatrolDuty.lua +++ b/scripts/scenario_54_PatrolDuty.lua @@ -145,6 +145,16 @@ end -- Initialization -- ---------------------- function init() + scenario_version = "8.0.1" + ee_version = "2024.12.08" + print(string.format(" ---- Scenario: Patrol Duty ---- 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 setVariations() setConstants() diagnostic = false @@ -162,6 +172,74 @@ function init() addGMFunction(_("buttonGM", "Skip to defend U.P."),skipToDefendUP) addGMFunction(_("buttonGM", "Skip to destroy S.C."),skipToDestroySC) 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() local enemy_config = { ["Easy"] = {number = .5}, @@ -4601,7 +4679,7 @@ function handleDockedState() local sx, sy = comms_target:getPosition() local nearby_objects = getObjectsInRadius(sx,sy,30000) for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then if brochure_stations == "" then brochure_stations = string.format(_("cartographyOffice-comms", "%s %s %s"),obj:getSectorName(),obj:getFaction(),obj:getCallSign()) @@ -4623,7 +4701,7 @@ function handleDockedState() local sx, sy = comms_target:getPosition() local nearby_objects = getObjectsInRadius(sx,sy,30000) for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then if obj.comms_data.goods ~= nil then for good, good_data in pairs(obj.comms_data.goods) do @@ -4657,7 +4735,7 @@ function handleDockedState() local nearby_objects = getObjectsInRadius(sx,sy,50000) local stations_known = 0 for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then stations_known = stations_known + 1 addCommsReply(obj:getCallSign(),function() @@ -4695,7 +4773,7 @@ function handleDockedState() local button_count = 0 local by_goods = {} for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then if obj.comms_data.goods ~= nil then for good, good_data in pairs(obj.comms_data.goods) do @@ -5181,7 +5259,7 @@ function masterCartographer() local nearby_objects = getAllObjects() local stations_known = 0 for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then local station_distance = distance(comms_target,obj) if station_distance > 50000 then @@ -5223,7 +5301,7 @@ function masterCartographer() local nearby_objects = getAllObjects() local by_goods = {} for i, obj in ipairs(nearby_objects) do - if obj.typeName == "SpaceStation" then + if isObjectType(obj,"SpaceStation") then if not obj:isEnemy(comms_target) then local station_distance = distance(comms_target,obj) if station_distance > 50000 then @@ -5746,7 +5824,7 @@ function friendlyComms(comms_data) addCommsReply(_("Back"), commsShip) end) for i, 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 addCommsReply(string.format(_("shipAssist-comms", "Dock at %s"), obj:getCallSign()), function() setCommsMessage(string.format(_("shipAssist-comms", "Docking at %s."), obj:getCallSign())); comms_target:orderDock(obj) @@ -7589,7 +7667,7 @@ function jumpStart(delta) objList = getObjectsInRadius(x, y, 30000) nebulaList = {} for i, obj in ipairs(objList) do - if obj.typeName == "Nebula" then + if isObjectType(obj,"Nebula") then table.insert(nebulaList,obj) end end From 83d2cda93cf332d8b38eefc2ff03074654d88d4f Mon Sep 17 00:00:00 2001 From: Xansta <> Date: Thu, 17 Apr 2025 08:53:37 -0500 Subject: [PATCH 2/2] Rely on function in utils.lua in #2331 --- scripts/scenario_54_PatrolDuty.lua | 72 ------------------------------ 1 file changed, 72 deletions(-) diff --git a/scripts/scenario_54_PatrolDuty.lua b/scripts/scenario_54_PatrolDuty.lua index e435a43023..9992964557 100644 --- a/scripts/scenario_54_PatrolDuty.lua +++ b/scripts/scenario_54_PatrolDuty.lua @@ -151,10 +151,6 @@ function init() if _VERSION ~= nil then print("Lua version:",_VERSION) end - ECS = false - if createEntity then - ECS = true - end setVariations() setConstants() diagnostic = false @@ -172,74 +168,6 @@ function init() addGMFunction(_("buttonGM", "Skip to defend U.P."),skipToDefendUP) addGMFunction(_("buttonGM", "Skip to destroy S.C."),skipToDestroySC) 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() local enemy_config = { ["Easy"] = {number = .5},