diff options
author | Hop311 <hop3114@gmail.com> | 2023-08-26 00:25:12 +0200 |
---|---|---|
committer | Hop311 <hop3114@gmail.com> | 2023-09-03 12:53:52 +0200 |
commit | 366f1b3941315641bdcb0ee98465b4d2134eee86 (patch) | |
tree | ebb1e95b5e874c6eab09f19a323d721fd1fdac1b /src/openvic/map | |
parent | efa88c722fcb6c8fea7a86e1b3b8a83f1f59eb31 (diff) |
Followup big dataloader commit
Diffstat (limited to 'src/openvic/map')
-rw-r--r-- | src/openvic/map/Building.cpp | 2 | ||||
-rw-r--r-- | src/openvic/map/Map.cpp | 18 | ||||
-rw-r--r-- | src/openvic/map/Province.cpp | 6 | ||||
-rw-r--r-- | src/openvic/map/Province.hpp | 5 |
4 files changed, 19 insertions, 12 deletions
diff --git a/src/openvic/map/Building.cpp b/src/openvic/map/Building.cpp index d2662c4..00e0135 100644 --- a/src/openvic/map/Building.cpp +++ b/src/openvic/map/Building.cpp @@ -2,8 +2,8 @@ #include <cassert> -#include "openvic/utility/Logger.hpp" #include "openvic/map/Province.hpp" +#include "openvic/utility/Logger.hpp" using namespace OpenVic; diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp index 95d94fd..c9dd9d2 100644 --- a/src/openvic/map/Map.cpp +++ b/src/openvic/map/Map.cpp @@ -31,7 +31,7 @@ Map::Map() : provinces { "provinces" }, mapmodes { "mapmodes" } {} return_t Map::add_province(const std::string_view identifier, colour_t colour) { - if (provinces.get_item_count() >= Province::MAX_INDEX) { + if (provinces.size() >= Province::MAX_INDEX) { Logger::error("The map's province list is full - there can be at most ", Province::MAX_INDEX, " provinces"); return FAILURE; } @@ -43,7 +43,7 @@ return_t Map::add_province(const std::string_view identifier, colour_t colour) { Logger::error("Invalid province colour for ", identifier, ": ", Province::colour_to_hex_string(colour)); return FAILURE; } - Province new_province { identifier, colour, static_cast<Province::index_t>(provinces.get_item_count() + 1) }; + Province new_province { identifier, colour, static_cast<Province::index_t>(provinces.size() + 1) }; const Province::index_t index = get_index_from_colour(colour); if (index != Province::NULL_INDEX) { Logger::error("Duplicate province colours: ", get_province_by_index(index)->to_string(), " and ", new_province.to_string()); @@ -101,7 +101,7 @@ return_t Map::add_region(const std::string_view identifier, std::vector<std::str size_t other_region_index = reinterpret_cast<size_t>(province->get_region()); if (other_region_index != 0) { other_region_index--; - if (other_region_index < regions.get_item_count()) + if (other_region_index < regions.size()) Logger::error("Cannot add province ", province_identifier, " to region ", identifier, " - it is already part of ", regions.get_item_by_index(other_region_index)->get_identifier()); else Logger::error("Cannot add province ", province_identifier, " to region ", identifier, " - it is already part of an unknown region with index ", other_region_index); @@ -124,7 +124,7 @@ return_t Map::add_region(const std::string_view identifier, std::vector<std::str // Used to detect provinces listed in multiple regions, will // be corrected once regions is stable (i.e. lock_regions). - Region* tmp_region_index = reinterpret_cast<Region*>(regions.get_item_count()); + Region* tmp_region_index = reinterpret_cast<Region*>(regions.size()); for (Province* province : new_region.get_provinces()) province->region = tmp_region_index; if (regions.add_item(std::move(new_region)) != SUCCESS) ret = FAILURE; @@ -139,7 +139,7 @@ void Map::lock_regions() { } size_t Map::get_province_count() const { - return provinces.get_item_count(); + return provinces.size(); } Province* Map::get_province_by_index(Province::index_t index) { @@ -225,7 +225,7 @@ return_t Map::generate_province_shape_image(size_t new_width, size_t new_height, height = new_height; province_shape_image.resize(width * height); - std::vector<bool> province_checklist(provinces.get_item_count()); + std::vector<bool> province_checklist(provinces.size()); return_t ret = SUCCESS; std::unordered_set<colour_t> unrecognised_province_colours, unrecognised_terrain_colours; @@ -324,7 +324,7 @@ return_t Map::add_mapmode(const std::string_view identifier, Mapmode::colour_fun Logger::error("Mapmode colour function is null for identifier: ", identifier); return FAILURE; } - return mapmodes.add_item({ identifier, mapmodes.get_item_count(), colour_func }); + return mapmodes.add_item({ identifier, mapmodes.size(), colour_func }); } void Map::lock_mapmodes() { @@ -332,7 +332,7 @@ void Map::lock_mapmodes() { } size_t Map::get_mapmode_count() const { - return mapmodes.get_item_count(); + return mapmodes.size(); } Mapmode const* Map::get_mapmode_by_index(size_t index) const { @@ -354,7 +354,7 @@ return_t Map::generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) // Not an error if mapmodes haven't yet been loaded, // e.g. if we want to allocate the province colour // texture before mapmodes are loaded. - if (!(mapmodes.get_item_count() == 0 && index == 0)) { + if (!(mapmodes.size() == 0 && index == 0)) { Logger::error("Invalid mapmode index: ", index); ret = FAILURE; } diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp index 76e478f..f4588d4 100644 --- a/src/openvic/map/Province.cpp +++ b/src/openvic/map/Province.cpp @@ -91,6 +91,10 @@ distribution_t const& Province::get_culture_distribution() const { return cultures; } +distribution_t const& Province::get_religion_distribution() const { + return religions; +} + /* REQUIREMENTS: * MAP-65 */ @@ -98,10 +102,12 @@ void Province::update_pops() { total_population = 0; pop_types.clear(); cultures.clear(); + religions.clear(); for (Pop const& pop : pops) { total_population += pop.get_size(); pop_types[&pop.get_type()] += pop.get_size(); cultures[&pop.get_culture()] += pop.get_size(); + religions[&pop.get_religion()] += pop.get_size(); } } diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp index 3556bcb..527a6fe 100644 --- a/src/openvic/map/Province.hpp +++ b/src/openvic/map/Province.hpp @@ -1,7 +1,7 @@ #pragma once -#include "openvic/pop/Pop.hpp" #include "openvic/map/Building.hpp" +#include "openvic/pop/Pop.hpp" namespace OpenVic { struct Map; @@ -30,7 +30,7 @@ namespace OpenVic { std::vector<Pop> pops; Pop::pop_size_t total_population; - distribution_t pop_types, cultures; + distribution_t pop_types, cultures, religions; Province(const std::string_view new_identifier, colour_t new_colour, index_t new_index); @@ -55,6 +55,7 @@ namespace OpenVic { Pop::pop_size_t get_total_population() const; distribution_t const& get_pop_type_distribution() const; distribution_t const& get_culture_distribution() const; + distribution_t const& get_religion_distribution() const; void update_pops(); void update_state(Date const& today); |