ru:: better last_platform

This commit is contained in:
Zeno Rogue
2026-04-13 20:24:05 +02:00
parent efcf764742
commit 089113bc32
3 changed files with 44 additions and 29 deletions
+1 -1
View File
@@ -540,7 +540,7 @@ struct cycloid_platform : public moving_platform {
};
struct saw: public entity {
unique_ptr<entity> base;
unique_ptr<moving_platform> base;
moving_platform& mp() { return (moving_platform&)(*base); }
string glyph() override { return "*"; }
color_t color() override { return walls[wWall].color; }
+2 -6
View File
@@ -717,9 +717,7 @@ void moving_platform::act() {
}
void saw::act() {
auto b = base->as_platform();
if(!b) { addMessage("You have a vision of an otherworldly saw!"); existing = false; return; }
where = b->location_at(gframeid);
where = base->location_at(gframeid);
auto bb = get_pixel_bbox();
if(intersect(bb, m.get_pixel_bbox())) {
if(m.reduce_hp(40)) addMessage("The " + get_name() + " shreds you!");
@@ -741,9 +739,7 @@ void woodsaw::attacked(int s, power *p) {
}
void fakesaw::act() {
auto b = base->as_platform();
if(!b) { addMessage("You have a vision of an otherworldly saw!"); existing = false; return; }
where = b->location_at(gframeid);
where = base->location_at(gframeid);
auto bb = get_pixel_bbox();
if(intersect(bb, m.get_pixel_bbox())) {
addMessage("This " + get_name() + " turned out to be an illusion!");
+41 -22
View File
@@ -108,7 +108,20 @@ void create_long_rope(room& r, int step, xy w) {
mapswitch *lmev;
moving_platform *last_platform;
vector<moving_platform*> last_platform;
unique_ptr<entity>& find_entity(room &r, moving_platform *p) {
for(auto& e: r.entities)
if(&*e == p)
return e;
throw hr_exception("failed to find entity");
}
unique_ptr<moving_platform>& as_platform(unique_ptr<entity>& e) {
auto b = e->as_platform();
if(!b) throw hr_exception("not a platform as platform");
return (unique_ptr<moving_platform>&) e;
}
void load_room(fhstream& f, cell *c) {
setdist(c, 7, nullptr);
@@ -331,51 +344,57 @@ void load_room(fhstream& f, cell *c) {
else if(cap == "PENDULUM") {
auto b = std::make_unique<pendulum_platform>();
b->a = get_xy(); b->b = get_xy(); b->period = get_ld(); b->shift = get_ld();
last_platform = &*b;
last_platform = {&*b};
r.entities.emplace_back(std::move(b));
}
else if(cap == "HORO") {
auto b = std::make_unique<horoplatform>();
b->a = get_xy(); b->b = get_xy(); b->period = get_ld(); b->shift = get_ld();
last_platform = &*b;
last_platform = {&*b};
r.entities.emplace_back(std::move(b));
}
else if(cap == "ELLIPSE") {
auto b = std::make_unique<ellipse_platform>();
b->a = get_xy(); b->b = get_xy(); b->period = get_ld(); b->shift = get_ld(); b->ratio = get_ld();
last_platform = &*b;
last_platform = {&*b};
r.entities.emplace_back(std::move(b));
}
else if(cap == "CYCLOID") {
else if(cap == "CYCLOID") for(auto& p: last_platform) {
auto b = std::make_unique<cycloid_platform>();
b->base = last_platform; b->radius = get_ld(); b->period = get_ld(); b->shift = get_ld();
last_platform = &*b;
b->radius = get_ld(); b->period = get_ld(); b->shift = get_ld();
b->base = p->as_platform();
p = &*b;
r.entities.emplace_back(std::move(b));
}
else if(cap == "SAW") {
else if(cap == "SAW") for(auto p: last_platform) {
auto& f = find_entity(r, p);
auto b = std::make_unique<saw>(); nam(*b);
b->base = std::move(r.entities.back());
r.entities.back() = std::move(b);
b->base = std::move(as_platform(f));
f = std::move(b);
}
else if(cap == "TINYSAW") {
else if(cap == "TINYSAW") for(auto p: last_platform) {
auto& f = find_entity(r, p);
auto b = std::make_unique<tinysaw>(); nam(*b);
b->base = std::move(r.entities.back());
r.entities.back() = std::move(b);
b->base = std::move(as_platform(f));
f = std::move(b);
}
else if(cap == "WOODSAW") {
else if(cap == "WOODSAW") for(auto p: last_platform) {
auto& f = find_entity(r, p);
auto b = std::make_unique<woodsaw>(); nam(*b);
b->base = std::move(r.entities.back());
r.entities.back() = std::move(b);
b->base = std::move(as_platform(f));
f = std::move(b);
}
else if(cap == "WEAKSAW") {
else if(cap == "WEAKSAW") for(auto p: last_platform) {
auto& f = find_entity(r, p);
auto b = std::make_unique<weaksaw>(); nam(*b);
b->base = std::move(r.entities.back());
r.entities.back() = std::move(b);
b->base = std::move(as_platform(f));
f = std::move(b);
}
else if(cap == "FAKESAW") {
else if(cap == "FAKESAW") for(auto p: last_platform) {
auto& f = find_entity(r, p);
auto b = std::make_unique<fakesaw>(); nam(*b);
b->base = std::move(r.entities.back());
r.entities.back() = std::move(b);
b->base = std::move(as_platform(f));
f = std::move(b);
}
else if(cap == "ROLLINGSAW") {
auto b = std::make_unique<rollingsaw>(); nam(*b);