diff --git a/TR5Main/Game/Lara/lara_swim.cpp b/TR5Main/Game/Lara/lara_swim.cpp index 56003820d..b8bb9b665 100644 --- a/TR5Main/Game/Lara/lara_swim.cpp +++ b/TR5Main/Game/Lara/lara_swim.cpp @@ -151,9 +151,9 @@ int GetWaterDepth(int x, int y, int z, short roomNumber) if (r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP)) { - while (floor->skyRoom != NO_ROOM) + while (floor->RoomAbove() != NO_ROOM) { - r = &g_Level.Rooms[floor->skyRoom]; + r = &g_Level.Rooms[floor->RoomAbove()]; if (!(r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP))) { int wh = floor->ceiling << 8; @@ -166,9 +166,9 @@ int GetWaterDepth(int x, int y, int z, short roomNumber) } else { - while (floor->pitRoom != NO_ROOM) + while (floor->RoomBelow() != NO_ROOM) { - r = &g_Level.Rooms[floor->pitRoom]; + r = &g_Level.Rooms[floor->RoomBelow()]; if (r->flags & (ENV_FLAG_WATER|ENV_FLAG_SWAMP)) { int wh = floor->floor << 8; diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index f66dabd4f..ab76499b7 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -1247,11 +1247,11 @@ COLL_RESULT GetCollisionResult(FLOOR_INFO* floor, int x, int y, int z) // Probe bottom block through portals. // TODO: Check if it is really needed, as GetFloor should take care of it itself? ROOM_INFO* r; - while (floor->pitRoom != NO_ROOM) + while (floor->RoomBelow() != NO_ROOM) { if (CheckNoColFloorTriangle(floor, x, z) == 1) break; - r = &g_Level.Rooms[floor->pitRoom]; + r = &g_Level.Rooms[floor->RoomBelow()]; floor = XZ_GET_SECTOR(r, x - r->x, z - r->z); } diff --git a/TR5Main/Game/control.cpp b/TR5Main/Game/control.cpp index f39c14366..e15db24b1 100644 --- a/TR5Main/Game/control.cpp +++ b/TR5Main/Game/control.cpp @@ -875,9 +875,9 @@ int GetWaterSurface(int x, int y, int z, short roomNumber) if (room->flags & ENV_FLAG_WATER) { - while (floor->skyRoom != NO_ROOM) + while (floor->RoomAbove() != NO_ROOM) { - room = &g_Level.Rooms[floor->skyRoom]; + room = &g_Level.Rooms[floor->RoomAbove()]; if (!(room->flags & ENV_FLAG_WATER)) return (floor->ceiling << 8); floor = XZ_GET_SECTOR(room, x - room->x, z - room->z); @@ -886,9 +886,9 @@ int GetWaterSurface(int x, int y, int z, short roomNumber) } else { - while (floor->pitRoom != NO_ROOM) + while (floor->RoomBelow() != NO_ROOM) { - room = &g_Level.Rooms[floor->pitRoom]; + room = &g_Level.Rooms[floor->RoomBelow()]; if (room->flags & ENV_FLAG_WATER) return (floor->floor << 8); floor = XZ_GET_SECTOR(room, x - room->x, z - room->z); @@ -1016,56 +1016,24 @@ FLOOR_INFO *GetFloor(int x, int y, int z, short *roomNumber) int CheckNoColFloorTriangle(FLOOR_INFO *floor, int x, int z) { - if (floor->FloorIsSplit() && - (floor->FloorCollision.Portals[0] != 0 || floor->FloorCollision.Portals[1] != 0)) - { - int dx = x & 1023; - int dz = z & 1023; - - // TODO: bring these checks back! - - //if (type == NOCOLF1T && dx <= (SECTOR(1) - dz)) - // return -1; - //else if (type == NOCOLF1B && dx > (SECTOR(1) - dz)) - // return -1; - //else if (type == NOCOLF2T && dx <= dz) - // return -1; - //else if (type == NOCOLF2B && dx > dz) - // return -1; - //else - // return 1; + if (!floor->FloorIsSplit()) + return 0; + if (floor->FloorCollision.Portals[floor->SectorPlane(x, z)] == NO_ROOM) return 1; - } - - return 0; + else + return -1; } int CheckNoColCeilingTriangle(FLOOR_INFO *floor, int x, int z) { - if (floor->CeilingIsSplit() && - (floor->CeilingCollision.Portals[0] != 0 || floor->CeilingCollision.Portals[1] != 0)) - { - int dx = x & 1023; - int dz = z & 1023; - - // TODO: bring these checks back! - - //if (type == NOCOLC1T && dx <= (SECTOR(1) - dz)) - // return -1; - //else if (type == NOCOLC1B && dx > (SECTOR(1) - dz)) - // return -1; - //else if (type == NOCOLC2T && dx <= dz) - // return -1; - //else if (type == NOCOLC2B && dx > dz) - // return -1; - //else - // return 1; + if (!floor->CeilingIsSplit()) + return 0; + if (floor->CeilingCollision.Portals[floor->SectorPlaneCeiling(x, z)] == NO_ROOM) return 1; - } - - return 0; + else + return -1; } int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) @@ -2291,15 +2259,15 @@ int GetWaterHeight(int x, int y, int z, short roomNumber) if (r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP)) { - while (floor->skyRoom != NO_ROOM) + while (floor->RoomAbove() != NO_ROOM) { if (CheckNoColCeilingTriangle(floor, x, z) == 1) break; - r = &g_Level.Rooms[floor->skyRoom]; + r = &g_Level.Rooms[floor->RoomAbove()]; if (!(r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP))) return r->minfloor; floor = XZ_GET_SECTOR(r, x - r->x, z - r->z); - if (floor->skyRoom == NO_ROOM) + if (floor->RoomAbove() == NO_ROOM) break; } @@ -2307,15 +2275,15 @@ int GetWaterHeight(int x, int y, int z, short roomNumber) } else { - while (floor->pitRoom != NO_ROOM) + while (floor->RoomBelow() != NO_ROOM) { if (CheckNoColFloorTriangle(floor, x, z) == 1) break; - r = &g_Level.Rooms[floor->pitRoom]; + r = &g_Level.Rooms[floor->RoomBelow()]; if (r->flags & (ENV_FLAG_WATER | ENV_FLAG_SWAMP)) return r->maxceiling; floor = XZ_GET_SECTOR(r, x - r->x, z - r->z); - if (floor->pitRoom == NO_ROOM) + if (floor->RoomBelow() == NO_ROOM) break; } } diff --git a/TR5Main/Game/control/trigger.cpp b/TR5Main/Game/control/trigger.cpp index db25d8187..df9cd24f0 100644 --- a/TR5Main/Game/control/trigger.cpp +++ b/TR5Main/Game/control/trigger.cpp @@ -153,11 +153,11 @@ int SwitchTrigger(short itemNum, short timer) short* GetTriggerIndex(FLOOR_INFO* floor, int x, int y, int z) { ROOM_INFO* r; - while (floor->pitRoom != NO_ROOM) + while (floor->RoomBelow() != NO_ROOM) { if (CheckNoColFloorTriangle(floor, x, z) == 1) break; - r = &g_Level.Rooms[floor->pitRoom]; + r = &g_Level.Rooms[floor->RoomBelow()]; floor = XZ_GET_SECTOR(r, x - r->x, z - r->z); } diff --git a/TR5Main/Game/effects/debris.cpp b/TR5Main/Game/effects/debris.cpp index 1fd714380..9579d1e5c 100644 --- a/TR5Main/Game/effects/debris.cpp +++ b/TR5Main/Game/effects/debris.cpp @@ -129,18 +129,18 @@ void UpdateDebris() deb.angularVelocity *= deb.angularDrag; roomNumber = deb.roomNumber; - floor = GetFloor(deb.worldPosition.x, deb.worldPosition.y, deb.worldPosition.z,&roomNumber); + floor = GetFloor(deb.worldPosition.x, deb.worldPosition.y, deb.worldPosition.z, &roomNumber); if (deb.worldPosition.y < floor->ceiling*256) { - if (floor->skyRoom != NO_ROOM) - deb.roomNumber = floor->skyRoom; + if (floor->RoomAbove() != NO_ROOM) + deb.roomNumber = floor->RoomAbove(); } if (deb.worldPosition.y > floor->floor*256) { - if (floor->pitRoom != NO_ROOM) - deb.roomNumber = floor->pitRoom; + if (floor->RoomBelow() != NO_ROOM) + deb.roomNumber = floor->RoomBelow(); if (deb.numBounces > 3) { diff --git a/TR5Main/Game/floordata.cpp b/TR5Main/Game/floordata.cpp index 174f138ef..12ba57110 100644 --- a/TR5Main/Game/floordata.cpp +++ b/TR5Main/Game/floordata.cpp @@ -7,6 +7,26 @@ using namespace TEN::Floordata; +int FLOOR_INFO::RoomBelow() const +{ + if (FloorCollision.Portals[0] != NO_ROOM) + return FloorCollision.Portals[0]; + else if (FloorCollision.Portals[1] != NO_ROOM) + return FloorCollision.Portals[1]; + else + return NO_ROOM; +} + +int FLOOR_INFO::RoomAbove() const +{ + if (CeilingCollision.Portals[0] != NO_ROOM) + return CeilingCollision.Portals[0]; + else if (CeilingCollision.Portals[1] != NO_ROOM) + return CeilingCollision.Portals[1]; + else + return NO_ROOM; +} + int FLOOR_INFO::SectorPlane(int x, int z) const { const auto point = GetSectorPoint(x, z); @@ -52,16 +72,6 @@ bool FLOOR_INFO::CeilingIsSplit() const return differentPlanes || differentPortals; } -bool FLOOR_INFO::FloorIsDiagonalStep() const -{ - return FloorCollision.Planes[0].z != FloorCollision.Planes[1].z; -} - -bool FLOOR_INFO::CeilingIsDiagonalStep() const -{ - return CeilingCollision.Planes[0].z != CeilingCollision.Planes[1].z; -} - std::optional FLOOR_INFO::RoomBelow(int plane) const { const auto room = FloorCollision.Portals[plane]; diff --git a/TR5Main/Game/floordata.h b/TR5Main/Game/floordata.h index a689a6dfb..8cb40e4d9 100644 --- a/TR5Main/Game/floordata.h +++ b/TR5Main/Game/floordata.h @@ -31,9 +31,7 @@ class FLOOR_INFO int box; int fx; int stopper; - int pitRoom; int floor; - int skyRoom; int ceiling; SECTOR_COLLISION_INFO FloorCollision; SECTOR_COLLISION_INFO CeilingCollision; @@ -42,13 +40,18 @@ class FLOOR_INFO std::set BridgeItem; int Room; + // These two functions return single floor/ceiling portal for legacy code. + // Later, when there will be possible to make 2 separate portals in 2 + // planes, these functions should be somehow resolved along with legacy code. + + int RoomAbove() const; + int RoomBelow() const; + int SectorPlane(int x, int z) const; int SectorPlaneCeiling(int x, int z) const; std::pair FLOOR_INFO::TiltXZ(int x, int z) const; bool FloorIsSplit() const; bool CeilingIsSplit() const; - bool FloorIsDiagonalStep() const; - bool CeilingIsDiagonalStep() const; std::optional RoomBelow(int plane) const; std::optional RoomBelow(int x, int z) const; std::optional RoomBelow(int x, int z, int y) const; diff --git a/TR5Main/Objects/Generic/Doors/generic_doors.cpp b/TR5Main/Objects/Generic/Doors/generic_doors.cpp index 2e81a0908..a9f1d970e 100644 --- a/TR5Main/Objects/Generic/Doors/generic_doors.cpp +++ b/TR5Main/Objects/Generic/Doors/generic_doors.cpp @@ -438,11 +438,17 @@ namespace TEN::Entities::Doors if (floor) { floor->box = NO_BOX; - floor->ceiling = -127; - floor->floor = -127; floor->index = 0; - floor->skyRoom = NO_ROOM; - floor->pitRoom = NO_ROOM; + + // FIXME: HACK!!!!!!! + floor->FloorCollision.Portals[0] = NO_ROOM; + floor->FloorCollision.Portals[1] = NO_ROOM; + floor->CeilingCollision.Portals[0] = NO_ROOM; + floor->CeilingCollision.Portals[1] = NO_ROOM; + floor->FloorCollision.Planes[0].z = -127; + floor->FloorCollision.Planes[1].z = -127; + floor->CeilingCollision.Planes[0].z = -127; + floor->CeilingCollision.Planes[1].z = -127; short boxIndex = doorPos->block; if (boxIndex != NO_BOX) diff --git a/TR5Main/Specific/level.cpp b/TR5Main/Specific/level.cpp index f9a0a5fa7..0141ca4ff 100644 --- a/TR5Main/Specific/level.cpp +++ b/TR5Main/Specific/level.cpp @@ -648,9 +648,7 @@ void ReadRooms() floor.box = ReadInt32(); floor.fx = ReadInt32(); floor.stopper = ReadInt32(); - floor.pitRoom = ReadInt32(); floor.floor = ReadInt32(); - floor.skyRoom = ReadInt32(); floor.ceiling = ReadInt32(); floor.FloorCollision.SplitAngle = ReadFloat();