aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent60d3b5bdde3f0c4001fa8c4843f999e77568f810 (diff)
Add Pop attributes + generate test valuespop-menu
Diffstat (limited to 'src')
-rw-r--r--src/openvic-simulation/GameManager.cpp5
-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
-rw-r--r--src/openvic-simulation/pop/Pop.cpp84
-rw-r--r--src/openvic-simulation/pop/Pop.hpp21
7 files changed, 146 insertions, 7 deletions
diff --git a/src/openvic-simulation/GameManager.cpp b/src/openvic-simulation/GameManager.cpp
index a4cb5f4..bb807c9 100644
--- a/src/openvic-simulation/GameManager.cpp
+++ b/src/openvic-simulation/GameManager.cpp
@@ -63,7 +63,10 @@ bool GameManager::load_bookmark(Bookmark const* new_bookmark) {
Logger::warning("Bookmark date ", bookmark->get_date(), " is not in the game's time period!");
}
today = bookmark->get_date();
- ret &= map.apply_history_to_provinces(history_manager.get_province_manager(), today);
+ ret &= map.apply_history_to_provinces(
+ history_manager.get_province_manager(), today, politics_manager.get_ideology_manager(),
+ politics_manager.get_issue_manager(), *country_manager.get_country_by_identifier("ENG")
+ );
map.get_state_manager().generate_states(map);
// TODO - apply country history
return ret;
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
+ );
};
}
diff --git a/src/openvic-simulation/pop/Pop.cpp b/src/openvic-simulation/pop/Pop.cpp
index 21aede8..2490ef9 100644
--- a/src/openvic-simulation/pop/Pop.cpp
+++ b/src/openvic-simulation/pop/Pop.cpp
@@ -1,5 +1,6 @@
#include "Pop.hpp"
+#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/military/UnitType.hpp"
#include "openvic-simulation/politics/Ideology.hpp"
#include "openvic-simulation/politics/Issue.hpp"
@@ -23,6 +24,8 @@ Pop::Pop(
culture { new_culture },
religion { new_religion },
size { new_size },
+ location { nullptr },
+ total_change { 0 },
num_grown { 0 },
num_promoted { 0 },
num_demoted { 0 },
@@ -31,10 +34,89 @@ Pop::Pop(
num_migrated_colonial { 0 },
militancy { new_militancy },
consciousness { new_consciousness },
- rebel_type { new_rebel_type } {
+ rebel_type { new_rebel_type },
+ ideologies {},
+ issues {},
+ votes {},
+ unemployment { 0 },
+ cash { 0 },
+ income { 0 },
+ expenses { 0 },
+ savings { 0 },
+ life_needs_fulfilled { 0 },
+ everyday_needs_fulfilled { 0 },
+ luxury_needs_fulfilled { 0 } {
assert(size > 0);
}
+void Pop::setup_pop_test_values(
+ IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country
+) {
+ /* Returns +/- range% of size. */
+ const auto test_size = [this](int32_t range) -> pop_size_t {
+ return size * ((rand() % (2 * range + 1)) - range) / 100;
+ };
+
+ num_grown = test_size(5);
+ num_promoted = test_size(1);
+ num_demoted = test_size(1);
+ num_migrated_internal = test_size(3);
+ num_migrated_external = test_size(1);
+ num_migrated_colonial = test_size(2);
+
+ total_change =
+ num_grown + num_promoted + num_demoted + num_migrated_internal + num_migrated_external + num_migrated_colonial;
+
+ /* Generates a number between 0 and max (inclusive) and sets map[&key] to it if it's at least min. */
+ auto test_weight =
+ []<typename T, std::derived_from<T> U>(
+ fixed_point_map_t<T const*>& map, U const& key, int32_t min, int32_t max
+ ) -> void {
+ const int32_t value = rand() % (max + 1);
+ if (value >= min) {
+ map.emplace(&key, value);
+ }
+ };
+
+ /* All entries equally weighted for testing. */
+ ideologies.clear();
+ for (Ideology const& ideology : ideology_manager.get_ideologies()) {
+ test_weight(ideologies, ideology, 1, 5);
+ }
+ normalise_fixed_point_map(ideologies);
+
+ issues.clear();
+ for (Issue const& issue : issue_manager.get_issues()) {
+ test_weight(issues, issue, 3, 6);
+ }
+ for (Reform const& reform : issue_manager.get_reforms()) {
+ if (!reform.get_reform_group().get_type().is_uncivilised()) {
+ test_weight(issues, reform, 3, 6);
+ }
+ }
+ normalise_fixed_point_map(issues);
+
+ votes.clear();
+ for (CountryParty const& party : country.get_parties()) {
+ test_weight(votes, party, 4, 10);
+ }
+ normalise_fixed_point_map(votes);
+
+ /* Returns a fixed point between 0 and max. */
+ const auto test_range = [](fixed_point_t max = 1) -> fixed_point_t {
+ return (rand() % 256) * max / 256;
+ };
+
+ unemployment = test_range();
+ cash = test_range(20);
+ income = test_range(5);
+ expenses = test_range(5);
+ savings = test_range(15);
+ life_needs_fulfilled = test_range();
+ everyday_needs_fulfilled = test_range();
+ luxury_needs_fulfilled = test_range();
+}
+
Strata::Strata(std::string_view new_identifier) : HasIdentifier { new_identifier } {}
PopType::PopType(
diff --git a/src/openvic-simulation/pop/Pop.hpp b/src/openvic-simulation/pop/Pop.hpp
index c4e369f..fe1867f 100644
--- a/src/openvic-simulation/pop/Pop.hpp
+++ b/src/openvic-simulation/pop/Pop.hpp
@@ -23,6 +23,8 @@ namespace OpenVic {
struct IdeologyManager;
struct Issue;
struct IssueManager;
+ struct Province;
+ struct CountryParty;
/* REQUIREMENTS:
* POP-18, POP-19, POP-20, POP-21, POP-34, POP-35, POP-36, POP-37
@@ -39,8 +41,10 @@ namespace OpenVic {
Culture const& PROPERTY(culture);
Religion const& PROPERTY(religion);
pop_size_t PROPERTY(size);
+ Province const* PROPERTY_RW(location);
/* Last day's size change by source. */
+ pop_size_t PROPERTY(total_change);
pop_size_t PROPERTY(num_grown);
pop_size_t PROPERTY(num_promoted); // TODO - detailed promotion/demotion info (what to)
pop_size_t PROPERTY(num_demoted);
@@ -53,6 +57,19 @@ namespace OpenVic {
fixed_point_t PROPERTY(literacy);
RebelType const* PROPERTY(rebel_type);
+ fixed_point_map_t<Ideology const*> PROPERTY(ideologies);
+ fixed_point_map_t<Issue const*> PROPERTY(issues);
+ fixed_point_map_t<CountryParty const*> PROPERTY(votes);
+
+ fixed_point_t PROPERTY(unemployment);
+ fixed_point_t PROPERTY(cash);
+ fixed_point_t PROPERTY(income);
+ fixed_point_t PROPERTY(expenses);
+ fixed_point_t PROPERTY(savings);
+ fixed_point_t PROPERTY(life_needs_fulfilled);
+ fixed_point_t PROPERTY(everyday_needs_fulfilled);
+ fixed_point_t PROPERTY(luxury_needs_fulfilled);
+
Pop(
PopType const& new_type,
Culture const& new_culture,
@@ -68,6 +85,10 @@ namespace OpenVic {
Pop(Pop&&) = default;
Pop& operator=(Pop const&) = delete;
Pop& operator=(Pop&&) = delete;
+
+ void setup_pop_test_values(
+ IdeologyManager const& ideology_manager, IssueManager const& issue_manager, Country const& country
+ );
};
struct Strata : HasIdentifier {