载入中...
搜索中...
未找到
WaveDirector.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Module.h"
5#include "common/Result.h"
6
7#include <cstdint>
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace eve::towerdefense {
13
15struct WaveEntry {
16 std::string archetypeId;
17 int count = 1;
18 double intervalSeconds = 0.5;
19 double delaySeconds = 0.0;
20};
21
24 std::string id;
25 double prepSeconds = 3.0;
26 int rewardGold = 0;
27 std::vector<WaveEntry> entries;
28};
29
31enum class WavePhase : std::uint8_t {
32 Idle,
37 Failed,
38};
39
42 std::uint64_t sequence = 0;
43 std::string waveId;
44 int waveIndex = 0;
45 std::string archetypeId;
46 int entryIndex = 0;
47 int spawnIndex = 0;
48};
49
52 std::uint64_t sequence = 0;
53 std::string kind;
54 std::string waveId;
55 int waveIndex = 0;
56 int rewardGold = 0;
57 std::string reason;
58};
59
63 std::vector<WaveSpawnEvent> spawns;
64 std::vector<WaveLifecycleEvent> events;
65};
66
74public:
76 void clear();
78 [[nodiscard]] Result<void> registerWave(WaveDefinition definition);
80 [[nodiscard]] Result<int> loadScheduleJson(std::string_view json);
82 [[nodiscard]] int waveCount() const noexcept { return static_cast<int>(waves_.size()); }
84 [[nodiscard]] std::string phaseName() const;
86 [[nodiscard]] WavePhase phase() const noexcept { return phase_; }
88 [[nodiscard]] int waveIndex() const noexcept { return waveIndex_; }
90 [[nodiscard]] double remainingPrepSeconds() const noexcept { return remainingPrep_; }
92 [[nodiscard]] Result<void> start();
94 [[nodiscard]] Result<void> reset();
100 [[nodiscard]] Result<WaveAdvanceResult> advance(std::uint64_t tick, double dt);
101
102private:
103 [[nodiscard]] Result<void> beginWave(int index, WaveAdvanceResult& out);
104 void emitLifecycle(WaveAdvanceResult& out, std::string kind, std::string waveId, int waveIndex, int rewardGold,
105 std::string reason);
106
107 std::vector<WaveDefinition> waves_;
108 WavePhase phase_ = WavePhase::Idle;
109 int waveIndex_ = 0;
110 int entryIndex_ = 0;
111 int spawnedInEntry_ = 0;
112 double remainingPrep_ = 0.0;
113 double spawnCooldown_ = 0.0;
114 std::uint64_t lastTick_ = 0;
115 bool hasTick_ = false;
116 std::uint64_t eventSequence_ = 0;
117};
118
121public:
123 explicit DefenseBase(int lives = 20);
124 [[nodiscard]] int lives() const noexcept { return lives_; }
125 [[nodiscard]] int leaks() const noexcept { return leaks_; }
126 [[nodiscard]] bool isDefeated() const noexcept { return lives_ <= 0; }
128 [[nodiscard]] Result<int> leak(int count = 1);
130 [[nodiscard]] Result<void> reset(int lives);
131
132private:
133 int lives_ = 20;
134 int leaks_ = 0;
135};
136
138class TowerDefense : public Module {
139public:
141 TowerDefense() = default;
142 ~TowerDefense() override = default;
143};
144
145} // namespace eve::towerdefense
Duration start
EnvironmentTest definition
#define EVENGINE_API_FOUNDATION
每个链接组(link group)各自的导出宏。
Definition Export.h:106
double dt
Move-only, checked operation results for the common layer.
ScriptStructure out
std::string kind
int count
SimulationTick tick
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Lives / leak counter for a defended base.
bool isDefeated() const noexcept
int lives() const noexcept
int leaks() const noexcept
Script module factory for tower-defense schedule helpers.
~TowerDefense() override=default
Deterministic wave / creep spawn schedule.
WavePhase phase() const noexcept
Current phase.
int waveCount() const noexcept
Number of registered waves in schedule order.
int waveIndex() const noexcept
Index of the active/next wave, or waveCount when completed.
double remainingPrepSeconds() const noexcept
Remaining preparation/between-wave seconds.
WavePhase
Lifecycle phase of a WaveDirector.
Owning result of one advance step.
std::vector< WaveSpawnEvent > spawns
std::vector< WaveLifecycleEvent > events
Data-driven wave definition.
std::vector< WaveEntry > entries
One spawn group inside a wave.
One phase/reward event emitted by advance().
One deterministic spawn request emitted by advance().