From 7d4a375310431cfd172c94d9a9f99821298064e8 Mon Sep 17 00:00:00 2001 From: Floris Date: Wed, 22 Jan 2025 16:10:40 +0100 Subject: [PATCH] autodetect (anti)nukes via code --- gamedata/alldefs_post.lua | 35 ++++++------------------ luarules/gadgets/pve_nuke_controller.lua | 24 +++++++--------- luarules/gadgets/sfx_notifications.lua | 24 ++++++---------- luaui/Widgets/gui_anti_ranges.lua | 4 +-- 4 files changed, 29 insertions(+), 58 deletions(-) diff --git a/gamedata/alldefs_post.lua b/gamedata/alldefs_post.lua index eeb49196e9c..0150541cc55 100644 --- a/gamedata/alldefs_post.lua +++ b/gamedata/alldefs_post.lua @@ -259,30 +259,13 @@ function UnitDef_Post(name, uDef) end if modOptions.unit_restrictions_nonukes then - local Nukes = { - armamd = true, - armsilo = true, - armscab = true, - armseadragon = true, - corfmd = true, - corsilo = true, - cormabm = true, - cordesolator = true, - legsilo = true, - legabm = true, - armamd_scav = true, - armsilo_scav = true, - armscab_scav = true, - armseadragon_scav = true, - corfmd_scav = true, - corsilo_scav = true, - cormabm_scav = true, - cordesolator_scav = true, - legsilo_scav = true, - legabm_scav = true, - } - if Nukes[name] then - uDef.maxthisunit = 0 + if uDef.weapondefs then + for _, weapon in pairs(uDef.weapondefs) do + if (weapon.interceptor and weapon.interceptor == 1) or (weapon.targetable and weapon.targetable == 1) then + uDef.maxthisunit = 0 + break + end + end end end @@ -1413,8 +1396,8 @@ function WeaponDef_Post(name, wDef) wDef.mygravity = 0.1445 end end - - -- Accurate Lasers + + -- Accurate Lasers if modOptions.proposed_unit_reworks then if wDef.weapontype and wDef.weapontype == 'BeamLaser' then wDef.targetmoveerror = nil diff --git a/luarules/gadgets/pve_nuke_controller.lua b/luarules/gadgets/pve_nuke_controller.lua index 48aa3301a52..3ce4a21fdd0 100644 --- a/luarules/gadgets/pve_nuke_controller.lua +++ b/luarules/gadgets/pve_nuke_controller.lua @@ -47,19 +47,15 @@ for i = 1, #teams do end local nukeDefs = {} -for _, unitDefName in ipairs({ - "raptor_turret_meteor_t4_v1", - "corsilo_scav", - "armsilo_scav", - "legsilo_scav", - "corjuno_scav", - "armjuno_scav", - "legstarfall_scav", - "armseadragon_scav", - "cordesolator_scav", - }) do - if UnitDefNames[unitDefName] then - nukeDefs[UnitDefNames[unitDefName].id] = true +for unitDefID, def in ipairs(UnitDefs) do + if def.weapons then + for i = 1, #def.weapons do + local wDef = WeaponDefs[def.weapons[i].weaponDef] + if wDef.targetable == 1 then + nukeDefs[unitDefID] = true + break + end + end end end @@ -137,4 +133,4 @@ function gadget:GameFrame(frame) end end end -end \ No newline at end of file +end diff --git a/luarules/gadgets/sfx_notifications.lua b/luarules/gadgets/sfx_notifications.lua index 89a0b54f6d4..bde414ff29c 100644 --- a/luarules/gadgets/sfx_notifications.lua +++ b/luarules/gadgets/sfx_notifications.lua @@ -52,25 +52,17 @@ if gadgetHandler:IsSyncedCode() then end end end - local nukesNames = { - armsilo_nuclear_missile = true, - corsilo_crblmssl = true, - armsilo_scav_nuclear_missile = true, - corsilo_scav_crblmssl = true, - raptor_turret_meteor_t4_v1_weapon = true, - --raptor_allterrain_arty_basic_t4_v1_meteorlauncher = true, - } - -- convert weaponname -> weaponDefID - local nukes = {} - for name, params in pairs(nukesNames) do - if WeaponDefNames[name] then - nukes[WeaponDefNames[name].id] = params + local nukeWeapons = {} + for id, def in pairs(WeaponDefs) do + if def.targetable and def.targetable == 1 then + if def.name ~= "raptor_allterrain_arty_basic_t4_v1_meteorlauncher" then -- to not drive them mad + nukeWeapons[id] = true + end end end - nukesNames = nil function gadget:Initialize() - for k,v in pairs(nukes) do + for k,v in pairs(nukeWeapons) do Script.SetWatchProjectile(k, true) end end @@ -90,7 +82,7 @@ if gadgetHandler:IsSyncedCode() then -- NUKE LAUNCH send to all but ally team function gadget:ProjectileCreated(proID, proOwnerID, weaponDefID) local proDefID = Spring.GetProjectileDefID(proID) - if nukes[Spring.GetProjectileDefID(proID)] then + if nukeWeapons[Spring.GetProjectileDefID(proID)] then local players = AllButAllyTeamID(GetAllyTeamID(Spring.GetUnitTeam(proOwnerID))) for ct, player in pairs (players) do if tostring(player) then diff --git a/luaui/Widgets/gui_anti_ranges.lua b/luaui/Widgets/gui_anti_ranges.lua index 0d458164757..6bd03e92058 100644 --- a/luaui/Widgets/gui_anti_ranges.lua +++ b/luaui/Widgets/gui_anti_ranges.lua @@ -82,9 +82,9 @@ function identifyAntiNukeUnits() local weapons = unitDef.weapons for i=1, #weapons do local weaponDef = WeaponDefs[weapons[i].weaponDef] - if weaponDef and weaponDef.coverageRange and weaponDef.coverageRange > 0 then + if weaponDef and weaponDef.interceptor and weaponDef.interceptor == 1 then antiNukeDefs[unitDefID] = weaponDef.coverageRange - break -- No need to check further weapons for this unit + break end end end