diff --git a/src/boost_atk.cc b/src/boost_atk.cc index 5bb1d48..18da5d9 100644 --- a/src/boost_atk.cc +++ b/src/boost_atk.cc @@ -5,21 +5,21 @@ const int BOOST_ATK = 5; const int BOOST_ATK_DROW = 7; -boost_atk::boost_atk(): - potion{potion_type::boost_atk, -1} {} +boost_atk::boost_atk(const position &pos): + potion{potion_type::boost_atk, -1, pos} {} -void boost_atk::apply(enum race &race, int &HP, int &ATK, int &DEF, - float &base_hit_rate) { - if (remaining_duration > 0) { - if (race == rdrow) - ATK += BOOST_ATK_DROW; - else - ATK += BOOST_ATK; +void boost_atk::apply(const enum race &race, int &HP, int &ATK, int &DEF, + fraction &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + ATK += BOOST_ATK_DROW; + else + ATK += BOOST_ATK; - --remaining_duration; - } + --remaining_duration; + } } int boost_atk::get_priority() const { - return CALC_ADD_BASE; + return CALC_ADD_BASE; } diff --git a/src/boost_atk.h b/src/boost_atk.h index 5145667..bd54e9e 100644 --- a/src/boost_atk.h +++ b/src/boost_atk.h @@ -5,10 +5,10 @@ class boost_atk final: public potion { public: - boost_atk(); - void apply(enum race &race, int &HP, int &ATK, int &DEF, - float &base_hit_rate) override; - int get_priority() const override; + boost_atk(const position &pos); + void apply(const enum race &race, int &HP, int &ATK, int &DEF, + fraction &base_hit_rate) override; + int get_priority() const override; }; #endif diff --git a/src/boost_def.cc b/src/boost_def.cc index 59352f4..d4b1f38 100644 --- a/src/boost_def.cc +++ b/src/boost_def.cc @@ -2,24 +2,25 @@ #include +// TODO: move into class def as static constants const int BOOST_DEF = 5; const int BOOST_DEF_DROW = 7; -boost_def::boost_def(): - potion{potion_type::boost_def, -1} {} +boost_def::boost_def(const position &pos): + potion{potion_type::boost_def, -1, pos} {} -void boost_def::apply(enum race &race, int &HP, int &ATK, int &DEF, - float &base_hit_rate) { - if (remaining_duration > 0) { - if (race == rdrow) - DEF += BOOST_DEF_DROW; - else - DEF += BOOST_DEF; +void boost_def::apply(const enum race &race, int &HP, int &ATK, int &DEF, + fraction &base_hit_rate) { + if (remaining_duration > 0) { + if (race == rdrow) + DEF += BOOST_DEF_DROW; + else + DEF += BOOST_DEF; - --remaining_duration; - } + --remaining_duration; + } } int boost_def::get_priority() const { - return CALC_ADD_BASE; -} \ No newline at end of file + return CALC_ADD_BASE; +} diff --git a/src/boost_def.h b/src/boost_def.h index 09f0608..1a5eb74 100644 --- a/src/boost_def.h +++ b/src/boost_def.h @@ -5,10 +5,10 @@ class boost_def final: public potion { public: - boost_def(); - void apply(enum race &race, int &HP, int &ATK, int &DEF, - float &base_hit_rate) override; - int get_priority() const override; + boost_def(const position &pos); + void apply(const enum race &race, int &HP, int &ATK, int &DEF, + fraction &base_hit_rate) override; + int get_priority() const override; }; #endif diff --git a/src/drow.cc b/src/drow.cc index 7d4090f..6557362 100644 --- a/src/drow.cc +++ b/src/drow.cc @@ -2,31 +2,30 @@ #include #include -drow::drow(RNG &rng, const position_list &available_positions): - character{rng, race::rdrow} { - pos = available_positions[rng.rand_under(available_positions.size())]; - gold = 0; - hostile = true; +drow::drow(RNG *rng, const position &pos): + character{rng, race::rdrow, pos} { + gold = 0; + hostile = true; } result drow::attack(const direction dir, character_list &chlist) { - position tmp{pos + MOVE[dir]}; + position tmp{pos + MOVE[dir]}; - for (auto &ch : chlist) - if (tmp == ch.get_position()) { - return ch.get_hit(race, ATK, base_hit_rate); - } + for (auto &ch : chlist) + if (tmp == ch->get_position()) { + return ch->get_hit(race, ATK, base_hit_rate); + } - return result::fine; + return result::fine; } result drow::get_hit(const enum race &race, const int atk, - const float hitrate) { - if (rng.rand_num() <= hitrate * (float)RAND_MAX) - HP = std::max(HP - calc_dmg(atk, DEF), 0); + const fraction hitrate) { + if (rng->trial(hitrate)) + HP = std::max(HP - calc_dmg(atk, DEF), 0); - if (HP == 0) - return result::died; + if (HP == 0) + return result::died; - return result::hit; + return result::hit; } diff --git a/src/drow.h b/src/drow.h index 35271c9..6e7b39e 100644 --- a/src/drow.h +++ b/src/drow.h @@ -4,12 +4,12 @@ class drow final: public character { public: - drow(RNG &rng, - const position_list &available_positions); - virtual result attack(const direction dir, - character_list &chlist) override; - virtual result get_hit(const enum race &race, const int atk, - const float hit_rate) override; + drow(RNG *rng, + const position &pos); + virtual result attack(const direction dir, + character_list &chlist) override; + virtual result get_hit(const enum race &race, const int atk, + const fraction hit_rate) override; }; #endif diff --git a/src/goblin.cc b/src/goblin.cc index 1e8e87d..9abc4ac 100644 --- a/src/goblin.cc +++ b/src/goblin.cc @@ -9,35 +9,29 @@ goblin::goblin(RNG *rng, const position &pos): } result goblin::attack(const direction dir, character_list &chlist) { - position tmp{pos + MOVE[dir]}; + position tmp{pos + MOVE[dir]}; for (auto &ch : chlist) if (tmp == ch->get_position()) { auto res = ch->get_hit(race, ATK, base_hit_rate); - if (res == result::died) { - gold += GAIN_GOLD; - } + if (res == result::died) { + gold += GAIN_GOLD; + } - return res; - } + return res; + } - return result::fine; + return result::fine; } result goblin::get_hit(const enum race &race, const int atk, -<<<<<<< HEAD - const float hitrate) { - if (rng.rand_num() <= hitrate * (float)RAND_MAX) - HP = std::max(HP - calc_dmg(atk, DEF), 0); -======= const fraction hitrate) { if (rng->trial(hitrate)) HP = std::max(HP - calc_dmg(atk, DEF), 0); ->>>>>>> paul - if (HP == 0) - return result::died; + if (HP == 0) + return result::died; - return result::hit; + return result::hit; }