@@ -139,35 +139,16 @@ local function count_forbidden_eggs_for_race_in_claimed_nestobxes(race_creature_
139139 return eggs_count
140140end
141141
142- local function get_max_eggs_for_race (race_creature_id )
142+ local function get_config_for_race (race_creature_id )
143+ print_detalis ((" getting config for race %s " ):format (race_creature_id ))
143144 for k , v in pairs (target_eggs_count_per_race ) do
144145 if k == race_creature_id then
145- return v [ 1 ]
146+ return v
146147 end
147148 end
148149 target_eggs_count_per_race [race_creature_id ] = target_eggs_count_per_race .DEFAULT
149150 persist_state ()
150- return target_eggs_count_per_race [race_creature_id ][1 ]
151- end
152-
153- local function count_children_for_race (race_creature_id )
154- for k , v in pairs (target_eggs_count_per_race ) do
155- if k == race_creature_id then
156- return v [2 ]
157- end
158- end
159- target_eggs_count_per_race [race_creature_id ] = target_eggs_count_per_race .DEFAULT
160- return target_eggs_count_per_race [race_creature_id ][2 ]
161- end
162-
163- local function count_adults_for_race (race_creature_id )
164- for k , v in pairs (target_eggs_count_per_race ) do
165- if k == race_creature_id then
166- return v [3 ]
167- end
168- end
169- target_eggs_count_per_race [race_creature_id ] = target_eggs_count_per_race .DEFAULT
170- return target_eggs_count_per_race [race_creature_id ][3 ]
151+ return target_eggs_count_per_race [race_creature_id ]
171152end
172153
173154local function is_valid_animal (unit )
@@ -178,17 +159,16 @@ local function is_valid_animal(unit)
178159 dfhack .units .isTame (unit ) and
179160 not dfhack .units .isDead (unit )
180161end
181- local function count_live_animals ( race_creature_id )
182- local count_adults = count_adults_for_race (race_creature_id )
162+
163+ local function count_live_animals (race_creature_id , count_children , count_adults )
183164 if count_adults then print_detalis ((' we are counting adults for %s' ):format (race_creature_id )) end
184- local count_children = count_children_for_race (race_creature_id )
185165 if count_children then print_detalis ((' we are counting children and babies for %s' ):format (race_creature_id )) end
186166
187167 local count = 0
188168 if not count_adults and not count_children then
189169 return count
190170 end
191- -- dfhack.units.isAdult(unit)
171+
192172 for _ ,unit in ipairs (df .global .world .units .active ) do
193173 if race_creature_id == df .creature_raw .find (unit .race ).creature_id
194174 and is_valid_animal (unit )
@@ -202,7 +182,6 @@ local function count_live_animals(race_creature_id)
202182 return count
203183end
204184
205-
206185local function handle_eggs (eggs )
207186 print_detalis ((" start handle_eggs" ))
208187 if not eggs .egg_flags .fertile then
@@ -211,15 +190,23 @@ local function handle_eggs(eggs)
211190 end
212191
213192 local race_creature_id = df .creature_raw .find (eggs .race ).creature_id
214- local max_eggs = get_max_eggs_for_race (race_creature_id )
193+ local race_config = get_config_for_race (race_creature_id )
194+ local max_eggs = race_config [1 ]
195+ local count_children = race_config [2 ]
196+ local count_adults = race_config [3 ]
197+
198+ print_detalis ((" max_eggs %s " ):format (max_eggs ))
199+ print_detalis ((" count_children %s " ):format (count_children ))
200+ print_detalis ((" count_adults %s " ):format (count_adults ))
201+
215202 local current_eggs = eggs .stack_size
216203
217204 local total_count = current_eggs
218205 total_count = total_count + count_forbidden_eggs_for_race_in_claimed_nestobxes (race_creature_id )
219206
220207 if total_count - current_eggs < max_eggs then
221208 print_detalis ((" Total count for %s only existing eggs is %s, about to count life animals if enabled" ):format (race_creature_id , total_count - current_eggs ))
222- total_count = total_count + count_live_animals (race_creature_id )
209+ total_count = total_count + count_live_animals (race_creature_id , count_children , count_adults )
223210 else
224211 print_detalis ((" Total count for %s eggs only is %s greater than maximum %s, no need to count life animals" ):format (race_creature_id , total_count , max_eggs ))
225212 return
0 commit comments