Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

feat(gameengine): name each headless player's slot and team

Olcay Seygan46d8b6540c25
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 5f1baaa81..c59a8df5d 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1998,8 +1998,13 @@ static void updateHeadlessRun( void )
if (!p->isPlayableSide() || p->isPlayerObserver())
continue;
+ // The lobby seat and its -teams block, so a batch can add a team's result up without guessing
+ // which player index came from which slot. A player no slot built has neither.
+ const Int slot = ThePlayerList->getSlotIndex( i );
+ const Int team = (slot >= 0 && TheGameInfo) ? TheGameInfo->getConstSlot( slot )->getTeamNumber() : -1;
+
ScoreKeeper *score = p->getScoreKeeper();
- DEBUG_LOG(("HEADLESS PLAYER %d '%ls': %s | score %d | money %d earned %d spent | units %d built %d lost %d killed peak %d | buildings %d built %d lost\n",
+ DEBUG_LOG(("HEADLESS PLAYER %d '%ls': %s | score %d | money %d earned %d spent | units %d built %d lost %d killed peak %d | buildings %d built %d lost | slot %d team %d\n",
i, p->getPlayerDisplayName().str(),
TheVictoryConditions->hasAchievedVictory(p) ? "WON" :
(TheVictoryConditions->hasSinglePlayerBeenDefeated(p) ? "eliminated" : "alive"),
@@ -2007,7 +2012,8 @@ static void updateHeadlessRun( void )
score->getTotalMoneyEarned(), score->getTotalMoneySpent(),
score->getTotalUnitsBuilt(), score->getTotalUnitsLost(), score->getTotalUnitsDestroyed(),
peakUnits[ i ],
- score->getTotalBuildingsBuilt(), score->getTotalBuildingsLost()));
+ score->getTotalBuildingsBuilt(), score->getTotalBuildingsLost(),
+ slot, team));
}
/* Tear the match down the way the benchmark timer does, so the replay of the run is closed and
diff --git a/ai-batch.ps1 b/ai-batch.ps1
index 48565890b..be24ee68f 100644
--- a/ai-batch.ps1
+++ b/ai-batch.ps1
@@ -210,12 +210,14 @@ for ($i = 0; $i -lt $Runs; $i++) {
if ($report -match "repath (\d+)") { $pf.Repaths = [int]$Matches[1] }
if ($report -match "dither (\d+)") { $pf.Dithers = [int]$Matches[1] }
}
- elseif ($line -match "HEADLESS PLAYER (\d+) '(.*?)': (\w+) \| score (\d+) \| money (\d+) earned (\d+) spent \| units (\d+) built (\d+) lost (\d+) killed peak (\d+)") {
+ elseif ($line -match "HEADLESS PLAYER (\d+) '(.*?)': (\w+) \| score (\d+) \| money (\d+) earned (\d+) spent \| units (\d+) built (\d+) lost (\d+) killed peak (\d+)(?:.*\| slot (-?\d+) team (-?\d+))?") {
+ # the lobby team is -1 for a free-for-all seat, and absent from a log an older build wrote
+ $team = if ($Matches[12]) { [int]$Matches[12] } else { -1 }
$slots[[int]$Matches[1]] = [pscustomobject]@{
Name = $Matches[2]; Status = $Matches[3]; Score = [int]$Matches[4]
Earned = [int]$Matches[5]; Spent = [int]$Matches[6]
Built = [int]$Matches[7]; Lost = [int]$Matches[8]; Killed = [int]$Matches[9]
- Peak = [int]$Matches[10]
+ Peak = [int]$Matches[10]; Team = $team
}
}
}
@@ -263,6 +265,28 @@ $summary = foreach ($p in $slotIds) {
}
if ($summary) { $summary | Format-Table -AutoSize | Out-String | Write-Host }
+# With -Teams the question is which block won, not which seat: allies share a victory, so a team
+# is counted once per match it won, and its kills and losses are the sum over its members.
+$teamIds = $rows | ForEach-Object { $_.Slots.Values } | Where-Object { $_.Team -ge 0 } | ForEach-Object { $_.Team } | Sort-Object -Unique
+$teamSummary = foreach ($t in $teamIds) {
+ # not $matches: PowerShell names are case-insensitive and that is the -match result every parse above reads
+ $teamRows = @($rows | ForEach-Object { ,@($_.Slots.Values | Where-Object { $_.Team -eq $t }) } | Where-Object { $_.Count -gt 0 })
+ $wins = @($teamRows | Where-Object { @($_ | Where-Object { $_.Status -eq "WON" }).Count -gt 0 }).Count
+ $seats = $rows | ForEach-Object { $slots = $_.Slots; $slots.Keys | Where-Object { $slots[$_].Team -eq $t } } | Sort-Object -Unique
+ [pscustomobject]@{
+ Team = $t
+ Players = ($seats -join ",")
+ Wins = $wins
+ "Win%" = [math]::Round(100.0 * $wins / $rows.Count, 1)
+ AvgKills = [math]::Round(($teamRows | ForEach-Object { ($_ | Measure-Object Killed -Sum).Sum } | Measure-Object -Average).Average, 1)
+ AvgLost = [math]::Round(($teamRows | ForEach-Object { ($_ | Measure-Object Lost -Sum).Sum } | Measure-Object -Average).Average, 1)
+ }
+}
+if ($teamSummary) {
+ Write-Host "per team:"
+ $teamSummary | Format-Table -AutoSize | Out-String | Write-Host
+}
+
# Pathfinder cost and traffic, averaged per match. A match that produced no log has nothing to
# say here, so it is left out rather than counted as a zero.
$pfRows = @($rows | Where-Object { $null -ne $_.Pf -and $_.Frames -gt 0 })