载入中...
搜索中...
未找到
RTSProductionSpawn.cpp
浏览该文件的文档.
1#include "crowd/Crowd.h"
2#include "rts/RTS.h"
3
4namespace eve::rts {
5
6Result<ProductionSpawnOutcome> RTS::placeProducedUnit(Unit& unit, WorldPosition requested) {
7 if (crowd_ == nullptr || !unit.crowd()->link.isBound()) {
8 unit.motion()->x = requested.x;
9 unit.motion()->y = requested.y;
11 }
12 const auto& key = unit.crowd()->link.key();
13 if (crowd_->getNamedAgentIndex(key) >= 0)
15 DiagnosticCode::Conflict, "Produced unit already has a Crowd projection", "production.spawn"));
16 crowd::SpawnBatch batch;
18 batch.agents.push_back({key, requested.x, requested.y, unit.crowd()->heading, unit.crowd()->radius, {}});
19 auto placed = crowd_->applySpawnBatch(batch);
20 if (!placed) {
21 const auto* diagnostic = placed.status().primaryDiagnostic();
22 if (diagnostic != nullptr && (diagnostic->code() == DiagnosticCode::Conflict ||
23 diagnostic->code() == DiagnosticCode::PreconditionViolation))
27 }
28 std::move(placed).takeValue();
29 // Publish displaced peers immediately: the next movement phase imports ECS
30 // motion and must not overwrite the just-committed Crowd displacement.
31 auto view = ecs::View<Unit, Unit::Motion, Unit::Crowd, Unit::Containment>();
32 for (auto it = view.begin(); it != view.end(); ++it) {
33 auto [motion, settings, containment] = *it;
34 if (!settings->link.isBound() || containment->container.isBound()) continue;
35 const int agent = crowd_->getNamedAgentIndex(settings->link.key());
36 if (agent < 0) continue;
37 const auto state = crowd_->getAgentState(agent);
38 motion->x = state.x;
39 motion->y = state.y;
40 settings->heading = state.heading;
41 }
43}
44
45} // namespace eve::rts
std::uint32_t key
RTS module owner and phase-one composition profile entry point.
glm::mat4 view
TacticalUnit * unit
bool placed
TerrainThermalSettings settings
V3 heading
Definition TreeMesh.cpp:292
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
AgentState getAgentState(int id) const
读取单位状态快照(非法 id 返回 action=-1)。
Definition Crowd.cpp:317
int getNamedAgentIndex(const std::string &stableId) const
Resolve a stable logical identifier to the current compact slot.
Definition Crowd.cpp:139
Result< SpawnReceipt > applySpawnBatch(const SpawnBatch &batch)
Apply a caller-built spawn batch atomically, including neighbor displacement.
float x
世界 X
Definition Crowd.h:20