Skip to content

Commit 5b3cd6f

Browse files
committed
More ideology generation work
1 parent e867291 commit 5b3cd6f

File tree

8 files changed

+119
-15
lines changed

8 files changed

+119
-15
lines changed

src/headless/main.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
129129
// ret = false;
130130
// }
131131

132+
Pop const& pop = *game_manager.get_instance_manager()->get_map_instance().get_province_instance_by_index(300)->get_pops().begin();
133+
134+
Logger::info(
135+
"Pop has type ", pop.get_type()->get_identifier(),
136+
", size ", pop.get_size(),
137+
", culture ", pop.get_culture().get_identifier(),
138+
", religion ", pop.get_religion().get_identifier(),
139+
", ideology:"
140+
);
141+
for (auto [ideology, support] : pop.get_ideology_distribution()) {
142+
Logger::info(" ", ideology.get_identifier(), " - ", support);
143+
}
144+
145+
ProvinceInstance const& province = *pop.get_location();
146+
Logger::info("Province ", province.get_identifier(), " has ", province.get_total_population(), " pops with ideology:");
147+
for (auto [ideology, support] : province.get_ideology_distribution()) {
148+
Logger::info(" ", ideology.get_identifier(), " - ", support);
149+
}
150+
151+
State const& state = *province.get_state();
152+
Logger::info("State ", state.get_identifier(), " has ", state.get_total_population(), " pops with ideology:");
153+
for (auto [ideology, support] : state.get_ideology_distribution()) {
154+
Logger::info(" ", ideology.get_identifier(), " - ", support);
155+
}
156+
157+
CountryInstance const& country = *state.get_owner();
158+
Logger::info("Country ", country.get_identifier(), " has ", country.get_total_population(), " pops with ideology:");
159+
for (auto [ideology, support] : country.get_ideology_distribution()) {
160+
Logger::info(" ", ideology.get_identifier(), " - ", support);
161+
}
162+
163+
Logger::info("National value of ", country.get_identifier(), " is ", country.get_national_value());
164+
132165
return ret;
133166
}
134167

src/openvic-simulation/InstanceManager.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ bool InstanceManager::load_bookmark(Bookmark const* new_bookmark) {
138138
definition_manager.get_politics_manager().get_issue_manager()
139139
);
140140

141+
// It is important that province history is applied before country history as province history includes
142+
// generating pops which then have stats like literacy and consciousness set by country history.
143+
141144
ret &= country_instance_manager.apply_history_to_countries(*this);
142145

143146
ret &= map_instance.get_state_manager().generate_states(

src/openvic-simulation/country/CountryInstance.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -837,14 +837,10 @@ bool CountryInstance::apply_history_to_country(CountryHistoryEntry const& entry,
837837
}
838838
apply_foreign_investments(entry.get_foreign_investment(), instance_manager.get_country_instance_manager());
839839

840-
// These need to be applied to pops
841-
// entry.get_consciousness();
842-
// entry.get_nonstate_consciousness();
843-
// entry.get_literacy();
844-
// entry.get_nonstate_culture_literacy();
845-
846840
set_optional(releasable_vassal, entry.is_releasable_vassal());
847-
// entry.get_colonial_points();
841+
842+
// TODO - entry.get_colonial_points();
843+
848844
for (std::string const& flag : entry.get_country_flags()) {
849845
ret &= set_flag(flag, true);
850846
}
@@ -1445,15 +1441,32 @@ bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instanc
14451441
history_manager.get_country_history(country_instance.get_country_definition());
14461442

14471443
if (history_map != nullptr) {
1444+
static constexpr fixed_point_t DEFAULT_STATE_CULTURE_LITERACY = fixed_point_t::_0_50();
14481445
CountryHistoryEntry const* oob_history_entry = nullptr;
1446+
std::optional<fixed_point_t> state_culture_consciousness;
1447+
std::optional<fixed_point_t> nonstate_culture_consciousness;
1448+
fixed_point_t state_culture_literacy = DEFAULT_STATE_CULTURE_LITERACY;
1449+
std::optional<fixed_point_t> nonstate_culture_literacy;
14491450

14501451
for (auto const& [entry_date, entry] : history_map->get_entries()) {
14511452
if (entry_date <= today) {
14521453
ret &= country_instance.apply_history_to_country(*entry, instance_manager);
14531454

1454-
if (entry->get_inital_oob()) {
1455+
if (entry->get_inital_oob().has_value()) {
14551456
oob_history_entry = entry.get();
14561457
}
1458+
if (entry->get_consciousness().has_value()) {
1459+
state_culture_consciousness = entry->get_consciousness();
1460+
}
1461+
if (entry->get_nonstate_consciousness().has_value()) {
1462+
nonstate_culture_consciousness = entry->get_nonstate_consciousness();
1463+
}
1464+
if (entry->get_literacy().has_value()) {
1465+
state_culture_literacy = *entry->get_literacy();
1466+
}
1467+
if (entry->get_nonstate_culture_literacy().has_value()) {
1468+
nonstate_culture_literacy = entry->get_nonstate_culture_literacy();
1469+
}
14571470
} else {
14581471
// All foreign investments are applied regardless of the bookmark's date
14591472
country_instance.apply_foreign_investments(entry->get_foreign_investment(), *this);
@@ -1465,6 +1478,28 @@ bool CountryInstanceManager::apply_history_to_countries(InstanceManager& instanc
14651478
map_instance, country_instance, *oob_history_entry->get_inital_oob()
14661479
);
14671480
}
1481+
1482+
// TODO - check if better to do "if"s then "for"s, so looping multiple times rather than having lots of
1483+
// redundant "if" statements?
1484+
for (ProvinceInstance* province : country_instance.get_owned_provinces()) {
1485+
for (Pop& pop : province->get_mutable_pops()) {
1486+
if (country_instance.is_primary_or_accepted_culture(pop.get_culture())) {
1487+
pop.set_literacy(state_culture_literacy);
1488+
1489+
if (state_culture_consciousness.has_value()) {
1490+
pop.set_consciousness(*state_culture_consciousness);
1491+
}
1492+
} else {
1493+
if (nonstate_culture_literacy.has_value()) {
1494+
pop.set_literacy(*nonstate_culture_literacy);
1495+
}
1496+
1497+
if (nonstate_culture_consciousness.has_value()) {
1498+
pop.set_consciousness(*nonstate_culture_consciousness);
1499+
}
1500+
}
1501+
}
1502+
}
14681503
} else {
14691504
Logger::error("Country ", country_instance.get_identifier(), " has no history!");
14701505
ret = false;

src/openvic-simulation/map/MapInstance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ bool MapInstance::apply_history_to_provinces(
125125
}
126126

127127
if (pop_history_entry == nullptr) {
128-
Logger::warning("No pop history entry for province ",province.get_identifier(), " for date ", date.to_string());
128+
Logger::warning("No pop history entry for province ", province.get_identifier(), " for date ", date);
129129
} else {
130-
province.add_pop_vec(pop_history_entry->get_pops());
130+
ret &= province.add_pop_vec(pop_history_entry->get_pops());
131131
province.setup_pop_test_values(issue_manager);
132132
}
133133

134-
ret&=province.set_rgo_production_type_nullable(rgo_production_type_nullable);
134+
ret &= province.set_rgo_production_type_nullable(rgo_production_type_nullable);
135135
}
136136
}
137137
}

src/openvic-simulation/pop/Pop.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
using namespace OpenVic;
99

10+
static constexpr fixed_point_t DEFAULT_POP_LITERACY = fixed_point_t::_0_10();
11+
1012
PopBase::PopBase(
1113
PopType const& new_type, Culture const& new_culture, Religion const& new_religion, pop_size_t new_size,
1214
fixed_point_t new_militancy, fixed_point_t new_consciousness, RebelType const* new_rebel_type
@@ -23,6 +25,7 @@ Pop::Pop(PopBase const& pop_base, decltype(ideology_distribution)::keys_type con
2325
num_migrated_internal { 0 },
2426
num_migrated_external { 0 },
2527
num_migrated_colonial { 0 },
28+
literacy { DEFAULT_POP_LITERACY },
2629
ideology_distribution { &ideology_keys },
2730
issue_distribution {},
2831
vote_distribution { nullptr },
@@ -183,6 +186,17 @@ fixed_point_t Pop::get_party_support(CountryParty const& party) const {
183186
void Pop::update_gamestate(
184187
InstanceManager const& instance_manager, CountryInstance const* owner, const fixed_point_t pop_size_per_regiment_multiplier
185188
) {
189+
static constexpr fixed_point_t MIN_MILITANCY = fixed_point_t::_0();
190+
static constexpr fixed_point_t MAX_MILITANCY = fixed_point_t::_10();
191+
static constexpr fixed_point_t MIN_CONSCIOUSNESS = fixed_point_t::_0();
192+
static constexpr fixed_point_t MAX_CONSCIOUSNESS = fixed_point_t::_10();
193+
static constexpr fixed_point_t MIN_LITERACY = fixed_point_t::_0_01();
194+
static constexpr fixed_point_t MAX_LITERACY = fixed_point_t::_1();
195+
196+
militancy = std::clamp(militancy, MIN_MILITANCY, MAX_MILITANCY);
197+
consciousness = std::clamp(consciousness, MIN_CONSCIOUSNESS, MAX_CONSCIOUSNESS);
198+
literacy = std::clamp(literacy, MIN_LITERACY, MAX_LITERACY);
199+
186200
if (type->get_can_be_recruited()) {
187201
MilitaryDefines const& military_defines =
188202
instance_manager.get_definition_manager().get_define_manager().get_military_defines();

src/openvic-simulation/pop/Pop.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ namespace OpenVic {
1616
Culture const& PROPERTY_ACCESS(culture, protected);
1717
Religion const& PROPERTY_ACCESS(religion, protected);
1818
pop_size_t PROPERTY_ACCESS(size, protected);
19-
fixed_point_t PROPERTY_ACCESS(militancy, protected);
20-
fixed_point_t PROPERTY_ACCESS(consciousness, protected);
19+
fixed_point_t PROPERTY_RW_ACCESS(militancy, protected);
20+
fixed_point_t PROPERTY_RW_ACCESS(consciousness, protected);
2121
RebelType const* PROPERTY_ACCESS(rebel_type, protected);
2222

2323
PopBase(
@@ -66,7 +66,7 @@ namespace OpenVic {
6666
pop_size_t PROPERTY(num_migrated_external);
6767
pop_size_t PROPERTY(num_migrated_colonial);
6868

69-
fixed_point_t PROPERTY(literacy);
69+
fixed_point_t PROPERTY_RW(literacy);
7070

7171
// All of these should have a total size equal to the pop size, allowing the distributions from different pops to be
7272
// added together with automatic weighting based on their relative sizes. Similarly, the province, state and country

src/openvic-simulation/scripts/Condition.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,10 @@ static bool _parse_condition_node_value_callback(
534534
ret = definition_manager.get_politics_manager().get_issue_manager().expect_reform_identifier_or_string(
535535
assign_variable_callback_pointer(value)
536536
)(node);
537+
} else if constexpr (std::same_as<T, NationalValue const*>) {
538+
ret = definition_manager.get_politics_manager().get_national_value_manager().expect_national_value_identifier_or_string(
539+
assign_variable_callback_pointer(value)
540+
)(node);
537541
} else if constexpr (std::same_as<T, Invention const*>) {
538542
ret = definition_manager.get_research_manager().get_invention_manager().expect_invention_identifier_or_string(
539543
assign_variable_callback_pointer(value)
@@ -589,6 +593,9 @@ static bool _parse_condition_node_value_callback(
589593
"which", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback_string(value.first)),
590594
"value", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(value.second))
591595
)(node);
596+
} else {
597+
Logger::error("Cannot parse condition \"", condition.get_identifier(), "\": unknown value type!");
598+
ret = false;
592599
}
593600

594601
if (ret) {

src/openvic-simulation/types/fixed_point/FixedPoint.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace OpenVic {
3838
#include "openvic-simulation/types/fixed_point/FixedPointLUT_sin.hpp"
3939

4040
static_assert(SIN_LUT_PRECISION == PRECISION);
41-
41+
4242
// Doesn't account for sign, so -n.abc -> 1 - 0.abc
4343
constexpr fixed_point_t get_frac() const {
4444
return value & FRAC_MASK;
@@ -83,10 +83,22 @@ namespace OpenVic {
8383
return 4;
8484
}
8585

86+
static constexpr fixed_point_t _10() {
87+
return 10;
88+
}
89+
8690
static constexpr fixed_point_t _100() {
8791
return 100;
8892
}
8993

94+
static constexpr fixed_point_t _0_01() {
95+
return _1() / 100;
96+
}
97+
98+
static constexpr fixed_point_t _0_10() {
99+
return _1() / 10;
100+
}
101+
90102
static constexpr fixed_point_t _0_20() {
91103
return _1() / 5;
92104
}

0 commit comments

Comments
 (0)