Merge branch 'paul' into AL/races-potions
This commit is contained in:
@ -2,10 +2,21 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
character::character(RNG &rng, const enum race &nrace):
|
||||
rng{rng},
|
||||
race{nrace}, HP{STARTING_HP[race]},
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]} {}
|
||||
character::character(RNG *rng, const enum race &nrace, const position &pos):
|
||||
rng{rng}, race{nrace}, HP{STARTING_HP[race]},
|
||||
ATK{STARTING_ATK[race]}, DEF{STARTING_DEF[race]},
|
||||
base_hit_rate{1, 1}, pos{pos} {}
|
||||
|
||||
void character::start_turn() {
|
||||
ATK = STARTING_ATK[race];
|
||||
DEF = STARTING_DEF[race];
|
||||
base_hit_rate = {1, 1};
|
||||
}
|
||||
|
||||
void character::print(display *out, bool color, bool player) {
|
||||
out->print_char(pos, player ? '@' : CHARACTER_REP[race],
|
||||
COLOR_PAIR(COLOR_BLACK_ON_WHITE));
|
||||
}
|
||||
|
||||
enum race character::get_race() const {
|
||||
return race;
|
||||
@ -31,14 +42,26 @@ int character::get_gold() const {
|
||||
return gold;
|
||||
}
|
||||
|
||||
float character::get_hitrate() const {
|
||||
return base_hit_rate;
|
||||
float character::get_hitrate_real() const {
|
||||
return base_hit_rate.real();
|
||||
}
|
||||
|
||||
fraction character::get_hitrate() const {
|
||||
return base_hit_rate;
|
||||
}
|
||||
|
||||
int character::get_room_num() const {
|
||||
return room_num;
|
||||
}
|
||||
|
||||
bool character::is_hostile() const {
|
||||
return hostile;
|
||||
}
|
||||
|
||||
void character::set_room_num(const int room) {
|
||||
room_num = room;
|
||||
}
|
||||
|
||||
void character::set_position(const position &npos) {
|
||||
pos = npos;
|
||||
}
|
||||
@ -59,8 +82,8 @@ void character::set_gold(const int ngold) {
|
||||
gold = ngold;
|
||||
}
|
||||
|
||||
void character::set_hitrate(const float nhitrate) {
|
||||
base_hit_rate = nhitrate;
|
||||
void character::set_hitrate(const fraction nhitrate) {
|
||||
base_hit_rate = nhitrate;
|
||||
}
|
||||
|
||||
void character::set_hostile(const bool is_hostile) {
|
||||
@ -105,27 +128,55 @@ const {
|
||||
return result;
|
||||
}
|
||||
|
||||
result character::apply(direction &dir, const potion_list &potions) {
|
||||
// TODO: implement this after implementing potions
|
||||
return result::fine;
|
||||
void character::apply(direction &dir, potion_list &plist) {
|
||||
for (size_t i = 0; i < plist.size(); ++i)
|
||||
if (pos + MOVE[dir] == plist[i]->get_pos()) {
|
||||
insert_potion(plist[i]);
|
||||
plist.erase(plist.begin() + i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
position_list remove_from_list(const position_list &sorted_positions,
|
||||
position_list excluded) {
|
||||
std::sort(excluded.begin(), excluded.end());
|
||||
void character::insert_potion(potion *p) {
|
||||
effects.push_back(p);
|
||||
|
||||
position_list result{sorted_positions.size() - excluded.size()};
|
||||
for (int i = effects.size() - 1; i > 0; --i)
|
||||
if (p->get_priority() < effects[i - 1]->get_priority())
|
||||
std::swap(effects[i], effects[i - 1]);
|
||||
}
|
||||
|
||||
auto exc = excluded.begin();
|
||||
result character::apply_effects() {
|
||||
potion_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto src : sorted_positions) {
|
||||
if (exc != excluded.end() && src == *exc)
|
||||
++exc;
|
||||
else
|
||||
result.push_back(src);
|
||||
}
|
||||
for (auto p : effects) {
|
||||
p->apply(this->race, HP, ATK, DEF, base_hit_rate);
|
||||
|
||||
return result;
|
||||
if (HP <= 0)
|
||||
return result::died;
|
||||
|
||||
if (p->get_duration() != 0)
|
||||
tmp.push_back(p);
|
||||
}
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
|
||||
std::swap(tmp, effects);
|
||||
|
||||
return result::fine;
|
||||
}
|
||||
|
||||
void character::discard_level_effects() {
|
||||
potion_list tmp;
|
||||
tmp.reserve(effects.size());
|
||||
|
||||
for (auto p : effects)
|
||||
if (p->get_duration() != -1)
|
||||
tmp.push_back(p);
|
||||
|
||||
tmp.shrink_to_fit();
|
||||
|
||||
std::swap(tmp, effects);
|
||||
}
|
||||
|
||||
// IMPORTANT: remember to check if player is on the stairs
|
||||
|
Reference in New Issue
Block a user