-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit.hpp
More file actions
195 lines (163 loc) · 5.76 KB
/
unit.hpp
File metadata and controls
195 lines (163 loc) · 5.76 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
187
188
189
190
191
192
193
194
195
#ifndef UNIT_HPP
#define UNIT_HPP
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <memory>
#include <random>
#include <functional>
#include "gamevars.hpp"
#include "file.hpp"
#include "gfxobject.hpp"
#include "path.hpp"
namespace TerraNova {
struct MoveCostTable {
int base = 1;
int aquatic = -1;
int wooded = 1;
int hilly = 1;
int cold = 1;
};
// should also have support for orders with targets (different struct maybe?)
struct Order {
std::string name;
std::function<void()> func;
Order(const std::string& name, std::function<void()> func):
name(name), func(func){}
//Order(const char* name, void (*func)()): name(std::string(name)), func(func){}
};
class AttackType {
const std::string name;
const float accuracy;
const int attackRate;
const int damage;
public:
AttackType() = delete;
AttackType(const std::string& name, const float accuracy,
const int attackRate, const int damage): name(name),
accuracy(accuracy), attackRate(attackRate), damage(damage) {}
std::string Name() const {return name;}
std::string PathName() const {return File::PathifyString(name);}
float Accuracy() const {return accuracy;}
int AttackRate() const {return attackRate;}
int Damage() const {return damage;}
std::string DamageType() const {return "ballistic";}
};
class UnitType {
public:
// ultimately we want to construct this from a line of text as std::string
UnitType() = delete;
UnitType(const std::string& name, const int maxHealth,
const int moveSpeed,
const std::vector<std::shared_ptr<AttackType>>& attacks,
const int trainingTime):
name(name), maxHealth(maxHealth), moveSpeed(moveSpeed),
attacks(attacks), trainingTime(trainingTime) {}
const std::string& Name() const {return name;}
std::string PathName() const {return File::PathifyString(name);}
int MaxHealth() const {return maxHealth;}
int MoveSpeed() const {return moveSpeed;}
MoveCostTable MoveCosts() const {return moveCosts;}
int TrainingTime() const {return trainingTime;}
bool CanRespec() const {return canRespec;}
void SetCanRespec(const bool val) {canRespec = val;}
std::vector<std::shared_ptr<AttackType>> Attacks() const {return attacks;}
std::shared_ptr<AttackType> Attack(const int num) const
{if(num >= (int)attacks.size()) return nullptr; return attacks[num];}
private:
const std::string name;
const int maxHealth;
const int moveSpeed;
const MoveCostTable moveCosts;
const std::vector<std::shared_ptr<AttackType>> attacks;
const int trainingTime;
bool canRespec = true;
};
class Unit : public GFXObject {
std::shared_ptr<Sprite> healthBackground;
std::shared_ptr<Sprite> healthBar;
std::string givenName;
std::string surname;
bool female;
std::shared_ptr<UnitType> spec;
bool unique = false;
int health;
int movesLeft;
std::vector<std::string> inventory;
char faction;
std::array<unsigned int, 2> location;
std::unique_ptr<Path> myPath;
order_t orders = ORDER_PATROL;
std::shared_ptr<Sprite> orderIcon;
//std::vector<Order> availableOrders;
void Die();
static std::string GenerateGivenName();
static std::string GenerateSurname();
public:
Unit() = delete;
Unit(SDL_Renderer* ren,
const std::shared_ptr<UnitType> spec, const char faction);
Unit(const Unit& other) = delete;
Unit& operator=(const Unit other) = delete;
void ChangeName(const std::string givenName, const std::string surname);
void ChangeName(const std::string fullName);
void ChangeGender(const std::string gender);
void ChangeSpec(const std::shared_ptr<UnitType> spec);
bool TakeDamage(const int damage); // false = survived
bool Dead() const { return health <= 0; }
bool IsUnit() const { return true; }
void BeConsumed();
void MoveSpriteToTile(const int X, const int Y, const int W, const int H);
void Render() const;
void ProcessTurn();
std::string Name() const;
std::string GivenName() const;
std::string Surname() const;
std::string Species() const;
std::string Gender() const;
std::string NomPronoun()const;
std::string NomPronCap()const;
std::string AccPronoun()const;
std::string AccPronCap()const;
std::string PosPronoun()const;
std::string PosPronCap()const;
std::shared_ptr<UnitType> Spec() const;
int MaxHealth() const;
int Health() const;
std::vector<std::string> Inventory() const;
void AddItem(const std::string item);
int MoveSpeed() const;
int MovesLeft() const;
void SetLocation(const unsigned int row, const unsigned int colm,
const bool usesMove);
std::array<unsigned int, 2> Location() const;
int Row() const;
int Colm() const;
Path* CurrentPath() const { return myPath.get(); }
std::array<unsigned int, 2> NextStep();
bool AdvancePath();
MoveCostTable MoveCosts() const {return spec->MoveCosts(); }
order_t Orders() const { return orders; }
void SetOrders(const order_t newOrders);
void OrderMove(std::unique_ptr<Path> newPath);
void OrderPatrol();
void OrderHarvest();
//std::shared_ptr<Colony> OrderFoundColony();
// below function is not const because the buttons can make *this act
std::vector<Order> AvailableOrders();
void MarkUnique() {unique = true;}
bool Unique() const {return unique;}
bool CanRespec() const {return spec->CanRespec();}
char Faction() const {return faction;}
std::vector<std::shared_ptr<AttackType>> Attacks() const;
int Damage(const unsigned int num = 0) const;
float Accuracy(const unsigned int num = 0) const;
int AttackRate(const unsigned int num = 0) const;
std::string DamageType(const unsigned int num = 0) const;
bool CanAttack() const { return Attacks().size() > 0; }
bool Attack(Unit* target) const;
static void Fight(Unit* attacker, Unit* target);
};
} // namespace TerraNova
#endif