diff options
Diffstat (limited to 'src/openvic-simulation/diplomacy/DiplomaticAction.cpp')
-rw-r--r-- | src/openvic-simulation/diplomacy/DiplomaticAction.cpp | 117 |
1 files changed, 88 insertions, 29 deletions
diff --git a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp index d10eda3..a386d9f 100644 --- a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp +++ b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp @@ -1,19 +1,19 @@ #include "DiplomaticAction.hpp" #include <string_view> -#include <variant> +#include "openvic-simulation/GameManager.hpp" #include "openvic-simulation/types/IdentifierRegistry.hpp" #include "openvic-simulation/utility/Logger.hpp" using namespace OpenVic; DiplomaticActionType::DiplomaticActionType(DiplomaticActionType::Initializer&& initializer) - : commit_action_caller { std::move(initializer.commit) }, - allowed_to_commit { std::move(initializer.allowed) }, get_acceptance { std::move(initializer.get_acceptance) } {} + : commit_action_caller { std::move(initializer.commit) }, allowed_to_commit { std::move(initializer.allowed) }, + get_acceptance { std::move(initializer.get_acceptance) } {} CancelableDiplomaticActionType::CancelableDiplomaticActionType(CancelableDiplomaticActionType::Initializer&& initializer) - : allowed_to_cancel{std::move(initializer.allowed_cancel)}, DiplomaticActionType(std::move(initializer)) {} + : allowed_to_cancel { std::move(initializer.allowed_cancel) }, DiplomaticActionType(std::move(initializer)) {} DiplomaticActionManager::DiplomaticActionManager() {} @@ -38,7 +38,7 @@ bool DiplomaticActionManager::add_cancelable_diplomatic_action( } DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick( - std::string_view identifier, Country& sender, Country& reciever, std::any context_data + std::string_view identifier, CountryInstance* sender, CountryInstance* reciever, std::any context_data ) { auto type = diplomatic_action_types.get_item_by_identifier(identifier); @@ -52,92 +52,151 @@ DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick return result; } -bool DiplomaticActionManager::setup_diplomatic_actions() { +bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) { using Argument = DiplomaticActionType::Argument; bool result = true; result &= add_diplomatic_action( "form_alliance", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "call_ally", { .commit = [](Argument& arg) {}, - .allowed = [](const Argument& arg) { return false; }, - .get_acceptance = [](const Argument& arg) { return 1; } + .allowed = + [](const Argument& arg) { + return false; + }, + .get_acceptance = + [](const Argument& arg) { + return 1; + }, } ); result &= add_cancelable_diplomatic_action( "request_military_access", { .commit = [](Argument& arg) {}, - .allowed_cancel = [](const Argument& arg) { return true; } + .allowed_cancel = + [](const Argument& arg) { + return true; + }, } ); - result &= add_diplomatic_action( - "give_military_access", - { [](Argument& arg) {} } - ); + result &= add_diplomatic_action("give_military_access", { [](Argument& arg) {} }); result &= add_diplomatic_action( "increase_relations", { - .commit = [](Argument& arg) {}, - .allowed = [](const Argument& arg) { return false; }, + .commit = + [&manager](Argument& arg) { + auto relation = manager.get_diplomacy_manager().get_country_relation_manager().get_country_relation_ptr( + arg.sender, arg.reciever + ); + if (!relation) { + return; + } + *relation += 25; + }, + .allowed = + [](const Argument& arg) { + return false; + }, } ); result &= add_diplomatic_action( "decrease_relations", - { [](Argument& arg) {} } + { + .commit = + [&manager](Argument& arg) { + auto relation = manager.get_diplomacy_manager().get_country_relation_manager().get_country_relation_ptr( + arg.sender, arg.reciever + ); + if (!relation) { + return; + } + *relation -= 25; + }, + .allowed = + [](const Argument& arg) { + return false; + }, + } ); result &= add_diplomatic_action( "war_subsidies", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "declare_war", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "offer_peace", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "command_units", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "discredit", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "expel_advisors", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "increase_opinion", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "decrease_opinion", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "add_to_sphere", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "remove_from_sphere", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "justify_war", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); result &= add_diplomatic_action( "give_vision", - { [](Argument& arg) {} } + { + [](Argument& arg) {}, + } ); diplomatic_action_types.lock(); |