Skip to content

Commit fd59eae

Browse files
committed
validate eggs before handling them
1 parent 9006144 commit fd59eae

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

eggwatch.lua

+25-2
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,33 @@ local function count_live_animals(race, count_children, count_adults)
321321
return count
322322
end
323323

324+
local function validate_eggs(eggs)
325+
if not eggs.egg_flags.fertile then
326+
print_details("Newly laid eggs are not fertile, do nothing")
327+
return false
328+
end
329+
330+
local should_be_nestbox = dfhack.items.getHolderBuilding(eggs)
331+
if should_be_nestbox ~= nil then
332+
for _, nestbox in ipairs(df.global.world.buildings.other.NEST_BOX) do
333+
if nestbox == should_be_nestbox then
334+
print_details("Found nestbox, continue with egg handling")
335+
return true
336+
end
337+
end
338+
print_details("Newly laid eggs are in building different than nestbox, we were to late")
339+
return false
340+
else
341+
print_details("Newly laid eggs are not in building, we were to late")
342+
return false
343+
end
344+
return true
345+
end
346+
324347
local function handle_eggs(eggs)
325348
print_details(("start handle_eggs"))
326-
if not eggs.egg_flags.fertile then
327-
print_local("Newly laid eggs are not fertile, do nothing")
349+
350+
if not validate_eggs(eggs) then
328351
return
329352
end
330353

0 commit comments

Comments
 (0)