Skip to main content

ChaseSystem.ixx File

System for updating entity steering to chase targets. More...

Included Headers

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...

namespacesystems

AI behavior processing systems. More...

Classes Index

classChaseSystem

System that steers entities towards their chase targets. More...

Description

System for updating entity steering to chase targets.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file ChaseSystem.ixx
3 * @brief System for updating entity steering to chase targets.
4 */
5module;
6
7#include <algorithm>
8
9export module helios.engine.modules.ai.systems.ChaseSystem;
10
11
12import helios.math;
13
14import helios.core.units.Unit;
15
16import helios.engine.ecs.GameObject;
17import helios.engine.runtime.world.GameWorld;
18import helios.engine.runtime.world.UpdateContext;
19
20import helios.engine.modules.ai.components.ChaseComponent;
21import helios.engine.modules.physics.motion.components.SteeringComponent;
22
23import helios.engine.modules.spatial.transform.components.TranslationStateComponent;
24
25import helios.engine.mechanics.lifecycle.components.Active;
26
27import helios.engine.mechanics.lifecycle.components;
28
30
31import helios.engine.common.tags.SystemRole;
32
34
35 /**
36 * @brief System that steers entities towards their chase targets.
37 *
38 * Processes all entities with ChaseComponent, SteeringComponent, and
39 * TranslationStateComponent. Updates steering intent to face the target
40 * entity based on a cooldown timer.
41 *
42 * The system:
43 * 1 Finds the target entity by handle
44 * 2 Waits for the cooldown timer to expire
45 * 3 Calculates direction from entity to target
46 * 4 Sets steering intent to face that direction
47 */
48 class ChaseSystem {
49
50
51 public:
52
54 /**
55 * @brief Updates steering for all chasing entities.
56 *
57 * @param updateContext Context providing delta time and game world access.
58 */
60
61 for (auto [entity, sc, cc, tsc, active] : updateContext.view<
66 >().whereEnabled()) {
67
68 const auto entityHandle = cc->target();
69
70 auto go = updateContext.find(entityHandle);
71
72 if (!go || !go->isActive() || go->has<DeadTagComponent>()) {
73 continue;
74 }
75
77 if (!ttr) {
78 continue;
79 }
80
81 cc->updateCooldownTimerBy(updateContext.deltaTime());
82
83 if (cc->cooldownTimer() < cc->cooldown()) {
84 continue;
85 }
86
87 cc->setCooldownTimer(0.0f);
88
89 const auto translation = tsc->translation();
90 const auto direction = (ttr->translation() - translation).normalize();
91
92 if (std::abs(direction.length() - 1.0f) > helios::math::EPSILON_LENGTH) {
93 continue;
94 }
95
96 sc->setSteeringIntent(direction, 1.0f);
97
98 }
99 }
100
101 };
102
103}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.