now some mutations can be made biome specific
This commit is contained in:
parent
6113068335
commit
e099b13af2
@ -118,6 +118,17 @@ local function apiary_node_timer(pos,elapsed)
|
||||
is_princess = minetest.get_item_group(monarchlist[1]:get_name(),"bee_princess") == 1
|
||||
is_drone = minetest.get_item_group(dronelist[1]:get_name(),"bee_drone") == 1
|
||||
|
||||
--------------------fix for bees taken from creative (where the genes are not created by default)
|
||||
if (is_princess or is_queen) and (monarchlist[1]:get_meta():get_string("genes") == "") then
|
||||
inv:set_stack("monarch",1,forestry_bees.format_bee(monarchlist[1]))
|
||||
end
|
||||
if is_drone and (dronelist[1]:get_meta():get_string("genes") == "") then
|
||||
local count = dronelist[1]:get_count()
|
||||
local bee = forestry_bees.format_bee(dronelist[1])
|
||||
bee:set_count(count)
|
||||
inv:set_stack("drone",1,bee)
|
||||
end
|
||||
---------------------
|
||||
can_breed = is_princess and is_drone
|
||||
can_live = is_queen --these two event are disjoint (there are no queen & princess)
|
||||
actionable = can_breed or can_live
|
||||
@ -161,7 +172,7 @@ local function apiary_node_timer(pos,elapsed)
|
||||
src_time = src_time - needed_time
|
||||
else --if actionable but not can_breed we have can_live
|
||||
local queen = monarchlist[1]
|
||||
local princess, dronelistout = forestry_bees.apiary_result(queen)
|
||||
local princess, dronelistout = forestry_bees.apiary_result(queen, pos)
|
||||
|
||||
if inv:get_size("dst")-forestry_bees.stacks_in_inv(inv,"dst") >= 1 + #dronelistout then
|
||||
inv:add_item("dst",princess)
|
||||
|
@ -1,2 +1,2 @@
|
||||
--base multiplier for bee lifespan, default value is 27.5 to have parity with MC-forestry
|
||||
lifespan_multiplier = 1.0
|
||||
lifespan_multiplier = 0.05
|
||||
|
@ -43,6 +43,13 @@ function forestry_bees.stacks_in_inv(inv,listname)
|
||||
return result
|
||||
end
|
||||
|
||||
function forestry_bees.format_bee(bee)
|
||||
local name = bee:get_name()
|
||||
local meta = bee:get_meta()
|
||||
local genes = forestry_bees.return_all_genes_double(string.sub(string.match(string.match(name,":.*"),".*_"),2,-2))
|
||||
return forestry_bees.Bee(string.sub(string.match(string.sub(string.match(name,"_.*"),2),"_.*"),2),genes)
|
||||
end
|
||||
|
||||
function forestry_bees.breed_princess_drone(princess,drone)
|
||||
--local princess_meta = princess:get_meta()
|
||||
local princess_genes = minetest.deserialize(princess:get_meta():get_string("genes")) --princess_meta["genes"]
|
||||
@ -67,19 +74,20 @@ local function final_gene(gene1,gene2)
|
||||
return output
|
||||
end
|
||||
|
||||
local function mutation(type1,type2)
|
||||
local function mutation(type1,type2,pos)
|
||||
local out_table1 = {}
|
||||
local out_table2 = {}
|
||||
local mutation = {false, false}
|
||||
--check every possible mutation to see if we may obtain it
|
||||
if ( (not (forestry_bees.bee_mutations[type1] == nil)) and (not (forestry_bees.bee_mutations[type1][type2] == nil)) ) then
|
||||
for out_type, chance in pairs(forestry_bees.bee_mutations[type1][type2]) do
|
||||
for out_type, t in pairs(forestry_bees.bee_mutations[type1][type2]) do
|
||||
local prob1 = math.random()
|
||||
local prob2 = math.random()
|
||||
if chance > prob1 then
|
||||
local flag = t["check_fun"](pos)
|
||||
if (t["chance"] > prob1) and flag then
|
||||
table.insert(out_table1, out_type)
|
||||
end
|
||||
if chance > prob2 then
|
||||
if (t["chance"] > prob2) and flag then
|
||||
table.insert(out_table2, out_type)
|
||||
end
|
||||
end
|
||||
@ -110,12 +118,12 @@ local function choose_genes(genes)
|
||||
return output
|
||||
end
|
||||
|
||||
local function output_genes(mother_genes,father_genes)
|
||||
local function output_genes(mother_genes,father_genes,pos)
|
||||
local mother_chosen_genes = choose_genes(mother_genes)
|
||||
local father_chosen_genes = choose_genes(father_genes)
|
||||
local genes = {}
|
||||
|
||||
genes["type_gene"], is_mutated = mutation(mother_chosen_genes["type_gene"], father_chosen_genes["type_gene"])
|
||||
genes["type_gene"], is_mutated = mutation(mother_chosen_genes["type_gene"], father_chosen_genes["type_gene"],pos)
|
||||
|
||||
for key,_ in pairs(mother_chosen_genes) do
|
||||
--if key == "type_gene" then
|
||||
@ -138,18 +146,18 @@ local function output_genes(mother_genes,father_genes)
|
||||
return genes
|
||||
end
|
||||
|
||||
function forestry_bees.apiary_result(queen)
|
||||
function forestry_bees.apiary_result(queen, pos)
|
||||
--given a queen calculates the correct princess + drone output
|
||||
local meta = queen:get_meta()
|
||||
local mother_genes = minetest.deserialize(meta:get_string("genes"))
|
||||
local father_genes = minetest.deserialize(meta:get_string("drone_genes"))
|
||||
local genes = output_genes(mother_genes,father_genes)
|
||||
local genes = output_genes(mother_genes,father_genes,pos)
|
||||
--local genes = final_gene(mother_chosen_gene, father_chosen_gene)
|
||||
local princess = forestry_bees.Bee("princess", genes)
|
||||
local dronelist = {}
|
||||
local fertility = mother_genes["fertility"][1]
|
||||
for i=1,fertility do
|
||||
local genes = output_genes(mother_genes,father_genes)
|
||||
local genes = output_genes(mother_genes,father_genes,pos)
|
||||
local drone = forestry_bees.Bee("drone", genes)
|
||||
table.insert(dronelist, drone)
|
||||
end
|
||||
|
@ -1,6 +1,14 @@
|
||||
forestry_bees.bee_mutations = {}
|
||||
|
||||
local function register_mutation(bee_type_in1,bee_type_in2,bee_type_out,chance)
|
||||
local function fun_true(pos) return true end
|
||||
|
||||
local function check_biome(biome)
|
||||
return function(pos)
|
||||
return (minetest.get_biome_name(minetest.get_biome_data(pos)["biome"]) == biome)
|
||||
end
|
||||
end
|
||||
|
||||
local function register_mutation(bee_type_in1,bee_type_in2,bee_type_out,chance,check_fun)
|
||||
--bee_type_in are string of the gene ex. "forest" or "meadows"
|
||||
--bee_type_out is a string of the gene
|
||||
--chance is the base probability of the mutation
|
||||
@ -23,22 +31,22 @@ local function register_mutation(bee_type_in1,bee_type_in2,bee_type_out,chance)
|
||||
forestry_bees.bee_mutations[bee_type_in2][bee_type_in1] = {}
|
||||
end
|
||||
|
||||
forestry_bees.bee_mutations[bee_type_in1][bee_type_in2][bee_type_out] = chance
|
||||
forestry_bees.bee_mutations[bee_type_in2][bee_type_in1][bee_type_out] = chance
|
||||
forestry_bees.bee_mutations[bee_type_in1][bee_type_in2][bee_type_out] = {chance = chance, check_fun = check_fun}
|
||||
forestry_bees.bee_mutations[bee_type_in2][bee_type_in1][bee_type_out] = {chance = chance, check_fun = check_fun}
|
||||
end
|
||||
|
||||
--common branch
|
||||
register_mutation("forest","meadows","common",0.15)
|
||||
register_mutation("forest","common","cultivated",0.12)
|
||||
register_mutation("meadows","common","cultivated",0.12)
|
||||
register_mutation("forest","meadows","common",0.15,fun_true)
|
||||
register_mutation("forest","common","cultivated",0.12,fun_true)
|
||||
register_mutation("meadows","common","cultivated",0.12,fun_true)
|
||||
--noble branch
|
||||
register_mutation("common","cultivated","noble",0.10)
|
||||
register_mutation("noble","cultivated","majestic",0.08)
|
||||
register_mutation("noble","majestic","imperial",0.08)
|
||||
register_mutation("common","cultivated","noble",0.10,fun_true)
|
||||
register_mutation("noble","cultivated","majestic",0.08,fun_true)
|
||||
register_mutation("noble","majestic","imperial",0.08,fun_true)
|
||||
--industrious branch
|
||||
register_mutation("common","cultivated","diligent",0.10)
|
||||
register_mutation("diligent","cultivated","unweary",0.08)
|
||||
register_mutation("diligent","unweary","industrious",0.08)
|
||||
register_mutation("common","cultivated","diligent",0.10,fun_true)
|
||||
register_mutation("diligent","cultivated","unweary",0.08,fun_true)
|
||||
register_mutation("diligent","unweary","industrious",0.08,fun_true)
|
||||
---heroic branch
|
||||
---infernal branch
|
||||
--- austere branch
|
||||
@ -47,7 +55,7 @@ register_mutation("diligent","unweary","industrious",0.08)
|
||||
---frozen branch
|
||||
---festive branch
|
||||
--agrarian branch
|
||||
register_mutation("diligent","meadows","rural",0.12) --ATTENTION WE SHOULD RESTRICT THIS TO THE PLAINS BIOME
|
||||
register_mutation("diligent","meadows","rural",0.12,check_biome("grassland"))
|
||||
|
||||
|
||||
--print(forestry_bees.mutations["meadows"]["forest"]["common"])
|
||||
|
@ -9,6 +9,9 @@ end
|
||||
local function printbeestats(itemstack, user, pointed_thing)
|
||||
local meta = itemstack:get_meta()
|
||||
local name = itemstack:get_name()
|
||||
-- if meta:get_string("genes") == "" then
|
||||
-- meta:set_string("genes", minetest.serialize(forestry_bees.return_all_genes_double(string.sub(string.match(string.match(name,":.*"),".*_"),2,-2))))
|
||||
-- end
|
||||
minetest.chat_send_player(user:get_player_name(), "Name: "..string.sub(string.match(name, ":.*"),2).."\nGenes:"..string.gsub(meta:get_string("genes"), "return", "") )
|
||||
--minetest.chat_send_player(user:get_player_name(), "Name:"..string.sub(string.match(name, ":.*"),2)..", Active:"..minetest.deserialize(meta:get_string("genes"))["type_gene"][1]..", Inactive:"..minetest.deserialize(meta:get_string("genes"))["type_gene"][2])
|
||||
end
|
||||
@ -20,6 +23,7 @@ local function register_bee(name, color1, color2)
|
||||
"princess.body2.png",
|
||||
"princess.outline.png",color1,color2),
|
||||
on_use = printbeestats,
|
||||
stack_max = 1,
|
||||
groups = {bee_princess=1, bee_monarch=1},
|
||||
})
|
||||
minetest.register_craftitem("forestry_bees:"..name.."_drone", {
|
||||
@ -36,6 +40,7 @@ local function register_bee(name, color1, color2)
|
||||
"queen.body2.png",
|
||||
"queen.outline.png",color1,color2),
|
||||
on_use = printbeestats,
|
||||
stack_max = 1,
|
||||
groups = {bee_queen=1, bee_monarch=1},
|
||||
})
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user