summary refs log tree commit diff stats
path: root/src/components
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-03 14:41:01 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-03 14:41:01 -0400
commit83f51a6892629921b4cc482b986656a0a5cc5f6a (patch)
tree50dcd4485a165b29591dafbec907c20dcf9284b1 /src/components
parentb2311e1ba43a72a205b51a24376a1f363faa569e (diff)
downloadtherapy-83f51a6892629921b4cc482b986656a0a5cc5f6a.tar.gz
therapy-83f51a6892629921b4cc482b986656a0a5cc5f6a.tar.bz2
therapy-83f51a6892629921b4cc482b986656a0a5cc5f6a.zip
Added simple AI implementation
The new AutomatingSystem and AutomatableComponent are responsible for simple AI tasks. This currently is limited to moving entities at a certain speed for certain periods of time. These tasks are arranged as a set of behaviors, which are picked randomly when automation starts or when a behavior finishes executing. A behavior is a sequence of actions that run one after another.

Currently, if an automated entity is blocked from moving by a collision, it will be coerced out of its intended path. This is because the automation parameters are stored as a speed and a duration, rather than a starting location and an ending location. This may end up being changed, or made configurable, as this is an early implementation of this feature and will need to be more complex later.

Added an RNG object to the Game class, so that the AutomatingSystem can pick behaviors at random.
Diffstat (limited to 'src/components')
-rw-r--r--src/components/automatable.h96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/components/automatable.h b/src/components/automatable.h new file mode 100644 index 0000000..b37945f --- /dev/null +++ b/src/components/automatable.h
@@ -0,0 +1,96 @@
1#ifndef AUTOMATABLE_H_3D519131
2#define AUTOMATABLE_H_3D519131
3
4#include "component.h"
5#include <vector>
6#include <random>
7
8class AutomatableComponent : public Component {
9public:
10
11 /**
12 * Helper class that defines an automatable action.
13 */
14 class Action {
15 public:
16
17 /**
18 * The horizontal and vertical speed, in pixels/sec, that the entity should
19 * move at.
20 */
21 double speedX;
22 double speedY;
23
24 /**
25 * The duration of the action in seconds.
26 */
27 double dur;
28 };
29
30 /**
31 * Helper type that defines a behavior that an entity can exhibit, which is a
32 * list of actions that are stepped through in sequence.
33 */
34 using Behavior = std::vector<Action>;
35
36 /**
37 * A group of behaviors that the entity can exhibit, which are picked at
38 * random at the start of automation and whenever a behavior completes.
39 *
40 * @managed_by RealizingSystem
41 */
42 std::vector<Behavior> behaviors;
43
44 /**
45 * A random distribution over the above behaviors.
46 *
47 * @managed_by RealizingSystem
48 */
49 std::discrete_distribution<size_t> behaviorDist;
50
51 /**
52 * A flag indicating whether a behavior is currently executing.
53 *
54 * @managed_by AutomatingSystem
55 */
56 bool behaviorRunning = false;
57
58 /**
59 * A flag indicating whether an action is currently executing.
60 *
61 * @managed_by AutomatingSystem
62 */
63 bool actionRunning = false;
64
65 /**
66 * The index of the currently executing behavior, if there is one.
67 *
68 * @managed_by AutomatingSystem
69 */
70 size_t currentBehavior;
71
72 /**
73 * The index of the currently executing action, if there is one.
74 *
75 * @managed_by AutomatingSystem
76 */
77 size_t currentAction;
78
79 /**
80 * The amount of time remaining, in seconds, of the currently executing
81 * action.
82 *
83 * @managed_by AutomatingSystem
84 */
85 double remaining;
86
87 /**
88 * If this flag is disabled, the entity will be ignored by the automating
89 * system.
90 *
91 * @managed_by RealizingSystem
92 */
93 bool active = false;
94};
95
96#endif /* end of include guard: AUTOMATABLE_H_3D519131 */