diff --git a/docs/archive/uml.md b/docs/archive/uml.md index eaccc85..9f6e295 100644 --- a/docs/archive/uml.md +++ b/docs/archive/uml.md @@ -2,7 +2,8 @@ ## Class Diagram - -Please see UML generated by Mermaid Chart as official documentation. +Archived. Please see new UML diagram uploaded in chats. Thanks! + diff --git a/src/characters.cc b/src/characters.cc index cc0e56f..a2dcd91 100644 --- a/src/characters.cc +++ b/src/characters.cc @@ -201,6 +201,6 @@ result character::move(const direction dir, 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); } diff --git a/src/characters.h b/src/characters.h index 2d75f80..e9554de 100644 --- a/src/characters.h +++ b/src/characters.h @@ -16,7 +16,7 @@ class character; // forward declaration // Note: player should not be in the character list -typedef std::vector character_list; + class character { public: @@ -32,78 +32,65 @@ public: struct attack_result { result res; - int dmg_dealt; - int remaining_HP; - character *which; // hit whom + std::string msg; }; struct apply_result { 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 apply_result apply(const direction &dir, potion_list &potions); - virtual hit_result get_hit(const enum race &race, const int atk, - const fraction hitrate) = 0; + virtual attack_result get_hit(const enum race &race, const int atk, + const fraction hitrate) = 0; // 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 start_turn(); + virtual void start_turn(); 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_ATK() const; int get_DEF() const; - int get_gold() const; - float get_hitrate_real() const; fraction get_hitrate() const; int get_room_num() const; - - void set_position(const position &npos); void set_HP(const int nHP); void set_ATK(const int nATK); void set_DEF(const int nDEF); - void set_gold(const int ngold); void set_hitrate(const fraction nhitrate); void set_room_num(const int room); protected: RNG *rng; + + const feature enabled_features; const enum race race; int HP; + position pos; // IMPORTANT: keep track of ATK and DEF in game at turn time int ATK; int DEF; fraction base_hit_rate; - position pos; + potion_list effects; - int gold; // characters spawn with gold - potion_list potions; // inventory - potion_list effects; // applied potions - - int room_num; + int calc_dmg(const int ATK, const int DEF); private: - void insert_potion(potion *p); + void insert_effect(potion *effect); }; -int calc_dmg(const int ATK, const int DEF); +typedef std::vector character_list; #endif diff --git a/src/constants.h b/src/constants.h index 02c2e45..89014eb 100644 --- a/src/constants.h +++ b/src/constants.h @@ -35,22 +35,33 @@ enum game_command {game_command_terminate = 0, game_command_pass, game_command_panic }; -enum stat_name {HP, ATK, DEF, hostile}; - -const int RACE_CNT = 6; // TODO: update as you go - -enum race {rshade = 0, rvampire, rgoblin, rdrow, rdragon, rmerchant /* 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, 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'}; +// Character generation related +const int RACE_CNT = 12; +enum race {rshade = 0, rdrow, rvampire, rtroll, + rgoblin, rhuman, rdwarf, relf, + rorc, rmerchant, rdragon, rhalfling + }; 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 DEFAULT_POTION_TYPE_CNT = 6; 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_ADD_FIXED = 4; + const int DIRECTION_CNT = 8; // IMPORTANT: east is positive for x and SOUTH is positive for y // initializes all directions to an int @@ -75,8 +87,8 @@ enum direction { north = 0, south, east, west, northeast, }; const position MOVE[DIRECTION_CNT] = { - {0, -1}, {0, 1}, {1, 0}, {-1, 0}, - {1, -1}, {-1, -1}, {1, 1}, {-1, 1} + {0, -1}, {0, 1}, {1, 0}, {-1, 0}, + {1, -1}, {-1, -1}, {1, 1}, {-1, 1} }; const int MAP_HEIGHT = 25; diff --git a/src/goblin.cc b/src/goblin.cc index 9abc4ac..fa0a745 100644 --- a/src/goblin.cc +++ b/src/goblin.cc @@ -1,9 +1,7 @@ #include "goblin.h" -#include -#include goblin::goblin(RNG *rng, const position &pos): - character{rng, race::rshade, pos} { + character{rng, race::rgoblin, pos} { gold = 0; 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, const fraction hitrate) { - if (rng->trial(hitrate)) + if (rng->trial(hitrate)) HP = std::max(HP - calc_dmg(atk, DEF), 0); if (HP == 0) diff --git a/src/goblin.h b/src/goblin.h index a1d81cf..460fe9e 100644 --- a/src/goblin.h +++ b/src/goblin.h @@ -1,5 +1,6 @@ #ifndef __GOBLIN_H__ #define __GOBLIN_H__ + #include "characters.h" class goblin final: public character { diff --git a/src/map.cc b/src/map.cc index 24f64e8..03d30bb 100644 --- a/src/map.cc +++ b/src/map.cc @@ -277,7 +277,7 @@ std::vector game_map::distr_rooms(RNG *rng, if (l == r) { result.push_back({ 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.y, {0, 0}, {0, 0}}); continue; diff --git a/src/races.h b/src/races.h index ddd0058..55b5a8a 100644 --- a/src/races.h +++ b/src/races.h @@ -2,8 +2,9 @@ #define __RACES_H__ #include "shade.h" -#include "goblin.h" #include "vampire.h" +#include "troll.h" +#include "goblin.h" #include "dragon.h" #endif diff --git a/src/shade.cc b/src/shade.cc index 6d58d56..d639c6b 100644 --- a/src/shade.cc +++ b/src/shade.cc @@ -1,8 +1,5 @@ #include "shade.h" -#include -#include - shade::shade(RNG *rng, const position &pos): character{rng, race::rshade, pos} { gold = 0; diff --git a/src/troll.cc b/src/troll.cc new file mode 100644 index 0000000..61a5b22 --- /dev/null +++ b/src/troll.cc @@ -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; +} diff --git a/src/troll.h b/src/troll.h new file mode 100644 index 0000000..d144db3 --- /dev/null +++ b/src/troll.h @@ -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 diff --git a/src/vampire.cc b/src/vampire.cc index 6725522..208a405 100644 --- a/src/vampire.cc +++ b/src/vampire.cc @@ -1,9 +1,7 @@ #include "vampire.h" -#include -#include vampire::vampire(RNG *rng, const position &pos): - character{rng, race::rshade, pos} { + character{rng, race::rvampire, pos} { gold = 0; hostile = true; } diff --git a/src/vampire.h b/src/vampire.h index acb1a01..b7ccf6c 100644 --- a/src/vampire.h +++ b/src/vampire.h @@ -1,5 +1,6 @@ #ifndef __VAMPIRE_H__ #define __VAMPIRE_H__ + #include "characters.h" class vampire final: public character {