Various minor fixes (mostly code style)

This commit is contained in:
sapier 2013-12-09 15:29:46 +01:00
parent 0dcdd786e3
commit ce8ea00d80
4 changed files with 76 additions and 76 deletions

View File

@ -1,8 +1,8 @@
-------------------------------------------------------------------------------
-- Mob Framework Mod by Sapier
--
--
-- You may copy, use, modify or do nearly anything except removing this
-- copyright notice.
-- copyright notice.
-- And of course you are NOT allow to pretend you have written it.
--
--! @file debug_trace.lua
@ -29,91 +29,91 @@ dbg_mobf = {
generic_lvl1 = function () end,
generic_lvl2 = function () end,
generic_lvl3 = function () end,
graphics_lvl1 = function () end,
graphics_lvl2 = function () end,
graphics_lvl3 = function () end,
spawning_lvl1 = function () end,
spawning_lvl2 = function () end,
spawning_lvl3 = function () end,
permanent_store_lvl1 = function () end,
permanent_store_lvl2 = function () end,
permanent_store_lvl3 = function () end,
movement_lvl1 = function () end,
movement_lvl2 = function () end,
movement_lvl3 = function () end,
pmovement_lvl1 = function () end,
pmovement_lvl2 = function () end,
pmovement_lvl3 = function () end,
fmovement_lvl1 = function () end,
fmovement_lvl2 = function () end,
fmovement_lvl3 = function () end,
flmovement_lvl1 = function () end,
flmovement_lvl2 = function () end,
flmovement_lvl3 = function () end,
path_mov_lvl1 = function () end,
path_mov_lvl2 = function () end,
path_mov_lvl3 = function () end,
fighting_lvl1 = function () end,
fighting_lvl2 = function () end,
fighting_lvl3 = function () end,
environment_lvl1 = function () end,
environment_lvl2 = function () end,
environment_lvl3 = function () end,
harvesting_lvl1 = function () end,
harvesting_lvl2 = function () end,
harvesting_lvl3 = function () end,
sound_lvl1 = function () end,
sound_lvl2 = function () end,
sound_lvl3 = function () end,
random_drop_lvl1 = function () end,
random_drop_lvl2 = function () end,
random_drop_lvl3 = function () end,
mob_state_lvl1 = function () end,
mob_state_lvl2 = function () end,
mob_state_lvl3 = function () end,
mobf_core_lvl1 = function () end,
mobf_core_lvl2 = function () end,
mobf_core_lvl3 = function () end,
mob_preserve_lvl1 = function () end,
mob_preserve_lvl2 = function () end,
mob_preserve_lvl3 = function () end,
mobf_core_helper_lvl1 = function () end,
mobf_core_helper_lvl2 = function () end,
mobf_core_helper_lvl3 = function () end,
trader_inv_lvl1 = function () end,
trader_inv_lvl2 = function () end,
trader_inv_lvl3 = function () end,
ride_lvl1 = function () end,
ride_lvl2 = function () end,
ride_lvl3 = function () end,
path_lvl1 = function () end,
path_lvl2 = function () end,
path_lvl3 = function () end,
lifebar_lvl1 = function () end,
lifebar_lvl2 = function () end,
lifebar_lvl3 = function () end,
attention_lvl1 = function () end,
attention_lvl2 = function () end,
attention_lvl3 = function () end,

View File

@ -164,7 +164,6 @@ function fighting.hit(entity,attacker)
mobf_lifebar.del(entity.lifebar)
--if entity.dynamic_data.generic.health < 1 then
local result = entity.data.generic.kill_result
if type(entity.data.generic.kill_result) == "function" then
result = entity.data.generic.kill_result()

View File

@ -30,7 +30,7 @@ mobf_job_queue = {}
-------------------------------------------------------------------------------
function mobf_job_queue.add_job(job)
table.insert(mobf_job_queue.queue, job)
statistics.data.queue.maxabs = MAX(statistics.data.queue.maxabs,#mobf_job_queue.queue)
statistics.data.queue.max = MAX(statistics.data.queue.max,#mobf_job_queue.queue)
end
-------------------------------------------------------------------------------

View File

@ -1,8 +1,8 @@
-------------------------------------------------------------------------------
-- Mob Framework Mod by Sapier
--
--
-- You may copy, use, modify or do nearly anything except removing this
-- copyright notice.
-- copyright notice.
-- And of course you are NOT allow to pretend you have written it.
--
--! @file path_based_movement_gen.lua
@ -13,7 +13,7 @@
--
--! @defgroup mgen_path_based MGEN: Path based movement generator
--! @ingroup framework_int
--! @{
--! @{
-- Contact sapier a t gmx net
-------------------------------------------------------------------------------
@ -43,42 +43,42 @@ function p_mov_gen.callback(entity,now,dstep)
mobf_assert_backtrace(entity ~= nil)
mobf_assert_backtrace(entity.dynamic_data ~= nil)
mobf_assert_backtrace(entity.dynamic_data.p_movement ~= nil)
if entity.dynamic_data.p_movement.eta ~= nil then
if now < entity.dynamic_data.p_movement.eta then
return
end
end
local current_pos = entity.object:getpos()
local handled = false
if entity.dynamic_data.p_movement.path == nil then
dbg_mobf.path_mov_lvl1(
"MOBF: path movement but mo path set!!")
return
end
local max_distance = entity.data.movement.max_distance
if entity.dynamic_data.movement.max_distance ~= nil then
max_distance = entity.dynamic_data.movement.max_distance
end
mobf_assert_backtrace(entity.dynamic_data.p_movement.next_path_index ~= nil)
mobf_assert_backtrace(max_distance ~= nil)
--check if target is reached
if p_mov_gen.distance_to_next_point(entity,current_pos)
if p_mov_gen.distance_to_next_point(entity,current_pos)
< max_distance then
dbg_mobf.path_mov_lvl1("MOBF: pathmov next to next point switching target")
local update_target = true
--return to begining of path
if entity.dynamic_data.p_movement.next_path_index
if entity.dynamic_data.p_movement.next_path_index
== #entity.dynamic_data.p_movement.path then
if entity.dynamic_data.p_movement.cycle_path or
(entity.dynamic_data.p_movement.cycle_path == nil and
entity.data.patrol ~= nil and
@ -95,36 +95,36 @@ function p_mov_gen.callback(entity,now,dstep)
handled = true
end
end
if update_target then
mobf_assert_backtrace(entity.dynamic_data.p_movement.path ~= nil)
entity.dynamic_data.p_movement.next_path_index =
entity.dynamic_data.p_movement.next_path_index =
entity.dynamic_data.p_movement.next_path_index + 1
entity.dynamic_data.movement.target =
entity.dynamic_data.movement.target =
entity.dynamic_data.p_movement.path
[entity.dynamic_data.p_movement.next_path_index]
dbg_mobf.path_mov_lvl1("MOBF: (1) setting new target to index: " ..
entity.dynamic_data.p_movement.next_path_index .. " pos: " ..
printpos(entity.dynamic_data.movement.target))
handled = true
end
end
if not handled and
entity.dynamic_data.movement.target == nil then
mobf_assert_backtrace(entity.dynamic_data.p_movement.path ~= nil)
entity.dynamic_data.movement.target =
entity.dynamic_data.movement.target =
entity.dynamic_data.p_movement.path
[entity.dynamic_data.p_movement.next_path_index]
dbg_mobf.path_mov_lvl1("MOBF: (2) setting new target to index: " ..
entity.dynamic_data.p_movement.next_path_index .. " pos: " ..
printpos(entity.dynamic_data.movement.target))
end
mgen_follow.callback(entity,now)
end
@ -138,7 +138,7 @@ end
--
--! @param entity mob to check
--! @param current_pos position mob is atm
--
--
--! @retval distance
-------------------------------------------------------------------------------
function p_mov_gen.distance_to_next_point(entity,current_pos)
@ -172,20 +172,21 @@ function p_mov_gen.init_dynamic_data(entity,now,restored_data)
pathowner = nil,
pathname = nil,
}
if restored_data ~= nil then
if restored_data ~= nil and
type(restored_data) == "table" then
dbg_mobf.path_mov_lvl3(
"MOBF: path movement reading stored data: " .. dump(restored_data))
if restored_data.pathowner ~= nil and
restored_data.pathname ~= nil then
data.pathowner = restored_data.pathowner
data.pathname = restored_data.pathname
data.path = mobf_path.getpoints(data.pathowner,data.pathname)
dbg_mobf.path_mov_lvl3(
"MOBF: path movement restored points: " .. dump(data.path))
end
if restored_data.pathindex ~= nil and
type(restored_data.pathindex) == "number" and
restored_data.pathindex > 0 and
@ -194,9 +195,9 @@ function p_mov_gen.init_dynamic_data(entity,now,restored_data)
data.next_path_index = restored_data.pathindex
end
end
entity.dynamic_data.p_movement = data
mgen_follow.init_dynamic_data(entity,now)
end
@ -216,10 +217,10 @@ function p_mov_gen.set_path(entity,path)
entity.dynamic_data.p_movement.next_path_index = 1
entity.dynamic_data.movement.max_distance = 0.5
entity.dynamic_data.p_movement.path = path
--a valid path has at least 2 positions
mobf_assert_backtrace(#entity.dynamic_data.p_movement.path > 1)
entity.dynamic_data.movement.target =
entity.dynamic_data.movement.target =
entity.dynamic_data.p_movement.path[2]
return true
else
@ -272,10 +273,10 @@ end
-------------------------------------------------------------------------------
function p_mov_gen.set_target(entity,target)
mobf_assert_backtrace(target ~= nil)
local current_pos = entity.getbasepos(entity)
local targetpos = nil
if not mobf_is_pos(target) then
if target:is_player() then
targetpos = target:getpos()
@ -290,55 +291,55 @@ function p_mov_gen.set_target(entity,target)
else
targetpos = target
end
if targetpos == nil then
return false
end
if entity.dynamic_data.p_movement.lasttargetpos ~= nil then
if mobf_pos_is_same(entity.dynamic_data.p_movement.lasttargetpos,
targetpos) then
return true
end
end
entity.dynamic_data.p_movement.lasttargetpos = targetpos
entity.dynamic_data.p_movement.path = nil
entity.dynamic_data.p_movement.next_path_index = 1
--on target mode max distance is always 0.5
entity.dynamic_data.movement.max_distance = 0.5
--try to find path on our own
if not mobf_get_world_setting("mobf_disable_pathfinding") then
entity.dynamic_data.p_movement.path =
entity.dynamic_data.p_movement.path =
minetest.find_path(current_pos,targetpos,5,1,1,nil)
else
entity.dynamic_data.p_movement.path = nil
end
if entity.dynamic_data.p_movement.path ~= nil then
--a valid path has at least 2 positions
mobf_assert_backtrace(#entity.dynamic_data.p_movement.path > 1)
entity.dynamic_data.movement.target =
entity.dynamic_data.movement.target =
entity.dynamic_data.p_movement.path[2]
return true
end
if entity.dynamic_data.p_movement.path == nil then
print(
"MOBF: no pathfinding support/ no path found directly setting targetpos as path")
entity.dynamic_data.p_movement.path = {}
table.insert(entity.dynamic_data.p_movement.path,targetpos)
entity.dynamic_data.movement.target =
entity.dynamic_data.movement.target =
entity.dynamic_data.p_movement.path[1]
return true
end
return false
end