R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Spawner.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** Spawner component for declarative entity spawning
6*/
7
8#pragma once
9
10#include <string>
11#include <vector>
12#include "IComponent.hpp"
13
14namespace ecs {
19 struct SpawnRequest {
20 float x;
21 float y;
22 std::string enemyType; // "basic", "advanced", etc.
23 std::string scriptPath; // Lua script for behavior
24 float health;
26 float spawnDelay; // Delay in seconds from wave start
27 bool hasSpawned = false; // Track if this request has been spawned
28 };
29
30 struct WaveConfig {
31 std::vector<SpawnRequest> enemies;
32 float spawnInterval; // Time between spawns in this wave
33 };
34
36 std::vector<WaveConfig> waves;
37 std::vector<int> wavesIntervals; // Time between waves
38 };
39
48 class Spawner : public IComponent {
49 public:
50 Spawner() = default;
51 ~Spawner() override = default;
52
57 void queueSpawn(const SpawnRequest &request) { _spawnRequests.push_back(request); }
58
63 const std::vector<SpawnRequest> &getSpawnRequests() const { return _spawnRequests; }
64
69
74 bool hasPendingSpawns() const { return !_spawnRequests.empty(); }
75
80 ComponentType getType() const override { return getComponentType<Spawner>(); }
81
82 void setConfig(const SpawnerConfig &config) {
83 _config = config;
84 // Reset spawner state
85 waveElapsedTime = 0.0f;
87 isActive = true;
88 // Ensure all hasSpawned flags are reset
89 for (auto &wave : _config.waves) {
90 for (auto &enemy : wave.enemies) {
91 enemy.hasSpawned = false;
92 }
93 }
94 }
95 const SpawnerConfig &getConfig() const { return _config; }
97
98 float waveElapsedTime = 0.0f; // Time elapsed within current wave
100
101 bool isActive = true;
102
103 private:
104 std::vector<SpawnRequest> _spawnRequests;
106 };
107
108} // namespace ecs
Base interface for all ECS components.
Component that holds spawn requests to be processed by SpawnSystem.
Definition Spawner.hpp:48
SpawnerConfig _config
Definition Spawner.hpp:105
const SpawnerConfig & getConfig() const
Definition Spawner.hpp:95
const std::vector< SpawnRequest > & getSpawnRequests() const
Get all pending spawn requests.
Definition Spawner.hpp:63
bool hasPendingSpawns() const
Check if there are pending spawns.
Definition Spawner.hpp:74
void queueSpawn(const SpawnRequest &request)
Queue a spawn request.
Definition Spawner.hpp:57
void clearSpawnRequests()
Clear all pending spawn requests (called after processing)
Definition Spawner.hpp:68
int currentWaveIndex
Definition Spawner.hpp:99
~Spawner() override=default
std::vector< SpawnRequest > _spawnRequests
Definition Spawner.hpp:104
ComponentType getType() const override
Get component type ID.
Definition Spawner.hpp:80
SpawnerConfig & getConfigMutable()
Definition Spawner.hpp:96
float waveElapsedTime
Definition Spawner.hpp:98
Spawner()=default
void setConfig(const SpawnerConfig &config)
Definition Spawner.hpp:82
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::size_t ComponentType
Type alias for component identification.
Declarative request for spawning an entity.
Definition Spawner.hpp:19
std::string scriptPath
Definition Spawner.hpp:23
std::string enemyType
Definition Spawner.hpp:22
std::vector< WaveConfig > waves
Definition Spawner.hpp:36
std::vector< int > wavesIntervals
Definition Spawner.hpp:37
float spawnInterval
Definition Spawner.hpp:32
std::vector< SpawnRequest > enemies
Definition Spawner.hpp:31