Compare commits

...

3 Commits

Author SHA1 Message Date
2490a7105a Adjust comments 2026-03-08 14:34:07 -05:00
c820748eca Make spectator markers a constant 2026-03-08 14:32:54 -05:00
2244f6494b Adjust Lua diagnostics 2026-03-08 14:27:41 -05:00
5 changed files with 74 additions and 75 deletions

View File

@@ -39,6 +39,8 @@
--
--/////////////////////////////////////////////////////////////////////////////////////////////////
---@diagnostic disable
require("PGDebug")
YieldCount = 0;
@@ -52,7 +54,6 @@ function ScriptExit()
end
function Sleep(time)
--DebugMessage("Sleeping... SleepTime: %.3f, CurTime: %.3f\n", time, GetCurrentTime())
ThreadValue.Set("StartTime", GetCurrentTime())
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
-- Pass -1 max_duration to use optional alternate break function with no time limit
function BlockOnCommand(block, max_duration, alternate_break_func)
PumpEvents()
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))
return nil
end
until (block.IsFinished() == true)
PumpEvents()
@@ -116,7 +115,6 @@ function TestCommand(block)
end
function PumpEvents()
if Object and type(Object) == "userdata" then
Object.Service_Wrapper()
end
@@ -188,16 +186,15 @@ function Simple_Mod(a,b)
return a - b * Dirty_Floor(a / b)
end
-- Returns if something happened, given a % chance
function Chance(seed, percent)
roll = Simple_Mod((seed + 1), 100)
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
end
function GetCurrentMinute()
--return math.floor(GetCurrentTime()/60)
return Dirty_Floor(GetCurrentTime() / 60)
@@ -219,7 +216,6 @@ function GetChanceAllowed(difficulty)
return chance
end
function PlayerSpecificName(player_object, var_name)
-- ret_value = tostring(player_object.Get_ID()) .. "_" .. var_name
-- DebugMessage("%s -- creating player specific string %s.", tostring(Script), ret_value)
@@ -228,7 +224,6 @@ function PlayerSpecificName(player_object, var_name)
end
function Flush_G()
entries_for_deletion = {}
--Define the set of tables that we had better keep around
@@ -248,7 +243,6 @@ function Flush_G()
--Iterate all globals
for i, g_entry in pairs(_G) do
if type(g_entry) == "table" then
--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.
@@ -263,7 +257,6 @@ function Flush_G()
end
keep_table = nil
elseif type(g_entry) == "userdata" then
--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.
@@ -271,9 +264,7 @@ function Flush_G()
if not g_entry.Is_Pool_Safe() then
table.insert(entries_for_deletion, i)
end
end
end
for i, bad_entry in pairs(entries_for_deletion) do
@@ -282,6 +273,4 @@ function Flush_G()
entries_for_deletion = nil
very_important_tables = nil
end

View File

@@ -39,6 +39,7 @@
--
--/////////////////////////////////////////////////////////////////////////////////////////////////
---@diagnostic disable
function DebugEventAlert(event, params)
message = tostring(Script) .. ": handled event " .. tostring(event)

View File

@@ -70,6 +70,16 @@ end
---@type FactionStruct[]
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
-- ==================================================
@@ -77,12 +87,16 @@ Factions = DefineFactions()
---GUI Component to display game time.
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"
--- GUI Component to display Team 1 credits text.
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"
---GUI Component to display Team 2 credits text.
UI_CreditsT2 = "s_shield_41"
---GUI Component to enable/disable population.
@@ -90,16 +104,3 @@ UI_PlanetaryPop = "text_planetary_pop"
---GUI Component to enable/disable tactical credits.
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

View File

@@ -24,9 +24,15 @@ function SkirmishGameClass:New(gameMode)
local function FindSpectators()
---@type SpectatorStruct[]
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
local playerWrapper = marker.Get_Owner()
local playerId = playerWrapper.Get_ID()

View File

@@ -63,6 +63,7 @@ function Base_Definitions()
end
---Main script function. Does event pumps and servicing.
---@diagnostic disable-next-line
function main()
DebugMessage("%s -- In main.", tostring(Script))
@@ -412,7 +413,7 @@ function Init_Tactical(gameMode)
GUIManager:InitTactical(TacticalGame)
end
---Resets Tactica mode.
---Resets Tactical mode.
function Reset_Tactical()
DebugMessage("%s -- Resetting Tactical rules.", tostring(Script))
Reset_Tactical_Stats()
@@ -434,6 +435,7 @@ function Init_Skirmish(gameMode)
GUIManager:InitSkirmish(SkirmishGame)
end
---Resets Skirmish mode.
function Reset_Skirmish()
DebugMessage("%s -- Resetting Skirmish Tactical rules.", tostring(Script))
Reset_Stats()