R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
AISystem.cpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** AISystem
6*/
7
8#include "AISystem.hpp"
9#include <cmath>
10#include "../../Components/IComponent.hpp"
11#include "../../Components/Weapon.hpp"
12
13namespace ecs {
17 void AISystem::update(Registry &registry, float deltaTime) {
18 auto entities = registry.getEntitiesWithMask(this->getComponentMask());
19
20 for (auto entityId : entities) {
21 auto &enemy = registry.getComponent<Enemy>(entityId);
22 auto &transform = registry.getComponent<Transform>(entityId);
23 auto &velocity = registry.getComponent<Velocity>(entityId);
24
25 applyMovementPattern(enemy, transform, velocity, deltaTime);
26
27 // Auto-fire for enemies with weapons
28 if (registry.hasComponent<Weapon>(entityId)) {
29 auto &weapon = registry.getComponent<Weapon>(entityId);
30 weapon.setShouldShoot(true);
31 }
32 }
33 }
34
38 void AISystem::applyMovementPattern([[maybe_unused]] const Enemy &enemy,
39 [[maybe_unused]] Transform &transform,
40 [[maybe_unused]] Velocity &velocity,
41 [[maybe_unused]] float deltaTime) {
42 // TODO: Implement different movement patterns based on enemy type
43 }
44
46 return (1ULL << getComponentType<Enemy>()) | (1ULL << getComponentType<Transform>()) |
47 (1ULL << getComponentType<Velocity>());
48 }
49} // namespace ecs
ComponentMask getComponentMask() const override
Gets the component mask for this system.
Definition AISystem.cpp:45
void update(Registry &registry, float deltaTime) override
Updates all enemy AI behaviors.
Definition AISystem.cpp:17
void applyMovementPattern(const Enemy &enemy, Transform &transform, Velocity &velocity, float deltaTime)
Applies movement pattern to an enemy entity.
Definition AISystem.cpp:38
Component identifying an entity as an enemy with AI behavior.
Definition Enemy.hpp:20
Manages entities, their signatures and component type registrations.
Definition Registry.hpp:68
std::vector< Address > getEntitiesWithMask(Signature requiredMask)
Get all entities matching a specific component mask.
Definition Registry.cpp:79
T & getComponent(Address address)
Get a component from an entity.
bool hasComponent(Address address)
Check if an entity has a specific component.
Component representing position, rotation and scale in 2D space.
Definition Transform.hpp:20
Component representing movement direction and speed.
Definition Velocity.hpp:20
Component for entities capable of shooting projectiles.
Definition Weapon.hpp:28
void setShouldShoot(bool shouldShoot)
Set whether the weapon should shoot.
Definition Weapon.hpp:116
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::uint64_t ComponentMask
Type alias for component bitmask.
Definition ISystem.hpp:24