载入中...
搜索中...
未找到
Building.cpp
浏览该文件的文档.
1#include "building/Building.h"
2#include <algorithm>
3#include <cmath>
4#include <simplesquirrel/simplesquirrel.hpp>
7#include "common/Json.h"
8
9// Building.cpp
10namespace eve::building {
11void exposeHouseBindings(ssq::Table &table);
12
14
15int Building::registerBuildingsFromJson(const std::string &json) {
17 return BuildingRegistry::loadFromJson(json, nullptr);
18}
19
21
23
24bool Building::hasBuildingDefinition(const std::string &buildingId) {
25 return BuildingRegistry::find(buildingId) != nullptr;
26}
27
28std::string Building::getBuildingDisplayName(const std::string &buildingId) {
29 const auto *def = BuildingRegistry::find(buildingId);
30 return def ? def->displayName : std::string{};
31}
32
33std::string Building::getBuildingCategory(const std::string &buildingId) {
34 const auto *def = BuildingRegistry::find(buildingId);
35 return def ? def->category : std::string{};
36}
37
38int Building::getBuildingFootprintW(const std::string &buildingId) {
39 const auto *def = BuildingRegistry::find(buildingId);
40 return def ? def->footprintW : 0;
41}
42
43int Building::getBuildingFootprintH(const std::string &buildingId) {
44 const auto *def = BuildingRegistry::find(buildingId);
45 return def ? def->footprintH : 0;
46}
47
48std::string Building::getBuildingSnapMode(const std::string &buildingId) {
49 const auto *def = BuildingRegistry::find(buildingId);
50 return def ? def->snapMode : std::string{};
51}
52
53std::string Building::getBuildingRotationMode(const std::string &buildingId) {
54 const auto *def = BuildingRegistry::find(buildingId);
55 return def ? def->rotationMode : std::string{};
56}
57
58std::string Building::getBuildingValidateRule(const std::string &buildingId) {
59 const auto *def = BuildingRegistry::find(buildingId);
60 return def ? def->validateRule : std::string{};
61}
62
63std::string Building::getBuildingChannel(const std::string &buildingId) {
64 const auto *def = BuildingRegistry::find(buildingId);
65 return def ? def->channel : std::string{};
66}
67
68std::string Building::getBuildingRenderMode(const std::string &buildingId) {
69 const auto *def = BuildingRegistry::find(buildingId);
70 return def ? def->renderMode : std::string{};
71}
72
73std::string Building::getBuildingPlacementKind(const std::string &buildingId) {
74 const auto *def = BuildingRegistry::find(buildingId);
75 return def ? def->placementKind : std::string{};
76}
77
78std::string Building::getBuildingConnectionGroup(const std::string &buildingId) {
79 const auto *def = BuildingRegistry::find(buildingId);
80 return def ? def->connectionGroup : std::string{};
81}
82
83std::string Building::getBuildingVisual2d(const std::string &buildingId, const std::string &key,
84 const std::string &fallback) {
85 const auto *def = BuildingRegistry::find(buildingId);
86 return def ? def->getVisual2d(key, fallback) : fallback;
87}
88
89std::string Building::getBuildingVisual3d(const std::string &buildingId, const std::string &key,
90 const std::string &fallback) {
91 const auto *def = BuildingRegistry::find(buildingId);
92 return def ? def->getVisual3d(key, fallback) : fallback;
93}
94
95bool Building::buildingHasTag(const std::string &buildingId, const std::string &tag) {
96 const auto *def = BuildingRegistry::find(buildingId);
97 return def ? def->hasTag(tag) : false;
98}
99
100std::string Building::getBuildingExtra(const std::string &buildingId, const std::string &key,
101 const std::string &fallback) {
102 const auto *def = BuildingRegistry::find(buildingId);
103 return def ? def->getExtra(key, fallback) : fallback;
104}
105
106int Building::getBuildingCost(const std::string &buildingId, const std::string &resource) {
107 const auto *def = BuildingRegistry::find(buildingId);
108 return def ? def->getCost(resource, 0) : 0;
109}
110
111PlacementWorld *Building::newWorld(int width, int height, float cellSize) {
113 return new PlacementWorld(width, height, cellSize);
114}
115
120
125
126bool Building::hasValidateRule(const std::string &ruleName) { return PlacementSystem::hasValidateRule(ruleName); }
127
128bool Building::hasSnapRule(const std::string &ruleName) { return PlacementSystem::hasSnapRule(ruleName); }
129
130bool Building::hasSurface(const std::string &surfaceName) { return PlacementSystem::hasSurface(surfaceName); }
131
133
135 const auto names = PlacementSystem::surfaceNames();
136 if (index < 0 || index >= int(names.size())) return {};
137 return names[size_t(index)];
138}
139
141
143
145
147
148std::string Building::getChangeEventAction(int index) const {
149 const auto &evs = PlacementSystem::events();
150 if (index < 0 || size_t(index) >= evs.size()) return {};
151 return evs[size_t(index)].action;
152}
153
155 const auto &evs = PlacementSystem::events();
156 if (index < 0 || size_t(index) >= evs.size()) return {};
157 return evs[size_t(index)].worldId;
158}
159
161 const auto &evs = PlacementSystem::events();
162 if (index < 0 || size_t(index) >= evs.size()) return {};
163 return evs[size_t(index)].buildingId;
164}
165
167 const auto &evs = PlacementSystem::events();
168 if (index < 0 || size_t(index) >= evs.size()) return 0;
169 return evs[size_t(index)].instanceId;
170}
171
173 const auto &evs = PlacementSystem::events();
174 if (index < 0 || size_t(index) >= evs.size()) return -1;
175 return evs[size_t(index)].cellX;
176}
177
179 const auto &evs = PlacementSystem::events();
180 if (index < 0 || size_t(index) >= evs.size()) return -1;
181 return evs[size_t(index)].cellY;
182}
183
185 const auto &evs = PlacementSystem::events();
186 if (index < 0 || size_t(index) >= evs.size()) return -1;
187 return evs[size_t(index)].otherCellX;
188}
189
191 const auto &evs = PlacementSystem::events();
192 if (index < 0 || size_t(index) >= evs.size()) return -1;
193 return evs[size_t(index)].otherCellY;
194}
195
197 const auto &evs = PlacementSystem::events();
198 if (index < 0 || size_t(index) >= evs.size()) return 0.f;
199 return evs[size_t(index)].rotationDeg;
200}
201
202void Building::expose(ssq::Table &table) {
203 exposeHouseBindings(table);
204 auto cls = table.addClass(name, Building::create, false);
205 expose(cls);
206
207 auto world = table.addClass<PlacementWorld>(
208 "PlacementWorld",
209 std::function<PlacementWorld *(int, int, float)>(
210 [](int w, int h, float cs) -> PlacementWorld * { return new PlacementWorld(w, h, cs); }),
211 true);
212 world.addFunc("destroy", &PlacementWorld::destroy);
213 world.addFunc("getId", &PlacementWorld::getId);
214 world.addFunc("setId", &PlacementWorld::setId);
215 world.addFunc("getWidth", &PlacementWorld::getWidth);
216 world.addFunc("getHeight", &PlacementWorld::getHeight);
217 world.addFunc("getCellSize", &PlacementWorld::getCellSize);
218 world.addFunc("setCellSize", &PlacementWorld::setCellSize);
219 world.addFunc("getOriginX", &PlacementWorld::getOriginX);
220 world.addFunc("getOriginY", &PlacementWorld::getOriginY);
221 world.addFunc("setOrigin", &PlacementWorld::setOrigin);
222 world.addFunc("getFloorHeight", &PlacementWorld::getFloorHeight);
223 world.addFunc("setFloorHeight", &PlacementWorld::setFloorHeight);
224 world.addFunc("getActiveLevel", &PlacementWorld::getActiveLevel);
225 world.addFunc("setActiveLevel", &PlacementWorld::setActiveLevel);
226 world.addFunc("getSnapMode", &PlacementWorld::getSnapMode);
227 world.addFunc("setSnapMode", &PlacementWorld::setSnapMode);
228 world.addFunc("getValidateRule", &PlacementWorld::getValidateRule);
229 world.addFunc("setValidateRule", &PlacementWorld::setValidateRule);
230 world.addFunc("setGridLayout", &PlacementWorld::setGridLayout);
231 world.addFunc("getGridLayoutName", &PlacementWorld::getGridLayoutName);
232 world.addFunc("setGridPlane", &PlacementWorld::setGridPlane);
233 world.addFunc("getGridPlaneName", &PlacementWorld::getGridPlaneName);
234 world.addFunc("setCellGap", &PlacementWorld::setCellGap);
235 world.addFunc("setHexSideLength", &PlacementWorld::setHexSideLength);
236 world.addFunc("setStagger", &PlacementWorld::setStagger);
237 world.addFunc("setGridFromLayer", &PlacementWorld::setGridFromLayer);
238 world.addFunc("hasGridFromLayer", &PlacementWorld::hasGridFromLayer);
239 world.addFunc("setExtra", &PlacementWorld::setExtra);
240 world.addFunc("getExtra", &PlacementWorld::getExtra);
241 world.addFunc("worldToCellX", &PlacementWorld::worldToCellX);
242 world.addFunc("worldToCellY", &PlacementWorld::worldToCellY);
243 world.addFunc("cellToWorldX", &PlacementWorld::cellToWorldX);
244 world.addFunc("cellToWorldY", &PlacementWorld::cellToWorldY);
245 world.addFunc("cellToWorld3DX", &PlacementWorld::cellToWorld3DX);
246 world.addFunc("cellToWorld3DY", &PlacementWorld::cellToWorld3DY);
247 world.addFunc("cellToWorld3DZ", &PlacementWorld::cellToWorld3DZ);
248 world.addFunc("worldToCell3DX", &PlacementWorld::worldToCell3DX);
249 world.addFunc("worldToCell3DY", &PlacementWorld::worldToCell3DY);
250 world.addFunc("fillTerrain", &PlacementWorld::fillTerrain);
251 world.addFunc("setTerrain", &PlacementWorld::setTerrain);
252 world.addFunc("getTerrain", &PlacementWorld::getTerrain);
253 world.addFunc("inBounds", &PlacementWorld::inBounds);
254 world.addFunc("bindTileLayer", &PlacementWorld::bindTileLayer);
255 world.addFunc("getTileLayer", &PlacementWorld::getTileLayer);
256 world.addFunc("clearTileLayer", &PlacementWorld::clearTileLayer);
257 world.addFunc("setTerrainGidMapJson", &PlacementWorld::setTerrainGidMapJson);
258 world.addFunc("setTerrainGid", &PlacementWorld::setTerrainGid);
259 world.addFunc("clearTerrainGidMap", &PlacementWorld::clearTerrainGidMap);
260 world.addFunc("getOccupant", &PlacementWorld::getOccupant);
261 world.addFunc("getOccupantInChannel", &PlacementWorld::getOccupantInChannel);
262 world.addFunc("getOccupantAtLevel", &PlacementWorld::getOccupantAtLevel);
263 world.addFunc("getAnyOccupant", &PlacementWorld::getAnyOccupant);
264 world.addFunc("getAnyOccupantAtLevel", &PlacementWorld::getAnyOccupantAtLevel);
265 world.addFunc("isCellEmpty", &PlacementWorld::isCellEmpty);
266 world.addFunc("isCellEmptyInChannel", &PlacementWorld::isCellEmptyInChannel);
267 world.addFunc("getEdgeOccupant", &PlacementWorld::getEdgeOccupant);
268 world.addFunc("getEdgeOccupantAtLevel", &PlacementWorld::getEdgeOccupantAtLevel);
269 world.addFunc("isEdgeEmpty", &PlacementWorld::isEdgeEmpty);
270 world.addFunc("getEdgeConnectionMask", &PlacementWorld::getEdgeConnectionMask);
271 world.addFunc("getEdgeVariant", &PlacementWorld::getEdgeVariant);
272 world.addFunc("getBuildingCount", &PlacementWorld::getBuildingCount);
273 world.addFunc("hasBuilding", &PlacementWorld::hasBuilding);
274 world.addFunc("getBuildingId", &PlacementWorld::getBuildingId);
275 world.addFunc("getBuildingCellX", &PlacementWorld::getBuildingCellX);
276 world.addFunc("getBuildingCellY", &PlacementWorld::getBuildingCellY);
277 world.addFunc("getBuildingWorldX", &PlacementWorld::getBuildingWorldX);
278 world.addFunc("getBuildingWorldY", &PlacementWorld::getBuildingWorldY);
279 world.addFunc("getBuildingWorldZ", &PlacementWorld::getBuildingWorldZ);
280 world.addFunc("getBuildingElevation", &PlacementWorld::getBuildingElevation);
281 world.addFunc("getBuildingLevel", &PlacementWorld::getBuildingLevel);
282 world.addFunc("getBuildingSupportCount", &PlacementWorld::getBuildingSupportCount);
283 world.addFunc("getBuildingSupportAt", &PlacementWorld::getBuildingSupportAt);
284 world.addFunc("getBuildingDependentCount", &PlacementWorld::getBuildingDependentCount);
285 world.addFunc("getBuildingSurfaceId", &PlacementWorld::getBuildingSurfaceId);
286 world.addFunc("getBuildingSurfaceRevision", &PlacementWorld::getBuildingSurfaceRevision);
287 world.addFunc("getBuildingSurfaceNormalX", &PlacementWorld::getBuildingSurfaceNormalX);
288 world.addFunc("getBuildingSurfaceNormalY", &PlacementWorld::getBuildingSurfaceNormalY);
289 world.addFunc("getBuildingSurfaceNormalZ", &PlacementWorld::getBuildingSurfaceNormalZ);
290 world.addFunc("getBuildingChannel", &PlacementWorld::getBuildingChannel);
291 world.addFunc("getBuildingRotation", &PlacementWorld::getBuildingRotation);
292 world.addFunc("getBuildingProp", &PlacementWorld::getBuildingProp);
293 world.addFunc("setBuildingProp", &PlacementWorld::setBuildingProp);
294 world.addFunc("buildingHasTag", &PlacementWorld::buildingHasTag);
295 world.addFunc("getBuildingInstanceAt", &PlacementWorld::getBuildingInstanceAt);
296 world.addFunc("canPlace", &PlacementWorld::canPlace);
297 world.addFunc("canPlaceReason", &PlacementWorld::canPlaceReason);
298 world.addFunc("placeAt", &PlacementWorld::placeAt);
299 world.addFunc("placeAtWorld", &PlacementWorld::placeAtWorld);
300 world.addFunc("placeAtWorld3D", &PlacementWorld::placeAtWorld3D);
301 world.addFunc("placeGhost", &PlacementWorld::placeGhost);
302 world.addFunc("placeEdge", &PlacementWorld::placeEdge);
303 world.addFunc("canPlaceEdge", &PlacementWorld::canPlaceEdge);
304 world.addFunc("canPlaceEdgeReason", &PlacementWorld::canPlaceEdgeReason);
305 world.addFunc("placeCorner", &PlacementWorld::placeCorner);
306 world.addFunc("canPlaceCorner", &PlacementWorld::canPlaceCorner);
307 world.addFunc("canPlaceCornerReason", &PlacementWorld::canPlaceCornerReason);
308 world.addFunc("getCornerOccupant", &PlacementWorld::getCornerOccupant);
309 world.addFunc("getCornerOccupantAtLevel", &PlacementWorld::getCornerOccupantAtLevel);
310 world.addFunc("isCornerEmpty", &PlacementWorld::isCornerEmpty);
311 world.addFunc("placeFree", &PlacementWorld::placeFree);
312 world.addFunc("canPlaceFree", &PlacementWorld::canPlaceFree);
313 world.addFunc("canPlaceFreeReason", &PlacementWorld::canPlaceFreeReason);
314 world.addFunc("getFreeOccupant", &PlacementWorld::getFreeOccupant);
315 world.addFunc("getFreeOccupantAtLevel", &PlacementWorld::getFreeOccupantAtLevel);
316 world.addFunc("removeBuilding", &PlacementWorld::removeBuilding);
317 world.addFunc("canRemoveBuildingReason", &PlacementWorld::canRemoveBuildingReason);
318 world.addFunc("removeBuildingCascade", &PlacementWorld::removeBuildingCascade);
319 world.addFunc("moveBuilding", &PlacementWorld::moveBuilding);
320 world.addFunc("clearBuildings", &PlacementWorld::clearBuildings);
321
322 auto ghost =
323 table.addClass<Ghost>("Ghost", std::function<Ghost *()>([]() -> Ghost * { return new Ghost(); }), true);
324 ghost.addFunc("destroy", &Ghost::destroy);
325 ghost.addFunc("getBuildingId", &Ghost::getBuildingId);
326 ghost.addFunc("setBuildingId", &Ghost::setBuildingId);
327 ghost.addFunc("getCellX", &Ghost::getCellX);
328 ghost.addFunc("getCellY", &Ghost::getCellY);
329 ghost.addFunc("setCell", &Ghost::setCell);
330 ghost.addFunc("getWorldX", &Ghost::getWorldX);
331 ghost.addFunc("getWorldY", &Ghost::getWorldY);
332 ghost.addFunc("setWorld", &Ghost::setWorld);
333 ghost.addFunc("getElevation", &Ghost::getElevation);
334 ghost.addFunc("setElevation", &Ghost::setElevation);
335 ghost.addFunc("getRotationDeg", &Ghost::getRotationDeg);
336 ghost.addFunc("setRotationDeg", &Ghost::setRotationDeg);
337 ghost.addFunc("rotateBy", &Ghost::rotateBy);
338 ghost.addFunc("getPlacementKind", &Ghost::getPlacementKind);
339 ghost.addFunc("getEdgeAxis", &Ghost::getEdgeAxis);
340 ghost.addFunc("setEdge", &Ghost::setEdge);
341 ghost.addFunc("setCorner", &Ghost::setCorner);
342 ghost.addFunc("setFree", &Ghost::setFree);
343 ghost.addFunc("isValid", &Ghost::isValid);
344 ghost.addFunc("getReason", &Ghost::getReason);
345 ghost.addFunc("getSurfaceId", &Ghost::getSurfaceId);
346 ghost.addFunc("getSurfaceRevision", &Ghost::getSurfaceRevision);
347 ghost.addFunc("getSurfaceNormalX", &Ghost::getSurfaceNormalX);
348 ghost.addFunc("getSurfaceNormalY", &Ghost::getSurfaceNormalY);
349 ghost.addFunc("getSurfaceNormalZ", &Ghost::getSurfaceNormalZ);
350 ghost.addFunc("getSurfaceTangentX", &Ghost::getSurfaceTangentX);
351 ghost.addFunc("getSurfaceTangentY", &Ghost::getSurfaceTangentY);
352 ghost.addFunc("getSurfaceTangentZ", &Ghost::getSurfaceTangentZ);
353 ghost.addFunc("getSurfaceSampleCount", &Ghost::getSurfaceSampleCount);
354 ghost.addFunc("getSurfaceMaxSlopeDegrees", &Ghost::getSurfaceMaxSlopeDegrees);
355 ghost.addFunc("getSurfaceHeightDelta", &Ghost::getSurfaceHeightDelta);
356 ghost.addFunc("setFromWorld", &Ghost::setFromWorld);
357 ghost.addFunc("setFromWorld3D", &Ghost::setFromWorld3D);
358 ghost.addFunc("setFromSurface", &Ghost::setFromSurface);
359 ghost.addFunc("validate", &Ghost::validate);
360
361 auto session = table.addClass<PlacementSession>(
362 "PlacementSession",
363 std::function<PlacementSession *()>([]() -> PlacementSession * { return new PlacementSession(); }), true);
364 session.addFunc("destroy", &PlacementSession::destroy);
365 session.addFunc("startPlacement", &PlacementSession::startPlacement);
366 session.addFunc("stopPlacement", &PlacementSession::stopPlacement);
367 session.addFunc("isActive", &PlacementSession::isActive);
368 session.addFunc("getBuildingId", &PlacementSession::getBuildingId);
369 session.addFunc("getGhost", &PlacementSession::getGhost);
370 session.addFunc("setMode", &PlacementSession::setMode);
371 session.addFunc("getMode", &PlacementSession::getMode);
372 session.addFunc("setRotationDeg", &PlacementSession::setRotationDeg);
373 session.addFunc("rotateBy", &PlacementSession::rotateBy);
374 session.addFunc("getRotationDeg", &PlacementSession::getRotationDeg);
375 session.addFunc("updateFromWorld", &PlacementSession::updateFromWorld);
376 session.addFunc("updateFromWorld3D", &PlacementSession::updateFromWorld3D);
377 session.addFunc("updateFromSurface", &PlacementSession::updateFromSurface);
378 session.addFunc("updateEdge", &PlacementSession::updateEdge);
379 session.addFunc("updateCorner", &PlacementSession::updateCorner);
380 session.addFunc("updateFree", &PlacementSession::updateFree);
381 session.addFunc("isValid", &PlacementSession::isValid);
382 session.addFunc("getReason", &PlacementSession::getReason);
383 session.addFunc("execute", &PlacementSession::execute);
384 session.addFunc("executeEdgeLine", &PlacementSession::executeEdgeLine);
385 session.addFunc("beginEdgePath", &PlacementSession::beginEdgePath);
386 session.addFunc("appendEdgePathVertex", &PlacementSession::appendEdgePathVertex);
387 session.addFunc("executeEdgePath", &PlacementSession::executeEdgePath);
388 session.addFunc("getEdgePathVertexCount", &PlacementSession::getEdgePathVertexCount);
389 session.addFunc("beginEdgeCurve", &PlacementSession::beginEdgeCurve);
390 session.addFunc("appendEdgeCurveControlPoint", &PlacementSession::appendEdgeCurveControlPoint);
391 session.addFunc("executeEdgeCurve", &PlacementSession::executeEdgeCurve);
392 session.addFunc("executeEdgeCurveOnSurface", &PlacementSession::executeEdgeCurveOnSurface);
393 session.addFunc("getEdgeCurveControlPointCount", &PlacementSession::getEdgeCurveControlPointCount);
394 session.addFunc("getLastPlacedCount", &PlacementSession::getLastPlacedCount);
395 session.addFunc("getLastPlacedId", &PlacementSession::getLastPlacedId);
396 session.addFunc("executeMove", &PlacementSession::executeMove);
397 session.addFunc("executeReplace", &PlacementSession::executeReplace);
398 session.addFunc("getLastEditedId", &PlacementSession::getLastEditedId);
399 session.addFunc("previewRectangle", &PlacementSession::previewRectangle);
400 session.addFunc("previewBrush", &PlacementSession::previewBrush);
401 session.addFunc("executeRectangle", &PlacementSession::executeRectangle);
402 session.addFunc("executeBrush", &PlacementSession::executeBrush);
403 session.addFunc("getAreaPreviewCount", &PlacementSession::getAreaPreviewCount);
404 session.addFunc("getAreaPreviewCellX", &PlacementSession::getAreaPreviewCellX);
405 session.addFunc("getAreaPreviewCellY", &PlacementSession::getAreaPreviewCellY);
406 session.addFunc("getAreaPreviewAccepted", &PlacementSession::getAreaPreviewAccepted);
407 session.addFunc("getAreaPreviewReason", &PlacementSession::getAreaPreviewReason);
408 session.addFunc("beginPattern", &PlacementSession::beginPattern);
409 session.addFunc("appendPatternPoint", &PlacementSession::appendPatternPoint);
410 session.addFunc("setPatternRadius", &PlacementSession::setPatternRadius);
411 session.addFunc("setPatternSubdivisions", &PlacementSession::setPatternSubdivisions);
412 session.addFunc("setPatternSurface", &PlacementSession::setPatternSurface);
413 session.addFunc("previewPattern", &PlacementSession::previewPattern);
414 session.addFunc("executePattern", &PlacementSession::executePattern);
415 session.addFunc("getPatternKind", &PlacementSession::getPatternKind);
416 session.addFunc("getPatternPointCount", &PlacementSession::getPatternPointCount);
417 session.addFunc("getPatternPreviewCount", &PlacementSession::getPatternPreviewCount);
418 session.addFunc("getPatternPreviewX", &PlacementSession::getPatternPreviewX);
419 session.addFunc("getPatternPreviewY", &PlacementSession::getPatternPreviewY);
420 session.addFunc("getPatternPreviewAxis", &PlacementSession::getPatternPreviewAxis);
421 session.addFunc("getPatternPreviewAccepted", &PlacementSession::getPatternPreviewAccepted);
422 session.addFunc("getPatternPreviewReason", &PlacementSession::getPatternPreviewReason);
423}
424
425void Building::expose(ssq::Class &cls) {
426 cls.addFunc("registerBuildingsFromJson", &Building::registerBuildingsFromJson);
427 cls.addFunc("clearBuildingDefinitions", &Building::clearBuildingDefinitions);
428 cls.addFunc("getBuildingDefinitionCount", &Building::getBuildingDefinitionCount);
429 cls.addFunc("hasBuildingDefinition", &Building::hasBuildingDefinition);
430 cls.addFunc("getBuildingDisplayName", &Building::getBuildingDisplayName);
431 cls.addFunc("getBuildingCategory", &Building::getBuildingCategory);
432 cls.addFunc("getBuildingFootprintW", &Building::getBuildingFootprintW);
433 cls.addFunc("getBuildingFootprintH", &Building::getBuildingFootprintH);
434 cls.addFunc("getBuildingSnapMode", &Building::getBuildingSnapMode);
435 cls.addFunc("getBuildingRotationMode", &Building::getBuildingRotationMode);
436 cls.addFunc("getBuildingValidateRule", &Building::getBuildingValidateRule);
437 cls.addFunc("getBuildingChannel", &Building::getBuildingChannel);
438 cls.addFunc("getBuildingRenderMode", &Building::getBuildingRenderMode);
439 cls.addFunc("getBuildingPlacementKind", &Building::getBuildingPlacementKind);
440 cls.addFunc("getBuildingConnectionGroup", &Building::getBuildingConnectionGroup);
441 cls.addFunc("getBuildingVisual2d", &Building::getBuildingVisual2d);
442 cls.addFunc("getBuildingVisual3d", &Building::getBuildingVisual3d);
443 cls.addFunc("buildingHasTag", &Building::buildingHasTag);
444 cls.addFunc("getBuildingExtra", &Building::getBuildingExtra);
445 cls.addFunc("getBuildingCost", &Building::getBuildingCost);
446 cls.addFunc("newWorld", &Building::newWorld);
447 cls.addFunc("newGhost", &Building::newGhost);
448 cls.addFunc("newSession", &Building::newSession);
449 cls.addFunc("hasValidateRule", &Building::hasValidateRule);
450 cls.addFunc("hasSnapRule", &Building::hasSnapRule);
451 cls.addFunc("hasSurface", &Building::hasSurface);
452 cls.addFunc("getSurfaceCount", &Building::getSurfaceCount);
453 cls.addFunc("getSurfaceName", &Building::getSurfaceName);
454 cls.addFunc("setPlaneSurfaceHeight", &Building::setPlaneSurfaceHeight);
455 cls.addFunc("getPlaneSurfaceHeight", &Building::getPlaneSurfaceHeight);
456 cls.addFunc("clearChangeEvents", &Building::clearChangeEvents);
457 cls.addFunc("getChangeEventCount", &Building::getChangeEventCount);
458 cls.addFunc("getChangeEventAction", &Building::getChangeEventAction);
459 cls.addFunc("getChangeEventWorldId", &Building::getChangeEventWorldId);
460 cls.addFunc("getChangeEventBuildingId", &Building::getChangeEventBuildingId);
461 cls.addFunc("getChangeEventInstanceId", &Building::getChangeEventInstanceId);
462 cls.addFunc("getChangeEventCellX", &Building::getChangeEventCellX);
463 cls.addFunc("getChangeEventCellY", &Building::getChangeEventCellY);
464 cls.addFunc("getChangeEventOtherCellX", &Building::getChangeEventOtherCellX);
465 cls.addFunc("getChangeEventOtherCellY", &Building::getChangeEventOtherCellY);
466 cls.addFunc("getChangeEventRotation", &Building::getChangeEventRotation);
467}
468
469} // namespace eve::building
470
471// BuildingDef.cpp
472namespace eve::building {
473
474using eve::json::Value;
475
476namespace {
477bool validConvexPolygon(const std::vector<float> &vertices);
478}
479
480bool BuildingDefinition::hasTag(const std::string &tag) const {
481 return std::find(tags.begin(), tags.end(), tag) != tags.end();
482}
483
484std::string BuildingDefinition::getExtra(const std::string &key, const std::string &fallback) const {
485 auto it = extra.find(key);
486 return it == extra.end() ? fallback : it->second;
487}
488
489std::string BuildingDefinition::getVisual2d(const std::string &key, const std::string &fallback) const {
490 auto it = visual2d.find(key);
491 return it == visual2d.end() ? fallback : it->second;
492}
493
494std::string BuildingDefinition::getVisual3d(const std::string &key, const std::string &fallback) const {
495 auto it = visual3d.find(key);
496 return it == visual3d.end() ? fallback : it->second;
497}
498
499int BuildingDefinition::getCost(const std::string &resource, int fallback) const {
500 auto it = cost.find(resource);
501 return it == cost.end() ? fallback : it->second;
502}
503
504bool BuildingDefinition::maskAt(int localX, int localY) const {
505 if (localX < 0 || localY < 0 || localX >= footprintW || localY >= footprintH) return false;
506 if (footprintMask.empty()) return true;
507 const size_t idx = size_t(localY) * size_t(footprintW) + size_t(localX);
508 if (idx >= footprintMask.size()) return false;
509 return footprintMask[idx] != 0;
510}
511
512bool PlacedBuilding::hasTag(const std::string &tag) const {
513 return std::find(tags.begin(), tags.end(), tag) != tags.end();
514}
515
516std::string PlacedBuilding::getProp(const std::string &key, const std::string &fallback) const {
517 auto it = props.find(key);
518 return it == props.end() ? fallback : it->second;
519}
520
521void PlacedBuilding::setProp(const std::string &key, const std::string &value) { props[key] = value; }
522
523std::unordered_map<std::string, BuildingDefinition> &BuildingRegistry::table() {
524 static std::unordered_map<std::string, BuildingDefinition> t;
525 return t;
526}
527
529 if (def.id.empty()) return;
530 BuildingDefinition copy = def;
531 if (copy.footprintW <= 0) copy.footprintW = 1;
532 if (copy.footprintH <= 0) copy.footprintH = 1;
533 if (copy.displayName.empty()) copy.displayName = copy.id;
534 if (copy.snapMode.empty()) copy.snapMode = "grid";
535 if (copy.rotationMode.empty()) copy.rotationMode = "cardinal";
536 if (copy.validateRule.empty()) copy.validateRule = "default";
537 if (copy.placementKind != "edge" && copy.placementKind != "corner" && copy.placementKind != "free")
538 copy.placementKind = "cell";
539 if (!std::isfinite(copy.edgeThicknessCells) || copy.edgeThicknessCells < 0.f) copy.edgeThicknessCells = 0.f;
540 if (!std::isfinite(copy.freeRadiusCells) || copy.freeRadiusCells <= 0.f) copy.freeRadiusCells = 0.25f;
541 if (!std::isfinite(copy.freeFootprintWidthCells) || copy.freeFootprintWidthCells <= 0.f ||
542 !std::isfinite(copy.freeFootprintHeightCells) || copy.freeFootprintHeightCells <= 0.f) {
543 copy.freeFootprintWidthCells = 0.f;
544 copy.freeFootprintHeightCells = 0.f;
545 }
546 if (!copy.freeFootprintVertices.empty() && !validConvexPolygon(copy.freeFootprintVertices))
547 copy.freeFootprintVertices.clear();
548 if (copy.supportMode != "cell_below" && copy.supportMode != "corner_below") copy.supportMode = "none";
549 copy.maxSurfaceSlopeDegrees = std::clamp(copy.maxSurfaceSlopeDegrees, 0.f, 180.f);
550 const size_t expected = size_t(copy.footprintW) * size_t(copy.footprintH);
551 if (!copy.footprintMask.empty() && copy.footprintMask.size() != expected) {
552 copy.footprintMask.clear(); // 长度不匹配时回退实心矩形
553 }
554 table()[copy.id] = std::move(copy);
555}
556
557const BuildingDefinition *BuildingRegistry::find(const std::string &id) {
558 auto &t = table();
559 auto it = t.find(id);
560 return it == t.end() ? nullptr : &it->second;
561}
562
563bool BuildingRegistry::remove(const std::string &id) { return table().erase(id) > 0; }
564
565void BuildingRegistry::clear() { table().clear(); }
566
567int BuildingRegistry::count() { return int(table().size()); }
568
569namespace {
570
571bool validConvexPolygon(const std::vector<float> &vertices) {
572 if (vertices.size() < 6 || vertices.size() % 2 != 0 || vertices.size() > 128) return false;
573 float winding = 0.f;
574 const size_t count = vertices.size() / 2;
575 for (size_t i = 0; i < count; ++i) {
576 const size_t next = (i + 1) % count;
577 const size_t after = (i + 2) % count;
578 const float ax = vertices[next * 2] - vertices[i * 2];
579 const float ay = vertices[next * 2 + 1] - vertices[i * 2 + 1];
580 const float bx = vertices[after * 2] - vertices[next * 2];
581 const float by = vertices[after * 2 + 1] - vertices[next * 2 + 1];
582 if (!std::isfinite(vertices[i * 2]) || !std::isfinite(vertices[i * 2 + 1])) return false;
583 const float cross = ax * by - ay * bx;
584 if (std::fabs(cross) <= 1e-5f) continue;
585 if (winding == 0.f)
586 winding = cross;
587 else if (cross * winding < 0.f)
588 return false;
589 }
590 return winding != 0.f;
591}
592
593BuildingDefinition parseBuildingObject(Value o) {
594 BuildingDefinition def;
595 if (!o.isObject()) return def;
596 def.id = o.getString("id");
597 def.displayName = o.getString("displayName", def.id);
598 def.category = o.getString("category");
599 def.channel = o.getString("channel");
600 def.renderMode = o.getString("renderMode");
601 def.placementKind = o.getString("placementKind", "cell");
602 def.freeRadiusCells = o.getFloat("freeRadiusCells", 0.25f);
603 def.freeFootprintWidthCells = o.getFloat("freeFootprintWidthCells", 0.f);
604 def.freeFootprintHeightCells = o.getFloat("freeFootprintHeightCells", 0.f);
605 def.freeFootprintVertices = o.getFloatArray("freeFootprintVertices");
606 def.connectionGroup = o.getString("connectionGroup");
607 def.edgeThicknessCells = o.getFloat("edgeThicknessCells", 0.f);
608 def.blockedByEdgeChannels = o.getStringArray("blockedByEdgeChannels");
609 def.structuralRole = o.getString("structuralRole");
610 def.supportMode = o.getString("supportMode", "none");
611 def.supportTag = o.getString("supportTag");
612 def.footprintW = o.getInt("footprintW", 1);
613 def.footprintH = o.getInt("footprintH", 1);
614 def.snapMode = o.getString("snapMode", "grid");
615 def.rotationMode = o.getString("rotationMode", "cardinal");
616 def.validateRule = o.getString("validateRule", "default");
617 def.maxSurfaceSlopeDegrees = o.getFloat("maxSurfaceSlopeDegrees", 180.f);
618 def.maxSurfaceHeightDelta = o.getFloat("maxSurfaceHeightDelta", -1.f);
619 def.tags = o.getStringArray("tags");
620 def.requireTerrain = o.getIntArray("requireTerrain");
621 def.forbidTerrain = o.getIntArray("forbidTerrain");
622 def.requireAdjacentTag = o.getString("requireAdjacentTag");
623 def.requireAdjacentTerrain = o.getInt("requireAdjacentTerrain", -1);
624 def.cost = o.getIntMap("cost");
625 def.extra = o.getStringMap("extra");
626 def.visual2d = o.getStringMap("visual2d");
627 def.visual3d = o.getStringMap("visual3d");
628
629 const Value mask = o.get("footprintMask");
630 def.footprintMask.reserve(mask.size());
631 for (size_t i = 0; i < mask.size(); ++i) def.footprintMask.push_back(uint8_t(mask.at(i).asInt(0) != 0 ? 1 : 0));
632 return def;
633}
634
635} // namespace
636
637int BuildingRegistry::loadFromJson(const std::string &json, std::string *error) {
638 std::string err;
639 const eve::json::Document doc = eve::json::Document::parse(json, &err);
640 if (!doc.valid()) {
641 if (error) *error = err.empty() ? "invalid json" : err;
642 return 0;
643 }
644
645 const Value root = doc.root();
646 int n = 0;
647 if (root.isArray()) {
648 for (size_t i = 0; i < root.size(); ++i) {
649 BuildingDefinition def = parseBuildingObject(root.at(i));
650 if (def.id.empty()) continue;
651 registerBuilding(def);
652 ++n;
653 }
654 } else if (root.isObject()) {
655 BuildingDefinition def = parseBuildingObject(root);
656 if (!def.id.empty()) {
657 registerBuilding(def);
658 ++n;
659 }
660 }
661 return n;
662}
663
664} // namespace eve::building
float w
Definition AnimClip.cpp:738
int root
Definition AnimSmr.cpp:119
int mask
HSQOBJECT cls
Definition ECS.cpp:39
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
glm::vec3 n
Definition Grass.cpp:63
int h
std::uint32_t height
std::uint32_t width
const std::string * tag
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:27
std::string error
Definition Package.cpp:174
int idx
Object::Ptr value
float t
std::string resource
int count
std::optional< InteractionSession > session
Definition Tactics.cpp:39
std::array< double, 2 > vertices[3]
float size
Definition TreeMesh.cpp:158
uint32_t index
static void clear()
Clears .
Definition Building.cpp:565
static int count()
Returns the number of .
Definition Building.cpp:567
static void registerBuilding(const BuildingDefinition &def)
Registers building.
Definition Building.cpp:528
static int loadFromJson(const std::string &json, std::string *error=nullptr)
从 JSON 数组或单对象批量注册,返回成功数量。 元素形如: { "id": "house.wood", "displayName": "木屋", "category": "housing",...
Definition Building.cpp:637
static const BuildingDefinition * find(const std::string &id)
Finds .
Definition Building.cpp:557
static bool remove(const std::string &id)
Removes .
Definition Building.cpp:563
建筑放置模块(eve.Building)。
Definition Building.h:20
std::string getBuildingRotationMode(const std::string &buildingId)
Returns the building rotation mode.
Definition Building.cpp:53
int registerBuildingsFromJson(const std::string &json)
从 JSON 注册建筑模板;返回成功注册数量。
Definition Building.cpp:15
bool hasSnapRule(const std::string &name)
True when snap rule.
Definition Building.cpp:128
int getChangeEventInstanceId(int index) const
Returns the change event instance id.
Definition Building.cpp:166
std::string getBuildingDisplayName(const std::string &buildingId)
Returns the building display name.
Definition Building.cpp:28
void setPlaneSurfaceHeight(float h)
Sets the plane surface height.
Definition Building.cpp:140
std::string getBuildingConnectionGroup(const std::string &buildingId)
Definition edge connection group, or empty when it falls back to id.
Definition Building.cpp:78
std::string getChangeEventBuildingId(int index) const
Returns the change event building id.
Definition Building.cpp:160
std::string getBuildingVisual3d(const std::string &buildingId, const std::string &key, const std::string &fallback={})
Returns the building visual 3 d.
Definition Building.cpp:89
bool hasValidateRule(const std::string &name)
扩展规则是否存在(校验/吸附)。
Definition Building.cpp:126
float getChangeEventRotation(int index) const
Returns the change event rotation.
Definition Building.cpp:196
int getBuildingFootprintW(const std::string &buildingId)
Returns the building footprint w.
Definition Building.cpp:38
int getSurfaceCount()
Returns the surface count.
Definition Building.cpp:132
void clearBuildingDefinitions()
清空全部建筑模板。
Definition Building.cpp:20
std::string getBuildingSnapMode(const std::string &buildingId)
Returns the building snap mode.
Definition Building.cpp:48
std::string getBuildingExtra(const std::string &buildingId, const std::string &key, const std::string &fallback={})
Returns the building extra.
Definition Building.cpp:100
bool buildingHasTag(const std::string &buildingId, const std::string &tag)
Building has tag.
Definition Building.cpp:95
float getPlaneSurfaceHeight()
Returns the plane surface height.
Definition Building.cpp:142
int getChangeEventCellY(int index) const
Returns the change event cell y.
Definition Building.cpp:178
int getBuildingCost(const std::string &buildingId, const std::string &resource)
Returns the building cost.
Definition Building.cpp:106
std::string getBuildingCategory(const std::string &buildingId)
Returns the building category.
Definition Building.cpp:33
std::string getBuildingChannel(const std::string &buildingId)
Returns the building channel.
Definition Building.cpp:63
PlacementSession * newSession()
Creates a session. @ownership Caller deletes unless documented otherwise.
Definition Building.cpp:121
std::string getChangeEventAction(int index) const
Returns the change event action.
Definition Building.cpp:148
int getChangeEventCellX(int index) const
Returns the change event cell x.
Definition Building.cpp:172
std::string getChangeEventWorldId(int index) const
Returns the change event world id.
Definition Building.cpp:154
int getBuildingFootprintH(const std::string &buildingId)
Returns the building footprint h.
Definition Building.cpp:43
std::string getBuildingVisual2d(const std::string &buildingId, const std::string &key, const std::string &fallback={})
Returns the building visual 2 d.
Definition Building.cpp:83
void clearChangeEvents()
变更事件队列(放置/移除/移动)。
Definition Building.cpp:144
std::string getBuildingRenderMode(const std::string &buildingId)
Returns the building render mode.
Definition Building.cpp:68
int getChangeEventOtherCellY(int index) const
Returns the change event other cell y.
Definition Building.cpp:190
std::string getSurfaceName(int index)
Returns the surface name.
Definition Building.cpp:134
int getChangeEventCount() const
Returns the change event count.
Definition Building.cpp:146
bool hasSurface(const std::string &name)
True when surface.
Definition Building.cpp:130
std::string getBuildingValidateRule(const std::string &buildingId)
Returns the building validate rule.
Definition Building.cpp:58
bool hasBuildingDefinition(const std::string &buildingId)
建筑模板查询(显示名/类别/占地/规则/标签/额外属性/成本)。
Definition Building.cpp:24
int getBuildingDefinitionCount()
已注册建筑模板数量。
Definition Building.cpp:22
std::string getBuildingPlacementKind(const std::string &buildingId)
Definition placement domain (cell or edge).
Definition Building.cpp:73
int getChangeEventOtherCellX(int index) const
Returns the change event other cell x.
Definition Building.cpp:184
Ghost * newGhost()
Creates a ghost. @ownership Caller deletes unless documented otherwise.
Definition Building.cpp:116
PlacementWorld * newWorld(int width, int height, float cellSize=32.f)
工厂:创建放置世界 / 鬼影。
Definition Building.cpp:111
EVENGINE_API_WORLD public API.
Definition Ghost.h:16
float getElevation() const
Returns the elevation.
Definition Ghost.h:45
int getCellY() const
Returns the cell y.
Definition Ghost.h:34
float getWorldY() const
Returns the world y.
Definition Ghost.h:41
float getSurfaceHeightDelta() const
Sampled elevation range across the complete footprint.
Definition Ghost.h:91
void setFree(PlacementWorld *world, float worldX, float worldY, float elevation=0.f)
Set an exact unsnapped world-plane anchor for a free-domain definition.
Definition Ghost.cpp:207
void setFromWorld(PlacementWorld *world, float worldX, float worldY)
按世界吸附模式,从世界坐标刷新格子与世界位姿。
Definition Ghost.cpp:105
void setRotationDeg(float deg)
Sets the rotation deg.
Definition Ghost.cpp:94
int getCellX() const
Returns the cell x.
Definition Ghost.h:32
void setElevation(float elevation)
Sets the elevation.
Definition Ghost.cpp:75
float getSurfaceTangentX() const
X component of the captured unit surface tangent.
Definition Ghost.h:81
std::string getSurfaceId() const
Surface identity captured by the last successful setFromSurface call.
Definition Ghost.h:71
bool validate(PlacementWorld *world)
对当前姿态做校验,写入 valid_/reason_。
Definition Ghost.cpp:270
void setFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
Sets the from world 3 d.
Definition Ghost.cpp:131
std::string getReason() const
Returns the reason.
Definition Ghost.h:69
void setCorner(PlacementWorld *world, int vertexX, int vertexY)
Snap this ghost to one canonical grid vertex.
Definition Ghost.cpp:190
bool isValid() const
True when valid.
Definition Ghost.h:67
std::string getPlacementKind() const
Current placement domain (cell, edge, corner, or free).
Definition Ghost.h:56
float getSurfaceTangentZ() const
Z component of the captured unit surface tangent.
Definition Ghost.h:85
float getWorldX() const
Returns the world x.
Definition Ghost.h:39
float getRotationDeg() const
Returns the rotation deg.
Definition Ghost.h:50
std::string getEdgeAxis() const
Canonical edge axis (horizontal/vertical), empty for cell ghosts.
Definition Ghost.cpp:157
void setEdge(PlacementWorld *world, int cellX, int cellY, const std::string &direction)
Snap this ghost to a canonicalized cell edge and its exact midpoint pose.
Definition Ghost.cpp:162
float getSurfaceTangentY() const
Y component of the captured unit surface tangent.
Definition Ghost.h:83
std::string getBuildingId() const
Returns the building id.
Definition Ghost.h:27
void setWorld(float worldX, float worldY)
Sets the world.
Definition Ghost.cpp:54
int getSurfaceSampleCount() const
Number of occupied footprint cells sampled in the current patch.
Definition Ghost.h:87
int64_t getSurfaceRevision() const
Surface revision captured by the last successful setFromSurface call.
Definition Ghost.h:73
void rotateBy(float deltaDeg)
Rotate by.
Definition Ghost.cpp:101
float getSurfaceNormalY() const
Y component of the captured unit surface normal.
Definition Ghost.h:77
float getSurfaceMaxSlopeDegrees() const
Maximum sampled slope relative to the grid-plane up axis.
Definition Ghost.h:89
void setCell(int cellX, int cellY)
Sets the cell.
Definition Ghost.cpp:33
float getSurfaceNormalZ() const
Z component of the captured unit surface normal.
Definition Ghost.h:79
void setFromSurface(PlacementWorld *world, const std::string &surface, float x, float y)
Sets the from surface.
Definition Ghost.cpp:225
void setBuildingId(const std::string &id)
Sets the building id.
Definition Ghost.cpp:13
void destroy()
Destroys .
Definition Ghost.cpp:11
float getSurfaceNormalX() const
X component of the captured unit surface normal.
Definition Ghost.h:75
EVENGINE_API_WORLD public API.
PlacementEditExecuteStatus executeReplace(int instanceId)
Replace an existing instance with the selected definition atomically.
float getRotationDeg() const
Returns the rotation deg.
PatternUpdateStatus setPatternSubdivisions(int subdivisions)
Configure analytic segments used by edge_cubic_bezier.
void stopPlacement()
Stops placement.
PatternUpdateStatus setPatternRadius(int radius)
Configure the circle radius used by circle_brush.
void setRotationDeg(float deg)
Sets the rotation deg.
int getAreaPreviewCount() const
Number of cells in the last successful preview.
bool isActive() const
True when active.
void setMode(const std::string &mode)
Sets the mode.
AreaExecuteStatus previewBrush(int centerCellX, int centerCellY, int radius)
Cache a non-mutating circular cell brush preview.
std::string getPatternKind() const
Stable name of the currently authored pattern, or empty.
std::string getMode() const
Returns the mode.
int getLastPlacedCount() const
Number of ids committed by the last successful edge-line operation.
bool startPlacement(PlacementWorld *world, const std::string &buildingId)
Starts placement.
PatternUpdateStatus setPatternSurface(const std::string &surfaceName)
Configure an optional named surface for edge_cubic_bezier.
int getAreaPreviewCellX(int index) const
Returns the area preview cell x.
bool getPatternPreviewAccepted(int index) const
Whether one concrete preview anchor passed validation.
FreeUpdateStatus updateFree(PlacementWorld *world, float worldX, float worldY, float elevation=0.f)
Refresh a free-object ghost at an exact world-plane position.
int getLastEditedId() const
Instance id affected by the last successful move/replace, or zero.
PlacementEditExecuteStatus executeMove(int instanceId)
Move an existing instance to the current domain-specific ghost pose atomically.
PatternUpdateStatus beginPattern(const std::string &kind)
Start a renderer-neutral built-in pattern request.
AreaExecuteStatus previewRectangle(int minCellX, int minCellY, int maxCellX, int maxCellY)
Cache a non-mutating inclusive rectangular preview for UI/BuildingFX.
int getPatternPointCount() const
Number of authoring points in the current pattern.
EdgePathUpdateStatus appendEdgeCurveControlPoint(float x, float y)
Append a cubic Bezier control point; exactly four controls are accepted.
bool getAreaPreviewAccepted(int index) const
Returns the area preview accepted.
bool isValid() const
True when valid.
int getPatternPreviewX(int index) const
Logical x coordinate for one concrete preview anchor, or zero.
std::string getReason() const
Returns the reason.
int getAreaPreviewCellY(int index) const
Returns the area preview cell y.
EdgeUpdateStatus updateEdge(PlacementWorld *world, int cellX, int cellY, const std::string &direction)
Refresh an edge-object ghost from a cell-relative cardinal edge.
bool updateFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
Updates from world 3 d.
EdgeLineExecuteStatus executeEdgeLine(int startVertexX, int startVertexY, int endVertexX, int endVertexY)
Atomically place an axis-aligned edge line between logical vertices.
std::string getPatternPreviewReason(int index) const
Stable rejection reason for an area anchor, or empty.
AreaExecuteStatus executeBrush(int centerCellX, int centerCellY, int radius)
Atomically place a circular brush using the selected definition.
std::string getBuildingId() const
Returns the building id.
int getEdgeCurveControlPointCount() const
Number of currently authored cubic Bezier control points.
CornerUpdateStatus updateCorner(PlacementWorld *world, int vertexX, int vertexY)
Refresh a corner-object ghost at a canonical grid vertex.
EdgePathUpdateStatus appendEdgePathVertex(int vertexX, int vertexY)
Append one orthogonally connected logical vertex to the current edge path.
int getPatternPreviewCount() const
Number of concrete edge/cell anchors in the last pattern preview.
Ghost * getGhost() const
Returns the ghost.
bool updateFromWorld(PlacementWorld *world, float worldX, float worldY)
Updates from world.
EdgeLineExecuteStatus executeEdgePath()
Atomically commit the complete edge path.
AreaExecuteStatus executeRectangle(int minCellX, int minCellY, int maxCellX, int maxCellY)
Atomically place an inclusive rectangle using the selected definition.
EdgeLineExecuteStatus executeEdgeCurveOnSurface(int subdivisions, const std::string &surfaceName)
Sample a named custom surface and atomically commit the authored curve.
void rotateBy(float deltaDeg)
Rotate by.
EdgePathUpdateStatus beginEdgePath(int vertexX, int vertexY)
Start a multi-segment edge path at one logical grid vertex.
PatternExecuteStatus executePattern()
Atomically commit the complete cached pattern request.
PatternUpdateStatus appendPatternPoint(float x, float y)
Append one logical grid point/control to the current pattern.
EdgeLineExecuteStatus executeEdgeCurve(int subdivisions)
Sample and atomically commit the authored cubic Bezier curve.
EdgePathUpdateStatus beginEdgeCurve(float x, float y)
Begin authoring four cubic Bezier controls in logical grid space.
std::string getPatternPreviewAxis(int index) const
Edge axis for an edge preview anchor, or empty for area anchors.
PatternUpdateStatus previewPattern()
Expand and cache the complete pattern without world mutation.
bool updateFromSurface(PlacementWorld *world, const std::string &surface, float x, float y)
Updates from surface.
int getLastPlacedId(int index) const
Instance id from the last successful edge-line operation, or zero.
int getEdgePathVertexCount() const
Number of logical vertices in the current edge path.
int getPatternPreviewY(int index) const
Logical y coordinate for one concrete preview anchor, or zero.
std::string getAreaPreviewReason(int index) const
Returns the area preview reason.
static std::vector< std::string > surfaceNames()
static const std::vector< BuildingChangeEvent > & events()
static void setPlaneSurfaceHeight(float h)
static void ensureBuiltins()
确保内置规则已注册(模块首次使用时自动调用)。
static bool hasSurface(const std::string &name)
static bool hasSnapRule(const std::string &name)
static bool hasValidateRule(const std::string &name)
格子型建筑放置世界(脚本可直接操作)。
float getBuildingSurfaceNormalZ(int instanceId) const
Z component of the unit surface normal captured at placement time.
bool isEdgeEmpty(const std::string &channel, int cellX, int cellY, const std::string &direction) const
Return whether an edge is unoccupied in the requested channel.
int getBuildingSupportCount(int instanceId) const
Number of direct structural supports used by an instance.
std::string canPlaceReason(const std::string &buildingId, int cellX, int cellY, float rotationDeg=0.f)
Can place reason.
std::string canPlaceEdgeReason(const std::string &buildingId, int cellX, int cellY, const std::string &direction)
Stable rejection token for edge placement.
bool inBounds(int cellX, int cellY) const
In bounds.
int worldToCellX(float worldX) const
世界像素 ↔ 格子坐标。
int placeFree(const std::string &buildingId, float worldX, float worldY, float elevation=0.f, float rotationDeg=0.f)
Compatibility-only script projection of exact free placement.
float getOriginX() const
Returns the origin x.
void destroy()
释放资源并使其失效。
int getTerrain(int cellX, int cellY) const
Returns the terrain.
std::string getBuildingProp(int instanceId, const std::string &key, const std::string &fallback={}) const
Returns the building prop.
void setCellSize(float s)
Sets the cell size.
int getWidth() const
尺寸 / 格子大小 / 原点。
bool canPlaceEdge(const std::string &buildingId, int cellX, int cellY, const std::string &direction)
Validate edge placement without mutation.
float getBuildingWorldY(int instanceId) const
Returns the building world y.
int getActiveLevel() const
Floor used by compatibility placement/query APIs.
int placeCorner(const std::string &buildingId, int vertexX, int vertexY)
Compatibility-only script projection of canonical corner placement.
void clearBuildings()
Clears buildings.
int getBuildingCellY(int instanceId) const
Returns the building cell y.
float getBuildingSurfaceNormalX(int instanceId) const
X component of the unit surface normal captured at placement time.
float getOriginY() const
Returns the origin y.
int getEdgeConnectionMask(int instanceId) const
Six-bit local connection mask for an edge object's compatible neighbours.
int getFreeOccupantAtLevel(const std::string &channel, float worldX, float worldY, int level) const
Query a free-domain footprint at an explicit floor.
void setGridFromLayer(map::TileLayer *layer)
Sets the grid from layer.
void setHexSideLength(float s)
Sets the hex side length.
float getBuildingWorldX(int instanceId) const
Returns the building world x.
std::string canPlaceFreeReason(const std::string &buildingId, float worldX, float worldY)
Can place free reason.
bool moveBuilding(int instanceId, int cellX, int cellY, float rotationDeg=-1.f)
Moves building.
int getOccupantAtLevel(const std::string &channel, int cellX, int cellY, int level) const
Query one channel at an explicit discrete floor.
void setValidateRule(const std::string &rule)
Sets the validate rule.
std::string getGridLayoutName() const
Returns the grid layout name.
int getBuildingLevel(int instanceId) const
Return an instance's authoritative discrete floor.
float getBuildingElevation(int instanceId) const
Returns the building elevation.
float getFloorHeight() const
Height between discrete floors along the grid plane normal.
int getOccupant(int cellX, int cellY) const
占用查询:格子上建筑实例 / 是否为空。
bool isCellEmptyInChannel(const std::string &channel, int cellX, int cellY) const
已放置建筑实例查询。
int removeBuildingCascade(int instanceId)
Compatibility-only script projection of the canonical Result removal API.
bool hasBuilding(int instanceId) const
True when building.
int getBuildingSupportAt(int instanceId, int index) const
Direct structural support id by stable footprint order, or zero.
void setOrigin(float x, float y)
Sets the origin.
int getBuildingInstanceAt(int index) const
按插入顺序取实例 id。
int getBuildingCellX(int instanceId) const
Returns the building cell x.
float cellToWorld3DX(int cellX, int cellY, float elevation) const
Cell to world 3 dx.
bool buildingHasTag(int instanceId, const std::string &tag) const
Building has tag.
std::string getSnapMode() const
放置策略:吸附模式 / 校验规则。
int placeAt(const std::string &buildingId, int cellX, int cellY, float rotationDeg=0.f)
Place at.
int placeEdge(const std::string &buildingId, int cellX, int cellY, const std::string &direction)
Place an edge definition on a north/east/south/west edge; returns instance id or 0.
std::string getId() const
世界 id(用于变更事件定位)。
void setGridLayout(const std::string &layout)
Sets the grid layout.
std::string getValidateRule() const
Returns the validate rule.
void setFloorHeight(float height)
Set positive height between discrete floors. Invalid values are ignored.
void setExtra(const std::string &key, const std::string &value)
世界级额外属性(键值)。
bool hasGridFromLayer() const
True when grid from layer.
void setCellGap(float gapX, float gapY)
Sets the cell gap.
int getBuildingCount() const
Returns the building count.
void setActiveLevel(int level)
Select the floor used by compatibility placement/query APIs.
bool isCellEmpty(int cellX, int cellY) const
True when cell empty.
map::TileLayer * getTileLayer() const
Returns the tile layer.
void setTerrain(int cellX, int cellY, int semantic)
Sets the terrain.
void setTerrainGid(int gid, int semantic)
Sets the terrain gid.
bool removeBuilding(int instanceId)
Removes building.
float getBuildingRotation(int instanceId) const
Returns the building rotation.
void clearTileLayer()
Clears tile layer.
int64_t getBuildingSurfaceRevision(int instanceId) const
Surface provider revision captured when this instance was placed.
int worldToCell3DX(float worldX, float worldY, float worldZ) const
World to cell 3 dx.
int getEdgeOccupant(const std::string &channel, int cellX, int cellY, const std::string &direction) const
Return the occupant of a canonicalized north/east/south/west cell edge.
bool canPlaceFree(const std::string &buildingId, float worldX, float worldY)
Can place free.
float cellToWorldX(int cellX) const
Cell to world x.
int placeAtWorld3D(const std::string &buildingId, float worldX, float worldY, float worldZ, float rotationDeg=0.f)
Place at world 3 d.
int getEdgeOccupantAtLevel(const std::string &channel, int cellX, int cellY, const std::string &direction, int level) const
Query a canonical edge at an explicit discrete floor.
std::string getGridPlaneName() const
Returns the grid plane name.
bool canPlace(const std::string &buildingId, int cellX, int cellY, float rotationDeg=0.f)
便捷操作(转发 PlacementSystem):放置 / 移除 / 移动。
float cellToWorldY(int cellY) const
Cell to world y.
std::string getEdgeVariant(int instanceId) const
Stable topology variant name for an edge instance.
void setId(const std::string &id)
Sets the id.
int placeGhost(Ghost *ghost)
Place ghost.
int worldToCellY(float worldY) const
World to cell y.
int getCornerOccupantAtLevel(const std::string &channel, int vertexX, int vertexY, int level) const
Query a corner-domain occupant at an explicit floor.
void setBuildingProp(int instanceId, const std::string &key, const std::string &value)
Sets the building prop.
std::string getBuildingId(int instanceId) const
Returns the building id.
void setGridPlane(const std::string &plane)
Sets the grid plane.
void setSnapMode(const std::string &mode)
Sets the snap mode.
void bindTileLayer(map::TileLayer *layer)
Binds tile layer.
std::string getExtra(const std::string &key, const std::string &fallback={}) const
Returns the extra.
int worldToCell3DY(float worldX, float worldY, float worldZ) const
World to cell 3 dy.
void setStagger(const std::string &axis, const std::string &index)
Sets the stagger.
int placeAtWorld(const std::string &buildingId, float worldX, float worldY, float rotationDeg=0.f)
Place at world.
float getCellSize() const
Returns the cell size.
int getCornerOccupant(const std::string &channel, int vertexX, int vertexY) const
Query a corner-domain occupant at the active floor.
int getAnyOccupant(int cellX, int cellY) const
Returns the any occupant.
std::string canPlaceCornerReason(const std::string &buildingId, int vertexX, int vertexY)
Stable corner placement rejection token.
std::string canRemoveBuildingReason(int instanceId) const
Stable rejection token for ordinary removal (support_in_use when depended on).
float cellToWorld3DY(int cellX, int cellY, float elevation) const
Cell to world 3 dy.
int getAnyOccupantAtLevel(int cellX, int cellY, int level) const
Query the first occupant across channels at an explicit floor.
int getHeight() const
Returns the height.
int getFreeOccupant(const std::string &channel, float worldX, float worldY) const
Return the first free-domain object whose circular footprint contains the point.
std::string getBuildingSurfaceId(int instanceId) const
Surface provider identity captured when this instance was placed.
std::string getBuildingChannel(int instanceId) const
Returns the building channel.
void setTerrainGidMapJson(const std::string &json)
Sets the terrain gid map json.
float getBuildingWorldZ(int instanceId) const
Returns the building world z.
int getOccupantInChannel(const std::string &channel, int cellX, int cellY) const
Returns the occupant in channel.
bool canPlaceCorner(const std::string &buildingId, int vertexX, int vertexY)
Validate corner placement without mutation.
float getBuildingSurfaceNormalY(int instanceId) const
Y component of the unit surface normal captured at placement time.
float cellToWorld3DZ(int cellX, int cellY, float elevation) const
Cell to world 3 dz.
void fillTerrain(int semantic)
地形语义(占用检查用)。
void clearTerrainGidMap()
Clears terrain gid map.
bool isCornerEmpty(const std::string &channel, int vertexX, int vertexY) const
Return whether a corner-domain address is empty in one channel.
int getBuildingDependentCount(int instanceId) const
Number of instances that directly depend on this instance.
EVENGINE_API_FOUNDATION public API.
Definition Json.h:137
bool valid() const
Valid.
Definition Json.h:158
static Document parse(const std::string &text, std::string *error=nullptr)
Parse.
Definition Json.cpp:623
Value root() const
Root.
Definition Json.h:160
EVENGINE_API_FOUNDATION public API.
Definition Json.h:39
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:10
void exposeHouseBindings(ssq::Table &table)
建筑模板(进程级注册表中的定义)。
std::string placementKind
Placement domain: cell (default), edge, corner, or free.
std::unordered_map< std::string, std::string > visual2d
std::vector< float > freeFootprintVertices
Optional convex local polygon as x/y pairs in grid-cell units, centered on the free anchor.
std::unordered_map< std::string, int > cost
std::unordered_map< std::string, std::string > visual3d
std::string supportMode
Structural support policy: none, cell_below, or corner_below.
float freeFootprintHeightCells
Optional oriented-box height in grid-cell units; positive width and height select OBB collision.
bool maskAt(int localX, int localY) const
占地掩码在局部坐标 (localX, localY) 处是否占用。
Definition Building.cpp:504
std::unordered_map< std::string, std::string > extra
std::string getVisual2d(const std::string &key, const std::string &fallback={}) const
Returns the visual 2 d.
Definition Building.cpp:489
std::string rotationMode
none | cardinal | free。
std::string validateRule
default | boundsOnly | overlapOk | 自定义。
int getCost(const std::string &resource, int fallback=0) const
Returns the cost.
Definition Building.cpp:499
std::string getExtra(const std::string &key, const std::string &fallback={}) const
Returns the extra.
Definition Building.cpp:484
float maxSurfaceSlopeDegrees
Maximum angle between a footprint normal and the grid-plane up axis.
std::string snapMode
grid | cell | free | 自定义。
std::vector< uint8_t > footprintMask
可选占地掩码,长度 footprintW*footprintH;空表示实心矩形。行主序、原点在最小 x/y。
bool hasTag(const std::string &tag) const
查询辅助。
Definition Building.cpp:480
float freeRadiusCells
Circular free-domain collision radius measured in grid-cell units.
std::vector< std::string > tags
float edgeThicknessCells
Solid edge thickness in cells; zero disables free/edge collision.
float freeFootprintWidthCells
Optional oriented-box width in grid-cell units; positive width and height select OBB collision.
std::string getVisual3d(const std::string &key, const std::string &fallback={}) const
Returns the visual 3 d.
Definition Building.cpp:494
std::vector< std::string > tags
void setProp(const std::string &key, const std::string &value)
Sets the prop.
Definition Building.cpp:521
std::string getProp(const std::string &key, const std::string &fallback={}) const
Returns the prop.
Definition Building.cpp:516
std::unordered_map< std::string, std::string > props
bool hasTag(const std::string &tag) const
True when tag.
Definition Building.cpp:512