From ac208f173e020e52a7a02729e23c6e3046ac0a69 Mon Sep 17 00:00:00 2001 From: berengma Date: Sun, 20 Dec 2020 13:49:10 +0100 Subject: [PATCH] fix spawn --- behaviors.lua | 5 +++-- init.lua | 3 ++- spawn.lua | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/behaviors.lua b/behaviors.lua index 25619ff..ecd78f1 100644 --- a/behaviors.lua +++ b/behaviors.lua @@ -67,7 +67,7 @@ local function sortout(self,ftable) end ]] local way = water_life.find_path(pos, ftable[i], self, self.dtime,true) - minetest.chat_send_all(dump(way)) + --minetest.chat_send_all(dump(way)) if not way or #way < 2 then table.remove(ftable,i) end end return ftable @@ -84,6 +84,7 @@ function wildcow.hq_overrun(self,prty,target) local hit = false local func = function(self) + if not mobkit.is_alive(target) then return true end local dist = water_life.dist2tgt(self,target) if dist > self.view_range then return true end @@ -260,7 +261,7 @@ function wildcow.hq_find_food(self,prty,radius) local pos2 = {x=pos.x +radius,y=pos.y+1,z=pos.z+radius} local food = minetest.find_node_near(pos,radius, {"group:growing","group:plant"}) if not food then food = minetest.find_node_near(pos,radius, {"group:flora","default:papyrus","default:dry_shrub"}) end - if not food then food = minetest.find_node_near(pos, 5, {"default:dirt_with_grass"}) end + if not food then food = minetest.find_node_near(pos, radius, {"default:dirt_with_grass"}) end if not food then return true end local snack = food local anim = false diff --git a/init.lua b/init.lua index c3cae73..50d821e 100644 --- a/init.lua +++ b/init.lua @@ -10,12 +10,13 @@ local path = minetest.get_modpath(minetest.get_current_modname()) wildcow = {} wildcow.spawnfreq = 30 -- spawn frequency +wildcow.maxheight = 80 -- max spawning height wildcow.herdsize = 5 -- max member in a herd wildcow.ptime = 360 -- time in secs until baby is born wildcow.btime = 720 -- time needed for a calf to grew up to an adult wildcow.lifetime = (wildcow.btime+wildcow.ptime)*4 -- lifetime in seconds wildcow.fast_pf = false -- faster pathfinding (false is better but slower) -wildcow.debug = true -- show debug +wildcow.debug = false -- show debug diff --git a/spawn.lua b/spawn.lua index 837a71f..648d301 100644 --- a/spawn.lua +++ b/spawn.lua @@ -30,10 +30,11 @@ local function spawnstep(dtime) local yaw = plyr:get_look_horizontal() local animal = water_life.count_objects(pos) if animal.all > water_life.maxmobs then toomuch = true end + if pos.y < 0 or pos.y > wildcow.maxheight then toomuch = true end -- no spawn under 0 and above maxheight local radius = (water_life.abr * 12) -- 75% from 16 = 12 nodes radius = random(16,radius) -- not nearer than 7 nodes in front of player - local angel = math.rad(random(80)) -- look for random angel 0 - 75 degrees + local angel = math.rad(random(80)) -- look for random angel 0 - 80 degrees if water_life.leftorright() then yaw = yaw + angel else yaw = yaw - angel end -- add or substract to/from yaw local pos2 = mobkit.pos_translate2d(pos,yaw,radius) -- calculate position local bdata = water_life_get_biome_data(pos2) -- get biome data at spawn position @@ -60,7 +61,7 @@ local function spawnstep(dtime) if landpos and not toomuch then - if not minetest.is_protected(landpos,mobname) then + if not minetest.is_protected(landpos,mobname) then -- do not spawn in protected areas local obj = minetest.add_entity(landpos,mobname) if obj then local entity = obj:get_luaentity()