-
Notifications
You must be signed in to change notification settings - Fork 2
/
Orders.h
274 lines (267 loc) · 8.35 KB
/
Orders.h
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
#pragma once
#include "Player.h"
#include "map.h"
#include <iostream>
#include <vector>
using namespace std;
class Player;
class Territory;
class Map;
/*
This is the header file for the orders
This class has an abstract orderclass and all its children orders [this is so they all fit in the same list]
*/
class Order {
public:
//constructor
Order();
//constructor with the isnull parameter initilized
Order(bool b);
//abstract method for validate
virtual bool validate() = 0;
//abstract method for execute
virtual bool execute() = 0;
//destructor
virtual ~Order();
//copy ocnstructor
Order(const Order&);
//assignment operator
Order& operator = (const Order& o);
//insertion operator
friend ostream& operator << (ostream& out, const Order& o);
//getter method
bool getisnull();
//print method to add polymorphism to operator <<
virtual string print()const = 0;
//setter method
void setisnull(bool b);
private:
//variable to tell if an object is null or an actual order
//nessecary for now as i cant seem to eliminate entries in the array
bool isnull;
};
//order for advancing unit (either for attacking or simply moving to allied territory
class Advanceorder : public Order {
public:
//constructor
Advanceorder();
Advanceorder(int* i, Player* orderp, Territory* destt, Territory* souret, Map* m);
//mehtod to validate if the conditions are met to execute the function
bool validate();
//method to execute the order
bool execute();
//destructor
~Advanceorder();
//sopy constructor
Advanceorder(const Advanceorder& old);
//Map accessor
Map* getMap();
//assignment operator
Advanceorder& operator = (const Advanceorder& o);
//stream insertion operations
friend ostream& operator << (ostream& out, const Advanceorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
// the nubmer of troops to be moved
int* troopnum;
//the territory where the troops are moving from
Territory* sourceterritory;
//the territory they are being asked to go to
Territory* destinationterritory;
//the player that orderd it [important for blockade and making sure they are ordering their own troops]
Player* orderplayer;
Map* map;
string msg;
};
//Airlift order, drops a set number troops into a owned territory from another non or adjacent territory
class Airliftorder : public Order {
public:
//constructor
Airliftorder(int* i, Territory* sourcet, Territory* destinationt, Player* orderp);
//makes sure the terrtories are both owned by the player and the number of troops doest not leave the territory with <1 troops
bool validate ();
//executes the order
bool execute();
//destructor
~Airliftorder();
//copy constructor
Airliftorder(const Airliftorder& old);
//assingmnet operator
Airliftorder& operator = (const Airliftorder& old);
//stream insertion override
friend ostream& operator << (ostream& out, const Airliftorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//# of troops to be moved
int* troopnum;
//territory where troops are being moved from
Territory* sourceterritory;
//territory where the troops are being moved to
Territory* destinationterritory;
//the playter who initiated the order
Player* orderplayer;
string msg;
//may also need a pointer to two Territory objects and a player pointer to make sure the player calling the order is the owner of source
};
//triples army count of owned territory but then turns neutral
class Blockadeorder : public Order {
public:
//constructor
Blockadeorder(Player* orderplayer, Territory* destt);
//makes sure the territory is owned by the player
bool validate();
//executes the order
bool execute();
//destructor
~Blockadeorder();
//copy constructor
Blockadeorder(const Blockadeorder& old);
//assignment operator
Blockadeorder& operator = (const Blockadeorder& old);
//insertion operators
friend ostream& operator << (ostream& out, const Blockadeorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//player who initiated the order
Player* orderplayer;
//territory to be turned neutral
Territory* destinationterritory;
string msg;
};
//country losses half its troops
class Bomborder : public Order {
public:
//constructor
Bomborder(Player* orderp, Territory* destt);
//no real validation, simply halves units rounded down (even if its the players territory)
bool validate();
//executes order
bool execute();
//destructor
~Bomborder();
//copy constructor
Bomborder(const Bomborder& old);
//addignment operator
Bomborder& operator = (const Bomborder& old);
//insertion operators
friend ostream& operator << (ostream& out, const Bomborder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//player who issued the order [may need for console but no validate]
Player* orderplayer;
//territory to be bombed
Territory* destinationterritory;
string msg;
};
//deploys the set ammount of troops the class has to a territory
//currently cant validate but needs to check the num of available troops
class Deployorder : public Order {
public:
//constructor
Deployorder(Player* orderp, int* troopnum, Territory* destt);
//makes sure the player owns the territory and that the ammount oftroops palced does not exceed the mamount that he has
bool validate();
//execute order
bool execute();
//destructor
~Deployorder();
//copy constructor
Deployorder(const Deployorder& old);
//assignment operator
Deployorder& operator = (const Deployorder& old);
//insertion operators
friend ostream& operator << (ostream& out, const Deployorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//player who issued the order
Player* orderplayer;
//ammount of troops to be placed
int* troopnum;
//territory to recieve troops
Territory* destinationterritory;
string msg;
};
//prevents battles between two players (will need to be added to some orders or player class)
class Negotiateorder : public Order {
public:
//constructor
Negotiateorder(Player* orderp, Player* destp);
//makes sure the two players are not the same player
bool validate();
//exectues order
bool execute();
//destructor
~Negotiateorder();
//copy constructor
Negotiateorder(const Negotiateorder& old);
//assignment operator
Negotiateorder& operator = (const Negotiateorder& old);
//insertion opperators
friend ostream& operator << (ostream& out, const Negotiateorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//player who issued the order
Player* orderplayer;
//player to be targeted for negotiation
Player* otherplayer;
string msg;
};
//gives the player 5 armies to deploy [needs to be instant and the player needs an ammount of troops]
class Reinforcementorder : public Order {
public:
//constructor
Reinforcementorder(Player* orderp);
//no validation required
bool validate();
//excecutes order
bool execute();
//destructor
~Reinforcementorder();
//copy constructor
Reinforcementorder(const Reinforcementorder& old);
//assignment operator
Reinforcementorder& operator = (const Reinforcementorder& old);
//insertion operator
friend ostream& operator << (ostream& out, const Reinforcementorder& o);
//print method to add polymorphism to operator <<
string print()const;
private:
//player hwo issued the order
Player* orderplayer;
string msg;
};
/*
Class orderlist
holds a list of orders and is able to execute the order, move them around, remove them and add them.
using a pointer to an object array but uncertain will check if this makes sense later
*/
class Orderlist {
public:
//constructor
Orderlist();
//destructor
~Orderlist();
// copy constructor
Orderlist(const Orderlist& ol);
//assignment operator
Orderlist& operator = (const Orderlist& o);
// insertion stream operator
friend ostream& operator << (ostream& stream, Orderlist& o);
// basic remove, move and add functions
bool remove(int i);
bool move(int i, int location);
void add(Order* o);
//executes all orders in the lsit and then removes them
void executelist();
//returns the actual list
vector<Order*>* retirevelist();
private:
//pointer to vector of order pointers
vector<Order*>* ptr;
};