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.cpp73
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp2
-rw-r--r--src/openvic-simulation/history/HistoryMap.cpp4
-rw-r--r--src/openvic-simulation/history/HistoryMap.hpp52
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp115
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp15
8 files changed, 174 insertions, 99 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 559957f..00c88b8 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -28,7 +28,7 @@ bool CountryHistoryMap::_load_history_entry(
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) {
@@ -67,7 +67,7 @@ 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
);
@@ -120,29 +120,70 @@ 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_MORE, decision_manager.expect_decision_identifier([&entry](Decision const& decision) -> bool {
- return entry.decisions.emplace(&decision).second;
- }),
+ "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;
- return expect_dictionary(
- [&entry, &government_type_manager, &government_type](std::string_view id, ast::NodeCPtr node) -> bool {
- bool ret = true;
+ 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") {
- government_type = government_type_manager.get_government_type_by_identifier(id);
- ret &= government_type != nullptr;
- } else if (id == "flag") {
- std::string_view flag;
- ret &= expect_identifier_or_string(assign_variable_callback(flag))(node);
- ret &= entry.government_flags.emplace(government_type, flag).second;
+ 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;
}
- return ret;
}
)(value);
+ 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)),
+ "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;
}),
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index 3f0965f..106b1c3 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -55,7 +55,7 @@ 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);
+ 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 4a79474..576f00e 100644
--- a/src/openvic-simulation/history/HistoryMap.hpp
+++ b/src/openvic-simulation/history/HistoryMap.hpp
@@ -18,37 +18,29 @@ 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 {
using entry_type = _Entry;
private:
+ 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:
- std::map<Date, std::unique_ptr<entry_type>> PROPERTY_ACCESS(entries, protected);
-
HistoryMap() = default;
virtual std::unique_ptr<entry_type> _make_entry(Date date) const = 0;
@@ -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 61638bc..4e92300 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -2,7 +2,6 @@
#include "openvic-simulation/GameManager.hpp"
#include "openvic-simulation/dataloader/NodeTools.hpp"
-#include <memory>
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -16,37 +15,6 @@ std::unique_ptr<ProvinceHistoryEntry> ProvinceHistoryMap::_make_entry(Date date)
return std::unique_ptr<ProvinceHistoryEntry> { new ProvinceHistoryEntry { province, date } };
}
-ProvinceHistoryEntry* ProvinceHistoryMap::_get_entry(Date date) {
- return entries.at(date).get();
-}
-
-bool ProvinceHistoryEntry::_load_province_pop_history(PopManager const& pop_manager, ast::NodeCPtr root) {
- return pop_manager.expect_pop_type_dictionary([this, &pop_manager](PopType const& type, ast::NodeCPtr pop_node) -> bool {
- CultureManager const& culture_manager = pop_manager.get_culture_manager();
- ReligionManager const& religion_manager = pop_manager.get_religion_manager();
- Culture const* culture = nullptr;
- Religion const* religion = nullptr;
- Pop::pop_size_t size = 0;
- bool ret = expect_dictionary_keys(
- "culture", ONE_EXACTLY, culture_manager.expect_culture_identifier(assign_variable_callback_pointer(culture)),
- "religion", ONE_EXACTLY, religion_manager.expect_religion_identifier(assign_variable_callback_pointer(religion)),
- "size", ONE_EXACTLY, expect_uint(assign_variable_callback(size)),
- "militancy", ZERO_OR_ONE, success_callback,
- "rebel_type", ZERO_OR_ONE, success_callback
- )(pop_node);
- if (culture != nullptr && religion != nullptr && size > 0) {
- pops.emplace_back(Pop { type, *culture, *religion, size });
- } else {
- Logger::warning(
- "Some pop arguments are invalid: province = ", province, ", type = ", type, ", culture = ", culture,
- ", religion = ", religion, ", size = ", size
- );
- }
- return ret;
- }
- )(root);
-}
-
bool ProvinceHistoryMap::_load_history_entry(
GameManager const& game_manager, ProvinceHistoryEntry& entry, ast::NodeCPtr root
) {
@@ -167,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
) {
@@ -178,30 +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;
}
- 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 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();
- return game_manager.get_map().expect_province_dictionary([this, &pop_manager, date](Province const& province, ast::NodeCPtr node) -> bool {
- if (province_histories.contains(&province)) {
- ProvinceHistoryEntry* entry = province_histories.at(&province)._get_entry(date);
- return entry != nullptr
- ? entry->_load_province_pop_history(pop_manager, node)
- : false;
- } else return false;
- })(root);
-} \ No newline at end of file
+ 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;
+ }
+}
+
+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 b69408e..c3c8e67 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -17,7 +17,6 @@ namespace OpenVic {
struct ProvinceHistoryEntry : HistoryEntry {
friend struct ProvinceHistoryMap;
- friend struct ProvinceHistoryManager;
private:
Province const& PROPERTY(province);
@@ -37,7 +36,8 @@ namespace OpenVic {
std::vector<Pop> PROPERTY(pops);
ProvinceHistoryEntry(Province const& new_province, Date new_date);
- bool _load_province_pop_history(PopManager const& pop_manager, ast::NodeCPtr root);
+
+ bool _load_province_pop_history(GameManager const& game_manager, ast::NodeCPtr root, bool *non_integer_size);
};
struct ProvinceHistoryManager;
@@ -48,13 +48,16 @@ namespace OpenVic {
private:
Province const& PROPERTY(province);
- ProvinceHistoryEntry* _get_entry(Date date);
-
protected:
ProvinceHistoryMap(Province const& new_province);
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 {
@@ -62,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;
@@ -71,6 +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 load_pop_history_file(GameManager const& game_manager, Date date, ast::NodeCPtr root, bool *non_integer_size);
};
} // namespace OpenVic