载入中...
搜索中...
未找到
PlacementDomains.cpp
浏览该文件的文档.
2
4#include "building/Ghost.h"
8#include "common/Diagnostic.h"
10
11#include <algorithm>
12#include <cmath>
13#include <limits>
14#include <unordered_set>
15
16namespace eve::building {
17
18using namespace placement_detail;
19
20eve::Result<EdgeAddress> PlacementSystem::canonicalEdge(int cellX, int cellY, const std::string &direction) {
22 edge.x = cellX;
23 edge.y = cellY;
24 if (direction == "north" || direction == "n") {
26 } else if (direction == "south" || direction == "s") {
28 ++edge.y;
29 } else if (direction == "west" || direction == "w") {
31 } else if (direction == "east" || direction == "e") {
33 ++edge.x;
34 } else {
36 "edge direction must be north/east/south/west",
37 direction, {}, "building.edge"));
38 }
40}
41
42bool PlacementSystem::canPlaceEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY,
43 const std::string &direction, int excludeInstanceId, std::string *reason,
44 int level) {
45 if (!world) {
46 if (reason) *reason = "no_world";
47 return false;
48 }
49 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
50 if (!def) {
51 if (reason) *reason = "unknown_building";
52 return false;
53 }
54 if (def->placementKind != "edge") {
55 if (reason) *reason = "not_edge_building";
56 return false;
57 }
58 auto result = canonicalEdge(cellX, cellY, direction);
59 if (!result.ok()) {
60 if (reason) *reason = "invalid_edge_direction";
61 return false;
62 }
63 const EdgeAddress edge = std::move(result).takeValue();
64 const bool inBounds = edge.axis == EdgeAxis::Horizontal
65 ? edge.x >= 0 && edge.x < world->width_ && edge.y >= 0 && edge.y <= world->height_
66 : edge.x >= 0 && edge.x <= world->width_ && edge.y >= 0 && edge.y < world->height_;
67 if (!inBounds) {
68 if (reason) *reason = "edge_out_of_bounds";
69 return false;
70 }
71 const int resolvedLevel = level == std::numeric_limits<int>::min() ? world->getActiveLevel() : level;
72 for (const auto &[id, placed] : world->buildings_) {
73 if (id == excludeInstanceId || placed.placementKind != "free" || placed.level != resolvedLevel) continue;
74 const auto *freeDef = BuildingRegistry::find(placed.buildingId);
75 if (freeDef && hasFreeEdgeOverlap(*world, *freeDef, placedFreeFootprint(placed), *def, edge)) {
76 if (reason) *reason = "edge_free_overlap";
77 return false;
78 }
79 }
80 const auto *channels = world->findEdgeChannels(edge.axis, resolvedLevel);
81 const size_t index = edge.axis == EdgeAxis::Horizontal
82 ? size_t(edge.y) * size_t(world->width_) + size_t(edge.x)
83 : size_t(edge.y) * size_t(world->width_ + 1) + size_t(edge.x);
84 if (!channels) return true;
85 const auto channelIt = channels->find(def->channel);
86 const int occupant =
87 channelIt != channels->end() && index < channelIt->second.size() ? channelIt->second[index] : 0;
88 if (occupant != 0 && occupant != excludeInstanceId) {
89 if (reason) *reason = "edge_occupied";
90 return false;
91 }
92 return true;
93}
94
95int PlacementSystem::placeEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY,
96 const std::string &direction) {
97 if (!canPlaceEdge(world, buildingId, cellX, cellY, direction, 0, nullptr)) return 0;
98 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
99 auto address = canonicalEdge(cellX, cellY, direction);
100 if (!def || !address.ok()) return 0;
101 const EdgeAddress edge = std::move(address).takeValue();
102
104 placed.instanceId = nextInstanceId(*world);
105 placed.buildingId = buildingId;
106 placed.placementKind = "edge";
107 placed.edge = edge;
108 placed.originCellX = edge.x;
109 placed.originCellY = edge.y;
110 placed.level = world->getActiveLevel();
111 placed.channel = def->channel;
112 placed.tags = def->tags;
113 float ax = 0.f, ay = 0.f, bx = 0.f, by = 0.f;
114 world->cellToWorldPlane(edge.x, edge.y, ax, ay);
115 world->cellToWorldPlane(edge.x + (edge.axis == EdgeAxis::Horizontal ? 1 : 0),
116 edge.y + (edge.axis == EdgeAxis::Vertical ? 1 : 0), bx, by);
117 placed.worldX = (ax + bx) * 0.5f;
118 placed.worldY = (ay + by) * 0.5f;
119 placed.rotationDeg = edge.axis == EdgeAxis::Horizontal ? 0.f : 90.f;
120
121 auto &channels = world->edgeChannels(edge.axis, placed.level);
122 auto &occupancy = channels[def->channel];
123 const size_t required = edge.axis == EdgeAxis::Horizontal ? size_t(world->width_) * size_t(world->height_ + 1)
124 : size_t(world->width_ + 1) * size_t(world->height_);
125 if (occupancy.size() != required) occupancy.assign(required, 0);
126 const size_t index = edge.axis == EdgeAxis::Horizontal
127 ? size_t(edge.y) * size_t(world->width_) + size_t(edge.x)
128 : size_t(edge.y) * size_t(world->width_ + 1) + size_t(edge.x);
129 occupancy[index] = placed.instanceId;
130 world->buildings()[placed.instanceId] = placed;
131 world->instanceOrder_.push_back(placed.instanceId);
132
134 event.action = "place";
135 event.worldId = world->getId();
136 event.buildingId = buildingId;
137 event.instanceId = placed.instanceId;
138 event.cellX = edge.x;
139 event.cellY = edge.y;
140 event.rotationDeg = placed.rotationDeg;
141 event.worldX = placed.worldX;
142 event.worldY = placed.worldY;
143 event.channel = placed.channel;
144 if (world->publishEvents_) emit(std::move(event));
145 return placed.instanceId;
146}
147
148bool PlacementSystem::canPlaceCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY,
149 int excludeInstanceId, std::string *reason, int level) {
150 if (!world) {
151 if (reason) *reason = "no_world";
152 return false;
153 }
154 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
155 if (!def) {
156 if (reason) *reason = "unknown_building";
157 return false;
158 }
159 if (def->placementKind != "corner") {
160 if (reason) *reason = "not_corner_building";
161 return false;
162 }
163 if (vertexX < 0 || vertexX > world->width_ || vertexY < 0 || vertexY > world->height_) {
164 if (reason) *reason = "corner_out_of_bounds";
165 return false;
166 }
167 const int resolvedLevel = level == std::numeric_limits<int>::min() ? world->getActiveLevel() : level;
168 const int occupant = world->getCornerOccupantAtLevel(def->channel, vertexX, vertexY, resolvedLevel);
169 if (occupant != 0 && occupant != excludeInstanceId) {
170 if (reason) *reason = "corner_occupied";
171 return false;
172 }
173 PlacementQuery query;
174 query.buildingId = buildingId;
175 query.cellX = vertexX;
176 query.cellY = vertexY;
177 query.level = resolvedLevel;
178 query.excludeInstanceId = excludeInstanceId;
179 return checkStructuralSupport(*world, *def, query, reason);
180}
181
183 int vertexX, int vertexY) {
184 std::string reason;
185 if (!canPlaceCorner(world, buildingId, vertexX, vertexY, 0, &reason)) {
187 "corner placement rejected without mutation",
188 reason, {}, "building.corner"));
189 }
190 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
191 if (!def) {
193 eve::DiagnosticCode::NotFound, "corner definition was not found", buildingId, {}, "building.corner"));
194 }
195
197 placed.instanceId = nextInstanceId(*world);
198 placed.buildingId = buildingId;
199 placed.placementKind = "corner";
200 placed.corner = CornerAddress{vertexX, vertexY};
201 placed.originCellX = vertexX;
202 placed.originCellY = vertexY;
203 placed.level = world->getActiveLevel();
204 placed.channel = def->channel;
205 placed.tags = def->tags;
206 world->cellToWorldPlane(vertexX, vertexY, placed.worldX, placed.worldY);
207 PlacementQuery supportQuery;
208 supportQuery.cellX = vertexX;
209 supportQuery.cellY = vertexY;
210 supportQuery.level = placed.level;
211 placed.supportInstanceIds = collectStructuralSupports(*world, *def, supportQuery);
212
213 auto &occupancy = world->cornerChannels(placed.level)[def->channel];
214 const size_t required = size_t(world->width_ + 1) * size_t(world->height_ + 1);
215 if (occupancy.size() != required) occupancy.assign(required, 0);
216 occupancy[size_t(vertexY) * size_t(world->width_ + 1) + size_t(vertexX)] = placed.instanceId;
217 world->buildings_[placed.instanceId] = placed;
218 world->instanceOrder_.push_back(placed.instanceId);
219
221 event.action = "place";
222 event.worldId = world->getId();
223 event.buildingId = buildingId;
224 event.instanceId = placed.instanceId;
225 event.cellX = vertexX;
226 event.cellY = vertexY;
227 event.level = placed.level;
228 event.worldX = placed.worldX;
229 event.worldY = placed.worldY;
230 event.channel = placed.channel;
231 if (world->publishEvents_) emit(std::move(event));
233}
234
235int PlacementSystem::placeCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY) {
236 auto result = placeCornerResult(world, buildingId, vertexX, vertexY);
237 return result.ok() ? result.value().instanceId : 0;
238}
239
240bool PlacementSystem::canPlaceFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY,
241 int excludeInstanceId, std::string *reason, int level, float rotationDeg) {
242 if (!world) {
243 if (reason) *reason = "no_world";
244 return false;
245 }
246 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
247 if (!def) {
248 if (reason) *reason = "unknown_building";
249 return false;
250 }
251 if (def->placementKind != "free") {
252 if (reason) *reason = "not_free_building";
253 return false;
254 }
255 if (!std::isfinite(worldX) || !std::isfinite(worldY)) {
256 if (reason) *reason = "free_invalid_anchor";
257 return false;
258 }
259 int cellX = 0;
260 int cellY = 0;
261 grid::worldToCell(*world->grid_, worldX, worldY, cellX, cellY, world->width_, world->height_);
262 if (cellX < 0 || cellX >= world->width_ || cellY < 0 || cellY >= world->height_) {
263 if (reason) *reason = "free_out_of_bounds";
264 return false;
265 }
266 const int resolvedLevel = level == std::numeric_limits<int>::min() ? world->getActiveLevel() : level;
267 const FreeFootprint candidate =
268 definitionFreeFootprint(*def, *world, worldX, worldY, normalizeRotation(buildingId, rotationDeg));
269 for (const auto &[id, placed] : world->buildings_) {
270 if (id == excludeInstanceId || placed.placementKind != "edge" || placed.level != resolvedLevel) continue;
271 const auto *edgeDef = BuildingRegistry::find(placed.buildingId);
272 if (edgeDef && hasFreeEdgeOverlap(*world, *def, candidate, *edgeDef, placed.edge)) {
273 if (reason) *reason = "free_edge_overlap";
274 return false;
275 }
276 }
277 for (const auto &[id, placed] : world->buildings_) {
278 if (id == excludeInstanceId || placed.placementKind != "free" || placed.level != resolvedLevel ||
279 placed.channel != def->channel)
280 continue;
282 if (reason) *reason = "free_overlap";
283 return false;
284 }
285 }
286 PlacementQuery query;
287 query.buildingId = buildingId;
288 query.cellX = cellX;
289 query.cellY = cellY;
290 query.worldX = worldX;
291 query.worldY = worldY;
292 query.level = resolvedLevel;
293 query.excludeInstanceId = excludeInstanceId;
294 return checkStructuralSupport(*world, *def, query, reason);
295}
296
297bool PlacementSystem::containsFreePoint(const PlacedBuilding &placed, float worldX, float worldY) {
298 return placed.placementKind == "free" && containsFreeFootprintPoint(placedFreeFootprint(placed), worldX, worldY);
299}
300
302 float worldX, float worldY, float elevation,
303 float rotationDeg) {
304 std::string reason;
305 if (!canPlaceFree(world, buildingId, worldX, worldY, 0, &reason, std::numeric_limits<int>::min(), rotationDeg)) {
307 eve::DiagnosticCode::Conflict, "free placement rejected without mutation", reason, {}, "building.free"));
308 }
309 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
311 placed.instanceId = nextInstanceId(*world);
312 placed.buildingId = buildingId;
313 placed.placementKind = "free";
314 placed.level = world->getActiveLevel();
315 placed.worldX = worldX;
316 placed.worldY = worldY;
317 placed.elevation = elevation;
318 placed.rotationDeg = normalizeRotation(buildingId, rotationDeg);
320 grid::worldToCell(*world->grid_, worldX, worldY, placed.originCellX, placed.originCellY, world->width_,
321 world->height_);
322 placed.channel = def->channel;
323 placed.tags = def->tags;
324 world->buildings_[placed.instanceId] = placed;
325 world->instanceOrder_.push_back(placed.instanceId);
326
328 event.action = "place";
329 event.worldId = world->getId();
330 event.buildingId = buildingId;
331 event.instanceId = placed.instanceId;
332 event.cellX = placed.originCellX;
333 event.cellY = placed.originCellY;
334 event.level = placed.level;
335 event.rotationDeg = placed.rotationDeg;
336 event.worldX = placed.worldX;
337 event.worldY = placed.worldY;
338 event.elevation = placed.elevation;
339 event.channel = placed.channel;
340 if (world->publishEvents_) emit(std::move(event));
342}
343
345 const std::string &buildingId,
346 const SurfacePatch &patch, float rotationDeg) {
347 if (!world) {
349 eve::DiagnosticCode::InvalidArgument, "free surface placement requires a world", {}, {}, "building.free"));
350 }
351 const BuildingDefinition *def = BuildingRegistry::find(buildingId);
352 if (!def || def->placementKind != "free") {
354 eve::DiagnosticCode::InvalidArgument, "free surface placement requires a free definition", buildingId, {},
355 "building.free"));
356 }
357 const float planeX = patch.anchor.worldX;
358 const float planeY = world->getGrid().plane == grid::GridPlane::XZ ? patch.anchor.worldZ : patch.anchor.worldY;
359 const float elevation = world->getGrid().plane == grid::GridPlane::XZ ? patch.anchor.worldY : patch.anchor.worldZ;
360 std::string reason;
361 if (!canPlaceFree(world, buildingId, planeX, planeY, 0, &reason, std::numeric_limits<int>::min(), rotationDeg) ||
363 (def->maxSurfaceHeightDelta >= 0.f && patch.heightDelta > def->maxSurfaceHeightDelta)) {
364 if (reason.empty())
365 reason = patch.maxSlopeDegrees > def->maxSurfaceSlopeDegrees ? "surface_slope" : "surface_height_delta";
367 eve::Diagnostic::error(eve::DiagnosticCode::Conflict, "free surface placement rejected without mutation",
368 reason, {}, "building.free"));
369 }
370
372 placed.instanceId = nextInstanceId(*world);
373 placed.buildingId = buildingId;
374 placed.placementKind = "free";
375 placed.level = world->getActiveLevel();
376 placed.worldX = planeX;
377 placed.worldY = planeY;
378 placed.elevation = elevation;
379 placed.rotationDeg = normalizeRotation(buildingId, rotationDeg);
381 grid::worldToCell(*world->grid_, planeX, planeY, placed.originCellX, placed.originCellY, world->width_,
382 world->height_);
383 placed.channel = def->channel;
384 placed.tags = def->tags;
385 placed.surfaceId = patch.anchor.surfaceId;
386 placed.surfaceRevision = patch.anchor.surfaceRevision;
387 placed.surfaceNormalX = patch.anchor.normalX;
388 placed.surfaceNormalY = patch.anchor.normalY;
389 placed.surfaceNormalZ = patch.anchor.normalZ;
390 placed.surfaceTangentX = patch.anchor.tangentX;
391 placed.surfaceTangentY = patch.anchor.tangentY;
392 placed.surfaceTangentZ = patch.anchor.tangentZ;
393 placed.surfaceSampleCount = static_cast<int>(patch.samples.size());
394 placed.surfaceMaxSlopeDegrees = patch.maxSlopeDegrees;
395 placed.surfaceHeightDelta = patch.heightDelta;
396 world->buildings_[placed.instanceId] = placed;
397 world->instanceOrder_.push_back(placed.instanceId);
398
400 event.action = "place";
401 event.worldId = world->getId();
402 event.buildingId = buildingId;
403 event.instanceId = placed.instanceId;
404 event.cellX = placed.originCellX;
405 event.cellY = placed.originCellY;
406 event.level = placed.level;
407 event.rotationDeg = placed.rotationDeg;
408 event.worldX = placed.worldX;
409 event.worldY = placed.worldY;
410 event.elevation = placed.elevation;
411 event.channel = placed.channel;
412 if (world->publishEvents_) emit(std::move(event));
414}
415
416int PlacementSystem::placeFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY,
417 float elevation, float rotationDeg) {
418 auto result = placeFreeResult(world, buildingId, worldX, worldY, elevation, rotationDeg);
419 return result.ok() ? std::move(result).takeValue().instanceId : 0;
420}
421
423 const auto placedIt = world.buildings_.find(instanceId);
424 if (placedIt == world.buildings_.end() || placedIt->second.placementKind != "edge") return 0;
425 const PlacedBuilding &placed = placedIt->second;
426 const BuildingDefinition *def = BuildingRegistry::find(placed.buildingId);
427 if (!def) return 0;
428 const std::string group = def->connectionGroup.empty() ? def->id : def->connectionGroup;
429
430 auto occupantAt = [&](const EdgeAddress &edge) {
431 const auto *channels = world.findEdgeChannels(edge.axis, placed.level);
432 const bool inBounds = edge.axis == EdgeAxis::Horizontal
433 ? edge.x >= 0 && edge.x < world.width_ && edge.y >= 0 && edge.y <= world.height_
434 : edge.x >= 0 && edge.x <= world.width_ && edge.y >= 0 && edge.y < world.height_;
435 if (!channels || !inBounds) return 0;
436 const auto channelIt = channels->find(placed.channel);
437 if (channelIt == channels->end()) return 0;
438 const size_t index = edge.axis == EdgeAxis::Horizontal
439 ? size_t(edge.y) * size_t(world.width_) + size_t(edge.x)
440 : size_t(edge.y) * size_t(world.width_ + 1) + size_t(edge.x);
441 return index < channelIt->second.size() ? channelIt->second[index] : 0;
442 };
443 auto connects = [&](const EdgeAddress &edge) {
444 const int otherId = occupantAt(edge);
445 if (otherId == 0 || otherId == instanceId) return false;
446 const auto otherIt = world.buildings_.find(otherId);
447 if (otherIt == world.buildings_.end()) return false;
448 const BuildingDefinition *otherDef = BuildingRegistry::find(otherIt->second.buildingId);
449 if (!otherDef) return false;
450 const std::string otherGroup = otherDef->connectionGroup.empty() ? otherDef->id : otherDef->connectionGroup;
451 return group == otherGroup;
452 };
453
454 const EdgeAddress e = placed.edge;
456 if (e.axis == EdgeAxis::Horizontal) {
457 candidates[0] = {e.x - 1, e.y, EdgeAxis::Horizontal};
458 candidates[1] = {e.x + 1, e.y, EdgeAxis::Horizontal};
459 candidates[2] = {e.x, e.y - 1, EdgeAxis::Vertical};
460 candidates[3] = {e.x, e.y, EdgeAxis::Vertical};
461 candidates[4] = {e.x + 1, e.y - 1, EdgeAxis::Vertical};
462 candidates[5] = {e.x + 1, e.y, EdgeAxis::Vertical};
463 } else {
464 candidates[0] = {e.x, e.y - 1, EdgeAxis::Vertical};
465 candidates[1] = {e.x, e.y + 1, EdgeAxis::Vertical};
466 candidates[2] = {e.x - 1, e.y, EdgeAxis::Horizontal};
467 candidates[3] = {e.x, e.y, EdgeAxis::Horizontal};
468 candidates[4] = {e.x - 1, e.y + 1, EdgeAxis::Horizontal};
469 candidates[5] = {e.x, e.y + 1, EdgeAxis::Horizontal};
470 }
471 uint8_t mask = 0;
472 for (int i = 0; i < 6; ++i)
473 if (connects(candidates[i])) mask |= uint8_t(1u << i);
474 return mask;
475}
476
478 const uint8_t mask = edgeConnectionMask(world, instanceId);
479 int count = 0;
480 for (int bit = 0; bit < 6; ++bit)
481 if ((mask & uint8_t(1u << bit)) != 0) ++count;
482 if (count == 0) return "isolated";
483 if (count == 1) return "end";
484 if (count == 2) return (mask & 0x03u) == 0x03u ? "straight" : "corner";
485 if (count == 3) return "tee";
486 return "cross";
487}
488
489
490} // namespace eve::building
std::map< std::string, std::vector< Key >, std::less<> > channels
int mask
Stable, structured diagnostics shared by engine modules.
int instanceId
Pure cell/world projection helpers for GridConfig.
float elevation
bool required
Poco::JSON::Object::Ptr result
int level
RoadLaneDirection direction
std::map< std::array< int, 4 >, std::vector< const Subject * > > candidates
Definition Sensing.cpp:32
int count
AbilityActivationGroup group
bool placed
uint32_t index
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
static const BuildingDefinition * find(const std::string &id)
Finds .
Definition Building.cpp:557
static int placeFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY, float elevation=0.f, float rotationDeg=0.f)
Compatibility-only id projection; prefer placeFreeResult in C++.
static int placeCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY)
Compatibility-only id projection; prefer placeCornerResult in C++.
static eve::Result< PlacedBuilding > placeFreeSurfaceResult(PlacementWorld *world, const std::string &buildingId, const SurfacePatch &patch, float rotationDeg=0.f)
Atomically place a free object from an owning validated surface patch snapshot.
static bool containsFreePoint(const PlacedBuilding &placed, float worldX, float worldY)
Test a world-plane point against a committed circular or oriented-box footprint.
static std::string edgeVariant(const PlacementWorld &world, int instanceId)
Stable visual topology class: isolated/end/straight/corner/tee/cross.
static bool canPlaceFree(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min(), float rotationDeg=0.f)
Validate an exact free-domain world-plane anchor and circular or oriented-box footprint.
static float normalizeRotation(const std::string &buildingId, float rotationDeg)
规范化旋转角(cardinal → 0/90/180/270;none → 0)。
static eve::Result< PlacedBuilding > placeFreeResult(PlacementWorld *world, const std::string &buildingId, float worldX, float worldY, float elevation=0.f, float rotationDeg=0.f)
Atomically place a free-domain definition at an unsnapped world-plane anchor.
static bool canPlaceCorner(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate a corner-domain placement at one canonical grid vertex.
static uint8_t edgeConnectionMask(const PlacementWorld &world, int instanceId)
Compute compatible neighbouring edge topology.
static eve::Result< PlacedBuilding > placeCornerResult(PlacementWorld *world, const std::string &buildingId, int vertexX, int vertexY)
Atomically place a corner-domain definition.
static int placeEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, const std::string &direction)
Place an edge-domain definition, returning the new instance id or zero.
static eve::Result< EdgeAddress > canonicalEdge(int cellX, int cellY, const std::string &direction)
Normalize a cell-relative cardinal direction to a unique edge address.
static bool canPlaceEdge(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, const std::string &direction, int excludeInstanceId=0, std::string *reason=nullptr, int level=std::numeric_limits< int >::min())
Validate an edge-domain placement without mutating the world.
格子型建筑放置世界(脚本可直接操作)。
bool containsFreeFootprintPoint(const FreeFootprint &footprint, float x, float y)
FreeFootprint definitionFreeFootprint(const BuildingDefinition &definition, const PlacementWorld &world, float x, float y, float rotationDeg)
bool hasFreeEdgeOverlap(const PlacementWorld &world, const BuildingDefinition &freeDefinition, const FreeFootprint &footprint, const BuildingDefinition &edgeDefinition, EdgeAddress edge)
void applyDefinitionFreeFootprint(PlacedBuilding &placed, const BuildingDefinition &definition, const PlacementWorld &world)
FreeFootprint placedFreeFootprint(const PlacedBuilding &placed)
bool hasFreeFootprintOverlap(const FreeFootprint &a, const FreeFootprint &b)
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:10
void worldToCell(const GridConfig &cfg, float px, float py, int &cx, int &cy, int mapW, int mapH)
Maps planar coordinates to the nearest cell. Staggered/hex layouts use a bounded nearest-neighbor sea...
一次成功放置变更的事件(供脚本 poll / C++ hook)。
std::string action
place / remove / move / rotate
建筑模板(进程级注册表中的定义)。
std::string placementKind
Placement domain: cell (default), edge, corner, or free.
std::string channel
占地格子尺寸。
float maxSurfaceHeightDelta
Maximum elevation range across a sampled footprint; negative disables it.
float maxSurfaceSlopeDegrees
Maximum angle between a footprint normal and the grid-plane up axis.
std::string connectionGroup
Edge topology compatibility group; empty falls back to building id.
std::vector< std::string > tags
Canonical address of one logical grid vertex used by corner objects.
Canonical address of one grid edge.
已放置的建筑实例。
校验上下文:传给可插拔规则。
int level
Discrete floor whose occupancy and adjacency are queried.
Surface samples and continuity metrics for one rotated building footprint.
std::vector< SurfacePatchSample > samples