Server-authoritative enemy AI system managing all enemy behaviors. More...
#include <EnemyAISystem.hpp>
Inheritance diagram for gme::EnemyAISystem:
Collaboration diagram for gme::EnemyAISystem:Public Member Functions | |
| EnemyAISystem (ecs::Registry ®istry, EntityManager &entityManager) | |
| Constructor. | |
| ~EnemyAISystem () override=default | |
| Destructor. | |
| EnemyAISystem (const EnemyAISystem &)=delete | |
| Deleted copy constructor (non-copyable) | |
| EnemyAISystem & | operator= (const EnemyAISystem &)=delete |
| Deleted copy assignment operator (non-copyable) | |
| EnemyAISystem (EnemyAISystem &&)=delete | |
| Deleted move constructor (non-movable) | |
| EnemyAISystem & | operator= (EnemyAISystem &&)=delete |
| Deleted move assignment operator (non-movable) | |
| void | update (ecs::Registry ®istry, float deltaTime) override |
| Update the enemy AI system (called each frame) | |
| void | setAggressiveness (float value) |
| Set global enemy aggressiveness multiplier. | |
| float | getAggressiveness () const |
| Get current aggressiveness setting. | |
Public Member Functions inherited from ecs::ASystem | |
| bool | isEnable () override |
| void | setEnable (const bool enable) override |
Public Member Functions inherited from ecs::ISystem | |
| virtual | ~ISystem ()=default |
Private Member Functions | |
| void | updateBasicEnemyAI (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime) |
| Update AI logic for basic enemy type. | |
| void | updateAdvancedEnemyAI (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime) |
| Update AI logic for advanced enemy type. | |
| void | updateBossAI (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime) |
| Update AI logic for boss enemy type. | |
| void | applySineWaveMovement (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime, float frequency=2.0f, float amplitude=50.0f) |
| Apply sine wave vertical movement pattern. | |
| void | applyAggressiveMovement (ecs::Entity enemy, float deltaTime, float speed=150.0f) |
| Apply aggressive pursuit movement toward nearest player. | |
| void | applyZigzagMovement (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime) |
| Apply zigzag diagonal movement pattern. | |
| void | tryShoot (std::uint32_t enemyId, ecs::Entity enemy, float deltaTime) |
| Attempt to shoot projectile at player. | |
| bool | canShoot (ecs::Entity enemy) const |
| Check if enemy is able to shoot (cooldown and component checks) | |
| ecs::Entity | findNearestPlayer (float x, float y) const |
| Find the nearest player entity to a given position. | |
| float | getDistanceToNearestPlayer (float x, float y) const |
| Calculate distance to nearest player. | |
| void | clampToScreen (ecs::Entity enemy) |
| Clamp enemy position to visible screen bounds. | |
Private Attributes | |
| ecs::Registry & | m_registry |
| ECS registry reference. | |
| EntityManager & | m_entityManager |
| Entity manager for spawning projectiles. | |
| float | m_aggressiveness |
| Global aggressiveness multiplier (affects pursuit speed) | |
| std::mt19937 | m_rng |
| Random number generator for shooting patterns. | |
| std::uniform_real_distribution< float > | m_shootChance |
| Random distribution for shoot probability. | |
| std::unordered_map< std::uint32_t, float > | m_enemyMovementTimers |
| Movement timing per enemy ID. | |
| std::unordered_map< std::uint32_t, float > | m_bossSpreadTimers |
| Boss spread shot timing per boss ID. | |
Server-authoritative enemy AI system managing all enemy behaviors.
This ECS system controls all enemy logic on the game server, including:
The system processes three enemy types:
All AI logic runs server-side to maintain authoritative gameplay state.
Definition at line 61 of file EnemyAISystem.hpp.
|
explicit |
Constructor.
| registry | ECS registry containing all entities and components |
| entityManager | Entity manager for spawning projectiles and effects |
Initializes the AI system with random number generation for shooting patterns
Definition at line 16 of file EnemyAISystem.cpp.
References utl::INFO, utl::Logger::log(), and m_rng.
Here is the call graph for this function:
|
overridedefault |
Destructor.
|
delete |
Deleted copy constructor (non-copyable)
|
delete |
Deleted move constructor (non-movable)
|
private |
Apply aggressive pursuit movement toward nearest player.
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
| speed | Movement speed in pixels per second (default: 150.0) |
Enemy moves directly toward nearest player position
Definition at line 203 of file EnemyAISystem.cpp.
References findNearestPlayer(), ecs::Registry::getComponent(), ecs::INVALID_ENTITY, m_aggressiveness, m_registry, ecs::Transform::x, and ecs::Transform::y.
Referenced by updateAdvancedEnemyAI(), and updateBossAI().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Apply sine wave vertical movement pattern.
| enemyId | Network ID of the enemy (for independent timing) |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
| frequency | Oscillation frequency in Hz (default: 2.0) |
| amplitude | Vertical oscillation amplitude in pixels (default: 50.0) |
Creates smooth vertical oscillation while moving left
Definition at line 182 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), m_enemyMovementTimers, m_registry, ecs::Transform::x, and ecs::Transform::y.
Referenced by updateAdvancedEnemyAI(), and updateBossAI().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Apply zigzag diagonal movement pattern.
| enemyId | Network ID of the enemy (for independent timing) |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
Creates erratic zigzag movement pattern
Definition at line 238 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), m_enemyMovementTimers, m_registry, ecs::Transform::x, and ecs::Transform::y.
Referenced by updateBossAI().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Check if enemy is able to shoot (cooldown and component checks)
| enemy | ECS entity handle |
Verifies entity has required components and shooting cooldown has elapsed
Definition at line 322 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), ecs::Enemy::last_shot_time, and m_registry.
Referenced by tryShoot().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Clamp enemy position to visible screen bounds.
| enemy | ECS entity handle |
Prevents enemies from moving off-screen vertically
Definition at line 383 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), m_registry, utl::GameConfig::Server::SCREEN_HEIGHT, utl::GameConfig::Server::SCREEN_WIDTH, and ecs::Transform::x.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Find the nearest player entity to a given position.
| x | X coordinate to search from |
| y | Y coordinate to search from |
Used for aggressive AI targeting
Definition at line 331 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), gme::EntityManager::getPlayers(), ecs::INVALID_ENTITY, m_entityManager, m_registry, and ecs::Transform::x.
Referenced by applyAggressiveMovement(), and tryShoot().
Here is the call graph for this function:
Here is the caller graph for this function:
|
inline |
Get current aggressiveness setting.
Definition at line 107 of file EnemyAISystem.hpp.
References m_aggressiveness.
|
private |
Calculate distance to nearest player.
| x | X coordinate to measure from |
| y | Y coordinate to measure from |
Used for distance-based behavior decisions
Definition at line 358 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), gme::EntityManager::getPlayers(), m_entityManager, m_registry, and ecs::Transform::x.
Referenced by tryShoot(), and updateAdvancedEnemyAI().
Here is the call graph for this function:
Here is the caller graph for this function:
|
delete |
Deleted copy assignment operator (non-copyable)
|
delete |
Deleted move assignment operator (non-movable)
|
inline |
Set global enemy aggressiveness multiplier.
| value | Aggressiveness factor (0.0-2.0, default 1.0) |
Higher values make enemies pursue players more aggressively. Affects movement speed and shooting frequency.
Definition at line 101 of file EnemyAISystem.hpp.
References m_aggressiveness.
|
private |
Attempt to shoot projectile at player.
| enemyId | Network ID of the enemy |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
Checks shooting conditions and spawns projectile with random chance
Definition at line 257 of file EnemyAISystem.cpp.
References canShoot(), gme::EntityManager::createEnemyProjectile(), findNearestPlayer(), ecs::Registry::getComponent(), getDistanceToNearestPlayer(), ecs::INVALID_ENTITY, m_entityManager, m_registry, m_rng, m_shootChance, and ecs::Transform::x.
Referenced by updateAdvancedEnemyAI(), updateBasicEnemyAI(), and updateBossAI().
Here is the call graph for this function:
Here is the caller graph for this function:
|
overridevirtual |
Update the enemy AI system (called each frame)
| registry | ECS registry containing all entities |
| deltaTime | Time elapsed since last frame (in seconds) |
Processes AI logic for all enemy entities including movement, shooting, and behavior pattern updates
Implements ecs::ISystem.
Definition at line 25 of file EnemyAISystem.cpp.
References gme::BOSS, clampToScreen(), gme::ENEMY_ADVANCED, gme::ENEMY_BASIC, gme::EntityManager::getEnemies(), gme::EntityManager::getEntityMetadata(), m_entityManager, updateAdvancedEnemyAI(), updateBasicEnemyAI(), and updateBossAI().
Here is the call graph for this function:
|
private |
Update AI logic for advanced enemy type.
| enemyId | Network ID of the enemy |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
Implements more complex movement patterns and frequent shooting
Definition at line 78 of file EnemyAISystem.cpp.
References applyAggressiveMovement(), applySineWaveMovement(), ecs::Registry::getComponent(), getDistanceToNearestPlayer(), m_enemyMovementTimers, m_registry, and tryShoot().
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Update AI logic for basic enemy type.
| enemyId | Network ID of the enemy |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
Implements simple movement patterns and occasional shooting
Definition at line 57 of file EnemyAISystem.cpp.
References ecs::Registry::getComponent(), m_enemyMovementTimers, m_registry, tryShoot(), and ecs::Velocity::x.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Update AI logic for boss enemy type.
| enemyId | Network ID of the boss |
| enemy | ECS entity handle |
| deltaTime | Time elapsed since last frame |
Implements special boss behaviors including spread shot patterns
Definition at line 107 of file EnemyAISystem.cpp.
References applyAggressiveMovement(), applySineWaveMovement(), applyZigzagMovement(), gme::EntityManager::createEnemyProjectile(), ecs::Registry::getComponent(), gme::EntityManager::getNetworkIdForEntity(), m_bossSpreadTimers, m_enemyMovementTimers, m_entityManager, m_registry, tryShoot(), and ecs::Transform::x.
Referenced by update().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Global aggressiveness multiplier (affects pursuit speed)
Definition at line 113 of file EnemyAISystem.hpp.
Referenced by applyAggressiveMovement(), getAggressiveness(), and setAggressiveness().
|
private |
Boss spread shot timing per boss ID.
Definition at line 119 of file EnemyAISystem.hpp.
Referenced by updateBossAI().
|
private |
Movement timing per enemy ID.
Definition at line 118 of file EnemyAISystem.hpp.
Referenced by applySineWaveMovement(), applyZigzagMovement(), updateAdvancedEnemyAI(), updateBasicEnemyAI(), and updateBossAI().
|
private |
Entity manager for spawning projectiles.
Definition at line 111 of file EnemyAISystem.hpp.
Referenced by findNearestPlayer(), getDistanceToNearestPlayer(), tryShoot(), update(), and updateBossAI().
|
private |
ECS registry reference.
Definition at line 110 of file EnemyAISystem.hpp.
Referenced by applyAggressiveMovement(), applySineWaveMovement(), applyZigzagMovement(), canShoot(), clampToScreen(), findNearestPlayer(), getDistanceToNearestPlayer(), tryShoot(), updateAdvancedEnemyAI(), updateBasicEnemyAI(), and updateBossAI().
|
private |
Random number generator for shooting patterns.
Definition at line 114 of file EnemyAISystem.hpp.
Referenced by EnemyAISystem(), and tryShoot().
|
private |
Random distribution for shoot probability.
Definition at line 115 of file EnemyAISystem.hpp.
Referenced by tryShoot().