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): -netai seats that many AIs after the -netgame addresses

Olcay Seyganc77f02447aa3
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 4d452358b..2cc766a74 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -464,6 +464,7 @@ public:
AsciiString m_netGameHosts; ///< -netgame <ip>[,<ip>...]: the slot list of a LAN game started from the command line (empty = off)
Bool m_netGameStarted; ///< that -netgame passed its checks and StartAutomatedGame ran, so every seat has this command line
Int m_netGameLocalSlot; ///< -netslot <n>: which of those addresses this copy of the game is
+ Int m_netGameAISlots; ///< -netai <n>: that many AI seats after the addresses, at the -aidiff rung
AsciiString m_lanPlayerName; ///< -lanname <name>: the name this copy takes in the LAN lobby (empty = the one in the preferences)
Bool m_lanLobbyOnStart; ///< -lanlobby: open the LAN lobby instead of stopping at the main menu
Bool m_skirmishLobbyOnStart; ///< -skirmishlobby: open the skirmish staging room instead of stopping at the main menu
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index 449d87dc8..f45ba93f7 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -2191,6 +2191,19 @@ Int parseNetSlot(char *args[], int num)
return 2;
}
+/* -netai <n> puts n AI seats after the -netgame addresses. Two idle copies play nothing, and a
+ desync that players meet ten minutes into a match needs a match that is being played: AIs
+ building, fighting and dying. An AI runs inside GameLogic on every machine alike, so every copy
+ has to be given the same number, the way every copy is given the same address list. */
+Int parseNetAI(char *args[], int num)
+{
+ if (TheWritableGlobalData && num > 1)
+ {
+ TheWritableGlobalData->m_netGameAISlots = max( 0, atoi(args[1]) );
+ }
+ return 2;
+}
+
/* -replay <file> plays a replay back without the menus, the way -autoskirmish starts a match
without them. The only route into playback was ReplayMenu's list box and the _DEBUG/_INTERNAL
-file switch, so a Release build could record a game and then had no way to play it back
@@ -2457,6 +2470,7 @@ static CommandLineParam params[] =
{ "-loadsave", parseLoadSave },
{ "-netgame", parseNetGame },
{ "-netslot", parseNetSlot },
+ { "-netai", parseNetAI },
{ "-lanip", parseLanIP },
{ "-lanname", parseLanName },
{ "-lanlobby", parseLanLobby },
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index 044703926..259c47946 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -634,9 +634,10 @@ static void startAutoNetGame( void )
return;
}
- if (numSlots > md->m_numPlayers)
+ const Int numSeats = numSlots + TheGlobalData->m_netGameAISlots;
+ if (numSeats > md->m_numPlayers || numSeats > MAX_SLOTS)
{
- DEBUG_LOG(("-netgame: '%s' holds %d players, not %d\n", mapName.str(), md->m_numPlayers, numSlots));
+ DEBUG_LOG(("-netgame: '%s' holds %d players, not %d\n", mapName.str(), md->m_numPlayers, numSeats));
return;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index 6cb3d1815..da60ab275 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -743,6 +743,7 @@ GlobalData::GlobalData()
m_netGameHosts.clear(); // no network game from the command line
m_netGameStarted = FALSE;
m_netGameLocalSlot = 0;
+ m_netGameAISlots = 0;
m_lanPlayerName.clear(); // the lobby name comes out of the preferences unless -lanname says otherwise
m_lanLobbyOnStart = FALSE;
m_skirmishLobbyOnStart = FALSE;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
index 782587626..ffb52215f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPICallbacks.cpp
@@ -228,9 +228,11 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedIn
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;
+ // -netai seats come after the addresses and take part in the team split like any other seat
+ const Int numSeats = numSlots + TheGlobalData->m_netGameAISlots;
+ const Int slotsPerTeam = (teams > 1 && numSeats >= teams) ? ((numSeats + teams - 1) / teams) : 0;
- for (Int i = 0; i < numSlots; ++i)
+ for (Int i = 0; i < numSeats; ++i)
{
/* The names have to differ: GameInfo looks players up by name, and the player list ends up
with one side per slot named after it. */
@@ -246,12 +248,19 @@ Bool LANAPI::StartAutomatedGame( AsciiString mapName, Int seed, const UnsignedIn
}
LANGameSlot slot;
- slot.setState( SLOT_PLAYER, playerName );
- slot.setIP( slotIPs[i] );
- slot.setPort( NETWORK_BASE_PORT_NUMBER ); // one address per player, so one port does for all
- slot.setLastHeard( timeGetTime() );
- slot.setLogin( m_userName );
- slot.setHost( m_hostName );
+ if (i < numSlots)
+ {
+ slot.setState( SLOT_PLAYER, playerName );
+ slot.setIP( slotIPs[i] );
+ slot.setPort( NETWORK_BASE_PORT_NUMBER ); // one address per player, so one port does for all
+ slot.setLastHeard( timeGetTime() );
+ slot.setLogin( m_userName );
+ slot.setHost( m_hostName );
+ }
+ else
+ {
+ slot.setState( (SlotState)TheGlobalData->m_autoSkirmishAIState );
+ }
slot.setPlayerTemplate( PLAYERTEMPLATE_RANDOM );
slot.setColor( -1 ); // -1 is "random" to populateRandomSideAndColor
slot.setStartPos( -1 ); // and to populateRandomStartPosition