Merge pull request #9 from berengma/range

Range
This commit is contained in:
Gundul 2019-11-13 20:35:27 +01:00 committed by GitHub
commit f2ba767431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

142
init.lua
View File

@ -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 = 30
local shark_spawn_rate = 100
@ -192,7 +193,7 @@ local function chose_turn(self,pos,yaw)
local remember = mobkit.recall(self,"turn")
if not remember then
if leftorright then
if leftorright() then
remember = "1"
mobkit.remember(self,"time", self.time_total)
mobkit.remember(self,"turn", "1")
@ -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 leftorright() 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
@ -382,19 +390,17 @@ local function whale_brain(self)
if node then
local def = minetest.registered_nodes[node.name]
if node then -- anything above head ? dive.
--minetest.chat_send_all(dump(def.is_ground_content))
if def.is_ground_content and node.name ~= "air" then
if node.name ~= "default:water_source" and node.name ~= "air" then
local hvel = vector.multiply(vector.normalize({x=head.x,y=0,z=head.z}),4)
self.object:set_velocity({x=hvel.x,y=-1,z=hvel.z})
end
end
local vcheck= minetest.find_nodes_in_area(up,down, {"group:water","default:sand_with_kelp"})
local hcheck = minetest.find_nodes_in_area(left,right, {"group:water","default:sand_with_kelp"})
local vcheck= minetest.find_nodes_in_area(up,down, {"default:water_source"})
local hcheck = minetest.find_nodes_in_area(left,right, {"default:water_source"})
--minetest.chat_send_all(dump(#vcheck).." - "..dump(#hcheck))
if #vcheck < 54 or #hcheck < 49 then
--mobkit.clear_queue_high(self)