workover spawning, less checks
This commit is contained in:
parent
063fbe48f2
commit
49c3daf2f8
130
init.lua
130
init.lua
@ -36,6 +36,7 @@ local nodename_water = minetest.registered_aliases.mapgen_water_source
|
||||
local maxwhales = 1
|
||||
local maxsharks = abo/2
|
||||
local maxmobs = 30
|
||||
local timer = 0
|
||||
|
||||
local abs = math.abs
|
||||
local pi = math.pi
|
||||
@ -49,8 +50,8 @@ local sign = math.sign
|
||||
|
||||
local time = os.time
|
||||
|
||||
local whale_spawn_rate = 0.01
|
||||
local shark_spawn_rate = 0.03
|
||||
local whale_spawn_rate = 50
|
||||
local shark_spawn_rate = 150
|
||||
|
||||
|
||||
|
||||
@ -243,75 +244,82 @@ end
|
||||
|
||||
local function spawnstep(dtime)
|
||||
|
||||
for _,plyr in ipairs(minetest.get_connected_players()) do
|
||||
timer = timer + dtime
|
||||
if timer > 5 then
|
||||
|
||||
for _,plyr in ipairs(minetest.get_connected_players()) do
|
||||
|
||||
local coin = random(1000)
|
||||
--minetest.chat_send_all(dump(coin))
|
||||
if plyr then -- each player gets a spawn chance every 5s on average
|
||||
|
||||
if plyr and random()<dtime*0.1 then -- each player gets a spawn chance every 5s on average
|
||||
local pos = plyr:get_pos()
|
||||
local yaw = plyr:get_look_horizontal()
|
||||
local chance = shark_spawn_rate
|
||||
local pos = plyr:get_pos()
|
||||
local yaw = plyr:get_look_horizontal()
|
||||
local chance = shark_spawn_rate
|
||||
|
||||
local mw, ms, all_objects = count_objects(pos)
|
||||
|
||||
local mw, ms, all_objects = count_objects(pos)
|
||||
--minetest.chat_send_all("yaw = "..dump(yaw).." mobs: "..dump(all_objects).." sharks: "..dump(ms).." whales: "..dump(mw))
|
||||
if all_objects > maxmobs then break end
|
||||
|
||||
-- find a pos randomly in look direction of player
|
||||
local radius = (abo * 12) - 1 -- 75% from 16 = 12 nodes
|
||||
radius = math.random(7,radius)
|
||||
local angel = math.random() * (pi/4) -- look for random angel 0 - 45 degrees
|
||||
if leftororight then yaw = yaw + angel else yaw = yaw - angel end -- add or substract to/from yaw
|
||||
|
||||
local pos2 = mobkit.pos_translate2d(pos,yaw,radius)
|
||||
|
||||
|
||||
local height, liquidflag = mobkit.get_terrain_height(pos2,32)
|
||||
|
||||
--minetest.chat_send_all("yaw = "..dump(yaw).." mobs: "..dump(all_objects).." sharks: "..dump(ms).." whales: "..dump(mw))
|
||||
if all_objects > maxmobs then break end
|
||||
|
||||
-- find a pos randomly in look direction of player
|
||||
local radius = (abo * 12) - 1 -- 75% from 16 = 12 nodes
|
||||
radius = math.random(7,radius)
|
||||
local angel = math.random() * (pi/4) -- look for random angel 0 - 45 degrees
|
||||
if leftororight then yaw = yaw + angel else yaw = yaw - angel end -- add or substract to/from yaw
|
||||
|
||||
local pos2 = mobkit.pos_translate2d(pos,yaw,radius)
|
||||
|
||||
|
||||
local height, liquidflag = mobkit.get_terrain_height(pos2,32)
|
||||
|
||||
if height and liquidflag then
|
||||
|
||||
|
||||
|
||||
if height and liquidflag then
|
||||
|
||||
local mobname = 'water_life:shark'
|
||||
if chance < random() then
|
||||
pos2.y = height+1.01
|
||||
|
||||
local a=pos2.x
|
||||
local b=pos2.y
|
||||
local c=pos2.z
|
||||
|
||||
local water = minetest.find_nodes_in_area({x=a-3, y=b-3, z=c-3}, {x=a+4, y=b+4, z=c+4}, {"default:water_source"})
|
||||
|
||||
if #water < 128 then break end -- sharks need water, much water
|
||||
|
||||
if ms > (maxsharks-1) then break end -- sharks are no sardines
|
||||
|
||||
local obj=minetest.add_entity(pos2,mobname) -- ok spawn it already damnit
|
||||
|
||||
end
|
||||
|
||||
|
||||
if whale_spawn_rate < random() then
|
||||
pos2.y = height+4.01
|
||||
|
||||
mobname = 'water_life:whale'
|
||||
local a=pos2.x
|
||||
local b=pos2.y
|
||||
local c=pos2.z
|
||||
|
||||
local water = minetest.find_nodes_in_area({x=a-5, y=b-5, z=c-5}, {x=a+5, y=b+5, z=c+5}, {"default:water_source"})
|
||||
|
||||
if #water < 900 then break end -- whales need water, much water
|
||||
|
||||
if mw > (maxwhales-1) then break end -- whales are no sardines
|
||||
local mobname = 'water_life:shark'
|
||||
if shark_spawn_rate >= coin then
|
||||
pos2.y = height+1.01
|
||||
|
||||
local a=pos2.x
|
||||
local b=pos2.y
|
||||
local c=pos2.z
|
||||
|
||||
local water = minetest.find_nodes_in_area({x=a-3, y=b-3, z=c-3}, {x=a+4, y=b+4, z=c+4}, {"default:water_source"})
|
||||
|
||||
if #water < 128 then break end -- sharks need water, much water
|
||||
|
||||
if ms > (maxsharks-1) then break end -- sharks are no sardines
|
||||
|
||||
local obj=minetest.add_entity(pos2,mobname) -- ok spawn it already damnit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
local obj=minetest.add_entity(pos2,mobname) -- ok spawn it already damnit
|
||||
|
||||
end
|
||||
|
||||
|
||||
if whale_spawn_rate >= coin then
|
||||
pos2.y = height+4.01
|
||||
|
||||
mobname = 'water_life:whale'
|
||||
local a=pos2.x
|
||||
local b=pos2.y
|
||||
local c=pos2.z
|
||||
|
||||
local water = minetest.find_nodes_in_area({x=a-5, y=b-5, z=c-5}, {x=a+5, y=b+5, z=c+5}, {"default:water_source"})
|
||||
|
||||
if #water < 900 then break end -- whales need water, much water
|
||||
|
||||
if mw > (maxwhales-1) then break end -- whales are no sardines
|
||||
|
||||
|
||||
local obj=minetest.add_entity(pos2,mobname) -- ok spawn it already damnit
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
timer = 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user