Skip to content

Commit

Permalink
Merge pull request #99 from berengma/dev
Browse files Browse the repository at this point in the history
Hippopotamus
  • Loading branch information
berengma authored Apr 1, 2024
2 parents 16f20b6 + 9fc4d4c commit fca2892
Show file tree
Hide file tree
Showing 19 changed files with 364 additions and 106 deletions.
6 changes: 3 additions & 3 deletions animals/crocodile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ local function croc_brain(self)
and not water_life.isinliquid(target) then
local dist = water_life.dist2tgt(self,target)
if dist < 10 then
water_life.hq_go2land(self,15,target)
water_life.hq_go2land(self,20,target)
end
end
if food and mobkit.is_alive(food) and not water_life.isinliquid(food) then
local dist = water_life.dist2tgt(self,food)
if dist < 16 then
water_life.hq_go2land(self,15,food)
water_life.hq_go2land(self,20,food)
end
end
end
Expand Down Expand Up @@ -154,7 +154,7 @@ minetest.register_entity("water_life:croc",{
{name = "water_life:meat_raw", chance = 1, min = 1, max = 5,},
{name = "water_life:crocleather", chance = 2, min = 1, max = 2},
},
attack={range=0.8,damage_groups={fleshy=7}},
attack={range=1.1,damage_groups={fleshy=7}},
sounds = {
attack={
{name = 'water_life_crocattack',
Expand Down
158 changes: 158 additions & 0 deletions animals/hippo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
local random = water_life.random
local abs = math.abs
local pi = math.pi
local floor = math.floor
local sqrt = math.sqrt
local max = math.max
local min = math.min
local pow = math.pow
local sign = math.sign
local rad = math.rad

local function hippo_brain(self)

local prty = mobkit.get_queue_priority(self)

--die
if self.hp <= 0 then
mobkit.clear_queue_high(self)
water_life.handle_drops(self)
mobkit.hq_die(self)
return
end

--chose between land and water
if mobkit.timer(self,10) then
local land = mobkit.recall(self,"landlife")
local water = mobkit.recall(self,"waterlife")

if land and prty < 15 then
land = math.floor(os.time() - land)
if land > 30 and random(100) < land then
water_life.hq_go2water(self,15)
end
end
if water and prty < 15 then
water = math.floor(os.time() - water)
if water > 120 and random (1000) < water then
water_life.hq_go2land(self,15)
end
end
end

--every other action check each second
if mobkit.timer(self,1) then
if not mobkit.recall(self,"landlife") and not mobkit.recall(self,"waterlife") then
mobkit.remember(self,"waterlife",os.time())
end
if self.isinliquid and mobkit.recall(self,"landlife") then
mobkit.remember(self,"waterlife",os.time())
mobkit.forget(self,"landlife")
end
if self.isonground and mobkit.recall(self,"waterlife") then
mobkit.remember(self,"landlife",os.time())
mobkit.forget(self,"waterlife")
end

local target = mobkit.get_nearby_player(self)
local aliveinwater = target and mobkit.is_alive(target) and water_life.isinliquid(target)
if target and mobkit.is_alive(target) and target:get_attach() == nil
and water_life.isinliquid(target) then
local dist = water_life.dist2tgt(self,target)
if dist and dist < 8 then
water_life.hq_water_attack(self,target,26,5,true)
end
end

--on land
if self.isonground then
local rnd = random(1000)
if rnd < 30 then
mobkit.make_sound(self,"idle")
end
if target and mobkit.is_alive(target) then
local dist = water_life.dist2tgt(self,target)
if dist < self.view_range / 2 then
water_life.hq_hunt(self,24,target,7)
end
end
end
end
if mobkit.is_queue_empty_high(self) then
if self.isinliquid then
water_life.hq_aqua_roam(self,10,1,nil,false)
else
water_life.hq_slow_roam(self,12)
end
end
end

minetest.register_entity("water_life:hippo",{
physical = true,
stepheight = 1.1,
collide_with_objects = true,
collisionbox = {-0.49, 0, -0.49, 0.49, 1.99, 0.49},
visual = "mesh",
mesh = "water_life_hippo.b3d",
textures = {"water_life_hippo.png"},
visual_size = {x = 1.5, y = 1.5},
static_save = true,
makes_footstep_sound = true,
on_step = mobkit.stepfunc,
on_activate = mobkit.actfunc,
get_staticdata = mobkit.statfunc,
springiness=0,
buoyancy = 0.98,
max_speed = 5,
jump_height = 1.49,
view_range = 16,
max_hp = 100,
timeout=300,
drops = {
{name = "default:diamond", chance = 5, min = 2, max = 6,},
{name = "water_life:meat_raw", chance = 1, min = 4, max = 10,},
},
attack={range=0.8,damage_groups={fleshy=12}},
sounds = {
attack={
{name = 'water_life_hippo_angry1',
gain = water_life.soundadjust},
{name = 'water_life_hippo_angry2',
gain = water_life.soundadjust}
},
idle={
{name = "water_life_hippo_idle1",
gain = water_life.soundadjust},
{name = "water_life_hippo_idle2",
gain = water_life.soundadjust},
{name = "water_life_hippo_idle3",
gain = water_life.soundadjust},
{name = "water_life_hippo_idle4",
gain = water_life.soundadjust},
{name = "water_life_hippo_idle5",
gain = water_life.soundadjust},
}
},
animation = {
def={range={x=0,y=100},speed=5,loop=true},
stand={range={x=0,y=100},speed=1,loop=false},
die={range={x=100,y=200},speed=1,loop=false},
walk={range={x=300,y=400},speed=15,loop=true},
swim={range={x=300,y=400},speed=30,loop=true},
},

brainfunc = hippo_brain,

on_punch=function(self, puncher, time_from_last_punch, tool_capabilities, dir)
if mobkit.is_alive(self) then
local hvel = vector.multiply(vector.normalize({x=dir.x,y=0,z=dir.z}),4)
self.object:set_velocity({x=hvel.x,y=2,z=hvel.z})
if water_life.bloody then water_life.spilltheblood(self.object) end
mobkit.hurt(self,tool_capabilities.damage_groups.fleshy or 1)
if type(puncher)=='userdata' and puncher:is_player() then
mobkit.clear_queue_high(self)
water_life.hq_water_attack(self,puncher,20,6,true)
end
end
end,
})
12 changes: 3 additions & 9 deletions animals/snake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ local function snake_brain(self)
if land then
land = math.floor(os.time() - land)
if random(240,360) < land then
mobkit.clear_queue_high(self)
water_life.hq_go2water(self, 15)
water_life.hq_go2water(self, 5)
end
end
if water then
water = math.floor(os.time()-water)
if random (60,120) < water then
mobkit.clear_queue_high(self)
water_life.hq_go2land(self, 25)
water_life.hq_go2land(self, 5)
end
end
end
Expand Down Expand Up @@ -64,9 +62,7 @@ local function snake_brain(self)
-- snakes do not attack when in water
end
end
if self.isinliquid then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
if self.isinliquid and prty < 21 then
water_life.hq_aqua_roam(self, 21, 1, "swim")
end
if self.isonground then
Expand All @@ -75,8 +71,6 @@ local function snake_brain(self)
local pname = target:get_player_name()
local dist = water_life.dist2tgt(self, target)
if dist > 4 and dist < self.view_range and not action then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_snake_warn(self, target, 30, 8)
elseif dist < 5 or action == pname then
mobkit.forget(self, "warned")
Expand Down
57 changes: 42 additions & 15 deletions api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,19 @@ function water_life.dist2tgt(self,tgt)
local pos = mobkit.get_stand_pos(self)
local tpos = tgt:get_pos()
if (not tgt or not self) then
return 100
return 100
else
return vector.distance(pos,tpos)
end
end

function water_life.dumbstep(self,height,tpos,speed_factor,idle_duration)
if height <= 0.001 then
if height <= 0.001 or self.isinliquid then
mobkit.lq_turn2pos(self,tpos)
water_life.lq_dumbwalk(self,tpos,speed_factor)
else
mobkit.lq_turn2pos(self,tpos)
water_life.lq_dumbjump(self,height)
mobkit.lq_dumbjump(self,height)
end
idle_duration = idle_duration or 6
mobkit.lq_idle(self,random(ceil(idle_duration*0.5),idle_duration))
Expand Down Expand Up @@ -615,6 +615,36 @@ function water_life.find_node_under_air(pos,radius,name)
end
end

-- recursively search for a water node with depth or return nil after stop tries
function water_life.get_pos_with_depth(start, radius, depth, stop, yaw, doNotUse)
local tgt = nil
radius = radius or 16
depth = depth or 2
stop = stop or radius
doNotUse = doNotUse or stop

if not start or stop <= 0 then
return nil
end
if not yaw then
tgt = minetest.find_node_near(start, radius, {"group:water"})
if not tgt then
return nil
end
yaw = minetest.dir_to_yaw(vector.direction(start, tgt))
else
tgt = mobkit.pos_translate2d(start, yaw, 3)
end
local dep, type, surface = water_life.water_depth(tgt)
if (surface and (dep < depth or stop > doNotUse - 3)) then
return water_life.get_pos_with_depth(tgt, radius, depth, stop - 1, yaw, doNotUse)
elseif surface then
return tgt
else
return nil
end
end

-- function to find liquid surface and depth at that position returns depth or max, type of water node and surface position
function water_life.water_depth(pos,max)
local surface = {}
Expand Down Expand Up @@ -704,25 +734,22 @@ function water_life.getLandPos(self, start)
local target = nil
local fpos = nil
local pos = mobkit.get_stand_pos(self)
local radius = math.abs(self.collisionbox[5] - self.collisionbox[2])
pos = mobkit.pos_shift(pos, {y = radius - 1})

for i = start,359,15 do
local yaw = rad(i)
target = mobkit.pos_translate2d(pos,yaw,self.view_range)
for yaw = start,359,15 do
target = mobkit.pos_translate2d(pos, rad(yaw), self.view_range)
fpos = water_life.find_collision(pos,target,false)
if fpos then
target = mobkit.pos_translate2d(pos,yaw,fpos+0.5)
local node=minetest.get_node({x=target.x,y=target.y+1,
target = mobkit.pos_translate2d(pos, rad(yaw), fpos+0.5)
local node=minetest.get_node({x=target.x,y=target.y + 1,
z=target.z})
if node.name == "air" then
if node.name == "air" then
return target
else
target = nil
end
else
target = nil
end
end
end
return target
return nil
end

function water_life.goto_next_waypoint(self,tpos)
Expand Down
Loading

0 comments on commit fca2892

Please sign in to comment.