mutations added, also fixed textures
This commit is contained in:
parent
95c1c2d5b7
commit
1ff9bce3d2
@ -93,29 +93,6 @@ local function swap_node(pos, name)
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
local function breed_princess_drone(princess,drone)
|
||||
local princess_meta = princess:get_meta()
|
||||
local drone_meta = drone:get_meta()
|
||||
local queen = forestry_bees.Bee("queen",
|
||||
princess_meta:get_string("active_gene"),
|
||||
princess_meta:get_string("inactive_gene"))
|
||||
local queen_meta = queen:get_meta()
|
||||
queen_meta:set_string("drone_active_gene",drone_meta:get_string("active_gene"))
|
||||
queen_meta:set_string("drone_inactive_gene",drone_meta:get_string("inactive_gene"))
|
||||
return queen
|
||||
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 = forestry_bees.Bee("princess",meta:get_string("active_gene"),meta:get_string("inactive_gene"))
|
||||
local drone = forestry_bees.Bee("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 meta = minetest.get_meta(pos)
|
||||
local src_time = meta:get_float("src_time") or 0 --how much time has passed since src started actioning
|
||||
@ -153,28 +130,31 @@ local function apiary_node_timer(pos,elapsed)
|
||||
if src_time >= breedtime then
|
||||
--if possible act accordingly to breed or live
|
||||
if can_breed then
|
||||
local queen = breed_princess_drone(monarchlist[1],dronelist[1])
|
||||
local queen = forestry_bees.breed_princess_drone(monarchlist[1],dronelist[1])
|
||||
local drone_count = dronelist[1]:get_count()
|
||||
if drone_count >1 then
|
||||
local final_drone = dronelist[1]:set_count(dronelist[1]:get_count()-1)
|
||||
else
|
||||
local final_drone
|
||||
if drone_count == 1 then
|
||||
final_drone = ItemStack()
|
||||
else
|
||||
dronelist[1]:set_count(drone_count - 1)
|
||||
final_drone = dronelist[1]
|
||||
end
|
||||
inv:set_stack("monarch",1,queen)
|
||||
inv:set_stack("drone",1,final_drone)
|
||||
src_time = src_time - breedtime
|
||||
else --if actionable but not can_breed we have can_live
|
||||
local queen = monarchlist[1]
|
||||
local princess, drone = apiary_result(queen)
|
||||
local princess, dronelistout = forestry_bees.apiary_result(queen)
|
||||
|
||||
if inv:get_size("dst")-forestry_bees.stacks_in_inv(inv,"dst")>=2 then
|
||||
if inv:get_size("dst")-forestry_bees.stacks_in_inv(inv,"dst") >= 1 + #dronelistout then
|
||||
inv:add_item("dst",princess)
|
||||
for _,drone in pairs(dronelistout) do
|
||||
inv:add_item("dst",drone)
|
||||
end
|
||||
inv:set_stack("monarch",1,ItemStack())
|
||||
src_time = src_time - breedtime
|
||||
update = true
|
||||
else
|
||||
minetest.chat_send_all("dst_full")
|
||||
dst_full = true
|
||||
end
|
||||
end
|
||||
|
@ -19,3 +19,72 @@ function forestry_bees.stacks_in_inv(inv,listname)
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function forestry_bees.breed_princess_drone(princess,drone)
|
||||
local princess_meta = princess:get_meta()
|
||||
local drone_meta = drone:get_meta()
|
||||
local queen = forestry_bees.Bee("queen",
|
||||
princess_meta:get_string("active_gene"),
|
||||
princess_meta:get_string("inactive_gene"))
|
||||
local queen_meta = queen:get_meta()
|
||||
queen_meta:set_string("drone_active_gene",drone_meta:get_string("active_gene"))
|
||||
queen_meta:set_string("drone_inactive_gene",drone_meta:get_string("inactive_gene"))
|
||||
return queen
|
||||
end
|
||||
|
||||
local function final_gene(type1,type2)
|
||||
local out_table1 = {}
|
||||
local out_table2 = {}
|
||||
--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
|
||||
local prob1 = math.random()
|
||||
local prob2 = math.random()
|
||||
if chance > prob1 then
|
||||
table.insert(out_table1, out_type)
|
||||
end
|
||||
if chance > prob2 then
|
||||
table.insert(out_table2, out_type)
|
||||
end
|
||||
end
|
||||
end
|
||||
--if we got no mutations then the eligible out_types are the input_types
|
||||
output = {}
|
||||
--randomly choose if the genes are 1,2 or 2,1
|
||||
if math.random(2)==2 then
|
||||
output[1] = type1
|
||||
output[2] = type2
|
||||
else
|
||||
output[1] = type2
|
||||
output[2] = type1
|
||||
end
|
||||
if next(out_table1) then --if a mutation accurred in gene 1
|
||||
output[1] = out_table1[math.random(#out_table1)]
|
||||
end
|
||||
if next(out_table2) then --if a mutation accurred in gene 2
|
||||
output[2] = out_table2[math.random(#out_table2)]
|
||||
end
|
||||
--out_table is always non-empty, now we uniformally
|
||||
--sample from out_table to get the output gene
|
||||
return output
|
||||
end
|
||||
|
||||
function forestry_bees.apiary_result(queen)
|
||||
--given a queen calculates the correct princess + drone output
|
||||
local meta = queen:get_meta()
|
||||
local mother_genes = {meta:get_string("active_gene"),meta:get_string("inactive_gene")}
|
||||
local father_genes = {meta:get_string("drone_active_gene"),meta:get_string("drone_inactive_gene")}
|
||||
local mother_chosen_gene = mother_genes[math.random(#mother_genes)]
|
||||
local father_chosen_gene = father_genes[math.random(#father_genes)]
|
||||
local genes = final_gene(mother_chosen_gene, father_chosen_gene)
|
||||
local princess = forestry_bees.Bee("princess", genes[1], genes[2])
|
||||
local dronelist = {}
|
||||
for i=1,4 do --in future bees will have fertility and this number should change, so a little bit of futureproofing
|
||||
mother_chosen_gene = mother_genes[math.random(#mother_genes)]
|
||||
father_chosen_gene = father_genes[math.random(#father_genes)]
|
||||
local genes = final_gene(mother_chosen_gene, father_chosen_gene)
|
||||
local drone = forestry_bees.Bee("drone", genes[1], genes[2])
|
||||
table.insert(dronelist, drone)
|
||||
end
|
||||
return princess, dronelist
|
||||
end
|
||||
|
@ -3,4 +3,5 @@ forestry_bees = {}
|
||||
|
||||
dofile(minetest.get_modpath("forestry_bees") .. "/helper.lua")
|
||||
dofile(minetest.get_modpath("forestry_bees") .. "/register.lua")
|
||||
dofile(minetest.get_modpath("forestry_bees") .. "/mutations.lua")
|
||||
dofile(minetest.get_modpath("forestry_bees") .. "/apiary.lua")
|
36
forestry_bees/mutations.lua
Normal file
36
forestry_bees/mutations.lua
Normal file
@ -0,0 +1,36 @@
|
||||
forestry_bees.bee_mutations = {}
|
||||
|
||||
local function register_mutation(bee_type_in1,bee_type_in2,bee_type_out,chance)
|
||||
--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
|
||||
|
||||
--the function appends in the table at position "bee_type_in1","bee_type_in2"
|
||||
--of the matrix forestry_bees.mutations "bee_type_out"=chance
|
||||
--and does so simmetrically
|
||||
|
||||
--populate table if nil
|
||||
if forestry_bees.bee_mutations[bee_type_in1] == nil or not next(forestry_bees.bee_mutations[bee_type_in1]) then
|
||||
forestry_bees.bee_mutations[bee_type_in1] = {}
|
||||
end
|
||||
if forestry_bees.bee_mutations[bee_type_in2] == nil or not next(forestry_bees.bee_mutations[bee_type_in2]) then
|
||||
forestry_bees.bee_mutations[bee_type_in2] = {}
|
||||
end
|
||||
if forestry_bees.bee_mutations[bee_type_in1][bee_type_in2] == nil or not next(forestry_bees.bee_mutations[bee_type_in1][bee_type_in2]) then
|
||||
forestry_bees.bee_mutations[bee_type_in1][bee_type_in2] = {}
|
||||
end
|
||||
if forestry_bees.bee_mutations[bee_type_in2][bee_type_in1] == nil or not next(forestry_bees.bee_mutations[bee_type_in2][bee_type_in1]) then
|
||||
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
|
||||
end
|
||||
|
||||
register_mutation("forest","meadow","common",0.15)
|
||||
register_mutation("forest","common","cultivated",0.12)
|
||||
register_mutation("meadow","common","cultivated",0.12)
|
||||
register_mutation("common","cultivated","noble",0.10)
|
||||
register_mutation("common","cultivated","diligent",0.10)
|
||||
|
||||
--print(forestry_bees.mutations["meadows"]["forest"]["common"])
|
@ -2,8 +2,8 @@ local function capitalize(s)
|
||||
return s:sub(1,1):upper()..s:sub(2)
|
||||
end
|
||||
|
||||
local function makebeetexture(body1,body2,outline,color,ratio)
|
||||
return body1.."^("..body1.."^[makealpha:0,0,0^[colorize:"..color..":"..ratio..")^"..body2.."^("..outline.."^[colorize:"..color..":"..ratio..")"
|
||||
local function makebeetexture(body1,body2,outline,color1,color2)
|
||||
return body1.."^("..body1.."^[makealpha:0,0,0^[colorize:"..color1..":255)^"..body2.."^("..outline.."^[colorize:"..color2..":255)"
|
||||
end
|
||||
|
||||
local function printbeestats(itemstack, user, pointed_thing)
|
||||
@ -12,12 +12,12 @@ local function printbeestats(itemstack, user, pointed_thing)
|
||||
minetest.chat_send_player(user:get_player_name(), "Name:"..string.sub(string.match(name, ":.*"),2)..", Active:"..meta:get_string("active_gene")..", Inactive:"..meta:get_string("inactive_gene"))
|
||||
end
|
||||
|
||||
local function register_bee(name, color, color_ratio)
|
||||
local function register_bee(name, color1, color2)
|
||||
minetest.register_craftitem("forestry_bees:"..name.."_princess", {
|
||||
description = capitalize(name).." Princess",
|
||||
inventory_image = makebeetexture("body1.png",
|
||||
"princess.body2.png",
|
||||
"princess.outline.png",color,color_ratio),
|
||||
"princess.outline.png",color1,color2),
|
||||
on_use = printbeestats,
|
||||
groups = {bee_princess=1, bee_monarch=1},
|
||||
})
|
||||
@ -25,7 +25,7 @@ local function register_bee(name, color, color_ratio)
|
||||
description = capitalize(name).." Drone",
|
||||
inventory_image = makebeetexture("body1.png",
|
||||
"drone.body2.png",
|
||||
"drone.outline.png",color,color_ratio),
|
||||
"drone.outline.png",color1,color2),
|
||||
on_use = printbeestats,
|
||||
groups = {bee_drone=1},
|
||||
})
|
||||
@ -33,7 +33,7 @@ local function register_bee(name, color, color_ratio)
|
||||
description = capitalize(name).." Queen",
|
||||
inventory_image = makebeetexture("body1.png",
|
||||
"queen.body2.png",
|
||||
"queen.outline.png",color,color_ratio),
|
||||
"queen.outline.png",color1,color2),
|
||||
on_use = printbeestats,
|
||||
groups = {bee_queen=1, bee_monarch=1},
|
||||
})
|
||||
@ -101,9 +101,13 @@ minetest.register_tool("forestry_bees:scoop", {
|
||||
},
|
||||
})
|
||||
|
||||
register_bee("forest","#19d0ec","255")
|
||||
register_bee("meadow","#ef131e","255")
|
||||
register_bee("common","#b2b2b2","255")
|
||||
register_bee("forest","#ffdc16","#19d0ec")
|
||||
register_bee("meadow","#ffdc16","#ef131e")
|
||||
register_bee("common","#ffdc16","#b2b2b2")
|
||||
register_bee("cultivated","#ffdc16","#5734ec")
|
||||
register_bee("noble","#ffdc16","#ec9a19")
|
||||
register_bee("diligent","#ffdc16","#c219ec")
|
||||
|
||||
|
||||
minetest.register_craftitem("forestry_bees:honey_comb", {
|
||||
description = "Honey Comb",
|
||||
|
Loading…
Reference in New Issue
Block a user