From aa44226a4e5afc1f5cfec8ff51d2ef0c4c9e1acb Mon Sep 17 00:00:00 2001 From: Duane Robertson Date: Mon, 30 May 2016 05:19:13 -0500 Subject: [PATCH] Separate fortress monster spawn system --- abms.lua | 43 +++++++++++++++++++++++++++++++++++++++++-- deco_caves.lua | 19 +++++++++++++++++-- goblin_coal.lua | 2 +- goblin_copper.lua | 2 +- mapgen.lua | 3 ++- mobs.lua | 29 +++++++++++++++++++++++++++-- 6 files changed, 89 insertions(+), 9 deletions(-) diff --git a/abms.lua b/abms.lua index 5db0883..e3c4745 100644 --- a/abms.lua +++ b/abms.lua @@ -4,12 +4,17 @@ local dps_delay = 3000000 local last_dps_check = 0 local cold_delay = 5 +local monster_delay = 3 local hunger_delay = 60 local dps_count = hunger_delay +-- maximum number of mobs near player in fortresses +local fortress_mob_count = 5 + local get_us_time = minetest.get_us_time local floor = math.floor local abs = math.abs local max = math.max +local min = math.min local rand = math.random local mushrooms = {"flowers:mushroom_brown", "flowers:mushroom_red"} local get_node_light = minetest.get_node_light @@ -35,6 +40,7 @@ minetest.register_globalstep(function(dtime) if mob.hp_max and mob.object and mob.health and mob.damage then local factor = 1 + (max(abs(pos.x), abs(pos.y), abs(pos.z)) / 6200) if fun_caves.is_fortress(pos) then + mob.started_in_fortress = true factor = factor * 1.5 end mob.hp_max = floor(mob.hp_max * factor) @@ -51,8 +57,9 @@ minetest.register_globalstep(function(dtime) local players = get_connected_players() for i = 1, #players do local player = players[i] - local minp = vector.subtract(player:getpos(), 0.5) - local maxp = vector.add(player:getpos(), 0.5) + local pos = player:getpos() + local minp = vector.subtract(pos, 0.5) + local maxp = vector.add(pos, 0.5) local counts = find_nodes_in_area(minp, maxp, {"group:surface_hot"}) if #counts > 1 then @@ -66,6 +73,38 @@ minetest.register_globalstep(function(dtime) end end + if dps_count % monster_delay == 0 then + local mob_count = 0 + for _, mob in pairs(minetest.luaentities) do + if mob.health and mob.started_in_fortress then + local dist = vector.subtract(pos, mob.object:getpos()) + local dist2 = max(abs(dist.x), abs(dist.y * 5), abs(dist.z)) + if dist2 < 30 then + --print(mob.name, dist.y) + mob_count = mob_count + 1 + else + --print("* not", mob.name, dist2) + --print(dump(dist)) + end + end + end + + if mob_count < fortress_mob_count then + local pos1, count = find_nodes_in_area_under_air({x=pos.x-30, y=pos.y-2, z=pos.z-30}, {x=pos.x+30, y=pos.y+2, z=pos.z+30}, {"group:fortress"}) + if #pos1 > 0 then + local pos2 = pos1[rand(#pos1)] + pos2.y = pos2.y + 2 + local name = fun_caves.fortress_spawns[rand(#fun_caves.fortress_spawns)] + local mob = minetest.add_entity(pos2, name) + if mob then + print("Fun Caves: Spawned "..name.." at ("..pos2.x..","..pos2.y..","..pos2.z..")") + else + print("Fun Caves: failed to spawn "..name) + end + end + end + end + -- hunger if dps_count % hunger_delay == 0 then player:set_hp(player:get_hp() - 1) diff --git a/deco_caves.lua b/deco_caves.lua index 266ed8c..a9c3491 100644 --- a/deco_caves.lua +++ b/deco_caves.lua @@ -107,7 +107,7 @@ minetest.register_node("fun_caves:moon_juice", { }) -- mushroom cap, giant -minetest.register_node("fun_caves:giant_mushroom_cap", { +local cap = { description = "Giant Mushroom Cap", tiles = {"vmg_mushroom_giant_cap.png", "vmg_mushroom_giant_under.png", "vmg_mushroom_giant_cap.png"}, is_ground_content = false, @@ -123,7 +123,22 @@ minetest.register_node("fun_caves:giant_mushroom_cap", { } }, light_source = fun_caves.light_max, groups = {fleshy=1, dig_immediate=3, flammable=2, plant=1}, -}) +} +if false then + cap.node_box.fixed = { + {-0.3, -0.25, -0.3, 0.3, 0.5, 0.3}, + {-0.3, -0.25, -0.4, 0.3, 0.4, -0.3}, + {-0.3, -0.25, 0.3, 0.3, 0.4, 0.4}, + {-0.4, -0.25, -0.3, -0.3, 0.4, 0.3}, + {0.3, -0.25, -0.3, 0.4, 0.4, 0.3}, + {-0.4, -0.5, -0.4, 0.4, -0.25, 0.4}, + {-0.5, -0.5, -0.4, -0.4, -0.25, 0.4}, + {0.4, -0.5, -0.4, 0.5, -0.25, 0.4}, + {-0.4, -0.5, -0.5, 0.4, -0.25, -0.4}, + {-0.4, -0.5, 0.4, 0.4, -0.25, 0.5}, + } +end +minetest.register_node("fun_caves:giant_mushroom_cap", cap) -- mushroom cap, huge minetest.register_node("fun_caves:huge_mushroom_cap", { diff --git a/goblin_coal.lua b/goblin_coal.lua index 9d95ada..7f1b64f 100644 --- a/goblin_coal.lua +++ b/goblin_coal.lua @@ -121,7 +121,7 @@ mobs:register_mob("fun_caves:goblin_coal", { }) mobs:register_egg("fun_caves:goblin_coal", "Goblin Egg (coal)", "default_mossycobble.png", 1) -mobs:register_spawn("fun_caves:goblin_coal", {"default:coalblock", "default:stone_with_coal", "group:fortress"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) +mobs:register_spawn("fun_caves:goblin_coal", {"default:coalblock", "default:stone_with_coal"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) mobs:register_spawn("fun_caves:goblin_coal", {"default:mossycobble", "fun_caves:hot_cobble"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) minetest.register_node("fun_caves:stone_with_coal_trap", { diff --git a/goblin_copper.lua b/goblin_copper.lua index bd4f648..5834c70 100644 --- a/goblin_copper.lua +++ b/goblin_copper.lua @@ -120,7 +120,7 @@ mobs:register_mob("fun_caves:goblin_copper", { end, }) mobs:register_egg("fun_caves:goblin_copper", "Goblin Egg (copper)", "default_mossycobble.png", 1) -mobs:register_spawn("fun_caves:goblin_copper", {"default:stone_with_copper", "group:fortress"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) +mobs:register_spawn("fun_caves:goblin_copper", {"default:stone_with_copper"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) mobs:register_spawn("fun_caves:goblin_copper", {"default:mossycobble"}, 100, 0, 1 * fun_caves.goblin_spawn_frequency, 3, -51) minetest.register_node("fun_caves:stone_with_copper_trap", { diff --git a/mapgen.lua b/mapgen.lua index 34ddf60..203cf9f 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -235,7 +235,8 @@ local function generate(p_minp, p_maxp, seed) data[ivm] = inner_floor end elseif (z - minp.z) % 5 == 0 or (x - minp.x) % 5 == 0 then - data[ivm] = DEBUG and node["default:glass"] or inner_wall + --data[ivm] = DEBUG and node["default:glass"] or inner_wall + data[ivm] = inner_wall else data[ivm] = node["air"] end diff --git a/mobs.lua b/mobs.lua index bc2c0cc..1aaca49 100644 --- a/mobs.lua +++ b/mobs.lua @@ -67,13 +67,12 @@ dofile(fun_caves.path .. "/danglers.lua") dofile(fun_caves.path .. "/spider.lua") dofile(fun_caves.path .. "/tarantula.lua") dofile(fun_caves.path .. "/spider_ice.lua") ---dofile(fun_caves.path .. "/dirt_monster.lua") dofile(fun_caves.path .. "/sand_monster.lua") dofile(fun_caves.path .. "/tar_monster.lua") if minetest.registered_entities["mobs_monster:dirt_monster"] then -- check this - mobs:register_spawn("mobs_monster:dirt_monster", {"default:dirt"}, 7, 0, 7000, 1, -50, false) + mobs:register_spawn("mobs_monster:dirt_monster", {"default:dirt"}, 7, 0, 4000, 1, -50, false) end if minetest.registered_entities["mobs_slimes:green_big"] then @@ -119,3 +118,29 @@ dofile(fun_caves.path.."/goblin_iron.lua") dofile(fun_caves.path.."/goblin_gold.lua") dofile(fun_caves.path.."/goblin_diamond.lua") dofile(fun_caves.path.."/goblin_king.lua") + +fun_caves.fortress_spawns = {} +local t_mobs = { + "mobs_monster:dungeon_master", + "mobs_monster:lava_flan", + "mobs_monster:mese_monster", + "mobs_monster:oerkki", + "mobs_monster:stone_monster", + "fun_caves:spider", + "mobs_slimes:green_big", + "mobs_slimes:green_medium", + "mobs_slimes:green_small", + "fun_caves:goblin_cobble", + "fun_caves:goblin_copper", + "fun_caves:goblin_coal", + "fun_caves:goblin_ice", + "fun_caves:goblin_iron", + "fun_caves:goblin_gold", + "fun_caves:goblin_diamond", + "fun_caves:goblin_king", +} +for _, mob in pairs(t_mobs) do + if minetest.registered_entities[mob] then + fun_caves.fortress_spawns[#fun_caves.fortress_spawns+1] = mob + end +end