1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2026-07-05 01:42:43 +00:00

ru:: map switches

This commit is contained in:
Zeno Rogue
2026-04-01 20:32:23 +02:00
parent 07215111ef
commit a5df8cdd29
3 changed files with 60 additions and 0 deletions
+22
View File
@@ -171,6 +171,12 @@ struct room {
place_block_full(x, y, b);
}
void replace_block_death(int x, int y, eWall w) {
auto orig = at(x, y);
replace_block(x, y, w);
add_revert(death_revert, {"BLOCK", id, its(x), its(y), its(orig)});
}
void replace_block_frev(int x, int y, eWall w) {
auto orig = at(x, y);
replace_block(x, y, w);
@@ -553,6 +559,22 @@ struct timed_orb : public located_entity {
string get_help() override { return "These orbs activate mechanisms for a limited time."; }
};
struct switch_event {
bbox box;
eWall wall;
};
struct mapswitch : public located_entity {
vector<switch_event> events;
string text, name;
xy siz() override { return {18, 18}; }
string glyph() override { return "!"; }
color_t color() override { return 0xA06000FF; }
void act() override;
string get_name() override { return name; }
string get_help() override { return text; }
};
struct npc_or_trader : public located_entity {
string text, name;
int talk_on;
+14
View File
@@ -369,6 +369,20 @@ void npc_or_trader::act() {
}
}
void mapswitch::act() {
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
bool didsomething = false;
for(auto& ev: events) {
for(int y=ev.box.miny; y<ev.box.maxy; y++)
for(int x=ev.box.minx; x<ev.box.maxx; x++) {
int b = current_room->at(x, y);
if(b != ev.wall) { didsomething = true; current_room->replace_block_death(x, y, ev.wall); }
}
}
if(didsomething) addMessage(text);
}
}
extern int gold_id;
string shopitem::glyph() { if(bought) return powers[gold_id].get_glyph(); else return item::glyph(); }
+24
View File
@@ -105,6 +105,8 @@ void create_long_rope(room& r, int step, xy w) {
}
}
mapswitch *lmev;
void load_room(fhstream& f, cell *c) {
setdist(c, 7, nullptr);
auto& r = *get_room_at(c);
@@ -370,6 +372,28 @@ void load_room(fhstream& f, cell *c) {
b->text = scanline_noblank(f);
visions.emplace_back(std::move(b));
}
else if(cap == "MAPSWITCH") {
auto b = std::make_unique<mapswitch>();
b->respawn = get_xy();
b->name = scanline_noblank(f);
b->text = scanline_noblank(f);
lmev = &*b;
r.entities.emplace_back(std::move(b));
}
else if(cap == "SWITCHEVENT") {
if(!lmev) throw hr_exception("SWITCHEVENT without MAPSWITCH");
auto& ev = lmev->events;
ev.emplace_back();
ev.back().box.minx = get_int();
ev.back().box.miny = get_int();
ev.back().box.maxx = get_int();
ev.back().box.maxy = get_int();
ev.back().wall = wDoor;
bool ok = false;
for(int i=0; i<qwall; i++) if(walls[i].name + " " == param)
ev.back().wall = eWall(i), ok = true;
if(!ok) println(hlog, "warning: SWITCHEVENT wall not recognized");
}
else println(hlog, "unknown mapline ", s);
}
else println(hlog, "unknown mapline ", s);