remove some remaining code from old spawning algorithms
This commit is contained in:
parent
19ff4fffb2
commit
323fb24b10
@ -534,25 +534,6 @@ function spawning.spawn_and_check(name,pos,text)
|
||||
return nil
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: register_cleanup_spawner(spawnername)
|
||||
-- @function [parent=#spawning] register_cleanup_spawner
|
||||
--
|
||||
--! @brief register an entity to cleanup spawners
|
||||
--! @memberof spawning
|
||||
--
|
||||
--! @param spawnername name of spawner to create a cleanup entity for
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.register_cleanup_spawner(spawnername)
|
||||
dbg_mobf.mobf_core_lvl2("MOBF: registering spawner cleanup " .. spawnername)
|
||||
minetest.register_entity(spawnername,
|
||||
{
|
||||
on_activate = function(self,staticdata)
|
||||
self.object:remove()
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: population_density_get_min(entity)
|
||||
-- @function [parent=#spawning] population_density_get_min
|
||||
@ -584,220 +565,6 @@ function spawning.population_density_get_min(entity)
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: collisionbox_get_max(entity)
|
||||
-- @function [parent=#spawning] collisionbox_get_max
|
||||
--
|
||||
--! @brief get maximum extent of mob
|
||||
--! @memberof spawning
|
||||
--
|
||||
--! @param mob mob specification
|
||||
--
|
||||
--! @return a collisionbox covering all state collisionboxes
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.collisionbox_get_max(mob)
|
||||
|
||||
--use 1 block as minimum for spawning
|
||||
local retval = {-0.5,-0.5,-0.5,0.5,0.5,0.5}
|
||||
|
||||
--check all states if there's some collisionbox that requires more room
|
||||
for i=1,#mob.states,1 do
|
||||
if mob.states[i] ~= nil and
|
||||
mob.states[i].graphics_3d ~= nil and
|
||||
type(mob.states[i].graphics_3d.collisionbox) == "table" then
|
||||
retval[1] = MIN(retval[1],mob.states[i].graphics_3d.collisionbox[1])
|
||||
retval[2] = MIN(retval[2],mob.states[i].graphics_3d.collisionbox[2])
|
||||
retval[3] = MIN(retval[3],mob.states[i].graphics_3d.collisionbox[3])
|
||||
retval[4] = MAX(retval[4],mob.states[i].graphics_3d.collisionbox[4])
|
||||
retval[5] = MAX(retval[5],mob.states[i].graphics_3d.collisionbox[5])
|
||||
retval[6] = MAX(retval[6],mob.states[i].graphics_3d.collisionbox[6])
|
||||
end
|
||||
end
|
||||
|
||||
return retval
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: pos_quality(spawning_data,pos)
|
||||
-- @function [parent=#spawning] pos_quality
|
||||
--
|
||||
--! @brief build a entity like datastructure to be passed to pos_quality check
|
||||
--! @memberof spawning
|
||||
--
|
||||
--! @param spawning_data to check quality for
|
||||
--! @param pos position to check quality at
|
||||
--
|
||||
--! @return a possition quality element
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.pos_quality(spawning_data,pos)
|
||||
local dummyentity = {}
|
||||
|
||||
dummyentity.collisionbox = spawning_data.collisionbox
|
||||
dummyentity.environment = spawning_data.environment
|
||||
|
||||
--TODO find a way to pass this information!
|
||||
dummyentity.data = {}
|
||||
dummyentity.data.movement = {}
|
||||
dummyentity.data.movement.canfly = false
|
||||
|
||||
return environment.pos_quality(pos,dummyentity)
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: position_in_use(pos,spawndata)
|
||||
-- @function [parent=#spawning] position_in_use
|
||||
--
|
||||
--! @brief check if there already is a mob at a specific position
|
||||
--! @memberof spawning
|
||||
--
|
||||
--! @param pos position to check
|
||||
--! @param spawndata data for this mob
|
||||
--
|
||||
--! @return true == mob present false == no mob
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.position_in_use(pos,spawndata)
|
||||
local mobcount = mobf_mob_around(
|
||||
spawndata.name,
|
||||
spawndata.name_secondary,
|
||||
pos,
|
||||
1.5,true)
|
||||
if mobcount > 0 then
|
||||
dbg_mobf.spawning_lvl2("MOBF: mob at same pos")
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
-- name: population_density_limit(pos,spawndata)
|
||||
-- @function [parent=#spawning] population_density_limit
|
||||
--
|
||||
--! @brief check if population density limit is reached
|
||||
--! @memberof spawning
|
||||
--
|
||||
--! @param pos position to check
|
||||
--! @param spawndata data for this mob
|
||||
--
|
||||
--! @return true == mob present false == no mob
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.population_density_limit(pos,spawndata)
|
||||
mobf_assert_backtrace(spawndata ~= nil)
|
||||
mobf_assert_validpos(pos)
|
||||
mobf_assert_backtrace(spawndata.name ~= nil)
|
||||
mobf_assert_backtrace(spawndata.density ~= nil)
|
||||
local mobcount = mobf_mob_around(
|
||||
spawndata.name,
|
||||
spawndata.name_secondary,
|
||||
pos,
|
||||
spawndata.density,true)
|
||||
if mobcount > 0 then
|
||||
dbg_mobf.spawning_lvl2("MOBF: not spawning within pop density")
|
||||
return true
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: spawner_get_water_pos(pos,max_depth,min_y,max_y)
|
||||
--
|
||||
--! @brief find a position at x/z within some y limitations
|
||||
--
|
||||
--! @param pos position do spawn
|
||||
--! @param min_depth min-y depth to spawn
|
||||
--! @param max_depth max-y depth to spawn
|
||||
--! @param min_y minimum y value of generated chunk
|
||||
--! @param max_y maximum y value of generated chunk
|
||||
-------------------------------------------------------------------------------
|
||||
function spawning.spawner_get_water_pos(pos,min_depth,max_depth,min_y,max_y)
|
||||
--get information about current position
|
||||
local upper_pos = {x=pos.x,y=max_y,z=pos.z}
|
||||
|
||||
mobf_assert_backtrace(type(min_depth) == "number")
|
||||
mobf_assert_backtrace(type(max_depth) == "number")
|
||||
|
||||
if max_depth > max_y then
|
||||
dbg_mobf.spawning_lvl3("MOBF: get_water_pos to deep")
|
||||
return nil
|
||||
end
|
||||
|
||||
if min_depth < min_y then
|
||||
dbg_mobf.spawning_lvl3("MOBF: get_water_pos to high")
|
||||
return nil
|
||||
end
|
||||
|
||||
local ground_distance = mobf_ground_distance(upper_pos,
|
||||
{ "default:water_flowing",
|
||||
"default:water_source",
|
||||
"air" },max_y - min_y)
|
||||
local ground_level = max_y - ground_distance +1
|
||||
|
||||
local ground_pos = {x=pos.x,y=ground_level,z=pos.z }
|
||||
local water_depth = mobf_air_distance(ground_pos)
|
||||
|
||||
local surfacenode = minetest.get_node(ground_pos)
|
||||
|
||||
|
||||
|
||||
if surfacenode == nil then
|
||||
dbg_mobf.spawning_lvl3("MOBF: invalid ground node")
|
||||
return nil
|
||||
end
|
||||
|
||||
if surfacenode.name ~= "default:water_flowing" and
|
||||
surfacenode.name ~= "default:water_source" then
|
||||
--mobf_print("MOBF: WD:" .. water_depth .. " GD: " .. ground_distance)
|
||||
--mobf_print("MOBF: MAXD:" .. max_depth .. " " .. min_y .. "<->" .. max_y)
|
||||
dbg_mobf.spawning_lvl3("MOBF: " .. surfacenode.name .. " isn't open water: " .. printpos(ground_pos))
|
||||
--if ground_pos.y > 0 then
|
||||
-- for i=min_y,max_y,1 do
|
||||
-- local node = minetest.get_node({x=pos.x,y=i,z=pos.z})
|
||||
-- print("i=" .. i .. " : " .. node.name)
|
||||
-- end
|
||||
--end
|
||||
return nil
|
||||
end
|
||||
|
||||
if water_depth <= 0 then
|
||||
dbg_mobf.spawning_lvl3("MOBF: water not found! GP: " .. ground_level .. " WD: " .. water_depth)
|
||||
--TODO spawn in caves?
|
||||
return nil
|
||||
end
|
||||
|
||||
local water_surface_pos = {x=pos.x,y=ground_level + water_depth,z=pos.z}
|
||||
|
||||
--dbg_mobf.spawning_lvl2
|
||||
dbg_mobf.spawning_lvl3("MOBF: mobf_spawner_get_water_pos GL: " ..
|
||||
ground_level ..
|
||||
" WDPT: " .. water_depth ..
|
||||
" WSP: " .. printpos(water_surface_pos))
|
||||
if MAX(ground_level,max_depth) > water_surface_pos.y then
|
||||
mobf_print("MOBF: WD:" .. water_depth .. " GD: " .. ground_distance)
|
||||
mobf_print("MOBF: MAXD:" .. max_depth .. " " .. min_y .. "<->" .. max_y)
|
||||
mobf_print("MOBF: mobf_spawner_get_water_pos GL: " ..
|
||||
ground_level ..
|
||||
" WDPT: " .. water_depth ..
|
||||
" WSP: " .. printpos(water_surface_pos))
|
||||
--this can happen if there are air bubbles within water
|
||||
--mobf_assert_backtrace(MAX(ground_level,max_depth) < water_surface_pos.y)
|
||||
return nil
|
||||
end
|
||||
|
||||
--check if there is any chance to find a suitable pos
|
||||
if MAX(ground_level,max_depth) >= MIN(water_surface_pos.y,min_depth) then
|
||||
return nil
|
||||
end
|
||||
|
||||
pos.y = math.floor(
|
||||
math.random(
|
||||
MAX(ground_level,max_depth),
|
||||
MIN(water_surface_pos.y,min_depth)
|
||||
)
|
||||
+ 0.5)
|
||||
return pos
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: check_activation_overlap(entity,pos,preserved_data)
|
||||
--
|
||||
|
Loading…
x
Reference in New Issue
Block a user