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
feat(gameengine): play a skirmish opponent yourself
Olcay Seygan767da7bc17ae
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex be30ddbca..302362948 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -296,7 +296,9 @@ found and fixed — EA's own, not port damage.**- Ported leaf-first: every library compiled, tested and green before its dependents.- 14 automated suites; most bugs above were found by tests, not by reading code.- The game plays itself: eight computer opponents from one command line.-- Shift-Ctrl-T hands you the opposing base itself: its brain is switched off and the whole army answers to you.+- An opponent can be set to Human in the skirmish screen: a base with no brain behind it.+- Its sight is yours from the first frame, and clicking any of it hands you the base itself.+- Shift-Ctrl-T does the same to any opponent, a computer one included, and walks around the table.- Headless, a 23-minute skirmish plays out in 38 seconds, identically every run.- It plays itself over a network too — two copies, one real connection.- That found every multiplayer replay falsely accusing itself of desync since 2003.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex b208fb5e4..8a1511f8b 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -312,3 +312,8 @@ ENDGUI:ShortcutSlot08Description"Presses the eighth button of the general's power bar in the top right corner."END++// Skirmish lobby: an opponent seat with no AI behind it (Shift-Ctrl-T takes it over).+GUI:HumanSlot+"Human"+ENDdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.hindex 8d43ad1f2..06d00ee91 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h@@ -129,4 +129,10 @@ extern void pickAndPlayUnitVoiceResponse( const DrawableList *list, GameMessage:///< does the stop key cancel a building that is going up, rather than stopping a unit?extern Bool Command_stopMeansCancelConstruction( Int selectionCount, Bool locallyControlled, Bool underConstruction );+class Player;+/** Single-player test hook: make this player the one at the keyboard, throwing away any AI behind+ * it first. FALSE if that player cannot be played (yourself, neutral, observer, beaten) or this+ * is not a single-player game. Bound to Shift-Ctrl-T, and to clicking a base nobody is driving. */+extern Bool takeControlOfPlayer( Player *p );+#endifdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 54d81d0aa..501f6926a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -816,6 +816,8 @@ public:void setArrowImage( const Image *arrowImage ){ m_genArrow = arrowImage; }void initSpecialPowershortcutBar( Player *player);+ ///< put the general's powers bar on screen now, filled in, with no slide-in (control changed hands)+ void showSpecialPowerShortcutInstantly( Player *player );void triggerRadarAttackGlow( void );diff --git a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.hindex 6bfc7519f..4fead6fe4 100644--- a/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h+++ b/GeneralsMD/Code/GameEngine/Include/GameNetwork/GameInfo.h@@ -43,7 +43,11 @@ enum SlotStateSLOT_EASY_AI,SLOT_MED_AI,SLOT_BRUTAL_AI,- SLOT_PLAYER+ SLOT_PLAYER,+ // fork: an opponent seat with nothing behind it - no AI is ever created for it and you take+ // it over in game with Shift-Ctrl-T. Appended on purpose: the values above are written into+ // save games and replays.+ SLOT_TAKEOVER};enum@@ -117,6 +121,7 @@ public:Bool isHuman( void ) const; ///< Is this slot occupied by a human player?Bool isOccupied( void ) const; ///< Is this slot occupied (by a human or an AI)?Bool isAI( void ) const; ///< Is this slot occupied by an AI?+ Bool isTakeover( void ) const { return m_state == SLOT_TAKEOVER; } ///< An AI seat with no AI: the player drives itBool isPlayer( AsciiString userName ) const; ///< Does this slot contain the given user?Bool isPlayer( UnicodeString userName ) const; ///< Does this slot contain the given user?Bool isPlayer( UnsignedInt ip ) const; ///< Is this slot at this IP?diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex ae6f95bcc..3c2275ff0 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -3933,6 +3933,22 @@ void ControlBar::initSpecialPowershortcutBar( Player *player)}+//-------------------------------------------------------------------------------------------------+/** Control of a player changed mid-game, so the general's powers bar has to be there this frame.+ * populateSpecialPowerShortcut() slides it in over half a second whenever it finds it hidden -+ * unhiding it first means it simply appears, already filled in. */+//-------------------------------------------------------------------------------------------------+void ControlBar::showSpecialPowerShortcutInstantly( Player *player )+{+ if( m_specialPowerShortcutParent && player+ && (player->hasAnyShortcutSpecialPower() || hasAnyShortcutSelection())+ && m_contextParent[ CP_MASTER ] && !m_contextParent[ CP_MASTER ]->winIsHidden() )+ {+ m_specialPowerShortcutParent->winHide( FALSE );+ }+ populateSpecialPowerShortcut( player );+}+void ControlBar::populateSpecialPowerShortcut( Player *player){const CommandSet *commandSet;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cppindex 8c46a2a29..d59c5074e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp@@ -1144,12 +1144,17 @@ void InitSkirmishGameGadgets( void )GadgetComboBoxSetItemData(comboBoxPlayer[i], 0, (void *)SLOT_OPEN);GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:Closed"),white); // leave this firstGadgetComboBoxSetItemData(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);GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:EasyAI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 2, (void *)SLOT_EASY_AI);+ GadgetComboBoxSetItemData(comboBoxPlayer[i], 3, (void *)SLOT_EASY_AI);GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:MediumAI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 3, (void *)SLOT_MED_AI);+ GadgetComboBoxSetItemData(comboBoxPlayer[i], 4, (void *)SLOT_MED_AI);GadgetComboBoxAddEntry(comboBoxPlayer[i],TheGameText->fetch("GUI:HardAI"),white);- GadgetComboBoxSetItemData(comboBoxPlayer[i], 4, (void *)SLOT_BRUTAL_AI);+ GadgetComboBoxSetItemData(comboBoxPlayer[i], 5, (void *)SLOT_BRUTAL_AI);+ // six entries now, one more than the layout's list box was sized for+ GadgetComboBoxSetMaxDisplay(comboBoxPlayer[i], 6);GadgetComboBoxSetSelectedPos(comboBoxPlayer[i],0);}diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex d0170e40e..bfb70449f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -2365,6 +2365,44 @@ GameMessage::Type CommandTranslator::evaluateContextCommand( Drawable *draw,} // end evaluateContextCommand+//-------------------------------------------------------------------------------------------------+/** Single-player test hook: make this player the one at the keyboard. Any AI behind it is thrown+ * away first, so nothing fights you for its units, and the HUD, money and shroud become its own.+ * Returns FALSE for a player you cannot sensibly play: yourself, the neutral side, an observer,+ * a beaten player - and for anything that is not a single-player game. */+//-------------------------------------------------------------------------------------------------+Bool takeControlOfPlayer( Player *p )+{+ if (p == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInMultiplayerGame() || TheGameLogic->isInReplayGame())+ return FALSE;+ if (p == ThePlayerList->getLocalPlayer() || p == ThePlayerList->getNeutralPlayer())+ return FALSE;+ if (!p->isPlayerActive() || !p->isPlayableSide())+ return FALSE;++ p->setPlayerType(PLAYER_HUMAN, FALSE); // throws away its AIPlayer, if it had one+ ThePlayerList->setLocalPlayer(p);+ TheInGameUI->deselectAllDrawables();++ /* Every driverless base feeds its sight to whoever is at the keyboard (Object::handleShroud), and+ that mask was worked out the last time each object looked - which for a building is when it was+ built. Make them all look again, or the base you just left goes dark behind you. */+ for (Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject())+ obj->handlePartitionCellMaintenance();++ ThePartitionManager->refreshShroudForLocalPlayer();+ TheControlBar->initSpecialPowershortcutBar(p);+ TheControlBar->setControlBarSchemeByPlayer(p);+ // initSpecialPowershortcutBar only builds the bar, hidden. Left alone it is filled in by the+ // control bar's next update and then slid in over half a second: this puts the general's+ // powers up on this frame instead.+ TheControlBar->showSpecialPowerShortcutInstantly(p);+ TheControlBar->markUIDirty();+ TheGameClient->updateFakeDrawables();+ TheInGameUI->message(UnicodeString(L"Now playing: %s"), p->getPlayerDisplayName().str());+ return TRUE;+}+// ------------------------------------------------------------------------------------------------// ------------------------------------------------------------------------------------------------//====================================================================================@@ -3965,35 +4003,21 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessageplayer's teams about; kill the script lists too if that ever gets in the way. */case GameMessage::MSG_META_SWITCH_CONTROL:{- if (TheGameLogic->isInGame() && !TheGameLogic->isInMultiplayerGame() && !TheGameLogic->isInReplayGame())+ Int count = ThePlayerList->getPlayerCount();+ Int idx = 0;+ for (Int i = 0; i < count; ++i){- Int count = ThePlayerList->getPlayerCount();- Int idx = 0;- for (Int i = 0; i < count; ++i)+ if (ThePlayerList->getNthPlayer(i) == ThePlayerList->getLocalPlayer()){- if (ThePlayerList->getNthPlayer(i) == ThePlayerList->getLocalPlayer())- {- idx = i;- break;- }+ idx = i;+ break;}+ }- for (Int i = 1; i < count; ++i)- {- Player *p = ThePlayerList->getNthPlayer((idx + i) % count);- if (p == NULL || p == ThePlayerList->getNeutralPlayer() || !p->isPlayerActive() || !p->isPlayableSide())- continue;-- p->setPlayerType(PLAYER_HUMAN, FALSE); // throws away its AIPlayer, if it had one- ThePlayerList->setLocalPlayer(p);- TheInGameUI->deselectAllDrawables();- ThePartitionManager->refreshShroudForLocalPlayer();- TheControlBar->initSpecialPowershortcutBar(p);- TheControlBar->setControlBarSchemeByPlayer(p);- TheGameClient->updateFakeDrawables();- TheInGameUI->message(UnicodeString(L"Now playing: %s"), p->getPlayerDisplayName().str());+ for (Int i = 1; i < count; ++i)+ {+ if (takeControlOfPlayer(ThePlayerList->getNthPlayer((idx + i) % count)))break;- }}disp = DESTROY_MESSAGE;break;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cppindex bb71bf0e3..d27f6e964 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/SelectionXlat.cpp@@ -635,6 +635,28 @@ GameMessageDisposition SelectionTranslator::translateGameMessage(const GameMessabreak;}+ /* Single-player test hook: a click that is not a command (nothing of yours selected, or+ nothing to do to it) on a base that nobody is driving - a Human seat from the skirmish+ screen, or a player you already took over - hands you that player, so the command bar,+ the money and the shroud become its own. Computer opponents are left alone; only+ Shift-Ctrl-T takes one of those. */+ for (DrawableListIt cit = drawablesThatWillSelect.begin(); cit != drawablesThatWillSelect.end(); ++cit)+ {+ Object *clicked = (*cit) ? (*cit)->getObject() : NULL;+ Player *owner = clicked ? clicked->getControllingPlayer() : NULL;+ if (owner == NULL || owner->getPlayerType() != PLAYER_HUMAN)+ continue;++ if (takeControlOfPlayer(owner))+ {+ selectSingleDrawableWithoutSound(*cit);+ disp = DESTROY_MESSAGE;+ }+ break;+ }+ if (disp == DESTROY_MESSAGE)+ break;+// There isn't a context command, so this is a selection thing. Now, based on the keys,// determine whether or not we should create a new group, or append these guys to our existing// group.diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex 0a466b1b7..cb049fdff 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -5060,6 +5060,18 @@ void Object::look()}}+ /* Single-player test hook: a base with nobody driving it - a Human seat from the+ skirmish screen, or a player taken over with Shift-Ctrl-T - shares its eyes with+ whoever is at the keyboard, so you can watch it without switching to it. Both+ ways round: switch to that base and your first one keeps feeding you its sight.+ Off in a network game, where the logic must not depend on who is looking. */+ if( getControllingPlayer()->getPlayerType() == PLAYER_HUMAN+ && !TheGameLogic->isInMultiplayerGame()+ && ThePlayerList->getLocalPlayer() )+ {+ lookingMask |= ThePlayerList->getLocalPlayer()->getPlayerMask();+ }+// Other players can also be looking through our eyes.lookingMask |= m_visionSpiedMask;}diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex f07e61b4f..f822fe8a1 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1332,7 +1332,9 @@ void GameLogic::startNewGame( Bool loadingSaveGame )AsciiString playerName;playerName.format("player%d", i);d.setAsciiString(TheKey_playerName, playerName);- d.setBool(TheKey_playerIsHuman, slot->isHuman());+ // A takeover seat is an AI slot everywhere in the lobby, but the player it makes is human:+ // no AIPlayer is attached, so its base just sits there until you take it over in game.+ d.setBool(TheKey_playerIsHuman, slot->isHuman() || slot->isTakeover());d.setUnicodeString(TheKey_playerDisplayName, slot->getName());const PlayerTemplate* pt;if (slot->getPlayerTemplate() >= 0)diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cppindex ebc359b1f..f9f7e1cb6 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp@@ -457,7 +457,19 @@ void UpdateSlotList( GameInfo *myGame, GameWindow *comboPlayer[],}else{- GadgetComboBoxSetSelectedPos(comboPlayer[i], slot->getState(), TRUE);+ /* The LAN and online menus fill this box in SlotState order and count on position ==+ state; the skirmish one has an extra entry and tags every line with its state, so+ ask the box first and fall back to the plain state when no line claims it. */+ Int pos = slot->getState();+ for (Int item = 0; comboPlayer[i] && item < GadgetComboBoxGetLength(comboPlayer[i]); ++item)+ {+ if ((Int)GadgetComboBoxGetItemData(comboPlayer[i], item) == slot->getState())+ {+ pos = item;+ break;+ }+ }+ GadgetComboBoxSetSelectedPos(comboPlayer[i], pos, TRUE);if( buttonAccept && buttonAccept[i] )buttonAccept[i]->winHide(TRUE);}diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cppindex 38f449345..abc501c38 100644--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameInfo.cpp@@ -202,7 +202,10 @@ void GameSlot::setMapAvailability( Bool hasMap )void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP ){- if (!(isAI() && (state == SLOT_EASY_AI || state == SLOT_MED_AI || state == SLOT_BRUTAL_AI)))+ // 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() && (state == SLOT_EASY_AI || state == SLOT_MED_AI || state == SLOT_BRUTAL_AI || state == SLOT_TAKEOVER))){m_color = -1;m_startPos = -1;@@ -239,6 +242,9 @@ void GameSlot::setState( SlotState state, UnicodeString name, UnsignedInt IP )case SLOT_BRUTAL_AI:m_name = TheGameText->fetch("GUI:HardAI");break;+ case SLOT_TAKEOVER:+ m_name = TheGameText->fetch("GUI:HumanSlot");+ break;case SLOT_CLOSED:default:m_name = TheGameText->fetch("GUI:Closed");@@ -257,12 +263,15 @@ Bool GameSlot::isHuman( void ) constBool GameSlot::isOccupied( void ) const{- return m_state == SLOT_PLAYER || m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI;+ return m_state == SLOT_PLAYER || isAI();}Bool GameSlot::isAI( void ) const{- return m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI;+ // 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.+ return m_state == SLOT_EASY_AI || m_state == SLOT_MED_AI || m_state == SLOT_BRUTAL_AI || m_state == SLOT_TAKEOVER;}Bool GameSlot::isPlayer( AsciiString userName ) const@@ -966,7 +975,9 @@ AsciiString GameInfoToAsciiString( const GameInfo *game )else if (slot && slot->isAI()){Char c;- if (slot->getState() == SLOT_EASY_AI)+ 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';@@ -1334,6 +1345,11 @@ Bool ParseAsciiStringToGameInfo(GameInfo *game, AsciiString options)//DEBUG_LOG(("ParseAsciiStringToGameInfo - Medium AI\n"));}break;+ case 'P':+ {+ newSlot[i].setState(SLOT_TAKEOVER);+ }+ break;case 'H':{newSlot[i].setState(SLOT_BRUTAL_AI);