From 69e693335fc63b3cd35681e623dba1e597b278e5 Mon Sep 17 00:00:00 2001 From: asasas9500 Date: Mon, 10 Apr 2023 20:39:53 -0300 Subject: [PATCH 1/6] Implement proper sector boundaries --- TOMB4/game/control.cpp | 181 ++++++++++++++++++++++++++++++++++++++-- TOMB4/game/control.h | 2 + TOMB4/game/laraswim.cpp | 4 +- 3 files changed, 176 insertions(+), 11 deletions(-) diff --git a/TOMB4/game/control.cpp b/TOMB4/game/control.cpp index 7133548b..23a2a057 100644 --- a/TOMB4/game/control.cpp +++ b/TOMB4/game/control.cpp @@ -1266,20 +1266,20 @@ FLOOR_INFO* GetFloor(long x, long y, long z, short* room_number) } while (door != 255); - if (y < floor->floor << 8) + if (y < GetMaximumFloor(floor, x, z)) { - if (y < floor->ceiling << 8 && floor->sky_room != 255) + if (y < GetMinimumCeiling(floor, x, z) && floor->sky_room != 255) { do { - if (CheckNoColCeilingTriangle(floor, x, z) == 1 || CheckNoColCeilingTriangle(floor, x, z) == -1 && y >= r->maxceiling) + if (CheckNoColCeilingTriangle(floor, x, z) == 1) break; *room_number = floor->sky_room; r = &room[floor->sky_room]; floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)]; - if (y >= floor->ceiling << 8) + if (y >= GetMinimumCeiling(floor, x, z)) break; } while (floor->sky_room != 255); @@ -1289,14 +1289,14 @@ FLOOR_INFO* GetFloor(long x, long y, long z, short* room_number) { while (1) { - if (CheckNoColFloorTriangle(floor, x, z) == 1 || CheckNoColFloorTriangle(floor, x, z) == -1 && y < r->minfloor) + if (CheckNoColFloorTriangle(floor, x, z) == 1) break; *room_number = floor->pit_room; r = &room[floor->pit_room]; floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)]; - if (y < floor->floor << 8) + if (y < GetMaximumFloor(floor, x, z)) break; if (floor->pit_room == 255) @@ -1365,12 +1365,12 @@ long GetWaterHeight(long x, long y, long z, short room_number) r = &room[floor->sky_room]; if (!(r->flags & ROOM_UNDERWATER)) - return r->minfloor; + break; floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)]; } - return r->maxceiling; + return GetMinimumCeiling(floor, x, z); } else { @@ -1382,7 +1382,7 @@ long GetWaterHeight(long x, long y, long z, short room_number) r = &room[floor->pit_room]; if (r->flags & ROOM_UNDERWATER) - return r->maxceiling; + return GetMaximumFloor(floor, x, z); floor = &r->floor[((z - r->z) >> 10) + r->x_size * ((x - r->x) >> 10)]; } @@ -3169,3 +3169,166 @@ long DoRayBox(GAME_VECTOR* start, GAME_VECTOR* target, short* bounds, PHD_3DPOS* return 0; } + +long GetMaximumFloor(FLOOR_INFO* floor, long x, long z) +{ + long height, h1, h2; + short* data, type, dx, dz, t0, t1, t2, t3, hadj; + + height = floor->floor << 8; + + if (height != NO_HEIGHT && floor->index) + { + data = &floor_data[floor->index]; + type = *data++; + h1 = 0; + h2 = 0; + + if ((type & 0x1F) != TILT_TYPE) + { + if ((type & 0x1F) == SPLIT1 || (type & 0x1F) == SPLIT2 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B || (type & 0x1F) == NOCOLF2T || (type & 0x1F) == NOCOLF2B) + { + dx = x & 0x3FF; + dz = z & 0x3FF; + t0 = *data & 0xF; + t1 = *data >> 4 & 0xF; + t2 = *data >> 8 & 0xF; + t3 = *data >> 12 & 0xF; + + if ((type & 0x1F) == SPLIT1 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B) + { + if (dx <= 1024 - dz) + { + hadj = type >> 10 & 0x1F; + h1 = t2 - t1; + h2 = t0 - t1; + } + else + { + hadj = type >> 5 & 0x1F; + h1 = t3 - t0; + h2 = t3 - t2; + } + } + else + { + if (dx <= dz) + { + hadj = type >> 10 & 0x1F; + h1 = t2 - t1; + h2 = t3 - t2; + } + else + { + hadj = type >> 5 & 0x1F; + h1 = t3 - t0; + h2 = t0 - t1; + } + } + + if (hadj & 0x10) + hadj |= 0xFFF0; + + height += hadj << 8; + } + } + else + { + h1 = *data >> 8; + h2 = *(char*)data; + } + + height += 256 * (abs(h1) + abs(h2)); + } + + return height; +} + +long GetMinimumCeiling(FLOOR_INFO* floor, long x, long z) +{ + long height, h1, h2; + short* data, type, dx, dz, t0, t1, t2, t3, hadj, ended; + + height = floor->ceiling << 8; + + if (height != NO_HEIGHT && floor->index) + { + data = &floor_data[floor->index]; + type = *data++; + ended = 0; + + if ((type & 0x1F) == TILT_TYPE || (type & 0x1F) == SPLIT1 || (type & 0x1F) == SPLIT2 || (type & 0x1F) == NOCOLF1T || (type & 0x1F) == NOCOLF1B || (type & 0x1F) == NOCOLF2T || (type & 0x1F) == NOCOLF2B) + { + data++; + + if (type & 0x8000) + ended = 1; + + type = *data++; + } + + if (!ended) + { + h1 = 0; + h2 = 0; + + if ((type & 0x1F) != ROOF_TYPE) + { + if ((type & 0x1F) == SPLIT3 || (type & 0x1F) == SPLIT4 || (type & 0x1F) == NOCOLC1T || (type & 0x1F) == NOCOLC1B || (type & 0x1F) == NOCOLC2T || (type & 0x1F) == NOCOLC2B) + { + dx = x & 0x3FF; + dz = z & 0x3FF; + t0 = -(*data & 0xF); + t1 = -(*data >> 4 & 0xF); + t2 = -(*data >> 8 & 0xF); + t3 = -(*data >> 12 & 0xF); + + if ((type & 0x1F) == SPLIT3 || (type & 0x1F) == NOCOLC1T || (type & 0x1F) == NOCOLC1B) + { + if (dx <= 1024 - dz) + { + hadj = type >> 10 & 0x1F; + h1 = t2 - t1; + h2 = t3 - t2; + } + else + { + hadj = type >> 5 & 0x1F; + h1 = t3 - t0; + h2 = t0 - t1; + } + } + else + { + if (dx <= dz) + { + hadj = type >> 10 & 0x1F; + h1 = t2 - t1; + h2 = t0 - t1; + } + else + { + hadj = type >> 5 & 0x1F; + h1 = t3 - t0; + h2 = t3 - t2; + } + } + + if (hadj & 0x10) + hadj |= 0xFFF0; + + height += hadj << 8; + } + } + else + { + h1 = *data >> 8; + h2 = *(char*)data; + } + + height -= 256 * (abs(h1) + abs(h2)); + } + } + + return height; +} diff --git a/TOMB4/game/control.h b/TOMB4/game/control.h index d56111e2..ebec606d 100644 --- a/TOMB4/game/control.h +++ b/TOMB4/game/control.h @@ -35,6 +35,8 @@ long GetTargetOnLOS(GAME_VECTOR* src, GAME_VECTOR* dest, long DrawTarget, long f void AnimateItem(ITEM_INFO* item); long RayBoxIntersect(PHD_VECTOR* min, PHD_VECTOR* max, PHD_VECTOR* mid, PHD_VECTOR* dir, PHD_VECTOR* Coord); long DoRayBox(GAME_VECTOR* start, GAME_VECTOR* target, short* bounds, PHD_3DPOS* ItemPos, PHD_VECTOR* Coord, short item_number); +long GetMaximumFloor(FLOOR_INFO* floor, long x, long z); +long GetMinimumCeiling(FLOOR_INFO* floor, long x, long z); extern ITEM_INFO* items; extern ANIM_STRUCT* anims; diff --git a/TOMB4/game/laraswim.cpp b/TOMB4/game/laraswim.cpp index c9e2e97d..76b8f9df 100644 --- a/TOMB4/game/laraswim.cpp +++ b/TOMB4/game/laraswim.cpp @@ -350,7 +350,7 @@ long GetWaterDepth(long x, long y, long z, short room_number) if (!(r->flags & ROOM_UNDERWATER)) { - h = floor->ceiling << 8; + h = GetMinimumCeiling(floor, x, z); floor = GetFloor(x, y, z, &room_number); return GetHeight(floor, x, y, z) - h; } @@ -368,7 +368,7 @@ long GetWaterDepth(long x, long y, long z, short room_number) if (r->flags & ROOM_UNDERWATER) { - h = floor->floor << 8; + h = GetMaximumFloor(floor, x, z); floor = GetFloor(x, y, z, &room_number); return GetHeight(floor, x, y, z) - h; } From bd2d52b9270f9a25b6e6ec0c67ee2170adc68d97 Mon Sep 17 00:00:00 2001 From: asasas9500 Date: Tue, 11 Apr 2023 14:28:16 -0300 Subject: [PATCH 2/6] Implement hair mesh collision --- TOMB4/game/hair.cpp | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/TOMB4/game/hair.cpp b/TOMB4/game/hair.cpp index 69252976..16dc2a51 100644 --- a/TOMB4/game/hair.cpp +++ b/TOMB4/game/hair.cpp @@ -409,35 +409,22 @@ void HairControl(long in_cutscene, long pigtail, short* cutscenething) hair->pos.z_pos += SmokeWindZ; } - switch (lara.water_status) + if (water == NO_HEIGHT || hair->pos.y_pos < water) { - case LW_ABOVE_WATER: - case LW_WADE: //here instead of the other case to fix stiff hair during wade hair->pos.y_pos += 10; if (water != NO_HEIGHT && hair->pos.y_pos > water) hair->pos.y_pos = water; - else if (hair->pos.y_pos > height) - { - hair->pos.x_pos = pos.x; - - if (hair->pos.y_pos - height <= 256) //snap to floor if it goes below, no more than 1 click to avoid hairection when going through corners - hair->pos.y_pos = height; - - hair->pos.z_pos = pos.z; - } - - break; + } - case LW_UNDERWATER: - case LW_SURFACE: + if (hair->pos.y_pos > height) + { + hair->pos.x_pos = pos.x; - if (hair->pos.y_pos < water) - hair->pos.y_pos = water; - else if (hair->pos.y_pos > height) + if (hair->pos.y_pos - height <= 256) //snap to floor if it goes below, no more than 1 click to avoid hairection when going through corners hair->pos.y_pos = height; - break; + hair->pos.z_pos = pos.z; } for (int j = 0; j < 6; j++) //6 instead of 5 for new sphere From 0ca68047ef33befdcbe860688f5154d53921f6ee Mon Sep 17 00:00:00 2001 From: Troye Date: Tue, 11 Apr 2023 21:00:12 -0500 Subject: [PATCH 3/6] fix wade snapping --- TOMB4/game/lara.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TOMB4/game/lara.cpp b/TOMB4/game/lara.cpp index 885ea963..a6537692 100644 --- a/TOMB4/game/lara.cpp +++ b/TOMB4/game/lara.cpp @@ -2126,7 +2126,9 @@ void lara_col_back(ITEM_INFO* item, COLL_INFO* coll) if (TestLaraSlide(item, coll)) return; - if (coll->mid_floor != NO_HEIGHT) + if (lara.water_status == LW_WADE && coll->mid_floor >= 50) + item->pos.y_pos += 50; + else if (coll->mid_floor != NO_HEIGHT) item->pos.y_pos += coll->mid_floor; } @@ -2220,7 +2222,9 @@ void lara_col_stepright(ITEM_INFO* item, COLL_INFO* coll) if (TestLaraSlide(item, coll)) return; - if (coll->mid_floor != NO_HEIGHT) + if (lara.water_status == LW_WADE && coll->mid_floor >= 50) + item->pos.y_pos += 50; + else if (coll->mid_floor != NO_HEIGHT) item->pos.y_pos += coll->mid_floor; } From be718ff86cb6db4c6d745a9f8b88139ebd80db1b Mon Sep 17 00:00:00 2001 From: Troye Date: Tue, 11 Apr 2023 21:02:01 -0500 Subject: [PATCH 4/6] update changelog; --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e33c904..42637ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Fix the random fires on screen bug. - Fix Ahmet/Scale save crashes in Temple of Horus. +- Fix Lara snapping when moving off a ledge while wading. ### tomb4 bug fixes From a0c112c47dccdc5347297a051643a54e0983cfef Mon Sep 17 00:00:00 2001 From: Troye Date: Tue, 11 Apr 2023 21:24:27 -0500 Subject: [PATCH 5/6] update changelog again; --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42637ff9..3598fdcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ### new tomb4 features +- Improve how the hair interacts with water. ## [2.1.0](https://github.com/Trxyebeep/TOMB4/tree/V2.1.0) (Mar. 3 2023) From f62974521670cb765dfc55e4e2d77565da27af53 Mon Sep 17 00:00:00 2001 From: Troye Date: Tue, 11 Apr 2023 21:25:09 -0500 Subject: [PATCH 6/6] last time --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3598fdcd..ce04a9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Fix the random fires on screen bug. - Fix Ahmet/Scale save crashes in Temple of Horus. - Fix Lara snapping when moving off a ledge while wading. +- Fix floordata issues with triangular geometry, no collision tiles, and more generic situations. ### tomb4 bug fixes