blob: 242ff89fb5f034125b05c66c83f3a7dae32bec67 (
plain)
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
|
#pragma once
#include "Component.h"
#include "types.h"
namespace crepe {
class AI : public Component {
public:
enum BehaviorType {
NONE = 0x00000,
SEEK = 0x00002,
FLEE = 0x00004,
ARRIVE = 0x00008,
PATH_FOLLOW = 0x00010,
};
public:
AI(game_object_id_t id, float mass, float max_speed, float max_force);
bool on(BehaviorType behavior) const { return (flags & behavior) == behavior; }
void seek_on() { flags |= SEEK; }
void seek_off() {
if (on(SEEK)) flags ^= SEEK;
}
void flee_on() { flags |= FLEE; }
void flee_off() {
if (on(FLEE)) flags ^= FLEE;
}
void arrive_on() { flags |= ARRIVE; }
void arrive_off() {
if (on(ARRIVE)) flags ^= ARRIVE;
}
void path_follow_on() { flags |= PATH_FOLLOW; }
void path_follow_off() {
if (on(PATH_FOLLOW)) flags ^= PATH_FOLLOW;
}
public:
float mass;
float max_speed;
float max_force;
// The target to seek or arrive at
vec2 seek_target;
// The target to flee from
vec2 flee_target;
// The distance at which the entity will start to flee from the target
float square_flee_panic_distance = 100.0f * 100.0f;
// The deceleration rate for the arrive behavior (higher values will make the entity decelerate faster (less overshoot))
float arrive_deceleration = 2.0f;
private:
vec2 velocity;
friend class AISystem;
int flags = 0;
};
} // namespace crepe
|