From 212d591c31f4200b06d38e98b23c5c2bccde1772 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Mon, 22 May 2023 10:26:37 +0100 Subject: Formatting / style cleanup --- src/openvic/map/Building.cpp | 12 ++++++++---- src/openvic/map/Building.hpp | 14 ++++++++++++-- src/openvic/map/Map.cpp | 15 ++++++++++----- src/openvic/map/Map.hpp | 9 ++++++--- src/openvic/map/Province.cpp | 10 ++++++---- src/openvic/map/Province.hpp | 1 + src/openvic/map/Region.cpp | 2 +- src/openvic/map/Region.hpp | 3 +++ 8 files changed, 47 insertions(+), 19 deletions(-) (limited to 'src/openvic/map') diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp index ccd5ad7..1513e06 100644 --- a/src/openvic/map/Building.cpp +++ b/src/openvic/map/Building.cpp @@ -7,7 +7,9 @@ using namespace OpenVic; -Building::Building(BuildingType const& new_type) : HasIdentifier{ new_type.get_identifier() }, type{ new_type } {} +Building::Building(BuildingType const& new_type) + : HasIdentifier { new_type.get_identifier() }, + type { new_type } {} bool Building::_can_expand() const { return level < type.get_max_level(); @@ -74,8 +76,10 @@ void Building::tick(Date const& today) { } } -BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) : - HasIdentifier{ new_identifier }, max_level{ new_max_level }, build_time{ new_build_time } { +BuildingType::BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time) + : HasIdentifier { new_identifier }, + max_level { new_max_level }, + build_time { new_build_time } { assert(max_level >= 0); assert(build_time >= 0); } @@ -88,7 +92,7 @@ Timespan BuildingType::get_build_time() const { return build_time; } -BuildingManager::BuildingManager() : building_types{ "building types" } {} +BuildingManager::BuildingManager() : building_types { "building types" } {} return_t BuildingManager::add_building_type(std::string const& identifier, Building::level_t max_level, Timespan build_time) { if (identifier.empty()) { diff --git a/src/openvic/map/Building.hpp b/src/openvic/map/Building.hpp index ca5c196..98c3991 100644 --- a/src/openvic/map/Building.hpp +++ b/src/openvic/map/Building.hpp @@ -2,8 +2,8 @@ #include -#include "../Types.hpp" #include "../Date.hpp" +#include "../Types.hpp" namespace OpenVic { struct Province; @@ -19,7 +19,13 @@ namespace OpenVic { using level_t = int8_t; - enum class ExpansionState { CannotExpand, CanExpand, Preparing, Expanding }; + enum class ExpansionState { + CannotExpand, + CanExpand, + Preparing, + Expanding + }; + private: BuildingType const& type; level_t level = 0; @@ -30,6 +36,7 @@ namespace OpenVic { Building(BuildingType const& new_type); bool _can_expand() const; + public: Building(Building&&) = default; @@ -49,11 +56,13 @@ namespace OpenVic { struct BuildingType : HasIdentifier { friend struct BuildingManager; + private: const Building::level_t max_level; const Timespan build_time; BuildingType(std::string const& new_identifier, Building::level_t new_max_level, Timespan new_build_time); + public: BuildingType(BuildingType&&) = default; @@ -64,6 +73,7 @@ namespace OpenVic { struct BuildingManager { private: IdentifierRegistry building_types; + public: BuildingManager(); diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp index af1ea8a..8d5b9e7 100644 --- a/src/openvic/map/Map.cpp +++ b/src/openvic/map/Map.cpp @@ -9,7 +9,9 @@ using namespace OpenVic; Mapmode::Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func) - : HasIdentifier{ new_identifier }, index{ new_index }, colour_func{ new_colour_func } { + : HasIdentifier { new_identifier }, + index { new_index }, + colour_func { new_colour_func } { assert(colour_func != nullptr); } @@ -21,7 +23,9 @@ colour_t Mapmode::get_colour(Map const& map, Province const& province) const { return colour_func ? colour_func(map, province) : NULL_COLOUR; } -Map::Map() : provinces{ "provinces" }, regions{ "regions" }, mapmodes{ "mapmodes" } {} +Map::Map() : provinces { "provinces" }, + regions { "regions" }, + mapmodes { "mapmodes" } {} return_t Map::add_province(std::string const& identifier, colour_t colour) { if (provinces.get_item_count() >= MAX_INDEX) { @@ -36,7 +40,7 @@ return_t Map::add_province(std::string const& identifier, colour_t colour) { Logger::error("Invalid province colour: ", Province::colour_to_hex_string(colour)); return FAILURE; } - Province new_province{ static_cast(provinces.get_item_count() + 1), identifier, colour }; + Province new_province { static_cast(provinces.get_item_count() + 1), identifier, colour }; const index_t index = get_index_from_colour(colour); if (index != NULL_INDEX) { Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string()); @@ -79,7 +83,7 @@ return_t Map::add_region(std::string const& identifier, std::vector Logger::error("Invalid region identifier - empty!"); return FAILURE; } - Region new_region{ identifier }; + Region new_region { identifier }; return_t ret = SUCCESS; for (std::string const& province_identifier : province_identifiers) { Province* province = get_province_by_identifier(province_identifier); @@ -330,7 +334,8 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager) { return_t ret = SUCCESS; for (Province& province : provinces.get_items()) { - if (!province.is_water()) // Set all land provinces to have an RGO based on their index to test them + // Set all land provinces to have an RGO based on their index to test them + if (!province.is_water()) province.rgo = good_manager.get_good_by_index(province.get_index() % good_manager.get_good_count()); if (building_manager.generate_province_buildings(province) != SUCCESS) ret = FAILURE; } diff --git a/src/openvic/map/Map.hpp b/src/openvic/map/Map.hpp index 39c37c0..a7c29bb 100644 --- a/src/openvic/map/Map.hpp +++ b/src/openvic/map/Map.hpp @@ -9,13 +9,15 @@ namespace OpenVic { struct Mapmode : HasIdentifier { friend struct Map; - using colour_func_t = std::function; + using colour_func_t = std::function; using index_t = size_t; + private: const index_t index; const colour_func_t colour_func; Mapmode(index_t new_index, std::string const& new_identifier, colour_func_t new_colour_func); + public: index_t get_index() const; colour_t get_colour(Map const& map, Province const& province) const; @@ -30,12 +32,12 @@ namespace OpenVic { using terrain_t = uint8_t; using terrain_variant_map_t = std::map; - #pragma pack(push, 1) +#pragma pack(push, 1) struct shape_pixel_t { index_t index; terrain_t terrain; }; - #pragma pack(pop) +#pragma pack(pop) private: using colour_index_map_t = std::map; @@ -51,6 +53,7 @@ namespace OpenVic { index_t selected_province = NULL_INDEX; index_t get_index_from_colour(colour_t colour) const; + public: Map(); diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp index b169021..d2a5ecf 100644 --- a/src/openvic/map/Province.cpp +++ b/src/openvic/map/Province.cpp @@ -1,13 +1,16 @@ #include "Province.hpp" #include -#include #include +#include using namespace OpenVic; -Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) : - HasIdentifier{ new_identifier }, HasColour{ new_colour }, index{ new_index }, buildings{ "buildings" } { +Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) + : HasIdentifier { new_identifier }, + HasColour { new_colour }, + index { new_index }, + buildings { "buildings" } { assert(index != NULL_INDEX); } @@ -66,7 +69,6 @@ std::string Province::to_string() const { void Province::update_state(Date const& today) { for (Building& building : buildings.get_items()) building.update_state(today); - } void Province::tick(Date const& today) { diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp index cc11046..f1f87a2 100644 --- a/src/openvic/map/Province.hpp +++ b/src/openvic/map/Province.hpp @@ -25,6 +25,7 @@ namespace OpenVic { Good const* rgo = nullptr; Province(index_t new_index, std::string const& new_identifier, colour_t new_colour); + public: Province(Province&&) = default; diff --git a/src/openvic/map/Region.cpp b/src/openvic/map/Region.cpp index d546ff9..b83f556 100644 --- a/src/openvic/map/Region.cpp +++ b/src/openvic/map/Region.cpp @@ -16,7 +16,7 @@ std::vector const& ProvinceSet::get_provinces() const { return provinces; } -Region::Region(std::string const& new_identifier) : HasIdentifier{ new_identifier } {} +Region::Region(std::string const& new_identifier) : HasIdentifier { new_identifier } {} colour_t Region::get_colour() const { if (provinces.empty()) return FULL_COLOUR << 16; diff --git a/src/openvic/map/Region.hpp b/src/openvic/map/Region.hpp index 953a3cc..331d883 100644 --- a/src/openvic/map/Region.hpp +++ b/src/openvic/map/Region.hpp @@ -7,6 +7,7 @@ namespace OpenVic { struct ProvinceSet { protected: std::vector provinces; + public: size_t get_province_count() const; bool contains_province(Province const* province) const; @@ -18,8 +19,10 @@ namespace OpenVic { */ struct Region : HasIdentifier, ProvinceSet { friend struct Map; + private: Region(std::string const& new_identifier); + public: Region(Region&&) = default; -- cgit v1.2.3-56-ga3b1