From 1a9c04ad5a95b3a87e976bc827be4062dd1c08db Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Thu, 18 Jul 2024 17:56:00 -0400 Subject: [PATCH] removed all C-style casts --- src/Makefile | 2 +- src/cc3k.cc | 7 ++++--- src/constants.h | 23 +++++++++++++++-------- src/enemies/dragon.cc | 8 ++++---- src/enemies/dragon.h | 2 +- src/enemies/dwarf.cc | 4 ---- src/enemies/dwarf.h | 1 - src/enemies/elf.cc | 4 ---- src/enemies/elf.h | 1 - src/enemies/halfling.cc | 4 ---- src/enemies/halfling.h | 3 +-- src/enemies/human.cc | 12 ++++++++---- src/enemies/human.h | 2 +- src/enemies/leprechaun.cc | 32 ++++++++++++++++++++++++++++++++ src/enemies/leprechaun.h | 18 ++++++++++++++++++ src/enemies/merchant.cc | 11 +++++++---- src/enemies/merchant.h | 2 +- src/enemies/orc.cc | 4 ---- src/enemies/orc.h | 1 - src/enemies/swordsman.cc | 12 ++++++++++++ src/enemies/swordsman.h | 13 +++++++++++++ src/enemies/viking.cc | 27 +++++++++++++++++++++++++++ src/enemies/viking.h | 14 ++++++++++++++ src/enemy.cc | 16 ++++------------ src/enemy.h | 2 ++ src/fraction.cc | 2 +- src/game.cc | 2 +- src/input.cc | 2 +- src/input/console_input.cc | 12 ++++++++---- src/input/curses_input.cc | 24 ++++++++++++++++-------- src/input/file_input.cc | 9 +++++---- src/level.cc | 3 ++- src/map.cc | 6 +++--- src/output/console_output.cc | 2 +- src/output/file_output.cc | 2 +- src/player.cc | 15 ++++++++------- 36 files changed, 212 insertions(+), 92 deletions(-) create mode 100644 src/enemies/leprechaun.cc create mode 100644 src/enemies/leprechaun.h create mode 100644 src/enemies/swordsman.cc create mode 100644 src/enemies/swordsman.h create mode 100644 src/enemies/viking.cc create mode 100644 src/enemies/viking.h diff --git a/src/Makefile b/src/Makefile index 897e856..e6ac7c4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ ########## Variables ########## CXX = g++ # compiler -CXXFLAGS = -std=c++20 -g -Wall -MMD -O0 # compiler flags +CXXFLAGS = -std=c++20 -g -Wall -Wold-style-cast -MMD -O0 # compiler flags MAKEFILE_NAME = ${firstword ${MAKEFILE_LIST}} # makefile name SOURCES = $(wildcard *.cc) $(wildcard */*.cc) # source files (*.cc) diff --git a/src/cc3k.cc b/src/cc3k.cc index 54e5466..8cdc04b 100644 --- a/src/cc3k.cc +++ b/src/cc3k.cc @@ -25,9 +25,10 @@ game_status CC3K::run() { if (tmp != -1) { curr_menu.reset(); - curr_game = std::make_unique((race)tmp, - enabled_features, - in, out, rng); + curr_game = + std::make_unique(static_cast(tmp), + enabled_features, + in, out, rng); out->clear(); curr_game->print(); out->render(); diff --git a/src/constants.h b/src/constants.h index aca06a0..ef45771 100644 --- a/src/constants.h +++ b/src/constants.h @@ -46,39 +46,46 @@ enum game_command : int {game_command_terminate = 0, }; // Character generation related -static const int RACE_CNT = 17; +static const int RACE_CNT = 23; enum race : int {rshade = 0, rdrow, rvampire, rtroll, rgoblin, rhuman, rdwarf, relf, rorc, rmerchant, rdragon, rhalfling, rt_800, rmr_goose, rmonk, rbrawler, - rassassin + rassassin, rviking, rswordsman, + rleprechaun, rwitch, rhacker, rbaby_dragon }; static const char CHAR_REP[RACE_CNT] = { 's', 'd', 'v', 't', 'g', 'H', 'W', 'E', 'O', 'M', 'D', 'L', - 't', 'g', 'm', 'b', 'a' + 't', 'g', 'm', 'b', 'a', + 'V', 'S', 'l', 'W', 'h', 'B' }; static const int MAX_HP[RACE_CNT] = { 125, 150, INF, 120, 110, 140, 100, 140, 180, 30, 150, 100, - 800, 130, 150, 120, 100 + 800, 130, 150, 120, 100, + 150, 100, 60, 100, 90, 140 }; static const int STARTING_HP[RACE_CNT] = { 125, 150, 50, 120, 110, 140, 100, 140, 180, 30, 150, 100, - 800, 130, 150, 120, 100 + 800, 130, 150, 120, 100, + 150, 100, 60, 100, 90, 140 }; static const int STARTING_ATK[RACE_CNT] = { 25, 25, 25, 25, 15, 20, 20, 30, 30, 70, 20, 15, - 40, 25, 80, 15, 30 + 40, 25, 80, 15, 30, + 30, 25, 10, 20, 15, 25 }; static const int STARTING_DEF[RACE_CNT] = { 25, 15, 25, 15, 20, 20, 30, 10, 25, 5, 20, 20, - 50, 20, 0, 20, 10 + 50, 20, 0, 20, 10, + 25, 15, 15, 15, 30, 40 }; static const fraction STARTING_HR[RACE_CNT] = { {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, - {1, 1}, {1, 1}, {100, 1}, {3, 4}, {1, 1} + {1, 1}, {1, 1}, {100, 1}, {3, 4}, {1, 1}, + {1, 3}, {1, 1}, {1, 2}, {1, 2}, {1, 2}, {1, 3} }; diff --git a/src/enemies/dragon.cc b/src/enemies/dragon.cc index 0367a39..03313c4 100644 --- a/src/enemies/dragon.cc +++ b/src/enemies/dragon.cc @@ -6,10 +6,6 @@ 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(output *out) { - out->print_char(pos, 'D', COLOR_PAIR(COLOR_RED)); -} - const char *dragon::get_race_name() const { return "Dragon"; } @@ -20,3 +16,7 @@ long_result dragon::act(level *lvl, character *pc, bool hostile) { return {fine, ""}; } + +int dragon::dies(level *lvl) { + return 0; +} diff --git a/src/enemies/dragon.h b/src/enemies/dragon.h index 346fc4a..0316265 100644 --- a/src/enemies/dragon.h +++ b/src/enemies/dragon.h @@ -7,9 +7,9 @@ class dragon final: public enemy_base { public: dragon(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(output *out) override; const char *get_race_name() const override; long_result act(level *lvl, character *pc, bool hostile) override; + int dies(level *lvl) override; }; #endif diff --git a/src/enemies/dwarf.cc b/src/enemies/dwarf.cc index 6ca9495..a92825b 100644 --- a/src/enemies/dwarf.cc +++ b/src/enemies/dwarf.cc @@ -6,10 +6,6 @@ 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(output *out) { - out->print_char(pos, 'W', COLOR_PAIR(COLOR_RED)); -} - const char *dwarf::get_race_name() const { return "Dwarf"; } diff --git a/src/enemies/dwarf.h b/src/enemies/dwarf.h index cad3ca9..efe02c6 100644 --- a/src/enemies/dwarf.h +++ b/src/enemies/dwarf.h @@ -7,7 +7,6 @@ class dwarf final: public enemy_base { public: dwarf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - 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 dc292e0..e071e9b 100644 --- a/src/enemies/elf.cc +++ b/src/enemies/elf.cc @@ -6,10 +6,6 @@ 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(output *out) { - out->print_char(pos, 'E', COLOR_PAIR(COLOR_RED)); -} - const char *elf::get_race_name() const { return "Elf"; } diff --git a/src/enemies/elf.h b/src/enemies/elf.h index 667d41f..d416a33 100644 --- a/src/enemies/elf.h +++ b/src/enemies/elf.h @@ -7,7 +7,6 @@ class elf final: public enemy_base { public: elf(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - 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 2e4bdc0..47d74d2 100644 --- a/src/enemies/halfling.cc +++ b/src/enemies/halfling.cc @@ -9,10 +9,6 @@ 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(output *out) { - out->print_char(pos, 'L', COLOR_PAIR(COLOR_RED)); -} - const char *halfling::get_race_name() const { return "Halfling"; } diff --git a/src/enemies/halfling.h b/src/enemies/halfling.h index 34840f0..6c8cd8f 100644 --- a/src/enemies/halfling.h +++ b/src/enemies/halfling.h @@ -8,10 +8,9 @@ class halfling final: public enemy_base { public: halfling(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - 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); + const fraction &hit_rate) override; }; #endif diff --git a/src/enemies/human.cc b/src/enemies/human.cc index 4ecbfe7..c0685ba 100644 --- a/src/enemies/human.cc +++ b/src/enemies/human.cc @@ -1,15 +1,19 @@ #include "human.h" #include "../constants.h" +#include "../level.h" 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(output *out) { - out->print_char(pos, 'H', COLOR_PAIR(COLOR_RED)); -} - const char *human::get_race_name() const { return "Human"; } + +int human::dies(level *lvl) { + lvl->add_gold(gold{pos, GOLD_NORMAL}); + auto plist = lvl->get_available_around_all(pos); + lvl->add_gold(gold{rng->get_rand_in_vector(plist), GOLD_NORMAL}); + return 0; +} diff --git a/src/enemies/human.h b/src/enemies/human.h index cace8fb..b6179a9 100644 --- a/src/enemies/human.h +++ b/src/enemies/human.h @@ -7,8 +7,8 @@ class human final: public enemy_base { public: human(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(output *out) override; const char *get_race_name() const override; + int dies(level *lvl) override; }; #endif diff --git a/src/enemies/leprechaun.cc b/src/enemies/leprechaun.cc new file mode 100644 index 0000000..e82dbba --- /dev/null +++ b/src/enemies/leprechaun.cc @@ -0,0 +1,32 @@ +#include "leprechaun.h" + +#include "../constants.h" +#include "../player.h" + +leprechaun::leprechaun(RNG *rng, const feature enabled_features, + const position &pos, + const int gen_room_num): + enemy_base{rng, enabled_features, rleprechaun, pos, gen_room_num, "l"} {} + +const char *leprechaun::get_race_name() const { + return "Leprechaun"; +} + +long_result leprechaun::attack(character *ch) { + long_result res; + + if (static_cast(ch)->get_gold() < STEAL_GOLD) { + res = ch->get_hit(this, BOOSTED_ATK, base_hit_rate); + res.msg = "l is angered because PC is too poor. " + res.msg; + } else { + res = ch->get_hit(this, ATK, base_hit_rate); + + if (res.res == hit) { + res.msg += "l steals " + std::to_string(STEAL_GOLD) + + " pieces of gold from PC. "; + static_cast(ch)->add_gold(-STEAL_GOLD); + } + } + + return res; +} diff --git a/src/enemies/leprechaun.h b/src/enemies/leprechaun.h new file mode 100644 index 0000000..c102a15 --- /dev/null +++ b/src/enemies/leprechaun.h @@ -0,0 +1,18 @@ +#ifndef __LEPRECHAUN_H__ +#define __LEPRECHAUN_H__ + +#include "../enemy.h" + +class leprechaun final: public enemy_base { + static const int STEAL_GOLD = 3; + static const int BOOSTED_ATK = 30; + static const int STARTING_GOLD = 5; + int gold_cnt; +public: + leprechaun(RNG *rng, const feature enabled_features, const position &pos, + const int gen_room_num); + const char *get_race_name() const override; + virtual long_result attack(character *ch) override; +}; + +#endif diff --git a/src/enemies/merchant.cc b/src/enemies/merchant.cc index 200fb97..3d33cc5 100644 --- a/src/enemies/merchant.cc +++ b/src/enemies/merchant.cc @@ -1,15 +1,18 @@ #include "merchant.h" #include "../constants.h" +#include "../gold.h" +#include "../level.h" 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(output *out) { - out->print_char(pos, 'M', COLOR_PAIR(COLOR_RED)); -} - const char *merchant::get_race_name() const { return "Merchant"; } + +int merchant::dies(level *lvl) { + lvl->add_gold(gold{pos, GOLD_MERCHANT}); + return 0; +} diff --git a/src/enemies/merchant.h b/src/enemies/merchant.h index 86b903e..b9dd030 100644 --- a/src/enemies/merchant.h +++ b/src/enemies/merchant.h @@ -7,8 +7,8 @@ class merchant final: public enemy_base { public: merchant(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(output *out) override; const char *get_race_name() const override; + int dies(level *lvl) override; }; #endif diff --git a/src/enemies/orc.cc b/src/enemies/orc.cc index 41c6010..dfdbfa9 100644 --- a/src/enemies/orc.cc +++ b/src/enemies/orc.cc @@ -6,10 +6,6 @@ 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(output *out) { - out->print_char(pos, 'O', COLOR_PAIR(COLOR_RED)); -} - const char *orc::get_race_name() const { return "Orc"; } diff --git a/src/enemies/orc.h b/src/enemies/orc.h index 26f13b2..f11913d 100644 --- a/src/enemies/orc.h +++ b/src/enemies/orc.h @@ -7,7 +7,6 @@ class orc final: public enemy_base { public: orc(RNG *rng, const feature enabled_features, const position &pos, const int gen_room_num); - void print(output *out) override; const char *get_race_name() const override; }; diff --git a/src/enemies/swordsman.cc b/src/enemies/swordsman.cc new file mode 100644 index 0000000..cdaf9b7 --- /dev/null +++ b/src/enemies/swordsman.cc @@ -0,0 +1,12 @@ +#include "swordsman.h" + +#include "../constants.h" + +swordsman::swordsman(RNG *rng, const feature enabled_features, + const position &pos, + const int gen_room_num): + enemy_base{rng, enabled_features, rswordsman, pos, gen_room_num, "S"} {} + +const char *swordsman::get_race_name() const { + return "Swordsman"; +} diff --git a/src/enemies/swordsman.h b/src/enemies/swordsman.h new file mode 100644 index 0000000..08578e7 --- /dev/null +++ b/src/enemies/swordsman.h @@ -0,0 +1,13 @@ +#ifndef __SWORDSMAN_H__ +#define __SWORDSMAN_H__ + +#include "../enemy.h" + +class swordsman final: public enemy_base { +public: + swordsman(RNG *rng, const feature enabled_features, const position &pos, + const int gen_room_num); + const char *get_race_name() const override; +}; + +#endif diff --git a/src/enemies/viking.cc b/src/enemies/viking.cc new file mode 100644 index 0000000..ab0d8b1 --- /dev/null +++ b/src/enemies/viking.cc @@ -0,0 +1,27 @@ +#include "viking.h" + +#include "../constants.h" + +viking::viking(RNG *rng, const feature enabled_features, const position &pos, + const int gen_room_num): + enemy_base{rng, enabled_features, rviking, pos, gen_room_num, "V"} {} + +const char *viking::get_race_name() const { + return "Viking"; +} + +long_result viking::attack(character *ch) { + auto res1 = ch->get_hit(this, ATK, base_hit_rate); + + if (res1.res == result::died) + return res1; + + auto res2 = ch->get_hit(this, ATK, base_hit_rate); + + if (res1.res == miss && res2.res == miss) + return {miss, res1.msg + res2.msg}; + else if (res2.res == died) + return {died, res1.msg + res2.msg}; + else + return {hit, res1.msg + res2.msg}; +} diff --git a/src/enemies/viking.h b/src/enemies/viking.h new file mode 100644 index 0000000..0fb19af --- /dev/null +++ b/src/enemies/viking.h @@ -0,0 +1,14 @@ +#ifndef __VIKING_H__ +#define __VIKING_H__ + +#include "../enemy.h" + +class viking final: public enemy_base { +public: + viking(RNG *rng, const feature enabled_features, const position &pos, + const int gen_room_num); + const char *get_race_name() const override; + long_result attack(character *ch) override; +}; + +#endif diff --git a/src/enemy.cc b/src/enemy.cc index 2e43b2f..5ca39f8 100644 --- a/src/enemy.cc +++ b/src/enemy.cc @@ -87,18 +87,6 @@ long_result enemy_base::get_hit(character *ch, const int tATK, } int enemy_base::dies(level *lvl) { - if (race == race::rdragon) { - return 0; - } else if (race == race::rmerchant) { - lvl->add_gold(gold{pos, GOLD_MERCHANT}); - return 0; - } else if (race == race::rhuman) { - lvl->add_gold(gold{pos, GOLD_NORMAL}); - auto plist = lvl->get_available_around_all(pos); - lvl->add_gold(gold{rng->get_rand_in_vector(plist), GOLD_NORMAL}); - return 0; - } - return rand_gold_drop(rng); } @@ -109,3 +97,7 @@ enemy_base *get_enemy_at(const position &pos, const enemy_list &elist) { return nullptr; } + +void enemy_base::print(output *out) { + out->print_char(pos, CHAR_REP[race], COLOR_PAIR(COLOR_RED)); +} diff --git a/src/enemy.h b/src/enemy.h index aed9034..92e7eda 100644 --- a/src/enemy.h +++ b/src/enemy.h @@ -24,6 +24,8 @@ public: virtual long_result get_hit(character *ch, const int tATK, const fraction &hit_rate) override; + void print(output *out) override; + virtual std::string get_abbrev() const override; virtual int dies(level *lvl); diff --git a/src/fraction.cc b/src/fraction.cc index 7910b86..1578eb7 100644 --- a/src/fraction.cc +++ b/src/fraction.cc @@ -33,7 +33,7 @@ fraction &fraction::simplify() { } float fraction::real() const { - return (float)numerator / denominator; + return static_cast(numerator) / denominator; } int fraction::gcd(int a, int b) { diff --git a/src/game.cc b/src/game.cc index 9e0cf0b..ae7b23f 100644 --- a/src/game.cc +++ b/src/game.cc @@ -178,7 +178,7 @@ game_result game::run() { if (killer == nullptr) return {dead, "You died: killed by your own stupidity!"}; - return {dead, (std::string)"You died: killed by a(n) " + + return {dead, std::string{"You died: killed by a(n) "} + killer->get_race_name()}; } diff --git a/src/input.cc b/src/input.cc index 7dddf6a..e0a3ab3 100644 --- a/src/input.cc +++ b/src/input.cc @@ -10,7 +10,7 @@ const int COMMANDS_CNT = 8; game_command get_direction(std::string &str) { for (int i = 0; i < COMMANDS_CNT; ++i) if (str == COMMANDS[i]) - return (game_command)i; + return static_cast(i); return game_command_panic; } diff --git a/src/input/console_input.cc b/src/input/console_input.cc index efbbcba..a3995be 100644 --- a/src/input/console_input.cc +++ b/src/input/console_input.cc @@ -30,11 +30,14 @@ game_command console_input::get_command() { auto tmp = get_direction(cmd); if (cmdtmp == "u") - return (game_command)(tmp + apply_north); + return static_cast + (tmp + apply_north); else if (cmdtmp == "a") - return (game_command)(tmp + attack_north); + return static_cast + (tmp + attack_north); else - return (game_command)(tmp + throw_north); + return static_cast + (tmp + throw_north); } else if (cmd == "yes") { return game_command::enter; } else if (cmd == "i") { @@ -43,7 +46,8 @@ game_command console_input::get_command() { auto tmp = get_direction(cmd); if (tmp != game_command_panic) - return (game_command)(tmp + move_north); + return static_cast + (tmp + move_north); } return game_command_pass; diff --git a/src/input/curses_input.cc b/src/input/curses_input.cc index 1a2adf0..7a833ea 100644 --- a/src/input/curses_input.cc +++ b/src/input/curses_input.cc @@ -68,28 +68,36 @@ game_command curses_input::get_command() { switch (curse->getcmd()) { case 'h': - return (game_command)(tmp + west); + return static_cast + (tmp + west); case 'j': - return (game_command)(tmp + south); + return static_cast + (tmp + south); case 'k': - return (game_command)(tmp + north); + return static_cast + (tmp + north); case 'l': - return (game_command)(tmp + east); + return static_cast + (tmp + east); case 'y': - return (game_command)(tmp + northwest); + return static_cast + (tmp + northwest); case 'u': - return (game_command)(tmp + northeast); + return static_cast + (tmp + northeast); case 'b': - return (game_command)(tmp + southwest); + return static_cast + (tmp + southwest); case 'n': - return (game_command)(tmp + southeast); + return static_cast + (tmp + southeast); default: return game_command_panic; diff --git a/src/input/file_input.cc b/src/input/file_input.cc index a70aa16..6029ee5 100644 --- a/src/input/file_input.cc +++ b/src/input/file_input.cc @@ -30,11 +30,11 @@ game_command file_input::get_command() { auto tmp = get_direction(cmd); if (cmdtmp == "u") - return (game_command)(tmp + apply_north); + return static_cast(tmp + apply_north); else if (cmdtmp == "a") - return (game_command)(tmp + attack_north); + return static_cast(tmp + attack_north); else - return (game_command)(tmp + throw_north); + return static_cast(tmp + throw_north); } else if (cmd == "yes") { return game_command::enter; } else if (cmd == "i") { @@ -43,7 +43,8 @@ game_command file_input::get_command() { auto tmp = get_direction(cmd); if (tmp != game_command_panic) - return tmp; + return static_cast + (tmp + move_north); } return game_command_pass; diff --git a/src/level.cc b/src/level.cc index ee1bc89..ae2a3ab 100644 --- a/src/level.cc +++ b/src/level.cc @@ -136,7 +136,8 @@ void level::gen_potions(RNG *rng, std::vector &tiles) { pplist.reserve(cnt); for (int i = 0; i < cnt; ++i) { - pplist.push_back(new_potion((potion_type)rng->rand_under(max_type), + pplist.push_back(new_potion(static_cast + (rng->rand_under(max_type)), get_rand_pos(rng, tiles))); plist.push_back(pplist[i].get()); } diff --git a/src/map.cc b/src/map.cc index 6448a14..7aff8e4 100644 --- a/src/map.cc +++ b/src/map.cc @@ -269,8 +269,8 @@ std::vector game_map::distr_rooms(RNG *rng, // and the max height of the layer for (std::size_t i = 0; i < room_dims.size(); ++i) if (room_dims[i].second == layer) { - l = std::min(l, (int)i); - r = std::max(r, (int)i); + l = std::min(l, static_cast(i)); + r = std::max(r, static_cast(i)); layer_height = std::max(layer_height, room_dims[i].first.y); } @@ -281,7 +281,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/output/console_output.cc b/src/output/console_output.cc index beff4c2..8aa3c83 100644 --- a/src/output/console_output.cc +++ b/src/output/console_output.cc @@ -74,7 +74,7 @@ void console_output::render() { out << std::endl; out << get_code(contents[idx]) - << (char)(contents[idx] ? contents[idx] : ' '); + << static_cast(contents[idx] ? contents[idx] : ' '); } out << std::endl; diff --git a/src/output/file_output.cc b/src/output/file_output.cc index 5408220..80c0e4b 100644 --- a/src/output/file_output.cc +++ b/src/output/file_output.cc @@ -12,7 +12,7 @@ void file_output::render() { if (idx % DISPLAY_WIDTH == 0 && idx) out << std::endl; - out << (char)(contents[idx] ? contents[idx] : ' '); + out << static_cast(contents[idx] ? contents[idx] : ' '); } out << std::endl; diff --git a/src/player.cc b/src/player.cc index b120014..e2c4f51 100644 --- a/src/player.cc +++ b/src/player.cc @@ -72,7 +72,7 @@ long_result player_base::move(level *lvl, pos = p; return {result::moved, ""}; } else if ((tmp = get_enemy_at(p, lvl->get_elist())) != nullptr) { - auto res = attack((character *)tmp); + auto res = attack(static_cast(tmp)); if (tmp->is_dead()) { int g = tmp->dies(lvl); @@ -170,7 +170,7 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) { } else { inv.enabled = false; return throw_potion(lvl, std::move(res.first), - (direction)res.second); + static_cast(res.second)); } } } @@ -213,7 +213,7 @@ long_result player_base::interpret_command(level *lvl, game_command cmd) { enemy_base *tmp = get_enemy_at(pos + MOVE[cmd - attack_north], lvl->get_elist()); - auto res = attack((character *)tmp); + auto res = attack(static_cast(tmp)); if (tmp != nullptr && tmp->is_dead()) { int g = tmp->dies(lvl); @@ -284,7 +284,8 @@ std::pair, int> player_base::inventory::run( if (owns.size()) { std::unique_ptr tmp = std::move(owns[curr]); owns.erase(owns.begin() + curr); - return {std::move(tmp), (direction)(cmd - throw_north)}; + return {std::move(tmp), + static_cast(cmd - throw_north)}; } return {nullptr, DIRECTION_CNT}; @@ -322,14 +323,14 @@ void player_base::inventory::print(output *out, unsigned long known_potions) { for (size_t i = 0; i < owns.size(); ++i) { out->print_str({INV_LEFT + INV_POTION_OFFSET, - (int) i + INV_TOP + INV_Y_OFFSET}, + static_cast(i) + INV_TOP + INV_Y_OFFSET}, "potion of " + (known_potions & (1 << owns[i]->get_type()) ? - owns[i]->get_name() : (std::string)"??")); + owns[i]->get_name() : std::string{"??"})); } if (owns.size()) out->print_str({INV_LEFT + INV_CURSOR_OFFSET, - (int)curr + INV_TOP + INV_Y_OFFSET}, + static_cast(curr) + INV_TOP + INV_Y_OFFSET}, "->"); }