progress on apiary
This commit is contained in:
parent
8220389462
commit
1cac798f18
@ -1,6 +1,3 @@
|
|||||||
-- support for MT game translation.
|
|
||||||
local S = default.get_translator
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Formspecs
|
-- Formspecs
|
||||||
--
|
--
|
||||||
@ -96,21 +93,65 @@ local function swap_node(pos, name)
|
|||||||
minetest.swap_node(pos, node)
|
minetest.swap_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function bee_change_type(bee_name,final_type)
|
||||||
|
--given a bee_name it gives the same bee_name but with a different type, for example queen -> princess
|
||||||
|
return string.gsub(bee_name,"_.-","_"..final_type)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function apiary_result(queen)
|
||||||
|
--given a queen calculates the correct princess + drone output
|
||||||
|
--atm easy just returns the same princess and the same drone
|
||||||
|
local meta = queen:get_meta()
|
||||||
|
--the "meta" of the queen is the princess meta and the drone_"meta" is the drone meta
|
||||||
|
local princess = Bee(bee_change_type(queen:get_name(),"princess"),meta:get_string("active_gene"),meta:get_string("inactive_gene"))
|
||||||
|
local drone = Bee(bee_change_type(queen:get_name(),"drone"),meta:get_string("drone_active_gene"),meta:get_string("drone_inactive_gene"))
|
||||||
|
drone:set_count(2)
|
||||||
|
return princess, drone
|
||||||
|
end
|
||||||
|
|
||||||
local function apiary_node_timer(pos,elapsed)
|
local function apiary_node_timer(pos,elapsed)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
|
local src_time = meta:get_float("src_time") or 0 --how much time has passed since src started actioning
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local monarchlist, dronelist
|
local monarchlist, dronelist
|
||||||
local timer_elapsed = meta:get_int("timer_elapsed") or 0
|
local timer_elapsed = meta:get_int("timer_elapsed") or 0
|
||||||
meta:set_int("timer_elapsed", timer_elapsed + 1)
|
meta:set_int("timer_elapsed", timer_elapsed + 1)
|
||||||
local update = true
|
local update = true
|
||||||
local is_queen, is_princess, is_drone
|
local is_queen, is_princess, is_drone
|
||||||
|
local can_breed, can_live
|
||||||
|
local actionable
|
||||||
|
|
||||||
|
local breedtime = 5 --hardcoded for now
|
||||||
|
|
||||||
while elapsed > 0 and update do
|
while elapsed > 0 and update do
|
||||||
update = false
|
update = false
|
||||||
monarchlist = inv:get_list("monarch")
|
monarchlist = inv:get_list("monarch")
|
||||||
dronelist = inv:get_list("drone")
|
dronelist = inv:get_list("drone")
|
||||||
is_queen = minetest.get_item_group(monarchlist[1]:get_name(),"bee_queen") == 1
|
is_queen = minetest.get_item_group(monarchlist[1]:get_name(),"bee_queen") == 1
|
||||||
is_princess = minetest.get_item_group(monarchlist[1]:get_name(),"bee_queen") == 1
|
is_princess = minetest.get_item_group(monarchlist[1]:get_name(),"bee_princess") == 1
|
||||||
is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_queen") == 1
|
is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1
|
||||||
|
|
||||||
|
can_breed = is_princess and is_drone
|
||||||
|
can_live = is_queen
|
||||||
|
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 actionable check if things are ready
|
||||||
|
if actionable then
|
||||||
|
src_time = src_time + el
|
||||||
|
if src_time >= breedtime then
|
||||||
|
--if possible act accordingly to breed or live
|
||||||
|
if can_breed then
|
||||||
|
local queen = Bee(bee_change_type())
|
||||||
|
inv:set_stack("monarch",1,)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -434,4 +475,4 @@ minetest.register_craft({
|
|||||||
{"default:wood", "", "default:wood"},
|
{"default:wood", "", "default:wood"},
|
||||||
{"default:wood", "default:wood", "default:wood"},
|
{"default:wood", "default:wood", "default:wood"},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user