Compare commits
3 Commits
77490ae8df
...
2490a7105a
| Author | SHA1 | Date | |
|---|---|---|---|
| 2490a7105a | |||
| c820748eca | |||
| 2244f6494b |
@@ -39,20 +39,21 @@
|
|||||||
--
|
--
|
||||||
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
---@diagnostic disable
|
||||||
|
|
||||||
require("PGDebug")
|
require("PGDebug")
|
||||||
|
|
||||||
YieldCount = 0;
|
YieldCount = 0;
|
||||||
|
|
||||||
function ScriptExit()
|
function ScriptExit()
|
||||||
_ScriptExit() -- set a flag in 'C' to terminate the whole script on next yield
|
_ScriptExit() -- set a flag in 'C' to terminate the whole script on next yield
|
||||||
|
|
||||||
if GetThreadID() >= 0 then
|
if GetThreadID() >= 0 then
|
||||||
coroutine.yield(false) -- return false to exit this thread
|
coroutine.yield(false) -- return false to exit this thread
|
||||||
end
|
end
|
||||||
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
|
||||||
@@ -72,9 +72,9 @@ function BlockOnCommand(block, max_duration, alternate_break_func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
break_block = false
|
break_block = false
|
||||||
|
|
||||||
ThreadValue.Set("BlockStart", GetCurrentTime())
|
ThreadValue.Set("BlockStart", GetCurrentTime())
|
||||||
|
|
||||||
repeat
|
repeat
|
||||||
if break_block == true then
|
if break_block == true then
|
||||||
break_block = false
|
break_block = false
|
||||||
@@ -82,9 +82,9 @@ function BlockOnCommand(block, max_duration, alternate_break_func)
|
|||||||
end
|
end
|
||||||
|
|
||||||
PumpEvents()
|
PumpEvents()
|
||||||
|
|
||||||
if ((max_duration ~= nil) and (max_duration ~= -1)
|
if ((max_duration ~= nil) and (max_duration ~= -1)
|
||||||
and (GetCurrentTime() - ThreadValue("BlockStart") > max_duration)) then
|
and (GetCurrentTime() - ThreadValue("BlockStart") > max_duration)) then
|
||||||
--MessageBox("%s -- Had a time limit and it expired", tostring(Script))
|
--MessageBox("%s -- Had a time limit and it expired", tostring(Script))
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@@ -93,8 +93,7 @@ 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
|
||||||
@@ -130,26 +128,26 @@ function PumpEvents()
|
|||||||
end
|
end
|
||||||
|
|
||||||
ThreadValue.Set("InPumpEvents", true)
|
ThreadValue.Set("InPumpEvents", true)
|
||||||
|
|
||||||
--DebugMessage("%s -- Entering yield. Count: %d, Time: %.3f\n", tostring(Script), YieldCount, GetCurrentTime())
|
--DebugMessage("%s -- Entering yield. Count: %d, Time: %.3f\n", tostring(Script), YieldCount, GetCurrentTime())
|
||||||
YieldCount = YieldCount + 1
|
YieldCount = YieldCount + 1
|
||||||
coroutine.yield(true) -- yield here and return to 'C'
|
coroutine.yield(true) -- yield here and return to 'C'
|
||||||
--DebugMessage("%s -- Return from yield. Count: %d, Time: %.3f\n", tostring(Script), YieldCount, GetCurrentTime())
|
--DebugMessage("%s -- Return from yield. Count: %d, Time: %.3f\n", tostring(Script), YieldCount, GetCurrentTime())
|
||||||
|
|
||||||
CurrentEvent = GetEvent()
|
CurrentEvent = GetEvent()
|
||||||
while CurrentEvent do
|
while CurrentEvent do
|
||||||
ScriptMessage("%s -- Pumping Event: %s.", tostring(Script), tostring(CurrentEvent))
|
ScriptMessage("%s -- Pumping Event: %s.", tostring(Script), tostring(CurrentEvent))
|
||||||
EventParams = GetEvent.Params()
|
EventParams = GetEvent.Params()
|
||||||
if EventParams then
|
if EventParams then
|
||||||
CurrentEvent(unpack(EventParams))
|
CurrentEvent(unpack(EventParams))
|
||||||
else
|
else
|
||||||
CurrentEvent()
|
CurrentEvent()
|
||||||
end
|
end
|
||||||
|
|
||||||
if Script.Debug_Should_Issue_Event_Alert() and DebugEventAlert then
|
if Script.Debug_Should_Issue_Event_Alert() and DebugEventAlert then
|
||||||
DebugEventAlert(CurrentEvent, EventParams)
|
DebugEventAlert(CurrentEvent, EventParams)
|
||||||
end
|
end
|
||||||
|
|
||||||
CurrentEvent = GetEvent()
|
CurrentEvent = GetEvent()
|
||||||
end
|
end
|
||||||
ThreadValue.Set("InPumpEvents", false)
|
ThreadValue.Set("InPumpEvents", false)
|
||||||
@@ -182,25 +180,24 @@ function Dirty_Floor(val)
|
|||||||
return string.format("%d", val) -- works on implicit string to int conversion
|
return string.format("%d", val) -- works on implicit string to int conversion
|
||||||
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,41 +216,38 @@ 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
|
||||||
very_important_tables = {
|
very_important_tables = {
|
||||||
_LOADED,
|
_LOADED,
|
||||||
coroutine,
|
coroutine,
|
||||||
string,
|
string,
|
||||||
LuaWrapperMetaTable,
|
LuaWrapperMetaTable,
|
||||||
_G,
|
_G,
|
||||||
security,
|
security,
|
||||||
table,
|
table,
|
||||||
entries_for_deletion
|
entries_for_deletion
|
||||||
}
|
}
|
||||||
|
|
||||||
--Silly thing is nil (we think) if we try to add it earlier
|
--Silly thing is nil (we think) if we try to add it earlier
|
||||||
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
|
||||||
@@ -261,27 +255,22 @@ function Flush_G()
|
|||||||
if not keep_table then
|
if not keep_table then
|
||||||
table.insert(entries_for_deletion, i)
|
table.insert(entries_for_deletion, i)
|
||||||
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.
|
||||||
|
|
||||||
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,16 +39,17 @@
|
|||||||
--
|
--
|
||||||
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
--/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
---@diagnostic disable
|
||||||
|
|
||||||
function DebugEventAlert(event, params)
|
function DebugEventAlert(event, params)
|
||||||
message = tostring(Script) .. ": handled event " .. tostring(event)
|
message = tostring(Script) .. ": handled event " .. tostring(event)
|
||||||
|
|
||||||
function AppendParameter(ival, parameter)
|
function AppendParameter(ival, parameter)
|
||||||
message = message .. "\nParameter " .. tostring(ival) .. ": " .. tostring(parameter)
|
message = message .. "\nParameter " .. tostring(ival) .. ": " .. tostring(parameter)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.foreachi(params, AppendParameter)
|
table.foreachi(params, AppendParameter)
|
||||||
|
|
||||||
MessageBox(message)
|
MessageBox(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,16 @@ end
|
|||||||
---@type FactionStruct[]
|
---@type FactionStruct[]
|
||||||
Factions = DefineFactions()
|
Factions = DefineFactions()
|
||||||
|
|
||||||
|
-- ==================================================
|
||||||
|
-- Define Spectator Constants
|
||||||
|
-- ==================================================
|
||||||
|
|
||||||
|
---Space marker used to identify the spectator player.
|
||||||
|
Spectator_Marker_Space = "Spectator_Reveal_Marker"
|
||||||
|
|
||||||
|
---Land marker used to identify the spectator player.
|
||||||
|
Spectator_Marker_Land = "Spectator_Reveal_Marker_Land"
|
||||||
|
|
||||||
-- ==================================================
|
-- ==================================================
|
||||||
-- Define UI Constants
|
-- Define UI Constants
|
||||||
-- ==================================================
|
-- ==================================================
|
||||||
@@ -77,12 +87,16 @@ Factions = DefineFactions()
|
|||||||
---GUI Component to display game time.
|
---GUI Component to display game time.
|
||||||
UI_GameTime = "s_select_41"
|
UI_GameTime = "s_select_41"
|
||||||
|
|
||||||
---GUI Components to display Team 1 credits.
|
---GUI Component to display Team 1 faction icon.
|
||||||
UI_IconT1 = "s_health_42"
|
UI_IconT1 = "s_health_42"
|
||||||
|
|
||||||
|
--- GUI Component to display Team 1 credits text.
|
||||||
UI_CreditsT1 = "s_health_41"
|
UI_CreditsT1 = "s_health_41"
|
||||||
|
|
||||||
---GUI Component to display Team 2 credits.
|
---GUI Component to display Team 2 faction icon.
|
||||||
UI_IconT2 = "s_shield_42"
|
UI_IconT2 = "s_shield_42"
|
||||||
|
|
||||||
|
---GUI Component to display Team 2 credits text.
|
||||||
UI_CreditsT2 = "s_shield_41"
|
UI_CreditsT2 = "s_shield_41"
|
||||||
|
|
||||||
---GUI Component to enable/disable population.
|
---GUI Component to enable/disable population.
|
||||||
@@ -90,16 +104,3 @@ UI_PlanetaryPop = "text_planetary_pop"
|
|||||||
|
|
||||||
---GUI Component to enable/disable tactical credits.
|
---GUI Component to enable/disable tactical credits.
|
||||||
UI_CreditsTactical = "text_credits_tactical"
|
UI_CreditsTactical = "text_credits_tactical"
|
||||||
|
|
||||||
---Gets the specator marker for the game mode.
|
|
||||||
---@param gameMode string Game mode.
|
|
||||||
---@return string|nil
|
|
||||||
function GetSpectatorMarkerName(gameMode)
|
|
||||||
if StringCompare(gameMode, "Space") then
|
|
||||||
return "Spectator_Reveal_Marker"
|
|
||||||
elseif StringCompare(gameMode, "Land") then
|
|
||||||
return "Spectator_Reveal_Marker_Land"
|
|
||||||
end
|
|
||||||
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -24,9 +24,15 @@ function SkirmishGameClass:New(gameMode)
|
|||||||
local function FindSpectators()
|
local function FindSpectators()
|
||||||
---@type SpectatorStruct[]
|
---@type SpectatorStruct[]
|
||||||
local spectators = {}
|
local spectators = {}
|
||||||
local spectatorMarker = GetSpectatorMarkerName(gameMode)
|
local spectatorMarker = nil
|
||||||
|
|
||||||
if spectatorMarker ~= nil then
|
if StringCompare(gameMode, "Space") then
|
||||||
|
spectatorMarker = Spectator_Marker_Space
|
||||||
|
elseif StringCompare(gameMode, "Land") then
|
||||||
|
spectatorMarker = Spectator_Marker_Land
|
||||||
|
end
|
||||||
|
|
||||||
|
if spectatorMarker then
|
||||||
for k, marker in pairs(Find_All_Objects_Of_Type(spectatorMarker)) do
|
for k, marker in pairs(Find_All_Objects_Of_Type(spectatorMarker)) do
|
||||||
local playerWrapper = marker.Get_Owner()
|
local playerWrapper = marker.Get_Owner()
|
||||||
local playerId = playerWrapper.Get_ID()
|
local playerId = playerWrapper.Get_ID()
|
||||||
|
|||||||
@@ -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))
|
||||||
|
|
||||||
@@ -412,7 +413,7 @@ function Init_Tactical(gameMode)
|
|||||||
GUIManager:InitTactical(TacticalGame)
|
GUIManager:InitTactical(TacticalGame)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Resets Tactica mode.
|
---Resets Tactical mode.
|
||||||
function Reset_Tactical()
|
function Reset_Tactical()
|
||||||
DebugMessage("%s -- Resetting Tactical rules.", tostring(Script))
|
DebugMessage("%s -- Resetting Tactical rules.", tostring(Script))
|
||||||
Reset_Tactical_Stats()
|
Reset_Tactical_Stats()
|
||||||
@@ -434,6 +435,7 @@ function Init_Skirmish(gameMode)
|
|||||||
GUIManager:InitSkirmish(SkirmishGame)
|
GUIManager:InitSkirmish(SkirmishGame)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Resets Skirmish mode.
|
||||||
function Reset_Skirmish()
|
function Reset_Skirmish()
|
||||||
DebugMessage("%s -- Resetting Skirmish Tactical rules.", tostring(Script))
|
DebugMessage("%s -- Resetting Skirmish Tactical rules.", tostring(Script))
|
||||||
Reset_Stats()
|
Reset_Stats()
|
||||||
|
|||||||
Reference in New Issue
Block a user