Hopefully fixed serialize.h error (math.atan returns non without checks)

master
TenPlus1 2015-12-14 14:43:41 +00:00
parent d2741a865c
commit 3f49e47df7
1 changed files with 71 additions and 29 deletions

100
api.lua
View File

@ -1,4 +1,4 @@
-- Mobs Api (9th December 2015)
-- Mobs Api (14th December 2015)
mobs = {}
mobs.mod = "redo"
@ -594,7 +594,6 @@ function day_docile(self)
end
-- register mob function
function mobs:register_mob(name, def)
minetest.register_entity(name, {
@ -673,7 +672,7 @@ minetest.register_entity(name, {
on_step = function(self, dtime)
local pos = self.object:getpos()
local yaw = 0
local yaw = self.object:getyaw() or 0
-- when lifetimer expires remove mob (except npc and tamed)
if self.type ~= "npc"
@ -774,6 +773,7 @@ minetest.register_entity(name, {
self.timer = 0
end
-- never go over 100
if self.timer > 100 then
self.timer = 1
@ -954,6 +954,7 @@ minetest.register_entity(name, {
and follow_holding(self, self.following) == false then
self.following = nil
end
end
-- follow that thing
@ -979,16 +980,24 @@ minetest.register_entity(name, {
if dist > self.view_range then
self.following = nil
else
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
local vec = {
x = p.x - s.x,
y = p.y - s.y,
z = p.z - s.z
}
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if vec.x ~= 0
and vec.z ~= 0 then
if p.x > s.x then
yaw = yaw + pi
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if p.x > s.x then
yaw = yaw + pi
end
self.object:setyaw(yaw)
end
self.object:setyaw(yaw)
-- anyone but standing npc's can move along
if dist > self.reach
and self.order ~= "stand" then
@ -1046,7 +1055,11 @@ minetest.register_entity(name, {
-- look at any players nearby, otherwise turn randomly
if lp then
local vec = {x = lp.x - s.x, y = lp.y - s.y, z = lp.z - s.z}
local vec = {
x = lp.x - s.x,
y = lp.y - s.y,
z = lp.z - s.z
}
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -1104,7 +1117,11 @@ minetest.register_entity(name, {
-- if water nearby then turn away
if lp then
local vec = {x = lp.x - s.x, y = lp.y - s.y, z = lp.z - s.z}
local vec = {
x = lp.x - s.x,
y = lp.y - s.y,
z = lp.z - s.z
}
yaw = math.atan(vec.z / vec.x) + 3 * pi / 2 - self.rotate
@ -1152,7 +1169,7 @@ minetest.register_entity(name, {
local p = self.attack:getpos() or s
local dist = vector.distance(p, s)
-- stop attacking if no player or out of range
-- stop attacking if player or out of range
if dist > self.view_range
or not self.attack
or not self.attack:getpos()
@ -1172,16 +1189,24 @@ minetest.register_entity(name, {
if self.attack_type == "explode" then
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
local vec = {
x = p.x - s.x,
y = p.y - s.y,
z = p.z - s.z
}
yaw = math.atan(vec.z / vec.x) + pi / 2 - self.rotate
if vec.x ~= 0
and vec.z ~= 0 then
if p.x > s.x then
yaw = yaw + pi
yaw = math.atan(vec.z / vec.x) + pi / 2 - self.rotate
if p.x > s.x then
yaw = yaw + pi
end
self.object:setyaw(yaw)
end
self.object:setyaw(yaw)
if dist > self.reach then
if not self.v_start then
@ -1314,16 +1339,24 @@ minetest.register_entity(name, {
end
-- end fly bit
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
local vec = {
x = p.x - s.x,
y = p.y - s.y,
z = p.z - s.z
}
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if vec.x ~= 0
and vec.z ~= 0 then
if p.x > s.x then
yaw = yaw + pi
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if p.x > s.x then
yaw = yaw + pi
end
self.object:setyaw(yaw)
end
self.object:setyaw(yaw)
-- move towards enemy if beyond mob reach
if dist > self.reach then
@ -1388,15 +1421,24 @@ minetest.register_entity(name, {
s.y = s.y + .5
local dist = vector.distance(p, s)
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
local vec = {
x = p.x - s.x,
y = p.y - s.y,
z = p.z - s.z
}
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if vec.x ~= 0
and vec.z ~= 0 then
if p.x > s.x then
yaw = yaw + pi
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
if p.x > s.x then
yaw = yaw + pi
end
self.object:setyaw(yaw)
end
self.object:setyaw(yaw)
set_velocity(self, 0)
if self.shoot_interval