summary refs log tree commit diff stats
path: root/src/components/automatable.h
blob: c1fd1a3746d9a40c87edaa4a7df2cc26d72278ca (plain) (blame)
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
#ifndef AUTOMATABLE_H_3D519131
#define AUTOMATABLE_H_3D519131

#include "component.h"
#include <vector>
#include <random>
#include "vector.h"

class AutomatableComponent : public Component {
public:

  /**
   * Helper class that defines an automatable action.
   */
  class Action {
  public:

    /**
     * The horizontal and vertical speed, in pixels/sec, that the entity should
     * move at.
     */
    vec2d speed;

    /**
     * The duration of the action in seconds.
     */
    double dur;
  };

  /**
   * Helper type that defines a behavior that an entity can exhibit, which is a
   * list of actions that are stepped through in sequence.
   */
  using Behavior = std::vector<Action>;

  /**
   * A group of behaviors that the entity can exhibit, which are picked at
   * random at the start of automation and whenever a behavior completes.
   *
   * @managed_by RealizingSystem
   */
  std::vector<Behavior> behaviors;

  /**
   * A random distribution over the above behaviors.
   *
   * @managed_by RealizingSystem
   */
  std::discrete_distribution<size_t> behaviorDist;

  /**
   * A flag indicating whether a behavior is currently executing.
   *
   * @managed_by AutomatingSystem
   */
  bool behaviorRunning = false;

  /**
   * A flag indicating whether an action is currently executing.
   *
   * @managed_by AutomatingSystem
   */
  bool actionRunning = false;

  /**
   * The index of the currently executing behavior, if there is one.
   *
   * @managed_by AutomatingSystem
   */
  size_t currentBehavior;

  /**
   * The index of the currently executing action, if there is one.
   *
   * @managed_by AutomatingSystem
   */
  size_t currentAction;

  /**
   * The amount of time remaining, in seconds, of the currently executing
   * action.
   *
   * @managed_by AutomatingSystem
   */
  double remaining;

  /**
   * If this flag is disabled, the entity will be ignored by the automating
   * system.
   *
   * @managed_by RealizingSystem
   */
  bool active = false;
};

#endif /* end of include guard: AUTOMATABLE_H_3D519131 */