added troll class, cleaned up shade, vampire, and goblin classes
This commit is contained in:
@ -33,7 +33,9 @@ enum stat_name {HP, ATK, DEF, hostile};
|
|||||||
|
|
||||||
const int RACE_CNT = 5; // TODO: update as you go
|
const int RACE_CNT = 5; // TODO: update as you go
|
||||||
|
|
||||||
enum race {rshade = 0, rvampire, rgoblin, rdrow, rdragon /* TODO: fill out the other races (including enemies) */};
|
// TODO: Update races as you go
|
||||||
|
// PC races [x], Enemy races [x], other? [ ]
|
||||||
|
enum race {rshade = 0, rdrow, rvampire, rtroll, rgoblin, rhuman, rdwarf, relf, rorc, rmerchant, rdragon, rhalfling};
|
||||||
|
|
||||||
// TODO: fill out the other races (including enemies)
|
// TODO: fill out the other races (including enemies)
|
||||||
const int MAX_HP[RACE_CNT] = {125, INF, 110, 150, 150};
|
const int MAX_HP[RACE_CNT] = {125, INF, 110, 150, 150};
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#include "goblin.h"
|
#include "goblin.h"
|
||||||
#include <algorithm>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
goblin::goblin(RNG *rng, const position &pos):
|
goblin::goblin(RNG *rng, const position &pos):
|
||||||
character{rng, race::rshade, pos} {
|
character{rng, race::rgoblin, pos} {
|
||||||
gold = 0;
|
gold = 0;
|
||||||
hostile = true;
|
hostile = true;
|
||||||
}
|
}
|
||||||
@ -27,7 +25,7 @@ result goblin::attack(const direction dir, character_list &chlist) {
|
|||||||
|
|
||||||
result goblin::get_hit(const enum race &race, const int atk,
|
result goblin::get_hit(const enum race &race, const int atk,
|
||||||
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);
|
||||||
|
|
||||||
if (HP == 0)
|
if (HP == 0)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef __GOBLIN_H__
|
#ifndef __GOBLIN_H__
|
||||||
#define __GOBLIN_H__
|
#define __GOBLIN_H__
|
||||||
|
|
||||||
#include "characters.h"
|
#include "characters.h"
|
||||||
|
|
||||||
class goblin final: public character {
|
class goblin final: public character {
|
||||||
|
@ -2,8 +2,9 @@
|
|||||||
#define __RACES_H__
|
#define __RACES_H__
|
||||||
|
|
||||||
#include "shade.h"
|
#include "shade.h"
|
||||||
#include "goblin.h"
|
|
||||||
#include "vampire.h"
|
#include "vampire.h"
|
||||||
|
#include "troll.h"
|
||||||
|
#include "goblin.h"
|
||||||
#include "dragon.h"
|
#include "dragon.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
#include "shade.h"
|
#include "shade.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
shade::shade(RNG *rng, const position &pos):
|
shade::shade(RNG *rng, const position &pos):
|
||||||
character{rng, race::rshade, pos} {
|
character{rng, race::rshade, pos} {
|
||||||
gold = 0;
|
gold = 0;
|
||||||
|
36
src/troll.cc
Normal file
36
src/troll.cc
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "troll.h"
|
||||||
|
|
||||||
|
troll::troll(RNG *rng, const position &pos):
|
||||||
|
character{rng, race::rtroll, pos} {
|
||||||
|
gold = 0;
|
||||||
|
hostile = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
result troll::attack(const direction dir, character_list &chlist) {
|
||||||
|
position tmp{pos + MOVE[dir]};
|
||||||
|
|
||||||
|
if (HP + REGAIN_HP > HP_CAP) {
|
||||||
|
HP = HP_CAP;
|
||||||
|
} else {
|
||||||
|
HP += REGAIN_HP;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &ch : chlist)
|
||||||
|
if (tmp == ch->get_position()) {
|
||||||
|
auto res = ch->get_hit(race, ATK, base_hit_rate);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result::fine;
|
||||||
|
}
|
||||||
|
|
||||||
|
result troll::get_hit(const enum race &race, const int atk,
|
||||||
|
const fraction hitrate) {
|
||||||
|
if (rng->trial(hitrate))
|
||||||
|
HP = std::max(HP - calc_dmg(atk, DEF), 0);
|
||||||
|
|
||||||
|
if (HP == 0)
|
||||||
|
return result::died;
|
||||||
|
|
||||||
|
return result::hit;
|
||||||
|
}
|
18
src/troll.h
Normal file
18
src/troll.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef __TROLL_H__
|
||||||
|
#define __TROLL_H__
|
||||||
|
|
||||||
|
#include "characters.h"
|
||||||
|
|
||||||
|
class troll final: public character {
|
||||||
|
static const int REGAIN_HP = 5;
|
||||||
|
static const int HP_CAP = 120;
|
||||||
|
public:
|
||||||
|
troll(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 afk,
|
||||||
|
const fraction hit_rate) override;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -1,9 +1,7 @@
|
|||||||
#include "vampire.h"
|
#include "vampire.h"
|
||||||
#include <algorithm>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
vampire::vampire(RNG *rng, const position &pos):
|
vampire::vampire(RNG *rng, const position &pos):
|
||||||
character{rng, race::rshade, pos} {
|
character{rng, race::rvampire, pos} {
|
||||||
gold = 0;
|
gold = 0;
|
||||||
hostile = true;
|
hostile = true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#ifndef __VAMPIRE_H__
|
#ifndef __VAMPIRE_H__
|
||||||
#define __VAMPIRE_H__
|
#define __VAMPIRE_H__
|
||||||
|
|
||||||
#include "characters.h"
|
#include "characters.h"
|
||||||
|
|
||||||
class vampire final: public character {
|
class vampire final: public character {
|
||||||
|
Reference in New Issue
Block a user