Initial commit
This commit is contained in:
120
Data/Scripts/Miscellaneous/GameManager/TacticalGameClass.lua
Normal file
120
Data/Scripts/Miscellaneous/GameManager/TacticalGameClass.lua
Normal file
@@ -0,0 +1,120 @@
|
||||
require("PGBase")
|
||||
require("GameManager.PlayerClass")
|
||||
|
||||
---@class TacticalGameClass
|
||||
---@field GameMode string The tactical game mode.
|
||||
---@field StartTime integer The start time.
|
||||
---@field Players PlayerClass[] The combatant players in this game.
|
||||
---@field ReinforcementUnitCount table<string, integer> Key: Unit Type, Value: Count
|
||||
---@field AliveUnitCount table<string, integer> Key: Unit Type, Value: Count
|
||||
---@field DeadUnitCount table<string, integer> Key: Unit Type, Value: Count
|
||||
TacticalGameClass = {}
|
||||
TacticalGameClass.__index = TacticalGameClass
|
||||
|
||||
---Creates a new Tactical Game context.
|
||||
---@param gameMode string The game mode.
|
||||
---@return TacticalGameClass
|
||||
function TacticalGameClass:New(gameMode)
|
||||
ScriptMessage("Initializing Tactical game...")
|
||||
local self = setmetatable({}, TacticalGameClass)
|
||||
|
||||
---Finds all combatant players in the game.
|
||||
---@return PlayerClass[]
|
||||
local function FindPlayers()
|
||||
---@type PlayerClass[]
|
||||
local players = {}
|
||||
|
||||
for k, faction in pairs(Factions) do
|
||||
local startingUnit = nil
|
||||
|
||||
if StringCompare(gameMode, "Land") then
|
||||
startingUnit = faction.LandStartUnitName
|
||||
elseif StringCompare(gameMode, "Space") then
|
||||
startingUnit = faction.SpaceStartUnitName
|
||||
end
|
||||
|
||||
if startingUnit then
|
||||
for i, unit in pairs(Find_All_Objects_Of_Type(startingUnit)) do
|
||||
local playerWrapper = unit.Get_Owner()
|
||||
local playerId = playerWrapper.Get_ID()
|
||||
|
||||
if players[playerId] == nil then
|
||||
local player = PlayerClass:New(playerWrapper)
|
||||
|
||||
players[playerId] = player
|
||||
ScriptMessage("Found Player: %s", player:Debug())
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return players
|
||||
end
|
||||
|
||||
self.GameMode = gameMode
|
||||
self.StartTime = GetCurrentTime()
|
||||
self.Players = FindPlayers()
|
||||
ScriptMessage("Tactical Game initialized!")
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
---Services the Tactical Game.
|
||||
function TacticalGameClass:Service()
|
||||
ScriptMessage("Servicing Tactical Game...")
|
||||
|
||||
-- Service Players
|
||||
for _, player in pairs(self.Players) do
|
||||
player:Service()
|
||||
end
|
||||
end
|
||||
|
||||
---Whether this Tactical game is in space mode.
|
||||
---@return boolean
|
||||
function TacticalGameClass:IsSpaceMode()
|
||||
return StringCompare(self.GameMode, "Space")
|
||||
end
|
||||
|
||||
---Whether this Tactical game is in land mode.
|
||||
function TacticalGameClass:IsLandMode()
|
||||
return StringCompare(self.GameMode, "Land")
|
||||
end
|
||||
|
||||
---Gets the Player by ID.
|
||||
---@param id integer Player ID
|
||||
---@return PlayerClass|nil
|
||||
function TacticalGameClass:GetPlayer(id)
|
||||
for playerId, player in pairs(self.Players) do
|
||||
if playerId == id then
|
||||
return player
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Records the Player ID as having quit at the current time.
|
||||
---@param id integer Player ID.
|
||||
function TacticalGameClass:PlayerQuit(id)
|
||||
for playerId, player in pairs(self.Players) do
|
||||
if playerId == id then
|
||||
player:Quit()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Adds a built unit to the Unit table.
|
||||
---@param objectType table The FoC GameObjectTypeWrapper object type that was built.
|
||||
---@param player table The FoC PlayerWrapper object that owns the new Unit.
|
||||
function TacticalGameClass:UnitBuilt(objectType, player)
|
||||
local playerId = player.Get_ID()
|
||||
local player = self.Players[playerId]
|
||||
|
||||
if player then
|
||||
player:AddUnit(objectType)
|
||||
end
|
||||
end
|
||||
|
||||
---Sets a unit as killed.
|
||||
---@param gameObject table The FoC GameObjectWrapper object that was killed.
|
||||
function TacticalGameClass:UnitKilled(gameObject)
|
||||
-- Find a way to set the unit as killed
|
||||
end
|
||||
Reference in New Issue
Block a user