Skip to content

Commit

Permalink
Fixes Skill adding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ciplogic committed Sep 8, 2018
1 parent 69b60fd commit e7b57e3
Show file tree
Hide file tree
Showing 35 changed files with 297 additions and 286 deletions.
4 changes: 1 addition & 3 deletions fheroes2.cfg
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
sound = off
sound volume = 1
music = off
music volume = 1
fullscreen = off
videomode = 800x600
videomode = 1024x768
heroes speed = 10
ai speed = 10
battle speed = 10
Binary file modified src/Installer/Installer/fh2enh.zip
Binary file not shown.
10 changes: 5 additions & 5 deletions src/fheroes2/ai/ai_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ void AIToShrine(Heroes& hero, uint32_t obj, s32 dst_index)
// check present spell (skip bag artifacts)
!hero.HaveSpell(spell, true) &&
// check valid level spell and wisdom skill
!(3 == spell_level && Skill::Level::NONE == hero.GetLevelSkill(Skill::Secondary::WISDOM)))
!(3 == spell_level && Skill::Level::NONE == hero.GetLevelSkill(Skill::SkillT::WISDOM)))
{
hero.AppendSpellToBook(spell);
hero.SetVisited(dst_index);
Expand Down Expand Up @@ -1137,7 +1137,7 @@ void AIToArtesianSpring(Heroes& hero, uint32_t obj, s32 dst_index)
void AIToXanadu(Heroes& hero, uint32_t obj, s32 dst_index)
{
const Maps::Tiles& tile = world.GetTiles(dst_index);
const uint32_t level1 = hero.GetLevelSkill(Skill::Secondary::DIPLOMACY);
const uint32_t level1 = hero.GetLevelSkill(Skill::SkillT::DIPLOMACY);
const uint32_t level2 = hero.GetLevel();

if (!hero.isVisited(tile) &&
Expand Down Expand Up @@ -1260,7 +1260,7 @@ void AIToPoorLuckObject(Heroes& hero, uint32_t obj, s32 dst_index)
// check magick book
if (hero.HaveSpellBook() &&
// check skill level for wisdom
Skill::Level::EXPERT == hero.GetLevelSkill(Skill::Secondary::WISDOM))
Skill::Level::EXPERT == hero.GetLevelSkill(Skill::SkillT::WISDOM))
{
hero.AppendSpellToBook(spell);
}
Expand Down Expand Up @@ -1684,7 +1684,7 @@ bool AI::HeroesValidObject(const Heroes& hero, s32 index)
!hero.HaveSpell(spell) &&
// check valid level spell and wisdom skill
!(3 == spell.Level() &&
Skill::Level::NONE == hero.GetLevelSkill(Skill::Secondary::WISDOM)))
Skill::Level::NONE == hero.GetLevelSkill(Skill::SkillT::WISDOM)))
return true;
}
break;
Expand Down Expand Up @@ -1742,7 +1742,7 @@ bool AI::HeroesValidObject(const Heroes& hero, s32 index)

case MP2::OBJ_XANADU:
{
const uint32_t level1 = hero.GetLevelSkill(Skill::Secondary::DIPLOMACY);
const uint32_t level1 = hero.GetLevelSkill(Skill::SkillT::DIPLOMACY);
const uint32_t level2 = hero.GetLevel();

if (!hero.isVisited(tile) &&
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/army/army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,12 +1304,12 @@ JoinCount Army::GetJoinSolution(const Heroes& hero, const Maps::Tiles& tile, con
{
if (join_free || join_force)
return {JOIN_FREE, troop.GetCount()};
if (hero.HasSecondarySkill(Skill::Secondary::DIPLOMACY))
if (hero.HasSecondarySkill(Skill::SkillT::DIPLOMACY))
{
// skill diplomacy
const uint32_t to_join = Monster::GetCountFromHitPoints(troop._monster,
troop.GetHitPointsTroop() *
hero.GetSecondaryValues(Skill::Secondary::DIPLOMACY)
hero.GetSecondaryValues(Skill::SkillT::DIPLOMACY)
/
100);

Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/battle/battle_arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ uint32_t Battle::Arena::GetObstaclesPenalty(const Unit& attacker, const Unit& de
if (castle)
{
// archery skill
if (enemy && Skill::Level::NONE != enemy->GetLevelSkill(Skill::Secondary::ARCHERY)) return 0;
if (enemy && Skill::Level::NONE != enemy->GetLevelSkill(Skill::SkillT::ARCHERY)) return 0;

// attacker is castle owner
if (attacker.GetColor() == castle->GetColor() &&
Expand Down Expand Up @@ -1153,7 +1153,7 @@ uint32_t Battle::Arena::GetObstaclesPenalty(const Unit& attacker, const Unit& de

if (enemy)
{
switch (enemy->GetLevelSkill(Skill::Secondary::ARCHERY))
switch (enemy->GetLevelSkill(Skill::SkillT::ARCHERY))
{
case Skill::Level::BASIC:
if (result < 2) return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/battle/battle_army.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ uint32_t Battle::Force::GetSurrenderCost() const

if (commander)
{
switch (commander->GetLevelSkill(Skill::Secondary::DIPLOMACY))
switch (commander->GetLevelSkill(Skill::SkillT::DIPLOMACY))
{
// 40%
case Skill::Level::BASIC:
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/battle/battle_catapult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
Battle::Catapult::Catapult(const HeroBase& hero, bool fortification) : cat_shots(1), cat_first(20),
cat_miss(true) /*, cat_fort(fortification) */
{
switch (hero.GetLevelSkill(Skill::Secondary::BALLISTICS))
switch (hero.GetLevelSkill(Skill::SkillT::BALLISTICS))
{
case Skill::Level::BASIC:
cat_first = 40;
Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/battle/battle_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ Battle::Result Battle::Loader(Army& army1, Army& army2, s32 mapsindex)

// eagle eye capability
if (hero_wins && hero_loss &&
hero_wins->GetLevelSkill(Skill::Secondary::EAGLEEYE) &&
hero_wins->GetLevelSkill(Skill::SkillT::EAGLEEYE) &&
hero_loss->isHeroes())
EagleEyeSkillAction(*hero_wins, arena.GetUsageSpells(), hero_wins->isControlHuman());

// necromancy capability
if (hero_wins &&
hero_wins->GetLevelSkill(Skill::Secondary::NECROMANCY))
hero_wins->GetLevelSkill(Skill::SkillT::NECROMANCY))
NecromancySkillAction(*hero_wins, result.killed, hero_wins->isControlHuman());


Expand Down Expand Up @@ -197,7 +197,7 @@ void Battle::EagleEyeSkillAction(HeroBase& hero, const SpellStorage& spells, boo
SpellStorage new_spells;
new_spells._items.reserve(10);

const Skill::Secondary eagleeye(Skill::Secondary::EAGLEEYE, hero.GetLevelSkill(Skill::Secondary::EAGLEEYE));
const Skill::Secondary eagleeye(Skill::SkillT::EAGLEEYE, hero.GetLevelSkill(Skill::SkillT::EAGLEEYE));

// filter spells
for (auto sp : spells._items)
Expand Down Expand Up @@ -257,7 +257,7 @@ void Battle::NecromancySkillAction(HeroBase& hero, uint32_t killed, bool local)
// fix over 60%
if (percent > 60) percent = 60;

percent += hero.GetSecondaryValues(Skill::Secondary::NECROMANCY);
percent += hero.GetSecondaryValues(Skill::SkillT::NECROMANCY);

// hard fix overflow
if (percent > 90) percent = 90;
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/battle/battle_troop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ uint32_t Battle::Unit::CalculateDamageUnit(const Unit& enemy, double dmg) const
// check skill archery +%10, +%25, +%50
if (GetCommander())
{
dmg += dmg * GetCommander()->GetSecondaryValues(Skill::Secondary::ARCHERY) / 100;
dmg += dmg * GetCommander()->GetSecondaryValues(Skill::SkillT::ARCHERY) / 100;
}

// check castle defense
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/castle/captain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ int Captain::GetType() const
return CAPTAIN;
}

int Captain::GetLevelSkill(int) const
int Captain::GetLevelSkill(Skill::SkillT) const
{
return 0;
}

uint32_t Captain::GetSecondaryValues(int) const
uint32_t Captain::GetSecondaryValues(Skill::SkillT) const
{
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/castle/captain.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ class Captain : public HeroBase

const Castle* inCastle() const;

int GetLevelSkill(int) const;
int GetLevelSkill(Skill::SkillT) const override;

uint32_t GetSecondaryValues(int) const;
uint32_t GetSecondaryValues(Skill::SkillT) const;

const Army& GetArmy() const;

Expand Down
3 changes: 2 additions & 1 deletion src/fheroes2/dialog/dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <string>
#include "gamedefs.h"
#include "sprites.h"
#include "skill.h"

#define SHADOWWIDTH 16
#define BOXAREA_WIDTH 245
Expand Down Expand Up @@ -106,7 +107,7 @@ namespace Dialog

void ExtSettings(bool);

int LevelUpSelectSkill(const std::string&, const std::string&, const Skill::Secondary&, const Skill::Secondary&,
Skill::SkillT LevelUpSelectSkill(const std::string&, const std::string&, const Skill::Secondary&, const Skill::Secondary&,
Heroes&);

bool SelectGoldOrExp(const std::string&, const std::string&, uint32_t gold, uint32_t expr, const Heroes&);
Expand Down
16 changes: 8 additions & 8 deletions src/fheroes2/dialog/dialog_levelup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void DialogPrimaryOnly(const string& name, const string& primary)
Message("", message, Font::BIG, Dialog::OK);
}

int DialogOneSecondary(const string& name, const string& primary, const Skill::Secondary& sec)
Skill::SkillT DialogOneSecondary(const string& name, const string& primary, const Skill::Secondary& sec)
{
string message = _("%{name} has gained a level.");
message.append("\n \n");
Expand Down Expand Up @@ -69,7 +69,7 @@ int DialogOneSecondary(const string& name, const string& primary, const Skill::S
return sec.Skill();
}

int DialogSelectSecondary(const string& name, const string& primary, const Skill::Secondary& sec1,
Skill::SkillT DialogSelectSecondary(const string& name, const string& primary, const Skill::Secondary& sec1,
const Skill::Secondary& sec2, Heroes& hero)
{
string header = _("%{name} has gained a level.");
Expand Down Expand Up @@ -213,18 +213,18 @@ int DialogSelectSecondary(const string& name, const string& primary, const Skill
}

cursor.Hide();
return Skill::Secondary::UNKNOWN;
return Skill::SkillT::UNKNOWN;
}

int Dialog::LevelUpSelectSkill(const string& name, const string& primary, const Skill::Secondary& sec1,
Skill::SkillT Dialog::LevelUpSelectSkill(const string& name, const string& primary, const Skill::Secondary& sec1,
const Skill::Secondary& sec2, Heroes& hero)
{
int result = Skill::Secondary::UNKNOWN;
Skill::SkillT result = Skill::SkillT::UNKNOWN;

if (Skill::Secondary::UNKNOWN == sec1.Skill() && Skill::Secondary::UNKNOWN == sec2.Skill())
if (Skill::SkillT::UNKNOWN == sec1.Skill() && Skill::SkillT::UNKNOWN == sec2.Skill())
DialogPrimaryOnly(name, primary);
else if (Skill::Secondary::UNKNOWN == sec1.Skill() || Skill::Secondary::UNKNOWN == sec2.Skill())
result = DialogOneSecondary(name, primary, Skill::Secondary::UNKNOWN == sec2.Skill() ? sec1 : sec2);
else if (Skill::SkillT::UNKNOWN == sec1.Skill() || Skill::SkillT::UNKNOWN == sec2.Skill())
result = DialogOneSecondary(name, primary, Skill::SkillT::UNKNOWN == sec2.Skill() ? sec1 : sec2);
else
result = DialogSelectSecondary(name, primary, sec1, sec2, hero);

Expand Down
8 changes: 4 additions & 4 deletions src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ string ShowGroundInfo(const Maps::Tiles& tile, bool show, const Heroes* hero)
if (!(dir != Direction::UNKNOWN))
return str;
uint32_t cost = Maps::Ground::GetPenalty(tile.GetIndex(), Direction::Reflect(dir),
hero->GetLevelSkill(Skill::Secondary::PATHFINDING));
hero->GetLevelSkill(Skill::SkillT::PATHFINDING));
if (cost)
{
str.append("\n");
Expand Down Expand Up @@ -675,7 +675,7 @@ void Dialog::QuickInfo(const Castle& castle)
(castle.isFriends(conf.CurrentColor()) ||
// show guardians (scouting: advanced)
from_hero &&
Skill::Level::ADVANCED <= from_hero->GetSecondaryValues(Skill::Secondary::SCOUTING)))
Skill::Level::ADVANCED <= from_hero->GetSecondaryValues(Skill::SkillT::SCOUTING)))
{
// heroes name
text.Set(guardian->GetName(), Font::SMALL);
Expand Down Expand Up @@ -708,7 +708,7 @@ void Dialog::QuickInfo(const Castle& castle)
// show limited
Army::DrawMons32LineWithScoute(castle.GetArmy().m_troops, cur_rt.x - 5, cur_rt.y + 100, 192, 0, 0,
from_hero && from_hero->CanScouteTile(castle.GetIndex())
? from_hero->GetSecondaryValues(Skill::Secondary::SCOUTING)
? from_hero->GetSecondaryValues(Skill::SkillT::SCOUTING)
: Skill::Level::NONE);

cursor.Show();
Expand Down Expand Up @@ -940,7 +940,7 @@ void Dialog::QuickInfo(const Heroes& hero)
// show limited
Army::DrawMons32LineWithScoute(hero.GetArmy().m_troops, cur_rt.x - 5, cur_rt.y + 114, 160, 0, 0,
from_hero && from_hero->CanScouteTile(hero.GetIndex())
? from_hero->GetSecondaryValues(Skill::Secondary::SCOUTING)
? from_hero->GetSecondaryValues(Skill::SkillT::SCOUTING)
: Skill::Level::NONE);

cursor.Show();
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/dialog/dialog_selectitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class SelectEnumSecSkill : public SelectEnum

void RedrawItem(const int& index, s32 dstx, s32 dsty, bool current)
{
Skill::Secondary skill(1 + index / 3, 1 + index % 3);
Skill::Secondary skill(static_cast < Skill::SkillT>(1 + index / 3), 1 + index % 3);
AGG::GetICN(ICN::MINISS, skill.GetIndexSprite2()).Blit(dstx + 5, dsty + 3);
string str = skill.GetName();
Text text(str, (current ? Font::YELLOW_BIG : Font::BIG));
Expand Down Expand Up @@ -269,7 +269,7 @@ Skill::Secondary Dialog::SelectSecondarySkill()

if (result == OK || listbox.ok)
{
skill.SetSkill(1 + listbox.GetCurrent() / 3);
skill.SetSkill(static_cast<Skill::SkillT>(1 + listbox.GetCurrent() / 3));
skill.SetLevel(1 + listbox.GetCurrent() % 3);
}

Expand Down
30 changes: 15 additions & 15 deletions src/fheroes2/game/game_static.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,37 +460,37 @@ const Skill::stats_t* GameStatic::GetSkillStats(int race)
return nullptr;
}

const Skill::values_t* GameStatic::GetSkillValues(int type)
const Skill::values_t* GameStatic::GetSkillValues(Skill::SkillT type)
{
switch (type)
{
case Skill::Secondary::PATHFINDING:
case Skill::SkillT::PATHFINDING:
return &Skill::_values[0];
case Skill::Secondary::ARCHERY:
case Skill::SkillT::ARCHERY:
return &Skill::_values[1];
case Skill::Secondary::LOGISTICS:
case Skill::SkillT::LOGISTICS:
return &Skill::_values[2];
case Skill::Secondary::SCOUTING:
case Skill::SkillT::SCOUTING:
return &Skill::_values[3];
case Skill::Secondary::DIPLOMACY:
case Skill::SkillT::DIPLOMACY:
return &Skill::_values[4];
case Skill::Secondary::NAVIGATION:
case Skill::SkillT::NAVIGATION:
return &Skill::_values[5];
case Skill::Secondary::LEADERSHIP:
case Skill::SkillT::LEADERSHIP:
return &Skill::_values[6];
case Skill::Secondary::WISDOM:
case Skill::SkillT::WISDOM:
return &Skill::_values[7];
case Skill::Secondary::MYSTICISM:
case Skill::SkillT::MYSTICISM:
return &Skill::_values[8];
case Skill::Secondary::LUCK:
case Skill::SkillT::LUCK:
return &Skill::_values[9];
case Skill::Secondary::BALLISTICS:
case Skill::SkillT::BALLISTICS:
return &Skill::_values[10];
case Skill::Secondary::EAGLEEYE:
case Skill::SkillT::EAGLEEYE:
return &Skill::_values[11];
case Skill::Secondary::NECROMANCY:
case Skill::SkillT::NECROMANCY:
return &Skill::_values[12];
case Skill::Secondary::ESTATES:
case Skill::SkillT::ESTATES:
return &Skill::_values[13];
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion src/fheroes2/game/game_static.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace GameStatic

const Skill::stats_t* GetSkillStats(int race);

const Skill::values_t* GetSkillValues(int skill);
const Skill::values_t* GetSkillValues(Skill::SkillT skill);

const Skill::secondary_t* GetSkillForWitchsHut();

Expand Down
3 changes: 1 addition & 2 deletions src/fheroes2/gui/interface_gamearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ void Interface::GameArea::DrawHeroRoute(Surface& dst, int flag, const Rect& rt)
: Route::Path::GetIndexSprite((*it1).GetDirection(), (*it3).GetDirection(),
Maps::Ground::GetPenalty(from, Direction::CENTER,
hero->GetLevelSkill(
Skill::Secondary::
PATHFINDING)));
Skill::SkillT::PATHFINDING)));

Sprite sprite = AGG::GetICN(0 > green ? ICN::ROUTERED : ICN::ROUTE, index);
sprite.SetAlphaMod(180);
Expand Down
3 changes: 2 additions & 1 deletion src/fheroes2/heroes/direction.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#include <string>
#include <vector>

#include "gamedefs.h"
#include "engine.h"


typedef std::vector<int> Directions;

Expand Down
Loading

0 comments on commit e7b57e3

Please sign in to comment.