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): take over another player with Shift+Ctrl+T

Olcay Seygan489085cece1d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f9968029..be30ddbca 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -296,6 +296,7 @@ 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.
- 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/INI/CommandMap.ini b/GeneralsMD/Code/Data/INI/CommandMap.ini
index ae7379252..29bd1ee95 100644
--- a/GeneralsMD/Code/Data/INI/CommandMap.ini
+++ b/GeneralsMD/Code/Data/INI/CommandMap.ini
@@ -556,3 +556,16 @@ CommandMap VIEW_VIEW8
Description = GUI:ViewView8Description
DisplayName = GUI:ViewView8
End
+
+;-----------------------------------------------------------------------------
+; Single-player test hook: take over the next player - its AI is thrown away,
+; so its base and units answer to you and nothing fights you for them. Press
+; again to walk on to the next one and eventually back to your own. Does
+; nothing in a network game or a replay.
+CommandMap SWITCH_CONTROL
+ Key = KEY_T
+ Transition = DOWN
+ Modifiers = SHIFT_CTRL
+ UseableIn = GAME
+ Category = DEBUG
+End
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index da96a983f..4e6dcdfe8 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -310,6 +310,7 @@ public:
MSG_META_TOGGLE_CAMERA_TRACKING_DRAWABLE,
MSG_META_TOGGLE_FAST_FORWARD_REPLAY, ///< Toggle the fast forward feature
MSG_META_DEMO_INSTANT_QUIT, ///< bail out of game immediately
+ MSG_META_SWITCH_CONTROL, ///< take over the next player in a single-player game, AI and all (fork)
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index c4d7dc049..0fd475e93 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -413,6 +413,7 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_META_CAMERA_RESET)
CHECK_IF(MSG_META_TOGGLE_CAMERA_TRACKING_DRAWABLE)
CHECK_IF(MSG_META_DEMO_INSTANT_QUIT)
+ CHECK_IF(MSG_META_SWITCH_CONTROL)
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index b0894d245..d0170e40e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -3957,6 +3957,48 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
+ //--------------------------------------------------------------------------------------
+ /* Single-player test hook: hand the next player over to the keyboard. Its AI is deleted
+ outright, so nothing fights you for its units - press again to walk on to the player
+ after it, and eventually back around to your own.
+ ponytail: only the AIPlayer goes away - the map's own scripts can still order that
+ player'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)
+ {
+ if (ThePlayerList->getNthPlayer(i) == ThePlayerList->getLocalPlayer())
+ {
+ 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());
+ break;
+ }
+ }
+ disp = DESTROY_MESSAGE;
+ break;
+ }
+
#ifdef ALLOW_ALT_F4
case GameMessage::MSG_META_DEMO_INSTANT_QUIT:
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 97ba1221e..e91ec6b1d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -222,6 +222,7 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "TOGGLE_CAMERA_TRACKING_DRAWABLE", GameMessage::MSG_META_TOGGLE_CAMERA_TRACKING_DRAWABLE },
{ "TOGGLE_FAST_FORWARD_REPLAY", GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY },
{ "DEMO_INSTANT_QUIT", GameMessage::MSG_META_DEMO_INSTANT_QUIT },
+ { "SWITCH_CONTROL", GameMessage::MSG_META_SWITCH_CONTROL },
#if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
{ "CHEAT_RUNSCRIPT1", GameMessage::MSG_CHEAT_RUNSCRIPT1 },