Skip to content

Commit de77231

Browse files
committed
add description to autobutcher.rst, take autobutcher setting into account when checking and adding config for new race
1 parent 184798f commit de77231

File tree

4 files changed

+180
-74
lines changed

4 files changed

+180
-74
lines changed

docs/plugins/autobutcher.rst

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ The default targets are: 2 male kids, 4 female kids, 2 male adults, and
3030
4 female adults. Note that you may need to set a target above 1 to have a
3131
reliable breeding population due to asexuality etc.
3232

33+
Nestboxes module extends autobutcher functionality to monitoring and protection
34+
of fertile eggs. It facilitates steady supplay of eggs protected for breading
35+
purposes while maintaining egg based food production. With default settings it
36+
will forbid fertile eggs in claimed nestboxes up to 4 + number of annimals
37+
missing to autobutcher target. This will allow for larger number of hatchilings
38+
in initial breadin program phase when increasing livestock.
39+
When population reaches intended target only base amount of eggs will be left
40+
for breading purpose.
41+
It is possible to alter this behaviour and compleatly stop protection of eggs
42+
when population target is reached.
43+
In case of clutch larger than needed target eggs will be split in two separate
44+
stacks and only one of them forbidden.
45+
Check for forbidding eggs is made when fertile eggs are laid for one of
46+
watched races.
47+
3348
Usage
3449
-----
3550

@@ -78,6 +93,50 @@ Usage
7893
``autobutcher list_export``
7994
Print commands required to set the current settings in another fort.
8095

96+
``autobutcher nestboxes enable (autobutcher nb e)``
97+
``autobutcher nestboxes disable (autobutcher nb d)``
98+
99+
It is possible to enable/ disable autobutcher nestboxes module.
100+
101+
``autobutcher nestboxes ignore <true/false> (autobutcher nb i <1/0>)``
102+
103+
By default nestboxes module respects main plugin's enabled status,
104+
autowatch and watched status for specific races.
105+
It is possible to allow nestboxes module to ignore that and work
106+
on it's own. In case like that missing animal count will not be added
107+
to target of protected eggs.
108+
109+
``autobutcher nestboxes target <race> <base_target> <ama> <stop> <watched>``
110+
``autobutcher nb t <race> <base_target> <ama> <stop> <watched>``
111+
112+
Nestboxes target command allows to change how script handles specific
113+
animal race, DEFAULT settings for new races or ALL curently watched races
114+
and default value for new ones.
115+
<race> parameter accepts "DEFAULT", "ALL", creature id (e.g. BIRD_TURKEY)
116+
or race id (190 for Turkey)
117+
<base_target> base number of fertile eggs that will be protected by
118+
frobidding them in nestboxes. Default 4.
119+
<ama> true/false value, if set to true animal count missing to autobutcher
120+
popualtion targets will be added to base target for protected eggs.
121+
Default true.
122+
<stop> if set to true module will stop protection of eggs for race as long
123+
as population target is maintained. Default true.
124+
<watched> If eggs laid by race should be monitored and protected.
125+
Default true.
126+
If parameter is not specified already existing value will be mantained.
127+
If new race is added missing values will be taken from default settings.
128+
129+
``autobutcher nestboxes split_stacks <true/false> (autobutcher nb s <1/0>)``
130+
131+
split_stacks command allows to specify how egg stacks that are only
132+
partialy over target should be handled. If set to false whole stack will
133+
be forbidden. If set to true only eggs below target will be forbidden,
134+
remaining part of stack will be separated and left for dwarves to collect.
135+
136+
``autobutcher nestboxes clear (autobutcher nb clear)``
137+
138+
Remove all settings for module and restore them to initial default values.
139+
81140
To see a list of all races, run this command::
82141

83142
devel/query --table df.global.world.raws.creatures.all --search ^creature_id --maxdepth 1
@@ -116,3 +175,27 @@ fortress::
116175
autobutcher target 2 2 4 2 ALPACA SHEEP LLAMA
117176
autobutcher target 5 5 6 2 PIG
118177
autobutcher target 0 0 0 0 new
178+
179+
180+
autobutcher nb t BEAK_DOG 10 1 1 1
181+
autobutcher nestboxes target BEAK_DOG 5 true true true
182+
183+
Command sets base target for beak dog eggs to 5, animals missing to population tresholds will be added to base target.
184+
Once autobutcher population target is reached no new eggs will be forbidden as long as population is at or above target.
185+
186+
autobutcher nb t DEFAULT 4 1 0 0
187+
autobutcher nestboxes target DEFAULT 4 true true false
188+
189+
Command will change default settings for watching new races disabling it.
190+
191+
autobutcher nb t ALL 15 0 1 1
192+
autobutcher nestboxes target ALL 15 false true true
193+
194+
Command will change setting for all currently watched egg races as well as default ones.
195+
Target for protected eggs is set to 15, missing animals count to livestock targets is not taken into account.
196+
Once population target is reached eggs will no longer be protected. All current and new races will be watched.
197+
198+
autobutcher nestboxes split_stacks false
199+
autobutcher nb s 0
200+
201+
Disable spliting of egg stacks.

plugins/autobutcher.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static int autobutcher_getInfoForNestboxes(lua_State* L) {
983983
int raceId = lua_tointeger(L, 1);
984984
lua_newtable(L);
985985
int ctable = lua_gettop(L);
986-
Lua::SetField(L, config.get_bool(CONFIG_IS_ENABLED), ctable, "autobutcher_enabled");
986+
Lua::SetField(L, config.get_bool(CONFIG_IS_ENABLED), ctable, "enabled");
987987

988988
if (!out)
989989
out = &Core::getInstance().getConsole();

plugins/lua/autobutcher/nestboxes.lua

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ local default_table = {
2828
watched = true, -- monitor eggs for race
2929
target = 4, --basic target for protected(forbidden) eggs
3030
ama = true, --Add Missing Animals to basic target for prottected eggs, difference between current amount of animals and target set for autobutcher, speeds up population growth in initial phase whiile limitting population explosion near end if egg target has low value
31-
full_stop = false -- stop protecting eggs once autobutcher target for live animals is reached
31+
stop = true -- stop protecting eggs once autobutcher target for live animals is reached
3232
}
3333
---------------------------------------------------------------------------------------------------
3434
local function getDefaultState()
@@ -140,14 +140,14 @@ local function doDisable()
140140
printDetails(('end doDisable'))
141141
end --doDisable
142142
---------------------------------------------------------------------------------------------------
143-
local function getConfigForRace(race)
143+
local function getConfigForRace(race , autobutcher_watched)
144144
printDetails(('start getConfigForRace'))
145145
printDetails(('getting config for race %s '):format(race))
146-
if state.config_per_race[race] == nil then
146+
if state.config_per_race[race] == nil and autobutcher_watched and state.default.watched then
147147
state.config_per_race[race] = state.default
148148
persistState()
149149
end
150-
printDetails(('end 2 getConfigForRace'))
150+
printDetails(('end getConfigForRace'))
151151
return state.config_per_race[race]
152152
end --getConfigForRace
153153
---------------------------------------------------------------------------------------------------
@@ -169,7 +169,7 @@ local function validateCreatureOrRace(value)
169169
handleError(('could not find %s'):format(value))
170170
end --validateCreatureOrRace
171171
---------------------------------------------------------------------------------------------------
172-
local function setTarget(target_race, target_count, add_missing_animals, full_stop, watch_race)
172+
local function setTarget(target_race, target_count, add_missing_animals, stop, watch_race)
173173
printDetails(('start setTarget'))
174174

175175
if type(target_race) == 'string' then
@@ -184,7 +184,7 @@ local function setTarget(target_race, target_count, add_missing_animals, full_st
184184
watched = getBoolean(watch_race),
185185
target = tonumber(target_count),
186186
ama = getBoolean(add_missing_animals),
187-
full_stop = getBoolean(full_stop)
187+
stop = getBoolean(stop)
188188
}
189189

190190
local race = validateCreatureOrRace(target_race)
@@ -193,6 +193,7 @@ local function setTarget(target_race, target_count, add_missing_animals, full_st
193193
elseif race == 'ALL' then
194194
for _, v in pairs(state.config_per_race) do
195195
utils.assign(v, new_config)
196+
utils.assign(state.default, new_config)
196197
end
197198
elseif race >= 0 then
198199
utils.assign(state.config_per_race[race], new_config)
@@ -211,26 +212,30 @@ local function clearConfig()
211212
updateEventListener()
212213
end
213214
---------------------------------------------------------------------------------------------------
215+
local function setIgnore(value)
216+
state.ignore_autobutcher = getBoolean(value)
217+
end
218+
---------------------------------------------------------------------------------------------------
214219
local function setVerbose(value)
215220
state.verbose = getBoolean(value)
216221
nestboxesCommon.verbose = state.verbose
217222
end
218223
---------------------------------------------------------------------------------------------------
219224
local function format_target_count_row(category, row)
220-
return (('%s: watched %s; target %s; add missing animals %s; full stop once animal target reached %s'):format(
225+
return (('%s: watched: %s; target: %s; ama: %s; stop: %s'):format(
221226
category,
222227
row.watched and 'enabled' or 'disabled',
223228
tostring(row.target),
224229
row.ama and 'enabled' or 'disabled',
225-
row.full_stop and 'enabled' or 'disabled'
230+
row.stop and 'enabled' or 'disabled'
226231
))
227232
end
228233
---------------------------------------------------------------------------------------------------
229234
local function printStatus()
230-
printLocal(('Script is currently %s.'):format(state.enabled and 'enabled' or 'disabled'))
231-
printLocal(('Egg stack splitting is %s'):format(state.split_stacks and 'enabled' or 'disabled'))
235+
printLocal(('Status %s.'):format(state.enabled and 'enabled' or 'disabled'))
236+
printLocal(('Stack splitting: %s'):format(state.split_stacks and 'enabled' or 'disabled'))
232237
printLocal(
233-
('Script is %s autobutcher\'s enabled status'):format(state.ignore_autobutcher and 'ignoring' or 'respecting')
238+
('%s autobutcher\'s enabled status'):format(state.ignore_autobutcher and 'Ignoring' or 'Tespecting')
234239
)
235240
printDetails(('verbose mode is %s'):format(state.verbose and 'enabled' or 'disabled'))
236241
printDetails(
@@ -242,7 +247,7 @@ local function printStatus()
242247
printLocal(format_target_count_row(df.global.world.raws.creatures.all[k].creature_id, v))
243248
end
244249
end
245-
printDetails(dumpToString(state))
250+
--printDetails(dumpToString(state))
246251
end
247252
---------------------------------------------------------------------------------------------------
248253
local function handleOnStateChange(sc)
@@ -260,7 +265,7 @@ end --handleOnStateChange
260265
---------------------------------------------------------------------------------------------------
261266
local function getInfoFromAutobutcher(race)
262267
local v_return = {
263-
autobutcher_enabled = false,
268+
enabled = false,
264269
watched = false,
265270
mac = 0
266271
}
@@ -279,29 +284,6 @@ local function getInfoFromAutobutcher(race)
279284
return v_return
280285
end --getInfoFromAutobutcher
281286
---------------------------------------------------------------------------------------------------
282-
local function validateEggs(eggs)
283-
if not eggs.egg_flags.fertile then
284-
printDetails('Newly laid eggs are not fertile, do nothing')
285-
return false
286-
end
287-
288-
local should_be_nestbox = dfhack.items.getHolderBuilding(eggs)
289-
if should_be_nestbox ~= nil then
290-
for _, nestbox in ipairs(df.global.world.buildings.other.NEST_BOX) do
291-
if nestbox == should_be_nestbox then
292-
printDetails('Found nestbox, continue with egg handling')
293-
return true
294-
end
295-
end
296-
printDetails('Newly laid eggs are in building different than nestbox, we were to late')
297-
return false
298-
else
299-
printDetails('Newly laid eggs are not in building, we were to late')
300-
return false
301-
end
302-
return true
303-
end --validateEggs
304-
---------------------------------------------------------------------------------------------------
305287
--<Global functions>
306288
---------------------------------------------------------------------------------------------------
307289
-- checkItemCreated function, called from eventfful on ITEM_CREATED event
@@ -310,16 +292,21 @@ function checkItemCreated(item_id)
310292
if item == nil or df.item_type.EGG ~= item:getType() then
311293
return
312294
else
313-
if validateEggs(item) then
295+
if nestboxesEvent.validateEggs(item) then
314296
local autobutcher_info = getInfoFromAutobutcher(item.race)
315-
local race_config = getConfigForRace(item.race)
297+
298+
local race_config = getConfigForRace(item.race, (autobutcher_info.watched and autobutcher_info.enabled) or state.ignore_autobutcher)
299+
if race_config == nil then -- if nil new race without config and no new races are being watched
300+
return
301+
end
316302
if
317-
(((autobutcher_info.watched and autobutcher_info.autobutcher_enabled and not state.ignore_autobutcher -- check eggs respecting autobutcher settings
318-
and not (race_config.full_stop and autobutcher_info.mac == 0)) -- do not check eggs if reached animal targets for race and full stop enabled
303+
(((autobutcher_info.watched and autobutcher_info.enabled and not state.ignore_autobutcher -- check eggs respecting autobutcher settings
304+
and not (race_config.stop and autobutcher_info.mac == 0)) -- do not check eggs if reached animal targets for race and full stop enabled
319305
or state.ignore_autobutcher) -- or check eggs ignoring autobutcher settings
320-
and race_config.watched)-- check eggs only when nestboxes is watching race
306+
and race_config.watched -- check eggs only when nestboxes is watching race
307+
)
321308
then
322-
nestboxesEvent.handleEggs(item, race_config, state.split_stacks, autobutcher_info.mac)
309+
nestboxesEvent.handleEggs(item, race_config.target, race_config.ama, state.split_stacks, autobutcher_info.mac)
323310
end
324311
end
325312
end
@@ -345,6 +332,8 @@ function handleCommand(positionals, opts)
345332
updateEventListener()
346333
elseif command == 'TARGET' or command == 'T' then
347334
setTarget(positionals[3], positionals[4], positionals[5], positionals[6], positionals[7])
335+
elseif command == 'IGNORE' or command == 'I' then
336+
setIgnore(positionals[3])
348337
elseif command == 'VERBOSE' or command == 'V' then
349338
setVerbose(positionals[3])
350339
elseif command == 'SPLIT_STACKS' or command == 'S' then

0 commit comments

Comments
 (0)