aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/CountryHistory.cpp
diff options
context:
space:
mode:
author hop311 <hop3114@gmail.com>2023-10-29 15:11:10 +0100
committer hop311 <hop3114@gmail.com>2023-10-29 21:08:08 +0100
commit1b5e43fa7750cc4025d32f18390593cbce3ba842 (patch)
treed37fcb69766ec029ea4e3e2816c419f9d7e05f7c /src/openvic-simulation/history/CountryHistory.cpp
parent164264b047921dbe1567d2af183e1cffb200a8cb (diff)
Clang-format formatting (with manual cleanup)
Diffstat (limited to 'src/openvic-simulation/history/CountryHistory.cpp')
-rw-r--r--src/openvic-simulation/history/CountryHistory.cpp270
1 files changed, 131 insertions, 139 deletions
diff --git a/src/openvic-simulation/history/CountryHistory.cpp b/src/openvic-simulation/history/CountryHistory.cpp
index 9ed271b..2dfc171 100644
--- a/src/openvic-simulation/history/CountryHistory.cpp
+++ b/src/openvic-simulation/history/CountryHistory.cpp
@@ -6,20 +6,11 @@ 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
+ 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 },
@@ -83,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!");
@@ -156,22 +134,13 @@ bool CountryHistoryManager::add_country_history_entry(
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;
}
@@ -179,8 +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");
@@ -224,8 +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;
@@ -264,93 +235,112 @@ inline bool CountryHistoryManager::_load_country_history_entry(GameManager& game
},
/* 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);
+ "capital", ZERO_OR_ONE,
+ game_manager.get_map().expect_province_identifier([&capital](Province const& province) -> bool {
+ capital = &province;
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)),
+ }),
+ "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", 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 = &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;
- },
+ 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;
}
@@ -361,22 +351,24 @@ bool CountryHistoryManager::load_country_history_file(GameManager& game_manager,
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;
-
- 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;
- }
+ 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;
+ }
- 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;
}