work in progress

This commit is contained in:
2024-07-13 16:12:09 -04:00
parent db354d232a
commit 8fad4d262f
7 changed files with 66 additions and 72 deletions

View File

@ -5,21 +5,21 @@
const int BOOST_ATK = 5; const int BOOST_ATK = 5;
const int BOOST_ATK_DROW = 7; const int BOOST_ATK_DROW = 7;
boost_atk::boost_atk(): boost_atk::boost_atk(const position &pos):
potion{potion_type::boost_atk, -1} {} potion{potion_type::boost_atk, -1, pos} {}
void boost_atk::apply(enum race &race, int &HP, int &ATK, int &DEF, void boost_atk::apply(const enum race &race, int &HP, int &ATK, int &DEF,
float &base_hit_rate) { fraction &base_hit_rate) {
if (remaining_duration > 0) { if (remaining_duration > 0) {
if (race == rdrow) if (race == rdrow)
ATK += BOOST_ATK_DROW; ATK += BOOST_ATK_DROW;
else else
ATK += BOOST_ATK; ATK += BOOST_ATK;
--remaining_duration; --remaining_duration;
} }
} }
int boost_atk::get_priority() const { int boost_atk::get_priority() const {
return CALC_ADD_BASE; return CALC_ADD_BASE;
} }

View File

@ -5,10 +5,10 @@
class boost_atk final: public potion { class boost_atk final: public potion {
public: public:
boost_atk(); boost_atk(const position &pos);
void apply(enum race &race, int &HP, int &ATK, int &DEF, void apply(const enum race &race, int &HP, int &ATK, int &DEF,
float &base_hit_rate) override; fraction &base_hit_rate) override;
int get_priority() const override; int get_priority() const override;
}; };
#endif #endif

View File

@ -2,24 +2,25 @@
#include <algorithm> #include <algorithm>
// TODO: move into class def as static constants
const int BOOST_DEF = 5; const int BOOST_DEF = 5;
const int BOOST_DEF_DROW = 7; const int BOOST_DEF_DROW = 7;
boost_def::boost_def(): boost_def::boost_def(const position &pos):
potion{potion_type::boost_def, -1} {} potion{potion_type::boost_def, -1, pos} {}
void boost_def::apply(enum race &race, int &HP, int &ATK, int &DEF, void boost_def::apply(const enum race &race, int &HP, int &ATK, int &DEF,
float &base_hit_rate) { fraction &base_hit_rate) {
if (remaining_duration > 0) { if (remaining_duration > 0) {
if (race == rdrow) if (race == rdrow)
DEF += BOOST_DEF_DROW; DEF += BOOST_DEF_DROW;
else else
DEF += BOOST_DEF; DEF += BOOST_DEF;
--remaining_duration; --remaining_duration;
} }
} }
int boost_def::get_priority() const { int boost_def::get_priority() const {
return CALC_ADD_BASE; return CALC_ADD_BASE;
} }

View File

@ -5,10 +5,10 @@
class boost_def final: public potion { class boost_def final: public potion {
public: public:
boost_def(); boost_def(const position &pos);
void apply(enum race &race, int &HP, int &ATK, int &DEF, void apply(const enum race &race, int &HP, int &ATK, int &DEF,
float &base_hit_rate) override; fraction &base_hit_rate) override;
int get_priority() const override; int get_priority() const override;
}; };
#endif #endif

View File

@ -2,31 +2,30 @@
#include <algorithm> #include <algorithm>
#include <math.h> #include <math.h>
drow::drow(RNG &rng, const position_list &available_positions): drow::drow(RNG *rng, const position &pos):
character{rng, race::rdrow} { character{rng, race::rdrow, pos} {
pos = available_positions[rng.rand_under(available_positions.size())]; gold = 0;
gold = 0; hostile = true;
hostile = true;
} }
result drow::attack(const direction dir, character_list &chlist) { result drow::attack(const direction dir, character_list &chlist) {
position tmp{pos + MOVE[dir]}; position tmp{pos + MOVE[dir]};
for (auto &ch : chlist) for (auto &ch : chlist)
if (tmp == ch.get_position()) { if (tmp == ch->get_position()) {
return ch.get_hit(race, ATK, base_hit_rate); 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, result drow::get_hit(const enum race &race, const int atk,
const float hitrate) { const fraction hitrate) {
if (rng.rand_num() <= hitrate * (float)RAND_MAX) if (rng->trial(hitrate))
HP = std::max(HP - calc_dmg(atk, DEF), 0); HP = std::max(HP - calc_dmg(atk, DEF), 0);
if (HP == 0) if (HP == 0)
return result::died; return result::died;
return result::hit; return result::hit;
} }

View File

@ -4,12 +4,12 @@
class drow final: public character { class drow final: public character {
public: public:
drow(RNG &rng, drow(RNG *rng,
const position_list &available_positions); const position &pos);
virtual result attack(const direction dir, virtual result attack(const direction dir,
character_list &chlist) override; character_list &chlist) override;
virtual result get_hit(const enum race &race, const int atk, virtual result get_hit(const enum race &race, const int atk,
const float hit_rate) override; const fraction hit_rate) override;
}; };
#endif #endif

View File

@ -9,35 +9,29 @@ goblin::goblin(RNG *rng, const position &pos):
} }
result goblin::attack(const direction dir, character_list &chlist) { result goblin::attack(const direction dir, character_list &chlist) {
position tmp{pos + MOVE[dir]}; position tmp{pos + MOVE[dir]};
for (auto &ch : chlist) for (auto &ch : chlist)
if (tmp == ch->get_position()) { if (tmp == ch->get_position()) {
auto res = ch->get_hit(race, ATK, base_hit_rate); auto res = ch->get_hit(race, ATK, base_hit_rate);
if (res == result::died) { if (res == result::died) {
gold += GAIN_GOLD; gold += GAIN_GOLD;
} }
return res; return res;
} }
return result::fine; return result::fine;
} }
result goblin::get_hit(const enum race &race, const int atk, 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) { const fraction hitrate) {
if (rng->trial(hitrate)) if (rng->trial(hitrate))
HP = std::max(HP - calc_dmg(atk, DEF), 0); HP = std::max(HP - calc_dmg(atk, DEF), 0);
>>>>>>> paul
if (HP == 0) if (HP == 0)
return result::died; return result::died;
return result::hit; return result::hit;
} }