Symphony Of Empires
diplomacy.cpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // diplomacy.cpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #include "eng3d/log.hpp"
26 
27 #include "diplomacy.hpp"
28 #include "nation.hpp"
29 #include "world.hpp"
30 
31 using namespace Diplomacy;
32 
33 TreatyClause::BaseClause::BaseClause(const Nation& _sender, const Nation& _receiver) {
34  sender_id = _sender;
35  receiver_id = _receiver;
36 }
37 
38 inline bool Diplomacy::is_friend(Nation& us, Nation& them) {
39  const auto& relation = g_world.get_relation(us, them);
40  // High enough relation with the threshold means it is friendly
41  return relation.relation >= 0.5f;
42 }
43 
44 inline bool Diplomacy::is_foe(Nation& us, Nation& them) {
45  return !is_friend(us, them);
46 }
47 
48 //
49 // Payment
50 //
52  return amount * days_duration;
53 }
54 
56  auto& world = World::get_instance();
57  world.nations[sender_id].prestige += 0.0001f;
58  world.nations[receiver_id].prestige -= 0.0001f;
59  world.nations[sender_id].budget -= amount;
60  world.nations[receiver_id].budget += amount;
61  days_duration--;
62 }
63 
65  return days_duration != 0;
66 }
67 
68 //
69 // Humiliate
70 //
72  const auto& world = World::get_instance();
73  return (world.nations[receiver_id].prestige * (amount * days_duration)) / 100;
74 }
75 
77  auto& world = World::get_instance();
78  world.nations[sender_id].prestige += amount;
79  world.nations[receiver_id].prestige -= amount;
80  days_duration--;
81 }
82 
84  return days_duration != 0;
85 }
86 
87 //
88 // LiberateNation
89 //
91  return 0;
92 }
93 
95  auto& world = World::get_instance();
96  world.nations[sender_id].prestige += cost() * 0.025f;
97  world.nations[receiver_id].prestige -= cost() * 0.05f;
98  for(const auto province_id : province_ids)
99  world.nations[liberated_id].give_province(world.provinces[province_id]);
100  done = true;
101 }
102 
104  return !done;
105 }
106 
107 //
108 // ImposePolicies
109 //
111  const auto& world = World::get_instance();
112  return imposed.difference(world.nations[receiver_id].current_policy);
113 }
114 
116  auto& world = World::get_instance();
117  world.nations[receiver_id].set_policy(imposed);
118  done = true;
119 }
120 
122  return !done;
123 }
124 
125 //
126 // AnnexProvince
127 //
129  return 0;
130 }
131 
133  auto& world = World::get_instance();
134  world.nations[sender_id].prestige += cost() * 0.025f;
135  world.nations[receiver_id].prestige -= cost() * 0.05f;
136  for(const auto province_id : province_ids)
137  world.nations[sender_id].give_province(world.provinces[province_id]);
138  done = true;
139 }
140 
142  return !done;
143 }
144 
145 //
146 // Puppet
147 //
149  return 0;
150 }
151 
153  auto& world = World::get_instance();
154  world.nations[receiver_id].make_puppet(world.nations[sender_id]);
155  done = true;
156 }
157 
159  return !done;
160 }
161 
162 // Checks if the specified nations participates in the treaty
163 bool Treaty::does_participate(const Nation& nation) const {
164  for(auto& [other_nation, _] : this->approval_status)
165  if(other_nation == nation)
166  return true;
167  return false;
168 }
169 
170 // Checks if the treaty has any clause which may still make the treaty be in effect
171 bool Treaty::in_effect() const {
172  bool on_effect = std::find_if(this->approval_status.begin(), this->approval_status.end(), [](const auto& status) { return status.second != TreatyApproval::ACCEPTED; }) == this->approval_status.end();
173  if(!on_effect)
174  return false;
175 
176  for(const auto& clause : this->clauses) {
177  if(clause->type == TreatyClauseType::PAYMENT) {
178  const auto* dyn_clause = static_cast<const TreatyClause::Payment*>(clause);
179  on_effect = dyn_clause->in_effect();
180  } else if(clause->type == TreatyClauseType::ANNEX_PROVINCES) {
181  const auto* dyn_clause = static_cast<const TreatyClause::AnnexProvince*>(clause);
182  on_effect = dyn_clause->in_effect();
183  } else if(clause->type == TreatyClauseType::LIBERATE_NATION) {
184  const auto* dyn_clause = static_cast<const TreatyClause::LiberateNation*>(clause);
185  on_effect = dyn_clause->in_effect();
186  } else if(clause->type == TreatyClauseType::HUMILIATE) {
187  const auto* dyn_clause = static_cast<const TreatyClause::Humiliate*>(clause);
188  on_effect = dyn_clause->in_effect();
189  } else if(clause->type == TreatyClauseType::IMPOSE_POLICIES) {
190  const auto* dyn_clause = static_cast<const TreatyClause::ImposePolicies*>(clause);
191  on_effect = dyn_clause->in_effect();
192  } else if(clause->type == TreatyClauseType::PUPPET) {
193  const auto* dyn_clause = static_cast<const TreatyClause::Puppet*>(clause);
194  on_effect = dyn_clause->in_effect();
195  }
196  if(on_effect) break;
197  }
198  return on_effect;
199 }
bool in_effect() const
Definition: diplomacy.cpp:83
bool in_effect() const
Definition: diplomacy.cpp:64
bool in_effect() const
Definition: diplomacy.cpp:158
Nation::Relation & get_relation(NationId a, NationId b)
Definition: world.hpp:192
static World & get_instance()
Definition: world.hpp:121
bool is_foe(Nation &us, Nation &them)
Definition: diplomacy.cpp:44
bool is_friend(Nation &us, Nation &them)
Definition: diplomacy.cpp:38
float relation
Definition: nation.hpp:75
bool in_effect() const
Definition: diplomacy.cpp:171
bool does_participate(const Nation &nation) const
Definition: diplomacy.cpp:163
World g_world
Definition: world.cpp:59