moved shade into a seperate file
This commit is contained in:
34
src/shade.cc
Normal file
34
src/shade.cc
Normal file
@ -0,0 +1,34 @@
|
||||
#include "shade.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <math.h>
|
||||
|
||||
shade::shade(const position_list &available_positions):
|
||||
character{race::rshade} {
|
||||
pos = available_positions[rng.rand_under(available_positions.size())];
|
||||
gold = 0;
|
||||
hostile = true;
|
||||
}
|
||||
|
||||
result shade::attack(const direction dir, character_list &chlist) {
|
||||
position tmp{pos + MOVE[dir]};
|
||||
|
||||
for (auto &ch : chlist)
|
||||
if (tmp == ch.get_position()) {
|
||||
return ch.get_hit(race, ATK, base_hit_rate);
|
||||
}
|
||||
|
||||
return result::fine;
|
||||
}
|
||||
|
||||
result shade::get_hit(const enum race &race, const int atk,
|
||||
const float hitrate) {
|
||||
if (rng.rand_num() <= hitrate * (float)RAND_MAX) // This is a hit!
|
||||
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
||||
|
||||
if (HP == 0)
|
||||
return result::died;
|
||||
|
||||
return result::hit;
|
||||
}
|
||||
|
Reference in New Issue
Block a user