Adjust Lua diagnostics
This commit is contained in:
@@ -39,6 +39,8 @@
|
|||||||
--
|
--
|
||||||
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
---@diagnostic disable
|
||||||
|
|
||||||
require("PGDebug")
|
require("PGDebug")
|
||||||
|
|
||||||
YieldCount = 0;
|
YieldCount = 0;
|
||||||
@@ -52,7 +54,6 @@ function ScriptExit()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Sleep(time)
|
function Sleep(time)
|
||||||
|
|
||||||
--DebugMessage("Sleeping... SleepTime: %.3f, CurTime: %.3f\n", time, GetCurrentTime())
|
--DebugMessage("Sleeping... SleepTime: %.3f, CurTime: %.3f\n", time, GetCurrentTime())
|
||||||
ThreadValue.Set("StartTime", GetCurrentTime())
|
ThreadValue.Set("StartTime", GetCurrentTime())
|
||||||
while GetCurrentTime() - ThreadValue("StartTime") < time do
|
while GetCurrentTime() - ThreadValue("StartTime") < time do
|
||||||
@@ -64,7 +65,6 @@ end
|
|||||||
-- Service the block until optional max duration has expired or alternate break function returns true
|
-- Service the block until optional max duration has expired or alternate break function returns true
|
||||||
-- Pass -1 max_duration to use optional alternate break function with no time limit
|
-- Pass -1 max_duration to use optional alternate break function with no time limit
|
||||||
function BlockOnCommand(block, max_duration, alternate_break_func)
|
function BlockOnCommand(block, max_duration, alternate_break_func)
|
||||||
|
|
||||||
PumpEvents()
|
PumpEvents()
|
||||||
|
|
||||||
if not block then
|
if not block then
|
||||||
@@ -93,7 +93,6 @@ function BlockOnCommand(block, max_duration, alternate_break_func)
|
|||||||
--MessageBox("%s-- had a break func and it returned true", tostring(Script))
|
--MessageBox("%s-- had a break func and it returned true", tostring(Script))
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
until (block.IsFinished() == true)
|
until (block.IsFinished() == true)
|
||||||
|
|
||||||
PumpEvents()
|
PumpEvents()
|
||||||
@@ -116,7 +115,6 @@ function TestCommand(block)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function PumpEvents()
|
function PumpEvents()
|
||||||
|
|
||||||
if Object and type(Object) == "userdata" then
|
if Object and type(Object) == "userdata" then
|
||||||
Object.Service_Wrapper()
|
Object.Service_Wrapper()
|
||||||
end
|
end
|
||||||
@@ -183,24 +181,23 @@ function Dirty_Floor(val)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Machine independent modulus function
|
-- Machine independent modulus function
|
||||||
function Simple_Mod(a,b)
|
function Simple_Mod(a, b)
|
||||||
--return a-b*math.floor(a/b)
|
--return a-b*math.floor(a/b)
|
||||||
return a-b*Dirty_Floor(a/b)
|
return a - b * Dirty_Floor(a / b)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Returns if something happened, given a % chance
|
-- Returns if something happened, given a % chance
|
||||||
function Chance(seed, percent)
|
function Chance(seed, percent)
|
||||||
roll = Simple_Mod((seed + 1), 100)
|
roll = Simple_Mod((seed + 1), 100)
|
||||||
is_allowed = roll < percent
|
is_allowed = roll < percent
|
||||||
DebugMessage("%s -- seed:%d percent:%d roll:%d is_allowed:%s", tostring(Script), seed, percent, roll, tostring(is_allowed))
|
DebugMessage("%s -- seed:%d percent:%d roll:%d is_allowed:%s", tostring(Script), seed, percent, roll,
|
||||||
|
tostring(is_allowed))
|
||||||
return is_allowed
|
return is_allowed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function GetCurrentMinute()
|
function GetCurrentMinute()
|
||||||
--return math.floor(GetCurrentTime()/60)
|
--return math.floor(GetCurrentTime()/60)
|
||||||
return Dirty_Floor(GetCurrentTime()/60)
|
return Dirty_Floor(GetCurrentTime() / 60)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Every X seconds, the AI will have a new opportunity to see if it's allowed to use an ability
|
-- Every X seconds, the AI will have a new opportunity to see if it's allowed to use an ability
|
||||||
@@ -219,16 +216,14 @@ function GetChanceAllowed(difficulty)
|
|||||||
return chance
|
return chance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function PlayerSpecificName(player_object, var_name)
|
function PlayerSpecificName(player_object, var_name)
|
||||||
-- ret_value = tostring(player_object.Get_ID()) .. "_" .. var_name
|
-- ret_value = tostring(player_object.Get_ID()) .. "_" .. var_name
|
||||||
-- DebugMessage("%s -- creating player specific string %s.", tostring(Script), ret_value)
|
-- DebugMessage("%s -- creating player specific string %s.", tostring(Script), ret_value)
|
||||||
-- return ret_value
|
-- return ret_value
|
||||||
return (tostring("PLAYER" .. player_object.Get_ID()) .. "_" .. var_name)
|
return (tostring("PLAYER" .. player_object.Get_ID()) .. "_" .. var_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Flush_G()
|
function Flush_G()
|
||||||
|
|
||||||
entries_for_deletion = {}
|
entries_for_deletion = {}
|
||||||
|
|
||||||
--Define the set of tables that we had better keep around
|
--Define the set of tables that we had better keep around
|
||||||
@@ -247,13 +242,12 @@ function Flush_G()
|
|||||||
table.insert(very_important_tables, very_important_tables)
|
table.insert(very_important_tables, very_important_tables)
|
||||||
|
|
||||||
--Iterate all globals
|
--Iterate all globals
|
||||||
for i,g_entry in pairs(_G) do
|
for i, g_entry in pairs(_G) do
|
||||||
|
|
||||||
if type(g_entry) == "table" then
|
if type(g_entry) == "table" then
|
||||||
--Tables are inherently unsafe: who knows what might be in there?
|
--Tables are inherently unsafe: who knows what might be in there?
|
||||||
--If they're not in the list of things we must keep then they go.
|
--If they're not in the list of things we must keep then they go.
|
||||||
|
|
||||||
for j,important_entry in pairs(very_important_tables) do
|
for j, important_entry in pairs(very_important_tables) do
|
||||||
if important_entry == g_entry then
|
if important_entry == g_entry then
|
||||||
keep_table = true
|
keep_table = true
|
||||||
end
|
end
|
||||||
@@ -263,7 +257,6 @@ function Flush_G()
|
|||||||
end
|
end
|
||||||
|
|
||||||
keep_table = nil
|
keep_table = nil
|
||||||
|
|
||||||
elseif type(g_entry) == "userdata" then
|
elseif type(g_entry) == "userdata" then
|
||||||
--Some User Data (e.g. our code functions) should be kept, but some is very, very dangerous.
|
--Some User Data (e.g. our code functions) should be kept, but some is very, very dangerous.
|
||||||
--Query the object to see whether it's safe to persist.
|
--Query the object to see whether it's safe to persist.
|
||||||
@@ -271,17 +264,13 @@ function Flush_G()
|
|||||||
if not g_entry.Is_Pool_Safe() then
|
if not g_entry.Is_Pool_Safe() then
|
||||||
table.insert(entries_for_deletion, i)
|
table.insert(entries_for_deletion, i)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
for i, bad_entry in pairs(entries_for_deletion) do
|
||||||
|
|
||||||
for i,bad_entry in pairs(entries_for_deletion) do
|
|
||||||
_G[bad_entry] = nil
|
_G[bad_entry] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
entries_for_deletion = nil
|
entries_for_deletion = nil
|
||||||
very_important_tables = nil
|
very_important_tables = nil
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
--
|
--
|
||||||
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
---@diagnostic disable
|
||||||
|
|
||||||
function DebugEventAlert(event, params)
|
function DebugEventAlert(event, params)
|
||||||
message = tostring(Script) .. ": handled event " .. tostring(event)
|
message = tostring(Script) .. ": handled event " .. tostring(event)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ function Base_Definitions()
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Main script function. Does event pumps and servicing.
|
---Main script function. Does event pumps and servicing.
|
||||||
|
---@diagnostic disable-next-line
|
||||||
function main()
|
function main()
|
||||||
DebugMessage("%s -- In main.", tostring(Script))
|
DebugMessage("%s -- In main.", tostring(Script))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user