From 170ee25469322d25931050813a779dfbc2eaa4b0 Mon Sep 17 00:00:00 2001 From: Hop311 Date: Thu, 10 Aug 2023 11:32:53 +0100 Subject: Added distributions for pop type and culture --- src/openvic/map/Province.cpp | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'src/openvic/map/Province.cpp') 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) { -- cgit v1.2.3-56-ga3b1