aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history
diff options
context:
space:
mode:
author Hop311 <Hop3114@gmail.com>2023-10-29 21:14:55 +0100
committer GitHub <noreply@github.com>2023-10-29 21:14:55 +0100
commit06cc0606156d009026930c785c62434276fbe782 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/history
parentd8ec90f07342876e9331819bd3cc372050f78248 (diff)
parent1b5e43fa7750cc4025d32f18390593cbce3ba842 (diff)
Merge pull request #67 from OpenVicProject/format
Formating
Diffstat (limited to 'src/openvic-simulation/history')
-rw-r--r--src/openvic-simulation/history/Bookmark.cpp66
-rw-r--r--src/openvic-simulation/history/Bookmark.hpp14
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp340
-rw-r--r--src/openvic-simulation/history/CountryHistory.hpp50
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.cpp533
-rw-r--r--src/openvic-simulation/history/ProvinceHistory.hpp139
6 files changed, 580 insertions, 562 deletions
diff --git a/src/openvic-simulation/history/Bookmark.cpp b/src/openvic-simulation/history/Bookmark.cpp
index 1786821..edfa064 100644
--- a/src/openvic-simulation/history/Bookmark.cpp
+++ b/src/openvic-simulation/history/Bookmark.cpp
@@ -12,20 +12,10 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;
Bookmark::Bookmark(
- size_t new_index,
- std::string_view new_name,
- std::string_view new_description,
- Date new_date,
- uint32_t new_initial_camera_x,
+ size_t new_index, std::string_view new_name, std::string_view new_description, Date new_date, uint32_t new_initial_camera_x,
uint32_t new_initial_camera_y
-)
- : HasIdentifier { std::to_string(new_index) },
- name { new_name },
- description { new_description },
- date { new_date },
- initial_camera_x { new_initial_camera_x },
- initial_camera_y { new_initial_camera_y } {
-}
+) : HasIdentifier { std::to_string(new_index) }, name { new_name }, description { new_description }, date { new_date },
+ initial_camera_x { new_initial_camera_x }, initial_camera_y { new_initial_camera_y } {}
std::string_view Bookmark::get_name() const {
return name;
@@ -50,40 +40,34 @@ uint32_t Bookmark::get_initial_camera_y() const {
BookmarkManager::BookmarkManager() : bookmarks { "bookmarks" } {}
bool BookmarkManager::add_bookmark(
- std::string_view name,
- std::string_view description,
- Date date,
- uint32_t initial_camera_x,
- uint32_t initial_camera_y
+ std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, uint32_t initial_camera_y
) {
return bookmarks.add_item({ bookmarks.size(), name, description, date, initial_camera_x, initial_camera_y });
}
bool BookmarkManager::load_bookmark_file(ast::NodeCPtr root) {
- bool ret = expect_dictionary(
- [this](std::string_view key, ast::NodeCPtr value) -> bool {
- if (key != "bookmark") {
- Logger::error("Invalid bookmark declaration ", key);
- return false;
- }
-
- std::string_view name, description;
- Date date;
- uint32_t initial_camera_x, initial_camera_y;
-
- bool ret = expect_dictionary_keys(
- "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
- "desc", ONE_EXACTLY, expect_string(assign_variable_callback(description)),
- "date", ONE_EXACTLY, expect_date(assign_variable_callback(date)),
- "cameraX", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_x)),
- "cameraY", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_y))
- )(value);
-
- ret &= add_bookmark(name, description, date, initial_camera_x, initial_camera_y);
- return ret;
+ const bool ret = expect_dictionary([this](std::string_view key, ast::NodeCPtr value) -> bool {
+ if (key != "bookmark") {
+ Logger::error("Invalid bookmark declaration ", key);
+ return false;
}
- )(root);
+
+ std::string_view name, description;
+ Date date;
+ uint32_t initial_camera_x, initial_camera_y;
+
+ bool ret = expect_dictionary_keys(
+ "name", ONE_EXACTLY, expect_string(assign_variable_callback(name)),
+ "desc", ONE_EXACTLY, expect_string(assign_variable_callback(description)),
+ "date", ONE_EXACTLY, expect_date(assign_variable_callback(date)),
+ "cameraX", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_x)),
+ "cameraY", ONE_EXACTLY, expect_uint(assign_variable_callback(initial_camera_y))
+ )(value);
+
+ ret &= add_bookmark(name, description, date, initial_camera_x, initial_camera_y);
+ return ret;
+ })(root);
lock_bookmarks();
return ret;
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/Bookmark.hpp b/src/openvic-simulation/history/Bookmark.hpp
index 63e1b3b..8f0075f 100644
--- a/src/openvic-simulation/history/Bookmark.hpp
+++ b/src/openvic-simulation/history/Bookmark.hpp
@@ -20,12 +20,8 @@ namespace OpenVic {
const uint32_t initial_camera_y;
Bookmark(
- size_t new_index,
- std::string_view new_name,
- std::string_view new_description,
- Date new_date,
- uint32_t new_initial_camera_x,
- uint32_t new_initial_camera_y
+ size_t new_index, std::string_view new_name, std::string_view new_description, Date new_date,
+ uint32_t new_initial_camera_x, uint32_t new_initial_camera_y
);
public:
@@ -45,9 +41,11 @@ namespace OpenVic {
public:
BookmarkManager();
- bool add_bookmark(std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, uint32_t initial_camera_y);
+ bool add_bookmark(
+ std::string_view name, std::string_view description, Date date, uint32_t initial_camera_x, uint32_t initial_camera_y
+ );
IDENTIFIER_REGISTRY_ACCESSORS(bookmark);
bool load_bookmark_file(ast::NodeCPtr root);
};
-} \ No newline at end of file
+}
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 5e91a85..2dfc171 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -6,21 +6,16 @@ using namespace OpenVic;
using namespace OpenVic::NodeTools;
CountryHistory::CountryHistory(
- Culture const* new_primary_culture,
- std::vector<Culture const*>&& new_accepted_cultures,
- Religion const* new_religion,
- CountryParty const* new_ruling_party,
- Date new_last_election,
- std::map<Ideology const*, fixed_point_t>&& new_upper_house,
- Province const* new_capital,
- GovernmentType const* new_government_type,
- fixed_point_t new_plurality,
- NationalValue const* new_national_value,
- bool new_civilised,
- fixed_point_t new_prestige,
- std::vector<Reform const*>&& new_reforms,
- Deployment const* new_inital_oob
-) : primary_culture { new_primary_culture }, accepted_cultures { std::move(new_accepted_cultures) }, religion { new_religion }, ruling_party { new_ruling_party }, last_election { new_last_election }, upper_house { std::move(new_upper_house) }, capital { new_capital }, government_type { new_government_type }, plurality { new_plurality }, national_value { new_national_value }, civilised { new_civilised }, prestige { new_prestige }, reforms { std::move(new_reforms) }, inital_oob { new_inital_oob } {}
+ Culture const* new_primary_culture, std::vector<Culture const*>&& new_accepted_cultures, Religion const* new_religion,
+ CountryParty const* new_ruling_party, Date new_last_election, std::map<Ideology const*, fixed_point_t>&& new_upper_house,
+ Province const* new_capital, GovernmentType const* new_government_type, fixed_point_t new_plurality,
+ NationalValue const* new_national_value, bool new_civilised, fixed_point_t new_prestige,
+ std::vector<Reform const*>&& new_reforms, Deployment const* new_inital_oob
+) : primary_culture { new_primary_culture }, accepted_cultures { std::move(new_accepted_cultures) },
+ religion { new_religion }, ruling_party { new_ruling_party }, last_election { new_last_election },
+ upper_house { std::move(new_upper_house) }, capital { new_capital }, government_type { new_government_type },
+ plurality { new_plurality }, national_value { new_national_value }, civilised { new_civilised },
+ prestige { new_prestige }, reforms { std::move(new_reforms) }, inital_oob { new_inital_oob } {}
Culture const* CountryHistory::get_primary_culture() const {
return primary_culture;
@@ -79,25 +74,12 @@ Deployment const* CountryHistory::get_inital_oob() const {
}
bool CountryHistoryManager::add_country_history_entry(
- Country const* country,
- Date date,
- Culture const* primary_culture,
- std::vector<Culture const*>&& accepted_cultures,
- Religion const* religion,
- CountryParty const* ruling_party,
- Date last_election,
- std::map<Ideology const*, fixed_point_t>&& upper_house,
- Province const* capital,
- GovernmentType const* government_type,
- fixed_point_t plurality,
- NationalValue const* national_value,
- bool civilised,
- fixed_point_t prestige,
- std::vector<Reform const*>&& reforms,
- Deployment const* initial_oob,
- bool updated_accepted_cultures,
- bool updated_upper_house,
- bool updated_reforms
+ Country const* country, Date date, Culture const* primary_culture, std::vector<Culture const*>&& accepted_cultures,
+ Religion const* religion, CountryParty const* ruling_party, Date last_election,
+ std::map<Ideology const*, fixed_point_t>&& upper_house, Province const* capital, GovernmentType const* government_type,
+ fixed_point_t plurality, NationalValue const* national_value, bool civilised, fixed_point_t prestige,
+ std::vector<Reform const*>&& reforms, Deployment const* initial_oob, bool updated_accepted_cultures,
+ bool updated_upper_house, bool updated_reforms
) {
if (locked) {
Logger::error("Cannot add new history entry to country history registry: locked!");
@@ -107,39 +89,58 @@ bool CountryHistoryManager::add_country_history_entry(
/* combine duplicate histories, priority to current (defined later) */
auto& country_registry = country_histories[country];
const auto existing_entry = country_registry.find(date);
-
+
if (existing_entry != country_registry.end()) {
- if (primary_culture != nullptr) existing_entry->second.primary_culture = primary_culture;
- if (updated_accepted_cultures) existing_entry->second.accepted_cultures = std::move(accepted_cultures);
- if (religion != nullptr) existing_entry->second.religion = religion;
- if (ruling_party != nullptr) existing_entry->second.ruling_party = ruling_party;
- if (last_election != Date(0)) existing_entry->second.last_election = last_election;
- if (updated_upper_house) existing_entry->second.upper_house = std::move(upper_house);
- if (capital != nullptr) existing_entry->second.capital = capital;
- if (government_type != nullptr) existing_entry->second.government_type = government_type;
- if (plurality >= 0) existing_entry->second.plurality = plurality;
- if (national_value != nullptr) existing_entry->second.national_value = national_value;
- if (civilised) existing_entry->second.civilised = true;
- if (prestige >= 0) existing_entry->second.prestige = prestige;
- if (updated_reforms) existing_entry->second.reforms = std::move(reforms);
- if (initial_oob != nullptr) existing_entry->second.inital_oob = initial_oob;
+ if (primary_culture != nullptr) {
+ existing_entry->second.primary_culture = primary_culture;
+ }
+ if (updated_accepted_cultures) {
+ existing_entry->second.accepted_cultures = std::move(accepted_cultures);
+ }
+ if (religion != nullptr) {
+ existing_entry->second.religion = religion;
+ }
+ if (ruling_party != nullptr) {
+ existing_entry->second.ruling_party = ruling_party;
+ }
+ if (last_election != Date(0)) {
+ existing_entry->second.last_election = last_election;
+ }
+ if (updated_upper_house) {
+ existing_entry->second.upper_house = std::move(upper_house);
+ }
+ if (capital != nullptr) {
+ existing_entry->second.capital = capital;
+ }
+ if (government_type != nullptr) {
+ existing_entry->second.government_type = government_type;
+ }
+ if (plurality >= 0) {
+ existing_entry->second.plurality = plurality;
+ }
+ if (national_value != nullptr) {
+ existing_entry->second.national_value = national_value;
+ }
+ if (civilised) {
+ existing_entry->second.civilised = true;
+ }
+ if (prestige >= 0) {
+ existing_entry->second.prestige = prestige;
+ }
+ if (updated_reforms) {
+ existing_entry->second.reforms = std::move(reforms);
+ }
+ if (initial_oob != nullptr) {
+ existing_entry->second.inital_oob = initial_oob;
+ }
} else {
- country_registry.emplace(date, CountryHistory {
- primary_culture,
- std::move(accepted_cultures),
- religion,
- ruling_party,
- last_election,
- std::move(upper_house),
- capital,
- government_type,
- plurality,
- national_value,
- civilised,
- prestige,
- std::move(reforms),
- initial_oob
- });
+ country_registry.emplace( date,
+ CountryHistory {
+ primary_culture, std::move(accepted_cultures), religion, ruling_party, last_election,
+ std::move(upper_house), capital, government_type, plurality, national_value, civilised,
+ prestige, std::move(reforms), initial_oob
+ }
+ );
}
return true;
}
@@ -147,7 +148,9 @@ bool CountryHistoryManager::add_country_history_entry(
void CountryHistoryManager::lock_country_histories() {
for (const auto& entry : country_histories) {
if (entry.second.size() == 0) {
- Logger::error("Attempted to lock country histories - country ", entry.first->get_identifier(), " has no history entries!");
+ Logger::error(
+ "Attempted to lock country histories - country ", entry.first->get_identifier(), " has no history entries!"
+ );
}
}
Logger::info("Locked country history registry after registering ", country_histories.size(), " items");
@@ -166,11 +169,17 @@ CountryHistory const* CountryHistoryManager::get_country_history(Country const*
Logger::error("Attempted to access history of undefined country ", country->get_identifier());
return nullptr;
}
-
+
for (const auto& current : country_registry->second) {
- if (current.first == entry) return &current.second;
- if (current.first > entry) continue;
- if (current.first > closest_entry && current.first < entry) closest_entry = current.first;
+ if (current.first == entry) {
+ return &current.second;
+ }
+ if (current.first > entry) {
+ continue;
+ }
+ if (current.first > closest_entry && current.first < entry) {
+ closest_entry = current.first;
+ }
}
auto entry_registry = country_registry->second.find(closest_entry);
@@ -185,7 +194,9 @@ inline CountryHistory const* CountryHistoryManager::get_country_history(Country
return get_country_history(country, entry->get_date());
}
-inline bool CountryHistoryManager::_load_country_history_entry(GameManager& game_manager, std::string_view name, Date const& date, ast::NodeCPtr root) {
+inline bool CountryHistoryManager::_load_country_history_entry(
+ GameManager& game_manager, std::string_view name, Date const& date, ast::NodeCPtr root
+) {
Province const* capital = nullptr;
Culture const* primary_culture = nullptr;
Religion const* religion = nullptr;
@@ -209,7 +220,8 @@ inline bool CountryHistoryManager::_load_country_history_entry(GameManager& game
Reform const* reform;
- bool ret = game_manager.get_politics_manager().get_issue_manager().expect_reform_identifier(assign_variable_callback_pointer(reform))(value);
+ bool ret = game_manager.get_politics_manager().get_issue_manager()
+ .expect_reform_identifier(assign_variable_callback_pointer(reform))(value);
if (std::find(reforms.begin(), reforms.end(), reform) != reforms.end()) {
Logger::error("Redefinition of reform ", reform->get_identifier(), " in history of ", name);
return false;
@@ -221,96 +233,142 @@ inline bool CountryHistoryManager::_load_country_history_entry(GameManager& game
// TODO: technologies & inventions
return true;
},
- /* we have to use a lambda, assign_variable_callback_pointer apparently doesn't play nice with const & non-const accessors */
- "capital", ZERO_OR_ONE, game_manager.get_map().expect_province_identifier([&capital](Province const& province) -> bool {
- capital = &province;
- return true;
- }),
- "primary_culture", ZERO_OR_ONE, game_manager.get_pop_manager().get_culture_manager().expect_culture_identifier(assign_variable_callback_pointer(primary_culture)),
- "culture", ZERO_OR_MORE, game_manager.get_pop_manager().get_culture_manager().expect_culture_identifier([&game_manager, &accepted_cultures, &updated_accepted_cultures](Culture const& culture) -> bool {
- updated_accepted_cultures = true;
- accepted_cultures.push_back(&culture);
- return true;
- }),
- "religion", ZERO_OR_ONE, game_manager.get_pop_manager().get_religion_manager().expect_religion_identifier(assign_variable_callback_pointer(religion)),
- "government", ZERO_OR_ONE, game_manager.get_politics_manager().get_government_type_manager().expect_government_type_identifier(assign_variable_callback_pointer(government_type)),
+ /* we have to use a lambda, assign_variable_callback_pointer
+ * apparently doesn't play nice with const & non-const accessors */
+ "capital", ZERO_OR_ONE,
+ game_manager.get_map().expect_province_identifier([&capital](Province const& province) -> bool {
+ capital = &province;
+ return true;
+ }),
+ "primary_culture", ZERO_OR_ONE,
+ game_manager.get_pop_manager().get_culture_manager().expect_culture_identifier(
+ assign_variable_callback_pointer(primary_culture)
+ ),
+ "culture", ZERO_OR_MORE,
+ game_manager.get_pop_manager().get_culture_manager().expect_culture_identifier(
+ [&game_manager, &accepted_cultures, &updated_accepted_cultures](Culture const& culture) -> bool {
+ updated_accepted_cultures = true;
+ accepted_cultures.push_back(&culture);
+ return true;
+ }
+ ),
+ "religion", ZERO_OR_ONE,
+ game_manager.get_pop_manager().get_religion_manager().expect_religion_identifier(
+ assign_variable_callback_pointer(religion)
+ ),
+ "government", ZERO_OR_ONE,
+ game_manager.get_politics_manager().get_government_type_manager().expect_government_type_identifier(
+ assign_variable_callback_pointer(government_type)
+ ),
"plurality", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(plurality)),
- "nationalvalue", ZERO_OR_ONE, game_manager.get_politics_manager().get_national_value_manager().expect_national_value_identifier(assign_variable_callback_pointer(national_value)),
+ "nationalvalue", ZERO_OR_ONE,
+ game_manager.get_politics_manager().get_national_value_manager().expect_national_value_identifier(
+ assign_variable_callback_pointer(national_value)
+ ),
"civilized", ZERO_OR_ONE, expect_bool(assign_variable_callback(civilised)),
"prestige", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(prestige)),
- "ruling_party", ZERO_OR_ONE, expect_identifier([this, &game_manager, &ruling_party, &name, &date](std::string_view identifier) -> bool {
- const std::vector<CountryParty>* parties = &game_manager.get_country_manager().get_country_by_identifier(name)->get_parties();
- for (auto& party : *parties) {
- if (party.get_name() == identifier) {
- if (party.get_start_date() <= date && date <= party.get_end_date()) {
- ruling_party = &party;
- return true;
- } else {
- if (party.get_start_date() > date) Logger::warning("Ruling party ", identifier, " of country ", name, " has invalid start date ", party.get_start_date(), " for bookmark: ", date.to_string());
- if (party.get_end_date() < date) Logger::warning("Ruling party ", identifier, " of country ", name, " has invalid end date ", party.get_end_date(), " for bookmark: ", date.to_string());
- ruling_party = &party;
- return true;
+ "ruling_party", ZERO_OR_ONE,
+ expect_identifier([this, &game_manager, &ruling_party, &name, &date](std::string_view identifier) -> bool {
+ const std::vector<CountryParty>* parties =
+ &game_manager.get_country_manager().get_country_by_identifier(name)->get_parties();
+ for (auto& party : *parties) {
+ if (party.get_name() == identifier) {
+ if (party.get_start_date() <= date && date <= party.get_end_date()) {
+ ruling_party = &party;
+ return true;
+ } else {
+ if (party.get_start_date() > date) {
+ Logger::warning(
+ "Ruling party ", identifier, " of country ", name, " has invalid start date ",
+ party.get_start_date(), " for bookmark: ", date.to_string()
+ );
+ }
+ if (party.get_end_date() < date) {
+ Logger::warning(
+ "Ruling party ", identifier, " of country ", name, " has invalid end date ",
+ party.get_end_date(), " for bookmark: ", date.to_string()
+ );
+ }
+ ruling_party = &party;
+ return true;
+ }
}
}
- }
- Logger::error("Ruling party ", identifier, " of country ", name, " is not defined!");
- return false;
- }),
+ Logger::error("Ruling party ", identifier, " of country ", name, " is not defined!");
+ return false;
+ }),
"last_election", ZERO_OR_ONE, expect_date(assign_variable_callback(last_election)),
- "upper_house", ZERO_OR_ONE, game_manager.get_politics_manager().get_ideology_manager().expect_ideology_dictionary([&upper_house, &updated_upper_house](Ideology const& ideology, ast::NodeCPtr value) -> bool {
- fixed_point_t popularity;
-
- updated_upper_house = true;
- bool ret = expect_fixed_point(assign_variable_callback(popularity))(value);
- upper_house.emplace(&ideology, popularity);
- return ret;
- }),
- "oob", ZERO_OR_ONE, [&game_manager, &initial_oob](ast::NodeCPtr node) -> bool {
- std::string_view string;
- expect_string(assign_variable_callback(string))(node);
-
- if (string.starts_with('/')) {
- if (game_manager.get_military_manager().get_deployment_manager().has_deployment_identifier(string.substr(1))) {
- initial_oob = game_manager.get_military_manager().get_deployment_manager().get_deployment_by_identifier(string.substr(1));
- return true;
+ "upper_house", ZERO_OR_ONE,
+ game_manager.get_politics_manager().get_ideology_manager().expect_ideology_dictionary(
+ [&upper_house, &updated_upper_house](Ideology const& ideology, ast::NodeCPtr value) -> bool {
+ fixed_point_t popularity;
+
+ updated_upper_house = true;
+ bool ret = expect_fixed_point(assign_variable_callback(popularity))(value);
+ upper_house.emplace(&ideology, popularity);
+ return ret;
}
- } else {
- if (game_manager.get_military_manager().get_deployment_manager().has_deployment_identifier(string)) {
- initial_oob = game_manager.get_military_manager().get_deployment_manager().get_deployment_by_identifier(string);
+ ),
+ "oob", ZERO_OR_ONE,
+ [&game_manager, &initial_oob](ast::NodeCPtr node) -> bool {
+ std::string_view string;
+ expect_string(assign_variable_callback(string))(node);
+
+ if (string.starts_with('/')) {
+ if (game_manager.get_military_manager().get_deployment_manager()
+ .has_deployment_identifier(string.substr(1))) {
+ initial_oob = game_manager.get_military_manager().get_deployment_manager()
+ .get_deployment_by_identifier(string.substr(1));
+ return true;
+ }
+ } else {
+ if (game_manager.get_military_manager().get_deployment_manager().has_deployment_identifier(string)) {
+ initial_oob =
+ game_manager.get_military_manager().get_deployment_manager().get_deployment_by_identifier(string);
+ }
}
- }
- initial_oob = game_manager.get_military_manager().get_deployment_manager().get_deployment_by_identifier("NULL");
- return true;
- },
- "schools", ZERO_OR_ONE, success_callback, // TODO: technology school
+ initial_oob =
+ game_manager.get_military_manager().get_deployment_manager().get_deployment_by_identifier("NULL");
+ return true;
+ },
+ "schools", ZERO_OR_ONE, success_callback, // TODO: technology school
"foreign_investment", ZERO_OR_ONE, success_callback // TODO: foreign investment
)(root);
- ret &= add_country_history_entry(game_manager.get_country_manager().get_country_by_identifier(name), date, primary_culture, std::move(accepted_cultures), religion, ruling_party, last_election, std::move(upper_house), capital, government_type, plurality, national_value, civilised, prestige, std::move(reforms), initial_oob, updated_accepted_cultures, updated_upper_house, updated_reforms);
+ ret &= add_country_history_entry(
+ game_manager.get_country_manager().get_country_by_identifier(name), date, primary_culture, std::move(accepted_cultures),
+ religion, ruling_party, last_election, std::move(upper_house), capital, government_type, plurality, national_value,
+ civilised, prestige, std::move(reforms), initial_oob, updated_accepted_cultures, updated_upper_house, updated_reforms
+ );
return ret;
}
bool CountryHistoryManager::load_country_history_file(GameManager& game_manager, std::string_view name, ast::NodeCPtr root) {
- if (game_manager.get_country_manager().get_country_by_identifier(name)->is_dynamic_tag()) return true; /* as far as I can tell dynamic countries are hardcoded, broken, and unused */
+ if (game_manager.get_country_manager().get_country_by_identifier(name)->is_dynamic_tag()) {
+ return true; /* as far as I can tell dynamic countries are hardcoded, broken, and unused */
+ }
bool ret = _load_country_history_entry(game_manager, name, game_manager.get_define_manager().get_start_date(), root);
- ret &= expect_dictionary(
- [this, &game_manager, &name](std::string_view key, ast::NodeCPtr value) -> bool {
- bool is_date = false;
- Date entry = Date().from_string(key, &is_date, true);
- if (!is_date) return true;
+ ret &= expect_dictionary([this, &game_manager, &name](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool is_date = false;
+ Date entry = Date().from_string(key, &is_date, true);
+ if (!is_date) {
+ return true;
+ }
- Date const& end_date = game_manager.get_define_manager().get_end_date();
- if (entry > end_date) {
- Logger::error("History entry ", entry.to_string(), " of country ", name, " defined after defined end date ", end_date.to_string());
- return false;
- }
-
- return _load_country_history_entry(game_manager, name, entry, value);
+ Date const& end_date = game_manager.get_define_manager().get_end_date();
+ if (entry > end_date) {
+ Logger::error(
+ "History entry ", entry.to_string(), " of country ", name, " defined after defined end date ",
+ end_date.to_string()
+ );
+ return false;
}
- )(root);
+
+ return _load_country_history_entry(game_manager, name, entry, value);
+ })(root);
return ret;
}
diff --git a/src/openvic-simulation/history/CountryHistory.hpp b/src/openvic-simulation/history/CountryHistory.hpp
index 56d04c6..52d99df 100644
--- a/src/openvic-simulation/history/CountryHistory.hpp
+++ b/src/openvic-simulation/history/CountryHistory.hpp
@@ -41,19 +41,11 @@ namespace OpenVic {
// TODO: starting foreign investment
CountryHistory(
- Culture const* new_primary_culture,
- std::vector<Culture const*>&& new_accepted_cultures,
- Religion const* new_religion,
- CountryParty const* new_ruling_party,
- Date new_last_election,
- std::map<Ideology const*, fixed_point_t>&& new_upper_house,
- Province const* new_capital,
- GovernmentType const* new_government_type,
- fixed_point_t new_plurality,
- NationalValue const* new_national_value,
- bool new_civilised,
- fixed_point_t new_prestige,
- std::vector<Reform const*>&& new_reforms,
+ Culture const* new_primary_culture, std::vector<Culture const*>&& new_accepted_cultures,
+ Religion const* new_religion, CountryParty const* new_ruling_party, Date new_last_election,
+ std::map<Ideology const*, fixed_point_t>&& new_upper_house, Province const* new_capital,
+ GovernmentType const* new_government_type, fixed_point_t new_plurality, NationalValue const* new_national_value,
+ bool new_civilised, fixed_point_t new_prestige, std::vector<Reform const*>&& new_reforms,
Deployment const* new_inital_oob
);
@@ -79,37 +71,27 @@ namespace OpenVic {
std::map<Country const*, std::map<Date, CountryHistory>> country_histories;
bool locked = false;
- inline bool _load_country_history_entry(GameManager& game_manager, std::string_view name, Date const& date, ast::NodeCPtr root);
+ inline bool _load_country_history_entry(
+ GameManager& game_manager, std::string_view name, Date const& date, ast::NodeCPtr root
+ );
public:
CountryHistoryManager() {}
bool add_country_history_entry(
- Country const* country,
- Date date,
- Culture const* primary_culture,
- std::vector<Culture const*>&& accepted_cultures,
- Religion const* religion,
- CountryParty const* ruling_party,
- Date last_election,
- std::map<Ideology const*, fixed_point_t>&& upper_house,
- Province const* capital,
- GovernmentType const* government_type,
- fixed_point_t plurality,
- NationalValue const* national_value,
- bool civilised,
- fixed_point_t prestige,
- std::vector<Reform const*>&& reforms,
- Deployment const* initial_oob,
- bool updated_accepted_cultures,
- bool updated_upper_house,
- bool updated_reforms
+ Country const* country, Date date, Culture const* primary_culture, std::vector<Culture const*>&& accepted_cultures,
+ Religion const* religion, CountryParty const* ruling_party, Date last_election,
+ std::map<Ideology const*, fixed_point_t>&& upper_house, Province const* capital,
+ GovernmentType const* government_type, fixed_point_t plurality, NationalValue const* national_value, bool civilised,
+ fixed_point_t prestige, std::vector<Reform const*>&& reforms, Deployment const* initial_oob,
+ bool updated_accepted_cultures, bool updated_upper_house, bool updated_reforms
);
void lock_country_histories();
bool is_locked() const;
- /* Returns history of country at date, if date doesn't have an entry returns closest entry before date. Return can be nullptr if an error occurs. */
+ /* Returns history of country at date, if date doesn't have an entry returns
+ * closest entry before date. Return can be nullptr if an error occurs. */
CountryHistory const* get_country_history(Country const* country, Date entry) const;
/* Returns history of country at bookmark date. Return can be nullptr if an error occurs. */
inline CountryHistory const* get_country_history(Country const* country, Bookmark const* entry) const;
diff --git a/src/openvic-simulation/history/ProvinceHistory.cpp b/src/openvic-simulation/history/ProvinceHistory.cpp
index cc6c5b8..4057bfa 100644
--- a/src/openvic-simulation/history/ProvinceHistory.cpp
+++ b/src/openvic-simulation/history/ProvinceHistory.cpp
@@ -1,323 +1,330 @@
#include "ProvinceHistory.hpp"
-#include "openvic-simulation/dataloader/NodeTools.hpp"
#include "openvic-simulation/GameManager.hpp"
+#include "openvic-simulation/dataloader/NodeTools.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
ProvinceHistory::ProvinceHistory(
- Country const* new_owner,
- Country const* new_controller,
- uint8_t new_colonial,
- bool new_slave,
- std::vector<Country const*>&& new_cores,
- Good const* new_rgo,
- uint8_t new_life_rating,
- TerrainType const* new_terrain_type,
- std::map<Building const*, uint8_t>&& new_buildings,
- std::map<Ideology const*, uint8_t>&& new_party_loyalties
-) : owner { new_owner },
- controller { new_controller },
- colonial { new_colonial },
- slave { new_slave },
- cores { std::move(new_cores) },
- rgo { new_rgo },
- life_rating { new_life_rating },
- terrain_type { new_terrain_type },
- buildings { std::move(new_buildings) },
- party_loyalties { std::move(new_party_loyalties) } {}
+ Country const* new_owner, Country const* new_controller, uint8_t new_colonial, bool new_slave,
+ std::vector<Country const*>&& new_cores, Good const* new_rgo, uint8_t new_life_rating, TerrainType const* new_terrain_type,
+ std::map<Building const*, uint8_t>&& new_buildings, std::map<Ideology const*, uint8_t>&& new_party_loyalties
+) : owner { new_owner }, controller { new_controller }, colonial { new_colonial }, slave { new_slave },
+ cores { std::move(new_cores) }, rgo { new_rgo }, life_rating { new_life_rating }, terrain_type { new_terrain_type },
+ buildings { std::move(new_buildings) }, party_loyalties { std::move(new_party_loyalties) } {}
Country const* ProvinceHistory::get_owner() const {
- return owner;
+ return owner;
}
Country const* ProvinceHistory::get_controller() const {
- return controller;
+ return controller;
}
uint8_t ProvinceHistory::get_colony_status() const {
- return colonial;
+ return colonial;
}
bool ProvinceHistory::is_slave() const {
- return slave;
+ return slave;
}
-const std::vector<Country const*>& ProvinceHistory::get_cores() const {
- return cores;
+std::vector<Country const*> const& ProvinceHistory::get_cores() const {
+ return cores;
}
bool ProvinceHistory::is_core_of(Country const* country) const {
- return std::find(cores.begin(), cores.end(), country) != cores.end();
+ return std::find(cores.begin(), cores.end(), country) != cores.end();
}
Good const* ProvinceHistory::get_rgo() const {
- return rgo;
+ return rgo;
}
uint8_t ProvinceHistory::get_life_rating() const {
- return life_rating;
+ return life_rating;
}
TerrainType const* ProvinceHistory::get_terrain_type() const {
- return terrain_type;
+ return terrain_type;
}
-const std::map<Building const*, uint8_t>& ProvinceHistory::get_buildings() const {
- return buildings;
+std::map<Building const*, uint8_t> const& ProvinceHistory::get_buildings() const {
+ return buildings;
}
-const std::map<Ideology const*, uint8_t>& ProvinceHistory::get_party_loyalties() const {
- return party_loyalties;
+std::map<Ideology const*, uint8_t> const& ProvinceHistory::get_party_loyalties() const {
+ return party_loyalties;
}
bool ProvinceHistoryManager::add_province_history_entry(
- Province const* province,
- Date date,
- Country const* owner,
- Country const* controller,
- uint8_t colonial,
- bool slave,
- std::vector<Country const*>&& cores,
- std::vector<Country const*>&& remove_cores,
- Good const* rgo,
- uint8_t life_rating,
- TerrainType const* terrain_type,
- std::map<Building const*, uint8_t>&& buildings,
- std::map<Ideology const*, uint8_t>&& party_loyalties,
- std::bitset<5> updates
+ Province const* province, Date date, Country const* owner, Country const* controller, uint8_t colonial, bool slave,
+ std::vector<Country const*>&& cores, std::vector<Country const*>&& remove_cores, Good const* rgo, uint8_t life_rating,
+ TerrainType const* terrain_type, std::map<Building const*, uint8_t>&& buildings,
+ std::map<Ideology const*, uint8_t>&& party_loyalties, std::bitset<5> updates
) {
- if (locked) {
- Logger::error("Cannot add new history entry to province history registry: locked!");
- return false;
- }
-
- /* combine duplicate histories, priority to current (defined later) */
- auto& province_registry = province_histories[province];
- const auto existing_entry = province_registry.find(date);
-
- if (existing_entry != province_registry.end()) {
- if (owner != nullptr) existing_entry->second.owner = owner;
- if (controller != nullptr) existing_entry->second.controller = controller;
- if (rgo != nullptr) existing_entry->second.rgo = rgo;
- if (terrain_type != nullptr) existing_entry->second.terrain_type = terrain_type;
- if (updates[0]) existing_entry->second.colonial = colonial;
- if (updates[1]) existing_entry->second.slave = slave;
- if (updates[2]) existing_entry->second.life_rating = life_rating;
- if (updates[3]) existing_entry->second.buildings = std::move(buildings);
- if (updates[4]) existing_entry->second.party_loyalties = std::move(party_loyalties);
- // province history cores are additive
- existing_entry->second.cores.insert(existing_entry->second.cores.end(), cores.begin(), cores.end());
- for (const auto which : remove_cores) {
- const auto core = std::find(cores.begin(), cores.end(), which);
- if (core == cores.end()) {
- Logger::error("In history of province ", province->get_identifier(), " tried to remove nonexistant core of country: ", which->get_identifier(), " at date ", date.to_string());
- return false;
- }
- existing_entry->second.cores.erase(core);
- }
- } else {
- province_registry.emplace(date, ProvinceHistory {
- owner,
- controller,
- colonial,
- slave,
- std::move(cores),
- rgo,
- life_rating,
- terrain_type,
- std::move(buildings),
- std::move(party_loyalties)
- });
- }
- return true;
+ if (locked) {
+ Logger::error("Cannot add new history entry to province history registry: locked!");
+ return false;
+ }
+
+ /* combine duplicate histories, priority to current (defined later) */
+ auto& province_registry = province_histories[province];
+ const auto existing_entry = province_registry.find(date);
+
+ if (existing_entry != province_registry.end()) {
+ if (owner != nullptr) {
+ existing_entry->second.owner = owner;
+ }
+ if (controller != nullptr) {
+ existing_entry->second.controller = controller;
+ }
+ if (rgo != nullptr) {
+ existing_entry->second.rgo = rgo;
+ }
+ if (terrain_type != nullptr) {
+ existing_entry->second.terrain_type = terrain_type;
+ }
+ if (updates[0]) {
+ existing_entry->second.colonial = colonial;
+ }
+ if (updates[1]) {
+ existing_entry->second.slave = slave;
+ }
+ if (updates[2]) {
+ existing_entry->second.life_rating = life_rating;
+ }
+ if (updates[3]) {
+ existing_entry->second.buildings = std::move(buildings);
+ }
+ if (updates[4]) {
+ existing_entry->second.party_loyalties = std::move(party_loyalties);
+ }
+ // province history cores are additive
+ existing_entry->second.cores.insert(existing_entry->second.cores.end(), cores.begin(), cores.end());
+ for (const auto which : remove_cores) {
+ const auto core = std::find(cores.begin(), cores.end(), which);
+ if (core == cores.end()) {
+ Logger::error(
+ "In history of province ", province->get_identifier(), " tried to remove nonexistant core of country: ",
+ which->get_identifier(), " at date ", date.to_string()
+ );
+ return false;
+ }
+ existing_entry->second.cores.erase(core);
+ }
+ } else {
+ province_registry.emplace(date, ProvinceHistory {
+ owner, controller, colonial, slave, std::move(cores), rgo, life_rating, terrain_type, std::move(buildings),
+ std::move(party_loyalties)
+ });
+ }
+ return true;
}
void ProvinceHistoryManager::lock_province_histories() {
- for (const auto& entry : province_histories) {
- if (entry.second.size() == 0) {
- Logger::error("Attempted to lock province histories - province ", entry.first->get_identifier(), " has no history entries!");
- }
- }
- Logger::info("Locked province history registry after registering ", province_histories.size(), " items");
- locked = true;
+ for (auto const& entry : province_histories) {
+ if (entry.second.size() == 0) {
+ Logger::error(
+ "Attempted to lock province histories - province ", entry.first->get_identifier(), " has no history entries!"
+ );
+ }
+ }
+ Logger::info("Locked province history registry after registering ", province_histories.size(), " items");
+ locked = true;
}
bool ProvinceHistoryManager::is_locked() const {
- return locked;
+ return locked;
}
ProvinceHistory const* ProvinceHistoryManager::get_province_history(Province const* province, Date entry) const {
- Date closest_entry;
- auto province_registry = province_histories.find(province);
-
- if (province_registry == province_histories.end()) {
- Logger::error("Attempted to access history of undefined province ", province->get_identifier());
- return nullptr;
- }
-
- for (const auto& current : province_registry->second) {
- if (current.first == entry) return &current.second;
- if (current.first > entry) continue;
- if (current.first > closest_entry && current.first < entry) closest_entry = current.first;
- }
-
- auto entry_registry = province_registry->second.find(closest_entry);
- if (entry_registry != province_registry->second.end()) return &entry_registry->second;
+ Date closest_entry;
+ auto province_registry = province_histories.find(province);
+
+ if (province_registry == province_histories.end()) {
+ Logger::error("Attempted to access history of undefined province ", province->get_identifier());
+ return nullptr;
+ }
+
+ for (auto const& current : province_registry->second) {
+ if (current.first == entry) {
+ return &current.second;
+ }
+ if (current.first > entry) {
+ continue;
+ }
+ if (current.first > closest_entry && current.first < entry) {
+ closest_entry = current.first;
+ }
+ }
+
+ auto entry_registry = province_registry->second.find(closest_entry);
+ if (entry_registry != province_registry->second.end()) {
+ return &entry_registry->second;
+ }
/* warned about lack of entries earlier, return nullptr */
return nullptr;
}
-inline ProvinceHistory const* ProvinceHistoryManager::get_province_history(Province const* province, Bookmark const* bookmark) const {
- return get_province_history(province, bookmark->get_date());
+inline ProvinceHistory const* ProvinceHistoryManager::get_province_history(
+ Province const* province, Bookmark const* bookmark
+) const {
+ return get_province_history(province, bookmark->get_date());
}
-inline bool ProvinceHistoryManager::_load_province_history_entry(GameManager& game_manager, std::string_view province, Date const& date, ast::NodeCPtr root) {
- Country const* owner = nullptr;
- Country const* controller = nullptr;
- std::vector<Country const*> cores;
- std::vector<Country const*> remove_cores;
- Good const* rgo;
- uint8_t life_rating, colonial;
- bool slave;
- TerrainType const* terrain_type;
- std::map<Building const*, uint8_t> buildings;
- std::map<Ideology const*, uint8_t> party_loyalties;
-
- std::bitset<5> updates;
-
- bool ret = expect_dictionary_keys_and_default(
- [&game_manager, &buildings, &updates](std::string_view key, ast::NodeCPtr value) -> bool {
- // used for province buildings like forts or railroads
- if (game_manager.get_economy_manager().get_building_manager().has_building_identifier(key)) {
- Building const* building;
- uint8_t level;
-
- bool ret = game_manager.get_economy_manager().get_building_manager().expect_building_str(assign_variable_callback_pointer(building))(key);
- ret &= expect_uint(assign_variable_callback(level))(value);
-
- buildings.emplace(building, level);
- updates[3] = true;
- return ret;
- }
-
- bool is_date;
- Date().from_string(key, &is_date, true);
- if (is_date) return true;
-
- return key_value_invalid_callback(key, value);
- },
- "owner", ZERO_OR_ONE, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(owner)),
- "controller", ZERO_OR_ONE, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(controller)),
- "add_core", ZERO_OR_MORE, [&game_manager, &cores](ast::NodeCPtr node) -> bool {
- Country const* core;
-
- bool ret = game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(core))(node);
- cores.push_back(core);
- return ret;
- },
- "remove_core", ZERO_OR_MORE, [&game_manager, &remove_cores](ast::NodeCPtr node) -> bool {
- Country const* remove;
-
- bool ret = game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(remove))(node);
- remove_cores.push_back(remove);
- return ret;
- },
- "colonial", ZERO_OR_ONE, expect_uint<uint8_t>([&colonial, &updates](uint8_t colony_level) -> bool {
- colonial = colony_level;
- updates[0] = true;
-
- return true;
- }),
- "colony", ZERO_OR_ONE, expect_uint<uint8_t>([&colonial, &updates](uint8_t colony_level) -> bool {
- colonial = colony_level;
- updates[0] = true;
-
- return true;
- }),
- "is_slave", ZERO_OR_ONE, expect_bool([&slave, &updates](bool is_slave) -> bool {
- if (is_slave) {
- slave = true;
- } else {
- slave = false;
- }
- updates[1] = true;
-
- return true;
- }),
- "trade_goods", ZERO_OR_ONE, game_manager.get_economy_manager().get_good_manager().expect_good_identifier(assign_variable_callback_pointer(rgo)),
- "life_rating", ZERO_OR_ONE, expect_uint<uint8_t>([&life_rating, &updates](uint8_t rating) -> bool {
- life_rating = rating;
- updates[2] = true;
-
- return true;
- }),
- "terrain", ZERO_OR_ONE, game_manager.get_map().get_terrain_type_manager().expect_terrain_type_identifier(assign_variable_callback_pointer(terrain_type)),
- "party_loyalty", ZERO_OR_MORE, [&game_manager, &party_loyalties, &updates](ast::NodeCPtr node) -> bool {
- Ideology const* ideology;
- uint8_t amount; // percent I do believe
-
- bool ret = expect_dictionary_keys(
- "ideology", ONE_EXACTLY, game_manager.get_politics_manager().get_ideology_manager().expect_ideology_identifier(assign_variable_callback_pointer(ideology)),
- "loyalty_value", ONE_EXACTLY, expect_uint(assign_variable_callback(amount))
- )(node);
- party_loyalties.emplace(ideology, amount);
- updates[4] = true;
- return ret;
- },
- "state_building", ZERO_OR_MORE, [&game_manager, &buildings, &updates](ast::NodeCPtr node) -> bool {
- Building const* building;
- uint8_t level;
-
- bool ret = expect_dictionary_keys(
- "level", ONE_EXACTLY, expect_uint(assign_variable_callback(level)),
- "building", ONE_EXACTLY, game_manager.get_economy_manager().get_building_manager().expect_building_identifier(assign_variable_callback_pointer(building)),
- "upgrade", ZERO_OR_ONE, success_callback // doesn't appear to have an effect
- )(node);
- buildings.emplace(building, level);
- updates[3] = true;
- return ret;
- }
- )(root);
-
- ret &= add_province_history_entry(
- game_manager.get_map().get_province_by_identifier(province),
- date,
- owner,
- controller,
- colonial,
- slave,
- std::move(cores),
- std::move(remove_cores),
- rgo,
- life_rating,
- terrain_type,
- std::move(buildings),
- std::move(party_loyalties),
- updates
- );
- return ret;
+inline bool ProvinceHistoryManager::_load_province_history_entry(
+ GameManager& game_manager, std::string_view province, Date const& date, ast::NodeCPtr root
+) {
+ Country const* owner = nullptr;
+ Country const* controller = nullptr;
+ std::vector<Country const*> cores;
+ std::vector<Country const*> remove_cores;
+ Good const* rgo;
+ uint8_t life_rating, colonial;
+ bool slave;
+ TerrainType const* terrain_type;
+ std::map<Building const*, uint8_t> buildings;
+ std::map<Ideology const*, uint8_t> party_loyalties;
+ std::bitset<5> updates;
+
+ bool ret = expect_dictionary_keys_and_default(
+ [&game_manager, &buildings, &updates](std::string_view key, ast::NodeCPtr value) -> bool {
+ // used for province buildings like forts or railroads
+ if (game_manager.get_economy_manager().get_building_manager().has_building_identifier(key)) {
+ Building const* building;
+ uint8_t level;
+
+ bool ret = game_manager.get_economy_manager().get_building_manager()
+ .expect_building_str(assign_variable_callback_pointer(building))(key);
+ ret &= expect_uint(assign_variable_callback(level))(value);
+
+ buildings.emplace(building, level);
+ updates[3] = true;
+ return ret;
+ }
+
+ bool is_date;
+ Date().from_string(key, &is_date, true);
+ if (is_date) {
+ return true;
+ }
+
+ return key_value_invalid_callback(key, value);
+ },
+ "owner", ZERO_OR_ONE, game_manager.get_country_manager()
+ .expect_country_identifier(assign_variable_callback_pointer(owner)),
+ "controller", ZERO_OR_ONE, game_manager.get_country_manager()
+ .expect_country_identifier(assign_variable_callback_pointer(controller)),
+ "add_core", ZERO_OR_MORE, [&game_manager, &cores](ast::NodeCPtr node) -> bool {
+ Country const* core;
+
+ bool ret = game_manager.get_country_manager()
+ .expect_country_identifier(assign_variable_callback_pointer(core))(node);
+ cores.push_back(core);
+ return ret;
+ },
+ "remove_core", ZERO_OR_MORE, [&game_manager, &remove_cores](ast::NodeCPtr node) -> bool {
+ Country const* remove;
+
+ bool ret = game_manager.get_country_manager()
+ .expect_country_identifier(assign_variable_callback_pointer(remove))(node);
+ remove_cores.push_back(remove);
+ return ret;
+ },
+ "colonial", ZERO_OR_ONE, expect_uint<uint8_t>([&colonial, &updates](uint8_t colony_level) -> bool {
+ colonial = colony_level;
+ updates[0] = true;
+
+ return true;
+ }),
+ "colony", ZERO_OR_ONE, expect_uint<uint8_t>([&colonial, &updates](uint8_t colony_level) -> bool {
+ colonial = colony_level;
+ updates[0] = true;
+
+ return true;
+ }),
+ "is_slave", ZERO_OR_ONE, expect_bool([&slave, &updates](bool is_slave) -> bool {
+ if (is_slave) {
+ slave = true;
+ } else {
+ slave = false;
+ }
+ updates[1] = true;
+
+ return true;
+ }),
+ "trade_goods", ZERO_OR_ONE, game_manager.get_economy_manager().get_good_manager()
+ .expect_good_identifier(assign_variable_callback_pointer(rgo)),
+ "life_rating", ZERO_OR_ONE, expect_uint<uint8_t>([&life_rating, &updates](uint8_t rating) -> bool {
+ life_rating = rating;
+ updates[2] = true;
+
+ return true;
+ }),
+ "terrain", ZERO_OR_ONE, game_manager.get_map().get_terrain_type_manager()
+ .expect_terrain_type_identifier(assign_variable_callback_pointer(terrain_type)),
+ "party_loyalty", ZERO_OR_MORE, [&game_manager, &party_loyalties, &updates](ast::NodeCPtr node) -> bool {
+ Ideology const* ideology;
+ uint8_t amount; // percent I do believe
+
+ bool ret = expect_dictionary_keys(
+ "ideology", ONE_EXACTLY, game_manager.get_politics_manager().get_ideology_manager()
+ .expect_ideology_identifier(assign_variable_callback_pointer(ideology)),
+ "loyalty_value", ONE_EXACTLY, expect_uint(assign_variable_callback(amount))
+ )(node);
+ party_loyalties.emplace(ideology, amount);
+ updates[4] = true;
+ return ret;
+ },
+ "state_building", ZERO_OR_MORE, [&game_manager, &buildings, &updates](ast::NodeCPtr node) -> bool {
+ Building const* building;
+ uint8_t level;
+
+ bool ret = expect_dictionary_keys(
+ "level", ONE_EXACTLY, expect_uint(assign_variable_callback(level)),
+ "building", ONE_EXACTLY, game_manager.get_economy_manager().get_building_manager()
+ .expect_building_identifier(assign_variable_callback_pointer(building)),
+ "upgrade", ZERO_OR_ONE, success_callback // doesn't appear to have an effect
+ )(node);
+ buildings.emplace(building, level);
+ updates[3] = true;
+ return ret;
+ }
+ )(root);
+
+ ret &= add_province_history_entry(
+ game_manager.get_map().get_province_by_identifier(province), date, owner, controller, colonial, slave,
+ std::move(cores), std::move(remove_cores), rgo, life_rating, terrain_type, std::move(buildings),
+ std::move(party_loyalties), updates
+ );
+ return ret;
}
bool ProvinceHistoryManager::load_province_history_file(GameManager& game_manager, std::string_view name, ast::NodeCPtr root) {
- bool ret = _load_province_history_entry(game_manager, name, game_manager.get_define_manager().get_start_date(), root);
-
- ret &= expect_dictionary(
- [this, &game_manager, &name](std::string_view key, ast::NodeCPtr value) -> bool {
- bool is_date = false;
- Date entry = Date().from_string(key, &is_date, true);
- if (!is_date) return true;
-
- Date const& end_date = game_manager.get_define_manager().get_end_date();
- if (entry > end_date) {
- Logger::error("History entry ", entry.to_string(), " of province ", name, " defined after defined end date ", end_date.to_string());
- return false;
- }
-
- return _load_province_history_entry(game_manager, name, entry, value);
- }
- )(root);
-
- return ret;
+ bool ret = _load_province_history_entry(game_manager, name, game_manager.get_define_manager().get_start_date(), root);
+
+ ret &= expect_dictionary(
+ [this, &game_manager, &name](std::string_view key, ast::NodeCPtr value) -> bool {
+ bool is_date = false;
+ Date entry = Date().from_string(key, &is_date, true);
+ if (!is_date) {
+ return true;
+ }
+
+ Date const& end_date = game_manager.get_define_manager().get_end_date();
+ if (entry > end_date) {
+ Logger::error(
+ "History entry ", entry.to_string(), " of province ", name, " defined after defined end date ",
+ end_date.to_string()
+ );
+ return false;
+ }
+
+ return _load_province_history_entry(game_manager, name, entry, value);
+ }
+ )(root);
+
+ return ret;
}
diff --git a/src/openvic-simulation/history/ProvinceHistory.hpp b/src/openvic-simulation/history/ProvinceHistory.hpp
index 0304b2a..00ce212 100644
--- a/src/openvic-simulation/history/ProvinceHistory.hpp
+++ b/src/openvic-simulation/history/ProvinceHistory.hpp
@@ -1,96 +1,85 @@
#pragma once
+#include <bitset>
#include <map>
#include <vector>
-#include <bitset>
-#include "openvic-simulation/map/Province.hpp"
-#include "openvic-simulation/map/TerrainType.hpp"
#include "openvic-simulation/country/Country.hpp"
-#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/economy/Building.hpp"
+#include "openvic-simulation/economy/Good.hpp"
#include "openvic-simulation/history/Bookmark.hpp"
+#include "openvic-simulation/map/Province.hpp"
+#include "openvic-simulation/map/TerrainType.hpp"
namespace OpenVic {
- struct ProvinceHistoryManager;
+ struct ProvinceHistoryManager;
+
+ struct ProvinceHistory {
+ friend struct ProvinceHistoryManager;
- struct ProvinceHistory {
- friend struct ProvinceHistoryManager;
+ private:
+ Country const* owner;
+ Country const* controller;
+ uint8_t colonial;
+ bool slave;
+ std::vector<Country const*> cores; // non-standard, maintains cores between entries
+ Good const* rgo;
+ uint8_t life_rating;
+ TerrainType const* terrain_type;
+ std::map<Building const*, uint8_t> buildings;
+ std::map<Ideology const*, uint8_t> party_loyalties;
- private:
- Country const* owner;
- Country const* controller;
- uint8_t colonial;
- bool slave;
- std::vector<Country const*> cores; // non-standard, maintains cores between entries
- Good const* rgo;
- uint8_t life_rating;
- TerrainType const* terrain_type;
- std::map<Building const*, uint8_t> buildings;
- std::map<Ideology const*, uint8_t> party_loyalties;
+ ProvinceHistory(
+ Country const* new_owner, Country const* new_controller, uint8_t new_colonial, bool new_slave,
+ std::vector<Country const*>&& new_cores, Good const* new_rgo, uint8_t new_life_rating,
+ TerrainType const* new_terrain_type, std::map<Building const*, uint8_t>&& new_buildings,
+ std::map<Ideology const*, uint8_t>&& new_party_loyalties
+ );
- ProvinceHistory(
- Country const* new_owner,
- Country const* new_controller,
- uint8_t new_colonial,
- bool new_slave,
- std::vector<Country const*>&& new_cores,
- Good const* new_rgo,
- uint8_t new_life_rating,
- TerrainType const* new_terrain_type,
- std::map<Building const*, uint8_t>&& new_buildings,
- std::map<Ideology const*, uint8_t>&& new_party_loyalties
- );
+ public:
+ Country const* get_owner() const;
+ Country const* get_controller() const;
+ uint8_t get_colony_status() const; // 0 = state, 1 = protectorate, 2 = colony
+ bool is_slave() const;
+ std::vector<Country const*> const& get_cores() const;
+ bool is_core_of(Country const* country) const;
+ Good const* get_rgo() const;
+ uint8_t get_life_rating() const;
+ TerrainType const* get_terrain_type() const;
+ std::map<Building const*, uint8_t> const& get_buildings() const;
+ std::map<Ideology const*, uint8_t> const& get_party_loyalties() const;
+ };
- public:
- Country const* get_owner() const;
- Country const* get_controller() const;
- uint8_t get_colony_status() const; // 0 = state, 1 = protectorate, 2 = colony
- bool is_slave() const;
- const std::vector<Country const*>& get_cores() const;
- bool is_core_of(Country const* country) const;
- Good const* get_rgo() const;
- uint8_t get_life_rating() const;
- TerrainType const* get_terrain_type() const;
- const std::map<Building const*, uint8_t>& get_buildings() const;
- const std::map<Ideology const*, uint8_t>& get_party_loyalties() const;
- };
+ struct ProvinceHistoryManager {
+ private:
+ std::map<Province const*, std::map<Date, ProvinceHistory>> province_histories;
+ bool locked = false;
- struct ProvinceHistoryManager {
- private:
- std::map<Province const*, std::map<Date, ProvinceHistory>> province_histories;
- bool locked = false;
+ inline bool _load_province_history_entry(
+ GameManager& game_manager, std::string_view province, Date const& date, ast::NodeCPtr root
+ );
- inline bool _load_province_history_entry(GameManager& game_manager, std::string_view province, Date const& date, ast::NodeCPtr root);
-
- public:
- ProvinceHistoryManager() {}
+ public:
+ ProvinceHistoryManager() {}
- bool add_province_history_entry(
- Province const* province,
- Date date,
- Country const* owner,
- Country const* controller,
- uint8_t colonial,
- bool slave,
- std::vector<Country const*>&& cores, // additive to existing entries
- std::vector<Country const*>&& remove_cores, // existing cores that need to be removed
- Good const* rgo,
- uint8_t life_rating,
- TerrainType const* terrain_type,
- std::map<Building const*, uint8_t>&& buildings,
- std::map<Ideology const*, uint8_t>&& party_loyalties,
- std::bitset<5> updates // bitmap of updated non-pointer values, top to bottom
- );
+ bool add_province_history_entry(
+ Province const* province, Date date, Country const* owner, Country const* controller, uint8_t colonial, bool slave,
+ std::vector<Country const*>&& cores, // additive to existing entries
+ std::vector<Country const*>&& remove_cores, // existing cores that need to be removed
+ Good const* rgo, uint8_t life_rating, TerrainType const* terrain_type,
+ std::map<Building const*, uint8_t>&& buildings, std::map<Ideology const*, uint8_t>&& party_loyalties,
+ std::bitset<5> updates // bitmap of updated non-pointer values, top to bottom
+ );
- void lock_province_histories();
- bool is_locked() const;
+ void lock_province_histories();
+ bool is_locked() const;
- /* Returns history of province at date, if date doesn't have an entry returns closest entry before date. Return can be nullptr if an error occurs. */
- ProvinceHistory const* get_province_history(Province const* province, Date entry) const;
- /* Returns history of province at bookmark date. Return can be nullptr if an error occurs. */
- inline ProvinceHistory const* get_province_history(Province const* province, Bookmark const* bookmark) const;
+ /* Returns history of province at date, if date doesn't have an entry returns closest entry before date.
+ * Return can be nullptr if an error occurs. */
+ ProvinceHistory const* get_province_history(Province const* province, Date entry) const;
+ /* Returns history of province at bookmark date. Return can be nullptr if an error occurs. */
+ inline ProvinceHistory const* get_province_history(Province const* province, Bookmark const* bookmark) const;
- bool load_province_history_file(GameManager& game_manager, std::string_view name, ast::NodeCPtr root);
- };
+ bool load_province_history_file(GameManager& game_manager, std::string_view name, ast::NodeCPtr root);
+ };
} // namespace OpenVic