Skip to content

Commit

Permalink
Make default knowledge value for random hero as 1
Browse files Browse the repository at this point in the history
Also, limit minimum knowledge value to 1 rather than 0.

close #8750
  • Loading branch information
ihhub committed Jun 7, 2024
1 parent 54de91f commit 443105b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/fheroes2/heroes/heroes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ int Heroes::GetAttack() const
int Heroes::GetAttack( std::string * strs ) const
{
int result = attack + GetAttackModificator( strs );
return result < 0 ? 0 : ( result > 255 ? 255 : result );
return std::clamp( result, 0, 255 );
}

int Heroes::GetDefense() const
Expand All @@ -923,7 +923,7 @@ int Heroes::GetDefense() const
int Heroes::GetDefense( std::string * strs ) const
{
int result = defense + GetDefenseModificator( strs );
return result < 0 ? 0 : ( result > 255 ? 255 : result );
return std::clamp( result, 0, 255 );
}

int Heroes::GetPower() const
Expand All @@ -934,7 +934,7 @@ int Heroes::GetPower() const
int Heroes::GetPower( std::string * strs ) const
{
const int result = power + GetPowerModificator( strs );
return result < 1 ? 1 : ( result > 255 ? 255 : result );
return std::clamp( result, 1, 255 );
}

int Heroes::GetKnowledge() const
Expand All @@ -945,7 +945,7 @@ int Heroes::GetKnowledge() const
int Heroes::GetKnowledge( std::string * strs ) const
{
int result = knowledge + GetKnowledgeModificator( strs );
return result < 0 ? 0 : ( result > 255 ? 255 : result );
return std::clamp( result, 1, 255 );
}

void Heroes::IncreasePrimarySkill( int skill )
Expand Down
9 changes: 1 addition & 8 deletions src/fheroes2/heroes/skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ uint32_t Skill::Secondary::GetValues() const
return 0;
}

Skill::Primary::Primary()
: attack( 0 )
, defense( 0 )
, power( 0 )
, knowledge( 0 )
{}

void Skill::Primary::LoadDefaults( int type, int race )
{
const stats_t * ptr = GameStatic::GetSkillStats( race );
Expand Down Expand Up @@ -192,7 +185,7 @@ int Skill::Primary::getHeroDefaultSkillValue( const int skill, const int race )
}
}

return skill == POWER ? 1 : 0;
return ( skill == POWER || skill == KNOWLEDGE ) ? 1 : 0;
}

int Skill::Primary::LevelUp( int race, int level, uint32_t seed )
Expand Down
9 changes: 4 additions & 5 deletions src/fheroes2/heroes/skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ namespace Skill
class Primary
{
public:
Primary();
virtual ~Primary() = default;

enum
Expand Down Expand Up @@ -203,10 +202,10 @@ namespace Skill
friend StreamBase & operator<<( StreamBase &, const Primary & );
friend StreamBase & operator>>( StreamBase &, Primary & );

int attack;
int defense;
int power;
int knowledge;
int attack{ 0 };
int defense{ 0 };
int power{ 0 };
int knowledge{ 0 };
};

StreamBase & operator<<( StreamBase &, const Primary & );
Expand Down

0 comments on commit 443105b

Please sign in to comment.