diff --git a/.gitignore b/.gitignore index b109400..c38e173 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ -build/* +build/ +cmake-build-*/ tcod/ +.idea/ *.a *.o *.lib diff --git a/include/Pataro/Animation.hpp b/include/Pataro/Animation.hpp index 299bf4f..cb02073 100644 --- a/include/Pataro/Animation.hpp +++ b/include/Pataro/Animation.hpp @@ -19,7 +19,7 @@ namespace pat * * @param source the entity to which the animation should be applied */ - Animation(Entity* source); + explicit Animation(Entity* source); /** * @brief Add a frame, after a given duration, executes once the given operation @@ -67,7 +67,7 @@ namespace pat * @return true * @return false */ - bool is_finished() const; + [[nodiscard]] bool is_finished() const; private: std::size_t m_current = 0; diff --git a/include/Pataro/Components/AI.hpp b/include/Pataro/Components/AI.hpp index 7efaed6..06a93ab 100644 --- a/include/Pataro/Components/AI.hpp +++ b/include/Pataro/Components/AI.hpp @@ -27,10 +27,10 @@ namespace pat::component */ virtual std::unique_ptr update(Entity* owner, Engine* engine) = 0; - inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } + [[nodiscard]] inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } protected: - virtual AI* clone_impl() const = 0; + [[nodiscard]] virtual AI* clone_impl() const = 0; }; } diff --git a/include/Pataro/Components/AI/ConfusedMonster.hpp b/include/Pataro/Components/AI/ConfusedMonster.hpp index 604d223..ec00618 100644 --- a/include/Pataro/Components/AI/ConfusedMonster.hpp +++ b/include/Pataro/Components/AI/ConfusedMonster.hpp @@ -35,7 +35,7 @@ namespace pat::component std::unique_ptr update(Entity* owner, Engine* engine) override; protected: - virtual ConfusedMonsterAI* clone_impl() const override; + [[nodiscard]] ConfusedMonsterAI* clone_impl() const override; private: int m_nb_turns; diff --git a/include/Pataro/Components/AI/Monster.hpp b/include/Pataro/Components/AI/Monster.hpp index bb06b1a..6de9fc9 100644 --- a/include/Pataro/Components/AI/Monster.hpp +++ b/include/Pataro/Components/AI/Monster.hpp @@ -27,7 +27,7 @@ namespace pat::component std::unique_ptr update(Entity* owner, Engine* engine) override; protected: - virtual MonsterAI* clone_impl() const override; + [[nodiscard]] MonsterAI* clone_impl() const override; private: /** diff --git a/include/Pataro/Components/AI/Player.hpp b/include/Pataro/Components/AI/Player.hpp index 49fe86f..712c08f 100644 --- a/include/Pataro/Components/AI/Player.hpp +++ b/include/Pataro/Components/AI/Player.hpp @@ -37,7 +37,7 @@ namespace pat::component */ std::unique_ptr handle_action_key(Entity* owner, Engine* engine, int keycode); - virtual PlayerAI* clone_impl() const override; + [[nodiscard]] PlayerAI* clone_impl() const override; }; } diff --git a/include/Pataro/Components/Attacker.hpp b/include/Pataro/Components/Attacker.hpp index 3a2eecf..ef80723 100644 --- a/include/Pataro/Components/Attacker.hpp +++ b/include/Pataro/Components/Attacker.hpp @@ -19,16 +19,16 @@ namespace pat::component * * @param power */ - Attacker(float power); + explicit Attacker(float power); virtual ~Attacker() = default; - inline float power() const { return m_power; } + [[nodiscard]] inline float power() const { return m_power; } - inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } + [[nodiscard]] inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } protected: - virtual Attacker* clone_impl() const; + [[nodiscard]] virtual Attacker* clone_impl() const; private: float m_power; diff --git a/include/Pataro/Components/Destructible.hpp b/include/Pataro/Components/Destructible.hpp index 36d392f..ae7a6f8 100644 --- a/include/Pataro/Components/Destructible.hpp +++ b/include/Pataro/Components/Destructible.hpp @@ -22,7 +22,7 @@ namespace pat::component * @param defense * @param corpse_name the name of the Entity once dead */ - Destructible(float max_hp, float defense, const std::string& corpse_name); + Destructible(float max_hp, float defense, std::string corpse_name); /** * @brief Destroy the Destructible object @@ -56,15 +56,15 @@ namespace pat::component */ float heal(float amount); - inline bool is_dead() { return m_hp <= 0.f; } - inline float max_hp() { return m_max_hp; } - inline float hp() { return m_hp; } - inline float defense() { return m_defense; } + [[nodiscard]] inline bool is_dead() const { return m_hp <= 0.f; } + [[nodiscard]] inline float max_hp() const { return m_max_hp; } + [[nodiscard]] inline float hp() const { return m_hp; } + [[nodiscard]] inline float defense() const { return m_defense; } - inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } + [[nodiscard]] inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } protected: - virtual Destructible* clone_impl() const; + [[nodiscard]] virtual Destructible* clone_impl() const; private: float m_max_hp, m_hp; diff --git a/include/Pataro/Components/Destructible/Monster.hpp b/include/Pataro/Components/Destructible/Monster.hpp index 5854c4f..72eb42d 100644 --- a/include/Pataro/Components/Destructible/Monster.hpp +++ b/include/Pataro/Components/Destructible/Monster.hpp @@ -28,7 +28,7 @@ namespace pat::component void die(Entity* owner, Engine* engine) override; protected: - virtual MonsterDestructible* clone_impl() const override; + [[nodiscard]] MonsterDestructible* clone_impl() const override; }; } diff --git a/include/Pataro/Components/Destructible/Player.hpp b/include/Pataro/Components/Destructible/Player.hpp index 502c93f..c8a180c 100644 --- a/include/Pataro/Components/Destructible/Player.hpp +++ b/include/Pataro/Components/Destructible/Player.hpp @@ -28,7 +28,7 @@ namespace pat::component void die(Entity* owner, Engine* engine) override; protected: - virtual PlayerDestructible* clone_impl() const override; + [[nodiscard]] PlayerDestructible* clone_impl() const override; }; } diff --git a/include/Pataro/Components/Inventory.hpp b/include/Pataro/Components/Inventory.hpp index 5eaf251..4b78b31 100644 --- a/include/Pataro/Components/Inventory.hpp +++ b/include/Pataro/Components/Inventory.hpp @@ -19,7 +19,7 @@ namespace pat::component * * @param size the number of elements in the inventory (0 = unlimited) */ - Inventory(std::size_t size); + explicit Inventory(std::size_t size); virtual ~Inventory() = default; @@ -60,19 +60,19 @@ namespace pat::component * * @return std::size_t */ - std::size_t size() const; + [[nodiscard]] std::size_t size() const; /** * @brief Returns the maximum capacity of the inventory * * @return std::size_t */ - std::size_t capacity() const; + [[nodiscard]] std::size_t capacity() const; - inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } + [[nodiscard]] inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } protected: - virtual Inventory* clone_impl() const; + [[nodiscard]] virtual Inventory* clone_impl() const; private: std::size_t m_max_size; diff --git a/include/Pataro/Components/Use.hpp b/include/Pataro/Components/Use.hpp index c4b465d..d142c6b 100644 --- a/include/Pataro/Components/Use.hpp +++ b/include/Pataro/Components/Use.hpp @@ -35,7 +35,7 @@ namespace pat::component * @param owner the owner of the source object we are dropping * @param engine */ - void drop(Entity* source, Entity* owner, Engine* engine); + void drop(Entity* source, Entity* owner, Engine* engine) const; /** * @brief Remove from inventory @@ -43,7 +43,7 @@ namespace pat::component */ void remove_from_inventory(Entity* owner, Entity* source); - inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } + [[nodiscard]] inline std::unique_ptr clone() const { return std::unique_ptr(clone_impl()); } protected: /** @@ -57,7 +57,7 @@ namespace pat::component */ virtual std::unique_ptr use(Entity* source, Entity* owner, Engine* engine) = 0; - virtual Use* clone_impl() const = 0; + [[nodiscard]] virtual Use* clone_impl() const = 0; private: bool m_destroyed = false; ///< When equal to true, can not use it again diff --git a/include/Pataro/Components/Use/OneTime.hpp b/include/Pataro/Components/Use/OneTime.hpp index 884f288..b55562a 100644 --- a/include/Pataro/Components/Use/OneTime.hpp +++ b/include/Pataro/Components/Use/OneTime.hpp @@ -27,7 +27,7 @@ namespace pat::component * * @param args */ - OneTimeUse(Args&&... args) + explicit OneTimeUse(Args&&... args) { m_function = [args = std::make_tuple(std::forward(args) ...)](Entity* source, Entity* owner) -> std::unique_ptr { return std::apply([source, owner](auto&&... args) { @@ -48,8 +48,8 @@ namespace pat::component } private: - OneTimeUse(const Callback_t& callback) : - m_function(callback) + explicit OneTimeUse(Callback_t callback) : + m_function(std::move(callback)) {} Callback_t m_function; diff --git a/include/Pataro/Components/Use/OneTimeSelect.hpp b/include/Pataro/Components/Use/OneTimeSelect.hpp index c9b9f1b..6c7d172 100644 --- a/include/Pataro/Components/Use/OneTimeSelect.hpp +++ b/include/Pataro/Components/Use/OneTimeSelect.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace pat::component { @@ -43,11 +44,11 @@ namespace pat::component */ bool pick(Engine* engine); - inline PickMethod get_method() const { return m_method; } - inline int get_x() const { return m_x; } - inline int get_y() const { return m_y; } - inline float get_range() const { return m_range; } - inline Entity* get_entity() const { return m_entity; } + [[nodiscard]] inline PickMethod get_method() const { return m_method; } + [[nodiscard]] inline int get_x() const { return m_x; } + [[nodiscard]] inline int get_y() const { return m_y; } + [[nodiscard]] inline float get_range() const { return m_range; } + [[nodiscard]] inline Entity* get_entity() const { return m_entity; } protected: /** @@ -88,8 +89,8 @@ namespace pat::component * @param range the range in which the click can be performed * @param args */ - OneTimeSelectUse(const std::string& left_click_text, PickTile picker, Args&&... args) : - m_text(left_click_text), m_picker(picker) + OneTimeSelectUse(std::string left_click_text, PickTile picker, Args&&... args) : + m_text(std::move(left_click_text)), m_picker(picker) { m_function = [args = std::make_tuple(std::forward(args) ...)](Entity* source, Entity* owner, const PickTile& picker) -> std::unique_ptr { return std::apply([source, owner, &picker](auto&&... args) { @@ -113,8 +114,8 @@ namespace pat::component } private: - OneTimeSelectUse(const std::string& text, const PickTile& picker, const Callback_t& callback) : - m_text(text), m_picker(picker), m_function(callback) + OneTimeSelectUse(std::string text, const PickTile& picker, Callback_t callback) : + m_text(std::move(text)), m_picker(picker), m_function(std::move(callback)) {} std::string m_text; diff --git a/include/Pataro/Config.hpp b/include/Pataro/Config.hpp index 8e8b2c7..58391c8 100644 --- a/include/Pataro/Config.hpp +++ b/include/Pataro/Config.hpp @@ -11,7 +11,7 @@ namespace pat { struct Tile { - unsigned char repr; + unsigned char repr {'#'}; tcod::ColorRGB color_visible; tcod::ColorRGB color_outside_fov; }; @@ -35,7 +35,7 @@ namespace pat }; std::vector themes; - unsigned fps_max = 30; + int fps_max = 30; }; } diff --git a/include/Pataro/Engine.hpp b/include/Pataro/Engine.hpp index ab9c66b..bdd5fd7 100644 --- a/include/Pataro/Engine.hpp +++ b/include/Pataro/Engine.hpp @@ -45,7 +45,7 @@ namespace pat * @param config engine configuration * @param show_debug default: false. Show debug gui */ - Engine(unsigned width, unsigned height, const std::string& title, const Config& config, bool show_debug = false); + Engine(unsigned width, unsigned height, const std::string& title, Config config, bool show_debug = false); /** * @brief Initialize the engine @@ -74,7 +74,7 @@ namespace pat * @return true * @return false */ - inline bool is_running() const { return m_running; } + [[nodiscard]] inline bool is_running() const { return m_running; } /** * @brief Log an event with a given name. Only names/occurences are kept @@ -110,14 +110,14 @@ namespace pat void render_defeat(); - inline unsigned width() { return m_width; } - inline unsigned height() { return m_height; } + [[nodiscard]] inline unsigned width() const { return m_width; } + [[nodiscard]] inline unsigned height() const { return m_height; } inline void change_state(GameState state) { m_state = state; } inline Entity* get_player() { return m_player.get(); } inline Map* get_map() { return m_map.get(); } inline Gui* get_gui() { return m_gui.get(); } - inline const SDL_Keycode& lastkey() { return m_lastkey; } + [[nodiscard]] inline const SDL_Keycode& lastkey() const { return m_lastkey; } inline const Mouse& mouse() { return m_mouse; } inline tcod::Console& console() { return m_console; } diff --git a/include/Pataro/Entity.hpp b/include/Pataro/Entity.hpp index db44daa..31193f5 100644 --- a/include/Pataro/Entity.hpp +++ b/include/Pataro/Entity.hpp @@ -38,7 +38,7 @@ namespace pat * @param name the name of the entity * @param color the color for the entity */ - Entity(int x, int y, int ch, const std::string& name, const tcod::ColorRGB& color); + Entity(int x, int y, int ch, std::string name, const tcod::ColorRGB& color); /** * @brief Construct a new Entity object diff --git a/include/Pataro/Gui.hpp b/include/Pataro/Gui.hpp index 832b762..7d5f6f9 100644 --- a/include/Pataro/Gui.hpp +++ b/include/Pataro/Gui.hpp @@ -26,7 +26,7 @@ namespace pat * @param height size of the GUI console * @param proxy a function to retrieve the value and the max value */ - Gui(unsigned width, unsigned height, const Proxy_t& proxy); + Gui(unsigned width, unsigned height, Proxy_t proxy); /** * @brief Render the GUI on a given TCOD console @@ -68,8 +68,8 @@ namespace pat m_log.erase(m_log.begin()); } - inline unsigned get_width() { return m_width; } - inline unsigned get_height() { return m_height; } + [[nodiscard]] inline unsigned get_width() const { return m_width; } + [[nodiscard]] inline unsigned get_height() const { return m_height; } private: /** @@ -91,7 +91,7 @@ namespace pat struct Message { std::string text; tcod::ColorRGB color; - Message(const std::string& text, const tcod::ColorRGB& color); + Message(std::string text, const tcod::ColorRGB& color); }; std::vector m_log; diff --git a/include/Pataro/Map.hpp b/include/Pataro/Map.hpp index 852f21d..e4765ba 100644 --- a/include/Pataro/Map.hpp +++ b/include/Pataro/Map.hpp @@ -33,7 +33,7 @@ namespace pat * @param y * @return Tile::Type */ - map::Tile::Type tile_at(int x, int y) const; + [[nodiscard]] map::Tile::Type tile_at(int x, int y) const; /** * @brief check if an entity can walk on a given tile @@ -43,7 +43,7 @@ namespace pat * @return true * @return false */ - bool can_walk(int x, int y) const; + [[nodiscard]] bool can_walk(int x, int y) const; /** * @brief Tries to get an entity at x, y @@ -52,7 +52,7 @@ namespace pat * @param y * @return Entity* nullptr if no entity was found */ - Entity* get_entity(int x, int y) const; + [[nodiscard]] Entity* get_entity(int x, int y) const; /** * @brief Returns the closest monster to a given entity in a given range @@ -61,7 +61,7 @@ namespace pat * @param range * @return Entity* */ - Entity* get_closest_monster(Entity* from, float range) const; + [[nodiscard]] Entity* get_closest_monster(Entity* from, float range) const; /** * @brief Compute the player field of view @@ -102,11 +102,11 @@ namespace pat */ inline map::Level& current_level() { return m_levels[m_current]; } - inline std::size_t floor() const { return m_current; } - inline bool is_bottom_floor() const { return m_current + 1 == m_levels.size(); } + [[nodiscard]] inline std::size_t floor() const { return m_current; } + [[nodiscard]] inline bool is_bottom_floor() const { return m_current + 1 == m_levels.size(); } - inline bool can_go_upstairs() const { return m_current > 0; } - inline bool can_go_downstairs() const { return m_current + 1 < m_levels.size(); } + [[nodiscard]] inline bool can_go_upstairs() const { return m_current > 0; } + [[nodiscard]] inline bool can_go_downstairs() const { return m_current + 1 < m_levels.size(); } bool move_upstairs(Entity* player); bool move_downstairs(Entity* player); diff --git a/include/Pataro/Map/BSPListener.hpp b/include/Pataro/Map/BSPListener.hpp index 66a4d70..4330743 100644 --- a/include/Pataro/Map/BSPListener.hpp +++ b/include/Pataro/Map/BSPListener.hpp @@ -18,15 +18,15 @@ namespace pat::map::details * * @param level */ - BSPListener(Level* level); + explicit BSPListener(Level* level); bool visitNode(TCODBsp* node, void* userData) override; private: Level* m_level; int m_room_nb; - int m_lastx; - int m_lasty; + int m_lastx; // TODO find a better name + int m_lasty; // TODO find a better name }; } diff --git a/include/Pataro/Map/Level.hpp b/include/Pataro/Map/Level.hpp index 7bfd13b..ea7d8a0 100644 --- a/include/Pataro/Map/Level.hpp +++ b/include/Pataro/Map/Level.hpp @@ -51,7 +51,7 @@ namespace pat::map * @param y * @return Tile::Type */ - Tile::Type tile_at(int x, int y) const; + [[nodiscard]] Tile::Type tile_at(int x, int y) const; /** * @brief check if an Entity can walk on a given tile @@ -61,7 +61,7 @@ namespace pat::map * @return true * @return false */ - bool can_walk(int x, int y) const; + [[nodiscard]] bool can_walk(int x, int y) const; /** * @brief Tries to get an Entity at x, y @@ -70,7 +70,7 @@ namespace pat::map * @param y * @return Entity* nullptr if no Entity was found */ - Entity* get_entity(int x, int y) const; + [[nodiscard]] Entity* get_entity(int x, int y) const; /** * @brief Returns the closest monster to a given entity in a given range @@ -79,7 +79,7 @@ namespace pat::map * @param range * @return Entity* */ - Entity* get_closest_monster(Entity* from, float range) const; + [[nodiscard]] Entity* get_closest_monster(Entity* from, float range) const; /** * @brief Check if a tile is in the field of view @@ -89,7 +89,7 @@ namespace pat::map * @return true * @return false */ - bool is_in_fov(int x, int y); + [[nodiscard]] bool is_in_fov(int x, int y); /** * @brief Check if a tile has been explored @@ -99,7 +99,7 @@ namespace pat::map * @return true * @return false */ - bool is_explored(int x, int y) const; + [[nodiscard]] bool is_explored(int x, int y) const; /** * @brief Compute the player field of view @@ -147,8 +147,8 @@ namespace pat::map inline const std::vector>& get_entities() { return m_entities; } - inline int width() const { return m_width; } - inline int height() const { return m_height; } + [[nodiscard]] inline int width() const { return m_width; } + [[nodiscard]] inline int height() const { return m_height; } friend class details::BSPListener; friend class pat::Map; diff --git a/include/Pataro/Map/Tile.hpp b/include/Pataro/Map/Tile.hpp index ae1c9d3..c87c42d 100644 --- a/include/Pataro/Map/Tile.hpp +++ b/include/Pataro/Map/Tile.hpp @@ -13,7 +13,7 @@ namespace pat::map Stairs } type; - Tile(Type type = Type::Wall); + explicit Tile(Type type = Type::Wall); }; } diff --git a/src/Pataro/Actions/Fireball.cpp b/src/Pataro/Actions/Fireball.cpp index 59b266a..6c672d0 100644 --- a/src/Pataro/Actions/Fireball.cpp +++ b/src/Pataro/Actions/Fireball.cpp @@ -22,7 +22,7 @@ pat::ActionResult FireballAction::perform(pat::Engine* engine) for (const auto& entity: engine->get_map()->current_level().get_entities()) { - float dist = static_cast(details::get_manhattan_distance(entity->get_x(), entity->get_y(), m_tx, m_ty)); + auto dist = static_cast(details::get_manhattan_distance(entity->get_x(), entity->get_y(), m_tx, m_ty)); if (pat::component::Destructible* d = entity->destructible(); d != nullptr && !d->is_dead() && dist < m_range) { engine->get_gui()->message(colors::orange, "The ", entity->get_name(), " gets burned for ", m_damage, " hit points."); diff --git a/src/Pataro/Actions/Move.cpp b/src/Pataro/Actions/Move.cpp index 7d4b627..e505c32 100644 --- a/src/Pataro/Actions/Move.cpp +++ b/src/Pataro/Actions/Move.cpp @@ -9,8 +9,6 @@ #include #include -#include - using namespace pat; MoveAction::MoveAction(Entity* source, int dx, int dy) : @@ -35,6 +33,7 @@ ActionResult MoveAction::perform(Engine* engine) } // physics + // TODO probably going to have to refactor either this, the way we handle the map (tiles+tcod map?) or both map::Tile::Type next_tile = map->tile_at(x + m_dx, y + m_dy); if (!map->can_walk(x + m_dx, y + m_dy)) return ActionResult::Fail; diff --git a/src/Pataro/Actions/PickUp.cpp b/src/Pataro/Actions/PickUp.cpp index dff3bc1..bfb2be6 100644 --- a/src/Pataro/Actions/PickUp.cpp +++ b/src/Pataro/Actions/PickUp.cpp @@ -13,7 +13,6 @@ PickUpAction::PickUpAction(pat::Entity* source, int x, int y) : pat::ActionResult PickUpAction::perform(pat::Engine* engine) { - bool found = false; if (m_source == engine->get_player()) engine->log("pick up"); @@ -24,8 +23,6 @@ pat::ActionResult PickUpAction::perform(pat::Engine* engine) // try to pick up the object if (m_source->inventory()->add(e.get())) { - found = true; - if (m_source == engine->get_player()) { engine->log("pick up " + e->get_name()); @@ -37,11 +34,9 @@ pat::ActionResult PickUpAction::perform(pat::Engine* engine) engine->get_map()->current_level().remove(e.get()); return pat::ActionResult::Success; } - else if (!found) + else { // we found an object but couldn't pick it up - found = true; - if (m_source == engine->get_player()) { engine->log("pick up with full inventory"); diff --git a/src/Pataro/Components/AI.cpp b/src/Pataro/Components/AI.cpp deleted file mode 100644 index ea56fad..0000000 --- a/src/Pataro/Components/AI.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include - -#include -#include - -using namespace pat::component; diff --git a/src/Pataro/Components/AI/Monster.cpp b/src/Pataro/Components/AI/Monster.cpp index 564e216..49e74fe 100644 --- a/src/Pataro/Components/AI/Monster.cpp +++ b/src/Pataro/Components/AI/Monster.cpp @@ -1,13 +1,11 @@ #include -#include #include #include #include #include #include #include -#include #include diff --git a/src/Pataro/Components/AI/Player.cpp b/src/Pataro/Components/AI/Player.cpp index dbe373e..14aaeef 100644 --- a/src/Pataro/Components/AI/Player.cpp +++ b/src/Pataro/Components/AI/Player.cpp @@ -2,19 +2,13 @@ #include #include -#include -#include #include -#include #include -#include #include #include #include -#include - using namespace pat::component; std::unique_ptr PlayerAI::update(pat::Entity* owner, pat::Engine* engine) diff --git a/src/Pataro/Components/Attacker.cpp b/src/Pataro/Components/Attacker.cpp index ca141ba..cfa9419 100644 --- a/src/Pataro/Components/Attacker.cpp +++ b/src/Pataro/Components/Attacker.cpp @@ -1,7 +1,5 @@ #include -#include -#include #include using namespace pat::component; diff --git a/src/Pataro/Components/Destructible.cpp b/src/Pataro/Components/Destructible.cpp index c0a1477..f202158 100644 --- a/src/Pataro/Components/Destructible.cpp +++ b/src/Pataro/Components/Destructible.cpp @@ -4,12 +4,12 @@ #include #include -#include +#include using namespace pat::component; -Destructible::Destructible(float max_hp, float defense, const std::string& corpse_name) : - m_max_hp(max_hp), m_hp(max_hp), m_defense(defense), m_corpse_name(corpse_name) +Destructible::Destructible(float max_hp, float defense, std::string corpse_name) : + m_max_hp(max_hp), m_hp(max_hp), m_defense(defense), m_corpse_name(std::move(corpse_name)) {} float Destructible::take_damage(pat::Entity* owner, float damage, pat::Engine* engine) diff --git a/src/Pataro/Components/Use.cpp b/src/Pataro/Components/Use.cpp index 3bb2961..f160528 100644 --- a/src/Pataro/Components/Use.cpp +++ b/src/Pataro/Components/Use.cpp @@ -13,7 +13,7 @@ std::unique_ptr Use::perform(pat::Entity* source, pat::Entity* owne return use(source, owner, engine); } -void Use::drop(pat::Entity* source, pat::Entity* owner, pat::Engine* engine) +void Use::drop(pat::Entity* source, pat::Entity* owner, pat::Engine* engine) const { // we can not drop a used object if (m_destroyed) diff --git a/src/Pataro/Engine.cpp b/src/Pataro/Engine.cpp index 7f26024..a102a1e 100644 --- a/src/Pataro/Engine.cpp +++ b/src/Pataro/Engine.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -13,13 +12,12 @@ #include #include -#include #include using namespace pat; -Engine::Engine(unsigned width, unsigned height, const std::string& title, const Config& config, bool show_debug) : - m_width(width), m_height(height), m_config(config), m_show_debug(show_debug), m_running(true), m_console(width, height) +Engine::Engine(unsigned width, unsigned height, const std::string& title, Config config, bool show_debug) : + m_width(width), m_height(height), m_config(std::move(config)), m_show_debug(show_debug), m_running(true), m_console(width, height) { TCOD_ContextParams params {}; params.tcod_version = TCOD_COMPILEDVERSION; @@ -232,7 +230,7 @@ bool Engine::pick_a_tile(int* x, int* y, float max_range) { for (int cy = 0, h = m_map->current_level().height(); cy < h; ++cy) { - float dist = static_cast(details::get_manhattan_distance(cx, cy, xp, yp)); + auto dist = static_cast(details::get_manhattan_distance(cx, cy, xp, yp)); if (m_map->is_in_fov(cx, cy) && (max_range == 0.f || dist <= max_range)) { @@ -247,7 +245,7 @@ bool Engine::pick_a_tile(int* x, int* y, float max_range) } } - float dist = static_cast(details::get_manhattan_distance(m_mouse.cx + dx, m_mouse.cy + dy, xp, yp)); + auto dist = static_cast(details::get_manhattan_distance(m_mouse.cx + dx, m_mouse.cy + dy, xp, yp)); if (m_map->is_in_fov(m_mouse.cx + dx, m_mouse.cy + dy) && (max_range == 0.f || dist <= max_range)) { m_console.at(m_mouse.cx, m_mouse.cy).bg = colors::white; diff --git a/src/Pataro/Entity.cpp b/src/Pataro/Entity.cpp index ef1dbb2..d8d8e09 100644 --- a/src/Pataro/Entity.cpp +++ b/src/Pataro/Entity.cpp @@ -1,13 +1,14 @@ #include #include +#include using namespace pat; unsigned Entity::Id = 0; -Entity::Entity(int x, int y, int ch, const std::string& name, const tcod::ColorRGB& color) : - m_id(Entity::Id++), m_x(x), m_y(y), m_ch(ch), m_name(name), m_color(color) +Entity::Entity(int x, int y, int ch, std::string name, const tcod::ColorRGB& color) : + m_id(Entity::Id++), m_x(x), m_y(y), m_ch(ch), m_name(std::move(name)), m_color(color) {} Entity::Entity(const Entity& other) : diff --git a/src/Pataro/Gui.cpp b/src/Pataro/Gui.cpp index 0d8d654..76bc4d1 100644 --- a/src/Pataro/Gui.cpp +++ b/src/Pataro/Gui.cpp @@ -2,11 +2,12 @@ #include #include +#include using namespace pat; -Gui::Gui(unsigned width, unsigned height, const Gui::Proxy_t& proxy) : - m_console(width, height), m_width(width), m_height(height), m_get_val(proxy) +Gui::Gui(unsigned width, unsigned height, Gui::Proxy_t proxy) : + m_console(width, height), m_width(width), m_height(height), m_get_val(std::move(proxy)) {} void Gui::render(Engine* engine, TCOD_Console* dest, int x, int y) @@ -64,7 +65,7 @@ void Gui::render_mouse_look(Engine* engine) if (!engine->get_map()->is_in_fov(x, y)) return; - std::string text = ""; + std::string text; bool first = true; for (const auto& entity : engine->get_map()->current_level().get_entities()) { @@ -81,6 +82,6 @@ void Gui::render_mouse_look(Engine* engine) tcod::print(m_console, {1, 0}, text, colors::lightGrey, std::nullopt); } -Gui::Message::Message(const std::string& text_, const tcod::ColorRGB& color_) : - text(text_), color(color_) +Gui::Message::Message(std::string text_, const tcod::ColorRGB& color_) : + text(std::move(text_)), color(color_) {} diff --git a/src/Pataro/Map.cpp b/src/Pataro/Map.cpp index f4d15b4..1856f33 100644 --- a/src/Pataro/Map.cpp +++ b/src/Pataro/Map.cpp @@ -2,8 +2,6 @@ #include -#include - using namespace pat; Map::Map(unsigned width, unsigned height, std::size_t depth, Engine* engine, const Config::Theme& theme) : diff --git a/src/Pataro/Map/BSPListener.cpp b/src/Pataro/Map/BSPListener.cpp index 50bb31e..15356d5 100644 --- a/src/Pataro/Map/BSPListener.cpp +++ b/src/Pataro/Map/BSPListener.cpp @@ -7,7 +7,7 @@ using namespace pat::map::details; using namespace pat::map; BSPListener::BSPListener(Level* level) : - m_level(level), m_room_nb(0) + m_level(level), m_room_nb(0), m_lastx(0), m_lasty(0) {} bool BSPListener::visitNode(TCODBsp* node, [[maybe_unused]] void* userData) diff --git a/src/Pataro/Map/Level.cpp b/src/Pataro/Map/Level.cpp index a2219ca..ab6cd79 100644 --- a/src/Pataro/Map/Level.cpp +++ b/src/Pataro/Map/Level.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -79,7 +78,7 @@ pat::Entity* Level::get_closest_monster(pat::Entity* from, float range) const if (component::Destructible* d = entity->destructible(); entity.get() != from && d != nullptr && !d->is_dead()) { - float dist = static_cast(pat::details::get_manhattan_distance( + auto dist = static_cast(pat::details::get_manhattan_distance( from->get_x(), from->get_y(), entity->get_x(), entity->get_y() )); @@ -131,7 +130,7 @@ void Level::render(float dt) TCOD_ConsoleTile& tile = m_engine->console().at(screen_x, screen_y); // IMPORTANT: the type index should the same (and have the same order) as the one defines under Config.hpp - std::size_t type_idx = static_cast(m_tiles[world_x + world_y * m_width].type); + auto type_idx = static_cast(m_tiles[world_x + world_y * m_width].type); if (type_idx <= 2) { if (is_in_fov(world_x, world_y)) @@ -170,14 +169,14 @@ void Level::render(float dt) void Level::update() { // called once per new turn - for (std::size_t i = 0; i < m_entities.size(); ++i) + for (const auto & entity : m_entities) { - if (m_entities[i].get() != m_engine->get_player()) + if (entity.get() != m_engine->get_player()) { - m_entities[i]->gain_energy(); - if (m_entities[i]->has_enough_energy()) + entity->gain_energy(); + if (entity->has_enough_energy()) { - std::unique_ptr action = m_entities[i]->update(m_engine); + std::unique_ptr action = entity->update(m_engine); if (action != nullptr) action->perform(m_engine); } diff --git a/src/Pataro/Utils.cpp b/src/Pataro/Utils.cpp index 268b6cc..74122fc 100644 --- a/src/Pataro/Utils.cpp +++ b/src/Pataro/Utils.cpp @@ -1,7 +1,7 @@ #include -#include -#include +#include +#include #include namespace pat::details @@ -10,7 +10,7 @@ namespace pat::details { time_t t = time(nullptr); char buffer[70]; - struct tm time_struct; + struct tm time_struct {}; #ifdef WIN32 localtime_s(&time_struct, &t); @@ -19,7 +19,7 @@ namespace pat::details #endif strftime(buffer, sizeof(buffer), "%d-%m-%Y_%H-%M-%S", &time_struct); - return std::string(buffer, strlen(buffer)); + return {buffer, strlen(buffer)}; } unsigned get_manhattan_distance(int x1, int y1, int x2, int y2)