v50 Steam/Premium information for editors
- v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
- Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.
Difference between revisions of "User:Fleeting Frames/max-wave"
Jump to navigation
Jump to search
(Initial writeup) |
m (Noted original author) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Usage: Save into /hack/scripts folder as max-wave.lua script, put 'repeat -time 1 -timeUnits months -command [ max-wave 10 80 ]' in onMapLoad.init | Usage: Save into /hack/scripts folder as max-wave.lua script, put 'repeat -time 1 -timeUnits months -command [ max-wave 10 80 ]' in onMapLoad.init | ||
− | < | + | (Original written by Loci [http://www.bay12forums.com/smf/index.php?topic=158503.msg7027874#msg7027874 here].) |
+ | |||
+ | <source lang="lua"> | ||
--Dynamically limit the next immigration wave | --Dynamically limit the next immigration wave | ||
--[[=begin | --[[=begin | ||
Line 14: | Line 16: | ||
max-wave wave_size (max_pop) | max-wave wave_size (max_pop) | ||
− | repeat -time 1 -timeUnits months -command [ max-wave 10 | + | repeat -time 1 -timeUnits months -command [ max-wave 10 200 ] |
The first example is abstract and only sets the population cap once; | The first example is abstract and only sets the population cap once; | ||
the second will update the population cap monthly, allowing a | the second will update the population cap monthly, allowing a | ||
− | maximum of 10 immigrants per wave, up to a total population of | + | maximum of 10 immigrants per wave, up to a total population of 200. |
=end]] | =end]] | ||
Line 35: | Line 37: | ||
--One would think the game would track this value somewhere... | --One would think the game would track this value somewhere... | ||
for k,v in ipairs(df.global.world.units.active) do | for k,v in ipairs(df.global.world.units.active) do | ||
− | if dfhack.units.isCitizen(v) or (dfhack.units.isOwnCiv(v) and dfhack.units.isAlive(v) and | + | if dfhack.units.isCitizen(v) or |
+ | (dfhack.units.isOwnCiv(v) and | ||
+ | dfhack.units.isAlive(v) and | ||
+ | df.global.world.raws.creatures.all[v.race].caste[v.caste].flags.CAN_LEARN and | ||
+ | not (dfhack.units.isMerchant(v) or dfhack.units.isForest(v) or v.flags1.diplomat or v.flags2.visitor) | ||
+ | ) | ||
+ | then | ||
current_pop = current_pop + 1 | current_pop = current_pop + 1 | ||
end | end | ||
Line 46: | Line 54: | ||
df.global.d_init.population_cap = new_limit | df.global.d_init.population_cap = new_limit | ||
print('max-wave: Population cap set to '.. new_limit) | print('max-wave: Population cap set to '.. new_limit) | ||
− | </ | + | </source> |
Latest revision as of 23:09, 7 May 2020
Usage: Save into /hack/scripts folder as max-wave.lua script, put 'repeat -time 1 -timeUnits months -command [ max-wave 10 80 ]' in onMapLoad.init
(Original written by Loci here.)
--Dynamically limit the next immigration wave
--[[=begin
max-wave.lua
============
Set the population cap to the lesser of current_pop + wave_size or max_pop.
Use with the `repeat` command to set a rolling immigration limit.
Usage examples::
max-wave wave_size (max_pop)
repeat -time 1 -timeUnits months -command [ max-wave 10 200 ]
The first example is abstract and only sets the population cap once;
the second will update the population cap monthly, allowing a
maximum of 10 immigrants per wave, up to a total population of 200.
=end]]
local args = {...}
local wave_size = tonumber(args[1])
local max_pop = tonumber(args[2])
local current_pop = 0
if not wave_size then
print('max-wave: wave_size required')
return
end
--One would think the game would track this value somewhere...
for k,v in ipairs(df.global.world.units.active) do
if dfhack.units.isCitizen(v) or
(dfhack.units.isOwnCiv(v) and
dfhack.units.isAlive(v) and
df.global.world.raws.creatures.all[v.race].caste[v.caste].flags.CAN_LEARN and
not (dfhack.units.isMerchant(v) or dfhack.units.isForest(v) or v.flags1.diplomat or v.flags2.visitor)
)
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
df.global.d_init.population_cap = new_limit
print('max-wave: Population cap set to '.. new_limit)