载入中...
搜索中...
未找到
Ghost.cpp
浏览该文件的文档.
1#include "building/Ghost.h"
4
5namespace eve::building {
6
7void Ghost::destroy() { delete this; }
8
9void Ghost::setBuildingId(const std::string &id) {
10 buildingId_ = id;
11 valid_ = false;
12 reason_.clear();
13}
14
15void Ghost::setCell(int cellX, int cellY) {
16 cellX_ = cellX;
17 cellY_ = cellY;
18 valid_ = false;
19 reason_.clear();
20}
21
22void Ghost::setWorld(float worldX, float worldY) {
23 worldX_ = worldX;
24 worldY_ = worldY;
25 valid_ = false;
26 reason_.clear();
27}
28
29void Ghost::setElevation(float elevation) {
30 elevation_ = elevation;
31 valid_ = false;
32 reason_.clear();
33}
34
35void Ghost::setRotationDeg(float deg) {
36 rotationDeg_ = deg;
37 valid_ = false;
38 reason_.clear();
39}
40
41void Ghost::rotateBy(float deltaDeg) {
42 setRotationDeg(rotationDeg_ + deltaDeg);
43}
44
45void Ghost::setFromWorld(PlacementWorld *world, float worldX, float worldY) {
46 if (!world) return;
47 const SnapResult s = PlacementSystem::snap(*world, buildingId_, worldX, worldY);
48 cellX_ = s.cellX;
49 cellY_ = s.cellY;
50 worldX_ = s.worldX;
51 worldY_ = s.worldY;
52 elevation_ = s.elevation;
53 valid_ = false;
54 reason_.clear();
55}
56
57void Ghost::setFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ) {
58 if (!world) return;
59 const SnapResult s = PlacementSystem::snap3D(*world, buildingId_, worldX, worldY, worldZ);
60 cellX_ = s.cellX;
61 cellY_ = s.cellY;
62 worldX_ = s.worldX;
63 worldY_ = s.worldY;
64 elevation_ = s.elevation;
65 valid_ = false;
66 reason_.clear();
67}
68
69void Ghost::setFromSurface(PlacementWorld *world, const std::string &surface, float x, float y) {
70 if (!world) return;
72 if (!PlacementSystem::surfaceHit(*world, surface, x, y, &hit)) {
73 valid_ = false;
74 reason_ = "no_surface_hit";
75 return;
76 }
77 setFromWorld3D(world, hit.worldX, hit.worldY, hit.worldZ);
78}
79
81 if (!world) {
82 valid_ = false;
83 reason_ = "no_world";
84 return false;
85 }
86 rotationDeg_ = PlacementSystem::normalizeRotation(buildingId_, rotationDeg_);
87 std::string reason;
88 valid_ = PlacementSystem::canPlaceElev(world, buildingId_, cellX_, cellY_, elevation_,
89 rotationDeg_, 0, &reason);
90 reason_ = reason;
91 return valid_;
92}
93
94} // namespace eve::building
std::string id
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t s
Definition Weather.cpp:28
void setFromWorld(PlacementWorld *world, float worldX, float worldY)
按世界吸附模式,从世界坐标刷新格子与世界位姿。
Definition Ghost.cpp:45
void setRotationDeg(float deg)
Definition Ghost.cpp:35
void setElevation(float elevation)
Definition Ghost.cpp:29
bool validate(PlacementWorld *world)
对当前姿态做校验,写入 valid_/reason_。
Definition Ghost.cpp:80
void setFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
Definition Ghost.cpp:57
void setWorld(float worldX, float worldY)
Definition Ghost.cpp:22
void rotateBy(float deltaDeg)
Definition Ghost.cpp:41
void setCell(int cellX, int cellY)
Definition Ghost.cpp:15
void setFromSurface(PlacementWorld *world, const std::string &surface, float x, float y)
Definition Ghost.cpp:69
void setBuildingId(const std::string &id)
Definition Ghost.cpp:9
static SnapResult snap(const PlacementWorld &world, const std::string &buildingId, float worldX, float worldY)
static SnapResult snap3D(const PlacementWorld &world, const std::string &buildingId, float worldX, float worldY, float worldZ)
static bool surfaceHit(const PlacementWorld &world, const std::string &name, float x, float y, PlacementHit *hit)
static float normalizeRotation(const std::string &buildingId, float rotationDeg)
规范化旋转角(cardinal → 0/90/180/270;none → 0)。
static bool canPlaceElev(PlacementWorld *world, const std::string &buildingId, int cellX, int cellY, float elevation, float rotationDeg=0.f, int excludeInstanceId=0, std::string *reason=nullptr)
格子型建筑放置世界(脚本可直接操作)。
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:7