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(gameengine): no rank auras in or out of a garrison or transport

Olcay Seygan7ae5ce5f9107
diff --git a/GeneralsMD/Code/Data/Scenarios/rankaura.txt b/GeneralsMD/Code/Data/Scenarios/rankaura.txt
index f012ea789..17fd67840 100644
--- a/GeneralsMD/Code/Data/Scenarios/rankaura.txt
+++ b/GeneralsMD/Code/Data/Scenarios/rankaura.txt
@@ -5,17 +5,31 @@
# the Altay 0.05 and no sight. The Cobra 500 east is out of reach and logs nothing. Each change is
# one "RANK AURA" line in the log. The Kirpi is an ambulance and cannot be ranked.
#
+# Inside anything, no auras either way. An Engineer beside the Altay climbs into the Kirpi before the
+# first pass and logs nothing all run. A Maroon Beret made Albay starts 330 east beside a spotter team
+# and the Cobra (both get its 0.10 at frame 60) and walks to the same Kirpi: beside the Altay it gives
+# the Altay 0.10 (frame 600), and once inside the Altay drops back to the Sungur's 0.05 (frame 960)
+# while the Beret itself holds nothing. The Kirpi, a vehicle outside, takes the Altay's 0.10.
+#
# generals.exe -headless -quickstart -noshellmap -observer -multiInstance -noFPSLimit
# -map "Maps\Twilight Flame\Twilight Flame.map" -autoskirmish 2 -takeover
-# -side 0 FactionTurkiye -side 1 FactionGLA -seed 1 -maxframes 900 -scenario rankaura -logPrefix rankaura_
+# -side 0 FactionTurkiye -side 1 FactionGLA -seed 1 -maxframes 1500 -scenario rankaura -logPrefix rankaura_
10 spawn 0 TurkiyeInfantrySungur 1 3350 3640
10 spawn 0 TurkiyeInfantryMehmetcik 1 3400 3640
10 spawn 0 TurkiyeTankAltay 1 3450 3640
10 spawn 0 TurkiyeVehicleCobra 1 3910 3640
+10 spawn 0 TurkiyeInfantryEngineer 1 3420 3670
+10 spawn 0 TurkiyeVehicleKirpi 1 3440 3690
+10 spawn 0 TurkiyeInfantryMaroonBeret 1 3780 3640
+10 spawn 0 TurkiyeInfantrySpotter 1 3760 3610
10 spawn 1 GLAVehicleTechnical 1 3330 4290
12 rank 0 TurkiyeInfantrySungur grade 10
12 rank 0 TurkiyeTankAltay grade 16
+12 rank 0 TurkiyeInfantryMaroonBeret grade 16
+
+12 enter 0 TurkiyeInfantryEngineer 0 TurkiyeVehicleKirpi
+12 enter 0 TurkiyeInfantryMaroonBeret 0 TurkiyeVehicleKirpi
-400 tally 0 *
+600 tally 0 *
diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
index 7751321a2..1f65f1514 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Object.h
@@ -309,6 +309,7 @@ public:
Bool isSpotter() const; ///< SpotterSight on the template, or the SPOTTER perk
void onRankSightChanged( Real oldScalar ); ///< look again if the rank sight moved
void giveRankRally(); ///< I fell: my death rally reaches the allies around me
+ void forgoRankRally() { m_forgoRankRally = TRUE; } ///< about to be killed inside a container that let go of me first
inline const AsciiString& getName() const { return m_name; }
inline void setName( const AsciiString& newName ) { m_name = newName; }
@@ -812,6 +813,7 @@ private:
Int m_sightJammerCount; ///< enemy jammers in whose field this stands; above zero its sight shrinks to a few feet
Real m_rankAura[ RANK_AURA_COUNT ]; ///< the strongest leader's of each kind, refilled once a second
UnsignedInt m_rankRallyUntil; ///< the frame the death rally on me ends
+ Bool m_forgoRankRally; ///< set and read within one kill, so not saved
DisabledMaskType m_disabledMask;
UnsignedInt m_disabledTillFrame[ DISABLED_COUNT ];
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 555ef97eb..6d6c71523 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1520,7 +1520,7 @@ void InGameUI::updateAuraRings()
{
const Object *obj = draw ? draw->getObject() : NULL;
const RankLadder *ladder = obj ? TheGlobalData->getRankLadder( obj->getTemplate() ) : NULL;
- if( ladder == NULL || local == NULL || obj->isEffectivelyDead()
+ if( ladder == NULL || local == NULL || obj->isEffectivelyDead() || obj->getContainedBy()
|| ( obj->getControllingPlayer() != local && local->getRelationship( obj->getTeam() ) != ALLIES )
|| obj->getShroudedStatus( local->getPlayerIndex() ) != OBJECTSHROUD_CLEAR )
return;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
index 71c046e46..7b22c114c 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Contain/OpenContain.cpp
@@ -488,6 +488,7 @@ void OpenContain::killAllContained( void )
onRemoving( rider );
rider->onRemovedFrom( getObject() );
+ rider->forgoRankRally(); // it dies inside, though no longer counted in
rider->kill();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
index 91d3d2ced..b9d7e32b6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Object.cpp
@@ -310,6 +310,7 @@ Object::Object( const ThingTemplate *tt, const ObjectStatusMaskType &objectStatu
for( Int aura = 0; aura < RANK_AURA_COUNT; ++aura )
m_rankAura[ aura ] = 0.0f;
m_rankRallyUntil = 0;
+ m_forgoRankRally = FALSE;
m_singleUseCommandUsed = false;
@@ -5538,7 +5539,8 @@ Real Object::getRankPerk( RankPerk perk ) const
//-------------------------------------------------------------------------------------------------
Real Object::getRankAura( RankAura aura ) const
{
- if( aura == RANK_AURA_RALLY && TheGameLogic->getFrame() >= m_rankRallyUntil )
+ // nothing reaches a man inside a building, a bunker or a transport, a rally already on him included
+ if( m_containedBy || ( aura == RANK_AURA_RALLY && TheGameLogic->getFrame() >= m_rankRallyUntil ) )
return 0.0f;
return m_rankAura[ aura ];
}
@@ -5601,7 +5603,7 @@ void Object::onRankSightChanged( Real oldScalar )
void Object::giveRankRally()
{
const RankLadder *ladder = TheGlobalData->getRankLadder( getTemplate() );
- if( ladder == NULL )
+ if( ladder == NULL || m_containedBy || m_forgoRankRally ) // one who falls inside a building or a transport rallies nobody
return;
const Int grade = getRankGrade();
const Real strength = ladder->aura( grade, RANK_AURA_RALLY );
@@ -5611,7 +5613,7 @@ void Object::giveRankRally()
const UnsignedInt until = TheGameLogic->getFrame() + TheGlobalData->m_rankRallyTime;
for( Object *other = TheGameLogic->getFirstObject(); other; other = other->getNextObject() )
{
- if( other == this || other->isEffectivelyDead() || other->isKindOf( KINDOF_STRUCTURE )
+ if( other == this || other->isEffectivelyDead() || other->isKindOf( KINDOF_STRUCTURE ) || other->getContainedBy()
|| getRelationship( other ) != ALLIES
|| ThePartitionManager->getDistanceSquared( this, other, FROM_CENTER_2D ) > radius * radius )
continue;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
index 7f0125235..27cce3e0b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogic.cpp
@@ -3932,7 +3932,9 @@ static void updateRankAuras( Object *objList )
for( Object *leader = objList; leader; leader = leader->getNextObject() )
{
const RankLadder *ladder = TheGlobalData->getRankLadder( leader->getTemplate() );
- if( ladder == NULL || leader->isEffectivelyDead() || leader->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) )
+ // a leader inside a building, a bunker or a transport leads nobody and spots nothing
+ if( ladder == NULL || leader->isEffectivelyDead() || leader->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION )
+ || leader->getContainedBy() )
continue;
const Int grade = leader->getRankGrade();
Real strength[ RANK_AURA_PASSED ];
@@ -3950,7 +3952,7 @@ static void updateRankAuras( Object *objList )
const Coord3D *at = leader->getPosition();
for( Object *other = objList; other; other = other->getNextObject() )
{
- if( other == leader || other->isEffectivelyDead() )
+ if( other == leader || other->isEffectivelyDead() || other->getContainedBy() )
continue;
const Real dx = other->getPosition()->x - at->x, dy = other->getPosition()->y - at->y;
const Real distSqr = dx * dx + dy * dy;