Skip to content

Commit

Permalink
collide: fix collision issues with bridges
Browse files Browse the repository at this point in the history
Fixed collision issues with drawbridges, trapdoors, and bridges when
stacked over each other, over slopes, and near the ground.

Resolves LostArtefacts#606.
  • Loading branch information
walkawayy committed Aug 2, 2024
1 parent 1a2521b commit 6006523
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- fixed Lara able to reach triggers through closed doors (#1419, regression from 1.1.4)
- fixed Lara voiding when loading the game on a closed door (#1419)
- fixed underwater caustics not resumed smoothly when unpausing (#1423, regression 3.2)
- fixed collision issues with drawbridges, trapdoors, and bridges when stacked over each other, over slopes, and near the ground (#606)
- improved initial level load time by lazy-loading audio samples (LostArtefacts/TR2X#114)

## [4.2](https://github.com/LostArtefacts/TR1X/compare/4.1.2...4.2) - 2024-07-14
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- fixed flickering in bats' death animations and rapid shooting if Lara continues to fire when they are killed
- fixed looking forward too far causing an upside down camera frame
- fixed the Scion being extremely difficult to shoot with the shotgun
- fixed collision issues with drawbridges, trapdoors, and bridges when stacked over each other, over slopes, and near the ground

#### Cheats
- added a fly cheat
Expand Down
98 changes: 62 additions & 36 deletions src/game/collide.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "game/collide.h"

#include "config.h"
#include "game/items.h"
#include "game/room.h"
#include "global/const.h"
Expand Down Expand Up @@ -27,6 +28,7 @@ void Collide_GetCollisionInfo(

FLOOR_INFO *floor = Room_GetFloor(x, ytop, z, &room_num);
int32_t height = Room_GetHeight(floor, x, ytop, z);
int32_t room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}
Expand All @@ -41,9 +43,15 @@ void Collide_GetCollisionInfo(
coll->mid_type = g_HeightType;
coll->trigger = g_TriggerIndex;

int16_t tilt = Room_GetTiltType(floor, x, g_LaraItem->pos.y, z);
coll->tilt_z = tilt >> 8;
coll->tilt_x = (int8_t)tilt;
if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
int16_t tilt = Room_GetTiltType(floor, x, g_LaraItem->pos.y, z);
coll->tilt_z = tilt >> 8;
coll->tilt_x = (int8_t)tilt;
} else {
coll->tilt_z = 0;
coll->tilt_x = 0;
}

int32_t xleft;
int32_t zleft;
Expand Down Expand Up @@ -98,10 +106,12 @@ void Collide_GetCollisionInfo(
break;
}

// Front.
x = xpos + xfront;
z = zpos + zfront;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}
Expand All @@ -114,23 +124,29 @@ void Collide_GetCollisionInfo(
coll->front_floor = height;
coll->front_ceiling = ceiling;
coll->front_type = g_HeightType;
if (coll->slopes_are_walls && coll->front_type == HT_BIG_SLOPE
&& coll->front_floor < 0) {
coll->front_floor = -32767;
} else if (
coll->slopes_are_pits && coll->front_type == HT_BIG_SLOPE
&& coll->front_floor > 0) {
coll->front_floor = 512;
} else if (
coll->lava_is_pit && coll->front_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->front_floor = 512;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->front_type == HT_BIG_SLOPE
&& coll->front_floor < 0) {
coll->front_floor = -32767;
} else if (
coll->slopes_are_pits && coll->front_type == HT_BIG_SLOPE
&& coll->front_floor > 0) {
coll->front_floor = 512;
} else if (
coll->lava_is_pit && coll->front_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->front_floor = 512;
}
}

// Left.
x = xpos + xleft;
z = zpos + zleft;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}
Expand All @@ -143,23 +159,29 @@ void Collide_GetCollisionInfo(
coll->left_floor = height;
coll->left_ceiling = ceiling;
coll->left_type = g_HeightType;
if (coll->slopes_are_walls && coll->left_type == HT_BIG_SLOPE
&& coll->left_floor < 0) {
coll->left_floor = -32767;
} else if (
coll->slopes_are_pits && coll->left_type == HT_BIG_SLOPE
&& coll->left_floor > 0) {
coll->left_floor = 512;
} else if (
coll->lava_is_pit && coll->left_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->left_floor = 512;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->left_type == HT_BIG_SLOPE
&& coll->left_floor < 0) {
coll->left_floor = -32767;
} else if (
coll->slopes_are_pits && coll->left_type == HT_BIG_SLOPE
&& coll->left_floor > 0) {
coll->left_floor = 512;
} else if (
coll->lava_is_pit && coll->left_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->left_floor = 512;
}
}

// Right.
x = xpos + xright;
z = zpos + zright;
floor = Room_GetFloor(x, ytop, z, &room_num);
height = Room_GetHeight(floor, x, ytop, z);
room_height = height;
if (height != NO_HEIGHT) {
height -= ypos;
}
Expand All @@ -172,17 +194,21 @@ void Collide_GetCollisionInfo(
coll->right_floor = height;
coll->right_ceiling = ceiling;
coll->right_type = g_HeightType;
if (coll->slopes_are_walls && coll->right_type == HT_BIG_SLOPE
&& coll->right_floor < 0) {
coll->right_floor = -32767;
} else if (
coll->slopes_are_pits && coll->right_type == HT_BIG_SLOPE
&& coll->right_floor > 0) {
coll->right_floor = 512;
} else if (
coll->lava_is_pit && coll->right_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->right_floor = 512;

if (!g_Config.fix_bridge_collision
|| !Room_IsOnWalkable(floor, x, ytop, z, room_height)) {
if (coll->slopes_are_walls && coll->right_type == HT_BIG_SLOPE
&& coll->right_floor < 0) {
coll->right_floor = -32767;
} else if (
coll->slopes_are_pits && coll->right_type == HT_BIG_SLOPE
&& coll->right_floor > 0) {
coll->right_floor = 512;
} else if (
coll->lava_is_pit && coll->right_floor > 0 && g_TriggerIndex
&& (g_TriggerIndex[0] & DATA_TYPE) == FT_LAVA) {
coll->right_floor = 512;
}
}

if (Collide_CollideStaticObjects(
Expand Down
Loading

0 comments on commit 6006523

Please sign in to comment.