Deep RTS
Player.h
Go to the documentation of this file.
1//
2// Created by Per-Arne on 24.02.2017.
3//
4
5#ifndef WARC2SIM_PLAYER_H
6#define WARC2SIM_PLAYER_H
7
8#include <string>
9#include <vector>
10#include <memory>
11#include <deque>
12#include <cmath>
13#include "unit/Unit.h"
14#include "Tile.h"
15#include "Config.h"
16
17class Game;
18class Player {
19private:
20
22 Game &game_;
23
24private:
25 void spawnPlayer();
26
28 int id_;
29
31 std::string name = "[NO NAME]";
32
34 int _getNextPrevUnitIdx();
35
37 int faction; // 0 = Human, 1 = Orc
38
44
46 int targetedUnitID = -1;
47
49 bool defeated = false;
50
52 void nextUnit();
53
55 void previousUnit();
56
57
58
59public:
60 const Config &config;
61
64 std::vector<int> unitIndexes;
65
67 Player(Game &game, int id);
68
69
75
77 void setName(std::string name);
78
80 void setTargetedUnitID(int targetedUnitID);
81
87
89 [[nodiscard]] Game &getGame() const;
90
92 [[nodiscard]] int getId() const;
93
95 [[maybe_unused]] [[nodiscard]] int getFoodConsumption() const;
96
97 [[maybe_unused]]
98 [[nodiscard]] int getFood() const;
99
101 [[maybe_unused]] [[nodiscard]] int getGold() const;
102
104 [[maybe_unused]] [[nodiscard]] int getStone() const;
105
107 [[maybe_unused]] [[nodiscard]] int getLumber() const;
108
109 [[nodiscard]] virtual
110 int getScore() const;
111
113 [[maybe_unused]] [[nodiscard]] int getUnitCount() const;
114
117
119 [[nodiscard]] int getTargetedUnitID() const;
120
121 virtual
123
125 [[nodiscard]] const std::string &getName() const;
126
127
133
135 Unit &addUnit(Constants::Unit unitType);
136
137 //
138 Unit &spawnUnit(Unit &unit, Tile &tile, int select);
139
141 void removeUnit(Unit & unit);
142
144 Unit &spawn(Tile &spawnPoint);
145
147 void reset();
148
150 void removeGold(int n);
151
153 void removeLumber(int n);
154
156 void removeStone(int n);
157
159 void addGold(int n);
160
162 void addLumber(int n);
163
165 void addStone(int n);
166
172 int stone = 0;
173 int gold = 0;
174 int lumber = 0;
176 int food = 0;
177
179 int num_archer = 0;
180 int num_peasant = 0;
181 int num_footman = 0;
183 int num_farm = 0;
184 int num_barrack = 0;
185
194 int sDamageDone = 0;
197
198
199 void do_action(int actionID);
200 void do_manual_action(int manual_action_id, int x, int y);
201
202 void leftClick(int x, int y);
203 void rightClick(int x, int y);
204
206 bool canPlace(Unit & builder, Unit & unit, Tile &tile);
207 bool canAfford(Unit & unit) const;
208
209
210
211};
212
213
214#endif //WARC2SIM_PLAYER_H
Definition: Config.h:8
Definition: Game.h:23
Definition: Player.h:18
int num_footman
Definition: Player.h:181
Unit & spawnUnit(Unit &unit, Tile &tile, int select)
Definition: Player.cpp:52
int num_barrack
Definition: Player.h:184
int stone
Definition: Player.h:172
int sDamageTaken
Definition: Player.h:195
void reset()
Reset the player state.
Definition: Player.cpp:64
const Config & config
Definition: Player.h:60
bool canPlace(Unit &builder, Unit &unit, Tile &tile)
TODO move these to Unit.h?
Definition: Player.cpp:227
int gold
Definition: Player.h:173
std::vector< int > unitIndexes
List of all unit Ids belonging to this player. The object itself is located in Game class units list.
Definition: Player.h:64
int foodConsumption
Definition: Player.h:175
void removeStone(int n)
Remove N oil from the player.
Definition: Player.cpp:264
int lumber
Definition: Player.h:174
void setTargetedUnitID(int targetedUnitID)
Select a unit.
Definition: Player.cpp:493
Game & getGame() const
Get the game instance.
Definition: Player.cpp:481
int num_peasant
Definition: Player.h:180
int num_archer
Counters for buildings.
Definition: Player.h:179
const std::string & getName() const
Get the player name.
Definition: Player.cpp:485
Unit * getTargetedUnit()
Get the targeted unit (Returns null if none)
Definition: Player.cpp:344
int getUnitCount() const
Get the unit count for this player.
Definition: Player.cpp:148
Unit & addUnit(Constants::Unit unitType)
Add a unit to the player.
Definition: Player.cpp:247
Player(Game &game, int id)
Constructor.
Definition: Player.cpp:13
int getId() const
Get Player's ID.
Definition: Player.cpp:152
bool canAfford(Unit &unit) const
Definition: Player.cpp:242
int getTargetedUnitID() const
Get the targeted unit ID (-1 if none)
Definition: Player.cpp:489
void spawnUnitNearSpawnPoint(Constants::Unit unitType)
Definition: Player.cpp:114
void addGold(int n)
Add N gold to the player.
Definition: Player.cpp:156
int food
Definition: Player.h:176
int sGatheredGold
Definition: Player.h:191
int sGatheredLumber
Definition: Player.h:192
Unit & spawn(Tile &spawnPoint)
Spawns a unit on a tile.
Definition: Player.cpp:31
int getFood() const
Get Max Food.
Definition: Player.cpp:132
void setName(std::string name)
Set the name of the player.
Definition: Player.cpp:276
int getFoodConsumption() const
Get the food consumption.
Definition: Player.cpp:128
virtual Constants::PlayerState playerState()
Check if player is defeated.
Definition: Player.cpp:208
int sGatheredStone
Definition: Player.h:193
void addLumber(int n)
Add N lumber to the player.
Definition: Player.cpp:160
void removeGold(int n)
Remove N gold from the player.
Definition: Player.cpp:272
void leftClick(int x, int y)
Definition: Player.cpp:352
int num_farm
Definition: Player.h:183
virtual int getScore() const
Get the score.
Definition: Player.cpp:168
void addStone(int n)
Add N oil to the player.
Definition: Player.cpp:164
int getLumber() const
Get the lumber resource.
Definition: Player.cpp:144
void do_action(int actionID)
Definition: Player.cpp:389
void do_manual_action(int manual_action_id, int x, int y)
Definition: Player.cpp:376
int sDamageDone
Definition: Player.h:194
int getStone() const
Get the oil resource.
Definition: Player.cpp:140
int sUnitsCreated
Definition: Player.h:196
void removeUnit(Unit &unit)
Removes a unit from the player.
Definition: Player.cpp:188
void rightClick(int x, int y)
Definition: Player.cpp:363
void removeLumber(int n)
Remove N lumber from the player.
Definition: Player.cpp:268
int num_town_hall
Definition: Player.h:182
int getGold() const
Get the gold resource.
Definition: Player.cpp:136
Definition: Tile.h:21
Definition: Unit.h:25
PlayerState
Definition: Constants.h:39
Unit
Definition: Constants.h:20