aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/map
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2024-03-20 00:23:58 +0100
committer hop311 <hop3114@gmail.com>2024-03-20 23:34:17 +0100
commit6a99bd8237fa61bd740ba482b59ff428a7e2f123 (patch)
tree5dc9698964d3980680dad3127fb53ecd4a600c5f /src/openvic-simulation/map
parent60d3b5bdde3f0c4001fa8c4843f999e77568f810 (diff)
Add Pop attributes + generate test valuespop-menu
Diffstat (limited to 'src/openvic-simulation/map')
-rw-r--r--src/openvic-simulation/map/Map.cpp13
-rw-r--r--src/openvic-simulation/map/Map.hpp5
-rw-r--r--src/openvic-simulation/map/Province.cpp19
-rw-r--r--src/openvic-simulation/map/Province.hpp6
4 files changed, 38 insertions, 5 deletions
diff --git a/src/openvic-simulation/map/Map.cpp b/src/openvic-simulation/map/Map.cpp
index f87246f..81a599e 100644
--- a/src/openvic-simulation/map/Map.cpp
+++ b/src/openvic-simulation/map/Map.cpp
@@ -446,25 +446,36 @@ bool Map::reset(BuildingTypeManager const& building_type_manager) {
return ret;
}
-bool Map::apply_history_to_provinces(ProvinceHistoryManager const& history_manager, Date date) {
+bool Map::apply_history_to_provinces(
+ ProvinceHistoryManager const& history_manager, Date date, IdeologyManager const& ideology_manager,
+ IssueManager const& issue_manager, Country const& country
+) {
bool ret = true;
+
for (Province& province : provinces.get_items()) {
if (!province.is_water()) {
ProvinceHistoryMap const* history_map = history_manager.get_province_history(&province);
+
if (history_map != nullptr) {
ProvinceHistoryEntry const* pop_history_entry = nullptr;
+
for (ProvinceHistoryEntry const* entry : history_map->get_entries_up_to(date)) {
province.apply_history_to_province(entry);
+
if (!entry->get_pops().empty()) {
pop_history_entry = entry;
}
}
+
if (pop_history_entry != nullptr) {
province.add_pop_vec(pop_history_entry->get_pops());
+
+ province.setup_pop_test_values(ideology_manager, issue_manager, country);
}
}
}
}
+
return ret;
}
diff --git a/src/openvic-simulation/map/Map.hpp b/src/openvic-simulation/map/Map.hpp
index e2c4bd6..807945a 100644
--- a/src/openvic-simulation/map/Map.hpp
+++ b/src/openvic-simulation/map/Map.hpp
@@ -128,7 +128,10 @@ namespace OpenVic {
bool generate_mapmode_colours(Mapmode::index_t index, uint8_t* target) const;
bool reset(BuildingTypeManager const& building_type_manager);
- bool apply_history_to_provinces(ProvinceHistoryManager const& history_manager, Date date);
+ bool apply_history_to_provinces(
+ ProvinceHistoryManager const& history_manager, Date date, IdeologyManager const& ideology_manager,
+ IssueManager const& issue_manager, Country const& country
+ );
void update_highest_province_population();
void update_total_map_population();
diff --git a/src/openvic-simulation/map/Province.cpp b/src/openvic-simulation/map/Province.cpp
index 94c8dcb..d1183f5 100644
--- a/src/openvic-simulation/map/Province.cpp
+++ b/src/openvic-simulation/map/Province.cpp
@@ -65,9 +65,14 @@ bool Province::expand_building(size_t building_index) {
return building->expand();
}
+void Province::_add_pop(Pop pop) {
+ pop.set_location(this);
+ pops.push_back(std::move(pop));
+}
+
bool Province::add_pop(Pop&& pop) {
if (!is_water()) {
- pops.push_back(std::move(pop));
+ _add_pop(std::move(pop));
return true;
} else {
Logger::error("Trying to add pop to water province ", get_identifier());
@@ -79,7 +84,7 @@ bool Province::add_pop_vec(std::vector<Pop> const& pop_vec) {
if (!is_water()) {
reserve_more(pops, pop_vec.size());
for (Pop const& pop : pop_vec) {
- pops.push_back(pop);
+ _add_pop(pop);
}
return true;
} else {
@@ -104,7 +109,7 @@ void Province::update_pops() {
for (Pop const& pop : pops) {
total_population += pop.get_size();
pop_type_distribution[&pop.get_type()] += pop.get_size();
- //ideology_distribution[&pop.get_???()] += pop.get_size();
+ ideology_distribution += pop.get_ideologies();
culture_distribution[&pop.get_culture()] += pop.get_size();
religion_distribution[&pop.get_religion()] += pop.get_size();
}
@@ -257,3 +262,11 @@ bool Province::apply_history_to_province(ProvinceHistoryEntry const* entry) {
// TODO: party loyalties for each POP when implemented on POP side
return ret;
}
+
+void Province::setup_pop_test_values(
+ IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country
+) {
+ for (Pop& pop : pops) {
+ pop.setup_pop_test_values(ideology_manager, issue_manager, country);
+ }
+}
diff --git a/src/openvic-simulation/map/Province.hpp b/src/openvic-simulation/map/Province.hpp
index 1df5676..476ecc9 100644
--- a/src/openvic-simulation/map/Province.hpp
+++ b/src/openvic-simulation/map/Province.hpp
@@ -128,6 +128,8 @@ namespace OpenVic {
Province(std::string_view new_identifier, colour_t new_colour, index_t new_index);
+ void _add_pop(Pop pop);
+
public:
Province(Province&&) = default;
@@ -155,5 +157,9 @@ namespace OpenVic {
bool reset(BuildingTypeManager const& building_type_manager);
bool apply_history_to_province(ProvinceHistoryEntry const* entry);
+
+ void setup_pop_test_values(
+ IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country
+ );
};
}