From acae4d0ee9a69a14d484c9e0124296e7a7cbb2b8 Mon Sep 17 00:00:00 2001 From: "Stephen C. Wills" Date: Sat, 6 May 2023 19:01:08 -0400 Subject: [PATCH] Fix state of doors after ObjChangeMapResync (#6085) --- Source/objects.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/Source/objects.cpp b/Source/objects.cpp index 9f031ff01..63e032be8 100644 --- a/Source/objects.cpp +++ b/Source/objects.cpp @@ -3644,6 +3644,21 @@ void SyncDoor(Object &door) } } +void ResyncDoors(WorldTilePosition p1, WorldTilePosition p2) +{ + const WorldTileSize size { static_cast(p2.x - p1.x), static_cast(p2.y - p1.y) }; + const WorldTileRectangle area { p1, size }; + + for (WorldTilePosition p : PointsInRectangleRange { area }) { + Object *obj = FindObjectAtPosition(p); + if (obj == nullptr) + continue; + if (IsNoneOf(obj->_otype, OBJ_L1LDOOR, OBJ_L1RDOOR, OBJ_L2LDOOR, OBJ_L2RDOOR, OBJ_L3LDOOR, OBJ_L3RDOOR, OBJ_L5LDOOR, OBJ_L5RDOOR)) + continue; + SyncDoor(*obj); + } +} + void UpdateState(Object &object, int frame) { if (object._oSelFlag == 0) { @@ -4349,20 +4364,26 @@ void ObjChangeMap(int x1, int y1, int x2, int y2) dungeon[i][j] = pdungeon[i][j]; } } + + WorldTilePosition mega1 { static_cast(x1), static_cast(y1) }; + WorldTilePosition mega2 { static_cast(x2), static_cast(y2) }; + WorldTilePosition world1 = mega1.megaToWorld(); + WorldTilePosition world2 = mega2.megaToWorld() + Displacement { 1, 1 }; if (leveltype == DTYPE_CATHEDRAL) { - ObjL1Special(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); - AddL1Objs(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + ObjL1Special(world1.x, world1.y, world2.x, world2.y); + AddL1Objs(world1.x, world1.y, world2.x, world2.y); } if (leveltype == DTYPE_CATACOMBS) { - ObjL2Special(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); - AddL2Objs(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + ObjL2Special(world1.x, world1.y, world2.x, world2.y); + AddL2Objs(world1.x, world1.y, world2.x, world2.y); } if (leveltype == DTYPE_CAVES) { - AddL3Objs(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + AddL3Objs(world1.x, world1.y, world2.x, world2.y); } if (leveltype == DTYPE_CRYPT) { - AddCryptObjects(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + AddCryptObjects(world1.x, world1.y, world2.x, world2.y); } + ResyncDoors(world1, world2); } void ObjChangeMapResync(int x1, int y1, int x2, int y2) @@ -4373,12 +4394,18 @@ void ObjChangeMapResync(int x1, int y1, int x2, int y2) dungeon[i][j] = pdungeon[i][j]; } } + + WorldTilePosition mega1 { static_cast(x1), static_cast(y1) }; + WorldTilePosition mega2 { static_cast(x2), static_cast(y2) }; + WorldTilePosition world1 = mega1.megaToWorld(); + WorldTilePosition world2 = mega2.megaToWorld() + Displacement { 1, 1 }; if (leveltype == DTYPE_CATHEDRAL) { - ObjL1Special(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + ObjL1Special(world1.x, world1.y, world2.x, world2.y); } if (leveltype == DTYPE_CATACOMBS) { - ObjL2Special(2 * x1 + 16, 2 * y1 + 16, 2 * x2 + 17, 2 * y2 + 17); + ObjL2Special(world1.x, world1.y, world2.x, world2.y); } + ResyncDoors(world1, world2); } _item_indexes ItemMiscIdIdx(item_misc_id imiscid)