From 83f51a6892629921b4cc482b986656a0a5cc5f6a Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 3 May 2018 14:41:01 -0400 Subject: 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. --- src/components/automatable.h | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/components/automatable.h (limited to 'src/components') 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 @@ +#ifndef AUTOMATABLE_H_3D519131 +#define AUTOMATABLE_H_3D519131 + +#include "component.h" +#include +#include + +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. + */ + double speedX; + double speedY; + + /** + * 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; + + /** + * 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 behaviors; + + /** + * A random distribution over the above behaviors. + * + * @managed_by RealizingSystem + */ + std::discrete_distribution 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 */ -- cgit 1.4.1