From 25f095d2256afe40c79ec013a9bd04950c88154a Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 24 May 2025 17:13:21 +0200 Subject: [PATCH] ru:: replace_block_frev --- rogueviz/ru/classes.cpp | 6 ++++++ rogueviz/ru/entity.cpp | 12 +++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index 2a281ef7..244d22a5 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -136,6 +136,12 @@ struct room { place_block_full(x, y, b); } + void replace_block_frev(int x, int y, eWall w) { + auto orig = at(x, y); + replace_block(x, y, w); + add_revert(fountain_revert, [this, x, y, orig] { replace_block(x, y, orig); }); + } + void generate(); void reveal(int cx, int cy); diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index a07ff08d..db87a278 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -111,11 +111,13 @@ void entity::apply_walls() { vel.y /= 2; if(abs(vel.y) < 1e-6) vel.y = 0; if(burning()) { - if(b == wWoodWall) current_room->replace_block(x, y, wAir); + if(b == wWoodWall) + current_room->replace_block_frev(x, y, wAir); else hit_wall(); } if(freezing()) { - if(b == wWater) current_room->replace_block(x, y, wFrozen); + if(b == wWater) + current_room->replace_block_frev(x, y, wFrozen); else if(b != wFrozen) hit_wall(); } if(pixel_to_block(get_pixel_bbox_at(where + vel)).maxy <= y) where.y += vel.y; @@ -134,7 +136,7 @@ void entity::apply_walls() { if(abs(vel.y) < 1e-6) vel.y = 0; if(pixel_to_block(get_pixel_bbox_at(where + vel)).miny > y) where.y += vel.y; if(burning()) { - if(b == wWoodWall) current_room->replace_block(x, y, wAir); + if(b == wWoodWall) current_room->replace_block_frev(x, y, wAir); } goto again; } @@ -154,7 +156,7 @@ void entity::apply_walls() { if(walls[b].flags & W_BLOCK) { if(freezing()) { hit_wall(); } if(burning()) { - if(b == wWoodWall) current_room->replace_block(x, y, wAir); + if(b == wWoodWall) current_room->replace_block_frev(x, y, wAir); else hit_wall(); } vel.x = (vel.x - max(vel.y, 0)/10) / 2; @@ -169,7 +171,7 @@ void entity::apply_walls() { if(walls[b].flags & W_BLOCK) { if(freezing()) { hit_wall(); } if(burning()) { - if(b == wWoodWall) current_room->replace_block(x, y, wAir); + if(b == wWoodWall) current_room->replace_block_frev(x, y, wAir); else hit_wall(); } vel.x = (vel.x + max(vel.y, 0)/10) / 2;