Skip to content

Commit

Permalink
remove redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkow committed Sep 20, 2024
1 parent 4e414ba commit 2868fad
Showing 1 changed file with 1 addition and 75 deletions.
76 changes: 1 addition & 75 deletions plugins/lua/autobutcher/nestboxesEvent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,85 +5,11 @@ local printLocal = nestboxesCommon.printLocal
local printDetails = nestboxesCommon.printDetails
local utils = require('utils')
---------------------------------------------------------------------------------------------------
local function copyEggFields(source_egg, target_egg)
printDetails('start copyEggFields')
target_egg.incubation_counter = source_egg.incubation_counter
target_egg.egg_flags = utils.clone(source_egg.egg_flags)
target_egg.hatchling_flags1 = utils.clone(source_egg.hatchling_flags1)
target_egg.hatchling_flags2 = utils.clone(source_egg.hatchling_flags2)
target_egg.hatchling_flags3 = utils.clone(source_egg.hatchling_flags3)
target_egg.hatchling_flags4 = utils.clone(source_egg.hatchling_flags4)
target_egg.hatchling_training_level = source_egg.hatchling_training_level
target_egg.hatchling_mother_id = source_egg.hatchling_mother_id
target_egg.mother_hf = source_egg.mother_hf
target_egg.father_hf = source_egg.mother_hf
target_egg.mothers_caste = source_egg.mothers_caste
target_egg.fathers_caste = source_egg.fathers_caste

local mothers_genes = df.unit_genes:new()
mothers_genes.appearance:assign(source_egg.mothers_genes.appearance)
mothers_genes.colors:assign(source_egg.mothers_genes.colors)

local fathers_genes = df.unit_genes:new()
fathers_genes.appearance:assign(source_egg.fathers_genes.appearance)
fathers_genes.colors:assign(source_egg.fathers_genes.colors)

target_egg.mothers_genes = mothers_genes
target_egg.fathers_genes = fathers_genes
printDetails("mothers_genes fathers_genes done")

target_egg.hatchling_civ_id = source_egg.hatchling_civ_id
printDetails('hatchling_civ_id done')
printDetails('end copyEggFields')
end --copyEggFields
---------------------------------------------------------------------------------------------------
local function resizeEggStack(egg_stack, new_stack_size)
printDetails('start resizeEggStack')
egg_stack.stack_size = new_stack_size
--TODO check if weight or size need adjustment
printDetails('end resizeEggStack')
end --resizeEggStack
---------------------------------------------------------------------------------------------------
local function createNewEggStack(original_eggs, new_stack_count)
printDetails('start createNewEggStack')
printDetails('about to create new egg stack')
printDetails(('type= %s'):format(original_eggs:getType()))
printDetails(('creature= %s'):format(original_eggs.race))
printDetails(('caste= %s '):format(original_eggs.caste))
printDetails(('stack size for new eggs = %s '):format(new_stack_count))

local created_items =
dfhack.items.createItem(
df.unit.find(original_eggs.hatchling_mother_id),
original_eggs:getType(),
-1,
original_eggs.race,
original_eggs.caste
)
printDetails('created new egg stack')
local created_egg_stack = created_items[0] or created_items[1]
printDetails(df.creature_raw.find(created_egg_stack.race).creature_id)
printDetails('about to copy fields from orginal eggs')
copyEggFields(original_eggs, created_egg_stack)

printDetails('about to resize new egg stack')
resizeEggStack(created_egg_stack, new_stack_count)

printDetails('about to move new stack to nestbox')
if dfhack.items.moveToBuilding(created_egg_stack, dfhack.items.getHolderBuilding(original_eggs)) then
printDetails('moved new egg stack to nestbox')
else
printLocal('move of separated eggs to nestbox failed')
end
printDetails('end createNewEggStack')
end --createNewEggStack
---------------------------------------------------------------------------------------------------
local function splitEggStack(source_egg_stack, to_be_left_in_source_stack)
printDetails('start splitEggStack')
local egg_count_in_new_stack_size = source_egg_stack.stack_size - to_be_left_in_source_stack
if egg_count_in_new_stack_size > 0 then
createNewEggStack(source_egg_stack, egg_count_in_new_stack_size)
resizeEggStack(source_egg_stack, to_be_left_in_source_stack)
source_egg_stack:splitStack(egg_count_in_new_stack_size, true)
else
printDetails('nothing to do, wrong egg_count_in_new_stack_size')
end
Expand Down

0 comments on commit 2868fad

Please sign in to comment.