From 3f9911dd1cbfca513c8615d778a8295906d8b7d5 Mon Sep 17 00:00:00 2001 From: Spartan322 Date: Thu, 4 Jan 2024 20:48:46 -0500 Subject: Add skeleton CountryRelationManager Change `DiplomaticAction::Argument` to refer to `CountryInstance*` instead of `Country*` Add `GameManager&` argument to `DiplomaticActionManager::setup_diplomatic_actions` Add some ErrorMacros, likely and unlikely macros and stringization macros (based on Godot's macros) Implement `increase_relations` DiplomaticAction commit function Implement `decrease_relations` DiplomaticAction commit function Fix include StringUtils.hpp errors --- .../diplomacy/CountryRelation.cpp | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/openvic-simulation/diplomacy/CountryRelation.cpp (limited to 'src/openvic-simulation/diplomacy/CountryRelation.cpp') 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 + +#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; +} -- cgit v1.2.3-56-ga3b1