aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp25
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp21
2 files changed, 32 insertions, 14 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 5eba9ee..935a769 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -6,13 +6,21 @@
using namespace OpenVic;
using namespace OpenVic::NodeTools;
-CountryHistoryEntry::CountryHistoryEntry(CountryDefinition const& new_country, Date new_date)
- : HistoryEntry { new_date }, country { new_country } {}
+CountryHistoryEntry::CountryHistoryEntry(
+ CountryDefinition const& new_country, Date new_date, decltype(upper_house)::keys_t const& ideology_keys,
+ decltype(government_flag_overrides)::keys_t const& government_type_keys
+) : HistoryEntry { new_date }, country { new_country }, upper_house { &ideology_keys },
+ government_flag_overrides { &government_type_keys } {}
-CountryHistoryMap::CountryHistoryMap(CountryDefinition const& new_country) : country { new_country } {}
+CountryHistoryMap::CountryHistoryMap(
+ CountryDefinition const& new_country, decltype(ideology_keys) new_ideology_keys,
+ decltype(government_type_keys) new_government_type_keys
+) : country { new_country }, ideology_keys { new_ideology_keys }, government_type_keys { new_government_type_keys } {}
std::unique_ptr<CountryHistoryEntry> CountryHistoryMap::_make_entry(Date date) const {
- return std::unique_ptr<CountryHistoryEntry> { new CountryHistoryEntry { country, date } };
+ return std::unique_ptr<CountryHistoryEntry> {
+ new CountryHistoryEntry { country, date, ideology_keys, government_type_keys }
+ };
}
bool CountryHistoryMap::_load_history_entry(
@@ -90,8 +98,7 @@ bool CountryHistoryMap::_load_history_entry(
"prestige", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.prestige)),
"ruling_party", ZERO_OR_ONE, country.expect_party_identifier(assign_variable_callback_pointer_opt(entry.ruling_party)),
"last_election", ZERO_OR_ONE, expect_date(assign_variable_callback(entry.last_election)),
- "upper_house", ZERO_OR_ONE, politics_manager.get_ideology_manager().expect_ideology_dictionary_reserve_length(
- entry.upper_house,
+ "upper_house", ZERO_OR_ONE, politics_manager.get_ideology_manager().expect_ideology_dictionary(
[&entry](Ideology const& ideology, ast::NodeCPtr value) -> bool {
return expect_fixed_point(map_callback(entry.upper_house, &ideology))(value);
}
@@ -216,7 +223,9 @@ CountryHistoryMap const* CountryHistoryManager::get_country_history(CountryDefin
}
bool CountryHistoryManager::load_country_history_file(
- DefinitionManager& definition_manager, Dataloader const& dataloader, CountryDefinition const& country, ast::NodeCPtr root
+ DefinitionManager& definition_manager, Dataloader const& dataloader, CountryDefinition const& country,
+ decltype(CountryHistoryMap::ideology_keys) ideology_keys,
+ decltype(CountryHistoryMap::government_type_keys) government_type_keys, ast::NodeCPtr root
) {
if (locked) {
Logger::error("Attempted to load country history file for ", country, " after country history registry was locked!");
@@ -230,7 +239,7 @@ bool CountryHistoryManager::load_country_history_file(
decltype(country_histories)::iterator it = country_histories.find(&country);
if (it == country_histories.end()) {
const std::pair<decltype(country_histories)::iterator, bool> result =
- country_histories.emplace(&country, CountryHistoryMap { country });
+ country_histories.emplace(&country, CountryHistoryMap { country, ideology_keys, government_type_keys });
if (result.second) {
it = result.first;
} else {
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index 0de76c6..c74841d 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -1,11 +1,11 @@
#pragma once
#include <optional>
-#include <vector>
#include "openvic-simulation/history/HistoryMap.hpp"
#include "openvic-simulation/types/Date.hpp"
#include "openvic-simulation/types/fixed_point/FixedPointMap.hpp"
+#include "openvic-simulation/types/IndexedMap.hpp"
#include "openvic-simulation/types/OrderedContainers.hpp"
namespace OpenVic {
@@ -36,7 +36,7 @@ namespace OpenVic {
std::optional<Religion const*> PROPERTY(religion);
std::optional<CountryParty const*> PROPERTY(ruling_party);
std::optional<Date> PROPERTY(last_election);
- fixed_point_map_t<Ideology const*> PROPERTY(upper_house);
+ IndexedMap<Ideology, fixed_point_t> PROPERTY(upper_house);
std::optional<ProvinceDefinition const*> PROPERTY(capital);
std::optional<GovernmentType const*> PROPERTY(government_type);
std::optional<fixed_point_t> PROPERTY(plurality);
@@ -57,10 +57,13 @@ namespace OpenVic {
std::optional<fixed_point_t> PROPERTY(colonial_points);
string_set_t PROPERTY(country_flags);
string_set_t PROPERTY(global_flags);
- ordered_map<GovernmentType const*, GovernmentType const*> PROPERTY(government_flag_overrides);
+ IndexedMap<GovernmentType, GovernmentType const*> PROPERTY(government_flag_overrides);
ordered_set<Decision const*> PROPERTY(decisions);
- CountryHistoryEntry(CountryDefinition const& new_country, Date new_date);
+ CountryHistoryEntry(
+ CountryDefinition const& new_country, Date new_date, decltype(upper_house)::keys_t const& ideology_keys,
+ decltype(government_flag_overrides)::keys_t const& government_type_keys
+ );
};
class Dataloader;
@@ -72,9 +75,14 @@ namespace OpenVic {
private:
CountryDefinition const& PROPERTY(country);
+ decltype(CountryHistoryEntry::upper_house)::keys_t const& PROPERTY(ideology_keys);
+ decltype(CountryHistoryEntry::government_flag_overrides)::keys_t const& PROPERTY(government_type_keys);
protected:
- CountryHistoryMap(CountryDefinition const& new_country);
+ CountryHistoryMap(
+ CountryDefinition const& new_country, decltype(ideology_keys) new_ideology_keys,
+ decltype(government_type_keys) new_government_type_keys
+ );
std::unique_ptr<CountryHistoryEntry> _make_entry(Date date) const override;
bool _load_history_entry(
@@ -99,7 +107,8 @@ namespace OpenVic {
bool load_country_history_file(
DefinitionManager& definition_manager, Dataloader const& dataloader, CountryDefinition const& country,
- ast::NodeCPtr root
+ decltype(CountryHistoryMap::ideology_keys) ideology_keys,
+ decltype(CountryHistoryMap::government_type_keys) government_type_keys, ast::NodeCPtr root
);
};