diff options
author | Hop311 <Hop3114@gmail.com> | 2024-03-21 00:31:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-21 00:31:05 +0100 |
commit | 020ada6c8f0f1bf4486fd9e76ec29673044794d6 (patch) | |
tree | 5dc9698964d3980680dad3127fb53ecd4a600c5f /src/openvic-simulation/pop/Pop.cpp | |
parent | eece77afebf0e4d36b4c9ace3b1044f2c3da50f1 (diff) | |
parent | 6a99bd8237fa61bd740ba482b59ff428a7e2f123 (diff) |
Merge pull request #152 from OpenVicProject/pop-menu
GUI and Pop attribute work for Population Menu
Diffstat (limited to 'src/openvic-simulation/pop/Pop.cpp')
-rw-r--r-- | src/openvic-simulation/pop/Pop.cpp | 84 |
1 files changed, 83 insertions, 1 deletions
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( |