fix vector calc, balance stuff, api and bahavior additions, gulls steal bait from player

This commit is contained in:
berengma 2021-01-17 18:58:36 +01:00
parent 0624bb5f2e
commit 9c62299ef9
5 changed files with 97 additions and 36 deletions

View File

@ -1,19 +1,9 @@
local random = water_life.random
local rad = math.rad
water_life.register_shark_food("water_life:gull")
-- locally, no one else uses this so far
local function is_bait(name)
if not name or #water_life.gull_bait < 1 then return false end
for i = 1,#water_life.gull_bait,1 do
if water_life.gull_bait[i] == name then return true end
end
return false
end
local function gull_brain(self)
if not mobkit.is_alive(self) then
@ -49,7 +39,7 @@ local function gull_brain(self)
--minetest.chat_send_all("WHALES !")
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_fly2obj(self,18,plyr,3)
water_life.hq_fly2obj(self,18,whale,4,true)
end
@ -57,10 +47,10 @@ local function gull_brain(self)
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))
--minetest.chat_send_all("YOU HOLD bait "..dump(water_life.gull_bait[wname]))
end
if plyr and prty < 17 and (is_bait(wname) or force) then
if plyr and prty < 17 and (water_life.gull_bait[wname] or force) then
--minetest.chat_send_all("MATCH")
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
@ -133,6 +123,8 @@ 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()
@ -209,7 +201,7 @@ minetest.register_entity("water_life:gull",{
buoyancy = 0.59, -- portion of hitbox submerged
max_speed = 3,
jump_height = 1.5,
view_range = 32,
view_range = water_life.abr*16, -- max what server can handle, birds need good eyes !
-- lung_capacity = 0, -- seconds
max_hp = 5,
timeout=60,

27
api.lua
View File

@ -242,7 +242,7 @@ function water_life.register_shark_food(name)
end
function water_life.register_gull_bait(name)
if name then table.insert(water_life.gull_bait,name) end
if name then water_life.gull_bait[name] = 1 end
end
@ -476,6 +476,31 @@ function water_life.find_collision(pos1,pos2,water)
end
-- fast radar, less accurate
-- yaw-x to the right, yaw + x to the left !
-- sonar = true water is no obstacle
function water_life.radar_fast(self,dist,sonar)
local water = not sonar
if not dist then dist = self.view_range end
local angel = atan(3/dist)
local yaw = self.object:get_yaw()
local tpos = self.object:get_pos()
local tapos = mobkit.pos_translate2d(tpos,(yaw-angel),dist)
local tbpos = mobkit.pos_translate2d(tpos,yaw,dist)
local tcpos = mobkit.pos_translate2d(tpos,(yaw+angel),dist)
local tupos = mobkit.pos_shift(tbpos,{y=2})
local tdpos = mobkit.pos_shift(tbpos,{y=-2})
local right = water_life.find_collision(tpos,tapos,water)
local left = water_life.find_collision(tpos,tcpos,water)
local center = water_life.find_collision(tpos,tbpos,water)
local up = water_life.find_collision(tpos,tupos,water)
local down = water_life.find_collision(tpos,tdpos,water)
return left,right,center,up,down
end
-- radar function for obstacles lying in front of an entity
-- use water = true if water should be an obstacle

View File

@ -1059,15 +1059,21 @@ function water_life.hq_fly2obj(self,prty,tgt,break_dist,force)
local pos = self.object:get_pos()
local yaw = self.object:get_yaw()
local tgtpos = tgt:get_pos()
local tgtyaw = tgt:get_yaw()
local tgtyaw = tgt:get_yaw() --water_life.get_yaw_to_object(self,tgt)
local tgtspeed = math.floor(vector.length(tgt:get_velocity() or {x=0,y=0,z=0}))
if not tgt:is_player() and tgt:get_luaentity().name == "water_life:whale" then tgtyaw = tgtyaw + rad(180) end -- whales moving backwards XD
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
if tgtpos.y < 0 then tgtpos.y = 1 end
if not water_life.gull_bait[wname] and not force then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_climb(self,15,4,16)
@ -1088,20 +1094,30 @@ function water_life.hq_fly2obj(self,prty,tgt,break_dist,force)
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 truetyaw = water_life.get_yaw_to_pos(self,truetpos)
local realdistance = vector.distance(pos,tgtpos)
local ang2tgt = mobkit.pos_translate2d(pos,truetyaw,15)
--chose right or left turn
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
diff = abs(truetyaw - yaw)
-- or chose straight ahead
if ddistance > 30 and diff <= 0.5 then
turn = 0
end
if ddistance > 20 and diff <= 0.3 then
turn = 0
end
if diff <= 0.1 then
turn = 0
end
--minetest.chat_send_all(">>> "..dump(math.floor(diff*100)/100).." <<<")
--minetest.chat_send_all("distance ="..dump(math.floor(ddistance*100)/100).." yawdiff ="..dump(math.floor((truetyaw-yaw)*100)/100))
if ddistance > 32 then
@ -1126,6 +1142,23 @@ function water_life.hq_fly2obj(self,prty,tgt,break_dist,force)
pitch = 5
end
--tim = minetest.get_us_time()
local left,right,center,up,down = water_life.radar_fast(self,20)
--minetest.chat_send_all(minetest.get_us_time()-tim)
if down and down < 16 then pitch = 15 end
if up and not down and not center then pitch = -10 end
if right and not center then roll = 10 end
if left and not center then roll = -10 end
if left and right and not center then roll = 0 end
if center and down and center < 5 then
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_climb(self,15,4,16)
return true
end
if water_life.radar_debug then
water_life.temp_show(ang2tgt,1)
for i = 1,10,1 do
@ -1138,7 +1171,17 @@ function water_life.hq_fly2obj(self,prty,tgt,break_dist,force)
mobkit.clear_queue_low(self)
if ddistance < break_dist then
if realdistance < break_dist+0.5 then -- steal bait from players
-- minetest.chat_send_all(">>> "..dump(math.floor(ddistance*100)/100).."<<< ###"..dump(math.floor(realdistance*100)/100).." ###")
if tgt:is_player() then
local bstack = tgt:get_wielded_item()
local bait = bstack:get_name()
if water_life.gull_bait[bait] then
bstack:take_item(1)
tgt:set_wielded_item(bstack)
end
end
mobkit.clear_queue_high(self)
mobkit.clear_queue_low(self)
water_life.hq_climb(self,15,4,16)

View File

@ -6,7 +6,7 @@
-----------------------------------------------------------
water_life = {}
water_life.version = "211601"
water_life.version = "211701"
water_life.shark_food = {}
water_life.repellant = {}
water_life.gull_bait = {}

View File

@ -88,6 +88,7 @@ local function spawnstep(dtime)
local landpos = nil
local geckopos = nil
local moskitopos = nil
local mobname = ""
-- no need of so many postions on land
if landtimer > landinterval then
@ -122,7 +123,7 @@ local function spawnstep(dtime)
if not water_life.dangerous then
-- the snake
local mobname = 'water_life:snake'
mobname = 'water_life:snake'
local faktor = (100 - getcount(animal[mobname]) * 50)
if random(100) < faktor then
local fits = minetest.is_protected(landpos,mobname)
@ -140,7 +141,7 @@ local function spawnstep(dtime)
--the beaver
local mobname = 'water_life:beaver'
mobname = 'water_life:beaver'
local faktor = (100 - getcount(animal[mobname]) * 25)
if random(100) < faktor then
@ -155,7 +156,7 @@ local function spawnstep(dtime)
if geckopos then
local landdata = water_life_get_biome_data(geckopos)
local mobname = 'water_life:gecko'
mobname = 'water_life:gecko'
local faktor = (100 - getcount(animal[mobname]) * 50)
if random(100) < faktor then
@ -211,7 +212,7 @@ local function spawnstep(dtime)
if water_life.swampz then
local mobname = 'water_life:alligator'
mobname = 'water_life:alligator'
local faktor = 100 - getcount(animal[mobname]) * 20
if random(100) < faktor then
local fits = false
@ -228,7 +229,7 @@ local function spawnstep(dtime)
--minetest.chat_send_all(dump(minetest.pos_to_string(surface)).." "..dump(minetest.pos_to_string(ground)))
local mobname = 'water_life:croc'
mobname = 'water_life:croc'
local faktor = 100 - getcount(animal[mobname]) * 33
if random(100) < faktor then
local fits = false
@ -243,7 +244,7 @@ local function spawnstep(dtime)
--minetest.chat_send_all(dump(minetest.pos_to_string(surface)).." "..dump(minetest.pos_to_string(ground)))
local mobname = 'water_life:snake'
mobname = 'water_life:snake'
local faktor = (100 - getcount(animal[mobname]) * 50) +25
if random(100) < faktor then
local fits = false
@ -257,7 +258,7 @@ local function spawnstep(dtime)
end
--minetest.chat_send_all(dump(minetest.pos_to_string(surface)).." "..dump(minetest.pos_to_string(ground)))
local mobname = 'water_life:shark'
mobname = 'water_life:shark'
if water_life.shark_spawn_rate >= random(1000) then
local bcheck = water_life.count_objects(pos2,12)
@ -272,13 +273,13 @@ local function spawnstep(dtime)
end
end
local mobname = "water_life:gull"
mobname = "water_life:gull"
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})
if random(100) < faktor and (liquidflag == "sea" or liquidflag == "river") then
if depth > 2 and not water_life.check_for_pool(nil,2,10,surface)then
--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
local obj=minetest.add_entity(surface,mobname) -- ok spawn it already damnit
end
end