@@ -4678,121 +4678,114 @@ setTmpValue(now);
46784678
46794679// ------------------------------------------------------------------------------------------------
46804680// ------------------------------------------------------------------------------------------------
4681- void AIUpdateInterface::evaluateMoraleBonus ( void )
4681+ Bool AIUpdateInterface::hasNationalism () const
46824682{
4683- Object *us = getObject ();
4684- #ifdef ALLOW_DEMORALIZE
4685- Bool demoralized = isDemoralized ();
4686- #endif
4687- Bool horde = FALSE ;
4688- Bool nationalism = FALSE ;
4689- Bool fanaticism = FALSE ;
4690-
4691- // do we have nationalism
4692- // /@todo Find a better way to represent nationalism without hardcoding here (CBD)
4693- static const UpgradeTemplate *nationalismTemplate = TheUpgradeCenter->findUpgrade ( " Upgrade_Nationalism" );
4694- DEBUG_ASSERTCRASH ( nationalismTemplate != NULL , (" AIUpdateInterface::evaluateMoraleBonus - Nationalism upgrade not found" ) );
4695- Player *player = us->getControllingPlayer ();
4696- if ( player && player->hasUpgradeComplete ( nationalismTemplate ) )
4697- nationalism = TRUE ;
4698-
4699- // do we have fanaticism
4700- // /@todo Find a better way to represent fanaticism without hardcoding here (MAL)
4701- static const UpgradeTemplate *fanaticismTemplate = TheUpgradeCenter->findUpgrade ( " Upgrade_Fanaticism" );
4702- DEBUG_ASSERTCRASH ( fanaticismTemplate != NULL , (" AIUpdateInterface::evaluateMoraleBonus - Fanaticism upgrade not found" ) );
4703- if ( player && player->hasUpgradeComplete ( fanaticismTemplate ) )
4704- fanaticism = TRUE ;
4705-
4706- // are we in a horde
4707- HordeUpdateInterface *hui;
4708- for ( BehaviorModule** u = us->getBehaviorModules (); *u; ++u )
4709- {
4710-
4711- hui = (*u)->getHordeUpdateInterface ();
4712- if ( hui && hui->isInHorde () )
4713- {
4714- horde = TRUE ;
4715-
4716- if ( !hui->isAllowedNationalism () )
4717- {
4718- // Sorry CBD and MAL, but the cancer has spread to the lymph nodes. After Alpha, just pump full of painkillers.
4719- nationalism = FALSE ;
4720- fanaticism = FALSE ;
4721- }
4722- }
4683+ if (const Player *player = getObject ()->getControllingPlayer ())
4684+ {
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+ }
47234692
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 );
47244703 }
4704+ return false ;
4705+ }
47254706
4707+ // ------------------------------------------------------------------------------------------------
4708+ // TheSuperHackers @refactor The implementation has been improved and simplified.
4709+ // ------------------------------------------------------------------------------------------------
4710+ void AIUpdateInterface::evaluateMoraleBonus ( Bool inHorde, Bool allowNationalism, HordeActionType type )
4711+ {
47264712#ifdef ALLOW_DEMORALIZE
4727- // if we are are not demoralized we can have horde and nationalism effects
4728- if ( demoralized == FALSE )
4729- # endif
4713+
4714+ // if we are demoralized, then we can not have horde and nationalism effects
4715+ if ( isDemoralized () )
47304716 {
4717+ Object *us = getObject ();
47314718
4732- #ifdef ALLOW_DEMORALIZE
47334719 // demoralized
4734- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_DEMORALIZED );
4735- #endif
4720+ us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_DEMORALIZED );
47364721
4737- // Lorenzen temporarily disabled, since it fights with the horde buff
4738- // Drawable *draw = us->getDrawable( );
4739- // if ( draw && ! us->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
4740- // draw->setTerrainDecal(TERRAIN_DECAL_NONE );
4722+ // we cannot have horde bonuses
4723+ us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
4724+ us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_NATIONALISM );
4725+ us-> clearWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );
47414726
4742- // horde
4743- if ( horde )
4727+ Drawable *draw = us-> getDrawable ();
4728+ if ( draw && !us-> isKindOf ( KINDOF_PORTABLE_STRUCTURE ) )
47444729 {
4745- us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
4746-
4730+ draw->setTerrainDecal (TERRAIN_DECAL_DEMORALIZED);
47474731 }
4748- else
4749- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
4750-
4751- // nationalism
4752- if ( nationalism )
4753- {
4754- us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_NATIONALISM );
4755- // fanaticism
4756- if ( fanaticism )
4757- us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );// FOR THE NEW GC INFANTRY GENERAL
4758- else
4759- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );
4760- }
4761- else
4762- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_NATIONALISM );
47634732
4733+ return ;
4734+ }
4735+
4736+ // demoralized
4737+ us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_DEMORALIZED );
4738+
4739+ #endif // ALLOW_DEMORALIZE
4740+
4741+ // Lorenzen temporarily disabled, since it fights with the horde buff
4742+ // Object *us = getObject();
4743+ // Drawable *draw = us->getDrawable();
4744+ // if ( draw && !us->isKindOf( KINDOF_PORTABLE_STRUCTURE ) )
4745+ // draw->setTerrainDecal(TERRAIN_DECAL_NONE);
47644746
4747+ switch (type)
4748+ {
4749+ case HORDEACTION_HORDE:
4750+ evaluateNationalismBonusClassic (inHorde, allowNationalism);
4751+ break ;
4752+ }
4753+ }
4754+
4755+ // ------------------------------------------------------------------------------------------------
4756+ // TheSuperHackers @info The classic Nationalism Bonus implementation.
4757+ // Is not great, because Nationalism and Fanaticism bonuses are not disabled when leaving the horde.
4758+ // ------------------------------------------------------------------------------------------------
4759+ void AIUpdateInterface::evaluateNationalismBonusClassic ( Bool inHorde, Bool allowNationalism )
4760+ {
4761+ Object *us = getObject ();
47654762
4763+ if ( inHorde )
4764+ {
4765+ us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
47664766 }
4767- #ifdef ALLOW_DEMORALIZE
47684767 else
47694768 {
4769+ us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
4770+ }
47704771
4771- // demoralized
4772- us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_DEMORALIZED );
4772+ if ( allowNationalism && hasNationalism () )
4773+ {
4774+ us->setWeaponBonusCondition ( WEAPONBONUSCONDITION_NATIONALISM );
47734775
4774- // we cannot have horde bonus condition
4775- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_HORDE );
4776- Drawable *draw = us->getDrawable ();
4777- if ( draw && !us->isKindOf ( KINDOF_PORTABLE_STRUCTURE ) )
4776+ if ( hasFanaticism () )
47784777 {
4779- draw-> setTerrainDecal (TERRAIN_DECAL_DEMORALIZED );
4778+ us-> setWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );
47804779 }
4781-
4782- // we cannot have nationalism bonus condition
4780+ else
4781+ {
4782+ us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );
4783+ }
4784+ }
4785+ else
4786+ {
47834787 us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_NATIONALISM );
4784- us->clearWeaponBonusCondition ( WEAPONBONUSCONDITION_FANATICISM );
4785-
47864788 }
4787- #endif
4788-
4789- /*
4790- UnicodeString msg;
4791- msg.format( L"'%S' Horde=%d,Nationalism=%d,Demoralized=%d",
4792- us->getTemplate()->getName().str(), horde, nationalism, demoralized );
4793- TheInGameUI->message( msg );
4794- */
4795-
47964789}
47974790
47984791#ifdef ALLOW_DEMORALIZE
@@ -4809,12 +4802,16 @@ void AIUpdateInterface::setDemoralized( UnsignedInt durationInFrames )
48094802 if ( (prevDemoralizedFrames == 0 && m_demoralizedFramesLeft > 0 ) ||
48104803 (prevDemoralizedFrames > 0 && m_demoralizedFramesLeft == 0 ) )
48114804 {
4812-
48134805 // evaluate demoralization, nationalism, and horde effect as they are all intertwined
4814- evaluateMoraleBonus ();
4815-
4806+ Object *us = getObject ();
4807+ for ( BehaviorModule** u = us->getBehaviorModules (); *u; ++u )
4808+ {
4809+ if ( HordeUpdateInterface *hui = (*u)->getHordeUpdateInterface () )
4810+ {
4811+ evaluateMoraleBonus ( hui->isInHorde (), hui->isAllowedNationalism (), hui->getHordeActionType () );
4812+ }
4813+ }
48164814 }
4817-
48184815}
48194816#endif
48204817
0 commit comments