Fix calculation of morale & luck modifiers for in-castle army without a commander (#5328)

This commit is contained in:
Oleg Derevenetz
2022-04-24 14:32:22 +03:00
committed by GitHub
parent 9f41872fe6
commit bc49f4dfdc
3 changed files with 22 additions and 16 deletions
+18 -2
View File
@@ -985,9 +985,18 @@ int Army::GetLuck( void ) const
return currentCommander != nullptr ? currentCommander->GetLuck() : GetLuckModificator( nullptr );
}
int Army::GetLuckModificator( const std::string * ) const
int Army::GetLuckModificator( std::string * strs ) const
{
return Luck::NORMAL;
int result = Luck::NORMAL;
// check castle modificator
const Castle * castle = inCastle();
if ( castle ) {
result += castle->GetLuckModificator( strs );
}
return result;
}
int Army::GetMorale( void ) const
@@ -1015,6 +1024,13 @@ int Army::GetMoraleModificator( std::string * strs ) const
int result = Morale::NORMAL;
// check castle modificator
const Castle * castle = inCastle();
if ( castle ) {
result += castle->GetMoraleModificator( strs );
}
// artifact "Arm of the Martyr" adds the undead morale penalty
hasUndead = hasUndead || ( GetCommander() && GetCommander()->GetBagArtifacts().isArtifactCursePresent( fheroes2::ArtifactCurseType::UNDEAD_MORALE_PENALTY ) );
+2 -2
View File
@@ -177,8 +177,8 @@ public:
int GetMorale( void ) const;
int GetLuck( void ) const;
int GetMoraleModificator( std::string * ) const;
int GetLuckModificator( const std::string * ) const;
int GetMoraleModificator( std::string * strs ) const;
int GetLuckModificator( std::string * strs ) const;
uint32_t ActionToSirens() const;
const HeroBase * GetCommander( void ) const;
+2 -12
View File
@@ -284,12 +284,7 @@ int HeroBase::GetMoraleModificator( std::string * strs ) const
{
int result = 0;
// check castle modificator
const Castle * castle = inCastle();
if ( castle )
result += castle->GetMoraleModificator( strs );
// army modificator
// army modificator (including the castle modificator)
result += GetArmy().GetMoraleModificator( strs );
if ( strs == nullptr ) {
@@ -316,12 +311,7 @@ int HeroBase::GetLuckModificator( std::string * strs ) const
{
int result = 0;
// check castle modificator
const Castle * castle = inCastle();
if ( castle )
result += castle->GetLuckModificator( strs );
// army modificator
// army modificator (including the castle modificator)
result += GetArmy().GetLuckModificator( strs );
if ( strs == nullptr ) {