From c9e96b5e6e10b4f4a4c6d72dc805fe575441d5cc Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Fri, 12 Jul 2024 09:58:30 -0400 Subject: [PATCH] changed unique_ptr access to using raw pointers to denote non-ownership added new flag -e for extra stuff (potions/races) IMPORTANT: main.cc is undergoing rework --- src/arguments.cc | 6 ++++-- src/arguments.h | 1 + src/constants.h | 1 + src/curses_input.cc | 6 +++--- src/curses_input.h | 4 ++-- src/curses_output.cc | 10 +++++----- src/curses_output.h | 4 ++-- src/game.h | 16 ++++++++-------- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/arguments.cc b/src/arguments.cc index 1b2462f..f9d27f1 100644 --- a/src/arguments.cc +++ b/src/arguments.cc @@ -47,6 +47,8 @@ feature proc_args(int argc, char **argv, result |= FEATURE_THROW; } else if (str == "-R") { result |= FEATURE_REVISIT; + } else if (str == "-e") { + result |= FEATURE_EXTRA_STUFF; } else if (str == "-s") { ++i; str = argv[i]; @@ -121,8 +123,8 @@ feature proc_args(int argc, char **argv, if (result & FEATURE_NCURSES) { curse = std::make_unique(); - in = std::make_unique(*curse); - out = std::make_unique(*curse); + in = std::make_unique(curse.get()); + out = std::make_unique(curse.get()); } if (result & FEATURE_SEED) { diff --git a/src/arguments.h b/src/arguments.h index 9af55de..0c0d088 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -18,6 +18,7 @@ -i : Enable inventory -t : Enable throw -R : Enable revisiting levels +-e : Enable extra potions and races -s [seed] : Sets initial seed to seed -L [file] : Enable logging to file -I [file] : Reads commands from file. CANNOT BE USED WITH -n. diff --git a/src/constants.h b/src/constants.h index d9c7962..7161acb 100644 --- a/src/constants.h +++ b/src/constants.h @@ -92,6 +92,7 @@ const feature FEATURE_SEED = 1 << 7; const feature FEATURE_MENU = 1 << 8; const feature FEATURE_IN_FILE = 1 << 9; const feature FEATURE_OUT_FILE = 1 << 10; +const feature FEATURE_EXTRA_STUFF = 1 << 11; const feature FEATURE_PANIC_SEED = 1 << 27; const feature FEATURE_PANIC_FILE = 1 << 28; diff --git a/src/curses_input.cc b/src/curses_input.cc index 44319c3..dfcab87 100644 --- a/src/curses_input.cc +++ b/src/curses_input.cc @@ -1,10 +1,10 @@ #include "curses_input.h" -curses_input::curses_input(cursor &new_curse): +curses_input::curses_input(cursor *new_curse): curse{new_curse} {} game_command curses_input::get_command() { - switch (curse.getcmd()) { + switch (curse->getcmd()) { case 'h': return game_command::move_west; @@ -51,7 +51,7 @@ game_command curses_input::get_command() { return game_command_pass; } - switch (curse.getcmd()) { + switch (curse->getcmd()) { case 'h': return game_command::apply_west; diff --git a/src/curses_input.h b/src/curses_input.h index 0f7808a..3d34d5c 100644 --- a/src/curses_input.h +++ b/src/curses_input.h @@ -8,9 +8,9 @@ class curses_input final: public input { private: - cursor &curse; + cursor *curse; public: - curses_input(cursor &new_curse); + curses_input(cursor *new_curse); game_command get_command() override; }; diff --git a/src/curses_output.cc b/src/curses_output.cc index ac4d8e8..e85a278 100644 --- a/src/curses_output.cc +++ b/src/curses_output.cc @@ -1,14 +1,14 @@ #include "curses_output.h" -curses_output::curses_output(cursor &new_curse): +curses_output::curses_output(cursor *new_curse): curse{new_curse} {} void curses_output::render() { - curse.show(); + curse->show(); } void curses_output::clear() { - curse.clear(); + curse->clear(); } void curses_output::print_char(const position &pos, const char ch, @@ -16,7 +16,7 @@ void curses_output::print_char(const position &pos, const char ch, if (pos.x >= DISPLAY_WIDTH || pos.y >= DISPLAY_HEIGHT) return; - curse.print_char(pos, ch, attrs); + curse->print_char(pos, ch, attrs); } void curses_output::print_str(const position &pos, const std::string &str, @@ -27,7 +27,7 @@ void curses_output::print_str(const position &pos, const std::string &str, position tmp = pos; for (std::size_t i = 0; i < str.length(); ++i) { - curse.print_char(tmp, str[i], attrs); + curse->print_char(tmp, str[i], attrs); tmp += {1, 0}; if (tmp.x >= DISPLAY_WIDTH) diff --git a/src/curses_output.h b/src/curses_output.h index 7024ec6..123bd67 100644 --- a/src/curses_output.h +++ b/src/curses_output.h @@ -8,9 +8,9 @@ class curses_output final : public display { private: - cursor &curse; + cursor *curse; public: - curses_output(cursor &new_curse); + curses_output(cursor *new_curse); void render() override; void clear() override; diff --git a/src/game.h b/src/game.h index f79aa5d..27198ab 100644 --- a/src/game.h +++ b/src/game.h @@ -13,19 +13,19 @@ class game final { private: feature features; - input ∈ - display &out; - logger &log; - RNG &rng; + input *in; + display *out; + logger *log; + RNG *rng; // IMPORTANT: during player generation, std::unique_ptr player; public: game(const feature enabled_features, - input &new_in, - display &new_out, - logger &new_log, - RNG &new_rng); + input *new_in, + display *new_out, + logger *new_log, + RNG *new_rng); game_status run(); private: int getcmd() const;