aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2024-08-30 23:29:03 +0200
committer GitHub <noreply@github.com>2024-08-30 23:29:03 +0200
commit6c88ecaf2d158dfff1e0b88f0509782e1a15ae3d (patch)
tree894e8c0514a572bb4cc64216f40833995660b22d
parent68fca4f504e7f178f69d0dfd64e90ffb1d579322 (diff)
parent8d5068c1db9a02a34d675536f41aee61ec3e482a (diff)
Merge pull request #188 from OpenVicProject/gov-flag-type
Load government flag overrides from history and apply them
-rw-r--r--src/openvic-simulation/InstanceManager.cpp1
-rw-r--r--src/openvic-simulation/country/CountryInstance.cpp20
-rw-r--r--src/openvic-simulation/country/CountryInstance.hpp10
-rw-r--r--src/openvic-simulation/types/IndexedMap.hpp10
4 files changed, 37 insertions, 4 deletions
diff --git a/src/openvic-simulation/InstanceManager.cpp b/src/openvic-simulation/InstanceManager.cpp
index cd5da59..1df6e90 100644
--- a/src/openvic-simulation/InstanceManager.cpp
+++ b/src/openvic-simulation/InstanceManager.cpp
@@ -80,6 +80,7 @@ bool InstanceManager::setup() {
definition_manager.get_research_manager().get_technology_manager().get_technologies(),
definition_manager.get_research_manager().get_invention_manager().get_inventions(),
definition_manager.get_politics_manager().get_ideology_manager().get_ideologies(),
+ definition_manager.get_politics_manager().get_government_type_manager().get_government_types(),
definition_manager.get_pop_manager().get_pop_types()
);
diff --git a/src/openvic-simulation/country/CountryInstance.cpp b/src/openvic-simulation/country/CountryInstance.cpp
index 0b27b78..3c2e7bb 100644
--- a/src/openvic-simulation/country/CountryInstance.cpp
+++ b/src/openvic-simulation/country/CountryInstance.cpp
@@ -16,6 +16,7 @@ CountryInstance::CountryInstance(
decltype(technologies)::keys_t const& technology_keys,
decltype(inventions)::keys_t const& invention_keys,
decltype(upper_house)::keys_t const& ideology_keys,
+ decltype(government_flag_overrides)::keys_t const& government_type_keys,
decltype(pop_type_distribution)::keys_t const& pop_type_keys
) : /* Main attributes */
country_definition { new_country_definition },
@@ -52,6 +53,8 @@ CountryInstance::CountryInstance(
ruling_party { nullptr },
upper_house { &ideology_keys },
reforms {},
+ government_flag_overrides { &government_type_keys },
+ flag_government_type { nullptr },
suppression_points { 0 },
infamy { 0 },
plurality { 0 },
@@ -300,7 +303,7 @@ bool CountryInstance::apply_history_to_country(CountryHistoryEntry const* entry,
for (std::string const& flag : entry->get_global_flags()) {
// TODO - set global flag
}
- // entry->get_government_flag_overrides();
+ government_flag_overrides.write_non_empty_values(entry->get_government_flag_overrides());
for (Decision const* decision : entry->get_decisions()) {
// TODO - take decision
}
@@ -393,6 +396,16 @@ void CountryInstance::update_gamestate() {
colour = ERROR_COLOUR;
}
+ if (government_type != nullptr) {
+ flag_government_type = government_flag_overrides[*government_type];
+
+ if (flag_government_type == nullptr) {
+ flag_government_type = government_type;
+ }
+ } else {
+ flag_government_type = nullptr;
+ }
+
// Order of updates might need to be changed/functions split up to account for dependencies
_update_production();
_update_budget();
@@ -421,12 +434,15 @@ bool CountryInstanceManager::generate_country_instances(
decltype(CountryInstance::technologies)::keys_t const& technology_keys,
decltype(CountryInstance::inventions)::keys_t const& invention_keys,
decltype(CountryInstance::upper_house)::keys_t const& ideology_keys,
+ decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys,
decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys
) {
reserve_more(country_instances, country_definition_manager.get_country_definition_count());
for (CountryDefinition const& country_definition : country_definition_manager.get_country_definitions()) {
- country_instances.add_item({ &country_definition, technology_keys, invention_keys, ideology_keys, pop_type_keys });
+ country_instances.add_item({
+ &country_definition, technology_keys, invention_keys, ideology_keys, government_type_keys, pop_type_keys
+ });
}
return true;
diff --git a/src/openvic-simulation/country/CountryInstance.hpp b/src/openvic-simulation/country/CountryInstance.hpp
index 5b26f7f..f4baf2d 100644
--- a/src/openvic-simulation/country/CountryInstance.hpp
+++ b/src/openvic-simulation/country/CountryInstance.hpp
@@ -78,6 +78,8 @@ namespace OpenVic {
IndexedMap<Ideology, fixed_point_t> PROPERTY(upper_house);
std::vector<Reform const*> PROPERTY(reforms); // TODO: should be map of reform groups to active reforms: must set defaults & validate applied history
// TODO - national issue support distribution (for just voters and for everyone)
+ IndexedMap<GovernmentType, GovernmentType const*> PROPERTY(government_flag_overrides);
+ GovernmentType const* PROPERTY(flag_government_type);
fixed_point_t PROPERTY(suppression_points);
fixed_point_t PROPERTY(infamy);
fixed_point_t PROPERTY(plurality);
@@ -127,8 +129,11 @@ namespace OpenVic {
UNIT_BRANCHED_GETTER(get_leaders, generals, admirals);
CountryInstance(
- CountryDefinition const* new_country_definition, decltype(technologies)::keys_t const& technology_keys,
- decltype(inventions)::keys_t const& invention_keys, decltype(upper_house)::keys_t const& ideology_keys,
+ CountryDefinition const* new_country_definition,
+ decltype(technologies)::keys_t const& technology_keys,
+ decltype(inventions)::keys_t const& invention_keys,
+ decltype(upper_house)::keys_t const& ideology_keys,
+ decltype(government_flag_overrides)::keys_t const& government_type_keys,
decltype(pop_type_distribution)::keys_t const& pop_type_keys
);
@@ -198,6 +203,7 @@ namespace OpenVic {
decltype(CountryInstance::technologies)::keys_t const& technology_keys,
decltype(CountryInstance::inventions)::keys_t const& invention_keys,
decltype(CountryInstance::upper_house)::keys_t const& ideology_keys,
+ decltype(CountryInstance::government_flag_overrides)::keys_t const& government_type_keys,
decltype(CountryInstance::pop_type_distribution)::keys_t const& pop_type_keys
);
diff --git a/src/openvic-simulation/types/IndexedMap.hpp b/src/openvic-simulation/types/IndexedMap.hpp
index 30cf5cd..5682c0e 100644
--- a/src/openvic-simulation/types/IndexedMap.hpp
+++ b/src/openvic-simulation/types/IndexedMap.hpp
@@ -169,6 +169,16 @@ namespace OpenVic {
return true;
}
+ constexpr void write_non_empty_values(IndexedMap const& other) {
+ const size_t count = std::min(container_t::size(), other.size());
+ for (size_t index = 0; index < count; ++index) {
+ value_t const& value = other[index];
+ if (value) {
+ container_t::operator[](index) = value;
+ }
+ }
+ }
+
fixed_point_map_t<key_t const *> to_fixed_point_map() const
requires(std::same_as<value_t, fixed_point_t>)
{