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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
fix(gamenetwork): the whole AI ladder in the LAN and online lobbies
Olcay Seygan2470281c8a6d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 05f2349d7..d5a65a6fd 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -83,6 +83,7 @@ found and fixed — EA's own, not port damage.**- Each step up switches on exactly one new thing, so you can say in a sentence what you get for climbing.- Measured, not asserted: Merciless beats Easy 15-0 over 32 headless matches with the seats swapped both ways, on twice the army and twice the spending.- The three new levels showed up in the lobby as "Closed" and lost their start position on the map every time the list refreshed. Both fixed. Easy is slow and brave. Steady saves its damaged units. Medium expands on its own. Hard counters your build. Brutal masses and commits. Merciless is the ceiling - everything on, no hesitation.+- All six are in the network and online lobbies too, not just skirmish. Those two only ever offered three, and a seat set to anything above Medium was sent to the other machines as Brutal - so a game meant to be played against Steady was played against Brutal by everyone at the table, host included. The seat list also drops down far enough to reach the bottom of it - it was still sized for the five entries the game shipped with, so the last levels were off the end of the list.- Making Easy easier means giving it worse decisions, never less money. That is the whole promise.- The computer also picks a personality each match and keeps it: one plays for the attack, the other for the base. Same resources, spent differently.diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.hindex f0bf0b447..d5fe42f55 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GUIUtil.h@@ -36,6 +36,10 @@ class GameInfo;void ShowUnderlyingGUIElements( Bool show, const char *layoutFilename, const char *parentName,const char **gadgetsToHide, const char **perPlayerGadgetsToHide );+// Every seat a lobby can offer - Open, Closed and the six rungs of the AI ladder - in one list,+// each entry tagged with the SlotState it stands for. allowTakeover adds the empty seat you+// take over in game, which only the skirmish lobby offers.+void PopulatePlayerSlotComboBox(GameWindow *comboBox, Int color, Bool allowTakeover);void PopulateColorComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool isObserver = FALSE);void PopulatePlayerTemplateComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool allowObservers );void PopulateTeamComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool isObserver = FALSE);diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.hindex d0cbbdca6..c60226aac 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h@@ -294,6 +294,16 @@ void GameInfo::setOldFactionsOnly( Bool oldFactionsOnly ) { m_oldFactionsAsciiString GameInfoToAsciiString( const GameInfo *game );Bool ParseAsciiStringToGameInfo( GameInfo *game, AsciiString options );+//+// Three things every lobby - skirmish, LAN and online - has to agree on about a slot state, kept+// here so that appending a rung to the enum above is one edit rather than a hunt through the menus.+// IsAISlotState() is what GameSlot::isAI() answers with; the two char functions are the AI seat's+// one-letter code in the options string the host sends every client.+//+Bool IsAISlotState( SlotState state );+char SlotStateToOptionsChar( SlotState state );+Bool OptionsCharToSlotState( char c, SlotState *state );+/*** The SkirmishGameInfo class holds information about the skirmish game anddiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cppindex c40a2c5f9..fbbc29797 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/LanGameOptionsMenu.cpp@@ -749,12 +749,7 @@ void InitLanGameGadgets( void )}else{- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),white);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);- GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);+ PopulatePlayerSlotComboBox(comboBoxPlayer[i], white, FALSE);}/*if(i != 0)@@ -1174,19 +1169,20 @@ WindowMsgHandledType LanGameOptionsMenuSystem( GameWindow *window, UnsignedInt m// GetInt pos = -1;GadgetComboBoxGetSelectedPos(comboBoxPlayer[i], &pos);- if( pos != SLOT_PLAYER && pos >= 0)+ SlotState pickedState = (pos >= 0) ? (SlotState)(Int)GadgetComboBoxGetItemData(comboBoxPlayer[i], pos) : SLOT_OPEN;+ if( pos >= 0 ){if( myGame->getLANSlot(i)->getState() == SLOT_PLAYER ){UnicodeString name = myGame->getPlayerName(i);- myGame->getLANSlot(i)->setState(SlotState(pos));+ myGame->getLANSlot(i)->setState(pickedState);myGame->resetAccepted();TheLAN->OnPlayerLeave(name);}- else if( myGame->getLANSlot(i)->getState() != pos )+ else if( myGame->getLANSlot(i)->getState() != pickedState ){Bool wasAI = (myGame->getLANSlot(i)->isAI());- myGame->getLANSlot(i)->setState(SlotState(pos));+ myGame->getLANSlot(i)->setState(pickedState);Bool isAI = (myGame->getLANSlot(i)->isAI());if (wasAI || isAI)myGame->resetAccepted();diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cppindex 5f023bb3f..3cb2396c5 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp@@ -1140,36 +1140,7 @@ void InitSkirmishGameGadgets( void )}else{- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),white); // leave this first- GadgetComboBoxSetItemData(comboBoxPlayer[i], 0, (void *)SLOT_OPEN);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white); // leave this first- GadgetComboBoxSetItemData(comboBoxPlayer[i], 1, (void *)SLOT_CLOSED);- // A seat with no AI behind it, for testing: Shift-Ctrl-T in game hands it to you.- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HumanSlot"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 2, (void *)SLOT_TAKEOVER);- //- // The six-rung ladder (AI-ROADMAP.md D6). Every rung plays by the player's rules - the- // steps are decisions the AI is or is not allowed to make, never money, build speed,- // vision or unit stats. Three of the six have no shipped string, so they read as plain- // English rather than as MISSING:; the three that do keep it, and EA's "HardAI" string- // now labels the rung that is actually called Hard.- //- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 3, (void *)SLOT_EASY_AI);- GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Steady AI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 4, (void *)SLOT_STEADY_AI);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 5, (void *)SLOT_MED_AI);- GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Hard AI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 6, (void *)SLOT_HARD_AI);- GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Brutal AI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 7, (void *)SLOT_BRUTAL_AI);- GadgetComboBoxAddEntry(comboBoxPlayer[i],UnicodeString(L"Merciless AI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 8, (void *)SLOT_MERCILESS_AI);- // nine entries now; the layout's list box was sized for five- GadgetComboBoxSetMaxDisplay(comboBoxPlayer[i], 9);- GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);-+ PopulatePlayerSlotComboBox(comboBoxPlayer[i], white, TRUE);}tmpString.format("SkirmishGameOptionsMenu.wnd:ComboBoxColor%d", i);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cppindex 76fae2d36..dab601b43 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLGameSetupMenu.cpp@@ -1221,12 +1221,7 @@ void InitWOLGameGadgets( void )}else{- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Open"),GameSpyColor[GSCOLOR_PLAYER_NORMAL]);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),GameSpyColor[GSCOLOR_PLAYER_NORMAL]);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),GameSpyColor[GSCOLOR_PLAYER_NORMAL]);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),GameSpyColor[GSCOLOR_PLAYER_NORMAL]);- GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),GameSpyColor[GSCOLOR_PLAYER_NORMAL]);- GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);+ PopulatePlayerSlotComboBox(comboBoxPlayer[i], GameSpyColor[GSCOLOR_PLAYER_NORMAL], FALSE);}tmpString.format("GameSpyGameOptionsMenu.wnd:ComboBoxColor%d", i);@@ -2645,7 +2640,8 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msg// GetInt pos = -1;GadgetComboBoxGetSelectedPos(comboBoxPlayer[i], &pos);- if( pos != SLOT_PLAYER && pos >= 0)+ SlotState pickedState = (pos >= 0) ? (SlotState)(Int)GadgetComboBoxGetItemData(comboBoxPlayer[i], pos) : SLOT_OPEN;+ if( pos >= 0 ){if( myGame->getSlot(i)->getState() == SLOT_PLAYER ){@@ -2660,16 +2656,16 @@ WindowMsgHandledType WOLGameSetupMenuSystem( GameWindow *window, UnsignedInt msgTheGameSpyPeerMessageQueue->addRequest(req);UnicodeString name = myGame->getSlot(i)->getName();- myGame->getSlot(i)->setState(SlotState(pos));+ myGame->getSlot(i)->setState(pickedState);myGame->resetAccepted();TheGameSpyInfo->setGameOptions();WOLDisplaySlotList();//TheLAN->OnPlayerLeave(name);}- else if( myGame->getSlot(i)->getState() != pos )+ else if( myGame->getSlot(i)->getState() != pickedState ){Bool wasAI = (myGame->getSlot(i)->isAI());- myGame->getSlot(i)->setState(SlotState(pos));+ myGame->getSlot(i)->setState(pickedState);Bool isAI = (myGame->getSlot(i)->isAI());myGame->resetAccepted();if (wasAI ^ isAI)diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cppindex 32ef39bf6..ef1d41bee 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLLobbyMenu.cpp@@ -1221,19 +1221,11 @@ void WOLLobbyMenuUpdate( WindowLayout * layout, void *userData)slot->setProfileID( resp.stagingRoom.profileID[i] );slot->setPlayerTemplate( resp.stagingRoom.faction[i] );slot->setColor( resp.stagingRoom.color[i] );- if (resp.stagingRoom.profileID[i] == SLOT_EASY_AI)+ // Every rung of the ladder, not the three the enum happened to start with: an online game+ // advertising a Steady or a Merciless seat used to show up in the browser as an empty one.+ if (IsAISlotState((SlotState)resp.stagingRoom.profileID[i])){- slot->setState(SLOT_EASY_AI);- ++numPlayers;- }- else if (resp.stagingRoom.profileID[i] == SLOT_MED_AI)- {- slot->setState(SLOT_MED_AI);- ++numPlayers;- }- else if (resp.stagingRoom.profileID[i] == SLOT_BRUTAL_AI)- {- slot->setState(SLOT_BRUTAL_AI);+ slot->setState((SlotState)resp.stagingRoom.profileID[i]);++numPlayers;}else if (resp.stagingRoomPlayerNames[i].length())diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cppindex f9f7e1cb6..202d89b9c 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp@@ -186,6 +186,61 @@ void ShowUnderlyingGUIElements( Bool show, const char *layoutFilename, const cha// -----------------------------------------------------------------------------+/** Fill a lobby's player slot combo box with every seat it can offer.+ *+ * All three lobbies used to keep their own list. The LAN and online ones held five entries in+ * SlotState order and read the choice back as SlotState(position), so the ladder's three added+ * rungs - appended to the enum, hence out of that order - could not be offered there at all: a+ * network game had Easy, Medium and Brutal and nothing else. Every entry now carries the state+ * it stands for and the position it sits at means nothing. */+void PopulatePlayerSlotComboBox(GameWindow *comboBox, Int color, Bool allowTakeover)+{+ if (!comboBox)+ return;++ // Three of the six rungs have no shipped string, so they read as plain English rather than as+ // a MISSING:, and EA's "HardAI" string is left on the seat the lobby calls Brutal.+ static const struct { const char *key; const WideChar *plainEnglish; SlotState state; } seats[] =+ {+ { "GUI:Open", NULL, SLOT_OPEN },+ { "GUI:Closed", NULL, SLOT_CLOSED },+ { "GUI:HumanSlot", NULL, SLOT_TAKEOVER },+ { "GUI:EasyAI", NULL, SLOT_EASY_AI },+ { NULL, L"Steady AI", SLOT_STEADY_AI },+ { "GUI:MediumAI", NULL, SLOT_MED_AI },+ { NULL, L"Hard AI", SLOT_HARD_AI },+ { NULL, L"Brutal AI", SLOT_BRUTAL_AI },+ { NULL, L"Merciless AI", SLOT_MERCILESS_AI },+ };++ // The combo box only grows its listbox when an add crosses the current length, and both+ // GadgetListBoxSetItemData and the add itself silently do nothing past it - so make room for+ // the whole list first, and tell the box how many rows to drop down before the first add.+ Int numSeats = (Int)(sizeof(seats)/sizeof(seats[0]));+ if (!allowTakeover)+ --numSeats;+ GameWindow *listBox = GadgetComboBoxGetListBox(comboBox);+ if (listBox)+ {+ ListboxData *listData = (ListboxData *)listBox->winGetUserData();+ if (listData && listData->listLength < numSeats)+ GadgetListBoxSetListLength(listBox, numSeats);+ }+ GadgetComboBoxSetMaxDisplay(comboBox, numSeats);++ Int shown = 0;+ for (Int i = 0; i < (Int)(sizeof(seats)/sizeof(seats[0])); ++i)+ {+ if (seats[i].state == SLOT_TAKEOVER && !allowTakeover)+ continue;+ UnicodeString label = seats[i].key ? TheGameText->fetch(seats[i].key) : UnicodeString(seats[i].plainEnglish);+ GadgetComboBoxAddEntry(comboBox, label, color);+ GadgetComboBoxSetItemData(comboBox, shown, (void *)seats[i].state);+ ++shown;+ }+ GadgetComboBoxSetSelectedPos(comboBox, 0);+}+void PopulateColorComboBox(Int comboBox, GameWindow *comboArray[], GameInfo *myGame, Bool isObserver){Int numColors = TheMultiplayerSettings->getNumColors();diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cppindex 88260d27e..df8b6c6cd 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp@@ -210,7 +210,7 @@ void GameSlot::setMapAvailability( Bool hasMap )* SLOT_TAKEOVER counts here on purpose: to the lobby it is an ordinary opponent seat that the* host owns and that no network peer is expected to check in from. It differs in one place only* - the player it creates is human (GameLogic::startNewGame), so no AI is ever attached. */-static Bool slotStateIsAI( SlotState state )+Bool IsAISlotState( SlotState state ){switch( state ){@@ -227,12 +227,54 @@ static Bool slotStateIsAI( SlotState state )}}+/** The one letter an AI seat is written as in the options string the host sends round.+ *+ * 'E', 'M', 'H' and 'P' are what shipped, so they keep their meaning - 'H' is Brutal, from when+ * Brutal was the top rung and the menu called it Hard. The three rungs the ladder added take+ * free letters. Every seat that was none of the four went out as 'H', which is why picking+ * Steady or Merciless in the LAN or online lobby handed everybody a Brutal opponent instead. */+static const struct { SlotState state; char code; } theAISlotCodes[] =+{+ { SLOT_EASY_AI, 'E' },+ { SLOT_STEADY_AI, 'S' },+ { SLOT_MED_AI, 'M' },+ { SLOT_HARD_AI, 'D' },+ { SLOT_BRUTAL_AI, 'H' },+ { SLOT_MERCILESS_AI, 'X' },+ { SLOT_TAKEOVER, 'P' },+};++char SlotStateToOptionsChar( SlotState state )+{+ for (Int i = 0; i < (Int)(sizeof(theAISlotCodes)/sizeof(theAISlotCodes[0])); ++i)+ {+ if (theAISlotCodes[i].state == state)+ return theAISlotCodes[i].code;+ }+ DEBUG_ASSERTCRASH(FALSE, ("No options string code for slot state %d", state));+ return 'H';+}++Bool OptionsCharToSlotState( char c, SlotState *state )+{+ for (Int i = 0; i < (Int)(sizeof(theAISlotCodes)/sizeof(theAISlotCodes[0])); ++i)+ {+ if (theAISlotCodes[i].code == c)+ {+ if (state)+ *state = theAISlotCodes[i].state;+ return TRUE;+ }+ }+ return FALSE;+}+void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP ){// An opponent seat keeps its colour, faction, team and start spot while it stays an opponent// seat - SLOT_TAKEOVER included, or the menu's own refresh (which re-sends the state to the// slot) would wipe the faction and team the moment you picked them.- if (!(isAI() && slotStateIsAI( state )))+ if (!(isAI() && IsAISlotState( state ))){m_color = -1;m_startPos = -1;@@ -309,7 +351,7 @@ Bool GameSlot::isOccupied( void ) constBool GameSlot::isAI( void ) const{- return slotStateIsAI( m_state );+ return IsAISlotState( m_state );}Bool GameSlot::isPlayer( AsciiString userName ) const@@ -1012,16 +1054,7 @@ AsciiString GameInfoToAsciiString( const GameInfo *game )}else if (slot && slot->isAI()){- Char c;- if (slot->getState() == SLOT_TAKEOVER)- c = 'P';- else if (slot->getState() == SLOT_EASY_AI)- c = 'E';- else if (slot->getState() == SLOT_MED_AI)- c = 'M';- else- c = 'H';- str.format("C%c,%d,%d,%d,%d:", c,+ str.format("C%c,%d,%d,%d,%d:", SlotStateToOptionsChar(slot->getState()),slot->getColor(), slot->getPlayerTemplate(),slot->getStartPos(), slot->getTeamNumber());}@@ -1369,38 +1402,16 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)break;}- switch(*(slotValue.str() + 1))+ SlotState aiState;+ if (OptionsCharToSlotState(*(slotValue.str() + 1), &aiState)){- case 'E':- {- newSlot[i].setState(SLOT_EASY_AI);- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Easy AI\n"));- }- break;- case 'M':- {- newSlot[i].setState(SLOT_MED_AI);- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Medium AI\n"));- }- break;- case 'P':- {- newSlot[i].setState(SLOT_TAKEOVER);- }- break;- case 'H':- {- newSlot[i].setState(SLOT_BRUTAL_AI);- //DEBUG_LOG(("ParseAsciiStringToGameInfo - Brutal AI\n"));- }- break;- default:- {- optionsOk = false;- DEBUG_LOG(("ParseAsciiStringToGameInfo - Unknown AI, quitting\n"));- }- break;- }//switch(*rawSlot.str()+1)+ newSlot[i].setState(aiState);+ }+ else+ {+ optionsOk = false;+ DEBUG_LOG(("ParseAsciiStringToGameInfo - Unknown AI, quitting\n"));+ }//Read color indexslotValue = strtok_r(NULL,",",&slotPos);diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex bf343a53a..8c360cf3b 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -6248,3 +6248,45 @@ TEST(walking_away_breaks_a_capture_but_turning_towards_it_does_not)// and nothing is broken when no power is up: walking is just walkingCHECK( !abilityBrokenByMovement( TRUE, FALSE, TRUE, TRUE ) );}++/* Every AI seat a lobby offers has to survive the trip to the other machines. The host writes the+ slot list into one options string and every client reads it back; an AI seat is one letter in+ there, and the writer used to have four - E, M, P and "everything else is H" - while the enum had+ grown to seven states. Steady, Hard and Merciless all went out as H, so a LAN or online game+ that was set up against the rungs in between was played against Brutal on every machine, the+ host's included. These two functions are the one place the letters live now. */+TEST(every_ai_seat_survives_the_options_string_the_host_sends_round)+{+ static const SlotState aiStates[] =+ {+ SLOT_EASY_AI, SLOT_STEADY_AI, SLOT_MED_AI, SLOT_HARD_AI, SLOT_BRUTAL_AI, SLOT_MERCILESS_AI,+ SLOT_TAKEOVER+ };+ const Int numAIStates = sizeof(aiStates)/sizeof(aiStates[0]);++ // every state IsAISlotState() claims as a seat has a letter, and it reads back as itself+ for (Int i = 0; i < numAIStates; ++i)+ {+ CHECK( IsAISlotState( aiStates[i] ) );+ SlotState readBack = SLOT_OPEN;+ CHECK( OptionsCharToSlotState( SlotStateToOptionsChar( aiStates[i] ), &readBack ) );+ CHECK_EQ( (Int)aiStates[i], (Int)readBack );+ }++ // and no two of them share one - the bug was six rungs sharing three letters+ for (Int a = 0; a < numAIStates; ++a)+ for (Int b = a + 1; b < numAIStates; ++b)+ CHECK_NE( SlotStateToOptionsChar( aiStates[a] ), SlotStateToOptionsChar( aiStates[b] ) );++ // the four letters that shipped keep their meaning, or an old replay reads as a different game+ CHECK_EQ( 'E', SlotStateToOptionsChar( SLOT_EASY_AI ) );+ CHECK_EQ( 'M', SlotStateToOptionsChar( SLOT_MED_AI ) );+ CHECK_EQ( 'H', SlotStateToOptionsChar( SLOT_BRUTAL_AI ) );+ CHECK_EQ( 'P', SlotStateToOptionsChar( SLOT_TAKEOVER ) );++ // a seat that is not an AI one is not written as an AI one, and a letter nobody uses is refused+ CHECK( !IsAISlotState( SLOT_OPEN ) );+ CHECK( !IsAISlotState( SLOT_CLOSED ) );+ CHECK( !IsAISlotState( SLOT_PLAYER ) );+ CHECK( !OptionsCharToSlotState( 'Q', NULL ) );+}