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): reveal attackers firing from the fog

Olcay Seygancff58982aa6a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a3df8ebe..13bc65740 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ found and fixed, EA's own, not port damage.**
---
+## A shot from the fog gives the shooter away
+
+- 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.
+
## 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 7caaea3d6..67280f57e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/PartitionManager.h
@@ -1324,7 +1324,7 @@ private:
Bool m_updatedSinceLastReset; ///< Used to force a return of OBJECTSHROUD_INVALID before update has been called.
Bool m_cellsFromSave; ///< see isKeepingCellsFromSave
- std::queue<SightingInfo *> m_pendingUndoShroudReveals; ///< Anything can queue up an Undo to happen later. This is a queue, because "later" is a constant
+ std::deque<SightingInfo *> m_pendingUndoShroudReveals; ///< Undos waiting for their frame, sorted by it: an unlook waits a constant and goes on the back, a timed reveal is inserted in order
#ifdef FASTER_GCO
Int m_maxGcoRadius;
@@ -1445,6 +1445,7 @@ public:
void doShroudReveal( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
void undoShroudReveal( Real centerX, Real centerY, Real radius, PlayerMaskType playerMask);
void queueUndoShroudReveal( SightingInfo *sighting ); ///< takes the sighting's recorded cells with it
+ void doTimedShroudReveal( const Coord3D *center, Real radius, PlayerMaskType playerMask, UnsignedInt frames ); ///< reveal now, undone after frames
/** 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
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 0bf256534..18eaab4b3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -2062,6 +2062,33 @@ Bool Object::isUnknownTo( Int playerIndex ) const
!m_partitionData->isFullyShroudedFor( playerIndex ) );
}
+//-------------------------------------------------------------------------------------------------
+// A shot out of the fog gives its shooter away: the victim's side sees a small circle round the
+// attacker for a moment, enough to see what hit it and not the ground around it.
+static const UnsignedInt FOG_ATTACKER_REVEAL_FRAMES = LOGICFRAMES_PER_SECOND * 5 / 2;
+static const Real FOG_ATTACKER_REVEAL_MARGIN = 15.0f; ///< past the attacker's own footprint, about a shroud cell and a half
+
+static void Object_revealAttackerInFog( const Object *victim, ObjectID attackerID )
+{
+ const Object *attacker = TheGameLogic->findObjectByID( attackerID );
+ if( attacker == NULL || victim->getRelationship( attacker ) != ENEMIES )
+ return;
+
+ // an unseen stealth unit stays unseen; the same test the reveal-to-all range makes
+ if( attacker->testStatus( OBJECT_STATUS_STEALTHED ) && !attacker->testStatus( OBJECT_STATUS_DETECTED ) &&
+ !attacker->testStatus( OBJECT_STATUS_DISGUISED ) )
+ return;
+
+ const Int victimIndex = victim->getControllingPlayer()->getPlayerIndex();
+ if( ThePartitionManager->getShroudStatusForPlayer( victimIndex, attacker->getPosition() ) == CELLSHROUD_CLEAR )
+ return;
+
+ // the victim's allies share its sight everywhere else, so they share this too
+ PlayerMaskType revealMask = ThePlayerList->getPlayersWithRelationship( victimIndex, ALLOW_SAME_PLAYER | ALLOW_ALLIES );
+ Real radius = attacker->getGeometryInfo().getBoundingCircleRadius() + FOG_ATTACKER_REVEAL_MARGIN;
+ ThePartitionManager->doTimedShroudReveal( attacker->getPosition(), radius, revealMask, FOG_ATTACKER_REVEAL_FRAMES );
+}
+
//-------------------------------------------------------------------------------------------------
/** Something is attempting to damage this object */
//-------------------------------------------------------------------------------------------------
@@ -2127,6 +2154,11 @@ void Object::attemptDamage( DamageInfo *damageInfo )
getControllingPlayer() == ThePlayerList->getLocalPlayer() )
TheRadar->tryUnderAttackEvent( this );
+ if( damageInfo->out.m_actualDamageDealt > 0.0f &&
+ damageInfo->in.m_damageType != DAMAGE_PENALTY &&
+ damageInfo->in.m_damageType != DAMAGE_HEALING )
+ Object_revealAttackerInFog( this, damageInfo->in.m_sourceID );
+
}
//-------------------------------------------------------------------------------------------------
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
index 5c56d919b..9a9cf26cb 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/PartitionManager.cpp
@@ -85,6 +85,7 @@
#include "GameClient/ControlBar.h"
#include "GameClient/ObserverCamera.h"
+#include <algorithm>
#include <float.h>
/* A hint that a cache line is about to be read. It reads nothing the program sees and decides
@@ -4320,7 +4321,7 @@ void PartitionManager::processPendingUndoShroudRevealQueue( Bool considerTimesta
undoShroudReveal( thisInfo->m_where.x, thisInfo->m_where.y, thisInfo->m_howFar, thisInfo->m_forWhom );
thisInfo->deleteInstance();
- m_pendingUndoShroudReveals.pop();
+ m_pendingUndoShroudReveals.pop_front();
}
}
@@ -4341,7 +4342,7 @@ void PartitionManager::resetPendingUndoShroudRevealQueue()
{
SightingInfo *thisInfo = m_pendingUndoShroudReveals.front();
thisInfo->deleteInstance();
- m_pendingUndoShroudReveals.pop();
+ m_pendingUndoShroudReveals.pop_front();
}
}
@@ -4367,6 +4368,21 @@ void PartitionManager::undoShroudReveal(Real centerX, Real centerY, Real radius,
}
}
+//-----------------------------------------------------------------------------
+static Bool undoFrameBefore( UnsignedInt frame, const SightingInfo *info )
+{
+ return frame < info->m_data;
+}
+
+//-----------------------------------------------------------------------------
+/** The queue is drained from the front while the front is due, so it has to stay sorted by undo
+ frame: an unlook and a timed reveal wait different times. An entry goes behind every one due on
+ the same frame, so the order is the same on every machine. */
+static void insertByUndoFrame( std::deque<SightingInfo *> &pending, SightingInfo *info )
+{
+ pending.insert( std::upper_bound( pending.begin(), pending.end(), info->m_data, undoFrameBefore ), info );
+}
+
//-----------------------------------------------------------------------------
void PartitionManager::queueUndoShroudReveal( SightingInfo *sighting )
{
@@ -4379,7 +4395,21 @@ void PartitionManager::queueUndoShroudReveal( SightingInfo *sighting )
newInfo->m_revealedCells.swap( sighting->m_revealedCells );
newInfo->m_data = now + TheGlobalData->m_unlookPersistDuration;
- m_pendingUndoShroudReveals.push(newInfo);
+ insertByUndoFrame( m_pendingUndoShroudReveals, newInfo );
+}
+
+//-----------------------------------------------------------------------------
+void PartitionManager::doTimedShroudReveal( const Coord3D *center, Real radius, PlayerMaskType playerMask, UnsignedInt frames )
+{
+ doShroudReveal( center->x, center->y, radius, playerMask );
+
+ SightingInfo *newInfo = newInstance(SightingInfo);
+ newInfo->m_where = *center;
+ newInfo->m_howFar = radius;
+ newInfo->m_forWhom = playerMask;
+ newInfo->m_data = TheGameLogic->getFrame() + frames;
+
+ insertByUndoFrame( m_pendingUndoShroudReveals, newInfo );
}
//-----------------------------------------------------------------------------
@@ -5296,20 +5326,13 @@ void PartitionManager::xfer( Xfer *xfer )
{
SightingInfo *newInfo = newInstance(SightingInfo);
xfer->xferSnapshot(newInfo);
- m_pendingUndoShroudReveals.push(newInfo);
+ insertByUndoFrame( m_pendingUndoShroudReveals, newInfo );
}
}
else
{
- // And on Save, I need to loop through, but not destroy anything, so I pop-push n times, cycling through the queue once
- // (No random access on queues, and speed not a concern in saveload)
for( Int infoIndex = 0; infoIndex < queueSize; infoIndex++ )
- {
- SightingInfo *saveInfo = m_pendingUndoShroudReveals.front();
- xfer->xferSnapshot(saveInfo);
- m_pendingUndoShroudReveals.pop();
- m_pendingUndoShroudReveals.push(saveInfo);
- }
+ xfer->xferSnapshot(m_pendingUndoShroudReveals[infoIndex]);
}
}