Skip to content

Commit a52e88f

Browse files
committed
Simplify the implementation
1 parent 39008f4 commit a52e88f

File tree

5 files changed

+125
-117
lines changed

5 files changed

+125
-117
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ class Player : public Snapshot
309309
/// return t iff the player has all sciences that are prereqs for knowing the given science
310310
Bool hasPrereqsForScience(ScienceType t) const;
311311

312-
Bool hasUpgradeComplete( const UpgradeTemplate *upgradeTemplate ); ///< does player have totally done and produced upgrade
313-
Bool hasUpgradeComplete( UpgradeMaskType testMask ); ///< does player have totally done and produced upgrade
312+
Bool hasUpgradeComplete( const UpgradeTemplate *upgradeTemplate ) const; ///< does player have totally done and produced upgrade
313+
Bool hasUpgradeComplete( UpgradeMaskType testMask ) const; ///< does player have totally done and produced upgrade
314314
UpgradeMaskType getCompletedUpgradeMask() const { return m_upgradesCompleted; } ///< get list of upgrades that are completed
315315
Bool hasUpgradeInProduction( const UpgradeTemplate *upgradeTemplate ); ///< does player have this upgrade in progress right now
316316
Upgrade *addUpgrade( const UpgradeTemplate *upgradeTemplate,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,11 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
561561
void setAttitude( AttitudeType tude ); ///< set the behavior modifier for this agent
562562

563563
// Common AI "status" effects -------------------------------------------------------------------
564+
Bool hasNationalism() const;
565+
Bool hasFanaticism() const;
564566
void evaluateMoraleBonus( Bool inHorde, Bool allowNationalism, HordeActionType type );
565-
void evaluateMoraleBonusImpl( Bool inHorde, Bool allowNationalism, Bool classicImplementation );
567+
void evaluateNationalismBonusClassic( Bool inHorde, Bool allowNationalism );
568+
void evaluateNationalismBonus( Bool inHorde, Bool allowNationalism );
566569

567570
#ifdef ALLOW_DEMORALIZE
568571
// demoralization ... what a nifty word to write.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ Upgrade *Player::findUpgrade( const UpgradeTemplate *upgradeTemplate )
29902990
//=================================================================================================
29912991
/** Does the player have this completed upgrade */
29922992
//=================================================================================================
2993-
Bool Player::hasUpgradeComplete( const UpgradeTemplate *upgradeTemplate )
2993+
Bool Player::hasUpgradeComplete( const UpgradeTemplate *upgradeTemplate ) const
29942994
{
29952995
UpgradeMaskType testMask = upgradeTemplate->getUpgradeMask();
29962996
return hasUpgradeComplete( testMask );
@@ -3001,7 +3001,7 @@ Bool Player::hasUpgradeComplete( const UpgradeTemplate *upgradeTemplate )
30013001
Does the player have this completed upgrade. This form is exposed so Objects can do quick lookups.
30023002
*/
30033003
//=================================================================================================
3004-
Bool Player::hasUpgradeComplete( UpgradeMaskType testMask )
3004+
Bool Player::hasUpgradeComplete( UpgradeMaskType testMask ) const
30053005
{
30063006
return m_upgradesCompleted.testForAll( testMask );
30073007
}

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

Lines changed: 109 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -4678,110 +4678,42 @@ setTmpValue(now);
46784678

46794679
// ------------------------------------------------------------------------------------------------
46804680
// ------------------------------------------------------------------------------------------------
4681-
void AIUpdateInterface::evaluateMoraleBonusImpl( Bool inHorde, Bool allowNationalism, Bool classicImplementation )
4681+
Bool AIUpdateInterface::hasNationalism() const
46824682
{
4683-
Object *us = getObject();
4684-
4685-
#ifdef ALLOW_DEMORALIZE
4686-
// if we are are not demoralized we can have horde and nationalism effects
4687-
if( !isDemoralized() )
4688-
#endif
4683+
if (const Player *player = getObject()->getControllingPlayer())
46894684
{
4690-
Player *player = us->getControllingPlayer();
4691-
4692-
Bool nationalism;
4693-
Bool fanaticism;
4685+
///@todo Find a better way to represent nationalism without hard coding here (CBD)
4686+
static const UpgradeTemplate *nationalismTemplate = TheUpgradeCenter->findUpgrade( "Upgrade_Nationalism" );
4687+
DEBUG_ASSERTCRASH( nationalismTemplate != NULL, ("AIUpdateInterface::evaluateMoraleBonusImpl - Nationalism upgrade not found") );
4688+
return player->hasUpgradeComplete( nationalismTemplate );
4689+
}
4690+
return false;
4691+
}
46944692

4695-
if (player && allowNationalism)
4696-
{
4697-
// do we have nationalism
4698-
///@todo Find a better way to represent nationalism without hard coding here (CBD)
4699-
static const UpgradeTemplate *nationalismTemplate = TheUpgradeCenter->findUpgrade( "Upgrade_Nationalism" );
4700-
DEBUG_ASSERTCRASH( nationalismTemplate != NULL, ("AIUpdateInterface::evaluateMoraleBonusImpl - Nationalism upgrade not found") );
4701-
nationalism = player->hasUpgradeComplete( nationalismTemplate );
4702-
4703-
// do we have fanaticism
4704-
///@todo Find a better way to represent fanaticism without hard coding here (MAL)
4705-
static const UpgradeTemplate *fanaticismTemplate = TheUpgradeCenter->findUpgrade( "Upgrade_Fanaticism" );
4706-
DEBUG_ASSERTCRASH( fanaticismTemplate != NULL, ("AIUpdateInterface::evaluateMoraleBonusImpl - Fanaticism upgrade not found") );
4707-
fanaticism = player->hasUpgradeComplete( fanaticismTemplate );
4708-
}
4709-
else
4710-
{
4711-
nationalism = FALSE;
4712-
fanaticism = FALSE;
4713-
}
4693+
// ------------------------------------------------------------------------------------------------
4694+
// ------------------------------------------------------------------------------------------------
4695+
Bool AIUpdateInterface::hasFanaticism() const
4696+
{
4697+
if (const Player *player = getObject()->getControllingPlayer())
4698+
{
4699+
///@todo Find a better way to represent fanaticism without hard coding here (MAL)
4700+
static const UpgradeTemplate *fanaticismTemplate = TheUpgradeCenter->findUpgrade( "Upgrade_Fanaticism" );
4701+
DEBUG_ASSERTCRASH( fanaticismTemplate != NULL, ("AIUpdateInterface::evaluateMoraleBonusImpl - Fanaticism upgrade not found") );
4702+
return player->hasUpgradeComplete( fanaticismTemplate );
4703+
}
4704+
return false;
4705+
}
47144706

4707+
// ------------------------------------------------------------------------------------------------
4708+
// ------------------------------------------------------------------------------------------------
4709+
void AIUpdateInterface::evaluateMoraleBonus( Bool inHorde, Bool allowNationalism, HordeActionType type )
4710+
{
47154711
#ifdef ALLOW_DEMORALIZE
4716-
// demoralized
4717-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_DEMORALIZED );
4718-
#endif
4719-
4720-
//Lorenzen temporarily disabled, since it fights with the horde buff
4721-
//Drawable *draw = us->getDrawable();
4722-
//if ( draw && !us->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
4723-
// draw->setTerrainDecal(TERRAIN_DECAL_NONE);
4724-
4725-
if (classicImplementation)
4726-
{
4727-
// TheSuperHackers @info The classic implementation.
4728-
// Is not great, because Nationalism and Fanaticism bonuses are not disabled when leaving the horde.
4729-
4730-
if( inHorde )
4731-
{
4732-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4733-
}
4734-
else
4735-
{
4736-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4737-
}
4738-
4739-
if( nationalism )
4740-
{
4741-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4742-
4743-
if ( fanaticism )
4744-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4745-
else
4746-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4747-
}
4748-
else
4749-
{
4750-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4751-
}
4752-
}
4753-
else
4754-
{
4755-
// TheSuperHackers @bugfix The fixed implementation.
4756-
// Nationalism and Fanaticism are now tied to the horde status.
4757-
// And Fanaticism is no longer dependent on Nationalism.
4758-
4759-
if( inHorde )
4760-
{
4761-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4762-
4763-
if( nationalism )
4764-
{
4765-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4766-
}
47674712

4768-
if( fanaticism )
4769-
{
4770-
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4771-
}
4772-
}
4773-
else
4774-
{
4775-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4776-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4777-
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4778-
}
4779-
}
4780-
4781-
}
4782-
#ifdef ALLOW_DEMORALIZE
4783-
else
4713+
// if we are demoralized, then we can not have horde and nationalism effects
4714+
if( isDemoralized() )
47844715
{
4716+
Object *us = getObject();
47854717

47864718
// demoralized
47874719
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_DEMORALIZED );
@@ -4797,28 +4729,100 @@ void AIUpdateInterface::evaluateMoraleBonusImpl( Bool inHorde, Bool allowNationa
47974729
draw->setTerrainDecal(TERRAIN_DECAL_DEMORALIZED);
47984730
}
47994731

4732+
return;
48004733
}
4801-
#endif
48024734

4803-
}
4735+
// demoralized
4736+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_DEMORALIZED );
4737+
4738+
#endif // ALLOW_DEMORALIZE
4739+
4740+
//Lorenzen temporarily disabled, since it fights with the horde buff
4741+
//Object *us = getObject();
4742+
//Drawable *draw = us->getDrawable();
4743+
//if ( draw && !us->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
4744+
// draw->setTerrainDecal(TERRAIN_DECAL_NONE);
48044745

4805-
// ------------------------------------------------------------------------------------------------
4806-
// ------------------------------------------------------------------------------------------------
4807-
void AIUpdateInterface::evaluateMoraleBonus( Bool inHorde, Bool allowNationalism, HordeActionType type )
4808-
{
48094746
switch (type)
48104747
{
48114748
case HORDEACTION_HORDE:
4812-
evaluateMoraleBonusImpl(inHorde, allowNationalism, TRUE);
4749+
evaluateNationalismBonusClassic(inHorde, allowNationalism);
48134750
break;
48144751

48154752
default:
48164753
case HORDEACTION_HORDE_FIXED:
4817-
evaluateMoraleBonusImpl(inHorde, allowNationalism, FALSE);
4754+
evaluateNationalismBonus(inHorde, allowNationalism);
48184755
break;
48194756
}
48204757
}
48214758

4759+
// ------------------------------------------------------------------------------------------------
4760+
// TheSuperHackers @info The classic Nationalism Bonus implementation.
4761+
// Is not great, because Nationalism and Fanaticism bonuses are not disabled when leaving the horde.
4762+
// ------------------------------------------------------------------------------------------------
4763+
void AIUpdateInterface::evaluateNationalismBonusClassic( Bool inHorde, Bool allowNationalism )
4764+
{
4765+
Object *us = getObject();
4766+
4767+
if( inHorde )
4768+
{
4769+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4770+
}
4771+
else
4772+
{
4773+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4774+
}
4775+
4776+
if( allowNationalism && hasNationalism() )
4777+
{
4778+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4779+
4780+
if ( hasFanaticism() )
4781+
{
4782+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4783+
}
4784+
else
4785+
{
4786+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4787+
}
4788+
}
4789+
else
4790+
{
4791+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4792+
}
4793+
}
4794+
4795+
// ------------------------------------------------------------------------------------------------
4796+
// TheSuperHackers @bugfix The fixed Nationalism Bonus implementation.
4797+
// Nationalism and Fanaticism are now tied to the horde status.
4798+
// And Fanaticism is no longer dependent on Nationalism.
4799+
// ------------------------------------------------------------------------------------------------
4800+
void AIUpdateInterface::evaluateNationalismBonus( Bool inHorde, Bool allowNationalism )
4801+
{
4802+
Object *us = getObject();
4803+
4804+
if( inHorde )
4805+
{
4806+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4807+
4808+
if( allowNationalism && hasNationalism() )
4809+
{
4810+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4811+
}
4812+
4813+
if( allowNationalism && hasFanaticism() )
4814+
{
4815+
us->setWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4816+
}
4817+
}
4818+
else
4819+
{
4820+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_HORDE );
4821+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_NATIONALISM );
4822+
us->clearWeaponBonusCondition( WEAPONBONUSCONDITION_FANATICISM );
4823+
}
4824+
}
4825+
48224826
#ifdef ALLOW_DEMORALIZE
48234827
// ------------------------------------------------------------------------------------------------
48244828
// ------------------------------------------------------------------------------------------------

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,21 @@ Bool HordeUpdate::isAllowedNationalism() const
190190
// ------------------------------------------------------------------------------------------------
191191
void HordeUpdate::joinOrLeaveHorde(SimpleObjectIterator *iter, Bool join)
192192
{
193-
Bool prevInHorde = m_inHorde;
194-
m_inHorde = join;
195-
196-
const HordeUpdateModuleData* md = getHordeUpdateModuleData();
197193
// give/remove bonus effects
198-
if( prevInHorde != m_inHorde )
194+
if( m_inHorde != join )
199195
{
200-
AIUpdateInterface *ai = getObject()->getAIUpdateInterface();
196+
m_inHorde = join;
201197

202-
if( ai )
198+
if( AIUpdateInterface *ai = getObject()->getAIUpdateInterface() )
199+
{
200+
const HordeUpdateModuleData* md = getHordeUpdateModuleData();
203201
ai->evaluateMoraleBonus(m_inHorde, md->m_allowedNationalism, md->m_action);
202+
}
204203
else
204+
{
205205
DEBUG_CRASH(( "HordeUpdate::joinOrLeaveHorde - We (%s) must have an AI to benefit from horde",
206206
getObject()->getTemplate()->getName().str() ));
207+
}
207208
}
208209
}
209210

0 commit comments

Comments
 (0)