Skip to content

Commit

Permalink
tr1/trapdoor: fix trapdoor location test
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Nov 16, 2024
1 parent 396bb5c commit 46bc253
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
- fixed the `/play` console command resulting in Lara starting the target level without pistols (#1861, regression from 4.5)
- fixed the demo mode text overlapping with the enemy health bar if the health bar is located in the bottom centered (#1446)
- fixed mutant explosions sometimes heavily damaging Lara even if they missed (#1758, regression since 4.5)
- fixed wrongly calculated trapdoor size that could affect custom levels (#1904)
- improved enemy item drops by supporting the TR2+ approach of having drops defined in level data (#1713)
- improved Italian localization for the Config Tool
- improved the injection approach for Lara's responsive jumping (#1823)
Expand Down
44 changes: 33 additions & 11 deletions src/tr1/game/objects/general/trapdoor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "game/items.h"
#include "global/const.h"

#include <libtrx/utils.h>

typedef enum {
TRAPDOOR_STATE_CLOSED,
TRAPDOOR_STATE_OPEN,
Expand All @@ -12,20 +14,40 @@ static bool M_IsItemOnTop(const ITEM *item, int32_t x, int32_t z);

static bool M_IsItemOnTop(const ITEM *item, int32_t x, int32_t z)
{
int32_t tx = item->pos.x >> WALL_SHIFT;
int32_t tz = item->pos.z >> WALL_SHIFT;
x >>= WALL_SHIFT;
z >>= WALL_SHIFT;
const BOUNDS_16 *const orig_bounds = &Item_GetBestFrame(item)->bounds;
BOUNDS_16 fixed_bounds = { 0 };

if (item->rot.y == 0 && x == tx && (z == tz || z == tz + 1)) {
return true;
} else if (item->rot.y == -PHD_180 && x == tx && (z == tz || z == tz - 1)) {
return true;
} else if (item->rot.y == PHD_90 && z == tz && (x == tx || x == tx + 1)) {
return true;
} else if (item->rot.y == -PHD_90 && z == tz && (x == tx || x == tx - 1)) {
// Bounds need to change in order to account for 2 sector trapdoors
// and the trapdoor angle.
if (item->rot.y == 0) {
fixed_bounds.min.x = orig_bounds->min.x;
fixed_bounds.max.x = orig_bounds->max.x;
fixed_bounds.min.z = orig_bounds->min.z;
fixed_bounds.max.z = orig_bounds->max.z;
} else if (item->rot.y == PHD_90) {
fixed_bounds.min.x = orig_bounds->min.z;
fixed_bounds.max.x = orig_bounds->max.z;
fixed_bounds.min.z = -orig_bounds->max.x;
fixed_bounds.max.z = -orig_bounds->min.x;
} else if (item->rot.y == -PHD_180) {
fixed_bounds.min.x = -orig_bounds->max.x;
fixed_bounds.max.x = -orig_bounds->min.x;
fixed_bounds.min.z = -orig_bounds->max.z;
fixed_bounds.max.z = -orig_bounds->min.z;
} else if (item->rot.y == -PHD_90) {
fixed_bounds.min.x = -orig_bounds->max.z;
fixed_bounds.max.x = -orig_bounds->min.z;
fixed_bounds.min.z = orig_bounds->min.x;
fixed_bounds.max.z = orig_bounds->max.x;
}

if (x <= item->pos.x + fixed_bounds.max.x
&& x >= item->pos.x + fixed_bounds.min.x
&& z <= item->pos.z + fixed_bounds.max.z
&& z >= item->pos.z + fixed_bounds.min.z) {
return true;
}

return false;
}

Expand Down

0 comments on commit 46bc253

Please sign in to comment.