added hard mob cap, more tweaks to spawn algorithm
This commit is contained in:
parent
ba1e41a384
commit
5bc52795b0
27
spawning.lua
27
spawning.lua
|
@ -174,8 +174,9 @@ end
|
||||||
|
|
||||||
-- Spawning Function --
|
-- Spawning Function --
|
||||||
|
|
||||||
local min_spawn_radius = 32
|
local min_spawn_radius = 64
|
||||||
local max_spawn_radius = 128
|
local max_spawn_radius = 256
|
||||||
|
local mob_hard_cap = 20
|
||||||
|
|
||||||
local function execute_spawns(player)
|
local function execute_spawns(player)
|
||||||
if not player:get_pos() then return end
|
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 mob = spawnable_mobs[random(#spawnable_mobs)]
|
||||||
local spawn = creatura.registered_mob_spawns[mob]
|
local spawn = creatura.registered_mob_spawns[mob]
|
||||||
if not spawn
|
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
|
-- Spawn cap check
|
||||||
local objects = minetest.get_objects_inside_radius(pos, max_spawn_radius)
|
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
|
for _, object in ipairs(objects) do
|
||||||
if creatura.is_alive(object)
|
if creatura.is_alive(object)
|
||||||
and not object:is_player()
|
and not object:is_player() then
|
||||||
and object:get_luaentity().name == mob then
|
mob_count = mob_count + 1
|
||||||
object_count = object_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
|
||||||
end
|
end
|
||||||
if object_count >= spawn.spawn_cap then
|
if same_mob_count >= spawn.spawn_cap then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -250,8 +257,8 @@ local function execute_spawns(player)
|
||||||
|
|
||||||
local obj
|
local obj
|
||||||
for _ = 1, group_size do
|
for _ = 1, group_size do
|
||||||
spawn_pos.x = spawn_pos.x + 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(-3, 3)
|
spawn_pos.z = spawn_pos.z + spawn.spawn_spacing + random(-5, 5)
|
||||||
spawn_pos = {
|
spawn_pos = {
|
||||||
x = spawn_pos.x,
|
x = spawn_pos.x,
|
||||||
y = spawn_pos.y,
|
y = spawn_pos.y,
|
||||||
|
|
Loading…
Reference in New Issue