Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make default knowledge value for random hero as 1 #8813

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Comment on lines +207 to +208
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also set 1 as the default value for power and knowledge skills then?

};

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