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_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;
}

View File

@ -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

View File

@ -2,24 +2,25 @@
#include <algorithm>
// 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;
}
return CALC_ADD_BASE;
}

View File

@ -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

View File

@ -2,31 +2,30 @@
#include <algorithm>
#include <math.h>
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;
}

View File

@ -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

View File

@ -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;
}