Initial commit

This commit is contained in:
2026-03-08 14:18:29 -05:00
parent c360c027e1
commit 77490ae8df
18 changed files with 2037 additions and 1 deletions

View File

@@ -0,0 +1,173 @@
require("PGBase")
require("GameManager.Constants")
require("GameManager.TacticalGameClass")
require("GameManager.SpectatorStruct")
require("GameManager.TeamStruct")
---@class SkirmishGameClass
---@field TacticalGame TacticalGameClass The underlying Tactical Game context.
---@field Spectators SpectatorStruct[] The spectator players in this game.
---@field IsLocalSpectator boolean Whether the local player is a spectator.
---@field Teams TeamStruct[] The teams in this game.
SkirmishGameClass = {}
SkirmishGameClass.__index = SkirmishGameClass
---Creates a new Skirmish Game context.
---@param gameMode string The game mode.
---@return SkirmishGameClass
function SkirmishGameClass:New(gameMode)
ScriptMessage("Initializing Skirmish game...")
local self = setmetatable({}, SkirmishGameClass)
---Finds all spectators in the game.
---@return SpectatorStruct[]
local function FindSpectators()
---@type SpectatorStruct[]
local spectators = {}
local spectatorMarker = GetSpectatorMarkerName(gameMode)
if spectatorMarker ~= nil then
for k, marker in pairs(Find_All_Objects_Of_Type(spectatorMarker)) do
local playerWrapper = marker.Get_Owner()
local playerId = playerWrapper.Get_ID()
if not spectators[playerId] then
local spectator = SpectatorStruct:New(playerWrapper)
spectators[playerId] = spectator
ScriptMessage("Found Spectator: %s", spectator:Debug())
end
end
end
return spectators
end
self.TacticalGame = TacticalGameClass:New(gameMode)
self.Spectators = FindSpectators()
---Gets whether the local player is a spectator.
---@returns boolean
local function GetLocalSpectator()
local localPlayer = Find_Player("local")
return self:GetSpectator(localPlayer.Get_ID()) ~= nil
end
self.IsLocalSpectator = GetLocalSpectator()
---Builds all teams in the game.
---@return TeamStruct[]
local function BuildTeams()
---@type TeamStruct[]
local teams = {}
-- Build combatant player teams
for playerId, player in pairs(self.TacticalGame.Players) do
local teamId = player.TeamId
if teamId >= 0 then
if teams[teamId] == nil then
teams[teamId] = TeamStruct:New(teamId, player.Faction, false)
end
end
end
-- Build spectator player teams
for playerId, spectator in pairs(self.Spectators) do
local teamId = spectator.TeamId
if teamId >= 0 then
local team = teams[teamId]
if team == nil then
team = TeamStruct:New(teamId, spectator.Faction, true)
teams[teamId] = team
ScriptMessage("Found Team: %s", team:Debug())
else
team.IsSpectator = true
end
end
end
return teams
end
self.Teams = BuildTeams()
ScriptMessage("Skirmish Game initialized!")
return self
end
---Services the Skirmish Game.
function SkirmishGameClass:Service()
ScriptMessage("Servicing Skirmish Game...")
-- Service TacticalGame
self.TacticalGame:Service()
end
---Gets the Spectator by Player ID.
---@param id integer Player ID
---@return SpectatorStruct|nil
function SkirmishGameClass:GetSpectator(id)
for playerId, spectator in pairs(self.Spectators) do
if playerId == id then
return spectator
end
end
end
---Gets the Team by ID.
---@param id integer Team ID
---@return TeamStruct|nil
function SkirmishGameClass:GetTeam(id)
for teamId, team in pairs(self.Teams) do
if teamId == id then
return team
end
end
end
---Gets the Players for the Team ID.
---@param id integer Team ID
---@return PlayerClass[]
function SkirmishGameClass:GetPlayersOnTeam(id)
---@type PlayerClass[]
local players = {}
for playerId, player in pairs(self.TacticalGame.Players) do
if player.TeamId == id then
players[playerId] = player
end
end
return players
end
---Calculates the Team ID's current total credits.
---@param id integer Team ID.
---@return integer
function SkirmishGameClass:CalculateTeamTotalCredits(id)
local players = self:GetPlayersOnTeam(id)
local totalCredits = 0
for playerId, player in pairs(players) do
totalCredits = totalCredits + player.Resource.Credits
end
return totalCredits
end
---Calculates the Team ID's current total income.
---@param id integer Team ID.
---@return integer
function SkirmishGameClass:CalculateTeamTotalIncome(id)
local players = self:GetPlayersOnTeam(id)
local totalIncome = 0
for playerId, player in pairs(players) do
totalIncome = totalIncome + player.Resource.Income
end
return totalIncome
end