aboutsummaryrefslogtreecommitdiff
path: root/src/openvic/map/Province.cpp
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-08-10 12:59:31 +0200
committer GitHub <noreply@github.com>2023-08-10 12:59:31 +0200
commit538e7dc4ec44c4d09a6a654f10229e6392653a50 (patch)
tree42bc9cc4a0e33ff1f1a64ae5e23edc4a52ca4320 /src/openvic/map/Province.cpp
parent8a08be3e7e8477973e243716d431ad7117acfa43 (diff)
parent170ee25469322d25931050813a779dfbc2eaa4b0 (diff)
Merge pull request #10 from OpenVicProject/distributions
Added distributions for pop type and culture
Diffstat (limited to 'src/openvic/map/Province.cpp')
-rw-r--r--src/openvic/map/Province.cpp37
1 files changed, 28 insertions, 9 deletions
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) {