Skip to content

Commit

Permalink
autodetect (anti)nukes via code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruwetuin committed Jan 22, 2025
1 parent ffdab5d commit 7d4a375
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 58 deletions.
35 changes: 9 additions & 26 deletions gamedata/alldefs_post.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
24 changes: 10 additions & 14 deletions luarules/gadgets/pve_nuke_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -137,4 +133,4 @@ function gadget:GameFrame(frame)
end
end
end
end
end
24 changes: 8 additions & 16 deletions luarules/gadgets/sfx_notifications.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions luaui/Widgets/gui_anti_ranges.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7d4a375

Please sign in to comment.