Skip to content

Commit d33fa42

Browse files
secprenticeclaude
andcommitted
Fix #2452: Per-object cooldown for under-attack radar alarm
Each object now tracks the last logic frame its under-attack alarm fired. A new alarm from the same object is suppressed until 10 seconds have elapsed, regardless of what other objects are doing. This replaces the map-wide PRESERVE_RADAR_WARNING_SUPPRESSION workaround (which could suppress a legitimate base-under-attack warning because a cargo plane's alarm had fired moments earlier). With per-object cooldown each unit is silenced independently, so simultaneous attacks at different locations each report correctly while a single continuously-hit unit (e.g. supply plane) cannot spam the alarm every 10 seconds. PRESERVE_RADAR_WARNING_SUPPRESSION is set to 0; the area-based 250-unit radius suppression in tryEvent handles the case of multiple units in the same locale. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f7d680f commit d33fa42

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

Core/GameEngine/Include/Common/GameDefines.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
#endif
6565

6666
#ifndef PRESERVE_RADAR_WARNING_SUPPRESSION
67-
#define PRESERVE_RADAR_WARNING_SUPPRESSION (1)
67+
#define PRESERVE_RADAR_WARNING_SUPPRESSION (0) // Per-object cooldown in tryUnderAttackEvent supersedes this map-wide suppression.
6868
#endif
6969

7070
#ifndef PRESERVE_STRUCTURE_STEALTH_DURING_REPAIR

Core/GameEngine/Include/Common/Radar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class RadarObject : public MemoryPoolObject,
117117
Object *m_object; ///< the object
118118
RadarObject *m_next; ///< next radar object
119119
Color m_color; ///< color to draw for this object on the radar
120+
UnsignedInt m_lastUnderAttackAlarmFrame; ///< last logic frame this object's under-attack alarm fired
120121

121122
};
122123

Core/GameEngine/Source/Common/System/Radar.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ RadarObject::RadarObject()
100100
m_object = nullptr;
101101
m_next = nullptr;
102102
m_color = GameMakeColor( 255, 255, 255, 255 );
103+
m_lastUnderAttackAlarmFrame = 0xFFFFFFFF;
103104

104105
}
105106

@@ -1046,9 +1047,21 @@ void Radar::tryUnderAttackEvent( const Object *obj )
10461047
if( obj == nullptr )
10471048
return;
10481049

1050+
// Per-object cooldown: each unit can alarm at most once per suppression window.
1051+
// This prevents a single object (e.g. a supply plane) from re-triggering the alarm
1052+
// every time the global event window expires.
1053+
const UnsignedInt framesBetweenAlarms = LOGICFRAMES_PER_SECOND * 10;
1054+
UnsignedInt currentFrame = TheGameLogic->getFrame();
1055+
RadarObject *radarData = obj->friend_getRadarData();
1056+
if( radarData && currentFrame - radarData->m_lastUnderAttackAlarmFrame < framesBetweenAlarms )
1057+
return;
1058+
10491059
// try to create the event
10501060
Bool eventCreated = tryEvent( RADAR_EVENT_UNDER_ATTACK, obj->getPosition() );
10511061

1062+
if( eventCreated && radarData )
1063+
radarData->m_lastUnderAttackAlarmFrame = currentFrame;
1064+
10521065
// if event created, do some more feedback
10531066
if( eventCreated )
10541067
{

0 commit comments

Comments
 (0)