Skip to main content

ChaseComponent.ixx File

Component for AI chase/seek behavior. More...

Included Headers

#include <cassert> #include <helios.engine.ecs.EntityHandle> #include <helios.util.Guid> #include <helios.core.types>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacemodules

Domain-specific components and systems. More...

namespaceai

AI behavior modules for game entities. More...

namespacecomponents

AI behavior data components. More...

Classes Index

classChaseComponent

Component storing chase behavior data. More...

Description

Component for AI chase/seek behavior.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ChaseComponent.ixx
3 * @brief Component for AI chase/seek behavior.
4 */
5module;
6
7#include <cassert>
8export module helios.engine.modules.ai.components.ChaseComponent;
9
10
11
12import helios.core.types;
13import helios.util.Guid;
14
15import helios.engine.ecs.EntityHandle;
16
17
19
20 /**
21 * @brief Component storing chase behavior data.
22 *
23 * Tracks a target entity by handle and controls the frequency
24 * of direction updates via a cooldown timer. Used by ChaseSystem
25 * to steer entities towards their targets.
26 */
28
29 /**
30 * @brief Time between target direction updates (seconds).
31 */
32 float cooldown_ = 0.0f;
33
34 /**
35 * @brief Current elapsed time since last update.
36 */
37 float cooldownTimer_ = 0.0f;
38
39 /**
40 * @brief EntityHandle of the entity to chase.
41 */
43
44 /**
45 * @brief Whether this component is enabled.
46 */
47 bool isEnabled_ = true;
48
49 public:
50
51 /**
52 * @brief Checks whether this component is enabled.
53 *
54 * @return True if enabled, false otherwise.
55 */
56 [[nodiscard]] bool isEnabled() const noexcept {
57 return isEnabled_;
58 }
59
60 /**
61 * @brief Enables this component.
62 */
63 void enable() noexcept {
64 isEnabled_ = true;
65 }
66
67 /**
68 * @brief Disables this component.
69 */
70 void disable() noexcept {
71 isEnabled_ = false;
72 }
73
74 /**
75 * @brief Default constructor.
76 */
77 ChaseComponent() = default;
78
80 cooldown_(other.cooldown_), cooldownTimer_(other.cooldownTimer_), target_(other.target_) {} ;
82 ChaseComponent(ChaseComponent&&) noexcept = default;
83 ChaseComponent& operator=(ChaseComponent&&) noexcept = default;
84
85 /**
86 * @brief Returns the target entity's handle.
87 *
88 * @return The handle of the chase target.
89 */
90 [[nodiscard]] helios::engine::ecs::EntityHandle target() const noexcept {
91 return target_;
92 }
93
94 /**
95 * @brief Returns the cooldown duration.
96 *
97 * @return Time between direction updates in seconds.
98 */
99 [[nodiscard]] float cooldown() const noexcept {
100 return cooldown_;
101 }
102
103 /**
104 * @brief Sets the cooldown duration.
105 *
106 * @param cooldown Time between direction updates in seconds.
107 */
108 void setCooldown(const float cooldown) noexcept {
109 cooldown_ = cooldown;
110 }
111
112 /**
113 * @brief Returns the current cooldown timer value.
114 *
115 * @return Elapsed time since last direction update.
116 */
117 [[nodiscard]] float cooldownTimer() const noexcept {
118 return cooldownTimer_;
119 }
120
121 /**
122 * @brief Advances the cooldown timer by delta time.
123 *
124 * @param delta Time to add to the timer.
125 */
126 void updateCooldownTimerBy(const float delta) noexcept {
127 cooldownTimer_ += delta;
128 }
129
130 /**
131 * @brief Sets the cooldown timer to a specific value.
132 *
133 * @param timer New timer value.
134 */
135 void setCooldownTimer(const float timer) noexcept {
136 cooldownTimer_ = timer;
137 }
138
139 /**
140 * @brief Sets the target entity to chase.
141 *
142 * @param entityHandle The EntityHandle of the target entity.
143 */
144 void setTarget(const helios::engine::ecs::EntityHandle& entityHandle) noexcept {
145 assert(entityHandle.isValid() && "Unexpected invalid entityHandle");
146 target_ = entityHandle;
147 }
148 };
149
150
151}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.