forked from DFHack/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
max-wave.lua
36 lines (29 loc) · 1.1 KB
/
max-wave.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
local args = {...}
local wave_size = tonumber(args[1])
local max_pop = tonumber(args[2])
local current_pop = 0
if not wave_size then
print(dfhack.script_help())
qerror('max-wave: wave_size required')
end
local function isCitizen(unit)
return dfhack.units.isCitizen(unit) or
(dfhack.units.isOwnCiv(unit) and
dfhack.units.isAlive(unit) and
df.global.world.raws.creatures.all[unit.race].caste[unit.caste].flags.CAN_LEARN and
not (dfhack.units.isMerchant(unit) or dfhack.units.isForest(unit) or unit.flags1.diplomat or unit.flags2.visitor))
end
--One would think the game would track this value somewhere...
for k,v in ipairs(df.global.world.units.active) do
if isCitizen(v) then
current_pop = current_pop + 1
end
end
local new_limit = current_pop + wave_size
if max_pop and new_limit > max_pop then new_limit = max_pop end
if new_limit == df.global.d_init.population_cap then
print('max-wave: Population cap (' .. new_limit .. ') not changed, maximum population reached')
else
df.global.d_init.population_cap = new_limit
print('max-wave: Population cap set to ' .. new_limit)
end