-
Notifications
You must be signed in to change notification settings - Fork 2
/
agent.h
163 lines (115 loc) · 4.74 KB
/
agent.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
#ifndef AGENT_H
#define AGENT_H
#include <vector>
#include "SFML/Graphics.hpp"
#include "agent_type.h"
//Forward declaration
class game;
class tile;
/// Logic of an agent; something that moves on the tiles
class agent {
public:
/// Constructor
/// @param x the x-coordinat of the top-left corner of the agent
/// @param y the y-coordinat of the top-left corner of the agent
/// @param type the type the tile
explicit agent(const agent_type type, const double x = 0.0, const double y = 0.0,
const double health = 1.0, const double direction = 0.0,
std::vector<agent_type> prey = std::vector<agent_type>());
std::vector<agent> process_events(game &g);
/// Get the tick at which the agent became a corpse
int get_corpse_ticks() const noexcept { return corpse_ticks; }
/// The type the tile
agent_type get_type() const noexcept { return m_type; }
double get_health() const noexcept { return m_health; }
double get_stamina() const noexcept { return m_stamina; }
/// The x-coordinat of the top-left corner of the agent
double get_x() const noexcept { return m_x; }
/// The y-coordinat of the top-left corner of the agent
double get_y() const noexcept { return m_y; }
/// The direction angle of the agent
double get_direction() const noexcept { return m_direction; }
void set_x(double x) noexcept { m_x = x; }
void set_y(double y) noexcept { m_y = y; }
void set_direction(double direction) noexcept { m_direction = direction; }
void set_health(double health) noexcept { m_health = health; }
sf::Vector2f get_center(const sf::Texture& sprite) const;
void move(double x, double y);
bool is_clicked(const double x, const double y, const sf::Texture& sprite) const noexcept;
/// Make this agent eat other agents
void eat(game& g);
bool is_in_range(double x, double y, double range);
/// Find the nearest agent
/// @param g the game logic, contains the other agents
agent nearest_agent(const game& g, agent& a, agent_type type);
///Moves the agent. It will do nothing if exhausted.
///If it has stamina, the agent will go looking for food
///@param game the game logic
void move(game& g);
void attract_to_agent(game& g, agent_type type);
std::vector <agent> reproduce_agents(game& g, agent_type type);
void find_destination(game &g);
private:
/// The type the tile
agent_type m_type;
/// The x-coordinat of the top-left corner of the agent
double m_x;
/// The y-coordinat of the top-left corner of the agent
double m_y;
/// The direction angle of the agent:
///
/// 0.5 * pi
/// |
/// |
/// 1.0 * pi ----+---- 0.0 * pi
/// |
/// |
/// 1.5 * pi
///
/// For example, for an m_direction of 1.5 pi, the agent moves down
double m_direction;
/// The health of the agent
double m_health;
///the stamina of the agent
double m_stamina;
int corpse_ticks = -1;
/// The types of agents this agent can eat
/// Added as a result of profiling
std::vector<agent_type> m_prey;
/// Motivation for a certain horizontal velocity
/// Added due to profiling results, see Issue #543
double m_dx_motivation = 0;
/// Motivation for a certain horizontal velocity
/// Added due to profiling results, see Issue #543
double m_dy_motivation = 0;
void damage_own_type(game &g, agent_type type);
std::vector<agent> destination;
friend std::ostream& operator<<(std::ostream& os, const agent& a) noexcept;
friend std::istream& operator>>(std::istream& is, agent& a);
friend bool operator==(const agent& lhs, const agent& rhs) noexcept;
};
double get_agent_reproduction_health(const agent_type t) noexcept;
std::vector<agent_type> can_eat(const agent_type type);
std::vector<agent> create_default_agents() noexcept;
void move_agent_to_tile(agent &a, double tile_x, double tile_y);
/// Will the agent drown in water with a certain depth
/// For example, a fish will down at a depth beyond 50;
/// only a whale can survive at a depth of 100
/// @param at the agent type
/// @param depth the depth at which the agent will or will not survive
bool will_drown(agent_type at, const int depth);
/// Determine if the agent_type is a plant
/// @return true if the agent_type is a plant
/// @note plankton is counted as plants, but do include small animals as well
bool is_plant(const agent_type type) noexcept;
//
int get_min_depth(agent_type a);
int get_max_depth(agent_type a);
/// Get the range at which the agent can survive
sf::Vector2i get_depth_range(agent_type a);
/// Test the tile class
void test_agent();
bool operator==(const agent& lhs, const agent& rhs) noexcept;
std::ostream& operator<<(std::ostream& os, const agent& a) noexcept;
std::istream& operator>>(std::istream& is, agent& a);
#endif // TILE_H