merged DT/add-troll-char
This commit is contained in:
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
## Class Diagram
|
## Class Diagram
|
||||||
|
|
||||||
<!----
|
<!---
|
||||||
|
|
||||||
```plantuml
|
```plantuml
|
||||||
@startuml
|
@startuml
|
||||||
class User {
|
class User {
|
||||||
@ -23,4 +24,5 @@ class User {
|
|||||||
```
|
```
|
||||||
-->
|
-->
|
||||||
|
|
||||||
Please see UML generated by Mermaid Chart as official documentation.
|
Archived. Please see new UML diagram uploaded in chats. Thanks!
|
||||||
|
|
||||||
|
@ -201,6 +201,6 @@ result character::move(const direction dir,
|
|||||||
return result::fine;
|
return result::fine;
|
||||||
}
|
}
|
||||||
|
|
||||||
int calc_dmg(const int ATK, const int DEF) {
|
int character::calc_dmg(const int ATK, const int DEF) {
|
||||||
return ceil((100.0f / (100.0f + DEF)) * ATK);
|
return ceil((100.0f / (100.0f + DEF)) * ATK);
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
class character; // forward declaration
|
class character; // forward declaration
|
||||||
|
|
||||||
// Note: player should not be in the character list
|
// Note: player should not be in the character list
|
||||||
typedef std::vector<character *> character_list;
|
|
||||||
|
|
||||||
class character {
|
class character {
|
||||||
public:
|
public:
|
||||||
@ -32,78 +32,65 @@ public:
|
|||||||
|
|
||||||
struct attack_result {
|
struct attack_result {
|
||||||
result res;
|
result res;
|
||||||
int dmg_dealt;
|
std::string msg;
|
||||||
int remaining_HP;
|
|
||||||
character *which; // hit whom
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct apply_result {
|
struct apply_result {
|
||||||
result res;
|
result res;
|
||||||
potion *which; // applied which potion
|
std::string msg;
|
||||||
};
|
};
|
||||||
|
virtual result move(position_list spots, const direction &dir);
|
||||||
|
|
||||||
struct hit_result {
|
|
||||||
result res;
|
|
||||||
int dmg_dealt;
|
|
||||||
int remaining_HP;
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual attack_result attack(const direction dir,
|
|
||||||
character_list &chlist) = 0;
|
|
||||||
virtual attack_result attack(const direction dir, character *ch) = 0;
|
virtual attack_result attack(const direction dir, character *ch) = 0;
|
||||||
|
|
||||||
virtual apply_result apply(const direction &dir,
|
virtual apply_result apply(const direction &dir,
|
||||||
potion_list &potions);
|
potion_list &potions);
|
||||||
virtual hit_result get_hit(const enum race &race, const int atk,
|
virtual attack_result get_hit(const enum race &race, const int atk,
|
||||||
const fraction hitrate) = 0;
|
const fraction hitrate) = 0;
|
||||||
|
|
||||||
// overload for different races
|
// overload for different races
|
||||||
virtual void print(display *out, bool player = false);
|
virtual void print(display *out);
|
||||||
|
|
||||||
result apply_effects();
|
virtual result calc_effects();
|
||||||
void discard_level_effects();
|
void discard_level_effects();
|
||||||
void start_turn();
|
virtual void start_turn();
|
||||||
|
|
||||||
enum race get_race() const;
|
enum race get_race() const;
|
||||||
position get_position() const;
|
position get_pos() const;
|
||||||
|
void set_pos(const position &npos);
|
||||||
|
|
||||||
int get_HP() const;
|
int get_HP() const;
|
||||||
int get_ATK() const;
|
int get_ATK() const;
|
||||||
int get_DEF() const;
|
int get_DEF() const;
|
||||||
int get_gold() const;
|
|
||||||
float get_hitrate_real() const;
|
|
||||||
fraction get_hitrate() const;
|
fraction get_hitrate() const;
|
||||||
int get_room_num() const;
|
int get_room_num() const;
|
||||||
|
|
||||||
void set_position(const position &npos);
|
|
||||||
void set_HP(const int nHP);
|
void set_HP(const int nHP);
|
||||||
void set_ATK(const int nATK);
|
void set_ATK(const int nATK);
|
||||||
void set_DEF(const int nDEF);
|
void set_DEF(const int nDEF);
|
||||||
void set_gold(const int ngold);
|
|
||||||
void set_hitrate(const fraction nhitrate);
|
void set_hitrate(const fraction nhitrate);
|
||||||
void set_room_num(const int room);
|
void set_room_num(const int room);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RNG *rng;
|
RNG *rng;
|
||||||
|
|
||||||
|
const feature enabled_features;
|
||||||
const enum race race;
|
const enum race race;
|
||||||
|
|
||||||
int HP;
|
int HP;
|
||||||
|
position pos;
|
||||||
|
|
||||||
// IMPORTANT: keep track of ATK and DEF in game at turn time
|
// IMPORTANT: keep track of ATK and DEF in game at turn time
|
||||||
int ATK;
|
int ATK;
|
||||||
int DEF;
|
int DEF;
|
||||||
fraction base_hit_rate;
|
fraction base_hit_rate;
|
||||||
|
|
||||||
position pos;
|
potion_list effects;
|
||||||
|
|
||||||
int gold; // characters spawn with gold
|
int calc_dmg(const int ATK, const int DEF);
|
||||||
potion_list potions; // inventory
|
|
||||||
potion_list effects; // applied potions
|
|
||||||
|
|
||||||
int room_num;
|
|
||||||
private:
|
private:
|
||||||
void insert_potion(potion *p);
|
void insert_effect(potion *effect);
|
||||||
};
|
};
|
||||||
|
|
||||||
int calc_dmg(const int ATK, const int DEF);
|
typedef std::vector<character *> character_list;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -35,22 +35,33 @@ enum game_command {game_command_terminate = 0,
|
|||||||
game_command_pass, game_command_panic
|
game_command_pass, game_command_panic
|
||||||
};
|
};
|
||||||
|
|
||||||
enum stat_name {HP, ATK, DEF, hostile};
|
// Character generation related
|
||||||
|
const int RACE_CNT = 12;
|
||||||
const int RACE_CNT = 6; // TODO: update as you go
|
enum race {rshade = 0, rdrow, rvampire, rtroll,
|
||||||
|
rgoblin, rhuman, rdwarf, relf,
|
||||||
enum race {rshade = 0, rvampire, rgoblin, rdrow, rdragon, rmerchant /* TODO: fill out the other races (including enemies) */};
|
rorc, rmerchant, rdragon, rhalfling
|
||||||
|
};
|
||||||
// TODO: fill out the other races (including enemies)
|
|
||||||
const int MAX_HP[RACE_CNT] = {125, INF, 110, 150, 150, 30};
|
|
||||||
const int STARTING_HP[RACE_CNT] = {125, 50, 110, 150, 150, 30};
|
|
||||||
const int STARTING_ATK[RACE_CNT] = {25, 25, 15, 25, 20, 70};
|
|
||||||
const int STARTING_DEF[RACE_CNT] = {25, 25, 20, 15, 20, 5};
|
|
||||||
const char CHARACTER_REP[RACE_CNT] = {'S', 'V', 'G', 'd', 'D', 'M'};
|
|
||||||
const char *RACE_NAME[RACE_CNT] = {
|
const char *RACE_NAME[RACE_CNT] = {
|
||||||
"Shade", "Vampire", "Goblin", "Drow", "Dragon"
|
"Shade", "Drow", "Vampire", "Troll",
|
||||||
|
"Goblin", "Human", "Dwarf", "Elf",
|
||||||
|
"Orc", "Merchant", "Dragon", "Halfling"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const int MAX_HP[RACE_CNT] = {
|
||||||
|
125, 150, INF, 120, 110, 140, 100, 140, 180, 30, 150, 100
|
||||||
|
};
|
||||||
|
const int STARTING_HP[RACE_CNT] = {
|
||||||
|
125, 150, 50, 120, 110, 140, 100, 140, 180, 30, 150, 100
|
||||||
|
};
|
||||||
|
const int STARTING_ATK[RACE_CNT] = {
|
||||||
|
25, 25, 25, 25, 15, 20, 20, 30, 30, 70, 20, 15
|
||||||
|
};
|
||||||
|
const int STARTING_DEF[RACE_CNT] = {
|
||||||
|
25, 15, 25, 15, 20, 20, 30, 10, 25, 5, 20, 20
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Potion-related
|
||||||
const int POTION_TYPE_CNT = 6;
|
const int POTION_TYPE_CNT = 6;
|
||||||
const int DEFAULT_POTION_TYPE_CNT = 6;
|
const int DEFAULT_POTION_TYPE_CNT = 6;
|
||||||
enum potion_type {restore_health = 0, boost_atk, boost_def,
|
enum potion_type {restore_health = 0, boost_atk, boost_def,
|
||||||
@ -67,6 +78,7 @@ const int CALC_ADD_LATER = 2;
|
|||||||
const int CALC_MUL_LATER = 3;
|
const int CALC_MUL_LATER = 3;
|
||||||
const int CALC_ADD_FIXED = 4;
|
const int CALC_ADD_FIXED = 4;
|
||||||
|
|
||||||
|
|
||||||
const int DIRECTION_CNT = 8;
|
const int DIRECTION_CNT = 8;
|
||||||
// IMPORTANT: east is positive for x and SOUTH is positive for y
|
// IMPORTANT: east is positive for x and SOUTH is positive for y
|
||||||
// initializes all directions to an int
|
// initializes all directions to an int
|
||||||
@ -75,8 +87,8 @@ enum direction { north = 0, south, east, west, northeast,
|
|||||||
};
|
};
|
||||||
|
|
||||||
const position MOVE[DIRECTION_CNT] = {
|
const position MOVE[DIRECTION_CNT] = {
|
||||||
{0, -1}, {0, 1}, {1, 0}, {-1, 0},
|
{0, -1}, {0, 1}, {1, 0}, {-1, 0},
|
||||||
{1, -1}, {-1, -1}, {1, 1}, {-1, 1}
|
{1, -1}, {-1, -1}, {1, 1}, {-1, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
const int MAP_HEIGHT = 25;
|
const int MAP_HEIGHT = 25;
|
||||||
|
@ -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 {
|
||||||
|
@ -277,7 +277,7 @@ std::vector<game_map::room> game_map::distr_rooms(RNG *rng,
|
|||||||
if (l == r) {
|
if (l == r) {
|
||||||
result.push_back({
|
result.push_back({
|
||||||
0, rng->rand_under(ACTUAL_MAP_WIDTH -
|
0, rng->rand_under(ACTUAL_MAP_WIDTH -
|
||||||
room_dims[l].first.x + 1),
|
room_dims[l].first.x + 1),
|
||||||
room_dims[l].first.x,
|
room_dims[l].first.x,
|
||||||
room_dims[l].first.y, {0, 0}, {0, 0}});
|
room_dims[l].first.y, {0, 0}, {0, 0}});
|
||||||
continue;
|
continue;
|
||||||
|
@ -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