Skip to content

Commit

Permalink
Improved morale ui when all troops are undead (#9398)
Browse files Browse the repository at this point in the history
  • Loading branch information
felix642 authored Jan 9, 2025
1 parent 0cf0b4d commit 92395ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/fheroes2/army/army.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2024 *
* Copyright (C) 2019 - 2025 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
Expand Down Expand Up @@ -1205,18 +1205,13 @@ int Army::GetMoraleModificator( std::string * strs ) const
// different race penalty
std::set<int> races;
bool hasUndead = false;
bool allUndead = true;

for ( const Troop * troop : *this )
if ( troop->isValid() ) {
races.insert( troop->GetRace() );
hasUndead = hasUndead || troop->isUndead();
allUndead = allUndead && troop->isUndead();
}

if ( allUndead )
return Morale::NORMAL;

int result = Morale::NORMAL;

// check castle modificator
Expand Down
18 changes: 16 additions & 2 deletions src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2024 *
* Copyright (C) 2019 - 2025 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
Expand Down Expand Up @@ -55,6 +55,7 @@
#include "maps_tiles_helper.h"
#include "math_base.h"
#include "mp2.h"
#include "pal.h"
#include "profit.h"
#include "resource.h"
#include "screen.h"
Expand Down Expand Up @@ -760,7 +761,20 @@ namespace
// morale
if ( isFullInfo ) {
const int32_t morale = hero.GetMorale();
const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::MINILKMR, ( 0 > morale ? 3 : ( 0 < morale ? 4 : 5 ) ) );

uint32_t spriteInx = 5;
if ( morale < 0 ) {
spriteInx = 3;
}
else if ( morale > 0 ) {
spriteInx = 4;
}

fheroes2::Sprite sprite = fheroes2::AGG::GetICN( ICN::MINILKMR, spriteInx );
if ( hero.GetArmy().AllTroopsAreUndead() ) {
fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::GRAY ) );
fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::DARKENING ) );
}
uint32_t count = ( 0 == morale ? 1 : std::abs( morale ) );
dst_pt.x = cur_rt.x + 10;
dst_pt.y = cur_rt.y + ( count == 1 ? 20 : 13 );
Expand Down
16 changes: 14 additions & 2 deletions src/fheroes2/heroes/heroes_indicator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2024 *
* Copyright (C) 2019 - 2025 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
Expand Down Expand Up @@ -33,7 +33,9 @@
#include "dialog.h"
#include "heroes.h"
#include "icn.h"
#include "image.h"
#include "localevent.h"
#include "pal.h"
#include "screen.h"
#include "tools.h"
#include "translations.h"
Expand Down Expand Up @@ -149,12 +151,22 @@ void MoraleIndicator::Redraw()
_description.append( modificators );
}

uint32_t spriteInx = 7;
if ( _morale < Morale::NORMAL ) {
spriteInx = 5;
}
else if ( _morale > Morale::NORMAL ) {
spriteInx = 4;
}

fheroes2::Sprite sprite = fheroes2::AGG::GetICN( ICN::HSICONS, spriteInx );
if ( _hero->GetArmy().AllTroopsAreUndead() ) {
_description.append( "\n\n" );
_description.append( _( "Entire army is undead, so morale does not apply." ) );
fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::GRAY ) );
fheroes2::ApplyPalette( sprite, PAL::GetPalette( PAL::PaletteType::DARKENING ) );
}

const fheroes2::Sprite & sprite = fheroes2::AGG::GetICN( ICN::HSICONS, ( 0 > _morale ? 5 : ( 0 < _morale ? 4 : 7 ) ) );
const int32_t inter = 6;
int32_t count = ( 0 == _morale ? 1 : std::abs( _morale ) );
int32_t cx = _area.x + ( _area.width - ( sprite.width() + inter * ( count - 1 ) ) ) / 2;
Expand Down

0 comments on commit 92395ac

Please sign in to comment.