From 295b808e144d8ea028fd3eca1330de646eac46f0 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 14:41:32 -0400 Subject: [PATCH 1/8] =?UTF-8?q?fixed:=201.=20potions=20being=20walked=20ov?= =?UTF-8?q?er=202.=20spawning=20on=20stairs=203.=20enemies=20walking=20und?= =?UTF-8?q?er=20players=204.=20merchants=20not=20being=20aggresive=205.=20?= =?UTF-8?q?potions=20losing=20effect=20when=20sending=20pass=20signal=20(c?= =?UTF-8?q?leared=20by=20player::start=5Fturn())=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arguments.cc | 2 +- src/cursor.cc | 2 +- src/enemy.cc | 7 +++++-- src/game.cc | 16 ++++++++++++---- src/level.cc | 34 ++++++++++++++++++++++++++++++---- src/player.cc | 25 +++++++++++++++++++++---- src/position.cc | 2 +- src/position.h | 2 +- 8 files changed, 72 insertions(+), 18 deletions(-) diff --git a/src/arguments.cc b/src/arguments.cc index 8e30406..538dcf3 100644 --- a/src/arguments.cc +++ b/src/arguments.cc @@ -175,7 +175,7 @@ void print_args_list() { -R : Enable revisiting levels\n\ -e : Enable extra potions and races\n\ -E : Enable extra levels\n\ --o : Allows monsters to go over gold and potions\n\ +-o : Allows characters to go over gold and potions\n\ -s [seed] : Sets initial seed to seed\n\ -I [file] : Reads commands from file. CANNOT BE USED WITH -n.\n\ -O [file] : Outputs to file. CANNOT BE USED WITH -n.\n\ diff --git a/src/cursor.cc b/src/cursor.cc index c3d04f8..892a90c 100644 --- a/src/cursor.cc +++ b/src/cursor.cc @@ -30,7 +30,7 @@ void cursor::show() const { } void cursor::clear() const { - ::clear(); + // ::clear(); } void cursor::print_char(const position &pos, const char ch, diff --git a/src/enemy.cc b/src/enemy.cc index 056f94f..463dbb8 100644 --- a/src/enemy.cc +++ b/src/enemy.cc @@ -73,11 +73,14 @@ long_result enemy_base::get_hit(character *ch, const int tATK, if (HP == 0) return {result::hit, "PC deals " + std::to_string(tmp) + - " damage to " + abbrev + ". " + abbrev + + " damage to " + abbrev + " (" + + std::to_string(HP) + " HP). " + + abbrev + " is slain by PC. "}; return {result::hit, "PC deals " + - std::to_string(tmp) + " damage to " + abbrev + ". "}; + std::to_string(tmp) + " damage to " + abbrev + " (" + + std::to_string(HP) + " HP). "}; } return {miss, "PC tried to hit " + abbrev + " but missed. "}; diff --git a/src/game.cc b/src/game.cc index 7e9c596..32e1b1e 100644 --- a/src/game.cc +++ b/src/game.cc @@ -83,11 +83,13 @@ character *game::move_enemies() { } game_result game::run() { - player->start_turn(); auto res = player->interpret_command(levels[curr_level].get(), in->get_command()); msg = res.msg; + if (res.msg.find('M') != std::string::npos) + hostile_merchants = true; + switch (res.res) { case result::terminate: return {terminated, ""}; @@ -99,14 +101,16 @@ game_result game::run() { if (curr_level == max_level - 1) return {won, "You won! You collected " + std::to_string(player->get_gold()) + - " after " + std::to_string(curr_turn + 1) + + " pieces of gold after " + + std::to_string(curr_turn + 1) + " turns!"}; player->discard_level_effects(); ++curr_level; - new_level(); + if (curr_level == levels.size()) + new_level(); break; } @@ -115,7 +119,8 @@ game_result game::run() { if (curr_level == 0) return {escaped, "You escaped the dungeon with " + std::to_string(player->get_gold()) + - " after " + std::to_string(curr_turn + 1) + + " pieces of gold after " + + std::to_string(curr_turn + 1) + " turns! Coward!"}; player->discard_level_effects(); @@ -169,6 +174,7 @@ const position STATUS_HP{0, 26}; const position STATUS_ATK{0, 27}; const position STATUS_DEF{0, 28}; const position STATUS_ACTION{0, 29}; +const std::string BLANK(DISPLAY_BUFFER_SIZE, ' '); size_t game::get_curr_turn() const { return curr_turn; @@ -180,6 +186,8 @@ void game::print() { msg += "..."; } + out->print_str({0, 0}, BLANK); + levels[curr_level]->print(out); player->print(out); diff --git a/src/level.cc b/src/level.cc index c3504e6..48c52cf 100644 --- a/src/level.cc +++ b/src/level.cc @@ -6,6 +6,15 @@ level::level(character *player, RNG *rng, const feature enabled_features): enabled_features{enabled_features}, map{player, rng, enabled_features}, player{player} { auto tiles = map.get_room_list(); + + for (size_t i = 0; i < tiles.size(); ++i) + remove_from_list(tiles[i], map.get_down_stairs()); + + if (enabled_features & FEATURE_REVISIT) + for (size_t i = 0; i < tiles.size(); ++i) + remove_from_list(tiles[i], map.get_up_stairs()); + + gen_potions(rng, tiles); gen_gold(rng, tiles); gen_enemies(rng, tiles); @@ -16,6 +25,14 @@ level::level(const std::string &map_data, character *player, RNG *rng, enabled_features{enabled_features}, map{player, map_data, rng, enabled_features}, player{player} { auto tiles = map.get_room_list(); + + for (size_t i = 0; i < tiles.size(); ++i) + remove_from_list(tiles[i], map.get_down_stairs()); + + if (enabled_features & FEATURE_REVISIT) + for (size_t i = 0; i < tiles.size(); ++i) + remove_from_list(tiles[i], map.get_up_stairs()); + gen_potions(rng, tiles); gen_gold(rng, tiles); gen_enemies(rng, tiles); @@ -42,9 +59,12 @@ void level::gen_enemies(RNG *rng, std::vector &tiles) { for (size_t i = 0; i < dhoard.size(); ++i) { position_list spots; - for (int i = 0; i < DIRECTION_CNT; ++i) - if (map.which_room(dhoard[i].pos + MOVE[i]) != -1) + for (int i = 0; i < DIRECTION_CNT; ++i) { + position tmp = dhoard[i].pos + MOVE[i]; + + if (map.which_room(tmp) != -1) spots.push_back(dhoard[i].pos + MOVE[i]); + } pelist.push_back(nullptr); new_dragon(rng, pelist[i], rng->get_rand_in_vector(spots), @@ -128,19 +148,22 @@ bool level::is_available(const position &pos, bool is_player) const { if (!map.is_available(pos)) return false; + if (player->get_pos() == pos) + return false; + for (size_t i = 0; i < elist.size(); ++i) if (pos == elist[i]->get_pos()) return false; - if (!(enabled_features & FEATURE_WALK_OVER) && !is_player) { + if (!(enabled_features & FEATURE_WALK_OVER)) for (size_t i = 0; i < plist.size(); ++i) if (pos == plist[i]->get_pos()) return false; + if (!(enabled_features & FEATURE_WALK_OVER) && !is_player) for (size_t i = 0; i < glist.size(); ++i) if (pos == glist[i].pos) return false; - } return true; } @@ -149,6 +172,9 @@ bool level::is_available_all(const position &pos) const { if (!map.is_available(pos)) return false; + if (player->get_pos() == pos) + return false; + for (size_t i = 0; i < elist.size(); ++i) if (pos == elist[i]->get_pos()) return false; diff --git a/src/player.cc b/src/player.cc index 3604228..f59a24e 100644 --- a/src/player.cc +++ b/src/player.cc @@ -111,18 +111,31 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) { return {result::terminate, ""}; } else if (cmd >= move_north && cmd <= move_southwest) { auto res = move(lvl, pos + MOVE[cmd - move_north]); + + if (res.res == result::moved) + start_turn(); + gold g = get_gold_at(pos, lvl->get_glist()); gold_cnt += g.amount; return res; } else if (cmd >= apply_north && cmd <= apply_southwest) { - return apply(get_potion_at(pos + MOVE[cmd - apply_north], - lvl->get_plist())); + auto res = apply(get_potion_at(pos + MOVE[cmd - apply_north], + lvl->get_plist())); + + if (res.res == result::applied) + start_turn(); + + return res; } else if (cmd == apply_panic) { return {result::fine, "PC tried to use in some non-existent direction. "}; } else if (cmd >= attack_north && cmd <= attack_southwest) { enemy_base *tmp = get_enemy_at(pos + MOVE[cmd - attack_north], lvl->get_elist()); + + if (tmp != nullptr) + start_turn(); + auto res = attack((character *)tmp); if (tmp != nullptr && tmp->is_dead()) @@ -131,14 +144,18 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) { return res; } else if (cmd == up_stairs) { if (lvl->get_up_stairs() == pos && - enabled_features & FEATURE_REVISIT) + enabled_features & FEATURE_REVISIT) { + start_turn(); return {go_up, "PC went up the stairs. "}; + } return {result::fine, "PC tried to fly through the ceiling. "}; } else if (cmd == down_stairs) { - if (lvl->get_down_stairs() == pos) + if (lvl->get_down_stairs() == pos) { + start_turn(); return {go_down, "PC went down the stairs. "}; + } return {result::fine, "PC tried to dig through the floor. "}; diff --git a/src/position.cc b/src/position.cc index baf3aa5..5563a38 100644 --- a/src/position.cc +++ b/src/position.cc @@ -67,7 +67,7 @@ std::vector remove_from_list(const std::vector void remove_from_list(std::vector &positions, - position &excluded) { + const position &excluded) { for (auto i = positions.begin(); i != positions.end(); ++i) if (*i == excluded) { positions.erase(i); diff --git a/src/position.h b/src/position.h index e05e984..b58fe71 100644 --- a/src/position.h +++ b/src/position.h @@ -26,7 +26,7 @@ std::size_t find(const position_list &sorted_list, std::vector remove_from_list(const position_list &sorted_positions, position_list excluded); void remove_from_list(position_list &sorted_positions, - position &excluded); + const position &excluded); float distance(const position &a, const position &b); int distance_sqr(const position &a, const position &b); From 9ad553706a870cf4ef9d4fea019cb9046e7ad206 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 14:52:28 -0400 Subject: [PATCH 2/8] fixed elfs being displayed as humans reduced radius of chasing enemies added warning to -c option --- src/arguments.cc | 5 ++--- src/enemies/elf.cc | 4 ++-- src/enemy.cc | 8 ++++---- src/enemy.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/arguments.cc b/src/arguments.cc index 538dcf3..3398a7d 100644 --- a/src/arguments.cc +++ b/src/arguments.cc @@ -168,9 +168,8 @@ void print_args_list() { static const char *ARGS_LIST = "-n : Use ncurses for I/O\n\ -r : Randomly generate maps\n\ -m : Enabled a main menu + options\n\ --c : Enemies chase the player (through doors and up stairs)\n\ --C : Give things better coloring\n\ --i : Enable inventory (player can walk on potions)\n\ +-c : Enemies chase the player (CAUTION: THEY CAN REALLY CHASE!!!)\n\ +-i : Enable inventory (player can pick up potions)\n\ -t : Enable throw\n\ -R : Enable revisiting levels\n\ -e : Enable extra potions and races\n\ diff --git a/src/enemies/elf.cc b/src/enemies/elf.cc index 90117b0..1d8b244 100644 --- a/src/enemies/elf.cc +++ b/src/enemies/elf.cc @@ -4,10 +4,10 @@ elf::elf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): - enemy_base{rng, enabled_features, relf, pos, gen_room_num, "H"} {} + enemy_base{rng, enabled_features, relf, pos, gen_room_num, "E"} {} void elf::print(display *out) { - out->print_char(pos, 'H', COLOR_PAIR(COLOR_RED)); + out->print_char(pos, 'E', COLOR_PAIR(COLOR_RED)); } const char *elf::get_race_name() const { diff --git a/src/enemy.cc b/src/enemy.cc index 463dbb8..d94f9a2 100644 --- a/src/enemy.cc +++ b/src/enemy.cc @@ -20,7 +20,7 @@ long_result enemy_base::act(level *lvl, character *pc, bool hostile) { if (is_adjacent(pos, pc->get_pos()) && hostile) return attack(pc); - if (enabled_features & FEATURE_ENEMIES_CHASE && + if (enabled_features & FEATURE_ENEMIES_CHASE && hostile && distance_sqr(pos, pc->get_pos()) <= DIST_THRESHOLD_SQR) { position tmp; position target = {BIG_NUMBER, BIG_NUMBER}; @@ -28,8 +28,7 @@ long_result enemy_base::act(level *lvl, character *pc, bool hostile) { for (int i = 0; i < DIRECTION_CNT; ++i) { tmp = pos + MOVE[i]; - if (lvl->get_room(tmp) == room_num && - lvl->is_available(tmp) && + if (lvl->is_available(tmp) && distance_sqr(tmp, pc->get_pos()) < distance_sqr(target, pc->get_pos())) target = tmp; @@ -43,7 +42,8 @@ long_result enemy_base::act(level *lvl, character *pc, bool hostile) { position choices[DIRECTION_CNT]; for (int i = 0; i < DIRECTION_CNT; ++i) - if (lvl->get_room(pos + MOVE[i]) == room_num && + if (((enabled_features & FEATURE_ENEMIES_CHASE) ? + true : lvl->get_room(pos + MOVE[i]) == room_num ) && lvl->is_available(pos + MOVE[i])) { choices[choices_cnt] = pos + MOVE[i]; ++choices_cnt; diff --git a/src/enemy.h b/src/enemy.h index 2f11c63..e43fd32 100644 --- a/src/enemy.h +++ b/src/enemy.h @@ -6,7 +6,7 @@ class enemy_base : public character { private: const static int BIG_NUMBER = 500; - const static int DIST_THRESHOLD_SQR = 8 * 8; + const static int DIST_THRESHOLD_SQR = 3 * 3; protected: const int room_num; From 55d269a2209fe24e2527271d6f96594b36646e55 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 15:26:28 -0400 Subject: [PATCH 3/8] reworked some arguments --- src/arguments.cc | 8 +++----- src/constants.h | 11 +++++------ src/enemy.cc | 6 ++++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/arguments.cc b/src/arguments.cc index 3398a7d..a22205e 100644 --- a/src/arguments.cc +++ b/src/arguments.cc @@ -38,12 +38,10 @@ feature proc_args(int argc, char **argv, result |= FEATURE_NCURSES; } else if (str == "-r") { result |= FEATURE_RAND_MAP; - } else if (str == "-m") { - result |= FEATURE_MENU; } else if (str == "-c") { result |= FEATURE_ENEMIES_CHASE; - } else if (str == "-C") { - result |= FEATURE_COLORFUL; + } else if (str == "-d") { + result |= FEATURE_DOORS; } else if (str == "-i") { result |= FEATURE_INVENTORY; } else if (str == "-t") { @@ -167,8 +165,8 @@ void panic_args(feature panic) { void print_args_list() { static const char *ARGS_LIST = "-n : Use ncurses for I/O\n\ -r : Randomly generate maps\n\ --m : Enabled a main menu + options\n\ -c : Enemies chase the player (CAUTION: THEY CAN REALLY CHASE!!!)\n\ +-d : Enemies can go through doors (CAUTION: DO NOT ENABLE WITH CHASING!)\n\ -i : Enable inventory (player can pick up potions)\n\ -t : Enable throw\n\ -R : Enable revisiting levels\n\ diff --git a/src/constants.h b/src/constants.h index aee224f..fbaa5cc 100644 --- a/src/constants.h +++ b/src/constants.h @@ -114,12 +114,11 @@ static const feature FEATURE_THROW = 1 << 4; static const feature FEATURE_REVISIT = 1 << 5; static const feature FEATURE_WALK_OVER = 1 << 6; static const feature FEATURE_SEED = 1 << 7; -static const feature FEATURE_MENU = 1 << 8; -static const feature FEATURE_IN_FILE = 1 << 9; -static const feature FEATURE_OUT_FILE = 1 << 10; -static const feature FEATURE_EXTRA_STUFF = 1 << 11; -static const feature FEATURE_EXTRA_LEVELS = 1 << 12; -static const feature FEATURE_COLORFUL = 1 << 13; +static const feature FEATURE_IN_FILE = 1 << 8; +static const feature FEATURE_OUT_FILE = 1 << 9; +static const feature FEATURE_EXTRA_STUFF = 1 << 10; +static const feature FEATURE_EXTRA_LEVELS = 1 << 11; +static const feature FEATURE_DOORS = 1 << 12; static const feature FEATURE_PANIC_SEED = 1 << 27; static const feature FEATURE_PANIC_FILE = 1 << 28; diff --git a/src/enemy.cc b/src/enemy.cc index d94f9a2..40810c8 100644 --- a/src/enemy.cc +++ b/src/enemy.cc @@ -28,7 +28,9 @@ long_result enemy_base::act(level *lvl, character *pc, bool hostile) { for (int i = 0; i < DIRECTION_CNT; ++i) { tmp = pos + MOVE[i]; - if (lvl->is_available(tmp) && + if (((enabled_features & FEATURE_DOORS) ? true + : lvl->get_room(tmp) == room_num) && + lvl->is_available(tmp) && distance_sqr(tmp, pc->get_pos()) < distance_sqr(target, pc->get_pos())) target = tmp; @@ -42,7 +44,7 @@ long_result enemy_base::act(level *lvl, character *pc, bool hostile) { position choices[DIRECTION_CNT]; for (int i = 0; i < DIRECTION_CNT; ++i) - if (((enabled_features & FEATURE_ENEMIES_CHASE) ? + if (((enabled_features & FEATURE_DOORS) ? true : lvl->get_room(pos + MOVE[i]) == room_num ) && lvl->is_available(pos + MOVE[i])) { choices[choices_cnt] = pos + MOVE[i]; From 5e48265c16c21f6e218e1f9c4fab277a8705a1c0 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 15:51:15 -0400 Subject: [PATCH 4/8] fixed restarting actually exiting the game --- src/cc3k.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc3k.cc b/src/cc3k.cc index 10e288f..3cb75e6 100644 --- a/src/cc3k.cc +++ b/src/cc3k.cc @@ -48,6 +48,7 @@ game_status CC3K::run() { out->clear(); curr_menu->print(out); out->render(); + gresult.status = main_menu; return main_menu; } else if (gresult.status == in_game) { out->clear(); From 73cdb8845873d26cdd2fd07434a046493c874640 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 16:29:06 -0400 Subject: [PATCH 5/8] made main menu friendlier --- src/cc3k.cc | 6 +++--- src/menu.cc | 29 +++++++++++++++++++++++------ src/menu.h | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/cc3k.cc b/src/cc3k.cc index 3cb75e6..561510a 100644 --- a/src/cc3k.cc +++ b/src/cc3k.cc @@ -8,7 +8,7 @@ CC3K::CC3K(const feature enabled_features, in{in}, out{out}, rng{rng} { curr_menu = std::make_unique(enabled_features); out->clear(); - curr_menu->print(out); + curr_menu->print(out, rng->get_init_seed()); out->render(); gresult.status = game_status::main_menu; } @@ -34,7 +34,7 @@ game_status CC3K::run() { } out->clear(); - curr_menu->print(out); + curr_menu->print(out, rng->get_init_seed()); out->render(); return main_menu; } @@ -46,7 +46,7 @@ game_status CC3K::run() { curr_game = nullptr; curr_menu = std::make_unique(enabled_features); out->clear(); - curr_menu->print(out); + curr_menu->print(out, rng->get_init_seed()); out->render(); gresult.status = main_menu; return main_menu; diff --git a/src/menu.cc b/src/menu.cc index b0ed548..503985d 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -36,7 +36,7 @@ const char *NORMAL_SCREEN = | | \\_ | \\_ _\\ || \\ |\ | \\____/\\____//____/\\_|\\_\\ |\ +-----------------------------------------------------------------------------+\ -| Choose your race | |\ +| Choose your race: |\ +-----------------------------------------------------------------------------+\ | Shade | |\ +-----------------------------------------------------------------------------+\ @@ -51,7 +51,7 @@ const char *NORMAL_SCREEN = | |\ | |\ | |\ -| |\ +|-----------------------------------------------------------------------------|\ | |\ +-----------------------------------------------------------------------------+"; @@ -63,7 +63,7 @@ const char *EXTRA_SCREEN = | | \\_ | \\_ _\\ || \\ |\ | \\____/\\____//____/\\_|\\_\\ |\ +-----------------------------------------------------------------------------+\ -| Choose your race | |\ +| Choose your race: |\ +-----------------------------------------------------------------------------+\ | Shade | |\ +-----------------------------------------------------------------------------+\ @@ -78,7 +78,7 @@ const char *EXTRA_SCREEN = | |\ | |\ | |\ -| |\ +|-----------------------------------------------------------------------------|\ | |\ +-----------------------------------------------------------------------------+"; @@ -152,10 +152,27 @@ int menu::run(input *in) { return -1; } -void menu::print(display *out) { +const position MSG_POS = {2, 23}; +const char *MSG_NORMAL = + "Move with movement commands, 'yes' to confirm, 'q' to quit."; +const char *MSG_NCURSES = + "Move with movement commands, press 'e' to confirm, 'q' to quit."; +const position SEED_POS = {1, 25}; + +void menu::print(display *out, const unsigned int seed) { if (enabled_features & FEATURE_EXTRA_STUFF) out->print_str({0, 0}, NORMAL_SCREEN); else out->print_str({0, 0}, EXTRA_SCREEN); - out->print_str(cur, "->", COLOR_PAIR(COLOR_BLUE)); + + if (enabled_features & FEATURE_NCURSES) + out->print_str(MSG_POS, MSG_NCURSES, COLOR_PAIR(COLOR_YELLOW)); + else + out->print_str(MSG_POS, MSG_NORMAL, COLOR_PAIR(COLOR_YELLOW)); + + out->print_str(SEED_POS, "Seed: " + std::to_string(seed), + COLOR_PAIR(COLOR_BLUE)); + + out->print_str(cur, "->", COLOR_PAIR(COLOR_GREEN)); + } diff --git a/src/menu.h b/src/menu.h index 903f295..e8fc0e4 100644 --- a/src/menu.h +++ b/src/menu.h @@ -15,7 +15,7 @@ private: public: menu(const feature enabled_features); int run(input *in); - void print(display *out); + void print(display *out, const unsigned int seed); }; #endif From fb026e36a83d239df8e05991a521689fae9ad78b Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 16:49:18 -0400 Subject: [PATCH 6/8] renamed display to output --- src/arguments.cc | 8 +-- src/arguments.h | 4 +- src/cc3k.cc | 2 +- src/cc3k.h | 6 +- src/characters.h | 4 +- src/cursor.h | 2 +- src/display.cc | 17 ------ src/display.h | 35 ------------ src/display/console_output.cc | 100 ---------------------------------- src/display/console_output.h | 21 ------- src/display/curses_output.cc | 38 ------------- src/display/curses_output.h | 23 -------- src/display/file_output.cc | 38 ------------- src/display/file_output.h | 20 ------- src/enemies/dragon.cc | 2 +- src/enemies/dragon.h | 2 +- src/enemies/dwarf.cc | 2 +- src/enemies/dwarf.h | 2 +- src/enemies/elf.cc | 2 +- src/enemies/elf.h | 2 +- src/enemies/halfling.cc | 2 +- src/enemies/halfling.h | 2 +- src/enemies/human.cc | 2 +- src/enemies/human.h | 2 +- src/enemies/merchant.cc | 2 +- src/enemies/merchant.h | 2 +- src/enemies/orc.cc | 2 +- src/enemies/orc.h | 2 +- src/game.cc | 2 +- src/game.h | 6 +- src/level.cc | 2 +- src/level.h | 4 +- src/main.cc | 2 +- src/map.cc | 2 +- src/map.h | 4 +- src/menu.cc | 2 +- src/menu.h | 4 +- src/player.cc | 2 +- src/player.h | 2 +- src/potion.cc | 2 +- src/potion.h | 4 +- src/result.cc | 2 +- src/result.h | 4 +- 43 files changed, 49 insertions(+), 341 deletions(-) delete mode 100644 src/display.cc delete mode 100644 src/display.h delete mode 100644 src/display/console_output.cc delete mode 100644 src/display/console_output.h delete mode 100644 src/display/curses_output.cc delete mode 100644 src/display/curses_output.h delete mode 100644 src/display/file_output.cc delete mode 100644 src/display/file_output.h diff --git a/src/arguments.cc b/src/arguments.cc index a22205e..8d52f2c 100644 --- a/src/arguments.cc +++ b/src/arguments.cc @@ -8,17 +8,17 @@ #include "constants.h" #include "input/file_input.h" -#include "display/file_output.h" +#include "output/file_output.h" #include "input/console_input.h" -#include "display/console_output.h" +#include "output/console_output.h" #include "input/curses_input.h" -#include "display/curses_output.h" +#include "output/curses_output.h" #include "rng.h" feature proc_args(int argc, char **argv, std::unique_ptr &curse, std::unique_ptr &in, - std::unique_ptr &out, + std::unique_ptr &out, std::unique_ptr &rng) { feature result = 0; std::string str; diff --git a/src/arguments.h b/src/arguments.h index beb71d8..e1701ec 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -2,7 +2,7 @@ #define __ARGUMENTS_H__ #include #include "cursor.h" -#include "display.h" +#include "output.h" #include "input.h" #include "rng.h" @@ -12,7 +12,7 @@ typedef unsigned int feature; feature proc_args(int argc, char **argv, std::unique_ptr &curse, std::unique_ptr &in, - std::unique_ptr &out, + std::unique_ptr &out, std::unique_ptr &rng); void panic_args(feature panic); diff --git a/src/cc3k.cc b/src/cc3k.cc index 561510a..519606a 100644 --- a/src/cc3k.cc +++ b/src/cc3k.cc @@ -3,7 +3,7 @@ #include "constants.h" CC3K::CC3K(const feature enabled_features, - input *in, display *out, RNG *rng): + input *in, output *out, RNG *rng): enabled_features{enabled_features}, in{in}, out{out}, rng{rng} { curr_menu = std::make_unique(enabled_features); diff --git a/src/cc3k.h b/src/cc3k.h index 4280d6e..5948248 100644 --- a/src/cc3k.h +++ b/src/cc3k.h @@ -2,7 +2,7 @@ #define __CC3K_H__ #include "input.h" -#include "display.h" +#include "output.h" #include "game.h" #include "menu.h" #include "result.h" @@ -11,7 +11,7 @@ class CC3K final { private: const feature enabled_features; input *in; - display *out; + output *out; RNG *rng; game_result gresult; @@ -19,7 +19,7 @@ private: std::unique_ptr curr_menu; public: CC3K(const feature enabled_features, - input *in, display *out, RNG *rng); + input *in, output *out, RNG *rng); game_status run(); }; diff --git a/src/characters.h b/src/characters.h index ab162c7..888d476 100644 --- a/src/characters.h +++ b/src/characters.h @@ -5,7 +5,7 @@ #include #include -#include "display.h" +#include "output.h" #include "fraction.h" #include "position.h" #include "potions.h" @@ -31,7 +31,7 @@ public: virtual void apply_effect(potion *effect); // override for different types - virtual void print(display *out) = 0; + virtual void print(output *out) = 0; result calc_effects(); void discard_level_effects(); diff --git a/src/cursor.h b/src/cursor.h index c0e064a..87419b1 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -5,7 +5,7 @@ #include "position.h" /* Attributes - A_NORMAL Normal display (no highlight) + A_NORMAL Normal output (no highlight) A_STANDOUT Best highlighting mode of the terminal. A_UNDERLINE Underlining A_REVERSE Reverse video diff --git a/src/display.cc b/src/display.cc deleted file mode 100644 index 8f223fc..0000000 --- a/src/display.cc +++ /dev/null @@ -1,17 +0,0 @@ -#include "display.h" - -#include "constants.h" - -display::display(): - contents{DISPLAY_BUFFER_SIZE, 0} { - for (int i = 0; i < DISPLAY_BUFFER_SIZE; ++i) - contents.push_back(0); -} - -void display::clear() { - contents.clear(); - contents.reserve(DISPLAY_BUFFER_SIZE); - - for (int i = 0; i < DISPLAY_BUFFER_SIZE; ++i) - contents.push_back(0); -} diff --git a/src/display.h b/src/display.h deleted file mode 100644 index 9bd4ee2..0000000 --- a/src/display.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __DISPLAY_H__ -#define __DISPLAY_H__ - -#include -#include -#include "position.h" -#include "cursor.h" - -class display { -protected: - // use an array of ints to keep track of what's on the screen - // This will have a bit of buffer for the last line - // just in case it overflows - std::vector contents; -public: - display(); - - virtual ~display() = default; - - // Only call this to refresh the entire output - virtual void render() = 0; - - // Clears the contents buffer - virtual void clear(); - - virtual void print_char(const position &pos, const char ch, - const int attrs = - A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0; - virtual void print_str(const position &pos, const std::string &str, - const int attrs = - A_NORMAL | COLOR_PAIR(COLOR_WHITE)) = 0; - // default arguments are to be set in the base class's declaration -}; - -#endif diff --git a/src/display/console_output.cc b/src/display/console_output.cc deleted file mode 100644 index beff4c2..0000000 --- a/src/display/console_output.cc +++ /dev/null @@ -1,100 +0,0 @@ -#include "console_output.h" - -#include -#include -#include - -#include "../constants.h" - -console_output::console_output(std::ostream &cout): out{cout} {} - -/* Attributes - black 30 40 - red 31 41 - green 32 42 - yellow 33 43 - blue 34 44 - magenta 35 45 - cyan 36 46 - white 37 47 - reset 0 (everything back to normal) - bold/bright 1 (often a brighter shade of the same colour) - underline 4 - inverse 7 (swap foreground and background colours) - bold/bright off 21 - underline off 24 - inverse off 27 - - Format: - \033[X;Ym - X Y are numbers from above -*/ - -std::string console_output::get_code(const int attrs) { - if (attrs < 255) - return "\033[0m"; - - std::string result = "\033[0m\033["; - - if (attrs & A_BOLD) - result += "1;"; - - if (attrs & A_UNDERLINE) - result += "4;"; - - if (attrs & A_STANDOUT) - result += "7;"; - - if ((attrs & COLOR_PAIR(COLOR_WHITE)) == COLOR_PAIR(COLOR_WHITE)) - result += "37;"; - else if ((attrs & COLOR_PAIR(COLOR_CYAN)) == COLOR_PAIR(COLOR_CYAN)) - result += "36;"; - else if ((attrs & COLOR_PAIR(COLOR_MAGENTA)) == COLOR_PAIR(COLOR_MAGENTA)) - result += "35;"; - else if ((attrs & COLOR_PAIR(COLOR_BLUE)) == COLOR_PAIR(COLOR_BLUE)) - result += "34;"; - else if ((attrs & COLOR_PAIR(COLOR_YELLOW)) == COLOR_PAIR(COLOR_YELLOW)) - result += "33;"; - else if ((attrs & COLOR_PAIR(COLOR_RED)) == COLOR_PAIR(COLOR_RED)) - result += "31;"; - else if ((attrs & COLOR_PAIR(COLOR_GREEN)) == COLOR_PAIR(COLOR_GREEN)) - result += "32;"; - else if ((attrs & COLOR_PAIR(COLOR_BLACK_ON_WHITE)) == COLOR_BLACK_ON_WHITE) - result += "30;47;"; - - result[result.length() - 1] = 'm'; - return result; -} - -void console_output::render() { - out << "\x1B[2J\x1B[H"; - - for (std::size_t idx = 0; idx < contents.size(); ++idx) { - if (idx % DISPLAY_WIDTH == 0 && idx) - out << std::endl; - - out << get_code(contents[idx]) - << (char)(contents[idx] ? contents[idx] : ' '); - } - - out << std::endl; -} - -void console_output::print_char(const position &pos, const char ch, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - contents[pos.y * DISPLAY_WIDTH + pos.x] = attrs | ch; -} - -void console_output::print_str(const position &pos, const std::string &str, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - int head = pos.y * DISPLAY_WIDTH + pos.x; - - for (std::size_t i = 0; i < str.length(); ++i) - contents[i + head] = attrs | str[i]; -} diff --git a/src/display/console_output.h b/src/display/console_output.h deleted file mode 100644 index a4eaf62..0000000 --- a/src/display/console_output.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __CONSOLE_OUTPUT_H__ -#define __CONSOLE_OUTPUT_H__ - -#include -#include "../display.h" - -class console_output final : public display { -private: - std::ostream &out; - std::string get_code(const int attrs); -public: - console_output(std::ostream &cout); - - void render() override; - void print_char(const position &pos, - const char ch, const int attrs) override; - void print_str(const position &pos, - const std::string &str, const int attrs) override; -}; - -#endif diff --git a/src/display/curses_output.cc b/src/display/curses_output.cc deleted file mode 100644 index bee3adf..0000000 --- a/src/display/curses_output.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "curses_output.h" - -#include "../constants.h" - -curses_output::curses_output(cursor *new_curse): - curse{new_curse} {} - -void curses_output::render() { - curse->show(); -} - -void curses_output::clear() { - curse->clear(); -} - -void curses_output::print_char(const position &pos, const char ch, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - curse->print_char(pos, ch, attrs); -} - -void curses_output::print_str(const position &pos, const std::string &str, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - position tmp = pos; - - for (std::size_t i = 0; i < str.length(); ++i) { - curse->print_char(tmp, str[i], attrs); - tmp += {1, 0}; - - if (tmp.x >= DISPLAY_WIDTH) - tmp = {0, tmp.y + 1}; - } -} diff --git a/src/display/curses_output.h b/src/display/curses_output.h deleted file mode 100644 index 22a8cda..0000000 --- a/src/display/curses_output.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __CURSES_OUTPUT_H__ -#define __CURSES_OUTPUT_H__ - -#include -#include -#include "../cursor.h" -#include "../display.h" - -class curses_output final : public display { -private: - cursor *curse; -public: - curses_output(cursor *new_curse); - - void render() override; - void clear() override; - void print_char(const position &pos, - const char ch, const int attrs) override; - void print_str(const position &pos, - const std::string &str, const int attrs) override; -}; - -#endif diff --git a/src/display/file_output.cc b/src/display/file_output.cc deleted file mode 100644 index 5408220..0000000 --- a/src/display/file_output.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include "file_output.h" - -#include - -#include "../constants.h" - -file_output::file_output(std::ofstream &&ofs): - out{std::move(ofs)} {} - -void file_output::render() { - for (std::size_t idx = 0; idx < contents.size(); ++idx) { - if (idx % DISPLAY_WIDTH == 0 && idx) - out << std::endl; - - out << (char)(contents[idx] ? contents[idx] : ' '); - } - - out << std::endl; -} - -void file_output::print_char(const position &pos, const char ch, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - contents[pos.y * DISPLAY_WIDTH + pos.x] = ch; -} - -void file_output::print_str(const position &pos, const std::string &str, - const int attrs) { - if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) - return; - - int head = pos.y * DISPLAY_WIDTH + pos.x; - - for (std::size_t i = 0; i < str.length(); ++i) - contents[i + head] = str[i]; -} diff --git a/src/display/file_output.h b/src/display/file_output.h deleted file mode 100644 index c53e4be..0000000 --- a/src/display/file_output.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __FILE_OUTPUT_H__ -#define __FILE_OUTPUT_H__ - -#include -#include "../display.h" - -class file_output final : public display { -private: - std::ofstream out; -public: - file_output(std::ofstream &&ofs); - - void render() override; - void print_char(const position &pos, - const char ch, const int attrs) override; - void print_str(const position &pos, - const std::string &str, const int attrs) override; -}; - -#endif diff --git a/src/enemies/dragon.cc b/src/enemies/dragon.cc index c8c21b9..0367a39 100644 --- a/src/enemies/dragon.cc +++ b/src/enemies/dragon.cc @@ -6,7 +6,7 @@ dragon::dragon(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, rdragon, pos, gen_room_num, "D"} {} -void dragon::print(display *out) { +void dragon::print(output *out) { out->print_char(pos, 'D', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/dragon.h b/src/enemies/dragon.h index 535e54f..346fc4a 100644 --- a/src/enemies/dragon.h +++ b/src/enemies/dragon.h @@ -7,7 +7,7 @@ class dragon final: public enemy_base { public: dragon(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; long_result act(level *lvl, character *pc, bool hostile) override; }; diff --git a/src/enemies/dwarf.cc b/src/enemies/dwarf.cc index c04f82c..6ca9495 100644 --- a/src/enemies/dwarf.cc +++ b/src/enemies/dwarf.cc @@ -6,7 +6,7 @@ dwarf::dwarf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, rdwarf, pos, gen_room_num, "W"} {} -void dwarf::print(display *out) { +void dwarf::print(output *out) { out->print_char(pos, 'W', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/dwarf.h b/src/enemies/dwarf.h index 850f9a9..cad3ca9 100644 --- a/src/enemies/dwarf.h +++ b/src/enemies/dwarf.h @@ -7,7 +7,7 @@ class dwarf final: public enemy_base { public: dwarf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; }; diff --git a/src/enemies/elf.cc b/src/enemies/elf.cc index 1d8b244..ed37011 100644 --- a/src/enemies/elf.cc +++ b/src/enemies/elf.cc @@ -6,7 +6,7 @@ elf::elf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, relf, pos, gen_room_num, "E"} {} -void elf::print(display *out) { +void elf::print(output *out) { out->print_char(pos, 'E', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/elf.h b/src/enemies/elf.h index 2e7f9f5..667d41f 100644 --- a/src/enemies/elf.h +++ b/src/enemies/elf.h @@ -7,7 +7,7 @@ class elf final: public enemy_base { public: elf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; long_result attack(character *ch) override; }; diff --git a/src/enemies/halfling.cc b/src/enemies/halfling.cc index 28be1b9..2e4bdc0 100644 --- a/src/enemies/halfling.cc +++ b/src/enemies/halfling.cc @@ -9,7 +9,7 @@ halfling::halfling(RNG *rng, const feature enabled_features, const int gen_room_num): enemy_base{rng, enabled_features, rhalfling, pos, gen_room_num, "L"} {} -void halfling::print(display *out) { +void halfling::print(output *out) { out->print_char(pos, 'L', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/halfling.h b/src/enemies/halfling.h index 5413646..34840f0 100644 --- a/src/enemies/halfling.h +++ b/src/enemies/halfling.h @@ -8,7 +8,7 @@ class halfling final: public enemy_base { public: halfling(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; long_result get_hit(character *ch, const int tATK, const fraction &hit_rate); diff --git a/src/enemies/human.cc b/src/enemies/human.cc index a6976ca..4ecbfe7 100644 --- a/src/enemies/human.cc +++ b/src/enemies/human.cc @@ -6,7 +6,7 @@ human::human(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, rhuman, pos, gen_room_num, "H"} {} -void human::print(display *out) { +void human::print(output *out) { out->print_char(pos, 'H', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/human.h b/src/enemies/human.h index 3eb6dbe..cace8fb 100644 --- a/src/enemies/human.h +++ b/src/enemies/human.h @@ -7,7 +7,7 @@ class human final: public enemy_base { public: human(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; }; diff --git a/src/enemies/merchant.cc b/src/enemies/merchant.cc index aa91c3a..200fb97 100644 --- a/src/enemies/merchant.cc +++ b/src/enemies/merchant.cc @@ -6,7 +6,7 @@ merchant::merchant(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, rmerchant, pos, gen_room_num, "M"} {} -void merchant::print(display *out) { +void merchant::print(output *out) { out->print_char(pos, 'M', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/merchant.h b/src/enemies/merchant.h index befbac6..86b903e 100644 --- a/src/enemies/merchant.h +++ b/src/enemies/merchant.h @@ -7,7 +7,7 @@ class merchant final: public enemy_base { public: merchant(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; }; diff --git a/src/enemies/orc.cc b/src/enemies/orc.cc index ebc61a8..41c6010 100644 --- a/src/enemies/orc.cc +++ b/src/enemies/orc.cc @@ -6,7 +6,7 @@ orc::orc(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num): enemy_base{rng, enabled_features, rorc, pos, gen_room_num, "O"} {} -void orc::print(display *out) { +void orc::print(output *out) { out->print_char(pos, 'O', COLOR_PAIR(COLOR_RED)); } diff --git a/src/enemies/orc.h b/src/enemies/orc.h index 42ae94c..26f13b2 100644 --- a/src/enemies/orc.h +++ b/src/enemies/orc.h @@ -7,7 +7,7 @@ class orc final: public enemy_base { public: orc(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(display *out) override; + void print(output *out) override; const char *get_race_name() const override; }; diff --git a/src/game.cc b/src/game.cc index 32e1b1e..8f41182 100644 --- a/src/game.cc +++ b/src/game.cc @@ -6,7 +6,7 @@ game::game(const enum race starting_race, const feature enabled_features, input *new_in, - display *new_out, + output *new_out, RNG *new_rng): enabled_features{enabled_features}, in{new_in}, out{new_out}, rng{new_rng}, diff --git a/src/game.h b/src/game.h index 74ead18..4b3a5ad 100644 --- a/src/game.h +++ b/src/game.h @@ -2,7 +2,7 @@ #define __GAME_H__ #include #include -#include "display.h" +#include "output.h" #include "input.h" #include "rng.h" #include "characters.h" @@ -22,7 +22,7 @@ private: const feature enabled_features; input *in; - display *out; + output *out; RNG *rng; unsigned int curr_turn; @@ -42,7 +42,7 @@ public: game(const enum race starting_race, const feature enabled_features, input *new_in, - display *new_out, + output *new_out, RNG *new_rng); game_result run(); size_t get_curr_level() const; diff --git a/src/level.cc b/src/level.cc index 48c52cf..6f66f5a 100644 --- a/src/level.cc +++ b/src/level.cc @@ -131,7 +131,7 @@ void level::gen_potions(RNG *rng, std::vector &tiles) { } } -void level::print(display *out) const { +void level::print(output *out) const { map.print(out); for (size_t i = 0; i < plist.size(); ++i) diff --git a/src/level.h b/src/level.h index 08e0c6d..34f6ca7 100644 --- a/src/level.h +++ b/src/level.h @@ -4,7 +4,7 @@ #include #include #include -#include "display.h" +#include "output.h" #include "gold.h" #include "enemies.h" #include "enemy.h" @@ -33,7 +33,7 @@ public: // read map from a string level(const std::string &map_data, character *player, RNG *rng, const feature enabled_features); - void print(display *out) const; + void print(output *out) const; bool is_available(const position &pos, bool is_player = false) const; bool is_available_all(const position &pos) const; diff --git a/src/main.cc b/src/main.cc index eba5c5d..0dff37a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,7 +7,7 @@ int main(int argc, char **argv) { std::unique_ptr curse; std::unique_ptr in; - std::unique_ptr out; + std::unique_ptr out; std::unique_ptr rng; feature enabled_features = proc_args(argc, argv, curse, in, out, rng); diff --git a/src/map.cc b/src/map.cc index a5af9dd..1e515cb 100644 --- a/src/map.cc +++ b/src/map.cc @@ -124,7 +124,7 @@ position_list game_map::get_available_around(const position &pos) const { return result; } -void game_map::print(display *out) const { +void game_map::print(output *out) const { for (std::size_t i = 0; i < map.size(); ++i) out->print_char(remap_index(i), map[i] <= 9 ? '.' : map[i], map[i] == '\\' || map[i] == '>' || diff --git a/src/map.h b/src/map.h index 717cad2..e0e5ba1 100644 --- a/src/map.h +++ b/src/map.h @@ -4,7 +4,7 @@ #include #include -#include "display.h" +#include "output.h" #include "position.h" #include "rng.h" #include "fraction.h" @@ -64,7 +64,7 @@ public: position_list get_room_list(int idx) const; std::vector get_room_list() const; // IMPORTANT: always print a map before anything else - void print(display *out) const; + void print(output *out) const; position get_up_stairs() const; position get_down_stairs() const; diff --git a/src/menu.cc b/src/menu.cc index 503985d..edd18f4 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -159,7 +159,7 @@ const char *MSG_NCURSES = "Move with movement commands, press 'e' to confirm, 'q' to quit."; const position SEED_POS = {1, 25}; -void menu::print(display *out, const unsigned int seed) { +void menu::print(output *out, const unsigned int seed) { if (enabled_features & FEATURE_EXTRA_STUFF) out->print_str({0, 0}, NORMAL_SCREEN); else diff --git a/src/menu.h b/src/menu.h index e8fc0e4..24fdf3b 100644 --- a/src/menu.h +++ b/src/menu.h @@ -2,7 +2,7 @@ #define __MENU_H__ #include "position.h" -#include "display.h" +#include "output.h" #include "input.h" typedef unsigned int feature; @@ -15,7 +15,7 @@ private: public: menu(const feature enabled_features); int run(input *in); - void print(display *out, const unsigned int seed); + void print(output *out, const unsigned int seed); }; #endif diff --git a/src/player.cc b/src/player.cc index f59a24e..2640d7b 100644 --- a/src/player.cc +++ b/src/player.cc @@ -8,7 +8,7 @@ player_base::player_base(RNG *rng, const feature enabled_features, const enum race &nrace): character{rng, enabled_features, nrace, {0, 0}}, gold_cnt(0) {} -void player_base::print(display *out) { +void player_base::print(output *out) { out->print_char(pos, '@', COLOR_PAIR(COLOR_BLUE)); } diff --git a/src/player.h b/src/player.h index 00a9398..6c8c3a3 100644 --- a/src/player.h +++ b/src/player.h @@ -23,7 +23,7 @@ public: virtual void add_gold(int amount); - void print(display *out) override; + void print(output *out) override; std::string get_abbrev() const override; diff --git a/src/potion.cc b/src/potion.cc index 3e4c67b..95751e0 100644 --- a/src/potion.cc +++ b/src/potion.cc @@ -43,7 +43,7 @@ potion &potion::operator=(potion &&p) { return *this; } -void potion::print(display *out) { +void potion::print(output *out) { out->print_char(pos, 'P', COLOR_PAIR(COLOR_GREEN)); } diff --git a/src/potion.h b/src/potion.h index ec62b43..745e889 100644 --- a/src/potion.h +++ b/src/potion.h @@ -3,7 +3,7 @@ #include #include "fraction.h" -#include "display.h" +#include "output.h" enum potion_type : int; enum race : int; @@ -36,7 +36,7 @@ public: void set_pos(const position &npos); virtual const char *get_name() const = 0; - virtual void print(display *out); + virtual void print(output *out); }; typedef std::vector potion_list; diff --git a/src/result.cc b/src/result.cc index c0c80fb..f60245b 100644 --- a/src/result.cc +++ b/src/result.cc @@ -39,7 +39,7 @@ void game_result::run(input *in) { in->get_command(); } -void game_result::print(display *out) { +void game_result::print(output *out) { out->print_str({0, 0}, WIN_SCREEN); out->print_str(MSG_START, msg, COLOR_PAIR(COLOR_YELLOW)); } diff --git a/src/result.h b/src/result.h index 38f64e3..8ad6dc6 100644 --- a/src/result.h +++ b/src/result.h @@ -2,7 +2,7 @@ #define __RESULT_H__ #include -#include "display.h" +#include "output.h" #include "input.h" enum game_status : int; @@ -12,7 +12,7 @@ struct game_result final { std::string msg; void run(input *in); - void print(display *out); + void print(output *out); }; #endif From e29b26303d10d795deb225105b0254a501970c59 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 16:54:19 -0400 Subject: [PATCH 7/8] removed character::move --- src/characters.cc | 11 ----------- src/characters.h | 2 -- src/player.h | 3 +-- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/characters.cc b/src/characters.cc index 0d664f4..6203f55 100644 --- a/src/characters.cc +++ b/src/characters.cc @@ -75,17 +75,6 @@ void character::discard_level_effects() { std::swap(tmp, effects); } -// IMPORTANT: remember to check if player is on the stairs -long_result character::move(level *lvl, - const position &p) { - if (lvl->is_available(p)) { - pos = p; - return {result::moved, ""}; - } - - return {result::fine, ""}; -} - int 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 888d476..5b9543f 100644 --- a/src/characters.h +++ b/src/characters.h @@ -22,8 +22,6 @@ public: character(RNG *rng, const feature enabled_features, const race &nrace, const position &pos); // fills out the starting stats - virtual long_result move(level *lvl, const position &p); - virtual long_result attack(character *ch) = 0; virtual long_result get_hit(character *ch, const int tATK, const fraction &hit_rate) = 0; diff --git a/src/player.h b/src/player.h index 6c8c3a3..0139bc4 100644 --- a/src/player.h +++ b/src/player.h @@ -12,8 +12,7 @@ protected: public: player_base(RNG *rng, const feature enabled_features, const enum race &nrace); - virtual long_result move(level *lvl, - const position &p) override; + virtual long_result move(level *lvl, const position &p); virtual long_result apply(potion *p); From 356bfb3b2ecd9d04646e3e7b9bcf9b47fb44229f Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 16:57:14 -0400 Subject: [PATCH 8/8] stripped some unused files --- src/room.h | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/room.h diff --git a/src/room.h b/src/room.h deleted file mode 100644 index 1c4196e..0000000 --- a/src/room.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef __ROOM_H__ -#define __ROOM_H__ - -#endif