aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/diplomacy/CountryRelation.cpp
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2024-01-19 12:08:19 +0100
committer GitHub <noreply@github.com>2024-01-19 12:08:19 +0100
commit04e8d365687e5ce6d803f1b3d4c8fb7f2358079b (patch)
tree4b911cea0cf5e5ac467bbbd2073144866c52b265 /src/openvic-simulation/diplomacy/CountryRelation.cpp
parentc1bac9acee88a7ce1123aed3a748712fb2441762 (diff)
parent3f9911dd1cbfca513c8615d778a8295906d8b7d5 (diff)
Merge pull request #119 from OpenVicProject/add/country-relations
Diffstat (limited to 'src/openvic-simulation/diplomacy/CountryRelation.cpp')
-rw-r--r--src/openvic-simulation/diplomacy/CountryRelation.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/openvic-simulation/diplomacy/CountryRelation.cpp b/src/openvic-simulation/diplomacy/CountryRelation.cpp
new file mode 100644
index 0000000..d07739c
--- /dev/null
+++ b/src/openvic-simulation/diplomacy/CountryRelation.cpp
@@ -0,0 +1,53 @@
+#include "CountryRelation.hpp"
+
+#include <cassert>
+
+#include "openvic-simulation/country/CountryInstance.hpp"
+#include "openvic-simulation/utility/ErrorMacros.hpp"
+
+using namespace OpenVic;
+
+CountryRelationInstanceProxy::CountryRelationInstanceProxy(std::string_view id) : country_id { id } {}
+
+CountryRelationInstanceProxy::CountryRelationInstanceProxy(CountryInstance const* country)
+ : country_id { country->get_base_country()->get_identifier() } {}
+
+CountryRelationInstanceProxy::operator std::string_view() const {
+ return country_id;
+}
+
+CountryRelationManager::CountryRelationManager(/* TODO: Country Instance Manager Reference */) {}
+
+bool CountryRelationManager::add_country(CountryRelationInstanceProxy country) {
+ // TODO: iterate through Country Instances adding country to every previously existing country_relations
+ return true;
+}
+
+bool CountryRelationManager::remove_country(CountryRelationInstanceProxy country) {
+ // TODO: iterate through country_relations removing every pair that references the country's id
+ return true;
+}
+
+country_relation_value_t CountryRelationManager::get_country_relation(
+ CountryRelationInstanceProxy country, CountryRelationInstanceProxy recepient
+) const {
+ auto it = country_relations.find({ country.country_id, recepient.country_id });
+ OV_ERR_FAIL_COND_V(it == country_relations.end(), 0);
+ return it->second;
+}
+
+country_relation_value_t*
+CountryRelationManager::get_country_relation_ptr(CountryRelationInstanceProxy country, CountryRelationInstanceProxy recepient) {
+ auto it = country_relations.find({ country.country_id, recepient.country_id });
+ OV_ERR_FAIL_COND_V(it == country_relations.end(), nullptr);
+ return &it.value();
+}
+
+bool CountryRelationManager::set_country_relation(
+ CountryRelationInstanceProxy country, CountryRelationInstanceProxy recepient, country_relation_value_t value
+) {
+ auto it = country_relations.find({ country.country_id, recepient.country_id });
+ OV_ERR_FAIL_COND_V(it == country_relations.end(), false);
+ it.value() = value;
+ return true;
+}