Compare commits

...

5 Commits

10 changed files with 759 additions and 62 deletions

View File

@@ -241,6 +241,7 @@ function GameObject.Is_Transport() end
function GameObject.Can_Land_On_Planet(planet) end
---@public
---@return GameObjectType
function GameObject.Get_Game_Scoring_Type() end
---@public

View File

@@ -39,3 +39,15 @@ function Add_Tutorial_Text(key, text, duration, r, g, b, a) end
---Removes the specified text key from the tutorial text box.
---@param key string The key to remove.
function Remove_Tutorial_Text(key) end
-- ==================================================
-- GameObjectType extensions
-- ==================================================
---@class GameObjectType
---A generic GameObjectType that represents a C++ GameObjectTypeClass
local GameObjectType = {}
---@public
---Returns the display name for the object type.
---@return string
function GameObjectType.Get_Display_Name() end

View File

@@ -18,6 +18,12 @@ TextManager = TutorialTextManager:New()
---@type PlayerObject|nil
LocalPlayer = nil
---Frag Index of Kill Stat Tables
FragIndex = 1
---Death Index of Kill Stat Tables
DeathIndex = 2
-- ==================================================
-- Define Faction constants
-- ==================================================
@@ -88,6 +94,31 @@ end
---@type FactionStruct[]
Factions = DefineFactions()
---Faction Title Rank table. Rebel at 2, Empire at 3
---@type table
FactionTitleTable = {
{ 145000, "TEXT_REBEL_TITLE19", "TEXT_EMPIRE_TITLE19" },
{ 125000, "TEXT_REBEL_TITLE18", "TEXT_EMPIRE_TITLE18" },
{ 115000, "TEXT_REBEL_TITLE17", "TEXT_EMPIRE_TITLE17" },
{ 100000, "TEXT_REBEL_TITLE16", "TEXT_EMPIRE_TITLE16" },
{ 90000, "TEXT_REBEL_TITLE15", "TEXT_EMPIRE_TITLE15" },
{ 85000, "TEXT_REBEL_TITLE14", "TEXT_EMPIRE_TITLE14" },
{ 80000, "TEXT_REBEL_TITLE13", "TEXT_EMPIRE_TITLE13" },
{ 75000, "TEXT_REBEL_TITLE12", "TEXT_EMPIRE_TITLE12" },
{ 70000, "TEXT_REBEL_TITLE11", "TEXT_EMPIRE_TITLE11" },
{ 60000, "TEXT_REBEL_TITLE10", "TEXT_EMPIRE_TITLE10" },
{ 55000, "TEXT_REBEL_TITLE9", "TEXT_EMPIRE_TITLE9" },
{ 50000, "TEXT_REBEL_TITLE8", "TEXT_EMPIRE_TITLE8" },
{ 45000, "TEXT_REBEL_TITLE7", "TEXT_EMPIRE_TITLE7" },
{ 40000, "TEXT_REBEL_TITLE6", "TEXT_EMPIRE_TITLE6" },
{ 25000, "TEXT_REBEL_TITLE5", "TEXT_EMPIRE_TITLE5" },
{ 20000, "TEXT_REBEL_TITLE4", "TEXT_EMPIRE_TITLE4" },
{ 15000, "TEXT_REBEL_TITLE3", "TEXT_EMPIRE_TITLE3" },
{ 10000, "TEXT_REBEL_TITLE2", "TEXT_EMPIRE_TITLE2" },
{ 5000, "TEXT_REBEL_TITLE1", "TEXT_EMPIRE_TITLE1" },
{ 0, "TEXT_REBEL_TITLE0", "TEXT_EMPIRE_TITLE0" }
}
-- ==================================================
-- Define Spectator Constants
-- ==================================================

View File

@@ -91,7 +91,7 @@ function GUIManager:DisplayTeamCredits(team, credits, income)
positiveText = ""
end
local text = string.format("Team %d: $%d (%s%d)", team.Number, credits, positiveText, income)
local text = string.format("Team %d: $ %d (%s%d)", team.Number, credits, positiveText, income)
local icon = team.Faction.Icon
local color = team.Faction.Color

View File

@@ -5,7 +5,10 @@ require("GameManager/UnitClass")
---@class GalacticGameClass
---@field StartTime integer The start time.
---@field Players PlayerClass[] The combatant players in this game.
---@field Units UnitClass[] The units in this game.
---@field BuildStatsTable table The engine-owned GalacticBuildStatsTable reference, set from GameScoring.lua.
---@field KillStatsTable table The engine-owned GalacticKillStatsTable reference, set from GameScoring.lua.
---@field NeutralizedStatsTable table The engine-owned GalacticNeutralizedTable reference, set from GameScoring.lua.
---@field GalacticConquestTable table The engine-owned GalacticConquestTable reference, set from GameScoring.lua.
GalacticGameClass = {}
GalacticGameClass.__index = GalacticGameClass
@@ -15,15 +18,8 @@ function GalacticGameClass:New()
ScriptMessage("Initializing Galactic game...")
local self = setmetatable({}, GalacticGameClass)
---Finds all combatant players in the game.
---@return PlayerClass[]
local function FindPlayers()
return {}
end
self.StartTime = GetCurrentTime()
self.Players = FindPlayers()
self.Units = {}
self.Players = self:_FindPlayers()
ScriptMessage("Galactic Game initialized!")
return self
@@ -34,11 +30,15 @@ function GalacticGameClass:Service()
ScriptMessage("Servicing Galactic game...")
-- Service Players
for playerId, player in pairs(self.Players) do
for _, player in pairs(self.Players) do
player:Service()
end
end
-- ==================================================
-- Player event handlers
-- ==================================================
---Gets the Player by ID.
---@param id integer Player ID
---@return PlayerClass|nil
@@ -60,14 +60,263 @@ function GalacticGameClass:PlayerQuit(id)
end
end
-- ==================================================
-- Unit event handlers
-- ==================================================
---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 GalacticGameClass:UnitBuilt(objectType, player)
---@param objectType GameObjectType The game object type that was built.
---@param player PlayerObject The player that owns the new game object.
---@param planet PlanetObject The planet the game object type was built at.
function GalacticGameClass:UnitBuilt(objectType, player, planet)
local playerId = player.Get_ID()
local playerEntry = self.Players[playerId]
if playerEntry then
playerEntry:AddUnit(objectType)
local unit = playerEntry:AddUnit(objectType)
self:UpdateGalacticBuildStatsTable(unit, planet)
end
end
---Sets a unit as killed.
---@param gameObject GameObject The game object that was killed.
---@param killer PlayerObject The player that killed the game object.
function GalacticGameClass:UnitKilled(gameObject, killer)
local ownerId = gameObject.Get_Owner().Get_ID()
local owner = self.Players[ownerId]
if not owner then
return
end
---@type UnitClass|nil
local killedUnit = nil
for _, unit in pairs(owner.Units) do
if unit.GameObject == gameObject then
killedUnit = unit
break
end
end
if killedUnit then
killedUnit:SetDead(killer.Get_ID())
self:UpdateGalacticKillStatsTable(killedUnit, killer)
end
end
function GalacticGameClass:UnitNeutralized(objectType, killer)
self:UpdateGalacticNeutralizedTable(objectType, killer)
end
-- ==================================================
-- Planet event handlers
-- ==================================================
---Sets a planet as changed faction.
---@param planet PlanetObject
---@param newOwner PlayerObject
---@param oldOwner PlayerObject
function GalacticGameClass:PlanetFactionChange(planet, newOwner, oldOwner)
end
-- ==================================================
-- Stat tables
-- ==================================================
---Updates the Galactic Build Stats Table with the build object type.
---@param unit UnitClass The game object type that was built.
---@param planet PlanetObject|nil The planet where the game object was built.
function GalacticGameClass:UpdateGalacticBuildStatsTable(unit, planet)
---@type GameObjectType|integer
local planetType = 1
if planet then
planetType = planet.Get_Type()
end
local playerEntry = self.BuildStatsTable[unit.OwnerId]
if not playerEntry then
playerEntry = {}
self.BuildStatsTable[unit.OwnerId] = playerEntry
end
local planetEntry = playerEntry[planetType]
if not planetEntry then
planetEntry = {}
playerEntry[planetType] = planetEntry
end
local typeEntry = planetEntry[unit.Name]
if not typeEntry then
typeEntry = {
build_count = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
planetEntry[unit.Name] = typeEntry
else
typeEntry.build_count = typeEntry.build_count + 1
typeEntry.combat_power = typeEntry.combat_power + unit.CombatRating
typeEntry.build_cost = typeEntry.build_cost + unit.BuildCost
typeEntry.score_value = typeEntry.score_value + unit.ScoreValue
end
end
---Updates the Galactic Kill Stats Table with the killed object.
---@param unit UnitClass The unit that was killed.
---@param killer PlayerObject The player that killed the unit.
function GalacticGameClass:UpdateGalacticKillStatsTable(unit, killer)
if not TestValid(killer) then
return
end
-- Update Frags
local fragEntry = self.KillStatsTable[FragIndex]
if not fragEntry then
fragEntry = {}
self.KillStatsTable[FragIndex] = fragEntry
end
local killerId = killer.Get_ID()
local killerEntry = fragEntry[killerId]
if not killerEntry then
killerEntry = {}
fragEntry[killerId] = killerEntry
end
local killerObjEntry = killerEntry[unit.GameObjectType]
if not killerObjEntry then
killerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
killerEntry[unit.GameObjectType] = killerObjEntry
else
killerObjEntry.kills = killerObjEntry.kills + 1
killerObjEntry.combat_power = killerObjEntry.combat_power + unit.CombatRating
killerObjEntry.build_cost = killerObjEntry.build_cost + unit.BuildCost
killerObjEntry.score_value = killerObjEntry.score_value + unit.ScoreValue
end
-- Update Deaths
local deathEntry = self.KillStatsTable[DeathIndex]
if not deathEntry then
deathEntry = {}
self.KillStatsTable[DeathIndex] = deathEntry
end
local ownerEntry = deathEntry[unit.OwnerId]
if not ownerEntry then
ownerEntry = {}
deathEntry[unit.OwnerId] = ownerEntry
end
local ownerObjEntry = ownerEntry[unit.GameObjectType]
if not ownerObjEntry then
ownerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
ownerEntry[unit.GameObjectType] = ownerObjEntry
else
ownerObjEntry.kills = ownerObjEntry.kills + 1
ownerObjEntry.combat_power = ownerObjEntry.combat_power + unit.CombatRating
ownerObjEntry.build_cost = ownerObjEntry.build_cost + unit.BuildCost
ownerObjEntry.score_value = ownerObjEntry.score_value + unit.ScoreValue
end
end
---Updates the Galactic Neutralized Table with the neutralized hero.
---@param objectType GameObjectType The hero type that was neutralized.
---@param killer GameObject The hero that killed this hero.
function GalacticGameClass:UpdateGalacticNeutralizedTable(objectType, killer)
local killerId = killer.Get_Owner().Get_ID()
local killerEntry = self.NeutralizedStatsTable[killerId]
if not killerEntry then
killerEntry = {}
self.NeutralizedStatsTable[killerId] = killerEntry
end
local neutralizedEntry = killerEntry[objectType]
if not neutralizedEntry then
neutralizedEntry = {
neutralized = 1
}
killerEntry[objectType] = neutralizedEntry
else
neutralizedEntry.neutralized = neutralizedEntry.neutralized + 1
end
end
-- ==================================================
-- Private functions
-- ==================================================
---@private
---Finds all players of defined Factions via FoCAPI.
---@return PlayerClass[]
function GalacticGameClass:_FindPlayers()
local isSuccess, result = pcall(Get_All_Players)
if isSuccess then
local players = {}
for _, playerWrapper in pairs(result) do
local factionName = playerWrapper.Get_Faction_Name()
for _, faction in pairs(Factions) do
if faction.Name == factionName then
local player = PlayerClass:New(playerWrapper)
players[player.Id] = player
end
end
end
return players
end
return self:_FindPlayersFallback()
end
---@private
---Finds all players of defined Factions via planets.
---@return PlayerClass[]
function GalacticGameClass:_FindPlayersFallback()
---@type PlayerClass[]
local players = {}
for _, planet in pairs(FindPlanet.Get_All_Planets()) do
local owner = planet.Get_Owner()
local factionName = owner.Get_Faction_Name()
for _, faction in pairs(Factions) do
if faction.Name == factionName then
local player = PlayerClass:New(owner)
players[player.Id] = player
end
end
end
return players
end

View File

@@ -80,7 +80,7 @@ function PlayerClass:HasQuit()
end
---Adds a Unit type to the Player's reinforcement list.
---@param objectType table FoC GameObjectTypeWrapper object that was built.
---@param objectType GameObjectType FoC GameObjectTypeWrapper object that was built.
---@return UnitClass
function PlayerClass:AddUnit(objectType)
local unit = UnitClass:New(objectType, self.Id)

View File

@@ -47,6 +47,11 @@ end
---Displays unit built combat text.
---@param unit UnitClass The built unit.
function SkirmishGameClass:CombatTextUnitBuilt(unit)
if not self.IsLocalSpectator then
-- No Text feed for combatants
return
end
local owner = self.Players[unit.OwnerId]
if not owner then
@@ -60,8 +65,8 @@ function SkirmishGameClass:CombatTextUnitBuilt(unit)
end
local timeText = FormatTime(unit.BuildTime)
local text = string.format("%s\t<T%d> [%s]: BUILT %s ($%d)", timeText, team.Number, owner.Name, unit.Name,
unit.BuildCost)
local text = string.format("%s [T%d %s]: BUILT %s ($ %d)", timeText, team.Number, team.Faction.DisplayName,
unit.DisplayName, unit.BuildCost)
local faction = Factions[owner.Faction]
---@type ColorStruct
local color
@@ -79,47 +84,57 @@ end
---Displays killed unit combat text.
---@param unit UnitClass The killed unit.
function SkirmishGameClass:CombatTextUnitKilled(unit)
local owner = self.Players[unit.OwnerId]
if not owner then
-- Right now, we don't really care about seeing killed units in the combat feed
-- If we want it in the future, uncomment the lines below.
return
end
-- if not self.IsLocalSpectator then
-- -- No Text feed for combatants
-- return
-- end
local killer = self.Players[unit.KillerId]
local timeText = FormatTime(unit.DeathTime)
-- local owner = self.Players[unit.OwnerId]
if not killer then
local team = self.Teams[owner.TeamId]
-- if not owner then
-- return
-- end
if not team then
return
end
-- local killer = self.Players[unit.KillerId]
-- local timeText = FormatTime(unit.DeathTime)
local text = string.format("%s\t<T%d> [%s]: MISTAKES WERE MADE %s", timeText, team.Number, owner.Name, unit.Name)
local color = ColorStruct:New(0.8, 0.8, 0.8, 1)
-- if not killer then
-- local team = self.Teams[owner.TeamId]
self.CombatFeed:Append(text, -1, color)
else
local team = self.Teams[killer.TeamId]
-- if not team then
-- return
-- end
if not team then
return
end
-- local text = string.format("%s\t<T%d> [%s]: MISTAKES WERE MADE %s", timeText, team.Number, owner.Name,
-- unit.DisplayName)
-- local color = ColorStruct:New(0.8, 0.8, 0.8, 1)
local text = string.format("%s\t<T%d> [%s]: KILLED %s (%s)", timeText, team.Number, killer.Name, unit.Name,
owner.Name)
local faction = Factions[killer.Faction]
---@type ColorStruct
local color = nil
-- self.CombatFeed:Append(text, -1, color)
-- else
-- local team = self.Teams[killer.TeamId]
if faction then
color = faction.Color
else
color = ColorStruct:New(1, 1, 1, 1)
end
-- if not team then
-- return
-- end
self.CombatFeed:Append(text, -1, color)
end
-- local text = string.format("%s\t<T%d> [%s]: KILLED %s (%s)", timeText, team.Number, killer.Name, unit
-- .DisplayName,
-- owner.Name)
-- local faction = Factions[killer.Faction]
-- ---@type ColorStruct
-- local color = nil
-- if faction then
-- color = faction.Color
-- else
-- color = ColorStruct:New(1, 1, 1, 1)
-- end
-- self.CombatFeed:Append(text, -1, color)
-- end
end
-- ==================================================
@@ -140,6 +155,19 @@ function SkirmishGameClass:GetTeam(id)
return self.Teams[id]
end
---Gets the Team of the Player ID.
---@param id integer Player ID.
---@return TeamStruct|nil
function SkirmishGameClass:GetTeamForPlayer(id)
local player = self.Players[id]
if not player then
return nil
end
return self.Teams[player.TeamId]
end
---Gets the Players for the Team ID.
---@param id integer Team ID
---@return PlayerClass[]
@@ -188,6 +216,113 @@ function SkirmishGameClass:CalculateTeamTotalIncome(id)
return totalIncome
end
--- ==================================================
--- Stat tables
--- ==================================================
---Updates the Tactical Kill Stats Table with the killed object.
---@param unit UnitClass The object that was killed.
---@param killer PlayerObject The player that killed the object.
function SkirmishGameClass:UpdateTacticalKillStatsTable(unit, killer)
if not TestValid(killer) then
return
end
-- Update Frags
local fragEntry = self.KillStatsTable[FragIndex]
if not fragEntry then
fragEntry = {}
self.KillStatsTable[FragIndex] = fragEntry
end
local killerId = killer.Get_ID()
if self.IsLocalSpectator then
local killerTeam = self:GetTeamForPlayer(killerId)
if killerTeam and killerTeam.Number == 1 then
-- For the spectator, let's show Team 1's kills on the left side
killerId = LocalPlayer.Get_ID()
end
end
local killerEntry = fragEntry[killerId]
if not killerEntry then
killerEntry = {}
fragEntry[killerId] = killerEntry
end
local killerObjEntry = killerEntry[unit.GameObjectType]
if not killerObjEntry then
killerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
killerEntry[unit.GameObjectType] = killerObjEntry
else
killerObjEntry.kills = killerObjEntry.kills + 1
killerObjEntry.combat_power = killerObjEntry.combat_power + unit.CombatRating
killerObjEntry.build_cost = killerObjEntry.build_cost + unit.BuildCost
killerObjEntry.score_value = killerObjEntry.score_value + unit.ScoreValue
end
-- Update Deaths
local deathEntry = self.KillStatsTable[DeathIndex]
if not deathEntry then
deathEntry = {}
self.KillStatsTable[DeathIndex] = deathEntry
end
local ownerId = unit.OwnerId
if self.IsLocalSpectator then
local ownerTeam = self:GetTeamForPlayer(ownerId)
if ownerTeam and ownerTeam.Number == 1 then
-- For the spectator, let's show Team 1's lost units on the left side
ownerId = LocalPlayer.Get_ID()
end
else
-- Non-spectator: show all teammate deaths as local player's losses
local ownerTeam = self:GetTeamForPlayer(ownerId)
local localTeam = self:GetTeamForPlayer(LocalPlayer.Get_ID())
if ownerTeam and localTeam and ownerTeam.Id == localTeam.Id then
ownerId = LocalPlayer.Get_ID()
end
end
local ownerEntry = deathEntry[ownerId]
if not ownerEntry then
ownerEntry = {}
deathEntry[ownerId] = ownerEntry
end
local ownerObjEntry = ownerEntry[unit.GameObjectType]
if not ownerObjEntry then
ownerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
ownerEntry[unit.GameObjectType] = ownerObjEntry
else
ownerObjEntry.kills = ownerObjEntry.kills + 1
ownerObjEntry.combat_power = ownerObjEntry.combat_power + unit.CombatRating
ownerObjEntry.build_cost = ownerObjEntry.build_cost + unit.BuildCost
ownerObjEntry.score_value = ownerObjEntry.score_value + unit.ScoreValue
end
end
-- ==================================================
-- Private functions
-- ==================================================

View File

@@ -8,6 +8,8 @@ require("GameManager/TutorialTextFeed")
---@field StartTime integer The start time.
---@field Players PlayerClass[] The combatant players in this game.
---@field CombatFeed TutorialTextFeed Text feed for unit builds and kills.
---@field BuildStatsTable table The engine-owned TacticalBuildStatsTable reference, set from GameScoring.lua.
---@field KillStatsTable table The engine-owned TacticalKillStatsTable reference, set from GameScoring.lua.
TacticalGameClass = {}
TacticalGameClass.__index = TacticalGameClass
@@ -82,15 +84,17 @@ end
-- ==================================================
---Adds a built unit to the Unit table.
---@param objectType GameObjectType The FoC GameObjectTypeWrapper object type that was built.
---@param player PlayerObject The FoC PlayerWrapper object that owns the new Unit.
function TacticalGameClass:UnitBuilt(objectType, player)
---@param objectType GameObjectType The game object type that was built.
---@param player PlayerObject The player that owns the new game object.
---@param planet PlanetObject|nil The planet the game object type was built at.
function TacticalGameClass:UnitBuilt(objectType, player, planet)
local playerId = player.Get_ID()
local playerEntry = self.Players[playerId]
if playerEntry then
local unit = playerEntry:AddUnit(objectType)
self:UpdateTacticalBuildStatsTable(unit, planet)
self:CombatTextUnitBuilt(unit)
end
end
@@ -104,6 +108,11 @@ function TacticalGameClass:CombatTextUnitBuilt(unit)
return
end
if not StringCompare(LocalPlayer.Get_Faction_Name(), owner.Faction) then
-- Do not display combat feed for players on opposite factions
return
end
local timeText = FormatTime(unit.BuildTime)
local text = string.format("%s\t[%s]: BUILT %s ($%d)", timeText, owner.Name, unit.Name, unit.BuildCost)
local faction = Factions[owner.Faction]
@@ -120,8 +129,8 @@ function TacticalGameClass:CombatTextUnitBuilt(unit)
end
---Sets a unit as killed.
---@param gameObject GameObject The FoC GameObjectWrapper object that was killed.
---@param killer PlayerObject The FoC PlayerWrapper object that killed the Unit.
---@param gameObject GameObject The game object that was killed.
---@param killer PlayerObject The player that killed the game object.
function TacticalGameClass:UnitKilled(gameObject, killer)
local ownerId = gameObject.Get_Owner().Get_ID()
local owner = self.Players[ownerId]
@@ -142,6 +151,7 @@ function TacticalGameClass:UnitKilled(gameObject, killer)
if killedUnit then
killedUnit:SetDead(killer.Get_ID())
self:UpdateTacticalKillStatsTable(killedUnit, killer)
self:CombatTextUnitKilled(killedUnit)
end
end
@@ -155,6 +165,11 @@ function TacticalGameClass:CombatTextUnitKilled(unit)
return
end
if not StringCompare(LocalPlayer.Get_Faction_Name(), owner.Faction) then
-- Do not display combat feed for players on opposite factions
return
end
local killer = self.Players[unit.KillerId]
local timeText = FormatTime(unit.DeathTime)
@@ -179,14 +194,166 @@ function TacticalGameClass:CombatTextUnitKilled(unit)
end
end
--- ==================================================
--- Stat tables
--- ==================================================
---Updates the Tactical Build Stats Table with the build object type.
---@param unit UnitClass The game object type that was built.
---@param planet PlanetObject|nil The planet the game object type was built at.
function TacticalGameClass:UpdateTacticalBuildStatsTable(unit, planet)
---@type GameObjectType|integer
local planetType = 1
if planet then
planetType = planet.Get_Type()
end
local playerEntry = self.BuildStatsTable[unit.OwnerId]
if not playerEntry then
playerEntry = {}
self.BuildStatsTable[unit.OwnerId] = playerEntry
end
local planetEntry = playerEntry[planetType]
if not planetEntry then
planetEntry = {}
playerEntry[planetType] = planetEntry
end
local typeEntry = planetEntry[unit.Name]
if not typeEntry then
typeEntry = {
build_count = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
planetEntry[unit.Name] = typeEntry
else
typeEntry.build_count = typeEntry.build_count + 1
typeEntry.combat_power = typeEntry.combat_power + unit.CombatRating
typeEntry.build_cost = typeEntry.build_cost + unit.BuildCost
typeEntry.score_value = typeEntry.score_value + unit.ScoreValue
end
end
---Updates the Tactical Kill Stats Table with the killed object.
---@param unit UnitClass The object that was killed.
---@param killer PlayerObject The player that killed the object.
function TacticalGameClass:UpdateTacticalKillStatsTable(unit, killer)
if not TestValid(killer) then
return
end
-- Update Frags
local fragEntry = self.KillStatsTable[FragIndex]
if not fragEntry then
fragEntry = {}
self.KillStatsTable[FragIndex] = fragEntry
end
local killerId = killer.Get_ID()
local killerEntry = fragEntry[killerId]
if not killerEntry then
killerEntry = {}
fragEntry[killerId] = killerEntry
end
local killerObjEntry = killerEntry[unit.GameObjectType]
if not killerObjEntry then
killerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
killerEntry[unit.GameObjectType] = killerObjEntry
else
killerObjEntry.kills = killerObjEntry.kills + 1
killerObjEntry.combat_power = killerObjEntry.combat_power + unit.CombatRating
killerObjEntry.build_cost = killerObjEntry.build_cost + unit.BuildCost
killerObjEntry.score_value = killerObjEntry.score_value + unit.ScoreValue
end
-- Update Deaths
local deathEntry = self.KillStatsTable[DeathIndex]
if not deathEntry then
deathEntry = {}
self.KillStatsTable[DeathIndex] = deathEntry
end
local ownerEntry = deathEntry[unit.OwnerId]
if not ownerEntry then
ownerEntry = {}
deathEntry[unit.OwnerId] = ownerEntry
end
local ownerObjEntry = ownerEntry[unit.GameObjectType]
if not ownerObjEntry then
ownerObjEntry = {
kills = 1,
combat_power = unit.CombatRating,
build_cost = unit.BuildCost,
score_value = unit.ScoreValue
}
ownerEntry[unit.GameObjectType] = ownerObjEntry
else
ownerObjEntry.kills = ownerObjEntry.kills + 1
ownerObjEntry.combat_power = ownerObjEntry.combat_power + unit.CombatRating
ownerObjEntry.build_cost = ownerObjEntry.build_cost + unit.BuildCost
ownerObjEntry.score_value = ownerObjEntry.score_value + unit.ScoreValue
end
end
-- ==================================================
-- Private functions
-- ==================================================
---@private
---Finds all players of defined Factions via FoCAPI.
---@param gameMode string The current game mode.
---@return PlayerClass[]
function TacticalGameClass:_FindPlayers(gameMode)
local isSuccess, result = pcall(Get_All_Players)
if isSuccess then
local players = {}
for _, playerWrapper in pairs(result) do
local factionName = playerWrapper.Get_Faction_Name()
for _, faction in pairs(Factions) do
if faction.Name == factionName then
local player = PlayerClass:New(playerWrapper)
players[player.Id] = player
end
end
end
return players
end
return self:_FindPlayersFallback(gameMode)
end
---@private
---Finds all players of defined Factions via starting unit.
---Note: this will not work when starting units are disabled.
---For the spectator team, it will only ever find the player in seat 1.
---@param gameMode string The current game mode.
---@return PlayerClass[]
function TacticalGameClass:_FindPlayersFallback(gameMode)
---@type PlayerClass[]
local players = {}

View File

@@ -2,9 +2,12 @@ require("PGBase")
---@class UnitClass
---@field Name string Unit name.
---@field DisplayName string|nil The localized display name.
---@field OwnerId integer Owner Player ID.
---@field BuildCost integer Tactical build cost.
---@field BuildCost integer Galactic build cost.
---@field TacticalBuildCost integer Tactical build cost.
---@field CombatRating integer AI combat power rating.
---@field ScoreValue integer Score cost credits.
---@field BuildTime number Game time that this unit was built.
---@field AliveTime number Game time that this unit became "alive".
---@field DeathTime number Game time that this unit was killed.
@@ -15,15 +18,18 @@ UnitClass = {}
UnitClass.__index = UnitClass
---Constructs a new Unit object.
---@param objectType table FoC GameObjectTypeWrapper object
---@param objectType GameObjectType The game object type.
---@param playerId integer The Owner Player ID
function UnitClass:New(objectType, playerId)
local self = setmetatable({}, UnitClass)
self.Name = objectType.Get_Name()
_, self.DisplayName = pcall(objectType.Get_Display_Name)
self.OwnerId = playerId
self.BuildCost = objectType.Get_Tactical_Build_Cost()
self.BuildCost = objectType.Get_Build_Cost()
self.TacticalBuildCost = objectType.Get_Tactical_Build_Cost()
self.CombatRating = objectType.Get_Combat_Rating()
self.ScoreValue = objectType.Get_Score_Cost_Credits()
self.BuildTime = GetCurrentTime()
self.AliveTime = -1
self.DeathTime = -1

View File

@@ -12,7 +12,7 @@ require("GameManager/SkirmishGameClass")
local DebugCounter = 0
---Debugging service rate.
local ServiceDebugRate = 5
local ServiceDebugRate = 10
---The Galactic Game manager.
---@type GalacticGameClass|nil
@@ -38,6 +38,43 @@ GameSpy_Game_Stats = {}
---@deprecated
GameSpy_Player_Stats = {}
---Tactical Build Stat Table for post-game.
---[playerid][planetname][object_type][build_count, credits_spent, combat_power]
TacticalBuildStatsTable = {}
---Tactical Frag/Death Stat Table for post-game.
---[frag|death][playerid][object_type][build_count, credits_spent, combat_power]
TacticalKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
---Tactical Team Frag/Death Stat Table for post-game.
---[frag|death][playerid][object_type][build_count, credits_spent, combat_power]
TacticalTeamKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
---Galactic Build Stat Table for post-game.
---[playerid][planetname][object_type][build_count, credits_spent, combat_power]
GalacticBuildStatsTable = {}
---Galactic Frag/Death Stat Table for post-game.
---[frag|death][playerid][object_type][build_count, credits_spent, combat_power]
GalacticKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
---Galactic Neutralized Hero Table for post-game.
---[playerid][object_type][neutralized_count]
GalacticNeutralizedTable = {}
---Galactic Planet Conquest Table for post-game.
---[playerid][planet_type][sacked_count, lost_count]
GalacticConquestTable = {}
-- ==================================================
-- Script State Functions
-- ==================================================
@@ -84,7 +121,31 @@ end
---Script debug servicing.
function ServiceDebug()
DebugMessage("%s -- TacticalKillStatsTable dump:", tostring(Script))
local fragEntry = TacticalKillStatsTable[FragIndex]
if fragEntry then
for playerId, unitTypes in pairs(fragEntry) do
for objType, data in pairs(unitTypes) do
DebugMessage(" FRAG player=%d type=%s kills=%d cp=%d cost=%d score=%d",
playerId, tostring(objType), data.kills, data.combat_power, data.build_cost, data.score_value)
end
end
else
DebugMessage(" FRAG (empty)")
end
local deathEntry = TacticalKillStatsTable[DeathIndex]
if deathEntry then
for playerId, unitTypes in pairs(deathEntry) do
for objType, data in pairs(unitTypes) do
DebugMessage(" DEATH player=%d type=%s kills=%d cp=%d cost=%d score=%d",
playerId, tostring(objType), data.kills, data.combat_power, data.build_cost, data.score_value)
end
end
else
DebugMessage(" DEATH (empty)")
end
end
-- ==================================================
@@ -95,6 +156,16 @@ end
function Reset_Tactical_Stats()
DebugMessage("%s -- In Reset_Tactical_Stats", tostring(Script))
TacticalBuildStatsTable = {}
TacticalKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
TacticalTeamKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
ResetTacticalRegistry()
end
@@ -103,6 +174,14 @@ function Reset_Stats()
DebugMessage("%s -- In Reset_Stats", tostring(Script))
Reset_Tactical_Stats()
GalacticBuildStatsTable {}
GalacticKillStatsTable = {
[FragIndex] = {},
[DeathIndex] = {}
}
GalacticNeutralizedTable = {}
GalacticConquestTable = {}
end
---A dirty hack to reset tactical script registry values
@@ -217,18 +296,25 @@ end
---@param object GameObject|GameObjectType FoC GameObjectWrapper or GameObjectTypeWrapper of the object that was just created.
function Galactic_Production_End_Event(planet, object)
local typeName = ""
local type = nil
if object.Get_Type == nil then
-- object must be a GameObjectTypeWrapper not a GameObjectWrapper if it doesn't
-- have a Get_Type function.
-- object must be a GameObjectTypeWrapper if it doesn't have a Get_Type function.
---@cast object GameObjectType
type = object
typeName = object.Get_Name()
else
-- object points to the GameObjectWrapper that was just created.
type = object.Get_Type()
typeName = object.Get_Type().Get_Name()
end
DebugMessage("%s -- Galactic production of %s ended at %s.", tostring(Script), typeName,
planet.Get_Type().Get_Name())
if GalacticGame then
GalacticGame:UnitBuilt(type, planet.Get_Owner(), planet)
end
end
---This event is triggered when a unit is destroyed in galactic mode.
@@ -236,6 +322,14 @@ end
---@param killer PlayerObject FoC PlayerWrapper object that killed the object.
function Galactic_Unit_Destroyed_Event(object, killer)
DebugMessage("%s -- Object %s killed by %s.", tostring(Script), object.Get_Type().Get_Name(), killer.Get_Name())
if GalacticGame then
GalacticGame:UnitKilled(object, killer)
end
if TacticalGame then
TacticalGame:UnitKilled(object, killer)
end
end
---This event is triggered when the level of a starbase changes.
@@ -394,9 +488,10 @@ function Init_Tactical(gameMode)
DebugMessage("%s -- Initializing Tactical %s rules.", tostring(Script), gameMode)
Reset_Tactical_Stats()
TacticalGame = TacticalGameClass:New(gameMode)
TacticalGame.KillStatsTable = TacticalTeamKillStatsTable
GUIManager:InitTactical()
TextManager:RegisterView(TacticalGame.CombatFeed)
TextManager:SetCurrentView("combat_feed")
--TextManager:RegisterView(TacticalGame.CombatFeed)
--TextManager:SetCurrentView("combat_feed")
end
---Resets Tactical mode.
@@ -418,6 +513,7 @@ function Init_Skirmish(gameMode)
DebugMessage("%s -- Initializing Skirmish Tactical %s rules.", tostring(Script), gameMode)
Reset_Stats()
TacticalGame = SkirmishGameClass:New(gameMode)
TacticalGame.KillStatsTable = TacticalKillStatsTable
GUIManager:InitSkirmish(TacticalGame.IsLocalSpectator)
TextManager:RegisterView(TacticalGame.CombatFeed)
TextManager:SetCurrentView("combat_feed")