From 7b7083c57388904575eb486847c28f2fa6ffbd5a Mon Sep 17 00:00:00 2001 From: berengma Date: Wed, 13 Jan 2021 18:21:17 +0100 Subject: [PATCH] dtime measurement, gull run from predator --- animals/gulls.lua | 37 ++++++++++++++++++++++++++----------- animals/shark.lua | 4 ++-- behaviors.lua | 10 +++++----- chatcommands.lua | 14 ++++++++++++++ init.lua | 4 +++- spawn.lua | 31 +++++++++++++++++++++++++++++-- 6 files changed, 79 insertions(+), 21 deletions(-) diff --git a/animals/gulls.lua b/animals/gulls.lua index 1019ab2..fa004a2 100644 --- a/animals/gulls.lua +++ b/animals/gulls.lua @@ -79,7 +79,7 @@ local function gull_brain(self) if mobkit.timer(self,1) then - + local enemy = water_life.get_closest_enemy(self) --minetest.chat_send_all(dump(prty)..") "..dump(self.isinliquid)) --.." : "..dump(self.dtime)) --colinfo.collides)) if self.isinliquid then @@ -88,6 +88,15 @@ local function gull_brain(self) mobkit.forget(self,"landlife") mobkit.forget(self,"airlife") + if prty > 19 and prty < 22 and enemy then + --minetest.chat_send_all("WARNING: "..dump(enemy:get_luaentity().name)) + local eyaw = enemy:get_yaw() + mobkit.clear_queue_high(self) + mobkit.clear_queue_low(self) + water_life.hq_water_takeoff(self,22,'takeoff',eyaw) + water_life.hq_climb(self,15,4,16) + end + -- anything else from inwater behavior if prty < 20 or prty > 30 then mobkit.clear_queue_high(self) @@ -111,11 +120,17 @@ local function gull_brain(self) if mobkit.is_queue_empty_high(self) then - --self.object:add_velocity({x=2,y=4,z=2}) - water_life.hq_climb(self,15,4,16) - mobkit.remember(self,"airlife",os.clock()) - mobkit.forget(self,"landlife") - mobkit.forget(self,"waterlife") + if not self.isinliquid then + self.object:add_velocity({x=2,y=4,z=2}) + water_life.hq_climb(self,15,4,16) + mobkit.remember(self,"airlife",os.clock()) + mobkit.forget(self,"landlife") + mobkit.forget(self,"waterlife") + else + water_life.hq_idle(self,21,20,'float') + water_life.hq_water_takeoff(self,20,'takeoff') + water_life.hq_climb(self,15,4,16) + end end @@ -134,7 +149,7 @@ minetest.register_entity("water_life:gull",{ physical = true, stepheight = 0.5, collide_with_objects = false, - collisionbox = {-0.45, -0.15, -0.85, 0.65, 0.15, 0.25}, + collisionbox = {-0.45, -0.25, -0.45, 0.45, 0.15, 0.45}, visual = "mesh", mesh = "water_life_gull.b3d", textures = {"water_life_gull1.png","water_life_gull2.png","water_life_gull3.png"}, @@ -149,7 +164,7 @@ minetest.register_entity("water_life:gull",{ buoyancy = 0.89, -- portion of hitbox submerged max_speed = 3, jump_height = 1.5, - view_range = 16, + view_range = 32, -- lung_capacity = 0, -- seconds max_hp = 5, timeout=60, @@ -157,9 +172,9 @@ minetest.register_entity("water_life:gull",{ drops = {}, -- {name = "default:diamond", chance = 20, min = 1, max = 1,}, -- {name = "water_life:meat_raw", chance = 2, min = 1, max = 1,}, - predators = {"water_life:shark", - "water_life:alligator", - "water_life:whale" + predators = {["water_life:shark"] = 1, + ["water_life:alligator"] = 1, + ["water_life:whale"] = 1 }, sounds = { idle={ diff --git a/animals/shark.lua b/animals/shark.lua index 8bcbc45..09729ae 100644 --- a/animals/shark.lua +++ b/animals/shark.lua @@ -60,7 +60,7 @@ local function shark_brain(self) local tbuoy = water_life.count_objects(ppos,10,"water_life:buoy") local dist = water_life.dist2tgt(self,target) if dist > 3 and tbuoy.name == 0 then - water_life.hq_water_attack(self,target,20,9) + water_life.hq_water_attack(self,target,20,7) end end @@ -69,7 +69,7 @@ local function shark_brain(self) if dist > 3 then mobkit.clear_queue_high(self) --mobkit.hq_aqua_attack(self,30,food,7) - water_life.hq_water_attack(self,food,20,9) + water_life.hq_water_attack(self,food,20,7) end end end diff --git a/behaviors.lua b/behaviors.lua index 623c676..38e86e1 100644 --- a/behaviors.lua +++ b/behaviors.lua @@ -935,13 +935,12 @@ function water_life.hq_glide(self,prty,fmin,fmax) end -function water_life.hq_water_takeoff(self,prty,anim) +function water_life.hq_water_takeoff(self,prty,anim,tyaw) local init = true local startup = true local turned = false local timer = 0 if not anim then anim = 'def' end - local tyaw = nil local pos2 = {} @@ -951,6 +950,7 @@ function water_life.hq_water_takeoff(self,prty,anim) local pos = self.object:get_pos() if startup then + if tyaw then yaw = tyaw end --water_life.temp_show(pos,5,1) for i = 0,330,30 do pos2 = mobkit.pos_translate2d(pos,yaw+rad(i),self.view_range*2) @@ -971,7 +971,7 @@ function water_life.hq_water_takeoff(self,prty,anim) if turned then if init then - self.object:set_velocity({x=0, y=0, z=0}) + self.object:set_velocity({x=0, y=0.5, z=0}) minetest.after(2,function() mobkit.animate(self,anim) end) @@ -979,7 +979,7 @@ function water_life.hq_water_takeoff(self,prty,anim) end - minetest.after(6,function() + minetest.after(4,function() mobkit.animate(self,'fly') end) @@ -990,7 +990,7 @@ function water_life.hq_water_takeoff(self,prty,anim) mobkit.go_forward_horizontal(self,3) timer = timer + self.dtime - if timer > 10 then + if timer > 8 then local vec = vector.multiply(minetest.yaw_to_dir(tyaw),2) vec.y = vec.y + 4 self.object:add_velocity(vec) diff --git a/chatcommands.lua b/chatcommands.lua index 68dba1e..39c056f 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -98,3 +98,17 @@ minetest.register_chatcommand("wl_test", { end }) + + +minetest.register_chatcommand("wl_showdtime", { + params = "", + description = "shows everage dtime and max dtime", + privs = {server = true}, + func = function(name, action) + local player = minetest.get_player_by_name(name) + if not player then return false end + + minetest.chat_send_player(name,core.colorize("#14ee00","AVGdtime= "..dump(water_life.avg_dtime).." Max dtime= "..dump(water_life.max_dtime))) + + end +}) diff --git a/init.lua b/init.lua index 11a4963..4bd7051 100644 --- a/init.lua +++ b/init.lua @@ -6,7 +6,7 @@ ----------------------------------------------------------- water_life = {} -water_life.version = "271220" +water_life.version = "211301" water_life.shark_food = {} water_life.repellant = {} water_life.catchNet = "water_life:placeholder" @@ -16,6 +16,8 @@ water_life.farming = minetest.get_modpath("farming") water_life.swampz = minetest.get_modpath("swaz") water_life.abr = tonumber(minetest.settings:get('active_block_range')) or 2 water_life.abo = tonumber(minetest.settings:get('active_object_send_range_blocks')) or 3 +water_life.avg_dtime = 0 +water_life.max_dtime = 0 -- settingtypes water_life.whale_spawn_rate = tonumber(minetest.settings:get("water_life_whale_spawn_rate")) or 100 diff --git a/spawn.lua b/spawn.lua index 82b0c10..7ea0e7b 100644 --- a/spawn.lua +++ b/spawn.lua @@ -1,5 +1,10 @@ local timer = 0 local landtimer = 0 +local dttot=0 +local dtavg=0 +local dtnum=0 +local dtmax=0 +local dttimer = 10 local pi = math.pi local random = water_life.random local landinterval = 120 -- check every 60 seconds for spawnpos on land @@ -16,12 +21,34 @@ end local function spawnstep(dtime) + + -- dtime measurement by Termos + if dtnum < 10001 then + dttot=dttot+dtime + dtnum=dtnum+1 + dtmax = dtime>dtmax and dtime or dtmax + + if dttot>dttimer then + dttimer=dttimer+10 + water_life.avg_dtime = dttot/dtnum + water_life.max_dtime = dtmax + dtmax=0 + end + else -- reset after 10000 steps + dtnum = 0 + dtavg = 0 + dttot = 0 + dtmax = 0 + dttimer = 10 + end + -- end dtime measurement timer = timer + dtime landtimer = landtimer + dtime if timer > waterinterval then - + + for _,plyr in ipairs(minetest.get_connected_players()) do local toomuch = false @@ -250,7 +277,7 @@ local function spawnstep(dtime) local faktor = 100 - getcount(animal[mobname]) * 20 if random(100) < faktor and liquidflag == "sea" then if depth > 4 then - local spawn = mobkit.pos_shift(surface,{y=1}) + local spawn = mobkit.pos_shift(surface,{y=-1}) --spawn.y = spawn.y + 12 local obj=minetest.add_entity(spawn,mobname) -- ok spawn it already damnit end