aboutsummaryrefslogtreecommitdiff
path: root/src/openvic-simulation/diplomacy/DiplomaticAction.cpp
blob: d10eda37d821583bbc0ab3ea16136a3292f7a030 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "DiplomaticAction.hpp"

#include <string_view>
#include <variant>

#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) } {}

CancelableDiplomaticActionType::CancelableDiplomaticActionType(CancelableDiplomaticActionType::Initializer&& initializer)
   : allowed_to_cancel{std::move(initializer.allowed_cancel)}, DiplomaticActionType(std::move(initializer)) {}

DiplomaticActionManager::DiplomaticActionManager() {}

bool DiplomaticActionManager::add_diplomatic_action(
   std::string_view identifier, DiplomaticActionType::Initializer&& initializer
) {
   if (identifier.empty()) {
      Logger::error("Invalid diplomatic action identifier - empty!");
      return false;
   }
   return diplomatic_action_types.add_item({ identifier, DiplomaticActionType { std::move(initializer) } });
}

bool DiplomaticActionManager::add_cancelable_diplomatic_action(
   std::string_view identifier, CancelableDiplomaticActionType::Initializer&& initializer
) {
   if (identifier.empty()) {
      Logger::error("Invalid cancelable diplomatic action identifier - empty!");
      return false;
   }
   return diplomatic_action_types.add_item({ identifier, CancelableDiplomaticActionType { std::move(initializer) } });
}

DiplomaticActionTickCache DiplomaticActionManager::create_diplomatic_action_tick(
   std::string_view identifier, Country& sender, Country& reciever, std::any context_data
) {
   auto type = diplomatic_action_types.get_item_by_identifier(identifier);

   DiplomaticActionTickCache result { { 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);
      }
   });

   return result;
}

bool DiplomaticActionManager::setup_diplomatic_actions() {
   using Argument = DiplomaticActionType::Argument;

   bool result = true;

   result &= add_diplomatic_action(
      "form_alliance",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "call_ally",
      {
         .commit = [](Argument& arg) {},
         .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; }
      }
   );
   result &= add_diplomatic_action(
      "give_military_access",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "increase_relations",
      {
         .commit = [](Argument& arg) {},
         .allowed = [](const Argument& arg) { return false; },
      }
   );
   result &= add_diplomatic_action(
      "decrease_relations",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "war_subsidies",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "declare_war",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "offer_peace",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "command_units",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "discredit",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "expel_advisors",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "increase_opinion",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "decrease_opinion",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "add_to_sphere",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "remove_from_sphere",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "justify_war",
      { [](Argument& arg) {} }
   );
   result &= add_diplomatic_action(
      "give_vision",
      { [](Argument& arg) {} }
   );
   diplomatic_action_types.lock();

   return result;
}