Skip to content

Commit 637dbba

Browse files
authored
bugfix(battleplan): Battle plans are now transferred to the new owner on capture (#2257)
1 parent 8456e12 commit 637dbba

File tree

8 files changed

+48
-24
lines changed

8 files changed

+48
-24
lines changed

Generals/Code/GameEngine/Include/Common/Player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class Player : public Snapshot
345345
//it's possible for multiple strategy centers to have the same plan, so we need
346346
//to keep track of that like radar. Keep in mind multiple strategy centers with
347347
//same plan do not stack, but different strategy centers with different plans do.
348-
void changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonusesData *bonus );
348+
void changeBattlePlan( BattlePlanStatus plan, Int delta, const BattlePlanBonusesData *bonus );
349349
Int getNumBattlePlansActive() const { return m_bombardBattlePlans + m_holdTheLineBattlePlans + m_searchAndDestroyBattlePlans; }
350350
Int getBattlePlansActiveSpecific( BattlePlanStatus plan ) const;
351351
void applyBattlePlanBonusesForObject( Object *obj ) const; //New object or converted object gaining our current battle plan bonuses.

Generals/Code/GameEngine/Include/GameLogic/Module/BattlePlanUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class BattlePlanUpdate : public UpdateModule, public SpecialPowerUpdateInterface
162162
virtual void onObjectCreated() override;
163163
virtual void onDelete() override;
164164
virtual UpdateSleepTime update() override;
165+
virtual void onCapture(Player* oldOwner, Player* newOwner) override;
165166

166167
virtual CommandOption getCommandOption() const override;
167168
protected:

Generals/Code/GameEngine/Source/Common/RTS/Player.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,8 +2921,7 @@ Bool Player::doesObjectQualifyForBattlePlan( Object *obj ) const
29212921
}
29222922

29232923
//-------------------------------------------------------------------------------------------------
2924-
// note, bonus is an in-out parm.
2925-
void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonusesData *bonus )
2924+
void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, const BattlePlanBonusesData *bonus )
29262925
{
29272926
DUMPBATTLEPLANBONUSES(bonus, this, nullptr);
29282927
Bool addBonus = false;
@@ -2976,22 +2975,24 @@ void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonus
29762975
else if( removeBonus )
29772976
{
29782977
//First, inverse the bonuses
2979-
bonus->m_armorScalar = 1.0f / __max( bonus->m_armorScalar, 0.01f );
2980-
bonus->m_sightRangeScalar = 1.0f / __max( bonus->m_sightRangeScalar, 0.01f );
2981-
if( bonus->m_bombardment > 0 )
2978+
BattlePlanBonusesData invertedBonus = *bonus;
2979+
2980+
invertedBonus.m_armorScalar = 1.0f / __max(bonus->m_armorScalar, 0.01f);
2981+
invertedBonus.m_sightRangeScalar = 1.0f / __max(bonus->m_sightRangeScalar, 0.01f);
2982+
if (invertedBonus.m_bombardment > 0)
29822983
{
2983-
bonus->m_bombardment = -1;
2984+
invertedBonus.m_bombardment = -1;
29842985
}
2985-
if( bonus->m_holdTheLine > 0 )
2986+
if (invertedBonus.m_holdTheLine > 0)
29862987
{
2987-
bonus->m_holdTheLine = -1;
2988+
invertedBonus.m_holdTheLine = -1;
29882989
}
2989-
if( bonus->m_searchAndDestroy > 0 )
2990+
if (invertedBonus.m_searchAndDestroy > 0)
29902991
{
2991-
bonus->m_searchAndDestroy = -1;
2992+
invertedBonus.m_searchAndDestroy = -1;
29922993
}
29932994

2994-
applyBattlePlanBonusesForPlayerObjects( bonus );
2995+
applyBattlePlanBonusesForPlayerObjects(&invertedBonus);
29952996
}
29962997
}
29972998

Generals/Code/GameEngine/Source/GameLogic/Object/Update/BattlePlanUpdate.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ void BattlePlanUpdate::onObjectCreated()
247247
enableTurret( false );
248248
}
249249

250+
//-------------------------------------------------------------------------------------------------
251+
void BattlePlanUpdate::onCapture(Player* oldOwner, Player* newOwner)
252+
{
253+
#if !RETAIL_COMPATIBLE_CRC
254+
// TheSuperHackers @bugfix Stubbjax 04/11/2025 Transfer battle plan bonuses on capture.
255+
oldOwner->changeBattlePlan(m_planAffectingArmy, -1, m_bonuses);
256+
newOwner->changeBattlePlan(m_planAffectingArmy, 1, m_bonuses);
257+
#endif
258+
}
259+
250260
//-------------------------------------------------------------------------------------------------
251261
Bool BattlePlanUpdate::initiateIntentToDoSpecialPower(const SpecialPowerTemplate *specialPowerTemplate, const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions )
252262
{

GeneralsMD/Code/GameEngine/Include/Common/Player.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ class Player : public Snapshot
369369
//it's possible for multiple strategy centers to have the same plan, so we need
370370
//to keep track of that like radar. Keep in mind multiple strategy centers with
371371
//same plan do not stack, but different strategy centers with different plans do.
372-
void changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonusesData *bonus );
372+
void changeBattlePlan( BattlePlanStatus plan, Int delta, const BattlePlanBonusesData *bonus );
373373
Int getNumBattlePlansActive() const { return m_bombardBattlePlans + m_holdTheLineBattlePlans + m_searchAndDestroyBattlePlans; }
374374
Int getBattlePlansActiveSpecific( BattlePlanStatus plan ) const;
375375
void applyBattlePlanBonusesForObject( Object *obj ) const; //New object or converted object gaining our current battle plan bonuses.

GeneralsMD/Code/GameEngine/Include/GameLogic/Module/BattlePlanUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class BattlePlanUpdate : public SpecialPowerUpdateModule
162162
virtual void onObjectCreated() override;
163163
virtual void onDelete() override;
164164
virtual UpdateSleepTime update() override;
165+
virtual void onCapture(Player* oldOwner, Player* newOwner) override;
165166

166167
virtual CommandOption getCommandOption() const override;
167168
protected:

GeneralsMD/Code/GameEngine/Source/Common/RTS/Player.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,8 +3414,7 @@ Bool Player::doesObjectQualifyForBattlePlan( Object *obj ) const
34143414
}
34153415

34163416
//-------------------------------------------------------------------------------------------------
3417-
// note, bonus is an in-out parm.
3418-
void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonusesData *bonus )
3417+
void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, const BattlePlanBonusesData *bonus )
34193418
{
34203419
DUMPBATTLEPLANBONUSES(bonus, this, nullptr);
34213420
Bool addBonus = false;
@@ -3469,22 +3468,24 @@ void Player::changeBattlePlan( BattlePlanStatus plan, Int delta, BattlePlanBonus
34693468
else if( removeBonus )
34703469
{
34713470
//First, inverse the bonuses
3472-
bonus->m_armorScalar = 1.0f / __max( bonus->m_armorScalar, 0.01f );
3473-
bonus->m_sightRangeScalar = 1.0f / __max( bonus->m_sightRangeScalar, 0.01f );
3474-
if( bonus->m_bombardment > 0 )
3471+
BattlePlanBonusesData invertedBonus = *bonus;
3472+
3473+
invertedBonus.m_armorScalar = 1.0f / __max(bonus->m_armorScalar, 0.01f);
3474+
invertedBonus.m_sightRangeScalar = 1.0f / __max(bonus->m_sightRangeScalar, 0.01f);
3475+
if (invertedBonus.m_bombardment > 0)
34753476
{
3476-
bonus->m_bombardment = -1;
3477+
invertedBonus.m_bombardment = -1;
34773478
}
3478-
if( bonus->m_holdTheLine > 0 )
3479+
if (invertedBonus.m_holdTheLine > 0)
34793480
{
3480-
bonus->m_holdTheLine = -1;
3481+
invertedBonus.m_holdTheLine = -1;
34813482
}
3482-
if( bonus->m_searchAndDestroy > 0 )
3483+
if (invertedBonus.m_searchAndDestroy > 0)
34833484
{
3484-
bonus->m_searchAndDestroy = -1;
3485+
invertedBonus.m_searchAndDestroy = -1;
34853486
}
34863487

3487-
applyBattlePlanBonusesForPlayerObjects( bonus );
3488+
applyBattlePlanBonusesForPlayerObjects(&invertedBonus);
34883489
}
34893490
}
34903491

GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/BattlePlanUpdate.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,16 @@ void BattlePlanUpdate::onObjectCreated()
247247
enableTurret( false );
248248
}
249249

250+
//-------------------------------------------------------------------------------------------------
251+
void BattlePlanUpdate::onCapture(Player* oldOwner, Player* newOwner)
252+
{
253+
#if !RETAIL_COMPATIBLE_CRC
254+
// TheSuperHackers @bugfix Stubbjax 04/11/2025 Transfer battle plan bonuses on capture.
255+
oldOwner->changeBattlePlan(m_planAffectingArmy, -1, m_bonuses);
256+
newOwner->changeBattlePlan(m_planAffectingArmy, 1, m_bonuses);
257+
#endif
258+
}
259+
250260
//-------------------------------------------------------------------------------------------------
251261
Bool BattlePlanUpdate::initiateIntentToDoSpecialPower(const SpecialPowerTemplate *specialPowerTemplate, const Object *targetObj, const Coord3D *targetPos, const Waypoint *way, UnsignedInt commandOptions )
252262
{

0 commit comments

Comments
 (0)