Skip to content

Commit e867291

Browse files
committed
Calculate pop ideology distributions
1 parent a691b6d commit e867291

20 files changed

+640
-119
lines changed

src/openvic-simulation/InstanceManager.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void InstanceManager::update_gamestate() {
4444
Logger::info("Update: ", today);
4545
update_modifier_sums();
4646
// Update gamestate...
47-
map_instance.update_gamestate(today, definition_manager.get_define_manager());
47+
map_instance.update_gamestate(*this);
4848
country_instance_manager.update_gamestate(*this);
4949

5050
gamestate_updated();
@@ -79,6 +79,7 @@ bool InstanceManager::setup() {
7979
definition_manager.get_economy_manager().get_building_type_manager(),
8080
market_instance,
8181
definition_manager.get_modifier_manager().get_modifier_effect_cache(),
82+
definition_manager.get_pop_manager().get_stratas(),
8283
definition_manager.get_pop_manager().get_pop_types(),
8384
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies()
8485
);
@@ -128,6 +129,8 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
128129

129130
today = bookmark->get_date();
130131

132+
politics_instance_manager.setup_starting_ideologies();
133+
131134
bool ret = map_instance.apply_history_to_provinces(
132135
definition_manager.get_history_manager().get_province_manager(), today,
133136
country_instance_manager,
@@ -139,16 +142,14 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
139142

140143
ret &= map_instance.get_state_manager().generate_states(
141144
map_instance,
145+
definition_manager.get_pop_manager().get_stratas(),
142146
definition_manager.get_pop_manager().get_pop_types(),
143147
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies()
144148
);
145149

146150
if (ret) {
147151
update_modifier_sums();
148-
map_instance.initialise_for_new_game(
149-
today,
150-
definition_manager.get_define_manager()
151-
);
152+
map_instance.initialise_for_new_game(*this);
152153
market_instance.execute_orders();
153154
}
154155

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ CountryInstance::CountryInstance(
111111
total_population { 0 },
112112
national_consciousness { 0 },
113113
national_militancy { 0 },
114+
population_by_strata { &strata_keys },
115+
militancy_by_strata { &strata_keys },
116+
life_needs_fulfilled_by_strata { &strata_keys },
117+
everyday_needs_fulfilled_by_strata { &strata_keys },
118+
luxury_needs_fulfilled_by_strata { &strata_keys },
114119
pop_type_distribution { &pop_type_keys },
115120
ideology_distribution { &ideology_keys },
116121
issue_distribution {},
@@ -220,14 +225,6 @@ bool CountryInstance::is_neighbour(CountryInstance const& country) const {
220225
return neighbouring_countries.contains(&country);
221226
}
222227

223-
fixed_point_t CountryInstance::get_pop_type_proportion(PopType const& pop_type) const {
224-
return pop_type_distribution[pop_type];
225-
}
226-
227-
fixed_point_t CountryInstance::get_ideology_support(Ideology const& ideology) const {
228-
return ideology_distribution[ideology];
229-
}
230-
231228
fixed_point_t CountryInstance::get_issue_support(Issue const& issue) const {
232229
const decltype(issue_distribution)::const_iterator it = issue_distribution.find(&issue);
233230

@@ -915,6 +912,13 @@ void CountryInstance::_update_population() {
915912
national_literacy = 0;
916913
national_consciousness = 0;
917914
national_militancy = 0;
915+
916+
population_by_strata.clear();
917+
militancy_by_strata.clear();
918+
life_needs_fulfilled_by_strata.clear();
919+
everyday_needs_fulfilled_by_strata.clear();
920+
luxury_needs_fulfilled_by_strata.clear();
921+
918922
pop_type_distribution.clear();
919923
ideology_distribution.clear();
920924
issue_distribution.clear();
@@ -931,6 +935,18 @@ void CountryInstance::_update_population() {
931935
national_consciousness += state->get_average_consciousness() * state_population;
932936
national_militancy += state->get_average_militancy() * state_population;
933937

938+
population_by_strata += state->get_population_by_strata();
939+
militancy_by_strata.mul_add(state->get_militancy_by_strata(), state->get_population_by_strata());
940+
life_needs_fulfilled_by_strata.mul_add(
941+
state->get_life_needs_fulfilled_by_strata(), state->get_population_by_strata()
942+
);
943+
everyday_needs_fulfilled_by_strata.mul_add(
944+
state->get_everyday_needs_fulfilled_by_strata(), state->get_population_by_strata()
945+
);
946+
luxury_needs_fulfilled_by_strata.mul_add(
947+
state->get_luxury_needs_fulfilled_by_strata(), state->get_population_by_strata()
948+
);
949+
934950
pop_type_distribution += state->get_pop_type_distribution();
935951
ideology_distribution += state->get_ideology_distribution();
936952
issue_distribution += state->get_issue_distribution();
@@ -943,6 +959,11 @@ void CountryInstance::_update_population() {
943959
national_literacy /= total_population;
944960
national_consciousness /= total_population;
945961
national_militancy /= total_population;
962+
963+
militancy_by_strata /= population_by_strata;
964+
life_needs_fulfilled_by_strata /= population_by_strata;
965+
everyday_needs_fulfilled_by_strata /= population_by_strata;
966+
luxury_needs_fulfilled_by_strata /= population_by_strata;
946967
}
947968

948969
// TODO - update national focus capacity

src/openvic-simulation/country/CountryInstance.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "openvic-simulation/military/Leader.hpp"
99
#include "openvic-simulation/military/UnitInstanceGroup.hpp"
1010
#include "openvic-simulation/modifier/ModifierSum.hpp"
11+
#include "openvic-simulation/politics/Ideology.hpp"
1112
#include "openvic-simulation/politics/Rule.hpp"
1213
#include "openvic-simulation/pop/PopType.hpp"
1314
#include "openvic-simulation/types/Date.hpp"
@@ -161,6 +162,13 @@ namespace OpenVic {
161162
// TODO - population change over last 30 days
162163
fixed_point_t PROPERTY(national_consciousness);
163164
fixed_point_t PROPERTY(national_militancy);
165+
166+
IndexedMap<Strata, pop_size_t> PROPERTY(population_by_strata);
167+
IndexedMap<Strata, fixed_point_t> PROPERTY(militancy_by_strata);
168+
IndexedMap<Strata, fixed_point_t> PROPERTY(life_needs_fulfilled_by_strata);
169+
IndexedMap<Strata, fixed_point_t> PROPERTY(everyday_needs_fulfilled_by_strata);
170+
IndexedMap<Strata, fixed_point_t> PROPERTY(luxury_needs_fulfilled_by_strata);
171+
164172
IndexedMap<PopType, pop_size_t> PROPERTY(pop_type_distribution);
165173
IndexedMap<Ideology, fixed_point_t> PROPERTY(ideology_distribution);
166174
fixed_point_map_t<Issue const*> PROPERTY(issue_distribution);
@@ -244,12 +252,31 @@ namespace OpenVic {
244252

245253
// The values returned by these functions are scaled by population size, so they must be divided by population size
246254
// to get the support as a proportion of 1.0
247-
fixed_point_t get_pop_type_proportion(PopType const& pop_type) const;
248-
fixed_point_t get_ideology_support(Ideology const& ideology) const;
255+
constexpr fixed_point_t get_pop_type_proportion(PopType const& pop_type) const {
256+
return pop_type_distribution[pop_type];
257+
}
258+
constexpr fixed_point_t get_ideology_support(Ideology const& ideology) const {
259+
return ideology_distribution[ideology];
260+
}
249261
fixed_point_t get_issue_support(Issue const& issue) const;
250262
fixed_point_t get_party_support(CountryParty const& party) const;
251263
fixed_point_t get_culture_proportion(Culture const& culture) const;
252264
fixed_point_t get_religion_proportion(Religion const& religion) const;
265+
constexpr pop_size_t get_strata_population(Strata const& strata) const {
266+
return population_by_strata[strata];
267+
}
268+
constexpr fixed_point_t get_strata_militancy(Strata const& strata) const {
269+
return militancy_by_strata[strata];
270+
}
271+
constexpr fixed_point_t get_strata_life_needs_fulfilled(Strata const& strata) const {
272+
return life_needs_fulfilled_by_strata[strata];
273+
}
274+
constexpr fixed_point_t get_strata_everyday_needs_fulfilled(Strata const& strata) const {
275+
return everyday_needs_fulfilled_by_strata[strata];
276+
}
277+
constexpr fixed_point_t get_strata_luxury_needs_fulfilled(Strata const& strata) const {
278+
return luxury_needs_fulfilled_by_strata[strata];
279+
}
253280

254281
bool add_owned_province(ProvinceInstance& new_province);
255282
bool remove_owned_province(ProvinceInstance const& province_to_remove);

src/openvic-simulation/map/MapInstance.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "MapInstance.hpp"
22

33
#include "openvic-simulation/history/ProvinceHistory.hpp"
4+
#include "openvic-simulation/InstanceManager.hpp"
45
#include "openvic-simulation/map/MapDefinition.hpp"
56
#include "openvic-simulation/utility/Logger.hpp"
67

@@ -45,6 +46,7 @@ bool MapInstance::setup(
4546
BuildingTypeManager const& building_type_manager,
4647
MarketInstance& market_instance,
4748
ModifierEffectCache const& modifier_effect_cache,
49+
decltype(ProvinceInstance::population_by_strata)::keys_type const& strata_keys,
4850
decltype(ProvinceInstance::pop_type_distribution)::keys_type const& pop_type_keys,
4951
decltype(ProvinceInstance::ideology_distribution)::keys_type const& ideology_keys
5052
) {
@@ -66,6 +68,7 @@ bool MapInstance::setup(
6668
market_instance,
6769
modifier_effect_cache,
6870
province,
71+
strata_keys,
6972
pop_type_keys,
7073
ideology_keys
7174
});
@@ -142,12 +145,12 @@ void MapInstance::update_modifier_sums(const Date today, StaticModifierCache con
142145
}
143146
}
144147

145-
void MapInstance::update_gamestate(const Date today, DefineManager const& define_manager) {
148+
void MapInstance::update_gamestate(InstanceManager const& instance_manager) {
146149
highest_province_population = 0;
147150
total_map_population = 0;
148151

149152
for (ProvinceInstance& province : province_instances.get_items()) {
150-
province.update_gamestate(today, define_manager);
153+
province.update_gamestate(instance_manager);
151154

152155
// Update population stats
153156
const pop_size_t province_population = province.get_total_population();
@@ -166,11 +169,11 @@ void MapInstance::map_tick(const Date today) {
166169
}
167170
}
168171

169-
void MapInstance::initialise_for_new_game(
170-
const Date today,
171-
DefineManager const& define_manager
172-
) {
173-
update_gamestate(today, define_manager);
172+
void MapInstance::initialise_for_new_game(InstanceManager const& instance_manager) {
173+
update_gamestate(instance_manager);
174+
175+
const Date today = instance_manager.get_today();
176+
174177
for (ProvinceInstance& province : province_instances.get_items()) {
175178
province.initialise_rgo();
176179
province.province_tick(today);

src/openvic-simulation/map/MapInstance.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace OpenVic {
4747
BuildingTypeManager const& building_type_manager,
4848
MarketInstance& market_instance,
4949
ModifierEffectCache const& modifier_effect_cache,
50+
decltype(ProvinceInstance::population_by_strata)::keys_type const& strata_keys,
5051
decltype(ProvinceInstance::pop_type_distribution)::keys_type const& pop_type_keys,
5152
decltype(ProvinceInstance::ideology_distribution)::keys_type const& ideology_keys
5253
);
@@ -56,8 +57,8 @@ namespace OpenVic {
5657
);
5758

5859
void update_modifier_sums(const Date today, StaticModifierCache const& static_modifier_cache);
59-
void update_gamestate(const Date today, DefineManager const& define_manager);
60+
void update_gamestate(InstanceManager const& instance_manager);
6061
void map_tick(const Date today);
61-
void initialise_for_new_game(const Date today, DefineManager const& define_manager);
62+
void initialise_for_new_game(InstanceManager const& instance_manager);
6263
};
6364
}

0 commit comments

Comments
 (0)