diff options
Diffstat (limited to 'src/openvic/map')
-rw-r--r-- | src/openvic/map/Map.cpp | 4 | ||||
-rw-r--r-- | src/openvic/map/Province.cpp | 37 | ||||
-rw-r--r-- | src/openvic/map/Province.hpp | 8 |
3 files changed, 37 insertions, 12 deletions
diff --git a/src/openvic/map/Map.cpp b/src/openvic/map/Map.cpp index 0f4ed46..21bb6a5 100644 --- a/src/openvic/map/Map.cpp +++ b/src/openvic/map/Map.cpp @@ -366,12 +366,14 @@ Pop::pop_size_t Map::get_total_map_population() const { return_t Map::setup(GoodManager const& good_manager, BuildingManager const& building_manager, PopManager const& pop_manager) { return_t ret = SUCCESS; for (Province& province : provinces.get_items()) { + province.clear_pops(); // Set all land provinces to have an RGO based on their index to test them if (!province.is_water() && good_manager.get_good_count() > 0) 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; // Add some pops to the province (for testing purposes) - pop_manager.generate_test_pops(province); + if (!province.is_water()) + pop_manager.generate_test_pops(province); } return ret; } diff --git a/src/openvic/map/Province.cpp b/src/openvic/map/Province.cpp index 75612ad..0b6d1f4 100644 --- a/src/openvic/map/Province.cpp +++ b/src/openvic/map/Province.cpp @@ -7,8 +7,7 @@ using namespace OpenVic; Province::Province(index_t new_index, std::string const& new_identifier, colour_t new_colour) - : HasIdentifier { new_identifier }, - HasColour { new_colour, false }, + : HasIdentifierAndColour { new_identifier, new_colour, false }, index { new_index }, buildings { "buildings" } { assert(index != NULL_INDEX); @@ -67,27 +66,47 @@ std::string Province::to_string() const { } void Province::add_pop(Pop&& pop) { - pops.push_back(std::move(pop)); + if (is_water()) { + Logger::error("Trying to add pop to water province ", get_identifier()); + } else { + pops.push_back(std::move(pop)); + } +} + +void Province::clear_pops() { + pops.clear(); +} + +Pop::pop_size_t Province::get_total_population() const { + return total_population; +} + +distribution_t const& Province::get_pop_type_distribution() const { + return pop_types; +} + +distribution_t const& Province::get_culture_distribution() const { + return cultures; } /* REQUIREMENTS: * MAP-65 */ -void Province::update_total_population() { +void Province::update_pops() { total_population = 0; + pop_types.clear(); + cultures.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(); } } -Pop::pop_size_t Province::get_total_population() const { - return total_population; -} - void Province::update_state(Date const& today) { for (Building& building : buildings.get_items()) building.update_state(today); - update_total_population(); + update_pops(); } void Province::tick(Date const& today) { diff --git a/src/openvic/map/Province.hpp b/src/openvic/map/Province.hpp index cd90f7d..3ca5d93 100644 --- a/src/openvic/map/Province.hpp +++ b/src/openvic/map/Province.hpp @@ -11,7 +11,7 @@ namespace OpenVic { /* REQUIREMENTS: * MAP-5, MAP-7, MAP-8, MAP-43, MAP-47 */ - struct Province : HasIdentifier, HasColour { + struct Province : HasIdentifierAndColour { friend struct Map; using life_rating_t = int8_t; @@ -27,6 +27,7 @@ namespace OpenVic { std::vector<Pop> pops; Pop::pop_size_t total_population; + distribution_t pop_types, cultures; Province(index_t new_index, std::string const& new_identifier, colour_t new_colour); @@ -47,8 +48,11 @@ namespace OpenVic { std::string to_string() const; void add_pop(Pop&& pop); - void update_total_population(); + void clear_pops(); Pop::pop_size_t get_total_population() const; + distribution_t const& get_pop_type_distribution() const; + distribution_t const& get_culture_distribution() const; + void update_pops(); void update_state(Date const& today); void tick(Date const& today); |