aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/history/DiplomaticHistory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/history/DiplomaticHistory.cpp')
-rw-r--r--src/openvic-simulation/history/DiplomaticHistory.cpp203
1 files changed, 130 insertions, 73 deletions
diff --git a/src/openvic-simulation/history/DiplomaticHistory.cpp b/src/openvic-simulation/history/DiplomaticHistory.cpp
index 22ee765..f56b3dc 100644
--- a/src/openvic-simulation/history/DiplomaticHistory.cpp
+++ b/src/openvic-simulation/history/DiplomaticHistory.cpp
@@ -1,8 +1,6 @@
#include "DiplomaticHistory.hpp"
#include "openvic-simulation/GameManager.hpp"
-#include "openvic-simulation/dataloader/NodeTools.hpp"
-#include "openvic-simulation/history/Period.hpp"
using namespace OpenVic;
using namespace OpenVic::NodeTools;
@@ -13,8 +11,9 @@ WarHistory::added_wargoal_t::added_wargoal_t(
Country const* new_receiver,
WargoalType const* new_wargoal,
std::optional<Country const*> new_third_party,
- std::optional<Province const*> new_target
-) : added { new_added }, actor { new_actor }, receiver { new_receiver }, wargoal { new_wargoal }, third_party { new_third_party }, target { new_target } {}
+ std::optional<ProvinceDefinition const*> new_target
+) : added { new_added }, actor { new_actor }, receiver { new_receiver }, wargoal { new_wargoal },
+ third_party { new_third_party }, target { new_target } {}
WarHistory::war_participant_t::war_participant_t(
Country const* new_country,
@@ -26,7 +25,8 @@ WarHistory::WarHistory(
std::vector<war_participant_t>&& new_attackers,
std::vector<war_participant_t>&& new_defenders,
std::vector<added_wargoal_t>&& new_wargoals
-) : war_name { new_war_name }, attackers { std::move(new_attackers) }, defenders { std::move(new_defenders) }, wargoals { std::move(new_wargoals) } {}
+) : war_name { new_war_name }, attackers { std::move(new_attackers) }, defenders { std::move(new_defenders) },
+ wargoals { std::move(new_wargoals) } {}
AllianceHistory::AllianceHistory(
Country const* new_first,
@@ -56,7 +56,9 @@ void DiplomaticHistoryManager::reserve_more_wars(size_t size) {
}
void DiplomaticHistoryManager::lock_diplomatic_history() {
- Logger::info("Locked diplomacy history registry after registering ", alliances.size() + subjects.size() + wars.size(), " items");
+ Logger::info(
+ "Locked diplomacy history registry after registering ", alliances.size() + subjects.size() + wars.size(), " items"
+ );
locked = true;
}
@@ -66,7 +68,7 @@ bool DiplomaticHistoryManager::is_locked() const {
std::vector<AllianceHistory const*> DiplomaticHistoryManager::get_alliances(Date date) const {
std::vector<AllianceHistory const*> ret {};
- for (const auto& alliance : alliances) {
+ for (auto const& alliance : alliances) {
if (alliance.period.is_date_in_period(date)) {
ret.push_back(&alliance);
}
@@ -76,7 +78,7 @@ std::vector<AllianceHistory const*> DiplomaticHistoryManager::get_alliances(Date
std::vector<ReparationsHistory const*> DiplomaticHistoryManager::get_reparations(Date date) const {
std::vector<ReparationsHistory const*> ret {};
- for (const auto& reparation : reparations) {
+ for (auto const& reparation : reparations) {
if (reparation.period.is_date_in_period(date)) {
ret.push_back(&reparation);
}
@@ -86,7 +88,7 @@ std::vector<ReparationsHistory const*> DiplomaticHistoryManager::get_reparations
std::vector<SubjectHistory const*> DiplomaticHistoryManager::get_subjects(Date date) const {
std::vector<SubjectHistory const*> ret {};
- for (const auto& subject : subjects) {
+ for (auto const& subject : subjects) {
if (subject.period.is_date_in_period(date)) {
ret.push_back(&subject);
}
@@ -96,9 +98,9 @@ std::vector<SubjectHistory const*> DiplomaticHistoryManager::get_subjects(Date d
std::vector<WarHistory const*> DiplomaticHistoryManager::get_wars(Date date) const {
std::vector<WarHistory const*> ret;
- for (const auto& war : wars) {
+ for (auto const& war : wars) {
Date start {};
- for (const auto& wargoal : war.wargoals) {
+ for (auto const& wargoal : war.wargoals) {
if (wargoal.added < start) start = wargoal.added;
}
if (start >= date) ret.push_back(&war);
@@ -115,8 +117,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(first)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(second)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(first)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(second)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -131,8 +135,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -147,8 +153,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -163,8 +171,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(overlord)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(subject)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -179,8 +189,10 @@ bool DiplomaticHistoryManager::load_diplomacy_history_file(CountryManager const&
std::optional<Date> end {};
bool ret = expect_dictionary_keys(
- "first", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(receiver)),
- "second", ONE_EXACTLY, country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(sender)),
+ "first", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(receiver)),
+ "second", ONE_EXACTLY,
+ country_manager.expect_country_identifier_or_string(assign_variable_callback_pointer(sender)),
"start_date", ONE_EXACTLY, expect_date_identifier_or_string(assign_variable_callback(start)),
"end_date", ZERO_OR_ONE, expect_date_identifier_or_string(assign_variable_callback(end))
)(node);
@@ -199,88 +211,133 @@ bool DiplomaticHistoryManager::load_war_history_file(GameManager const& game_man
Date current_date {};
bool ret = expect_dictionary_keys_and_default(
- [&game_manager, &attackers, &defenders, &wargoals, &current_date, &name](std::string_view key, ast::NodeCPtr node) -> bool {
+ [&game_manager, &attackers, &defenders, &wargoals, &current_date, &name](
+ std::string_view key, ast::NodeCPtr node
+ ) -> bool {
bool ret = expect_date_str(assign_variable_callback(current_date))(key);
+
ret &= expect_dictionary_keys(
- "add_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&attackers, &current_date, &name](Country const& country) -> bool {
- for (const auto& attacker : attackers) {
- if (attacker.get_country() == &country) {
- Logger::error("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to add attacking country ", attacker.get_country()->get_identifier(), " which is already present!");
- return false;
+ "add_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&attackers, &current_date, &name](Country const& country) -> bool {
+ for (auto const& attacker : attackers) {
+ if (attacker.get_country() == &country) {
+ Logger::error(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to add attacking country ", attacker.get_country()->get_identifier(),
+ " which is already present!"
+ );
+ return false;
+ }
}
- }
- attackers.push_back({ &country, { current_date, {} } });
- return true;
- }),
- "add_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&defenders, &current_date, &name](Country const& country) -> bool {
- for (const auto& defender : defenders) {
- if (defender.get_country() == &country) {
- Logger::error("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to add defending country ", defender.get_country()->get_identifier(), " which is already present!");
- return false;
- }
+ attackers.push_back({ &country, { current_date, {} } });
+ return true;
}
-
- defenders.push_back({ &country, { current_date, {} } });
- return true;
- }),
- "rem_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&attackers, &current_date, &name](Country const& country) -> bool {
- WarHistory::war_participant_t* participant_to_remove = nullptr;
-
- for (auto& attacker : attackers) {
- if (attacker.country == &country) {
- participant_to_remove = &attacker;
- break;
+ ),
+ "add_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&defenders, &current_date, &name](Country const& country) -> bool {
+ for (auto const& defender : defenders) {
+ if (defender.get_country() == &country) {
+ Logger::error(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to add defending country ", defender.get_country()->get_identifier(),
+ " which is already present!"
+ );
+ return false;
+ }
}
- }
- if (participant_to_remove == nullptr) {
- Logger::warning("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to remove attacking country ", country.get_identifier(), " which was not present!");
+ defenders.push_back({ &country, { current_date, {} } });
return true;
}
+ ),
+ "rem_attacker", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&attackers, &current_date, &name](Country const& country) -> bool {
+ WarHistory::war_participant_t* participant_to_remove = nullptr;
+
+ for (auto& attacker : attackers) {
+ if (attacker.country == &country) {
+ participant_to_remove = &attacker;
+ break;
+ }
+ }
- return participant_to_remove->period.try_set_end(current_date);
- }),
- "rem_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier([&defenders, &current_date, &name](Country const& country) -> bool {
- WarHistory::war_participant_t* participant_to_remove = nullptr;
-
- for (auto& defender : defenders) {
- if (defender.country == &country) {
- participant_to_remove = &defender;
- break;
+ if (participant_to_remove == nullptr) {
+ Logger::warning(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to remove attacking country ", country.get_identifier(),
+ " which was not present!"
+ );
+ return true;
}
- }
- if (participant_to_remove == nullptr) {
- Logger::warning("In history of war ", name, " at date ", current_date.to_string(), ": Attempted to remove attacking country ", country.get_identifier(), " which was not present!");
- return true;
+ return participant_to_remove->period.try_set_end(current_date);
}
+ ),
+ "rem_defender", ZERO_OR_MORE, game_manager.get_country_manager().expect_country_identifier(
+ [&defenders, &current_date, &name](Country const& country) -> bool {
+ WarHistory::war_participant_t* participant_to_remove = nullptr;
+
+ for (auto& defender : defenders) {
+ if (defender.country == &country) {
+ participant_to_remove = &defender;
+ break;
+ }
+ }
- return participant_to_remove->period.try_set_end(current_date);
- }),
+ if (participant_to_remove == nullptr) {
+ Logger::warning(
+ "In history of war ", name, " at date ", current_date.to_string(),
+ ": Attempted to remove attacking country ", country.get_identifier(),
+ " which was not present!"
+ );
+ return true;
+ }
+
+ return participant_to_remove->period.try_set_end(current_date);
+ }
+ ),
"war_goal", ZERO_OR_MORE, [&game_manager, &wargoals, &current_date](ast::NodeCPtr value) -> bool {
Country const* actor = nullptr;
Country const* receiver = nullptr;
WargoalType const* type = nullptr;
std::optional<Country const*> third_party {};
- std::optional<Province const*> target {};
+ std::optional<ProvinceDefinition const*> target {};
bool ret = expect_dictionary_keys(
- "actor", ONE_EXACTLY, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(actor)),
- "receiver", ONE_EXACTLY, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(receiver)),
- "casus_belli", ONE_EXACTLY, game_manager.get_military_manager().get_wargoal_type_manager().expect_wargoal_type_identifier(assign_variable_callback_pointer(type)),
- "country", ZERO_OR_ONE, game_manager.get_country_manager().expect_country_identifier(assign_variable_callback_pointer(*third_party)),
- "state_province_id", ZERO_OR_ONE, game_manager.get_map().expect_province_identifier(assign_variable_callback_pointer(*target))
+ "actor", ONE_EXACTLY,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(actor)
+ ),
+ "receiver", ONE_EXACTLY,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(receiver)
+ ),
+ "casus_belli", ONE_EXACTLY,
+ game_manager.get_military_manager().get_wargoal_type_manager().expect_wargoal_type_identifier(
+ assign_variable_callback_pointer(type)
+ ),
+ "country", ZERO_OR_ONE,
+ game_manager.get_country_manager().expect_country_identifier(
+ assign_variable_callback_pointer(*third_party)
+ ),
+ "state_province_id", ZERO_OR_ONE,
+ game_manager.get_map().expect_province_definition_identifier(
+ assign_variable_callback_pointer(*target)
+ )
)(value);
+
wargoals.push_back({ current_date, actor, receiver, type, third_party, target });
return ret;
}
)(node);
+
return ret;
},
"name", ZERO_OR_ONE, expect_string(assign_variable_callback(name))
)(root);
wars.push_back({ name, std::move(attackers), std::move(defenders), std::move(wargoals) });
+
return ret;
-} \ No newline at end of file
+}