-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaiplayer.hpp
executable file
·165 lines (115 loc) · 3.19 KB
/
aiplayer.hpp
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
#ifndef AIPLAYER_HPP
#define AIPLAYER_HPP
#include "aipathfinding.hpp"
#include "player.hpp"
#include <stack>
#include <queue>
#include <vector>
class AIPlayer:public Player
{
public:
AIPlayer(
float x,
float y,
ShipType *type,
team_type newTeam);
virtual ~AIPlayer();
std::string nextCommand;
std::string deathTrigger;
void timepass(void);
void die(int killer);
inline void setState(ai_state state)
{ aiState = state; }
inline ai_state getState() const
{ return aiState; }
inline ai_role getRole() const
{ return aiRole; }
/*void setStopAtNextGoal(bool stopAtNextGoal)
{ shouldStopAtGoal = stopAtNextGoal; }*/
//void setGoal(WaypointMarker *destination);
//void setGoal(const Position &destination);
int getCollisionEffect(void);
bool isHuman(void) { return false; }
/*void setNewGoal(WaypointMarker *destination);
void setNewGoal(const Position &destination);*/
void updateOldGoal();
virtual bool isTurret() = 0;
//indicates that the bot currently has no target
static const int noTarget;
//acceptable range of error for angle calculations, to minimize "wiggling"
static const float angleErrorRange;
protected:
ai_state aiState;
ai_role aiRole;
ai_steering_state aiSteeringState;
Position targetPosition;
int targetID;
float aimOffsetX, aimOffsetY;
bool canAttack;
virtual void runAI() = 0;
void updateTargetPosition();
int getBestTargetID() const;
bool hasTarget();
bool isEntityValid(Entity *ent) const;
bool isEntityVisible(Entity *ent) const;
bool isEntityInRange(Entity *ent) const;
bool shouldFaceTarget() const;
void attackTarget(Entity *target);
Position getPredictedTargetPosition();
//returns the distance squared between a destination and the bot
float distSquaredTo(const Position &destination) const;
AISteering steering;
float shotInaccuracy;
};
class AIShip:public AIPlayer
{
public:
AIShip(
float x,
float y,
ShipType *type,
team_type newTeam);
~AIShip();
void setNewGoal(WaypointMarker *destination);
void setNewGoal(const Position &destination);
void updateOldGoal();
bool isTurret() { return false; }
void setStopAtNextGoal(bool stopAtNextGoal)
{ shouldStopAtGoal = stopAtNextGoal; }
protected:
bool shouldStopAtGoal;
Position oldGoal;
Position currentGoal;
WaypointMarker *oldTargetWaypoint;
void updateGoal();
void runAI();
void roam();
void chase();
void stop();
//int getBestTargetID() const;
float rateEntity(Entity *ent);
//bool hasTarget();
bool isEntityValid(Entity *ent) const;
//bool shouldFaceTarget() const;
bool isNearNextWaypoint() const;
bool isCloseToGoal();
//used to determine roaming goals
bool isNextWaypointFarEnough() const;
WaypointMarker *getNearestWaypoint() const;
WaypointMarker *getRandomGoalFrom(WaypointMarker *source) const;
AIPathfinding pathfinding;
};
class AITurret:public AIPlayer
{
public:
AITurret(
float x,
float y,
ShipType *type,
team_type newTeam);
~AITurret();
bool isTurret() { return true; }
protected:
void runAI();
};
#endif //AIPLAYER_HPP