Skip to content

Commit

Permalink
#3959 Refactored stockpile limits into unit custom params (#3994)
Browse files Browse the repository at this point in the history
Refactor to move stockpile limits to the weapon defs instead of a list in gadget. Engine still only supports one stockpile weapon per unit, however.
  • Loading branch information
ryanbennitt authored Dec 30, 2024
1 parent cacb6fb commit d35d55b
Show file tree
Hide file tree
Showing 53 changed files with 133 additions and 222 deletions.
4 changes: 2 additions & 2 deletions gamedata/scavengers/unitdef_changes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ customDefs.armjuno = {
commandfire = true,
customparams = {
scavforcecommandfire = true,
stockpileLimit = 1,
stockpilelimit = 1,
},
},
},
Expand All @@ -112,7 +112,7 @@ customDefs.corjuno = {
commandfire = true,
customparams = {
scavforcecommandfire = true,
stockpileLimit = 1,
stockpilelimit = 1,
},
},
},
Expand Down
101 changes: 12 additions & 89 deletions luarules/gadgets/unit_stockpile_limit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,87 +19,7 @@ if gadgetHandler:IsSyncedCode() then
local StockpileDesiredTarget = {}

local defaultStockpileLimit = 99
local isStockpilingUnitNames = { -- number represents maximum stockpile. You can also use stockpileLimit customParam which overwrites whatever is set in this table
['armmercury'] = 5,
['corscreamer'] = 5,

['armthor'] = 2,

['legmos'] = 8,
['legmost3'] = 8,
['legmineb'] = 1,
['legsrailt4'] = 3,

['armsilo'] = 10,
['corsilo'] = 10,
['legsilo'] = 10,
['cordesolator'] = 10,
['armseadragon'] = 10,


['armamd'] = 20,
['legabm'] = 20,
['corfmd'] = 20,
['raptor_turret_antinuke_t2_v1'] = 5,
['raptor_turret_antinuke_t3_v1'] = 10,

['armjuno'] = 20,
['corjuno'] = 20,

['armcarry'] = 20,
['corcarry'] = 20,

['armantiship'] = 20,
['corantiship'] = 20,

['armscab'] = 20,
['cormabm'] = 20,

['armemp'] = 10,
['cortron'] = 10,
['legperdition'] = 10,

['armbotrail'] = 50,
['armcomlvl2'] = 3,
['armcomlvl3'] = 3,
['armdecomlvl3'] = 1,
['armcomlvl4'] = 3,
['armcomlvl5'] = 4,
['armcomlvl6'] = 4,
['armdecomlvl6'] = 2,
['armcomlvl7'] = 4,
['armcomlvl8'] = 5,
['armcomlvl9'] = 5,
['armcomlvl10'] = 5,
['armdecomlvl10'] = 2,
['legcom'] = 2,
['legcomlvl2'] = 3,
['legcomlvl3'] = 3,
['legdecomlvl3'] = 1,
['legcomlvl4'] = 3,
['legcomlvl5'] = 4,
['legcomlvl6'] = 4,
['legdecomlvl6'] = 2,
['legcomlvl7'] = 4,
['legcomlvl8'] = 5,
['legcomlvl9'] = 5,
['legcomlvl10'] = 5,
['legdecomlvl10'] = 3,

['legstarfall'] = 1,
['legrampart'] = 20,
}
-- convert unitname -> unitDefID + add scavengers
local isStockpilingUnit = {}
for name, params in pairs(isStockpilingUnitNames) do
if UnitDefNames[name] then
isStockpilingUnit[UnitDefNames[name].id] = params
if UnitDefNames[name..'_scav'] then
isStockpilingUnit[UnitDefNames[name..'_scav'].id] = params
end
end
end
isStockpilingUnitNames = nil
local unitStockpileLimit = {}

----------------------------------------------------------------------------
----------------------------------------------------------------------------
Expand All @@ -112,15 +32,18 @@ if gadgetHandler:IsSyncedCode() then
if ud.canStockpile then
canStockpile[udid] = true
end
if ud.customParams and ud.customParams.stockpileLimit then
isStockpilingUnit[udid] = tonumber(ud.customParams.stockpileLimit)
elseif ud.customParams and ud.customParams.stockpilelimit then
isStockpilingUnit[udid] = tonumber(ud.customParams.stockpilelimit)
if ud.weapons then
for i = 1, #ud.weapons do
local weaponDef = WeaponDefs[ud.weapons[i].weaponDef]
if weaponDef.stockpile and weaponDef.customParams and weaponDef.customParams.stockpilelimit then
unitStockpileLimit[udid] = tonumber(weaponDef.customParams.stockpilelimit)
end
end
end
end

function UpdateStockpile(unitID, unitDefID)
local MaxStockpile = math.max(math.min(isStockpilingUnit[unitDefID] or defaultStockpileLimit, StockpileDesiredTarget[unitID]), 0)
local MaxStockpile = math.max(math.min(unitStockpileLimit[unitDefID] or defaultStockpileLimit, StockpileDesiredTarget[unitID]), 0)

local stock,queued = GetUnitStockpile(unitID)
if queued and stock then
Expand Down Expand Up @@ -181,7 +104,7 @@ if gadgetHandler:IsSyncedCode() then
if fromLua == true and fromSynced == true then -- fromLua is *true* if command is sent from a gadget and *false* if it's sent by a player.
return true
else
StockpileDesiredTarget[unitID] = math.max(math.min(StockpileDesiredTarget[unitID] + addQ, isStockpilingUnit[unitDefID] or defaultStockpileLimit), 0) -- let's make sure desired target doesn't go above maximum of this unit, and doesn't go below 0
StockpileDesiredTarget[unitID] = math.max(math.min(StockpileDesiredTarget[unitID] + addQ, unitStockpileLimit[unitDefID] or defaultStockpileLimit), 0) -- let's make sure desired target doesn't go above maximum of this unit, and doesn't go below 0
UpdateStockpile(unitID, unitDefID)
return false
end
Expand All @@ -192,14 +115,14 @@ if gadgetHandler:IsSyncedCode() then

function gadget:UnitCreated(unitID, unitDefID, unitTeam)
if canStockpile[unitDefID] then
StockpileDesiredTarget[unitID] = isStockpilingUnit[unitDefID] or defaultStockpileLimit
StockpileDesiredTarget[unitID] = unitStockpileLimit[unitDefID] or defaultStockpileLimit
UpdateStockpile(unitID, unitDefID)
end
end

function gadget:UnitGiven(unitID, unitDefID, unitTeam)
if canStockpile[unitDefID] then
StockpileDesiredTarget[unitID] = isStockpilingUnit[unitDefID] or defaultStockpileLimit
StockpileDesiredTarget[unitID] = unitStockpileLimit[unitDefID] or defaultStockpileLimit
UpdateStockpile(unitID, unitDefID)
end
end
Expand Down
3 changes: 3 additions & 0 deletions units/ArmBots/T2/armscab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ return {
weapontimer = 2,
weapontype = "StarburstLauncher",
weaponvelocity = 7000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 500,
},
Expand Down
3 changes: 3 additions & 0 deletions units/ArmBuildings/LandDefenceOffence/armamd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ return {
weapontimer = 3,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
3 changes: 3 additions & 0 deletions units/ArmBuildings/LandDefenceOffence/armemp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ return {
weapontimer = 3,
weapontype = "StarburstLauncher",
weaponvelocity = 1200,
customparams = {
stockpilelimit = 10,
},
damage = {
default = 50000,
},
Expand Down
1 change: 1 addition & 0 deletions units/ArmBuildings/LandDefenceOffence/armjuno.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ return {
customparams = {
lups_noshockwave = 1,
nofire = true,
stockpilelimit = 20,
},
damage = {
default = 1,
Expand Down
3 changes: 3 additions & 0 deletions units/ArmBuildings/LandDefenceOffence/armmercury.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ return {
weaponacceleration = 1000,
weapontype = "MissileLauncher",
weaponvelocity = 1850,
customparams = {
stockpilelimit = 5,
},
damage = {
vtol = 750,
},
Expand Down
1 change: 1 addition & 0 deletions units/ArmBuildings/LandDefenceOffence/armsilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ return {
weaponvelocity = 1600,
customparams = {
place_target_on_ground = "true",
stockpilelimit = 10,
},
damage = {
commanders = 2500,
Expand Down
3 changes: 3 additions & 0 deletions units/ArmGantry/armthor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 500,
customparams = {
stockpilelimit = 2,
},
damage = {
default = 80000,
},
Expand Down
3 changes: 3 additions & 0 deletions units/ArmShips/T2/armantiship.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
3 changes: 3 additions & 0 deletions units/ArmShips/T2/armcarry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
1 change: 1 addition & 0 deletions units/ArmShips/T2/armseadragon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ return {
customparams = {
place_target_on_ground = "true",
scavforcecommandfire = true,
stockpilelimit = 10,
},
damage = {
commanders = 2500,
Expand Down
3 changes: 3 additions & 0 deletions units/CorBuildings/LandDefenceOffence/corfmd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
3 changes: 3 additions & 0 deletions units/CorBuildings/LandDefenceOffence/corjuno.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ return {
weapontimer = 4,
weapontype = "StarburstLauncher",
weaponvelocity = 500,
customparams = {

This comment has been minimized.

Copy link
@Beherith

Beherith Jan 21, 2025

Collaborator

WARINING! DUPLICATE TABLE KEY!

stockpilelimit = 20,
},
customparams = {
lups_noshockwave = 1,
nofire = true,
Expand Down
3 changes: 3 additions & 0 deletions units/CorBuildings/LandDefenceOffence/corscreamer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ return {
weaponacceleration = 1000,
weapontype = "MissileLauncher",
weaponvelocity = 1850,
customparams = {
stockpilelimit = 5,
},
damage = {
vtol = 750,
},
Expand Down
1 change: 1 addition & 0 deletions units/CorBuildings/LandDefenceOffence/corsilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ return {
weaponvelocity = 1600,
customparams = {
place_target_on_ground = "true",
stockpilelimit = 10,
},
damage = {
commanders = 2500,
Expand Down
3 changes: 3 additions & 0 deletions units/CorBuildings/LandDefenceOffence/cortron.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ return {
weapontimer = 3,
weapontype = "StarburstLauncher",
weaponvelocity = 1200,
customparams = {
stockpilelimit = 10,
},
damage = {
commanders = 750,
default = 4000,
Expand Down
3 changes: 3 additions & 0 deletions units/CorShips/T2/corantiship.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
3 changes: 3 additions & 0 deletions units/CorShips/T2/corcarry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
1 change: 1 addition & 0 deletions units/CorShips/T2/cordesolator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ return {
customparams = {
place_target_on_ground = "true",
scavforcecommandfire = true,
stockpilelimit = 10,
},
damage = {
commanders = 2500,
Expand Down
3 changes: 3 additions & 0 deletions units/CorVehicles/T2/cormabm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ return {
weapontimer = 2,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 500,
},
Expand Down
1 change: 1 addition & 0 deletions units/Legion/Air/T2 Air/legmineb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ return {
bogus = 1,
spawns_name = "cormine1",
spawns_surface = "LAND",
stockpilelimit = 1,
},
damage = {
default = 1,
Expand Down
3 changes: 3 additions & 0 deletions units/Legion/Air/legmos.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ return {
weapontimer = 2,
weapontype = "MissileLauncher",
weaponvelocity = 400,
customparams = {
stockpilelimit = 8,
},
damage = {
default = 44,
},
Expand Down
5 changes: 4 additions & 1 deletion units/Legion/Defenses/legabm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ return {
select = {
[1] = "loadwtr1",
},
},
},
weapondefs = {
fmd_rocket = {
areaofeffect = 420,
Expand Down Expand Up @@ -148,6 +148,9 @@ return {
weapontimer = 2.5,
weapontype = "StarburstLauncher",
weaponvelocity = 6000,
customparams = {
stockpilelimit = 20,
},
damage = {
default = 1500,
},
Expand Down
3 changes: 2 additions & 1 deletion units/Legion/Defenses/legperdition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ return {
area_onhit_damage = 175,
area_onhit_range = 150,
area_onhit_time = 15,
stockpilelimit = 10,
},
damage = {
commanders = 700,
default = 2000,--plus 150*15 within 150 area
},
},

},
weapons = {
[1] = {
Expand Down
1 change: 1 addition & 0 deletions units/Legion/Defenses/legsilo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ return {
weaponvelocity = 1600,
customparams = {
place_target_on_ground = "true",
stockpilelimit = 10,
},
damage = {
commanders = 2500,
Expand Down
Loading

0 comments on commit d35d55b

Please sign in to comment.