@@ -5,85 +5,11 @@ local printLocal = nestboxesCommon.printLocal
55local printDetails = nestboxesCommon .printDetails
66local utils = require (' utils' )
77---- -----------------------------------------------------------------------------------------------
8- local function copyEggFields (source_egg , target_egg )
9- printDetails (' start copyEggFields' )
10- target_egg .incubation_counter = source_egg .incubation_counter
11- target_egg .egg_flags = utils .clone (source_egg .egg_flags )
12- target_egg .hatchling_flags1 = utils .clone (source_egg .hatchling_flags1 )
13- target_egg .hatchling_flags2 = utils .clone (source_egg .hatchling_flags2 )
14- target_egg .hatchling_flags3 = utils .clone (source_egg .hatchling_flags3 )
15- target_egg .hatchling_flags4 = utils .clone (source_egg .hatchling_flags4 )
16- target_egg .hatchling_training_level = source_egg .hatchling_training_level
17- target_egg .hatchling_mother_id = source_egg .hatchling_mother_id
18- target_egg .mother_hf = source_egg .mother_hf
19- target_egg .father_hf = source_egg .mother_hf
20- target_egg .mothers_caste = source_egg .mothers_caste
21- target_egg .fathers_caste = source_egg .fathers_caste
22-
23- local mothers_genes = df .unit_genes :new ()
24- mothers_genes .appearance :assign (source_egg .mothers_genes .appearance )
25- mothers_genes .colors :assign (source_egg .mothers_genes .colors )
26-
27- local fathers_genes = df .unit_genes :new ()
28- fathers_genes .appearance :assign (source_egg .fathers_genes .appearance )
29- fathers_genes .colors :assign (source_egg .fathers_genes .colors )
30-
31- target_egg .mothers_genes = mothers_genes
32- target_egg .fathers_genes = fathers_genes
33- printDetails (" mothers_genes fathers_genes done" )
34-
35- target_egg .hatchling_civ_id = source_egg .hatchling_civ_id
36- printDetails (' hatchling_civ_id done' )
37- printDetails (' end copyEggFields' )
38- end -- copyEggFields
39- ---- -----------------------------------------------------------------------------------------------
40- local function resizeEggStack (egg_stack , new_stack_size )
41- printDetails (' start resizeEggStack' )
42- egg_stack .stack_size = new_stack_size
43- -- TODO check if weight or size need adjustment
44- printDetails (' end resizeEggStack' )
45- end -- resizeEggStack
46- ---- -----------------------------------------------------------------------------------------------
47- local function createNewEggStack (original_eggs , new_stack_count )
48- printDetails (' start createNewEggStack' )
49- printDetails (' about to create new egg stack' )
50- printDetails ((' type= %s' ):format (original_eggs :getType ()))
51- printDetails ((' creature= %s' ):format (original_eggs .race ))
52- printDetails ((' caste= %s ' ):format (original_eggs .caste ))
53- printDetails ((' stack size for new eggs = %s ' ):format (new_stack_count ))
54-
55- local created_items =
56- dfhack .items .createItem (
57- df .unit .find (original_eggs .hatchling_mother_id ),
58- original_eggs :getType (),
59- - 1 ,
60- original_eggs .race ,
61- original_eggs .caste
62- )
63- printDetails (' created new egg stack' )
64- local created_egg_stack = created_items [0 ] or created_items [1 ]
65- printDetails (df .creature_raw .find (created_egg_stack .race ).creature_id )
66- printDetails (' about to copy fields from orginal eggs' )
67- copyEggFields (original_eggs , created_egg_stack )
68-
69- printDetails (' about to resize new egg stack' )
70- resizeEggStack (created_egg_stack , new_stack_count )
71-
72- printDetails (' about to move new stack to nestbox' )
73- if dfhack .items .moveToBuilding (created_egg_stack , dfhack .items .getHolderBuilding (original_eggs )) then
74- printDetails (' moved new egg stack to nestbox' )
75- else
76- printLocal (' move of separated eggs to nestbox failed' )
77- end
78- printDetails (' end createNewEggStack' )
79- end -- createNewEggStack
80- ---- -----------------------------------------------------------------------------------------------
818local function splitEggStack (source_egg_stack , to_be_left_in_source_stack )
829 printDetails (' start splitEggStack' )
8310 local egg_count_in_new_stack_size = source_egg_stack .stack_size - to_be_left_in_source_stack
8411 if egg_count_in_new_stack_size > 0 then
85- createNewEggStack (source_egg_stack , egg_count_in_new_stack_size )
86- resizeEggStack (source_egg_stack , to_be_left_in_source_stack )
12+ source_egg_stack :splitStack (egg_count_in_new_stack_size , true )
8713 else
8814 printDetails (' nothing to do, wrong egg_count_in_new_stack_size' )
8915 end
0 commit comments