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): block sight behind hills and buildings, cap it by range

Olcay Seygan1aede71ce8b7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea4538a64..66e57c371 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -310,6 +310,8 @@ found and fixed — EA's own, not port damage.**
- A supply upgrade pays for what arrives. The bonus was a flat sum handed over on arrival, so a truck turning up with one box collected the same as a full load - and a driver dropping off little and often earned several times what the upgrade is worth.
- Taking over a defeated ally's base no longer starts his research again from scratch. A player upgrade is bought once for the whole player, and the buildings you inherit were left paying for a second copy of what you already had.
- A tank drives out the moment it is paid for. The factory doors only began opening once the vehicle was already finished, and it stood inside waiting for them, so every single unit cost its build time plus the whole door animation on top - on every tank, all game. The doors now start moving during the last seconds of the build and are open on the frame the unit is done. And they stay open while there is another vehicle behind him, however long that takes: a factory working through a queue keeps its doors up and shuts them when the queue runs out, instead of dropping and hauling them back for every unit. That was worth watching in its own right - there is no artwork for a door that changes its mind partway, so a door caught mid-close and pulled back open snapped wide in a single frame.
+- A unit lifts the fog only half as far again as its guns reach: enough to spot what it is about to fight, not enough to scout. A rifleman used to see well past the range of his rifle, so any cheap soldier was a scout. Artillery that outshoots its own eyes still needs a spotter, and units with no weapon at all, like bulldozers and supply trucks, keep the sight they had. Buildings are unchanged.
+- Hills and buildings block sight. A tank at the foot of a ridge used to see straight through it to the far side, and a squad in a city saw through every block around it. Now the fog stays on whatever a ridge, a building or a tree hides, yours, the enemy's or a civilian's, and a unit on high ground looks down over everything below it. Aircraft fly above it all and see past. Soldiers garrisoned in a building still see out of it; its own walls do not blind them.
## One crate, one collector
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
index 93582533e..253486888 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
@@ -174,6 +174,9 @@ extern Bool Object_constructionFootprintGoesDown( Bool underConstruction, Real w
extern Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real constructionPercent,
Real boundingCircleRadius );
+///< how far an armed unit clears shroud: no further than half as far again as its longest weapon reaches
+extern Real Object_armedShroudClearingRange( Real clearingRange, Real largestWeaponRange );
+
///< does this object go away without any death of its own - no explosion, no collapse, no rubble?
extern Bool Object_deathIsSilent( Bool underConstruction, Real constructionPercent );
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
index 982c5144e..447e10ae1 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
@@ -256,7 +256,13 @@ public:
Coord3D m_where;
Real m_howFar;
PlayerMaskType m_forWhom; // ask not for whom the sighting is masked; it masks for thee
-
+
+ /** For a sighting that hills and buildings cut short, the cells it actually revealed: one entry per
+ cell of the square around m_where, row by row, nonzero for revealed. Kept rather than worked out
+ again at undo time, because a building that went up or came down in between would hide a
+ different set and the looker counts would never come back. Empty for a whole circle. */
+ std::vector<UnsignedByte> m_revealedCells;
+
UnsignedInt m_data; // Threat and value use as the value. Sighting uses it for a Timestamp
protected:
@@ -268,6 +274,12 @@ protected:
};
+/** How far each cell of a square around an eye sits above the steepest ground between it and the eye.
+ heights and sightMargin are (2 * cellRadius + 1) cells a side, row by row, with the eye over the
+ middle cell; a cell is in sight when its margin is zero or more. */
+extern void PartitionManager_findSightMargins( const Real *heights, Int cellRadius, Real cellSize, Real eyeZ,
+ Real *sightMargin );
+
//=====================================
/**
We sometimes need to save whether or not an area was fogged or permanently revealed through a
@@ -1316,6 +1328,9 @@ protected:
friend void hLineAddValue(Int x1, Int x2, Int y, void *threatValueParms);
friend void hLineRemoveValue(Int x1, Int x2, Int y, void *threatValueParms);
+ /// add or take away a looker on every cell a sighting recorded as revealed
+ void applyRecordedReveal( const SightingInfo *sighting, Bool reveal );
+
void processPendingUndoShroudRevealQueue(Bool considerTimestamp = TRUE); ///< keep popping and processing untill you get to one that is in the future
void resetPendingUndoShroudRevealQueue(); ///< Just delete everything in the queue without doing anything with them
@@ -1367,7 +1382,12 @@ public:
// Queueing does not give you control of the timestamp to enforce the queue. I own the delay, you don't.
void doShroudReveal( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
void undoShroudReveal( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
- void queueUndoShroudReveal( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask );
+ void queueUndoShroudReveal( SightingInfo *sighting ); ///< takes the sighting's recorded cells with it
+
+ /** Reveal the circle around an eye except where a hill or a building stands between the eye and
+ the ground, and record in the sighting which cells that was. The looker never hides behind
+ itself or the building it sits in. */
+ void doBlockedShroudReveal( SightingInfo *sighting, const Object *looker );
void doShroudCover( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
void undoShroudCover( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index dc8691b5e..e2e17ab94 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -5188,7 +5188,12 @@ void Object::look()
// garrisoned buildings weren't looking, we were just seeing the leftover last look of the guy inside.
// Otherwise we'd just have enclosingContainer control looking which is the 'correct' answer.
+ // applied here and not in getShroudClearingRange, so the sight bonuses that multiply the
+ // stored range and later divide it back out never bake the weapon cap into it
Real shroudClearingRange = getShroudClearingRange();
+ if( !isKindOf( KINDOF_STRUCTURE ) )
+ shroudClearingRange = Object_armedShroudClearingRange( shroudClearingRange, getLargestWeaponRange() );
+
if( shroudClearingRange > 0.0f )
{
PlayerMaskType lookingMask = 0;
@@ -5227,12 +5232,14 @@ void Object::look()
lookingMask |= m_visionSpiedMask;
}
- Coord3D pos = *getPosition();
- ThePartitionManager->doShroudReveal( pos.x, pos.y, shroudClearingRange, lookingMask );
+ // the eye is at the top of the object, so an aircraft looks over the hill a tank cannot
+ Coord3D eye = *getPosition();
+ eye.z += getGeometryInfo().getMaxHeightAbovePosition();
- m_partitionLastLook->m_where = pos;
+ m_partitionLastLook->m_where = eye;
m_partitionLastLook->m_forWhom = lookingMask;
- m_partitionLastLook->m_howFar = getShroudClearingRange();
+ m_partitionLastLook->m_howFar = shroudClearingRange;
+ ThePartitionManager->doBlockedShroudReveal( m_partitionLastLook, this );
// DEBUG_LOG(( "A %s looks at %f, %f for %x at range %f\n",
// getTemplate()->getName().str(),
@@ -5278,11 +5285,7 @@ void Object::unlook()
return;
}
- ThePartitionManager->queueUndoShroudReveal(m_partitionLastLook->m_where.x,
- m_partitionLastLook->m_where.y,
- m_partitionLastLook->m_howFar,
- m_partitionLastLook->m_forWhom
- );
+ ThePartitionManager->queueUndoShroudReveal( m_partitionLastLook );
// DEBUG_LOG(( "A %s queues an unlook at %f, %f for %x at range %f\n",
// getTemplate()->getName().str(),
@@ -5296,11 +5299,7 @@ void Object::unlook()
if( !m_partitionRevealAllLastLook->isInvalid() )
{
- ThePartitionManager->queueUndoShroudReveal(m_partitionRevealAllLastLook->m_where.x,
- m_partitionRevealAllLastLook->m_where.y,
- m_partitionRevealAllLastLook->m_howFar,
- m_partitionRevealAllLastLook->m_forWhom
- );
+ ThePartitionManager->queueUndoShroudReveal( m_partitionRevealAllLastLook );
m_partitionRevealAllLastLook->reset();
}
@@ -5427,6 +5426,21 @@ Real Object_shroudClearingRange( Real ownRange, Bool underConstruction, Real con
return ownRange;
}
+//-------------------------------------------------------------------------------------------------
+/** A unit sees half as far again as it can shoot: far enough to spot what it would close with on an
+ * attack move before it is in range, no further. A unit with no weapon at all (largestWeaponRange
+ * is -1 then) keeps the sight its template gives it, or dozers, trucks and spies would go blind. */
+//-------------------------------------------------------------------------------------------------
+static const Real SIGHT_PER_WEAPON_RANGE = 1.5f;
+
+Real Object_armedShroudClearingRange( Real clearingRange, Real largestWeaponRange )
+{
+ if( largestWeaponRange <= 0.0f )
+ return clearingRange;
+
+ return min( clearingRange, largestWeaponRange * SIGHT_PER_WEAPON_RANGE );
+}
+
//-------------------------------------------------------------------------------------------------
Bool Object_deathIsSilent( Bool underConstruction, Real constructionPercent )
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
index df1f10674..20bbb72da 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
@@ -81,6 +81,8 @@
#include "GameClient/Line2D.h"
#include "GameClient/ControlBar.h"
+#include <float.h>
+
#ifdef _DEBUG
//#include "GameClient/InGameUI.h" // for debugHints
#include "Common/PlayerList.h"
@@ -4105,7 +4107,10 @@ void PartitionManager::processPendingUndoShroudRevealQueue( Bool considerTimesta
{
SightingInfo *thisInfo = m_pendingUndoShroudReveals.front();
- undoShroudReveal( thisInfo->m_where.x, thisInfo->m_where.y, thisInfo->m_howFar, thisInfo->m_forWhom );
+ if( !thisInfo->m_revealedCells.empty() )
+ applyRecordedReveal( thisInfo, FALSE );
+ else
+ undoShroudReveal( thisInfo->m_where.x, thisInfo->m_where.y, thisInfo->m_howFar, thisInfo->m_forWhom );
thisInfo->deleteInstance();
m_pendingUndoShroudReveals.pop();
@@ -4156,19 +4161,208 @@ void PartitionManager::undoShroudReveal(Real centerX, Real centerY, Real radius,
}
//-----------------------------------------------------------------------------
-void PartitionManager::queueUndoShroudReveal(Real centerX, Real centerY, Real radius, PlayerMaskType playerMask)
+void PartitionManager::queueUndoShroudReveal( SightingInfo *sighting )
{
UnsignedInt now = TheGameLogic->getFrame();
SightingInfo *newInfo = newInstance(SightingInfo);
- newInfo->m_where.x = centerX;
- newInfo->m_where.y = centerY;
- newInfo->m_howFar = radius;
- newInfo->m_forWhom = playerMask;
+ newInfo->m_where = sighting->m_where;
+ newInfo->m_howFar = sighting->m_howFar;
+ newInfo->m_forWhom = sighting->m_forWhom;
+ newInfo->m_revealedCells.swap( sighting->m_revealedCells );
newInfo->m_data = now + TheGlobalData->m_unlookPersistDuration;
m_pendingUndoShroudReveals.push(newInfo);
}
+
+//-----------------------------------------------------------------------------
+static Real slopeFromEye( Real height, Int cellOffsetX, Int cellOffsetY, Real cellSize, Real eyeZ )
+{
+ return ( height - eyeZ ) / ( sqrtf( (Real)( cellOffsetX * cellOffsetX + cellOffsetY * cellOffsetY ) ) * cellSize );
+}
+
+//-----------------------------------------------------------------------------
+/** minor * (major - 1) / major, rounded half away from zero: where a line from the middle through
+ (major, minor) crosses the ring one step further in. */
+static Int scaleOneRingIn( Int minor, Int major )
+{
+ const Int halfStep = minor < 0 ? -major : major;
+ return ( 2 * minor * ( major - 1 ) + halfStep ) / ( 2 * major );
+}
+
+//-----------------------------------------------------------------------------
+/** One pass, ring by ring outwards. Each cell takes the steepest slope met on the way in from its
+ neighbour one step closer to the middle, together with that neighbour's own slope, so a ridge
+ keeps hiding everything behind it however far the circle reaches. The middle cell is where the
+ eye stands and hides nothing. */
+void PartitionManager_findSightMargins( const Real *heights, Int cellRadius, Real cellSize, Real eyeZ,
+ Real *sightMargin )
+{
+ const Int side = 2 * cellRadius + 1;
+ const Int middle = cellRadius * side + cellRadius;
+ static std::vector<Real> steepestOnTheWay;
+ steepestOnTheWay.resize( side * side );
+
+ steepestOnTheWay[ middle ] = -FLT_MAX;
+ sightMargin[ middle ] = 0.0f;
+
+ for( Int ring = 1; ring <= cellRadius; ++ring )
+ {
+ for( Int offsetY = -ring; offsetY <= ring; ++offsetY )
+ {
+ const Int stepX = ( abs( offsetY ) == ring ) ? 1 : 2 * ring;
+ for( Int offsetX = -ring; offsetX <= ring; offsetX += stepX )
+ {
+ Int innerX, innerY;
+ if( abs( offsetX ) >= abs( offsetY ) )
+ {
+ innerX = offsetX - ( offsetX < 0 ? -1 : 1 );
+ innerY = scaleOneRingIn( offsetY, abs( offsetX ) );
+ }
+ else
+ {
+ innerY = offsetY - ( offsetY < 0 ? -1 : 1 );
+ innerX = scaleOneRingIn( offsetX, abs( offsetY ) );
+ }
+
+ const Int inner = ( innerY + cellRadius ) * side + innerX + cellRadius;
+ const Int here = ( offsetY + cellRadius ) * side + offsetX + cellRadius;
+
+ Real steepest = steepestOnTheWay[ inner ];
+ if( inner != middle )
+ steepest = max( steepest, slopeFromEye( heights[ inner ], innerX, innerY, cellSize, eyeZ ) );
+
+ steepestOnTheWay[ here ] = steepest;
+ sightMargin[ here ] = slopeFromEye( heights[ here ], offsetX, offsetY, cellSize, eyeZ ) - steepest;
+ }
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+struct RecordedLookers
+{
+ Int m_cornerX; ///< cell coordinates of the first entry of m_revealedCells
+ Int m_cornerY;
+ Int m_side;
+ const UnsignedByte *m_revealedCells;
+ Int m_playerIndex;
+ Bool m_reveal; ///< add the looker, or take it away again
+};
+
+//-----------------------------------------------------------------------------
+static void hLineRecordedLooker( Int x1, Int x2, Int y, void *lookersVoid )
+{
+ const RecordedLookers *lookers = (const RecordedLookers *)lookersVoid;
+ if( y < 0 || y >= ThePartitionManager->getCellCountY() )
+ return;
+
+ const UnsignedByte *revealed = lookers->m_revealedCells + ( y - lookers->m_cornerY ) * lookers->m_side - lookers->m_cornerX;
+ for( Int x = max( x1, 0 ); x <= min( x2, ThePartitionManager->getCellCountX() - 1 ); ++x )
+ {
+ if( !revealed[ x ] )
+ continue;
+
+ PartitionCell *cell = ThePartitionManager->getCellAt( x, y );
+ if( lookers->m_reveal )
+ cell->addLooker( lookers->m_playerIndex );
+ else
+ cell->removeLooker( lookers->m_playerIndex );
+ }
+}
+
+//-----------------------------------------------------------------------------
+static Int sightCellRadius( Real radius )
+{
+ return max( ThePartitionManager->worldToCellDist( radius ), 1 );
+}
+
+//-----------------------------------------------------------------------------
+void PartitionManager::applyRecordedReveal( const SightingInfo *sighting, Bool reveal )
+{
+ Int cellCenterX, cellCenterY;
+ worldToCell( sighting->m_where.x, sighting->m_where.y, &cellCenterX, &cellCenterY );
+ const Int cellRadius = sightCellRadius( sighting->m_howFar );
+
+ RecordedLookers lookers;
+ lookers.m_cornerX = cellCenterX - cellRadius;
+ lookers.m_cornerY = cellCenterY - cellRadius;
+ lookers.m_side = 2 * cellRadius + 1;
+ lookers.m_revealedCells = &sighting->m_revealedCells[0];
+ lookers.m_reveal = reveal;
+
+ DiscreteCircle circle( cellCenterX, cellCenterY, cellRadius );
+ for( Int currentIndex = ThePlayerList->getPlayerCount() - 1; currentIndex >= 0; currentIndex-- )
+ {
+ if( BitTest( sighting->m_forWhom, ThePlayerList->getNthPlayer( currentIndex )->getPlayerMask() ) )
+ {
+ lookers.m_playerIndex = currentIndex;
+ circle.drawCircle( hLineRecordedLooker, &lookers );
+ }
+ }
+}
+
+//-----------------------------------------------------------------------------
+/** The top of whatever stands in a cell: the highest ground in it, or the roof of a building on it if
+ that is higher. Trees and bushes that are objects count, a bridge does not (it is ground to walk
+ on and to see across). A planned building nobody has started is not there yet. */
+static Real sightBlockingHeight( PartitionCell *cell, const Object *looker, const Object *lookerContainer )
+{
+ Real height = cell->getHiTerrain();
+ for( CellAndObjectIntersection *coi = cell->getFirstCoiInCell(); coi; coi = coi->getNextCoi() )
+ {
+ // a ghost object has no Object behind it
+ const Object *obj = coi->getModule()->getObject();
+ if( obj == NULL || obj == looker || obj == lookerContainer )
+ continue;
+
+ if( !obj->isKindOf( KINDOF_STRUCTURE ) && !obj->isKindOf( KINDOF_SHRUBBERY ) )
+ continue;
+
+ if( obj->isKindOf( KINDOF_BRIDGE ) )
+ continue;
+
+ if( Object_isAwaitingBuilder( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ), obj->getConstructionPercent() ) )
+ continue;
+
+ height = max( height, obj->getPosition()->z + obj->getGeometryInfo().getMaxHeightAbovePosition() );
+ }
+ return height;
+}
+
+//-----------------------------------------------------------------------------
+void PartitionManager::doBlockedShroudReveal( SightingInfo *sighting, const Object *looker )
+{
+ Int cellCenterX, cellCenterY;
+ worldToCell( sighting->m_where.x, sighting->m_where.y, &cellCenterX, &cellCenterY );
+ const Int cellRadius = sightCellRadius( sighting->m_howFar );
+ const Object *lookerContainer = looker->getContainedBy();
+
+ const Int side = 2 * cellRadius + 1;
+ static std::vector<Real> heights;
+ static std::vector<Real> sightMargin;
+ heights.resize( side * side );
+ sightMargin.resize( side * side );
+
+ for( Int offsetY = -cellRadius; offsetY <= cellRadius; ++offsetY )
+ {
+ const Int cellY = min( max( cellCenterY + offsetY, 0 ), m_cellCountY - 1 );
+ for( Int offsetX = -cellRadius; offsetX <= cellRadius; ++offsetX )
+ {
+ const Int cellX = min( max( cellCenterX + offsetX, 0 ), m_cellCountX - 1 );
+ heights[ ( offsetY + cellRadius ) * side + offsetX + cellRadius ] =
+ sightBlockingHeight( getCellAt( cellX, cellY ), looker, lookerContainer );
+ }
+ }
+
+ PartitionManager_findSightMargins( &heights[0], cellRadius, m_cellSize, sighting->m_where.z, &sightMargin[0] );
+
+ sighting->m_revealedCells.resize( side * side );
+ for( Int cell = 0; cell < side * side; ++cell )
+ sighting->m_revealedCells[ cell ] = sightMargin[ cell ] >= 0.0f;
+
+ applyRecordedReveal( sighting, TRUE );
+}
//-----------------------------------------------------------------------------
void PartitionManager::doShroudCover(Real centerX, Real centerY, Real radius, PlayerMaskType playerMask)
@@ -5978,6 +6172,7 @@ void SightingInfo::reset()
m_howFar = 0.0f;
m_forWhom = 0;
m_data = 0;
+ m_revealedCells.clear();
}
// ------------------------------------------------------------------------------------------------
@@ -5998,13 +6193,14 @@ void SightingInfo::crc( Xfer *xfer )
// ------------------------------------------------------------------------------------------------
/** Xfer Method
* Version Info:
- * 1: Initial version */
+ * 1: Initial version
+ * 2: m_revealedCells; a version 1 sighting was a whole circle and is undone as one */
// ------------------------------------------------------------------------------------------------
void SightingInfo::xfer( Xfer *xfer )
{
// version
- XferVersion currentVersion = 1;
+ XferVersion currentVersion = 2;
XferVersion version = currentVersion;
xfer->xferVersion( &version, currentVersion );
@@ -6020,6 +6216,15 @@ void SightingInfo::xfer( Xfer *xfer )
// how much
xfer->xferUnsignedInt( &m_data );
+ if( version >= 2 )
+ {
+ Int revealedCellCount = m_revealedCells.size();
+ xfer->xferInt( &revealedCellCount );
+ m_revealedCells.resize( revealedCellCount );
+ if( revealedCellCount > 0 )
+ xfer->xferUser( &m_revealedCells[0], revealedCellCount );
+ }
+
} // end xfer
// ------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index db3626305..da61bdf09 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -124,6 +124,7 @@
#include "GameLogic/Object.h"
#include "GameClient/CommandXlat.h"
#include "Common/ActionManager.h"
+#include "GameLogic/PartitionManager.h"
#include <stdio.h>
#include <string.h>
@@ -6478,6 +6479,55 @@ TEST(a_planned_structure_opens_no_shroud_until_the_work_starts)
CHECK_NEAR( Object_shroudClearingRange( 0.0f, FALSE, CONSTRUCTION_COMPLETE, boundingRadius ), 0.0f, 0.0001f );
}
+/** A unit sees half as far again as its longest weapon reaches. Artillery that outranges its own sight
+ keeps the sight, and a unit with no weapon keeps what its template gives it. */
+TEST(an_armed_unit_sees_little_further_than_it_can_shoot)
+{
+ const Real noWeapon = -1.0f;
+
+ CHECK_NEAR( Object_armedShroudClearingRange( 200.0f, 100.0f ), 150.0f, 0.0001f );
+ CHECK_NEAR( Object_armedShroudClearingRange( 200.0f, 350.0f ), 200.0f, 0.0001f );
+ CHECK_NEAR( Object_armedShroudClearingRange( 200.0f, 150.0f ), 200.0f, 0.0001f );
+ CHECK_NEAR( Object_armedShroudClearingRange( 200.0f, noWeapon ), 200.0f, 0.0001f );
+ CHECK_NEAR( Object_armedShroudClearingRange( 0.0f, 100.0f ), 0.0f, 0.0001f );
+}
+
+
+/** A hill hides the ground behind it. Standing in the middle of flat ground with a wall of high cells
+ two to the east, the unit sees the wall and nothing past it, and sees everything to the west. Put
+ the eye above the wall, the way an aircraft flies, and the far side comes back. */
+TEST(a_unit_does_not_see_over_a_hill)
+{
+ const Int cellRadius = 4;
+ const Int side = 2 * cellRadius + 1;
+ const Real cellSize = 40.0f;
+ const Real groundZ = 10.0f;
+ const Real hillZ = 60.0f;
+ const Real tankEyeZ = groundZ + 15.0f;
+ const Real aircraftEyeZ = groundZ + 200.0f;
+ const Int wallOffsetX = 2;
+
+ Real heights[ side * side ];
+ Real sightMargin[ side * side ];
+ for( Int cell = 0; cell < side * side; ++cell )
+ heights[ cell ] = groundZ;
+ for( Int row = 0; row < side; ++row )
+ heights[ row * side + cellRadius + wallOffsetX ] = hillZ;
+
+ const Int middleRow = cellRadius * side;
+ PartitionManager_findSightMargins( heights, cellRadius, cellSize, tankEyeZ, sightMargin );
+
+ CHECK( sightMargin[ middleRow + cellRadius + 1 ] >= 0.0f );
+ CHECK( sightMargin[ middleRow + cellRadius + wallOffsetX ] >= 0.0f );
+ CHECK( sightMargin[ middleRow + cellRadius + wallOffsetX + 1 ] < 0.0f );
+ CHECK( sightMargin[ middleRow + side - 1 ] < 0.0f );
+ CHECK( sightMargin[ middleRow + 0 ] >= 0.0f );
+ CHECK( sightMargin[ 0 ] >= 0.0f );
+
+ PartitionManager_findSightMargins( heights, cellRadius, cellSize, aircraftEyeZ, sightMargin );
+ CHECK( sightMargin[ middleRow + side - 1 ] >= 0.0f );
+}
+
/** 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. */