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): make a -netgame run allied and unattended

Olcay Seygan8f872e2d015e
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 1031c5836..e972c1dc4 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1774,8 +1774,14 @@ static void updateHeadlessRun( void )
/* -autoskirmish counts as unattended even when it draws. THREADING-ROADMAP.md section 0 step 4
asks for a heavy scenario under a real renderer, and a run that never ends and never writes
its numbers down is not a measurement. This still cannot fire on a game a person started:
- reaching here needs -headless or -autoskirmish, and neither is on a menu. */
- const Bool unattended = TheGlobalData->m_headless || TheGlobalData->m_autoSkirmishPlayers > 0;
+ reaching here needs -headless, -autoskirmish or -netgame, and none of the three is on a menu.
+
+ -netgame is on that list for the same reason and one of its own: a network game that draws
+ is the only way to photograph anything that only exists between two machines, and until it
+ was here that run had to be -headless to end by itself, which is to say it could not be
+ photographed at all. */
+ const Bool unattended = TheGlobalData->m_headless || TheGlobalData->m_autoSkirmishPlayers > 0 ||
+ !TheGlobalData->m_netGameHosts.isEmpty();
/* Except that a run with a control socket open is not unattended at all - somebody is driving
it from the other end, and tearing the process down the moment a match is decided takes the
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
index d50fdb624..c54c9b88e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
@@ -222,6 +222,14 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedIn
gameName.format( L"%8.8X", slotIPs[0] );
game->setName( gameName );
+ /* -teams splits the slot list into allied blocks the same way it splits an -autoskirmish lobby:
+ with four slots and two teams the first two are team 0 and the rest team 1. Every machine is
+ handed the same slot count and the same team count, so every machine works out the same
+ split. Without it every slot is -1, "no team", and everybody fights everybody - which is
+ what a scripted throughput test wants and what a test of anything allied cannot use. */
+ const Int teams = TheGlobalData->m_autoSkirmishTeams;
+ const Int slotsPerTeam = (teams > 1 && numSlots >= teams) ? ((numSlots + teams - 1) / teams) : 0;
+
for (Int i = 0; i < numSlots; ++i)
{
/* The names have to differ: GameInfo looks players up by name, and the player list ends up
@@ -229,6 +237,14 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedIn
UnicodeString playerName;
playerName.format( L"Player%d", i + 1 );
+ Int teamNumber = -1;
+ if (slotsPerTeam > 0)
+ {
+ teamNumber = i / slotsPerTeam;
+ if (teamNumber >= teams)
+ teamNumber = teams - 1; // an uneven split puts the remainder on the last team
+ }
+
LANGameSlot slot;
slot.setState( SLOT_PLAYER, playerName );
slot.setIP( slotIPs[i] );
@@ -239,7 +255,7 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedIn
slot.setPlayerTemplate( PLAYERTEMPLATE_RANDOM );
slot.setColor( -1 ); // -1 is "random" to populateRandomSideAndColor
slot.setStartPos( -1 ); // and to populateRandomStartPosition
- slot.setTeamNumber( -1 ); // -1 is "no team", so everybody fights everybody
+ slot.setTeamNumber( teamNumber );
slot.setAccept();
game->setSlot( i, slot );