From 295b808e144d8ea028fd3eca1330de646eac46f0 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Mon, 15 Jul 2024 14:41:32 -0400 Subject: [PATCH] =?UTF-8?q?fixed:=201.=20potions=20being=20walked=20over?= =?UTF-8?q?=202.=20spawning=20on=20stairs=203.=20enemies=20walking=20under?= =?UTF-8?q?=20players=204.=20merchants=20not=20being=20aggresive=205.=20po?= =?UTF-8?q?tions=20losing=20effect=20when=20sending=20pass=20signal=20(cle?= =?UTF-8?q?ared=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);