2012-09-19 23:30:14 +02:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- Mob Framework Mod by Sapier
|
|
|
|
--
|
|
|
|
-- You may copy, use, modify or do nearly anything except removing this
|
|
|
|
-- copyright notice.
|
|
|
|
-- And of course you are NOT allow to pretend you have written it.
|
|
|
|
--
|
|
|
|
--! @file debug.lua
|
|
|
|
--! @brief contains debug functions for mob framework
|
|
|
|
--! @copyright Sapier
|
|
|
|
--! @author Sapier
|
|
|
|
--! @date 2012-08-09
|
|
|
|
--!
|
|
|
|
-- Contact sapier a t gmx net
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
--! @defgroup debug_in_game In game debugging functions
|
|
|
|
--! @brief debugging functions to be called from in game
|
|
|
|
--! @ingroup framework_int
|
|
|
|
--! @{
|
|
|
|
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug = {}
|
2013-01-04 23:49:58 +00:00
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: print_usage(player,command,toadd)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief send errormessage to player
|
|
|
|
--
|
|
|
|
--! @param player name of player to print usage
|
|
|
|
--! @param command display usage for this command
|
|
|
|
--! @param toadd additional information to transfer to player
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.print_usage(player, command, toadd)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
if toadd == nil then
|
|
|
|
toadd = ""
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "spawnmob" then
|
|
|
|
print("CMD: ".. player .."> ".. "Usage: /spawnmob <mobname> <X,Y,Z> " .. toadd)
|
|
|
|
minetest.chat_send_player(player, "Usage: /spawnmob <mobname> <X,Y,Z> " .. toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "ukn_mob" then
|
|
|
|
print("CMD: ".. player .."> ".. "Unknown mob name "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Unknown mob name "..toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "inv_pos" then
|
|
|
|
print("CMD: ".. player .."> ".. "Invalid position "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Invalid position "..toadd)
|
|
|
|
end
|
|
|
|
|
|
|
|
if command == "mob_spawned" then
|
|
|
|
print("CMD: ".. player .."> ".. "Mob successfully spawned "..toadd)
|
|
|
|
minetest.chat_send_player(player, "Mob successfully spawned "..toadd)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: spawn_mob(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief handle a spawn mob command
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.spawn_mob(name,param)
|
2013-01-04 23:49:58 +00:00
|
|
|
print("name: " .. name .. " param: " .. dump(param))
|
|
|
|
|
|
|
|
local parameters = param:split(" ")
|
|
|
|
|
2013-04-14 01:08:11 +02:00
|
|
|
if #parameters ~= 1 and
|
|
|
|
#parameters ~= 2 then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"spawnmob")
|
2013-01-04 23:49:58 +00:00
|
|
|
return
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
if mobf_is_known_mob(parameters[1]) ~= true then
|
2013-01-06 23:25:30 +00:00
|
|
|
mobf_debug.print_usage(name,"ukn_mob", ">"..parameters[1].."<")
|
2012-09-19 23:30:14 +02:00
|
|
|
return true
|
|
|
|
end
|
2013-04-14 01:08:11 +02:00
|
|
|
|
|
|
|
if #parameters == 2 then
|
|
|
|
local pos_strings = parameters[2]:split(",")
|
|
|
|
|
|
|
|
if #pos_strings ~= 3 then
|
|
|
|
mobf_debug.print_usage(name,"spawmob")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local spawnpoint = {
|
|
|
|
x=tonumber(pos_strings[1]),
|
|
|
|
y=tonumber(pos_strings[2]),
|
|
|
|
z=tonumber(pos_strings[3])
|
|
|
|
}
|
|
|
|
|
|
|
|
if spawnpoint.x == nil or
|
|
|
|
spawnpoint.y == nil or
|
|
|
|
spawnpoint.z == nil then
|
|
|
|
mobf_debug.print_usage(name,"spawnmob")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
spawning.spawn_and_check(parameters[1],"__default",spawnpoint,"mobf_debug_spawner")
|
|
|
|
else
|
|
|
|
--todo find random pos
|
2012-09-19 23:30:14 +02:00
|
|
|
|
2013-04-14 01:08:11 +02:00
|
|
|
local player = minetest.env:get_player_by_name(name)
|
|
|
|
|
|
|
|
if player == nil then
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local pos = player:getpos()
|
|
|
|
|
|
|
|
if pos == nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local found = false
|
|
|
|
local maxtries = 10
|
|
|
|
|
|
|
|
while (found == false) and (maxtries > 0) do
|
|
|
|
toadd = {}
|
|
|
|
toadd.x = pos.x + (math.random(20) -10)
|
|
|
|
toadd.z = pos.z + (math.random(20) -10)
|
|
|
|
|
|
|
|
local y = mobf_get_surface(toadd.x,toadd.z,pos.y-10,pos.y+10)
|
|
|
|
|
|
|
|
if y ~= nil then
|
2013-04-14 11:37:01 +02:00
|
|
|
toadd.y = y +2
|
2013-04-14 01:08:11 +02:00
|
|
|
if spawning.spawn_and_check(parameters[1],"__default",toadd,"mobf_debug_spawner") then
|
|
|
|
found = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
maxtries = maxtries -1
|
|
|
|
end
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
2013-04-14 01:08:11 +02:00
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: list_active_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief print list of all current active mobs
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.list_active_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
local count = 1
|
|
|
|
for index,value in pairs(minetest.luaentities) do
|
2013-01-19 13:50:54 +00:00
|
|
|
if value.data ~= nil and value.data.name ~= nil then
|
2013-01-04 23:49:58 +00:00
|
|
|
local tosend = count .. ": " .. value.data.name .. " at "
|
|
|
|
.. printpos(value.object:getpos())
|
2012-09-19 23:30:14 +02:00
|
|
|
print(tosend)
|
|
|
|
minetest.chat_send_player(name,tosend)
|
|
|
|
count = count +1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-24 14:23:24 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: mob_count(name,param)
|
|
|
|
--
|
|
|
|
--! @brief count active mobs
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
|
|
|
--! @param param parameters received
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
function mobf_debug.mob_count(name,param)
|
|
|
|
|
|
|
|
local count = 1
|
|
|
|
for index,value in pairs(minetest.luaentities) do
|
|
|
|
if value.data ~= nil and value.data.name ~= nil then
|
|
|
|
count = count +1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.chat_send_player(name,"Active mobs: " .. count)
|
|
|
|
end
|
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: add_tools(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief add toolset for testing
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.add_tools(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
local player = minetest.env:get_player_by_name(name)
|
|
|
|
|
|
|
|
if player ~= nil then
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:lasso 20")
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:net 20")
|
|
|
|
player:get_inventory():add_item("main", "animalmaterials:scissors 1")
|
2013-04-07 16:43:20 +02:00
|
|
|
player:get_inventory():add_item("main", "vessels:drinking_glass 10")
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-04 23:49:58 +00:00
|
|
|
-- name: list_defined_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief list all registred mobs
|
|
|
|
--
|
|
|
|
--! @param name name of player
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param param parameters received
|
2012-09-19 23:30:14 +02:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.list_defined_mobs(name,param)
|
2012-09-19 23:30:14 +02:00
|
|
|
|
|
|
|
local text = ""
|
2013-01-04 23:49:58 +00:00
|
|
|
for i,val in ipairs(mobf_rtd.registred_mob) do
|
2012-09-19 23:30:14 +02:00
|
|
|
text = text .. val .. " "
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(name, "MOBF: "..text)
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
-- name: init()
|
2012-09-19 23:30:14 +02:00
|
|
|
--
|
|
|
|
--! @brief initialize debug commands chat handler
|
|
|
|
--
|
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.init()
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
minetest.register_chatcommand("spawnmob",
|
|
|
|
{
|
|
|
|
params = "<name> <pos>",
|
2013-04-14 01:08:11 +02:00
|
|
|
description = "spawn a mob at position(optional)" ,
|
2013-01-04 23:49:58 +00:00
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.spawn_mob
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("listactivemobs",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "list all currently active mobs" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.list_active_mobs
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("listdefinedmobs",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "list all currently defined mobs" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.list_defined_mobs
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_chatcommand("mob_add_tools",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "add some mob specific tools to player" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-01-06 23:25:30 +00:00
|
|
|
func = mobf_debug.add_tools
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
2013-01-19 13:50:54 +00:00
|
|
|
|
|
|
|
minetest.register_chatcommand("mobf_version",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "show mobf version number" ,
|
2013-01-26 10:28:51 +00:00
|
|
|
privs = {},
|
2013-01-19 13:50:54 +00:00
|
|
|
func = function(name,param)
|
|
|
|
minetest.chat_send_player(name,"MOBF version: " .. mobf_version)
|
|
|
|
end
|
|
|
|
})
|
2013-02-24 14:23:24 +00:00
|
|
|
|
|
|
|
minetest.register_chatcommand("mobf_count",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "number of active mobs" ,
|
|
|
|
privs = {},
|
|
|
|
func = mobf_debug.mob_count
|
|
|
|
})
|
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
|
|
|
|
if mobf_rtd.luatrace_enabled then
|
|
|
|
minetest.register_chatcommand("traceon",
|
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "start luatrace tracing" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-04-14 01:08:11 +02:00
|
|
|
func = function()
|
|
|
|
luatrace.tron(nil)
|
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
|
2013-04-14 01:08:11 +02:00
|
|
|
minetest.register_chatcommand("traceoff",
|
2013-01-04 23:49:58 +00:00
|
|
|
{
|
|
|
|
params = "",
|
|
|
|
description = "stop luatrace tracing" ,
|
|
|
|
privs = {mobfw_admin=true},
|
2013-04-14 01:08:11 +02:00
|
|
|
func = function()
|
|
|
|
luatrace.troff()
|
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
})
|
|
|
|
end
|
2012-09-19 23:30:14 +02:00
|
|
|
end
|
|
|
|
|
2013-01-03 01:08:23 +00:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: handle_spawnhouse(name,message)
|
|
|
|
--
|
|
|
|
--! @brief spawn small house
|
|
|
|
--
|
2013-01-04 23:49:58 +00:00
|
|
|
--! @param entity entity rightclicked
|
|
|
|
--! @param player player doing rightclick
|
2013-01-03 01:08:23 +00:00
|
|
|
------------------------------------------------------------------------------
|
2013-01-06 23:25:30 +00:00
|
|
|
function mobf_debug.rightclick_callback(entity,player)
|
2013-01-04 23:49:58 +00:00
|
|
|
local lifetime = mobf_get_current_time() - entity.dynamic_data.spawning.original_spawntime
|
|
|
|
print("MOBF: " .. entity.data.name .. " is alive for " .. lifetime .. " seconds")
|
|
|
|
print("MOBF: \tCurrent state: " .. entity.dynamic_data.state.current )
|
|
|
|
print("MOBF: \tCurrent movgen: " .. entity.dynamic_data.current_movement_gen.name )
|
2013-02-10 16:29:59 +00:00
|
|
|
if entity.dynamic_data.current_movement_gen.name == "follow_mov_gen" or
|
|
|
|
entity.dynamic_data.current_movement_gen.name == "mgen_path" then
|
2013-01-25 23:07:21 +00:00
|
|
|
local basepos = entity.getbasepos(entity)
|
2013-02-10 16:29:59 +00:00
|
|
|
|
|
|
|
local targetpos = entity.dynamic_data.spawning.spawnpoint
|
|
|
|
if entity.dynamic_data.movement.target ~= nil then
|
|
|
|
if not mobf_is_pos(entity.dynamic_data.movement.target) then
|
|
|
|
targetpos = entity.dynamic_data.movement.target:getpos()
|
|
|
|
else
|
|
|
|
targetpos = entity.dynamic_data.movement.target
|
|
|
|
end
|
2013-01-25 23:07:21 +00:00
|
|
|
end
|
2013-02-03 23:13:59 +00:00
|
|
|
if targetpos ~= nil then
|
|
|
|
print("MOBF: \t\tmovement state: " .. mgen_follow.identify_movement_state(basepos,targetpos) )
|
|
|
|
else
|
|
|
|
print("MOBF: \t\tmovement state: invalid")
|
|
|
|
end
|
|
|
|
print("MOBF: \t\tguard spawnpoint: " .. dump(entity.dynamic_data.movement.guardspawnpoint))
|
2013-02-10 16:29:59 +00:00
|
|
|
print("MOBF: \t\ttarget: " .. dump(entity.dynamic_data.movement.target))
|
|
|
|
end
|
|
|
|
if entity.dynamic_data.current_movement_gen.name == "mgen_path" then
|
|
|
|
print("MOBF: \t\tpath index: " .. entity.dynamic_data.p_movement.next_path_index)
|
|
|
|
print("MOBF: \t\tpath: " .. dump(entity.dynamic_data.p_movement.path))
|
|
|
|
print("MOBF: \t\tdistance to next point: " .. p_mov_gen.distance_to_next_point(entity,entity.object:getpos()))
|
2013-01-25 23:07:21 +00:00
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
print("MOBF: \tTime to state change: " .. entity.dynamic_data.state.time_to_next_change .. " seconds")
|
2013-01-19 13:50:54 +00:00
|
|
|
print("MOBF: \tCurrent environmental state: " .. environment.pos_is_ok(entity.getbasepos(entity),entity))
|
2013-01-04 23:49:58 +00:00
|
|
|
print("MOBF: \tCurrent accel: " .. printpos(entity.object:getacceleration()))
|
|
|
|
print("MOBF: \tCurrent speed: " .. printpos(entity.object:getvelocity()))
|
2013-02-05 21:18:52 +00:00
|
|
|
print("MOBF: \tSpawnpoint: " .. printpos(entity.dynamic_data.spawning.spawnpoint))
|
|
|
|
print("MOBF: \tSpawner: " .. dump(entity.dynamic_data.spawning.spawner))
|
|
|
|
print("MOBF: \tCurrent pos: " .. printpos(entity.object:getpos()))
|
2013-02-03 19:28:32 +00:00
|
|
|
if entity.dynamic_data.combat ~= nil then
|
2013-04-14 11:37:01 +02:00
|
|
|
print("MOBF: \tCurrent combat target: " .. fighting.get_target_name(entity.dynamic_data.combat.target))
|
|
|
|
end
|
|
|
|
if entity.dynamic_data.attention ~= nil then
|
|
|
|
print("MOBF: \t Current attention table:")
|
|
|
|
for k,v in pairs(entity.dynamic_data.attention.watched_objects) do
|
|
|
|
print("MOBF: \t\t " .. k .. ": " .. v.value)
|
|
|
|
end
|
2013-02-03 19:28:32 +00:00
|
|
|
end
|
2013-01-04 23:49:58 +00:00
|
|
|
return false
|
2013-01-03 01:08:23 +00:00
|
|
|
end
|
|
|
|
|
2013-01-04 23:49:58 +00:00
|
|
|
|
2012-09-19 23:30:14 +02:00
|
|
|
--!@}
|