aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/AI.h
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-12-04 13:46:41 +0100
committermax-001 <maxsmits21@kpnmail.nl>2024-12-04 13:46:41 +0100
commitf9f5600b60d6944dc9a7dd502988703d59d0cd62 (patch)
tree4f6d7cfe7e15bf0fd3b838769cb2a093de487ba6 /src/crepe/api/AI.h
parentac87bfad20e1bcf1fd066a4eda231608fe12f504 (diff)
Setup some behaviors
Diffstat (limited to 'src/crepe/api/AI.h')
-rw-r--r--src/crepe/api/AI.h47
1 files changed, 43 insertions, 4 deletions
diff --git a/src/crepe/api/AI.h b/src/crepe/api/AI.h
index b755439..faeeba5 100644
--- a/src/crepe/api/AI.h
+++ b/src/crepe/api/AI.h
@@ -7,12 +7,51 @@ namespace crepe {
class AI : public Component {
public:
- AI(game_object_id_t id, double mass, double max_speed, double max_force);
+ enum BehaviorType {
+ NONE = 0x00000,
+ SEEK = 0x00002,
+ FLEE = 0x00004,
+ ARRIVE = 0x00008,
+ PATH_FOLLOW = 0x00010,
+ };
public:
- double mass;
- double max_speed;
- double max_force;
+ 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:
+ int flags = 0;
};
} // namespace crepe