now breedtime and lifetime are different

This commit is contained in:
StochasticMouse 2024-10-08 15:30:57 +02:00
parent beba692c05
commit b909d5e8a0

View File

@ -105,7 +105,9 @@ local function apiary_node_timer(pos,elapsed)
local can_breed, can_live local can_breed, can_live
local actionable local actionable
local breedtime = 5 --hardcoded for now local breedtime = 1 --hardcoded for now
local lifetime = 10
local needed_time = 200 --just so that the formspecs doesnt make an error
while elapsed > 0 and update do while elapsed > 0 and update do
update = false update = false
@ -116,18 +118,26 @@ local function apiary_node_timer(pos,elapsed)
is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1 is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1
can_breed = is_princess and is_drone can_breed = is_princess and is_drone
can_live = is_queen can_live = is_queen --these two event are disjoint (there are no queen & princess)
actionable = can_breed or can_live actionable = can_breed or can_live
local el = elapsed
if actionable then -- adjust el to action duration
el = math.min(el, breedtime - src_time)
end
--if can_breed then -- adjust el to action duration
-- el = math.min(el, breedtime - src_time)
--end
--if can_live then -- adjust el to action duration
-- el = math.min(el, lifetime - src_time)
--end
local el = elapsed
--if actionable check if things are ready --if actionable check if things are ready
if actionable then if actionable then
--ternary expression if can_breed it evals to breedtime else lifetime
needed_time = (can_breed and {breedtime} or {lifetime})[1]
el = math.min(el, needed_time - src_time)
src_time = src_time + el src_time = src_time + el
if src_time >= breedtime then
if src_time >= needed_time then
--if possible act accordingly to breed or live --if possible act accordingly to breed or live
if can_breed then if can_breed then
local queen = forestry_bees.breed_princess_drone(monarchlist[1],dronelist[1]) local queen = forestry_bees.breed_princess_drone(monarchlist[1],dronelist[1])
@ -141,7 +151,7 @@ local function apiary_node_timer(pos,elapsed)
end end
inv:set_stack("monarch",1,queen) inv:set_stack("monarch",1,queen)
inv:set_stack("drone",1,final_drone) inv:set_stack("drone",1,final_drone)
src_time = src_time - breedtime src_time = src_time - needed_time
else --if actionable but not can_breed we have can_live else --if actionable but not can_breed we have can_live
local queen = monarchlist[1] local queen = monarchlist[1]
local princess, dronelistout = forestry_bees.apiary_result(queen) local princess, dronelistout = forestry_bees.apiary_result(queen)
@ -152,7 +162,7 @@ local function apiary_node_timer(pos,elapsed)
inv:add_item("dst",drone) inv:add_item("dst",drone)
end end
inv:set_stack("monarch",1,ItemStack()) inv:set_stack("monarch",1,ItemStack())
src_time = src_time - breedtime src_time = src_time - needed_time
update = true update = true
else else
dst_full = true dst_full = true
@ -171,15 +181,15 @@ local function apiary_node_timer(pos,elapsed)
-- --
local formspec local formspec
local item_state local item_state
local queen_percent = 0 local percent = 0
--by default timer doesnt restart --by default timer doesnt restart
local result = false local result = false
if actionable then if actionable then
queen_percent = math.floor(src_time / breedtime * 100) percent = math.floor(src_time / needed_time * 100)
if dst_full then if dst_full then
item_state = "100% (output full)" item_state = "100% (output full)"
else else
item_state = tostring(item_percent).."%" item_state = tostring(percent).."%"
end end
--make sure timer restarts --make sure timer restarts
result = true result = true
@ -191,7 +201,7 @@ local function apiary_node_timer(pos,elapsed)
end end
end end
formspec = forestry_bees.get_apiary_active_formspec(queen_percent) formspec = forestry_bees.get_apiary_active_formspec(percent)
meta:set_float("src_time", src_time) meta:set_float("src_time", src_time)
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)