-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGovernment.cpp
323 lines (269 loc) · 7.25 KB
/
Government.cpp
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#pragma once
#ifndef WORLDSIM_GOVERNMENT_CPP
#define WORLDSIM_GOVERNMENT_CPP
/* WorldSim: Government.cpp
#include "Government.cpp"
The government controls executive decisions of a Settlement and/or Civ
*/
#include "Government.hpp"
#include "Settlement.hpp"
// Government_Position definitions
Government_Position::Government_Position(Government* _government) : government(_government)
{
character = nullptr;
}
Government_Position::Government_Position(const Government_Position& other)
: government(other.government), character(other.character)
{
}
Government_Position& Government_Position::operator=(const Government_Position& other)
{
if (this != &other)
{
government = other.government;
character = other.character;
}
return *this;
}
bool Government_Position::operator==(const Character* otherCharacter) const
{
return character == otherCharacter;
}
void Government_Position::assign(Character* _character)
{
character = _character;
}
bool Government_Position::empty()
{
return (character == nullptr);
}
// Government_Leader definitions
Government_Leader::Government_Leader(Government* _government) : Government_Position(_government)
{
}
void Government_Leader::governDaily()
{
if ( globalRandom.rand8(DAYS_PER_MONTH/4) == 0 )
{
if (government == nullptr || government->governedSettlement == nullptr)
{
return;
}
Settlement* s = government->governedSettlement;
Stockpile* stockpile = &(s->stockpile);
ItemRequestManager* requestManager = &(s->requestManager);
Stockpile* resourceManager = &(s->stockpile);
if (empty())
{
//std::cout << "There is no king\n";
return;
}
//std::cout << "King is kinging.\n";
if ( character->isAlive==false)
{
//std::cout<<"King is dead\n";
}
if (character->vIdea.size() > 0 && s!=0)
{
for (int i=0;i<character->vIdea.size();++i)
{
if (!s->hasIdea(character->vIdea(i)))
{
s->giveIdea(character->vIdea(i));
//std::cout<<"King has implemented an idea as a tech\n";
character->vIdea.removeSlot(i);
// limit 1 idea implemented per turn.
break;
}
}
}
// BUILDING
if ( s->getMiningCapacity() < s->getPopulation()/3 )
{
//std::cout<<"Leader building a mine\n";
//s->location.addLocation(LOCATION_MINE);
}
if ( s->getFarmingCapacity() < s->getPopulation()/2 )
{
//std::cout<<"Leader building a farm\n";
//s->location.addLocation(LOCATION_FARM);
}
if ( s->has(LOCATION_WEAPONSMITH) == false
&& s->canBuild(LOCATION_WEAPONSMITH) )
{
s->location.addLocation(LOCATION_WEAPONSMITH);
}
// PRODUCTION
// Put in any public production orders
// requestManager->removeAll(resourceManager,ITEM_HOE);
// if ( resourceManager->getMoney() > 0 )
// {
// int hoeShortfall = (s->vCharacter.size()/3) - stockpile->getNumberOfItems(ITEM_HOE);
// int marketValue = requestManager->getAverageValue(ITEM_HOE) + 1;
// for (int i=0;i<hoeShortfall/2;++i)
// {
// int amountCanPay = resourceManager->getMoney();
// if (marketValue < amountCanPay)
// {
// amountCanPay = marketValue;
// }
// //requestManager->add(this,ITEM_HOE,marketValue,false);
// std::cout<<"Request for hoe at price of "<<amountCanPay<<".\n";
// if ( resourceManager->getMoney() == 0 )
// {
// break;
// }
// }
// }
// Money distribution:
// The treasury aims to hold 10% of all money, any excess is given out at a rate of 10% per turn.
if (s != nullptr)
{
//std::cout << "King distribute money\n";
// Calculate the total money in the settlement's treasury
int treasuryMoney = s->stockpile.getMoney();
int totalSettlementMoney = s->getAllMoneyInSettlement();
// Check if the treasury holds more than 20% of total money in the settlement
if (static_cast<double>(treasuryMoney) / totalSettlementMoney > 0.2)
{
// Calculate the amount to distribute (e.g., 10% of the treasury money)
int amountToDistribute = treasuryMoney * 0.1;
//int amountToDistribute = treasuryMoney;
//std::cout<<"King distributed "<<amountToDistribute<<" coins.\n";
// Distribute the calculated amount
while (amountToDistribute > 0)
{
Character* c = s->getRandomCharacter();
if (s->stockpile.takeMoney(1))
{
c->giveMoney(1);
amountToDistribute -= 1;
}
else
{
// Break the loop if there's not enough money left to distribute
break;
}
}
}
}
}
}
// Put requested items into stockpile
void Government_Leader::recieveRequestedItem(Item* item)
{
if (government == nullptr || government->governedSettlement == nullptr)
{
return;
}
Settlement* s = government->governedSettlement;
Stockpile* stockpile = &(s->stockpile);
if (s != nullptr)
{
stockpile->add(item);
}
}
// Government_Scribe definitions
Government_Scribe::Government_Scribe(Government* _government) : Government_Position(_government)
{
}
void Government_Scribe::governDaily()
{
if (empty())
{
//std::cout << "There is no scribe\n";
return;
}
//std::cout << "Scribe is scribing.\n";
if (character->vIdea.size() > 0 && government->governedSettlement!=0)
{
for (int i=0;i<character->vIdea.size();++i)
{
if (!government->governedSettlement->hasIdea(character->vIdea(i)))
{
government->governedSettlement->giveIdea(character->vIdea(i));
//std::cout<<"Scribe has implemented an idea as a tech\n";
character->vIdea.removeSlot(i);
// limit 1 idea implemented per turn.
return;
}
}
}
// book production goes here.
}
// Government_Captain definitions
Government_Captain::Government_Captain(Government* _government) : Government_Position(_government)
{
}
void Government_Captain::governDaily()
{
if (empty())
{
//std::cout << "There is no captain\n";
return;
}
//std::cout << "Captain is capping.\n";
if (character->vIdea.size() > 0 && government->governedSettlement!=0)
{
for (int i=0;i<character->vIdea.size();++i)
{
if (!government->governedSettlement->hasIdea(character->vIdea(i)))
{
government->governedSettlement->giveIdea(character->vIdea(i));
//std::cout<<"Captain has implemented an idea as a tech\n";
character->vIdea.removeSlot(i);
// limit 1 idea implemented per turn.
return;
}
}
}
// military stuff goes here
}
// Government definitions
Government::Government() : leader(this), scribe(this), captain(this)
{
governedSettlement=0;
}
Government::Government(const Government& other)
: governedSettlement(other.governedSettlement), leader(this), scribe(this), captain(this)
{
}
Government& Government::operator=(const Government& other)
{
if (this != &other)
{
governedSettlement = other.governedSettlement;
setLeader(other.leader.character);
setScribe(other.scribe.character);
setCaptain(other.captain.character);
}
return *this;
}
void Government::governDaily()
{
if ( globalRandom.rand8(DAYS_PER_MONTH/4) == 0 )
{
//std::cout<<"Government:\n";
leader.governDaily();
scribe.governDaily();
captain.governDaily();
//std::cout<<"\n";
}
}
bool Government::needsLeader()
{
return leader.empty();
}
void Government::setLeader(Character* character)
{
leader.assign(character);
}
void Government::setScribe(Character* character)
{
scribe.assign(character);
}
void Government::setCaptain(Character* character)
{
captain.assign(character);
}
#endif // WORLDSIM_GOVERNMENT_CPP