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/Bookmark.cpp10
-rw-r--r--src/openvic-simulation/history/Bookmark.hpp2
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp82
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp6
-rw-r--r--src/openvic-simulation/history/HistoryMap.cpp4
-rw-r--r--src/openvic-simulation/history/HistoryMap.hpp48
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp71
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp11
8 files changed, 183 insertions, 51 deletions
diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp
index 2927950..b758867 100644
--- a/src/openvic-simulation/history/Bookmark.cpp
+++ b/src/openvic-simulation/history/Bookmark.cpp
@@ -48,3 +48,13 @@ bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) {
return ret;
}
+
+Date BookmarkManager::get_last_bookmark_date() const {
+ Date ret {};
+ for (Bookmark const& bookmark : get_bookmarks()) {
+ if (bookmark.get_date() > ret) {
+ ret = bookmark.get_date();
+ }
+ }
+ return ret;
+}
diff --git a/src/openvic-simulation/history/Bookmark.hpp b/src/openvic-simulation/history/Bookmark.hpp
index 7401105..6f30586 100644
--- a/src/openvic-simulation/history/Bookmark.hpp
+++ b/src/openvic-simulation/history/Bookmark.hpp
@@ -38,5 +38,7 @@ namespace OpenVic {
uint32_t initial_camera_y
);
bool load_bookmark_file(ast::NodeCPtr root);
+
+ Date get_last_bookmark_date() const;
};
}
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 9ee7d65..00c88b8 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -25,9 +25,10 @@ bool CountryHistoryMap::_load_history_entry(
CountryManager const& country_manager = game_manager.get_country_manager();
TechnologyManager const& technology_manager = game_manager.get_research_manager().get_technology_manager();
InventionManager const& invention_manager = game_manager.get_research_manager().get_invention_manager();
+ DecisionManager const& decision_manager = game_manager.get_decision_manager();
return expect_dictionary_keys_and_default(
- [this, &game_manager, &dataloader, &deployment_manager, &issue_manager,
+ [this, &game_manager, &dataloader, &deployment_manager, &issue_manager,
&technology_manager, &invention_manager, &country_manager, &entry](std::string_view key, ast::NodeCPtr value) -> bool {
ReformGroup const* reform_group = issue_manager.get_reform_group_by_identifier(key);
if (reform_group != nullptr) {
@@ -66,14 +67,11 @@ bool CountryHistoryMap::_load_history_entry(
return entry.inventions.emplace(invention, flag).second;
} else return false;
}
-
+
return _load_history_sub_entry_callback(
game_manager, dataloader, deployment_manager, entry.get_date(), value, key, value
);
},
- /* we have to use a lambda, assign_variable_callback_pointer
- * apparently doesn't play nice with const & non-const accessors */
- // TODO - fix this issue (cause by provinces having non-const accessors)
"capital", ZERO_OR_ONE,
game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(entry.capital)),
"primary_culture", ZERO_OR_ONE,
@@ -122,24 +120,74 @@ bool CountryHistoryMap::_load_history_entry(
"consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.consciousness)),
"nonstate_consciousness", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.nonstate_consciousness)),
"is_releasable_vassal", ZERO_OR_ONE, expect_bool(assign_variable_callback(entry.releasable_vassal)),
- "decision", ZERO_OR_ONE, success_callback, //TODO: decisions
+ "decision", ZERO_OR_MORE, decision_manager.expect_decision_identifier(set_callback_pointer(entry.decisions)),
"govt_flag", ZERO_OR_ONE, [&entry, &politics_manager](ast::NodeCPtr value) -> bool {
+ GovernmentTypeManager const& government_type_manager = politics_manager.get_government_type_manager();
GovernmentType const* government_type = nullptr;
- std::string_view flag;
- bool ret = expect_dictionary_keys(
- "government", ONE_EXACTLY, politics_manager.get_government_type_manager()
- .expect_government_type_identifier(assign_variable_callback_pointer(government_type)),
- "flag", ONE_EXACTLY, expect_identifier_or_string(assign_variable_callback(flag))
+ bool flag_expected = false;
+ bool ret = expect_dictionary(
+ [&entry, &government_type_manager, &government_type, &flag_expected](std::string_view id,
+ ast::NodeCPtr node) -> bool {
+ if (id == "government") {
+ bool ret = true;
+ if (flag_expected) {
+ Logger::error(
+ "Government key found when expect flag type override for ", government_type,
+ " in history of ", entry.get_country().get_identifier()
+ );
+ ret = false;
+ }
+ flag_expected = true;
+ government_type = nullptr;
+ ret &= government_type_manager.expect_government_type_identifier(
+ assign_variable_callback_pointer(government_type)
+ )(node);
+ return ret;
+ } else if (id == "flag") {
+ if (flag_expected) {
+ flag_expected = false;
+ GovernmentType const* flag_override_government_type = nullptr;
+ bool ret = government_type_manager.expect_government_type_identifier(
+ assign_variable_callback_pointer(flag_override_government_type)
+ )(node);
+ /* If the first government type is null, the "government" section will have already output
+ * an error, so no need to output another one here. */
+ if (government_type != nullptr && flag_override_government_type != nullptr) {
+ ret &= entry.government_flag_overrides.emplace(
+ government_type, flag_override_government_type
+ ).second;
+ }
+ return ret;
+ } else {
+ Logger::error(
+ "Flag key found when expecting government type for flag type override in history of ",
+ entry.get_country().get_identifier()
+ );
+ return false;
+ }
+ } else {
+ Logger::error(
+ "Invalid key ", id, " in government flag overrides in history of ",
+ entry.get_country().get_identifier()
+ );
+ return false;
+ }
+ }
)(value);
- if (government_type != nullptr) {
- return ret & entry.government_flags.emplace(government_type, flag).second;
- } else return false;
+ if (flag_expected) {
+ Logger::error(
+ "Missing flag type override for government type ", government_type, " in history of ",
+ entry.get_country().get_identifier()
+ );
+ ret = false;
+ }
+ return ret;
},
- "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.colonial_points)),
- "set_country_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
+ "colonial_points", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(entry.colonial_points)),
+ "set_country_flag", ZERO_OR_MORE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
return entry.country_flags.emplace(flag).second;
}),
- "set_global_flag", ZERO_OR_ONE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
+ "set_global_flag", ZERO_OR_MORE, expect_identifier_or_string([&entry](std::string_view flag) -> bool {
return entry.global_flags.emplace(flag).second;
})
)(root);
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index af7d502..106b1c3 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -3,6 +3,7 @@
#include <map>
#include <optional>
+#include "openvic-simulation/misc/Decision.hpp"
#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
#include "openvic-simulation/history/HistoryMap.hpp"
@@ -54,9 +55,8 @@ namespace OpenVic {
std::optional<fixed_point_t> PROPERTY(colonial_points);
string_set_t PROPERTY(country_flags);
string_set_t PROPERTY(global_flags);
- std::map<GovernmentType const*, std::string> PROPERTY(government_flags);
-
- //TODO: decisions
+ std::map<GovernmentType const*, GovernmentType const*> PROPERTY(government_flag_overrides);
+ std::set<Decision const*> decisions;
CountryHistoryEntry(Country const& new_country, Date new_date);
};
diff --git a/src/openvic-simulation/history/HistoryMap.cpp b/src/openvic-simulation/history/HistoryMap.cpp
index b669208..7b5353f 100644
--- a/src/openvic-simulation/history/HistoryMap.cpp
+++ b/src/openvic-simulation/history/HistoryMap.cpp
@@ -6,10 +6,10 @@ using namespace OpenVic;
HistoryEntry::HistoryEntry(Date new_date) : date { new_date } {}
-Date OpenVic::_get_start_date(GameManager const& game_manager) {
+Date _HistoryMapHelperFuncs::_get_start_date(GameManager const& game_manager) {
return game_manager.get_define_manager().get_start_date();
}
-Date OpenVic::_get_end_date(GameManager const& game_manager) {
+Date _HistoryMapHelperFuncs::_get_end_date(GameManager const& game_manager) {
return game_manager.get_define_manager().get_end_date();
}
diff --git a/src/openvic-simulation/history/HistoryMap.hpp b/src/openvic-simulation/history/HistoryMap.hpp
index 07f54f0..576f00e 100644
--- a/src/openvic-simulation/history/HistoryMap.hpp
+++ b/src/openvic-simulation/history/HistoryMap.hpp
@@ -18,9 +18,11 @@ namespace OpenVic {
struct GameManager;
- /* Helper functions to avoid cyclic dependency issues */
- Date _get_start_date(GameManager const& game_manager);
- Date _get_end_date(GameManager const& game_manager);
+ namespace _HistoryMapHelperFuncs {
+ /* Helper functions to avoid cyclic dependency issues */
+ Date _get_start_date(GameManager const& game_manager);
+ Date _get_end_date(GameManager const& game_manager);
+ }
template<std::derived_from<HistoryEntry> _Entry, typename... Args>
struct HistoryMap {
@@ -30,22 +32,12 @@ namespace OpenVic {
std::map<Date, std::unique_ptr<entry_type>> PROPERTY(entries);
bool _try_load_history_entry(GameManager const& game_manager, Args... args, Date date, ast::NodeCPtr root) {
- const Date end_date = _get_end_date(game_manager);
- if (date > end_date) {
- Logger::error("History entry ", date, " defined after end date ", end_date);
+ entry_type *const entry = _get_or_make_entry(game_manager, date);
+ if (entry != nullptr) {
+ return _load_history_entry(game_manager, args..., *entry, root);
+ } else {
return false;
}
- typename decltype(entries)::iterator it = entries.find(date);
- if (it == entries.end()) {
- const std::pair<typename decltype(entries)::iterator, bool> result = entries.emplace(date, _make_entry(date));
- if (result.second) {
- it = result.first;
- } else {
- Logger::error("Failed to create history entry at date ", date);
- return false;
- }
- }
- return _load_history_entry(game_manager, args..., *it->second, root);
}
protected:
@@ -58,7 +50,7 @@ namespace OpenVic {
) = 0;
bool _load_history_file(GameManager const& game_manager, Args... args, ast::NodeCPtr root) {
- return _try_load_history_entry(game_manager, args..., _get_start_date(game_manager), root);
+ return _try_load_history_entry(game_manager, args..., _HistoryMapHelperFuncs::_get_start_date(game_manager), root);
}
bool _load_history_sub_entry_callback(
@@ -87,6 +79,26 @@ namespace OpenVic {
return default_callback(key, value);
}
+ /* Returns history entry at specific date, if date doesn't have an entry creates one, if that fails returns nullptr. */
+ entry_type* _get_or_make_entry(GameManager const& game_manager, Date date) {
+ const Date end_date = _HistoryMapHelperFuncs::_get_end_date(game_manager);
+ if (date > end_date) {
+ Logger::error("History entry ", date, " defined after end date ", end_date);
+ return nullptr;
+ }
+ typename decltype(entries)::iterator it = entries.find(date);
+ if (it == entries.end()) {
+ const std::pair<typename decltype(entries)::iterator, bool> result = entries.emplace(date, _make_entry(date));
+ if (result.second) {
+ it = result.first;
+ } else {
+ Logger::error("Failed to create history entry at date ", date);
+ return nullptr;
+ }
+ }
+ return it->second.get();
+ }
+
public:
/* Returns history entry at specific date, if date doesn't have an entry returns nullptr. */
entry_type const* get_entry(Date date) const {
diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp
index d9d3ef6..4e92300 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -135,6 +135,21 @@ ProvinceHistoryMap const* ProvinceHistoryManager::get_province_history(Province
}
}
+ProvinceHistoryMap* ProvinceHistoryManager::_get_or_make_province_history(Province const& province) {
+ decltype(province_histories)::iterator it = province_histories.find(&province);
+ if (it == province_histories.end()) {
+ const std::pair<decltype(province_histories)::iterator, bool> result =
+ province_histories.emplace(&province, ProvinceHistoryMap { province });
+ if (result.second) {
+ it = result.first;
+ } else {
+ Logger::error("Failed to create province history map for province ", province.get_identifier());
+ return nullptr;
+ }
+ }
+ return &it->second;
+}
+
bool ProvinceHistoryManager::load_province_history_file(
GameManager const& game_manager, Province const& province, ast::NodeCPtr root
) {
@@ -146,18 +161,52 @@ bool ProvinceHistoryManager::load_province_history_file(
return false;
}
- decltype(province_histories)::iterator it = province_histories.find(&province);
- if (it == province_histories.end()) {
- const std::pair<decltype(province_histories)::iterator, bool> result =
- province_histories.emplace(&province, ProvinceHistoryMap { province });
- if (result.second) {
- it = result.first;
- } else {
- Logger::error("Failed to create province history map for province ", province.get_identifier());
- return false;
+ ProvinceHistoryMap* province_history = _get_or_make_province_history(province);
+ if (province_history != nullptr) {
+ return province_history->_load_history_file(game_manager, root);
+ } else {
+ return false;
+ }
+}
+
+bool ProvinceHistoryEntry::_load_province_pop_history(
+ GameManager const& game_manager, ast::NodeCPtr root, bool *non_integer_size
+) {
+ PopManager const& pop_manager = game_manager.get_pop_manager();
+ RebelManager const& rebel_manager = game_manager.get_politics_manager().get_rebel_manager();
+ return pop_manager.expect_pop_type_dictionary(
+ [this, &pop_manager, &rebel_manager, non_integer_size](PopType const& pop_type, ast::NodeCPtr pop_node) -> bool {
+ return pop_manager.load_pop_into_vector(rebel_manager, pops, pop_type, pop_node, non_integer_size);
}
+ )(root);
+}
+
+bool ProvinceHistoryMap::_load_province_pop_history(
+ GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size
+) {
+ ProvinceHistoryEntry* entry = _get_or_make_entry(game_manager, date);
+ if (entry != nullptr) {
+ return entry->_load_province_pop_history(game_manager, root, non_integer_size);
+ } else {
+ return false;
}
- ProvinceHistoryMap& province_history = it->second;
+}
- return province_history._load_history_file(game_manager, root);
+bool ProvinceHistoryManager::load_pop_history_file(
+ GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size
+) {
+ if (locked) {
+ Logger::error("Attempted to load pop history file after province history registry was locked!");
+ return false;
+ }
+ return game_manager.get_map().expect_province_dictionary(
+ [this, &game_manager, date, non_integer_size](Province const& province, ast::NodeCPtr node) -> bool {
+ ProvinceHistoryMap* province_history = _get_or_make_province_history(province);
+ if (province_history != nullptr) {
+ return province_history->_load_province_pop_history(game_manager, date, node, non_integer_size);
+ } else {
+ return false;
+ }
+ }
+ )(root);
}
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index e4adc08..c3c8e67 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -33,8 +33,11 @@ namespace OpenVic {
std::map<BuildingType const*, BuildingType::level_t> PROPERTY(province_buildings);
std::map<BuildingType const*, BuildingType::level_t> PROPERTY(state_buildings);
fixed_point_map_t<Ideology const*> PROPERTY(party_loyalties);
+ std::vector<Pop> PROPERTY(pops);
ProvinceHistoryEntry(Province const& new_province, Date new_date);
+
+ bool _load_province_pop_history(GameManager const& game_manager, ast::NodeCPtr root, bool *non_integer_size);
};
struct ProvinceHistoryManager;
@@ -50,6 +53,11 @@ namespace OpenVic {
std::unique_ptr<ProvinceHistoryEntry> _make_entry(Date date) const override;
bool _load_history_entry(GameManager const& game_manager, ProvinceHistoryEntry& entry, ast::NodeCPtr root) override;
+
+ private:
+ bool _load_province_pop_history(
+ GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size
+ );
};
struct ProvinceHistoryManager {
@@ -57,6 +65,8 @@ namespace OpenVic {
std::map<Province const*, ProvinceHistoryMap> PROPERTY(province_histories);
bool locked = false;
+ ProvinceHistoryMap* _get_or_make_province_history(Province const& province);
+
public:
ProvinceHistoryManager() = default;
@@ -66,5 +76,6 @@ namespace OpenVic {
ProvinceHistoryMap const* get_province_history(Province const* province) const;
bool load_province_history_file(GameManager const& game_manager, Province const& province, ast::NodeCPtr root);
+ bool load_pop_history_file(GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size);
};
} // namespace OpenVic