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(gamelogic): open one-cell holes in hill-blocked sight

Olcay Seygan15bd13613667
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 13bc65740..6eca57df7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,10 @@ found and fixed, EA's own, not port damage.**
- When something you cannot see hits one of your units or buildings, the fog opens around the shooter for two and a half seconds: a small circle, just wide enough to show what fired and not the ground around it. Artillery behind a ridge or a jet out of the dark shows itself the moment its shot lands. Your allies see it too, as they see everything else you see. A stealthed unit nobody has detected stays hidden, and a shot from something you can already see opens nothing. A replay recorded before this change plays out differently.
+## Sight without holes
+
+- What a unit sees used to come out dotted. Each square of ground is checked for a hill or a tree between it and the eye, and a single tree or a bump no taller than a tank hid one square here and a thin streak there, so the fog inside a unit's sight was full of pinholes. A hidden square now comes into sight when at least six of the eight around it are in sight: the pinholes and the one-square streaks open, while the shadow a real ridge or a building throws, two squares wide or more, stays dark, and nothing is seen further away than before. A replay recorded before this change plays out differently.
+
## The command bar fits the map
- The radar takes the map's shape at a height that never changes: a long map widens it to the right, a tall map narrows it, and the frame's top stays level with the bar beside it. The black bands beside the map are gone; only a map too long for the room before the command buttons keeps thin ones above and below. A click on the radar still lands where it always did.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
index 67280f57e..6f1455083 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
@@ -302,6 +302,13 @@ extern void PartitionManager_findSightMargins( const Real *heights, Int cellRadi
enum { SIGHT_CELL_GROUND = 0x01, SIGHT_CELL_AIR = 0x02 };
extern UnsignedByte PartitionManager_sightCellFlags( Bool groundRevealed, Int offsetX, Int offsetY, Int flatCellRadius );
+/** Open the one-cell holes and streaks a tree or a bump in the ground leaves in a hill-blocked
+ sighting, side cells a side: a hidden cell with SIGHT_GAP_SEEN_NEIGHBOURS of its eight neighbours
+ in sight comes into sight. Judged on the sighting as it was, so one opened hole never opens the
+ next, and the square's border is left alone, so the sight never grows past its edge. */
+enum { SIGHT_GAP_SEEN_NEIGHBOURS = 6 };
+extern void PartitionManager_closeSightGaps( UnsignedByte *revealedCells, Int side );
+
//=====================================
/**
We sometimes need to save whether or not an area was fogged or permanently revealed through a
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
index 9a9cf26cb..72bc25ca5 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
@@ -4528,6 +4528,31 @@ UnsignedByte PartitionManager_sightCellFlags( Bool groundRevealed, Int offsetX,
return flags;
}
+//-----------------------------------------------------------------------------
+void PartitionManager_closeSightGaps( UnsignedByte *revealedCells, Int side )
+{
+ static std::vector<UnsignedByte> before;
+ before.assign( revealedCells, revealedCells + side * side );
+
+ for( Int y = 1; y < side - 1; ++y )
+ {
+ for( Int x = 1; x < side - 1; ++x )
+ {
+ if( before[ y * side + x ] & SIGHT_CELL_GROUND )
+ continue;
+
+ Int seen = 0;
+ for( Int neighbourY = y - 1; neighbourY <= y + 1; ++neighbourY )
+ for( Int neighbourX = x - 1; neighbourX <= x + 1; ++neighbourX )
+ if( before[ neighbourY * side + neighbourX ] & SIGHT_CELL_GROUND )
+ ++seen;
+
+ if( seen >= SIGHT_GAP_SEEN_NEIGHBOURS )
+ revealedCells[ y * side + x ] |= SIGHT_CELL_GROUND;
+ }
+ }
+}
+
//-----------------------------------------------------------------------------
static Int sightCellRadius( Real radius )
{
@@ -4717,6 +4742,9 @@ void PartitionManager::doBlockedShroudReveal( SightingInfo *sighting, const Obje
sighting->m_revealedCells[ cell ] = PartitionManager_sightCellFlags( revealed, offsetX, offsetY, flatCellRadius );
}
+ // the cells outside the circle are recorded hidden and never applied, so the circle's edge stays put
+ PartitionManager_closeSightGaps( &sighting->m_revealedCells[0], side );
+
applyRecordedReveal( sighting, TRUE );
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 5418fe20d..5445b70dd 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -10275,6 +10275,42 @@ TEST(a_hill_hides_the_ground_behind_it_not_the_aircraft_over_it)
CHECK( PartitionManager_sightCellFlags( TRUE, 6, 0, 4 ) == SIGHT_CELL_GROUND );
}
+/** A tree or a bump in the ground hid single cells and one-cell streaks inside a unit's sight, and
+ the fog came out dotted. A hidden cell with nearly all of its neighbours in sight is in sight;
+ a strip two cells wide, and the edge of the sight itself, stay as they were. */
+TEST(sight_has_no_one_cell_holes)
+{
+ const Int side = 7;
+ UnsignedByte cells[ side * side ];
+
+ for( Int cell = 0; cell < side * side; ++cell )
+ cells[ cell ] = SIGHT_CELL_GROUND;
+ cells[ 2 * side + 2 ] = 0;
+ for( Int x = 0; x < side; ++x )
+ cells[ 4 * side + x ] = 0;
+ PartitionManager_closeSightGaps( cells, side );
+ CHECK( cells[ 2 * side + 2 ] == SIGHT_CELL_GROUND );
+ CHECK( cells[ 4 * side + 3 ] == SIGHT_CELL_GROUND );
+ CHECK( cells[ 4 * side + 0 ] == 0 );
+
+ for( Int cell = 0; cell < side * side; ++cell )
+ cells[ cell ] = SIGHT_CELL_GROUND;
+ for( Int x = 0; x < side; ++x )
+ {
+ cells[ 3 * side + x ] = 0;
+ cells[ 4 * side + x ] = 0;
+ }
+ PartitionManager_closeSightGaps( cells, side );
+ CHECK( cells[ 3 * side + 3 ] == 0 );
+ CHECK( cells[ 4 * side + 3 ] == 0 );
+
+ // a shadow's corner keeps its shape
+ for( Int cell = 0; cell < side * side; ++cell )
+ cells[ cell ] = ( cell / side >= 3 && cell % side >= 3 ) ? 0 : SIGHT_CELL_GROUND;
+ PartitionManager_closeSightGaps( cells, side );
+ CHECK( cells[ 3 * side + 3 ] == 0 );
+}
+
/** Since the plan reveals nothing, the fog it was placed in would swallow it - and there would be
nothing left on screen to click on and cancel. Your own plan is drawn through the fog; anything
else fogged, including an enemy's, is still hidden. */