Repository navigation
Expand file tree
/
Copy pathClass.cpp
More file actions
187 lines (186 loc) · 3.68 KB
/
Copy pathClass.cpp
File metadata and controls
187 lines (186 loc) · 3.68 KB
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
#include "Class.h"
#include "Manage.h"
#include <iostream>
#include <vector>
#include <iostream>
int Res::res_count = 0;
int Sight::sight_count = 0;
State::State()
{
this->defence = 0;
this->common_defence = &(this->defence);
}
void State::setName(std::string name)
{
this->name = name;
}
void State::setPopulation(int pop)
{
this->population = pop;
}
void State::setGDP(int gdp)
{
this->GDP = gdp;
}
void State::setID(int id)
{
this->ID = id;
}
void State::setDefence(int d)
{
this->defence = d;
//this->common_defence = &this->defence;
}
std::string State::getName()
{
return this->name;
}
int State::getPopulation()
{
return this->population;
}
int State::getGDP()
{
return this->GDP;
}
int State::getID()
{
return this->ID;
}
int State::getDefence()
{
return this->defence;
}
bool State::Vote()
{
return rand()%2;
}
Org::Org(){}
Org::Org(std::string name)
{
this->name = name;
}
void Org::setName(std::string name)
{
this->name = name;
}
std::string Org::getName()
{
return this->name;
}
Org::Org(State* s)
{
this->state[s->getID()] = s;
}
void Org::joinState(State* s)
{
std::map<int,State*>::iterator it;
it = this->state.find(s->getID());
if (it == this->state.end())
{
this->state[s->getID()] = s;
}
}
void Org::kickState(int i)
{
std::map<int,State*>::iterator it;
it = this->state.find(i);
if (it != this->state.end())
{
this->state.erase(it);
}
}
bool Org::checkState(int id)
{
std::map<int,State*>::iterator it;
it = this->state.find(id);
if (it != this->state.end())
{
return true;
}
return false;
}
std::map<int,State*> Org::getAllStates()
{
return this->state;
}
UN::UN():Org::Org(){}
UN::UN(std::string name):Org::Org(name) {}
void UN::addRes(Res* resol)
{
this->res.push_back(resol);
}
std::vector<Res*> UN::getAllRes()
{
return this->res;
}
Unesco::Unesco(std::string name):UN::UN(name){}
void Unesco::joinSight(Sight* s)
{
this->sights.push_back(s);
}
Alliance::Alliance():Org::Org(){this->defence = 0;}
Alliance::Alliance(std::string name):Org(name)
{
this->defence = 0;
}
void Alliance::joinState(State* s)
{
std::map<int,State*>::iterator it;
it = this->state.find(s->getID());
if (it == this->state.end())
{
this->state[s->getID()] = s;
this->defence += *(s->common_defence);
s->common_defence = &this->defence;
}
}
int Alliance::getDefence()
{
return this->defence;
}
void Alliance::kickState(int id)
{
std::map<int,State*>::iterator it;
it = this->state.find(id);
if (it != this->state.end())
{
this->defence = this->defence - (this->state[id])->defence;
(this->state[id])->common_defence = &(this->state[id]->defence);
this->state.erase(it);
}
}
Alliance::~Alliance()
{
std::map<int,State*>::iterator it;
for(it = this->state.begin(); it != this->state.end(); it++)
{
int id = it->second->getID();
this->kickState(id);
}
}
TradeOrg::TradeOrg():Org::Org(){}
TradeOrg::TradeOrg(std::string name,double growth):Org::Org(name){this->growth = growth;}
void TradeOrg::joinState(State* s)
{
std::map<int,State*>::iterator it;
it = this->state.find(s->getID());
if (it == this->state.end())
{
this->state[s->getID()] = s;
double gdp = s->getGDP() * this->growth;
s->setGDP((int)gdp);
}
}
void TradeOrg::kickState(int id)
{
std::map<int,State*>::iterator it;
it = this->state.find(id);
if (it != this->state.end())
{
int gdp = it->second->getGDP();
it->second->setGDP((int)(gdp/this->growth));
this->state.erase(it);
}
}
SC::SC(std::string name):UN::UN(name){}