introduce snake move and sleeping

This commit is contained in:
berengma 2020-08-15 18:58:01 +02:00
parent 451f4bca5d
commit 343ed7f640
4 changed files with 66 additions and 13 deletions

View File

@ -32,7 +32,8 @@ local function snake_brain(self)
if land then
land = math.floor(os.clock()-land)
if random(120,600) < land then
--minetest.chat_send_all(dump(land))
if random(240,360) < land then
--minetest.chat_send_all("Go to water")
mobkit.clear_queue_high(self)
water_life.hq_go2water(self,15)
@ -42,7 +43,7 @@ local function snake_brain(self)
if water then
water = math.floor(os.clock()-water)
if random (30,120) < water then
if random (60,120) < water then
--minetest.chat_send_all("Go to land")
mobkit.clear_queue_high(self)
water_life.hq_go2land(self,15)
@ -92,6 +93,9 @@ local function snake_brain(self)
if self.isinliquid then
water_life.hq_aqua_roam(self,21,1,"swim")
--[[
if target and mobkit.is_alive(target) and target:get_attach() == nil and not water_life.isinliquid(target) then --.is_in_deep(target) then
local dist = water_life.dist2tgt(self,target)
@ -100,7 +104,7 @@ local function snake_brain(self)
water_life.hq_go2land(self,20,target)
end
end
end]]
end
@ -128,7 +132,12 @@ local function snake_brain(self)
if mobkit.is_queue_empty_high(self) then
if self.isinliquid then water_life.hq_aqua_roam(self,10,1,"swim") end
if self.isonground then water_life.hq_slow_roam(self,10) end
if self.isonground then
water_life.hq_idle(self,10,random(60,180),"sleep")
water_life.hq_snake_move(self,9)
end
end

View File

@ -858,3 +858,42 @@ function water_life.hq_snake_warn(self,target,prty,duration,anim)
end
function water_life.hq_snake_move(self,prty,anim)
anim = anim or 'look'
local init = true
local getpos = nil
local func=function(self)
local getpos = nil
local pos = mobkit.get_stand_pos(self) --self.object:get_pos()
local yaw = 0
if init then
mobkit.animate(self,anim)
init=false
yaw = rad(random(360))
pos = mobkit.pos_translate2d(pos,yaw,self.view_range+5)
getpos = water_life.find_node_under_air(pos,self.view_range)
--water_life.temp_show(getpos,5,5)
end
if getpos then
water_life.hq_idle(self,prty-1,10,anim)
water_life.hq_findpath(self,prty-2,getpos, 1.5,0.1)
return true
else
return true
end
end
mobkit.queue_high(self,func,prty)
end

View File

@ -355,15 +355,16 @@ end
function water_life.hq_findpath(self,prty,tpos, dist)
function water_life.hq_findpath(self,prty,tpos, dist,speed)
if not dist then dist = 1 end
if not speed then speed = 1 end
local func = function(self)
if mobkit.is_queue_empty_low(self) and self.isonground then
local pos = self.object:get_pos()
if vector.distance(pos,tpos) > dist then
if not water_life.gopath(self,tpos) then return true end
if not water_life.gopath(self,tpos,speed) then return true end
else
return true
@ -375,7 +376,7 @@ end
function water_life.gopath(self,tpos)
function water_life.gopath(self,tpos,speedfactor)
local height, pos2 = water_life.go_further(self,tpos)
if not speedfactor then speedfactor = 1 end

View File

@ -2,7 +2,8 @@ local timer = 0
local landtimer = 0
local pi = math.pi
local random = water_life.random
local landinterval = 45 -- check every 45 seconds for spawnpos on land
local landinterval = 60 -- check every 60 seconds for spawnpos on land
local waterinterval = 20 -- check every 20 seconds for spawnpos in water
local function getcount(name)
@ -19,7 +20,7 @@ local function spawnstep(dtime)
timer = timer + dtime
landtimer = landtimer + dtime
if timer > 10 then
if timer > waterinterval then
for _,plyr in ipairs(minetest.get_connected_players()) do
@ -58,10 +59,12 @@ local function spawnstep(dtime)
local mobname = 'water_life:snake'
local faktor = 100 - getcount(animal[mobname]) * 50
local faktor = (100 - getcount(animal[mobname]) * 50) + 25
if random(100) < faktor then
local fits = false
if string.match(landdata.name,"desert") or string.match(landdata.name,"savanna") then
local fits = minetest.is_protected(landpos)
--minetest.chat_send_all(dump(fits))
if (string.match(landdata.name,"desert") or string.match(landdata.name,"savanna")) and not fits then
local obj=minetest.add_entity(landpos,mobname) -- ok spawn it already damnit
end
end
@ -188,12 +191,13 @@ local function spawnstep(dtime)
end
end
--minetest.chat_send_all(dump(minetest.pos_to_string(surface)).." "..dump(minetest.pos_to_string(ground)))
mobname = "water_life:jellyfish"
local faktor = 100 - getcount(animal[mobname]) * 20
if random(100) < faktor and liquidflag == "sea" then
if random(100) < faktor and liquidflag == "sea" and depth > 2 then
local obj=minetest.add_entity(mobkit.pos_shift(ground,{y=2}),mobname)
end