added hard mob cap, more tweaks to spawn algorithm

This commit is contained in:
sose 2022-08-13 11:59:11 -07:00
parent ba1e41a384
commit 5bc52795b0
1 changed files with 17 additions and 10 deletions

View File

@ -174,8 +174,9 @@ end
-- Spawning Function --
local min_spawn_radius = 32
local max_spawn_radius = 128
local min_spawn_radius = 64
local max_spawn_radius = 256
local mob_hard_cap = 20
local function execute_spawns(player)
if not player:get_pos() then return end
@ -193,19 +194,25 @@ local function execute_spawns(player)
local mob = spawnable_mobs[random(#spawnable_mobs)]
local spawn = creatura.registered_mob_spawns[mob]
if not spawn
or random(spawn.chance or 2) > 1 then return end
or random(spawn.chance or 1) < 2 then return end
-- Spawn cap check
local objects = minetest.get_objects_inside_radius(pos, max_spawn_radius)
local object_count = 0
local same_mob_count = 0
local mob_count = 0
for _, object in ipairs(objects) do
if creatura.is_alive(object)
and not object:is_player()
and object:get_luaentity().name == mob then
object_count = object_count + 1
and not object:is_player() then
mob_count = mob_count + 1
if random(mob_hard_cap) < mob_count then
return
end
if object:get_luaentity().name == mob then
same_mob_count = same_mob_count + 1
end
end
end
if object_count >= spawn.spawn_cap then
if same_mob_count >= spawn.spawn_cap then
return
end
@ -250,8 +257,8 @@ local function execute_spawns(player)
local obj
for _ = 1, group_size do
spawn_pos.x = spawn_pos.x + spawn.spawn_spacing + random(-3, 3)
spawn_pos.z = spawn_pos.z + spawn.spawn_spacing + random(-3, 3)
spawn_pos.x = spawn_pos.x + spawn.spawn_spacing + random(-5, 5)
spawn_pos.z = spawn_pos.z + spawn.spawn_spacing + random(-5, 5)
spawn_pos = {
x = spawn_pos.x,
y = spawn_pos.y,