Add killer bees. Correct light in trees.

This commit is contained in:
Duane 2016-06-13 13:10:14 -05:00
parent 99eb220fef
commit 68e8671235
4 changed files with 228 additions and 101 deletions

View file

@ -1,101 +1,6 @@
-- goblins_digger.lua -- goblins_digger.lua
-- --
-- He destroys everything diggable in his path. It's too much trouble
-- to fudge around with particulars. Besides, I don't want them to
-- mine for me.
--local diggable_nodes = {"group:stone", "group:sand", "group:soil", "group:plant", "default:stone_with_coal", "default:stone_with_iron", "default:stone_with_copper", "default:stone_with_gold", "default:stone_with_mese", "default:stone_with_diamond", "default:mese", "default:coalblock"}
local diggable_nodes = {"group:cracky", "group:snappy", "group:crumbly"}
-- This translates yaw into vectors.
local cardinals = {{x=0,y=0,z=0.75}, {x=-0.75,y=0,z=0}, {x=0,y=0,z=-0.75}, {x=0.75,y=0,z=0}}
local goblin_tunneling = function(self, type)
-- Types are available for fine-tuning.
if type == nil then
type = "digger"
end
local pos = self.object:getpos()
if self.state == "tunnel" then
-- Yaw is stored as one of the four cardinal directions.
if not self.digging_dir then
self.digging_dir = math.random(0,3)
end
-- Turn him roughly in the right direction.
-- self.object:setyaw(self.digging_dir * math.pi * 0.5 + math.random() * 0.5 - 0.25)
self.object:setyaw(self.digging_dir * math.pi * 0.5)
-- Get a pair of coordinates that should cover what's in front of him.
local p = vector.add(pos, cardinals[self.digging_dir+1])
p.y = p.y - 0.5 -- What's this about?
local p1 = vector.add(p, -0.3)
local p2 = vector.add(p, 0.3)
-- Get any diggable nodes in that area.
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes)
if #np_list > 0 then
-- Dig it.
for _, np in pairs(np_list) do
if np.name ~= "default:cobble" then
minetest.remove_node(np)
end
end
end
if math.random() < 0.2 then
local d = {-1,1}
self.digging_dir = (self.digging_dir + d[math.random(2)]) % 4
end
set_animation(self, "walk")
set_velocity(self, self.walk_velocity)
elseif self.state == "room" then -- Dig a room.
if not self.room_radius then
self.room_radius = 1
end
set_animation(self, "stand")
set_velocity(self, 0)
-- Work from the inside, out.
for r = 1,self.room_radius do
-- Get a pair of coordinates that form a room.
local p1 = vector.add(pos, -r)
local p2 = vector.add(pos, r)
-- But not below him.
p1.y = pos.y
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes)
-- I wanted to leave the outer layer incomplete, but this
-- actually tends to make it look worse.
if r >= self.room_radius and #np_list == 0 then
self.room_radius = math.random(1,2) + math.random(0,1)
self.state = "stand"
break
end
if #np_list > 0 then
-- Dig it.
minetest.remove_node(np_list[math.random(#np_list)])
break
end
end
end
if self.state == "stand" and math.random() < 0.5 then
self.state = "tunnel"
elseif self.state == "tunnel" and math.random() < 0.05 then
self.state = "room"
elseif self.state == "tunnel" and math.random() < 0.1 then
self.state = "stand"
end
end
mobs:register_mob("fun_caves:goblin_digger", { mobs:register_mob("fun_caves:goblin_digger", {
description = "Digger Goblin", description = "Digger Goblin",
type = "monster", type = "monster",
@ -209,7 +114,7 @@ mobs:register_mob("fun_caves:goblin_digger", {
return return
end end
goblin_tunneling(self, "digger") fun_caves.tunneling(self, "digger")
fun_caves.search_replace(self.object:getpos(), fun_caves.goblin_torch_freq, {"default:torch"}, "air") fun_caves.search_replace(self.object:getpos(), fun_caves.goblin_torch_freq, {"default:torch"}, "air")
fun_caves.search_replace(self.object:getpos(), fun_caves.goblin_trap_freq, {"group:stone", "default:sandstone"}, "default:mossycobble") fun_caves.search_replace(self.object:getpos(), fun_caves.goblin_trap_freq, {"group:stone", "default:sandstone"}, "default:mossycobble")

View file

@ -402,9 +402,12 @@ local function generate(p_minp, p_maxp, seed)
if fun_caves.DEBUG then if fun_caves.DEBUG then
vm:set_lighting({day = 15, night = 15}) vm:set_lighting({day = 15, night = 15})
else else
-- set_lighting causes shadows -- set_lighting causes lighting artifacts,
--vm:set_lighting({day = 0, night = 0}) -- but corrects the light inside trees.
vm:calc_lighting({x=minp.x,y=emin.y,z=minp.z}, maxp) vm:set_lighting({day = 0, night = 0})
vm:calc_lighting()
-- Does not work:
--vm:calc_lighting({x=minp.x,y=emin.y,z=minp.z}, maxp)
end end
vm:update_liquids() vm:update_liquids()
vm:write_to_map() vm:write_to_map()

221
mobs.lua
View file

@ -61,9 +61,109 @@ fun_caves.surface_damage = function(self, cold_natured)
--end --end
end end
local cardinals = {{x=0,y=0,z=0.75}, {x=-0.75,y=0,z=0}, {x=0,y=0,z=-0.75}, {x=0.75,y=0,z=0}}
--local diggable_nodes = {"group:stone", "group:sand", "group:soil", "group:plant", "default:stone_with_coal", "default:stone_with_iron", "default:stone_with_copper", "default:stone_with_gold", "default:stone_with_mese", "default:stone_with_diamond", "default:mese", "default:coalblock"}
local diggable_nodes = {
digger = {"group:cracky", "group:snappy", "group:crumbly"},
bee = {"fun_caves:tree", "fun_caves:glowing_fungal_wood", "fun_caves:sap"},
}
fun_caves.tunneling = function(self, type)
-- Types are available for fine-tuning.
if type == nil then
type = "digger"
end
-- This translates yaw into vectors.
local pos = self.object:getpos()
if self.state == "tunnel" then
-- Yaw is stored as one of the four cardinal directions.
if not self.digging_dir then
self.digging_dir = math.random(0,3)
end
-- Turn him roughly in the right direction.
self.object:setyaw(self.digging_dir * math.pi * 0.5)
-- Get a pair of coordinates that should cover what's in front of him.
local p = vector.add(pos, cardinals[self.digging_dir+1])
-- What's this about?
if type == "digger" then
p.y = p.y - 0.5
else
p.y = p.y + 0.25
end
local p1 = vector.add(p, -0.3)
local p2 = vector.add(p, 0.3)
-- Get any diggable nodes in that area.
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes[type])
if #np_list > 0 then
-- Dig it.
for _, np in pairs(np_list) do
if type ~= 'digger' or np.name ~= "default:cobble" then
minetest.remove_node(np)
end
end
end
if math.random() < 0.2 then
local d = {-1,1}
self.digging_dir = (self.digging_dir + d[math.random(2)]) % 4
end
set_animation(self, "walk")
set_velocity(self, self.walk_velocity)
elseif self.state == "room" then -- Dig a room.
if not self.room_radius or not self.room_count then
self.room_radius = 1
self.room_count = 0
end
set_animation(self, "stand")
set_velocity(self, 0)
-- Work from the inside, out.
for r = 1,self.room_radius do
-- Get a pair of coordinates that form a room.
local p1 = vector.add(pos, -r)
local p2 = vector.add(pos, r)
-- But not below him.
p1.y = pos.y
local np_list = minetest.find_nodes_in_area(p1, p2, diggable_nodes[type])
-- I wanted to leave the outer layer incomplete, but this
-- actually tends to make it look worse.
if r >= self.room_radius and self.room_count > (self.room_radius * 2 + 1) ^ 3 or #np_list == 0 then
self.room_radius = math.random(1,2) + math.random(0,1)
self.state = "stand"
break
end
self.room_count = self.room_count + 1
if #np_list > 0 then
-- Dig it.
minetest.remove_node(np_list[math.random(#np_list)])
break
end
end
end
if self.state ~= "room" and math.random() < (type == 'digger' and 0.5 or 0.2) then
self.state = "tunnel"
elseif self.state == "tunnel" and math.random() < 0.01 then
self.state = "room"
elseif self.state == "tunnel" and math.random() < 0.1 then
self.state = "stand"
end
end
-- executed in a mob's do_custom() to regulate their actions -- executed in a mob's do_custom() to regulate their actions
-- if false, do nothing -- if false, do nothing
local custom_delay = 1000000 local custom_delay = 5000000
fun_caves.custom_ready = function(self) fun_caves.custom_ready = function(self)
local time = minetest.get_us_time() local time = minetest.get_us_time()
if not self.custom_time or time - self.custom_time > custom_delay then if not self.custom_time or time - self.custom_time > custom_delay then
@ -75,6 +175,125 @@ fun_caves.custom_ready = function(self)
end end
if minetest.registered_entities["mobs:bee"] then
local function bee_summon(self)
if self.health < (self.hp_max / 2) and self.state == "attack" and math.random(4) == 1 then
local pos = self.object:getpos()
local p1 = vector.subtract(pos, 1)
local p2 = vector.add(pos, 1)
--look for nodes
local nodelist = minetest.find_nodes_in_area(p1, p2, "air")
if #nodelist > 0 then
for key,value in pairs(nodelist) do
minetest.add_entity(value, "fun_caves:killer_bee_drone")
print("Queen bee summons reinforcement.")
return -- only one at a time
end
end
end
end
local function bee_do(self)
if not fun_caves.custom_ready(self) then
return
end
if self.name == 'fun_caves:killer_bee' then
fun_caves.tunneling(self, "bee")
end
if self.name == 'fun_caves:killer_bee_queen' then
bee_summon(self)
end
fun_caves.climb(self)
--fun_caves.search_replace(self.object:getpos(), 50, {"fun_caves:wood"}, "fun_caves:glowing_fungal_wood")
fun_caves.surface_damage(self)
end
mobs:register_mob("fun_caves:killer_bee", {
description = "Killer Bee",
type = "monster",
passive = false,
attack_type = "dogfight",
attacks_monsters = true,
reach = 2,
damage = 1,
hp_min = 5,
hp_max = 10,
armor = 200,
collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.2, 0.2},
visual = "mesh",
mesh = "mobs_bee.x",
drawtype = "front",
textures = {
{"mobs_bee.png"},
},
--textures = { {"fun_caves_killer_bee.png"}, }
--visual_size = {x = 1.5, y = 1.5},
makes_footstep_sound = false,
sounds = {
random = "mobs_bee",
},
walk_velocity = 1,
run_velocity = 3,
jump = true,
view_range = 15,
floats = 0,
drops = {
{name = "mobs:honey", chance = 2, min = 1, max = 2},
},
water_damage = 1,
lava_damage = 5,
light_damage = 0,
fall_damage = 0,
--fall_speed = -3,
lifetimer = 360,
follow = nil,
animation = {
speed_normal = 15,
stand_start = 0,
stand_end = 30,
walk_start = 35,
walk_end = 65,
},
replace_rate = 50,
replace_what = {"fun_caves:glowing_fungal_wood", "fun_caves:sap",},
replace_with = "air",
replace_offset = -1,
do_custom = bee_do
})
mobs:register_spawn("fun_caves:killer_bee", {"fun_caves:tree", "fun_caves:ironwood", "fun_caves:diamondwood"}, 20, -1, 500, 5, 31000)
mobs:register_egg("fun_caves:killer_bee", "Killer Bee", "mobs_bee_inv.png", 1)
local m = table.copy(minetest.registered_entities["fun_caves:killer_bee"])
m.name = 'fun_caves:killer_bee_drone'
m.damage = 3
m.hp_min = 10
m.hp_max = 20
m.visual_size = {x = 1.25, y = 1.25}
minetest.registered_entities["fun_caves:killer_bee_drone"] = m
mobs.spawning_mobs["fun_caves:killer_bee_drone"] = true
mobs:register_spawn("fun_caves:killer_bee_drone", {"fun_caves:tree", "fun_caves:ironwood", "fun_caves:diamondwood"}, 20, -1, 1000, 5, 31000)
m = table.copy(minetest.registered_entities["fun_caves:killer_bee"])
m.damage = 2
m.hp_min = 15
m.hp_max = 30
m.name = 'fun_caves:killer_bee_queen'
m.visual_size = {x = 1.5, y = 1.25}
minetest.registered_entities["fun_caves:killer_bee_queen"] = m
mobs.spawning_mobs["fun_caves:killer_bee_queen"] = true
mobs:register_spawn("fun_caves:killer_bee_queen", {"fun_caves:tree", "fun_caves:ironwood", "fun_caves:diamondwood"}, 20, -1, 4000, 5, 31000)
end
if minetest.registered_entities["kpgmobs:wolf"] then if minetest.registered_entities["kpgmobs:wolf"] then
local m = table.copy(minetest.registered_entities["kpgmobs:wolf"]) local m = table.copy(minetest.registered_entities["kpgmobs:wolf"])
m.textures = { {"fun_caves_white_wolf.png"}, } m.textures = { {"fun_caves_white_wolf.png"}, }

View file

@ -241,7 +241,7 @@ fun_caves.treegen = function(minp, maxp, data, p2data, area, node)
-- foliage -- foliage
elseif y < 272 and y > 112 and floor(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2) < r2 ^ 2 and y % 10 == 0 and (floor(dx / 4) % 3 == 0 or floor(dz / 4) % 3 == 0) then elseif y < 272 and y > 112 and floor(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2) < r2 ^ 2 and y % 10 == 0 and (floor(dx / 4) % 3 == 0 or floor(dz / 4) % 3 == 0) then
if data[ivm] == node['air'] then if data[ivm] == node['air'] then
data[ivm] = node['fun_caves:tree'] data[ivm] = node['fun_caves:bark']
write = true write = true
end end
elseif y < 275 and y > 115 and floor(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2) < r2 ^ 2 and (y + 3) % 10 < 7 and (floor((dx + 3) / 4) % 3 < 2 or floor((dz + 3) / 4) % 3 < 2) then elseif y < 275 and y > 115 and floor(dx ^ 2 + dz ^ 2 + (y - 192) ^ 2) < r2 ^ 2 and (y + 3) % 10 < 7 and (floor((dx + 3) / 4) % 3 < 2 or floor((dz + 3) / 4) % 3 < 2) then