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(gameclient): show the watcher what the watcher can see
Olcay Seygan5a97951a9c27
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 158d1ab37..c34934ed6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -266,6 +266,8 @@ found and fixed — EA's own, not port damage.**- Pausing stops both clocks.- Watching a match, the strip becomes every player's queue at once: one row each, bordered in that player's colour, showing the five that land soonest and a count of the rest.- Watching, the bars over the buildings are everyone's too - what each factory is turning out, and how long the superweapons have left. An observer used to see none of it.+- Watching, you see the fog the player you are watching sees. The game only ever remembered one player's fog, so switching seats handed you the first player's idea of the map.+- An ally, and anyone watching, now sees a stealthed unit's muzzle flash, its promotion and the cash it earns - if they can see the unit at all. Those three asked 'is it mine' instead of 'can I see it', so allies and observers got nothing.## Placing buildingsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.hindex 31f8e13ab..fc287176a 100644--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/GhostObject.h@@ -93,6 +93,22 @@ public:virtual void restorePartitionData(void); ///<restores ghost objects into the partition manager.inline void lockGhostObjects(Bool enableLock) {m_lockGhostObjects=enableLock;} ///<temporary lock on creating new ghost objects. Only used by map border resizing!inline void saveLockGhostObjects(Bool enableLock) {m_saveLockGhostObjects=enableLock;}++ // Remembering what is under the fog costs a snapshot per player, so by default only the local+ // player's memory is kept. Anyone who can become a different player - an observer, or the+ // take-over key - needs every player's, or the fog they are handed is still the first player's.+ // This used to be the compile-time DEBUG_FOG_MEMORY, which meant it was never on in a build+ // anyone plays.+ inline void setTrackAllPlayers(Bool track) { m_trackAllPlayers = track; }+ inline Bool trackAllPlayers(void) const+ {+#ifdef DEBUG_FOG_MEMORY+ return TRUE;+#else+ return m_trackAllPlayers;+#endif+ }+protected:virtual void crc( Xfer *xfer );virtual void xfer( Xfer *xfer );@@ -100,6 +116,7 @@ protected:Int m_localPlayer;Bool m_lockGhostObjects;Bool m_saveLockGhostObjects; ///< used to lock the ghost object system during a save/load+ Bool m_trackAllPlayers; ///< keep every player's fog memory, not just the local player's};// the singletondiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cppindex fa93d3fee..ae6a62dea 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GameClient.cpp@@ -669,29 +669,35 @@ void GameClient::update( void )if (!freezeTime){+ Int numNonLocalPlayers=0;+ Int nonLocalPlayerIndices[MAX_PLAYER_COUNT];+#if defined(_DEBUG) || defined(_INTERNAL)if (TheGlobalData->m_shroudOn)#elseif (true)#endif{- //localPlayerIndex=TheGhostObjectManager->getLocalPlayerIndex(); //always use the first local player set since normally can't change. Doesn't work with debug "CTRL_SHIFT_SPACE"-#ifdef DEBUG_FOG_MEMORY- //Find indices of all active players- Int numPlayers=ThePlayerList->getPlayerCount();- Int numNonLocalPlayers=0;- Int nonLocalPlayerIndices[MAX_PLAYER_COUNT];- for (Int i=0; i<numPlayers; i++)- { Player *player=ThePlayerList->getNthPlayer(i);- //if (player->getPlayerType == PLAYER_HUMAN)- if (player->getPlayerIndex() != localPlayerIndex)- nonLocalPlayerIndices[numNonLocalPlayers++]=player->getPlayerIndex();+ // Whether every player's fog memory is kept is a runtime question now: an observer, and+ // anyone who can take a player over mid-match, needs all of them. It used to be the+ // compile-time DEBUG_FOG_MEMORY, so in a build anyone plays it was never on and+ // switching player handed you the first player's fog.+ if (TheGhostObjectManager->trackAllPlayers())+ {+ //Find indices of all active players+ Int numPlayers=ThePlayerList->getPlayerCount();+ for (Int i=0; i<numPlayers; i++)+ { Player *player=ThePlayerList->getNthPlayer(i);+ if (player->getPlayerIndex() != localPlayerIndex)+ nonLocalPlayerIndices[numNonLocalPlayers++]=player->getPlayerIndex();+ }+ //update ghostObjects which don't have drawables or objects.+ TheGhostObjectManager->updateOrphanedObjects(nonLocalPlayerIndices,numNonLocalPlayers);+ }+ else+ {+ TheGhostObjectManager->updateOrphanedObjects(NULL,0);}- //update ghostObjects which don't have drawables or objects.- TheGhostObjectManager->updateOrphanedObjects(nonLocalPlayerIndices,numNonLocalPlayers);-#else- TheGhostObjectManager->updateOrphanedObjects(NULL,0);-#endif}@@ -712,11 +718,14 @@ void GameClient::update( void )Object *object=draw->getObject();if (object){- #ifdef DEBUG_FOG_MEMORY- Int *playerIndex=nonLocalPlayerIndices;- for (i=0; i<numNonLocalPlayers; i++, playerIndex++)- object->getShroudedStatus(*playerIndex);- #endif+ if (numNonLocalPlayers > 0)+ {+ // keep the other players' view of this object current too, so their fog+ // memory is right the moment you become one of them+ Int *playerIndex=nonLocalPlayerIndices;+ for (Int p=0; p<numNonLocalPlayers; p++, playerIndex++)+ object->getShroudedStatus(*playerIndex);+ }ObjectShroudStatus ss=object->getShroudedStatus(localPlayerIndex);if (ss >= OBJECTSHROUD_FOGGED && draw->getShroudClearFrame()!=0) {UnsignedInt limit = 2*LOGICFRAMES_PER_SECOND;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cppindex bfb70449f..0606fa3a9 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp@@ -3535,9 +3535,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessageThePlayerList->setLocalPlayer(ThePlayerList->getNthPlayer(idx));TheInGameUI->deselectAllDrawables();- #ifdef DEBUG_FOG_MEMORY+ // the fog you are handed has to be the fog of the player you just becameTheGhostObjectManager->setLocalPlayerIndex(idx);- #endifThePartitionManager->refreshShroudForLocalPlayer();TheControlBar->initSpecialPowershortcutBar(ThePlayerList->getLocalPlayer());TheControlBar->setControlBarSchemeByPlayer(ThePlayerList->getLocalPlayer());@@ -4081,9 +4080,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessageThePlayerList->setLocalPlayer(ThePlayerList->getNthPlayer(idx));TheInGameUI->deselectAllDrawables();-#ifdef DEBUG_FOG_MEMORY+ // the fog you are handed has to be the fog of the player you just becameTheGhostObjectManager->setLocalPlayerIndex(idx);-#endifThePartitionManager->refreshShroudForLocalPlayer();TheControlBar->initSpecialPowershortcutBar(ThePlayerList->getLocalPlayer());TheControlBar->setControlBarSchemeByPlayer(ThePlayerList->getLocalPlayer());diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/GhostObject.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/GhostObject.cppindex c8f77f4d8..24509e463 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/GhostObject.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/GhostObject.cpp@@ -141,6 +141,7 @@ GhostObjectManager::GhostObjectManager(void)m_lockGhostObjects = FALSE;m_saveLockGhostObjects = FALSE;m_localPlayer = 0;+ m_trackAllPlayers = FALSE;}// ------------------------------------------------------------------------------------------------diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cppindex e40378fe1..2ac84da1f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp@@ -3185,14 +3185,13 @@ void Object::onVeterancyLevelChanged( VeterancyLevel oldLevel, VeterancyLevel neif (body)body->onVeterancyLevelChanged( oldLevel, newLevel, provideFeedback );- Bool hideAnimationForStealth = FALSE;- if( !isLocallyControlled() &&- testStatus( OBJECT_STATUS_STEALTHED ) &&- !testStatus( OBJECT_STATUS_DETECTED ) &&- !testStatus( OBJECT_STATUS_DISGUISED ) )- {- hideAnimationForStealth = TRUE;- }+ // Whether the promotion shows is simply whether this watcher can see the unit. The rule used+ // to be spelled out here as "mine, or not stealthed, or detected, or disguised", which reads+ // the same for a player but is wrong for everyone else at the table: an ally who shares your+ // sight, and an observer who sees everything, both got nothing. The drawable already answers+ // the question for whoever is watching.+ const Drawable *draw = getDrawable();+ Bool hideAnimationForStealth = ( draw == NULL || !((Drawable *)draw)->isVisible() );Bool doAnimation = ( ! hideAnimationForStealth&& (newLevel > oldLevel)diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cppindex 3bbef3106..9145a40af 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/HackInternetAIUpdate.cpp@@ -551,24 +551,13 @@ StateReturnType HackInternetState::update()//Grant the unit some experience for a successful hack.xp->addExperiencePoints( ai->getXpPerCashUpdate() );- Bool displayMoney = TRUE;- if( owner->testStatus(OBJECT_STATUS_STEALTHED) )- {- // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!- if( !owner->isLocallyControlled() && !owner->testStatus(OBJECT_STATUS_DETECTED) )- {- displayMoney = FALSE;- }- }- if( owner->getContainedBy() && owner->getContainedBy()->testStatus(OBJECT_STATUS_STEALTHED) )- {- // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!- if( !owner->getContainedBy()->isLocallyControlled() && !owner->getContainedBy()->testStatus(OBJECT_STATUS_DETECTED) )- {- displayMoney = FALSE;- }- }-+ // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!+ // Whether the figure shows is whether this watcher can see the hacker. Spelling the+ // rule out as "mine, or not stealthed, or detected" reads the same for a player but+ // hides it from an ally who shares the sight and from an observer who sees everything.+ Drawable *ownerDraw = owner->getDrawable();+ Bool displayMoney = ( ownerDraw != NULL && ownerDraw->isVisible() );+if( displayMoney ){// OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cppindex 883a6873b..d2a7b8f2f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AutoDepositUpdate.cpp@@ -66,6 +66,7 @@#include "GameClient/InGameUI.h"#include "GameClient/Color.h"#include "GameClient/GameText.h"+#include "GameClient/Drawable.h"//-------------------------------------------------------------------------------------------------void parseUpgradePair( INI *ini, void *instance, void *store, const void *userData )@@ -208,16 +209,11 @@ UpdateSleepTime AutoDepositUpdate::update( void )getObject()->getControllingPlayer()->getScoreKeeper()->addMoneyEarned( moneyAmount );}- Bool displayMoney = moneyAmount > 0 ? TRUE : FALSE;- if( getObject()->testStatus(OBJECT_STATUS_STEALTHED) )- {- // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!- if( !getObject()->isLocallyControlled() && !getObject()->testStatus(OBJECT_STATUS_DETECTED) )- {- displayMoney = FALSE;- }-- }+ // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!+ // The figure shows if this watcher can see the building - which covers an ally sharing the+ // sight and an observer, both of whom the old spelled-out rule left out.+ Drawable *depositDraw = getObject()->getDrawable();+ Bool displayMoney = ( moneyAmount > 0 && depositDraw != NULL && depositDraw->isVisible() );if( displayMoney ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cppindex 36a22de31..0b8002936 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/DockUpdate/SupplyCenterDockUpdate.cpp@@ -36,6 +36,7 @@#include "GameClient/Color.h"#include "GameClient/InGameUI.h"#include "GameClient/GameText.h"+#include "GameClient/Drawable.h"#ifdef _INTERNAL// for occasional debugging...@@ -133,15 +134,11 @@ Bool SupplyCenterDockUpdate::action( Object* docker, Object *drone )}}- Bool displayMoney = value > 0 ? TRUE : FALSE;- if( getObject()->testStatus(OBJECT_STATUS_STEALTHED) )- {- // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!- if( !getObject()->isLocallyControlled() && !getObject()->testStatus(OBJECT_STATUS_DETECTED) )- {- displayMoney = FALSE;- }- }+ // OY LOOK! I AM USING LOCAL PLAYER. Do not put anything other than TheInGameUI->addFloatingText in the block this controls!!!+ // The figure shows if this watcher can see the centre - an ally sharing the sight and an+ // observer both got nothing from the old spelled-out rule.+ Drawable *centerDraw = getObject()->getDrawable();+ Bool displayMoney = ( value > 0 && centerDraw != NULL && centerDraw->isVisible() );if( displayMoney ){diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cppindex 832245155..ed384693a 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Weapon.cpp@@ -933,10 +933,12 @@ UnsignedInt WeaponTemplate::fireWeaponTemplateBool handled;- if(!sourceObj->isLocallyControlled() // if user watching is not controller and- && sourceObj->testStatus(OBJECT_STATUS_STEALTHED) // if unit is stealthed (like a Pathfinder)- && !sourceObj->testStatus(OBJECT_STATUS_DETECTED) // but not detected...- && !sourceObj->testStatus(OBJECT_STATUS_DISGUISED) // and not disguised...+ // Whether the muzzle flash shows is simply whether this watcher can see the firer. The rule+ // used to be spelled out as "not mine, and stealthed, and not detected, and not disguised",+ // which reads the same for a player but hid the shot from an ally who shares your sight and+ // from an observer who sees everything.+ Drawable *sourceDraw = sourceObj->getDrawable();+ if((sourceDraw == NULL || !sourceDraw->isVisible()) // if the watcher cannot see us&& !sourceObj->isKindOf(KINDOF_MINE) // and not a mine (which always do the FX, even if hidden)...&& !isPlayFXWhenStealthed() // and not a weapon marked to playwhenstealthed)diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cppindex e783b7d93..4b6428d30 100644--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp@@ -1662,6 +1662,10 @@ void GameLogic::startNewGame( Bool loadingSaveGame )ThePartitionManager->init();ThePartitionManager->refreshShroudForLocalPlayer();// Can't do this until after init, and doesn't seem right to do in init+ // An observer watches from behind whichever player's eyes it picks, so its fog memory has to be+ // kept for every player from the first frame - there is no going back and remembering later.+ // A player watches only their own, which is what the extra snapshots are worth avoiding.+ TheGhostObjectManager->setTrackAllPlayers( ThePlayerList->getLocalPlayer()->isPlayerObserver() );TheGhostObjectManager->setLocalPlayerIndex(ThePlayerList->getLocalPlayer()->getPlayerIndex());TheGhostObjectManager->reset();diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cppindex 92ad1d930..e5c25e718 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DShroud.cpp@@ -266,7 +266,9 @@ W3DShroudLevel W3DShroud::getShroudLevel(Int x, Int y){DEBUG_ASSERTCRASH( m_pSrcTexture != NULL, ("Reading empty shroud"));- if (x < m_numCellsX && y < m_numCellsY)+ // the upper bound was checked and the lower was not, so a negative cell - which is what a+ // position just off the edge of the map gives - read backwards out of the shroud texture+ if (x >= 0 && y >= 0 && x < m_numCellsX && y < m_numCellsY){UnsignedShort pixel=*(UnsignedShort *)((Byte *)m_srcTextureData + x*2 + y*m_srcTexturePitch);