@@ -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---- -----------------------------------------------------------------------------------------------
3434local function getDefaultState ()
@@ -140,14 +140,14 @@ local function doDisable()
140140 printDetails ((' end doDisable' ))
141141end -- 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 ]
152152end -- getConfigForRace
153153---- -----------------------------------------------------------------------------------------------
@@ -169,7 +169,7 @@ local function validateCreatureOrRace(value)
169169 handleError ((' could not find %s' ):format (value ))
170170end -- 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 ()
212213end
213214---- -----------------------------------------------------------------------------------------------
215+ local function setIgnore (value )
216+ state .ignore_autobutcher = getBoolean (value )
217+ end
218+ ---- -----------------------------------------------------------------------------------------------
214219local function setVerbose (value )
215220 state .verbose = getBoolean (value )
216221 nestboxesCommon .verbose = state .verbose
217222end
218223---- -----------------------------------------------------------------------------------------------
219224local 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 ))
227232end
228233---- -----------------------------------------------------------------------------------------------
229234local 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))
246251end
247252---- -----------------------------------------------------------------------------------------------
248253local function handleOnStateChange (sc )
@@ -260,7 +265,7 @@ end --handleOnStateChange
260265---- -----------------------------------------------------------------------------------------------
261266local 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
280285end -- 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