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
11import helios.engine.ecs.System;
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
27
29
30 /**
31 * @brief System that steers entities towards their chase targets.
32 *
33 * Processes all entities with ChaseComponent, SteeringComponent, and
34 * TranslationStateComponent. Updates steering intent to face the target
35 * entity based on a cooldown timer.
36 *
37 * The system:
38 * 1 Finds the target entity by handle
39 * 2 Waits for the cooldown timer to expire
40 * 3 Calculates direction from entity to target
41 * 4 Sets steering intent to face that direction
42 */
44
45 public:
46
47 /**
48 * @brief Updates steering for all chasing entities.
49 *
50 * @param updateContext Context providing delta time and game world access.
51 */
52 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept override {
53
54 for (auto [entity, sc, cc, tsc, active] : gameWorld_->view<
59 >().whereEnabled()) {
60
61 const auto entityHandle = cc->target();
62
63 const auto go = gameWorld_->find(entityHandle);
64
65 if (!go || !go->isActive()) {
66 continue;
67 }
68
70 if (!ttr) {
71 continue;
72 }
73
74 cc->updateCooldownTimerBy(updateContext.deltaTime());
75
76 if (cc->cooldownTimer() < cc->cooldown()) {
77 continue;
78 }
79
80 cc->setCooldownTimer(0.0f);
81
82 const auto translation = tsc->translation();
83 const auto direction = (ttr->translation() - translation).normalize();
84
85 if (std::abs(direction.length() - 1.0f) > helios::math::EPSILON_LENGTH) {
86 continue;
87 }
88
89 sc->setSteeringIntent(direction, 1.0f);
90
91 }
92 }
93
94 };
95
96}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.