载入中...
搜索中...
未找到
PlacementSession.cpp
浏览该文件的文档.
2#include "building/Ghost.h"
4
5namespace eve::building {
6
8
10 if (ghost_) ghost_->destroy();
11 ghost_ = nullptr;
12 delete this;
13}
14
15bool PlacementSession::startPlacement(PlacementWorld *world, const std::string &buildingId) {
16 if (!world || buildingId.empty()) return false;
17 world_ = world;
18 ghost_->setBuildingId(buildingId);
19 active_ = true;
20 mode_ = "place";
21 return true;
22}
23
25 active_ = false;
26 world_ = nullptr;
27}
28
30 return ghost_ ? ghost_->getBuildingId() : std::string{};
31}
32
33void PlacementSession::setMode(const std::string &mode) {
34 if (mode == "remove") {
35 mode_ = "remove";
36 } else {
37 mode_ = "place";
38 }
39}
40
42 if (ghost_) ghost_->setRotationDeg(deg);
43}
44
45void PlacementSession::rotateBy(float deltaDeg) {
46 if (ghost_) ghost_->rotateBy(deltaDeg);
47}
48
50 return ghost_ ? ghost_->getRotationDeg() : 0.f;
51}
52
53bool PlacementSession::updateFromWorld(PlacementWorld *world, float worldX, float worldY) {
54 if (!active_ || !ghost_) return false;
55 if (world) world_ = world;
56 if (!world_) return false;
57 ghost_->setFromWorld(world_, worldX, worldY);
58 refreshValidate();
59 return true;
60}
61
62bool PlacementSession::updateFromWorld3D(PlacementWorld *world, float worldX, float worldY,
63 float worldZ) {
64 if (!active_ || !ghost_) return false;
65 if (world) world_ = world;
66 if (!world_) return false;
67 ghost_->setFromWorld3D(world_, worldX, worldY, worldZ);
68 refreshValidate();
69 return true;
70}
71
72bool PlacementSession::updateFromSurface(PlacementWorld *world, const std::string &surface,
73 float x, float y) {
74 if (!active_ || !ghost_) return false;
75 if (world) world_ = world;
76 if (!world_) return false;
77 ghost_->setFromSurface(world_, surface, x, y);
78 refreshValidate();
79 return true;
80}
81
82bool PlacementSession::isValid() const { return ghost_ ? ghost_->isValid() : false; }
83
84std::string PlacementSession::getReason() const {
85 return ghost_ ? ghost_->getReason() : std::string{};
86}
87
88void PlacementSession::refreshValidate() {
89 if (world_ && ghost_) ghost_->validate(world_);
90}
91
93 if (!active_ || !world_ || !ghost_) return 0;
94 if (mode_ == "remove") {
95 const int occ = world_->getOccupant(ghost_->getCellX(), ghost_->getCellY());
96 if (occ <= 0) return 0;
97 return world_->removeBuilding(occ) ? occ : 0;
98 }
99 return world_->placeGhost(ghost_);
100}
101
102} // namespace eve::building
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
int getCellY() const
Definition Ghost.h:24
void setFromWorld(PlacementWorld *world, float worldX, float worldY)
按世界吸附模式,从世界坐标刷新格子与世界位姿。
Definition Ghost.cpp:45
void setRotationDeg(float deg)
Definition Ghost.cpp:35
int getCellX() const
Definition Ghost.h:23
bool validate(PlacementWorld *world)
对当前姿态做校验,写入 valid_/reason_。
Definition Ghost.cpp:80
void setFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
Definition Ghost.cpp:57
std::string getReason() const
Definition Ghost.h:38
bool isValid() const
Definition Ghost.h:37
float getRotationDeg() const
Definition Ghost.h:33
std::string getBuildingId() const
Definition Ghost.h:20
void rotateBy(float deltaDeg)
Definition Ghost.cpp:41
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
void setMode(const std::string &mode)
bool startPlacement(PlacementWorld *world, const std::string &buildingId)
bool updateFromWorld3D(PlacementWorld *world, float worldX, float worldY, float worldZ)
bool updateFromWorld(PlacementWorld *world, float worldX, float worldY)
bool updateFromSurface(PlacementWorld *world, const std::string &surface, float x, float y)
格子型建筑放置世界(脚本可直接操作)。
int getOccupant(int cellX, int cellY) const
占用查询:格子上建筑实例 / 是否为空。
bool removeBuilding(int instanceId)
建筑放置模块入口:定义 / 放置世界 / 鬼影 / 变更事件的脚本绑定点。 设计文档:docs/dev/建筑放置系统设计.md
Definition Building.cpp:7