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.

fix(gameclient): placement shows only enemy buildings you have seen

Olcay Seyganf9382636eacc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4af8243ee..52d131a63 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -661,6 +661,7 @@ found and fixed — EA's own, not port damage.**
- Click a plan, or press Stop, to cancel it and take the money back.
- Cancelling a plan is silent — nothing was built, so nothing explodes.
- Ground your units have walked stays buildable after they leave it.
+- Placing a building no longer shows you the enemy's base. The red cells under the building on your cursor marked every structure on the map, the ones standing in the shroud and the ones going up in the fog since you last looked included, so sweeping the cursor over the dark drew your opponent's foundations for you. The red tint and the outline under the building did the same in the fog, and the building slid flush against walls you had never seen. All of it now goes by what you have seen: a building you scouted still shows where your eyes left it, one you have not shows nothing until you find it. Put a building down on top of one you could not see and the order is turned down, as it always was.
- A plan opens no fog of its own, and your opponent never sees it. Not with a unit parked right next
to the site, and not as a leftover outline in the fog after that unit walks away. Both used to show
an AI's whole base layout before its first worker arrived.
diff --git a/GeneralsMD/Code/BuildFingerprint.manifest b/GeneralsMD/Code/BuildFingerprint.manifest
index c9640d5a8..9e61e8d81 100644
--- a/GeneralsMD/Code/BuildFingerprint.manifest
+++ b/GeneralsMD/Code/BuildFingerprint.manifest
@@ -211,6 +211,7 @@ Data/Scenarios/exitmovebuild.txt
Data/Scenarios/exitorders.txt
Data/Scenarios/expansionbunker.txt
Data/Scenarios/explreel.txt
+Data/Scenarios/fogleak.txt
Data/Scenarios/givemoney.txt
Data/Scenarios/glowbase.txt
Data/Scenarios/glowfight.txt
diff --git a/GeneralsMD/Code/Data/Scenarios/fogleak.txt b/GeneralsMD/Code/Data/Scenarios/fogleak.txt
new file mode 100644
index 000000000..6cb98822b
--- /dev/null
+++ b/GeneralsMD/Code/Data/Scenarios/fogleak.txt
@@ -0,0 +1,15 @@
+# Seat 1 is a computer China on Twilight Flame building its base in seat 0's fog; seat 0 is the
+# player at this machine and builds nothing. At frame 1200 (40 seconds) a Comanche of seat 0 is
+# put down over seat 1's start and the base comes into view. With a structure on the cursor over
+# that base, the placement grid must wash none of its cells red before the Comanche and the seen
+# ones after it. A file cannot put a structure on the cursor, so the check is a drawing run with a
+# temporary log in W3DInGameUI::takeBuildGrid, or a look. On 2026-10-19 the 57-cell patch round
+# seat 1's command centre held 175 enemy cells (4 of them a building going up) and washed 0 of
+# them until the Comanche arrived, then 171.
+#
+# generals.exe -win -turbo -quickstart -noshellmap -multiInstance -noFPSLimit
+# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -aidiff easy
+# -side 0 FactionAmerica -side 1 FactionChina -seed 1 -maxframes 3000 -scenario fogleak
+# -logPrefix fogleak_
+
+1200 spawn 0 AmericaVehicleComanche 1 start1
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
index 113650441..4a8288c52 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/BuildAssistant.h
@@ -107,6 +107,13 @@ enum LegalBuildCode : Int
//-------------------------------------------------------------------------------------------------
extern Bool BuildAssistant_shroudBlocksBuilding( CellShroudStatus status );
+//-------------------------------------------------------------------------------------------------
+/** Is this object one the player at this machine has no picture of: shrouded, or a unit in the fog,
+ * or a building the fog closed over before he ever saw it? Client feedback only - the shroud
+ * status it reads is filled per machine and is not lockstep. */
+//-------------------------------------------------------------------------------------------------
+extern Bool BuildAssistant_isHiddenFromLocalPlayer( const Object *obj );
+
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class BuildAssistant : public SubsystemInterface
@@ -129,7 +136,8 @@ public:
SHROUD_REVEALED = 0x00000010, ///< Check to make sure the shroud is revealed
NO_ENEMY_OBJECT_OVERLAP = 0x00000020, ///< Can't overlap enemy objects only.
IGNORE_STEALTHED = 0x00000040, ///< Units that we can't see are legal to "build" on. (when moving mouse around)
- FAIL_STEALTHED_WITHOUT_FEEDBACK = 0x00000080 ///< USE WITH IGNORE_STEALTHED except it will fail without BIB feedback (when clicking to place).
+ FAIL_STEALTHED_WITHOUT_FEEDBACK = 0x00000080, ///< USE WITH IGNORE_STEALTHED except it will fail without BIB feedback (when clicking to place).
+ IGNORE_UNSEEN = 0x00000100 ///< Client only: what the local player cannot see is legal to build on (BuildAssistant_isHiddenFromLocalPlayer); never from logic
};
public:
@@ -183,7 +191,8 @@ public:
Real angle, // angle to consturct thing being tiled
const Coord3D *start, const Coord3D *end,
Real tilingSize, Int maxTiles,
- Object *builderObject );
+ Object *builderObject,
+ UnsignedInt extraOptions = 0 ); ///< IGNORE_UNSEEN from the client's ghost
/// return the "scratch pad" array that can be used to create a line of build locations
virtual inline Coord3D *getBuildLocations( void ) { return m_buildPositions; }
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
index 3551ff480..d4a7956f3 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/System/BuildAssistant.cpp
@@ -35,6 +35,7 @@
#include "Common/BuildAssistant.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
+#include "Common/PlayerList.h"
#include "Common/ThingTemplate.h"
#include "Common/GameAudio.h"
#include "Common/ThingFactory.h"
@@ -737,6 +738,13 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos
}
}
+ // The ghost and its red bib go by what this player has seen: counting a building standing in
+ // the shroud, or put up in the fog since he last looked, turned the ghost red over it and drew
+ // its footprint. The order still meets the full check in the logic, which refuses it there.
+ // A stealthed thing the click was told to fail on quietly (above) is left to fail.
+ if( BitTest( options, IGNORE_UNSEEN ) && feedbackWithFailure && BuildAssistant_isHiddenFromLocalPlayer( them ) )
+ continue;
+
//Kris: Patch 1.01 - November 5, 2003
//Prevent busy units (black lotus hacking from being moved by trying to place a building -- exploit).
if( rel == ALLIES )
@@ -890,6 +898,9 @@ LegalBuildCode BuildAssistant::isLocationClearOfObjects( const Coord3D *worldPos
}
}
+ if( BitTest( options, IGNORE_UNSEEN ) && BuildAssistant_isHiddenFromLocalPlayer( them ) )
+ continue;
+
// ignore any kind of class of objects that we will "remove" for building
if( isRemovableForConstruction( them ) == TRUE )
continue;
@@ -966,6 +977,26 @@ Bool BuildAssistant_shroudBlocksBuilding( CellShroudStatus status )
return status == CELLSHROUD_SHROUDED;
}
+//-------------------------------------------------------------------------------------------------
+/** Fogged is a picture: a building he walked past is still drawn there from the ghost, and the
+ * object's own status says FOGGED only for that (see PartitionData::getShroudedStatus). A unit in
+ * the fog, a building the fog closed over unseen and anything shrouded come back SHROUDED. A
+ * stealthed thing nobody has detected is not drawn for him either, wherever it stands. */
+//-------------------------------------------------------------------------------------------------
+Bool BuildAssistant_isHiddenFromLocalPlayer( const Object *obj )
+{
+ const Player *me = ThePlayerList->getLocalPlayer();
+ if( obj->getControllingPlayer() == me || me->getRelationship( obj->getTeam() ) == ALLIES )
+ return FALSE;
+
+ if( obj->testStatus( OBJECT_STATUS_STEALTHED ) && !obj->testStatus( OBJECT_STATUS_DETECTED ) &&
+ !obj->testStatus( OBJECT_STATUS_DISGUISED ) )
+ return TRUE;
+
+ const ObjectShroudStatus status = obj->getShroudedStatus( me->getPlayerIndex() );
+ return status != OBJECTSHROUD_CLEAR && status != OBJECTSHROUD_PARTIAL_CLEAR && status != OBJECTSHROUD_FOGGED;
+}
+
//-------------------------------------------------------------------------------------------------
/** Rule 16 of Pro Rules for one spot: are the owner's defences round the derrick cluster this spot
* belongs to already at the cap? The largest cluster measured on the game's maps is four derricks,
@@ -1192,7 +1223,8 @@ LegalBuildCode BuildAssistant::isLocationLegalToBuild( const Coord3D *worldPos,
// The relationship is asked here rather than through PartitionFilterPlayerAffiliation, which
// lets a player's own objects through whatever it is asked for - and the first building near
// any spot in a base is that base's own command center, so every base refused itself.
- if( owner->getRelationship( them->getTeam() ) == ENEMIES )
+ if( owner->getRelationship( them->getTeam() ) == ENEMIES &&
+ !( BitTest( options, IGNORE_UNSEEN ) && BuildAssistant_isHiddenFromLocalPlayer( them ) ) )
return LBC_TOO_CLOSE_TO_ENEMY;
}
}
@@ -1260,7 +1292,8 @@ BuildAssistant::TileBuildInfo *BuildAssistant::buildTiledLocations( const ThingT
const Coord3D *end,
Real tilingSize,
Int maxTiles,
- Object *builderObject )
+ Object *builderObject,
+ UnsignedInt extraOptions )
{
// sanity
@@ -1338,7 +1371,8 @@ BuildAssistant::TileBuildInfo *BuildAssistant::buildTiledLocations( const ThingT
BuildAssistant::TERRAIN_RESTRICTIONS |
BuildAssistant::CLEAR_PATH |
BuildAssistant::NO_OBJECT_OVERLAP |
- BuildAssistant::SHROUD_REVEALED,
+ BuildAssistant::SHROUD_REVEALED |
+ extraOptions,
builderObject,
NULL) != LBC_OK )
break;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index adc9a73f9..9b1d99fd2 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -2207,7 +2207,8 @@ void InGameUI::handleBuildPlacements( void )
&worldStart, &worldEnd,
objectSize,
TheGlobalData->m_maxLineBuildObjects,
- builderObject );
+ builderObject,
+ BuildAssistant::IGNORE_UNSEEN );
positions = tileBuildInfo->positions;
iconsUsed = tileBuildInfo->tilesUsed;
}
@@ -5740,7 +5741,9 @@ void InGameUI::computePlacementRow( const ThingTemplate *what, Real angle, const
/** The legality question asked of the spot under the ghost, in one place - the nudge search asks it
* of every candidate too. IGNORE_STEALTHED is deliberate: a structure you cannot put down is a
* place a stealthed unit is standing, and the placement cursor is not a detector. The click
- * re-asks with FAIL_STEALTHED_WITHOUT_FEEDBACK, which is where that actually gets decided. */
+ * re-asks with FAIL_STEALTHED_WITHOUT_FEEDBACK, which is where that actually gets decided.
+ * IGNORE_UNSEEN is the same for the fog: the ghost, its bib, the nudge and the click know only what
+ * this player has seen, and the logic's own check turns down an order on a building he has not. */
//-------------------------------------------------------------------------------------------------
UnsignedInt InGameUI::placementCheckOptions( void )
{
@@ -5749,7 +5752,8 @@ UnsignedInt InGameUI::placementCheckOptions( void )
BuildAssistant::CLEAR_PATH |
BuildAssistant::NO_OBJECT_OVERLAP |
BuildAssistant::SHROUD_REVEALED |
- BuildAssistant::IGNORE_STEALTHED;
+ BuildAssistant::IGNORE_STEALTHED |
+ BuildAssistant::IGNORE_UNSEEN;
} // end placementCheckOptions
@@ -5860,7 +5864,9 @@ void InGameUI::snapPlacementToNeighbour( Coord3D *world, const ThingTemplate *wh
MemoryPoolObjectHolder holder( iter );
for( Object *obj = iter->first(); obj; obj = iter->next() )
{
- if( !obj->isKindOf( KINDOF_STRUCTURE ) || obj->isEffectivelyDead() )
+ // a ghost that jumps flush against bare ground says where an unseen building stands
+ if( !obj->isKindOf( KINDOF_STRUCTURE ) || obj->isEffectivelyDead() ||
+ BuildAssistant_isHiddenFromLocalPlayer( obj ) )
continue;
PlacementBox standing;
diff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
index 13c9a3619..460260644 100644
--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DInGameUI.h
@@ -96,6 +96,13 @@ protected:
Matrix3D m_moveHintTransform[ MAX_MOVE_HINTS ]; ///< each ring laid on the ground at the sync point (recordDraw)
void takeMoveHintTransforms( void );
+ // the build grid's patch, read at the sync point (recordDraw) and drawn by drawBuildGrid
+ enum { BUILD_GRID_RADIUS = 28, BUILD_GRID_CELLS = BUILD_GRID_RADIUS * 2 + 1 };
+ Int m_buildGridCellX; ///< the patch's first pathfinder cell
+ Int m_buildGridCellY;
+ Bool m_buildGridBlocked[ BUILD_GRID_CELLS ][ BUILD_GRID_CELLS ]; ///< [y][x], washed red
+ void takeBuildGrid( void );
+
// recordDraw's lists, replayed by draw
Display::DrawCalls m_overWorldDraw; ///< preDraw to the guard markers, drawn where the world is
Display::DrawCalls m_dragBoxDraw; ///< the drag box, drawn where the pointer is
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index bdd549f47..a9ce1f467 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include "Lib/Clock.h"
+#include "Common/BuildAssistant.h"
#include "Common/GameEngine.h"
#include "Common/GlobalData.h"
#include "Common/Player.h"
@@ -44,6 +45,7 @@
#include "GameLogic/TerrainLogic.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
+#include "GameLogic/PartitionManager.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameClient/CinemaDirector.h"
@@ -304,6 +306,10 @@ W3DInGameUI::W3DInGameUI()
m_moveHintAnim[ i ] = NULL;
}
+ m_buildGridCellX = 0;
+ m_buildGridCellY = 0;
+ memset( m_buildGridBlocked, 0, sizeof( m_buildGridBlocked ) );
+
} // end W3DInGameUI
//-------------------------------------------------------------------------------------------------
@@ -537,6 +543,7 @@ void W3DInGameUI::recordDraw( void )
TheDisplay->beginRecording( &m_overWorldDraw );
preDraw();
+ takeBuildGrid(); // after preDraw, which puts the ghost where the patch is centred
// draw the formation line if one is being dragged out
if( m_isFormationDragging )
@@ -880,7 +887,10 @@ static void setGroundOverlayState( void )
* structure, plain impassable. It deliberately does not run the full isLocationLegalToBuild for
* every cell - that is a per-structure query (build radius, shroud, supply proximity) and a
* couple of hundred of them a frame is not worth it. The ghost's own red tint already answers
- * that question for the one spot the cursor is actually on. */
+ * that question for the one spot the cursor is actually on.
+ *
+ * The cells are read at the sync point (takeBuildGrid), not here: this runs in the terrain pass,
+ * beside the tick. */
//-------------------------------------------------------------------------------------------------
void W3DInGameUI::drawBuildGrid( void )
{
@@ -891,20 +901,12 @@ void W3DInGameUI::drawBuildGrid( void )
const Bool drawLines = gridPlacementOn();
if( m_placeIcon == NULL || m_placeIcon[ 0 ] == NULL )
return;
- if( TheTerrainLogic == NULL || TheAI == NULL )
- return;
-
- Pathfinder *pathfinder = TheAI->pathfinder();
- if( pathfinder == NULL )
- return;
-
- const Coord3D *center = m_placeIcon[ 0 ]->getPosition();
- if( center == NULL )
+ if( TheTerrainLogic == NULL )
return;
// how many cells each way around the cursor we light up
- enum { GRID_RADIUS = 28 };
- enum { GRID_CELLS = GRID_RADIUS * 2 + 1, GRID_POINTS = GRID_CELLS + 1 };
+ enum { GRID_RADIUS = BUILD_GRID_RADIUS };
+ enum { GRID_CELLS = BUILD_GRID_CELLS, GRID_POINTS = GRID_CELLS + 1 };
// half the width of a painted line, in world units - a cell is PLACEMENT_CELL (10) across
const Real LINE_HALF_WIDTH = 0.3f;
@@ -913,8 +915,8 @@ void W3DInGameUI::drawBuildGrid( void )
const Real GRID_LIFT = 0.35f;
// the pathfinder's own cell indexing, so the lines drawn are the lines it reasons about
- const Int cellX = REAL_TO_INT_FLOOR( (center->x + 0.5f) / PATHFIND_CELL_SIZE_F ) - GRID_RADIUS;
- const Int cellY = REAL_TO_INT_FLOOR( (center->y + 0.5f) / PATHFIND_CELL_SIZE_F ) - GRID_RADIUS;
+ const Int cellX = m_buildGridCellX;
+ const Int cellY = m_buildGridCellY;
// sample the terrain once per grid corner, rather than once per quad corner. Static, not
// automatic: at this radius the two square tables are ~27k together, which is more than a
@@ -990,8 +992,7 @@ void W3DInGameUI::drawBuildGrid( void )
{
for( ix = 0; ix < GRID_CELLS; ++ix )
{
- PathfindCell *cell = pathfinder->getCell( LAYER_GROUND, cellX + ix, cellY + iy );
- if( cell == NULL || cell->getType() == PathfindCell::CELL_CLEAR )
+ if( !m_buildGridBlocked[ iy ][ ix ] )
continue;
if( fade[ iy ][ ix ] <= 0.0f && fade[ iy + 1 ][ ix + 1 ] <= 0.0f )
@@ -1012,6 +1013,51 @@ void W3DInGameUI::drawBuildGrid( void )
} // end drawBuildGrid
+//-------------------------------------------------------------------------------------------------
+/** Which cells of the patch round the ghost drawBuildGrid washes red, read from the pathfinder at
+ * the sync point. The pathfinder marks every structure the moment it is placed, the enemy's in the
+ * shroud included, so its cells alone drew enemy foundations into the dark: a cell held by
+ * something the local player has no picture of stays clear here, and so does rubble under the
+ * shroud. Water, cliffs and plain impassable ground are the map's own and always show. */
+//-------------------------------------------------------------------------------------------------
+void W3DInGameUI::takeBuildGrid( void )
+{
+ if( m_pendingPlaceType == NULL || m_placeIcon == NULL || m_placeIcon[ 0 ] == NULL )
+ return;
+
+ const Coord3D *center = m_placeIcon[ 0 ]->getPosition();
+ m_buildGridCellX = REAL_TO_INT_FLOOR( (center->x + 0.5f) / PATHFIND_CELL_SIZE_F ) - BUILD_GRID_RADIUS;
+ m_buildGridCellY = REAL_TO_INT_FLOOR( (center->y + 0.5f) / PATHFIND_CELL_SIZE_F ) - BUILD_GRID_RADIUS;
+
+ Pathfinder *pathfinder = TheAI->pathfinder();
+ const Int me = ThePlayerList->getLocalPlayer()->getPlayerIndex();
+
+ for( Int iy = 0; iy < BUILD_GRID_CELLS; ++iy )
+ {
+ for( Int ix = 0; ix < BUILD_GRID_CELLS; ++ix )
+ {
+ const PathfindCell *cell = pathfinder->getCell( LAYER_GROUND, m_buildGridCellX + ix, m_buildGridCellY + iy );
+ Bool blocked = cell != NULL && cell->getType() != PathfindCell::CELL_CLEAR;
+
+ if( blocked && cell->getType() == PathfindCell::CELL_OBSTACLE )
+ {
+ blocked = !BuildAssistant_isHiddenFromLocalPlayer( TheGameLogic->findObjectByID( cell->getObstacleID() ) );
+ }
+ else if( blocked && cell->getType() == PathfindCell::CELL_RUBBLE )
+ {
+ Coord3D at;
+ at.x = ( (Real)( m_buildGridCellX + ix ) + 0.5f ) * PATHFIND_CELL_SIZE_F;
+ at.y = ( (Real)( m_buildGridCellY + iy ) + 0.5f ) * PATHFIND_CELL_SIZE_F;
+ at.z = 0.0f;
+ blocked = ThePartitionManager->getShroudStatusForPlayer( me, &at ) != CELLSHROUD_SHROUDED;
+ }
+
+ m_buildGridBlocked[ iy ][ ix ] = blocked;
+ }
+ }
+
+} // end takeBuildGrid
+
//-------------------------------------------------------------------------------------------------
/** The wash inside the circle a left drag is sweeping targets out of. The rim is a screen space
* line drawn with everything else; this is the ground it encloses, laid down in the terrain pass