Add debug print mechanism
parent
61d8a5bd5d
commit
a92d9daf75
48
factions.lua
48
factions.lua
|
@ -26,6 +26,14 @@ factions.data.objects = {}
|
|||
factions.dynamic_data = {}
|
||||
factions.dynamic_data.membertable = {}
|
||||
|
||||
factions.print = function(text)
|
||||
print("Factions: " .. dump(text))
|
||||
end
|
||||
|
||||
factions.dbg_lvl1 = function() end --factions.print -- errors
|
||||
factions.dbg_lvl2 = function() end --factions.print -- non cyclic trace
|
||||
factions.dbg_lvl3 = function() end --factions.print -- cyclic trace
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: add_faction(name)
|
||||
--
|
||||
|
@ -83,7 +91,7 @@ function factions.set_base_reputation(faction1,faction2,value)
|
|||
end
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- name: get_base_reputation(faction1,faction2,value)
|
||||
-- name: get_base_reputation(faction1,faction2)
|
||||
--
|
||||
--! @brief get base reputation between two factions
|
||||
--! @memberof factions
|
||||
|
@ -94,8 +102,8 @@ end
|
|||
--!
|
||||
--! @return reputation/0 if none set
|
||||
-------------------------------------------------------------------------------
|
||||
function factions.get_base_reputation(faction1,faction2,value)
|
||||
|
||||
function factions.get_base_reputation(faction1,faction2)
|
||||
factions.dbg_lvl3("get_base_reputation: " .. faction1 .. "<-->" .. faction2)
|
||||
if factions.data.factions[faction1] ~= nil and
|
||||
factions.data.factions[faction2] ~= nil then
|
||||
if factions.data.factions[faction1].base_reputation[faction2] ~= nil then
|
||||
|
@ -119,7 +127,7 @@ end
|
|||
-------------------------------------------------------------------------------
|
||||
function factions.set_description(name,description)
|
||||
|
||||
if factions.data.factions[name] ~= nil then
|
||||
if factions.data.factions[name] ~= nil then
|
||||
factions.data.factions[name].description = description
|
||||
factions.save()
|
||||
return true
|
||||
|
@ -140,7 +148,7 @@ end
|
|||
-------------------------------------------------------------------------------
|
||||
function factions.get_description(name)
|
||||
|
||||
if factions.data.factions[name] ~= nil and
|
||||
if factions.data.factions[name] ~= nil and
|
||||
factions.data.factions[name].description ~= nil then
|
||||
return factions.data.factions[name].description
|
||||
end
|
||||
|
@ -239,6 +247,8 @@ function factions.member_add(name, object)
|
|||
|
||||
new_entry.name,new_entry.temporary = factions.get_name(object)
|
||||
|
||||
factions.dbg_lvl2("Adding name=" .. dump(new_entry.name) .. " to faction: " .. name )
|
||||
|
||||
if new_entry.name ~= nil then
|
||||
if factions.data.objects[new_entry.name] == nil then
|
||||
factions.data.objects[new_entry.name] = new_entry
|
||||
|
@ -298,6 +308,8 @@ function factions.member_remove(name,object)
|
|||
|
||||
local id,type = factions.get_name(object)
|
||||
|
||||
factions.dbg_lvl2("removing name=" .. dump(id) .. " to faction: " .. name )
|
||||
|
||||
if id ~= nil and
|
||||
factions.data.objects[id] ~= nil and
|
||||
factions.data.objects[id].factions[name] ~= nil then
|
||||
|
@ -467,7 +479,7 @@ function factions.get_factions(object)
|
|||
local id,type = factions.get_name(object)
|
||||
|
||||
local retval = {}
|
||||
if id ~= nil and
|
||||
if id ~= nil and
|
||||
factions.data.objects[id] ~= nil then
|
||||
for key,value in pairs(factions.data.objects[id].factions) do
|
||||
table.insert(retval,key)
|
||||
|
@ -495,7 +507,7 @@ function factions.is_member(name,object)
|
|||
|
||||
local id,type = factions.get_name(object)
|
||||
|
||||
if id ~= nil and
|
||||
if id ~= nil and
|
||||
factions.data.objects[id] ~= nil then
|
||||
for key,value in pairs(factions.data.objects[id].factions) do
|
||||
if key == name then
|
||||
|
@ -525,15 +537,21 @@ function factions.get_reputation(name,object)
|
|||
|
||||
local id,type = factions.get_name(object)
|
||||
|
||||
factions.dbg_lvl3("get_reputation: " .. name .. "<-->" .. dump(id))
|
||||
|
||||
if id ~= nil and
|
||||
factions.data.factions[name] ~= nil then
|
||||
|
||||
if factions.data.factions[name].reputation[id] == nil then
|
||||
factions.dbg_lvl3("get_reputation: object reputation: " .. dump(factions.data.factions[name].reputation[id]))
|
||||
|
||||
if factions.data.factions[name].reputation[id] == nil then
|
||||
factions.data.factions[name].reputation[id]
|
||||
= factions.calc_base_reputation(name,object)
|
||||
end
|
||||
|
||||
return factions.data.factions[name].reputation[id]
|
||||
return factions.data.factions[name].reputation[id]
|
||||
else
|
||||
factions.dbg_lvl3("get_reputation: didn't find any factions for: " .. name)
|
||||
end
|
||||
|
||||
return 0
|
||||
|
@ -558,11 +576,11 @@ function factions.modify_reputation(name,object,delta)
|
|||
|
||||
if factions.data.factions[name] ~= nil then
|
||||
if factions.data.factions[name].reputation[id] == nil then
|
||||
factions.data.factions[name].reputation[id]
|
||||
factions.data.factions[name].reputation[id]
|
||||
= factions.calc_base_reputation(name,object)
|
||||
end
|
||||
|
||||
factions.data.factions[name].reputation[id]
|
||||
factions.data.factions[name].reputation[id]
|
||||
= factions.data.factions[name].reputation[id] + delta
|
||||
factions.save()
|
||||
return true
|
||||
|
@ -622,13 +640,17 @@ function factions.calc_base_reputation(name,object)
|
|||
local object_factions = factions.get_factions(object)
|
||||
local rep_value = 0
|
||||
|
||||
factions.dbg_lvl3("calc_base_reputation: " .. name .. " <--> " .. tostring(object))
|
||||
|
||||
if object_factions ~= nil then
|
||||
factions.dbg_lvl3("calc_base_reputation: " .. tostring(object) .. " is in " .. #object_factions .. " factions")
|
||||
for k,v in pairs(object_factions) do
|
||||
if factions.data.factions[v] == nil then
|
||||
print("FACTIONS: warning object is member of faction " .. v .. " which doesn't exist")
|
||||
else
|
||||
factions.dbg_lvl3("calc_base_reputation: " .. name .. " <--> " .. v .. " rep=" .. dump(factions.data.factions[v].base_reputation[name]))
|
||||
if factions.data.factions[v].base_reputation[name] ~= nil then
|
||||
rep_value =
|
||||
rep_value =
|
||||
rep_value + factions.data.factions[v].base_reputation[name]
|
||||
end
|
||||
end
|
||||
|
@ -714,7 +736,7 @@ function factions.load()
|
|||
if temp_objects[repkey] == nil then
|
||||
factions.data.factions[key].reputation[repkey] = repvalue
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
factions.dynamic_data.membertable[key] = {}
|
||||
end
|
||||
|
|
6
init.lua
6
init.lua
|
@ -12,9 +12,9 @@
|
|||
-- Contact sapier a t gmx net
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
local factions_version = "0.1.5"
|
||||
local factions_version = "0.1.6"
|
||||
|
||||
print("MOD: factions (by sapier) loading ...")
|
||||
core.log("action", "MOD: factions (by sapier) loading ...")
|
||||
|
||||
--!path of mod
|
||||
factions_modpath = minetest.get_modpath("factions")
|
||||
|
@ -26,4 +26,4 @@ dofile (factions_modpath .. "/chatcommands.lua")
|
|||
factions.load()
|
||||
factions_chat.init()
|
||||
|
||||
print("MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
||||
core.log("action","MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
||||
|
|
Loading…
Reference in New Issue