Skip to content

Commit

Permalink
Merge pull request #63 from berengma/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
berengma committed Jan 15, 2021
2 parents e672399 + 2204f62 commit d2bbbf8
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 8 deletions.
27 changes: 25 additions & 2 deletions animals/gulls.lua
Expand Up @@ -14,14 +14,37 @@ local function gull_brain(self)
--
--get prorities !
local prty = mobkit.get_queue_priority(self)
--
-- 10-19 fly 20-29 water 30-39 land
--
--



if mobkit.timer(self,10) then
if random(100) < 10 then
local rnd = random (100)
local force = false

if rnd < 10 then
mobkit.make_sound(self,"idle")
end

local plyr = mobkit.get_nearby_player(self)
local wname = ""

if plyr then
local stack = plyr:get_wielded_item()
wname = stack:get_name()
if rnd < 10 then force = true end
--minetest.chat_send_all("YOU HOLD a "..dump(wname))
end

if plyr and prty < 17 and (wname == "farming:bread" or force) then
--minetest.chat_send_all("MATCH")
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_fly2obj(self,18,plyr,2,force)
end

end

-- die if crashed somewhere
Expand Down
10 changes: 6 additions & 4 deletions api.lua
Expand Up @@ -180,7 +180,9 @@ function water_life.temp_show(pos,time,pillar)
for i = 1,pillar,step do

local obj = minetest.add_entity({x=pos.x, y=pos.y+i, z=pos.z}, "water_life:pos")
minetest.after(time, function(obj) obj:remove() end, obj)
if obj then
minetest.after(time, function(obj) obj:remove() end, obj)
end
end

end
Expand Down Expand Up @@ -258,7 +260,7 @@ end
function water_life.get_close_drops(self,name)


local objs = minetest.get_objects_inside_radius(self.object:get_pos(), water_life.abr * 16)
local objs = minetest.get_objects_inside_radius(self.object:get_pos(), self.view_range)
if #objs < 1 then return nil end

for i = #objs,1,-1 do
Expand Down Expand Up @@ -349,10 +351,10 @@ end



-- counts animals in specified radius or active_object_send_range_blocks, returns a table containing numbers
-- counts animals in specified radius or active_block_range, returns a table containing numbers
function water_life.count_objects(pos,radius,name)

if not radius then radius = water_life.abo * 16 end
if not radius then radius = water_life.abr * 16 end

local all_objects = minetest.get_objects_inside_radius(pos, radius)
local hasil = {}
Expand Down
135 changes: 134 additions & 1 deletion behaviors.lua
Expand Up @@ -71,7 +71,29 @@ end
------------------
-- LQ behaviors --
------------------
--[[
params:
lift: [number]
multiplier for lift. faster objects need less, slower need more. typical value: 0.6 for speeds around 4 m/s
pitch: [degrees]
angle between the longitudinal axis and horizontal plane. typical range: <-15.15>
aoa:
[degrees] angle of attack - the angle between the longitudinal axis and velocity vector.
roll: [degrees]
bank angle. positive is right, negative is left, this is how they turn. if set too large they'll loose height rapidly
acc: [number]
propulsion. use with positive pitch to make them fly level or climb, set it to 0 with slight negative pitch to make
them glide. typical value: around 1.0
anim: [string]
animation.
The example uses two simple high level behaviors to keep them between 18 and 24 nodes above ground, seems good already for ambient type flying creatures.
warning: never set_velocity when using these behaviors.
]]

function water_life.lq_fly_aoa(self,lift,aoa,roll,acc,anim)
aoa=rad(aoa)
Expand Down Expand Up @@ -851,7 +873,7 @@ end
end


-- flying
-- hq flying behaviors

function water_life.hq_climb(self,prty,fmin,fmax)
if not max then max = 30 end
Expand All @@ -871,7 +893,9 @@ function water_life.hq_climb(self,prty,fmin,fmax)
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()

--local tim = minetest.get_us_time()
local left, right, up, down, under, above = water_life.radar(pos,yaw,32,true)
--minetest.chat_send_all(minetest.get_us_time()-tim)

if (down < 3) and (under >= fmax) then
water_life.hq_glide(self,prty,fmin,fmax)
Expand Down Expand Up @@ -1020,6 +1044,115 @@ function water_life.hq_water_takeoff(self,prty,anim,tyaw)
end


function water_life.hq_fly2obj(self,prty,tgt,break_dist,force)

local func=function(self)
if not break_dist then break_dist = 5 end
if not tgt then
mobkit.clear_queue_high(self)
water_life.hq_climb(self,prty)
return true
end

local wname = ""
local roll = 0
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
local tgtpos = tgt:get_pos()
local tgtyaw = tgt:get_yaw()
local tgtspeed = math.floor(vector.length(tgt:get_velocity() or {x=0,y=0,z=0}))
if tgt:is_player() then
tgtyaw = tgt:get_look_horizontal()
local stack = tgt:get_wielded_item()
wname = stack:get_name()
end

if wname ~= "farming:bread" and not force then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_climb(self,15,4,16)
return true
end
--minetest.chat_send_all(dump(tgtpos).." "..dump(tgtyaw).." "..dump(tgtspeed))
if not tgtyaw or not tgtspeed or not mobkit.is_alive(tgt) or self.isonground or self.isinliquid then
mobkit.clear_queue_high(self)
water_life.hq_climb(self,prty)
return true
end
local turn = 0
local diff = 0
local lift = 1.2
local pitch = 5
local acc = 0.6
local anim = "fly"
local truetpos=mobkit.pos_translate2d(tgtpos,tgtyaw,tgtspeed*3)
local ddistance = vector.distance(pos,{x=truetpos.x,y= pos.y, z=truetpos.z})
local alpha = atan((pos.y - truetpos.y)/ ddistance)
local truetyaw = minetest.dir_to_yaw(vector.subtract(truetpos,pos))
local realdistance = vector.distance(pos,tgtpos)
local ang2tgt = mobkit.pos_translate2d(pos,truetyaw,15)

if yaw < truetyaw then
diff = truetyaw - yaw
turn = -1
elseif yaw > truetyaw then
diff = yaw - truetyaw
turn = 1
end
if abs(diff) <= 0.1 then
turn = 0
end
--minetest.chat_send_all("distance ="..dump(math.floor(ddistance*100)/100).." yawdiff ="..dump(math.floor((truetyaw-yaw)*100)/100))

if ddistance > 32 then
roll = 15 * turn
elseif ddistance > 22 then
roll = 10 * turn
elseif ddistance > 12 then
roll = 5 * turn
elseif ddistance <= 12 then
roll = 2 * turn
end

--water_life.temp_show(truetpos,1,3)
--minetest.chat_send_all(dump(minetest.pos_to_string(truetpos,2)).." -- "..dump(minetest.pos_to_string(pos,2)))

if pos.y > truetpos.y + 1 and pos.y > 2 and ddistance < 25 then
anim = "glide"
pitch = -10
elseif pos.y < truetpos.y - 1 then
pitch = 15
else
pitch = 5
end

if water_life.radar_debug then
water_life.temp_show(ang2tgt,1)
for i = 1,10,1 do
water_life.temp_show({x=truetpos.x, y=truetpos.y+i*2, z=truetpos.z},1)
end
--minetest.chat_send_all("Alpha= "..dump(alpha)..", Hight= "..dump(math.floor(pos.y)).." ###"..dump(yaw).."### hityaw="..dump(truetyaw))
--minetest.chat_send_all("distance ="..dump(math.floor(ddistance*100)/100).." Alpha ="..dump(math.floor(deg(alpha)*100)/100))
--minetest.chat_send_all("distance2prey ="..dump(vector.distance(pos,tgtpos)))
end

mobkit.clear_queue_low(self)

if ddistance < break_dist then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_climb(self,15,4,16)
return true

else
water_life.lq_fly_pitch(self,lift,pitch,roll,acc,anim)
end



end
mobkit.queue_high(self,func,prty)
end

--snakes
function water_life.hq_snake_warn(self,target,prty,duration,anim)
Expand Down
2 changes: 1 addition & 1 deletion init.lua
Expand Up @@ -6,7 +6,7 @@
-----------------------------------------------------------

water_life = {}
water_life.version = "211401"
water_life.version = "211501"
water_life.shark_food = {}
water_life.repellant = {}
water_life.catchNet = "water_life:placeholder"
Expand Down

0 comments on commit d2bbbf8

Please sign in to comment.