aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/diplomacy
diff options
context:
space:
mode:
Diffstat (limited to 'src/openvic-simulation/diplomacy')
-rw-r--r--src/openvic-simulation/diplomacy/DiplomacyManager.hpp11
-rw-r--r--src/openvic-simulation/diplomacy/DiplomaticAction.cpp31
-rw-r--r--src/openvic-simulation/diplomacy/DiplomaticAction.hpp23
3 files changed, 28 insertions, 37 deletions
diff --git a/src/openvic-simulation/diplomacy/DiplomacyManager.hpp b/src/openvic-simulation/diplomacy/DiplomacyManager.hpp
deleted file mode 100644
index 7aca409..0000000
--- a/src/openvic-simulation/diplomacy/DiplomacyManager.hpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-#include "openvic-simulation/diplomacy/CountryRelation.hpp"
-#include "openvic-simulation/diplomacy/DiplomaticAction.hpp"
-
-namespace OpenVic {
- class DiplomacyManager {
- DiplomaticActionManager PROPERTY_REF(diplomatic_action_manager);
- CountryRelationManager PROPERTY_REF(country_relation_manager);
- };
-}
diff --git a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp
index a386d9f..41c0aa2 100644
--- a/src/openvic-simulation/diplomacy/DiplomaticAction.cpp
+++ b/src/openvic-simulation/diplomacy/DiplomaticAction.cpp
@@ -2,15 +2,15 @@
#include <string_view>
-#include "openvic-simulation/GameManager.hpp"
+#include "openvic-simulation/InstanceManager.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)) {}
@@ -38,11 +38,12 @@ bool DiplomaticActionManager::add_cancelable_diplomatic_action(
}
DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick(
- std::string_view identifier, CountryInstance* sender, CountryInstance* reciever, std::any context_data
+ std::string_view identifier, CountryInstance* sender, CountryInstance* reciever, std::any context_data,
+ InstanceManager& instance_manager
) {
auto type = diplomatic_action_types.get_item_by_identifier(identifier);
- DiplomaticActionTickCache result { { sender, reciever, context_data }, type };
+ DiplomaticActionTickCache result { { instance_manager, sender, reciever, context_data }, type };
type->visit([&](auto type) {
if ((result.allowed_to_commit = type.allowed_to_commit(result.argument))) {
result.acceptance = type.get_acceptance(result.argument);
@@ -52,7 +53,7 @@ DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick
return result;
}
-bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
+bool DiplomaticActionManager::setup_diplomatic_actions() {
using Argument = DiplomaticActionType::Argument;
bool result = true;
@@ -68,11 +69,11 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
{
.commit = [](Argument& arg) {},
.allowed =
- [](const Argument& arg) {
+ [](Argument const& arg) {
return false;
},
.get_acceptance =
- [](const Argument& arg) {
+ [](Argument const& arg) {
return 1;
},
}
@@ -82,7 +83,7 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
{
.commit = [](Argument& arg) {},
.allowed_cancel =
- [](const Argument& arg) {
+ [](Argument const& arg) {
return true;
},
}
@@ -92,8 +93,8 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
"increase_relations",
{
.commit =
- [&manager](Argument& arg) {
- auto relation = manager.get_diplomacy_manager().get_country_relation_manager().get_country_relation_ptr(
+ [](Argument& arg) {
+ auto relation = arg.instance_manager.get_country_relation_manager().get_country_relation_ptr(
arg.sender, arg.reciever
);
if (!relation) {
@@ -102,7 +103,7 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
*relation += 25;
},
.allowed =
- [](const Argument& arg) {
+ [](Argument const& arg) {
return false;
},
}
@@ -111,8 +112,8 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
"decrease_relations",
{
.commit =
- [&manager](Argument& arg) {
- auto relation = manager.get_diplomacy_manager().get_country_relation_manager().get_country_relation_ptr(
+ [](Argument& arg) {
+ auto relation = arg.instance_manager.get_country_relation_manager().get_country_relation_ptr(
arg.sender, arg.reciever
);
if (!relation) {
@@ -121,7 +122,7 @@ bool DiplomaticActionManager::setup_diplomatic_actions(GameManager& manager) {
*relation -= 25;
},
.allowed =
- [](const Argument& arg) {
+ [](Argument const& arg) {
return false;
},
}
diff --git a/src/openvic-simulation/diplomacy/DiplomaticAction.hpp b/src/openvic-simulation/diplomacy/DiplomaticAction.hpp
index 352b16e..cf93c75 100644
--- a/src/openvic-simulation/diplomacy/DiplomaticAction.hpp
+++ b/src/openvic-simulation/diplomacy/DiplomaticAction.hpp
@@ -7,33 +7,33 @@
#include <type_traits>
#include <variant>
-#include "openvic-simulation/country/Country.hpp"
#include "openvic-simulation/country/CountryInstance.hpp"
#include "openvic-simulation/types/FunctionRef.hpp"
#include "openvic-simulation/types/IdentifierRegistry.hpp"
namespace OpenVic {
- struct GameManager;
+ struct InstanceManager;
struct DiplomaticActionType {
friend struct DiplomaticActionManager;
friend struct CancelableDiplomaticActionType;
struct Argument {
+ InstanceManager& instance_manager;
CountryInstance* sender;
CountryInstance* reciever;
std::any context_data;
};
- using allowed_to_commit_func = FunctionRef<bool(const Argument&)>;
- using get_acceptance_func = FunctionRef<std::int32_t(const Argument&)>;
+ using allowed_to_commit_func = FunctionRef<bool(Argument const&)>;
+ using get_acceptance_func = FunctionRef<std::int32_t(Argument const&)>;
using commit_action_func = FunctionRef<void(Argument&)>;
- static bool allowed_to_commit_default(const Argument& argument) {
+ static bool allowed_to_commit_default(Argument const& argument) {
return true;
}
- static std::int32_t get_acceptance_default(const Argument& argument) {
+ static std::int32_t get_acceptance_default(Argument const& argument) {
return 1;
}
@@ -58,9 +58,9 @@ namespace OpenVic {
struct CancelableDiplomaticActionType : DiplomaticActionType {
friend struct DiplomaticActionManager;
- using allowed_to_cancel_func = FunctionRef<bool(const Argument&)>;
+ using allowed_to_cancel_func = FunctionRef<bool(Argument const&)>;
- static bool allowed_to_cancel_default(const Argument& argument) {
+ static bool allowed_to_cancel_default(Argument const& argument) {
return true;
}
@@ -113,7 +113,7 @@ namespace OpenVic {
struct DiplomaticActionTickCache {
DiplomaticActionType::Argument argument;
- const DiplomaticActionTypeStorage* type;
+ DiplomaticActionTypeStorage const* type;
bool allowed_to_commit;
std::int32_t acceptance = -1;
};
@@ -131,9 +131,10 @@ namespace OpenVic {
);
DiplomaticActionTickCache create_diplomatic_action_tick(
- std::string_view identifier, CountryInstance* sender, CountryInstance* reciever, std::any context_data
+ std::string_view identifier, CountryInstance* sender, CountryInstance* reciever, std::any context_data,
+ InstanceManager& instance_manager
);
- bool setup_diplomatic_actions(GameManager& manager);
+ bool setup_diplomatic_actions();
};
}