Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
port LOS_CheckSmashable
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 3, 2023
1 parent 1fb9b4c commit a9ab1f8
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 12 deletions.
16 changes: 8 additions & 8 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ typedef enum LARA_MESH {
00415C80 000002EB + int32_t __cdecl LOS_CheckZ(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00415F70 000002EC + int32_t __cdecl LOS_CheckX(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00416260 000000DA + int32_t __cdecl LOS_ClipTarget(const struct GAME_VECTOR *start, struct GAME_VECTOR *target, const FLOOR_INFO *floor);
00416340 000002FE - int32_t __cdecl LOS_ObjectOnLOS(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00416340 000002FE + int32_t __cdecl LOS_CheckSmashable(const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
00416640 000000B3 - void __cdecl Room_FlipMap(void);
00416700 00000096 - void __cdecl Room_RemoveFlipItems(struct ROOM_INFO *r);
004167A0 0000005C - void __cdecl Room_AddFlipItems(struct ROOM_INFO *r);
Expand Down Expand Up @@ -2581,7 +2581,7 @@ typedef enum LARA_MESH {
0052618C - struct ROOM_INFO *g_Rooms;
00526240 - int32_t g_FlipStatus;
00526288 - int16_t *g_TriggerIndex;
005262F0 - struct ITEM_INFO g_Items[];
005262F0 - struct ITEM_INFO *g_Items;
005262F6 - int16_t g_NumCineFrames;
005262F8 - CINE_FRAME *g_CineData = NULL;
00526300 - struct PHD_3DPOS g_CinePos;
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ exe_sources = [
dll_sources = [
'src/filesystem.c',
'src/game/camera.c',
'src/game/items.c',
'src/game/lara/lara_col.c',
'src/game/lara/lara_misc.c',
'src/game/lara/lara_state.c',
Expand Down
105 changes: 105 additions & 0 deletions src/game/los.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "game/los.h"

#include "game/items.h"
#include "game/math.h"
#include "global/const.h"
#include "global/funcs.h"
#include "global/vars.h"
#include "util.h"

#include <assert.h>

int32_t __cdecl LOS_CheckX(
const struct GAME_VECTOR *const start, struct GAME_VECTOR *const target)
{
Expand Down Expand Up @@ -281,3 +285,104 @@ int32_t __cdecl LOS_Check(
}
return 0;
}

int32_t __cdecl LOS_CheckSmashable(
const struct GAME_VECTOR *const start, struct GAME_VECTOR *const target)
{
const int32_t dx = target->x - start->x;
const int32_t dy = target->y - start->y;
const int32_t dz = target->z - start->z;

for (int i = 0; i < g_LOSNumRooms; i++) {
for (int16_t item_num = g_Rooms[g_LOSRooms[i]].item_num;
item_num != NO_ITEM; item_num = g_Items[item_num].next_item) {
const struct ITEM_INFO *const item = &g_Items[item_num];
if (item->status == IS_DEACTIVATED) {
continue;
}

if (!Item_IsSmashable(item)) {
continue;
}

const enum DIRECTION direction = Math_GetDirection(item->pos.y_rot);
const int16_t *const bounds = Item_GetBoundsAccurate(item);
const int16_t *x_extent;
const int16_t *z_extent;
switch (direction) {
case DIR_EAST:
case DIR_WEST:
x_extent = &bounds[FBBOX_MIN_Z];
z_extent = &bounds[FBBOX_MIN_X];
break;
case DIR_NORTH:
case DIR_SOUTH:
x_extent = &bounds[FBBOX_MIN_X];
z_extent = &bounds[FBBOX_MIN_Z];
break;
default:
assert(false);
break;
}

int32_t failure = 0;
if (ABS(dz) > ABS(dx)) {
int32_t distance = item->pos.z + z_extent[0] - start->z;
for (int j = 0; j < 2; j++) {
if ((distance >= 0) == (dz >= 0)) {
const int32_t y = dy * distance / dz;
if (y <= item->pos.y + bounds[FBBOX_MIN_Y] - start->y
|| y >= item->pos.y + bounds[FBBOX_MAX_Y]
- start->y) {
continue;
}

const int32_t x = dx * distance / dz;
if (x < item->pos.x + x_extent[0] - start->x) {
failure |= 1;
} else if (x > item->pos.x + x_extent[1] - start->x) {
failure |= 2;
} else {
return item_num;
}
}

distance = item->pos.z + z_extent[1] - start->z;
}

if (failure == 3) {
return item_num;
}
} else {
int32_t distance = item->pos.x + x_extent[0] - start->x;
for (int j = 0; j < 2; j++) {
if ((distance >= 0) == (dx >= 0)) {
const int32_t y = dy * distance / dx;
if (y <= item->pos.y + bounds[FBBOX_MIN_Y] - start->y
|| y >= item->pos.y + bounds[FBBOX_MAX_Y]
- start->y) {
continue;
}

const int32_t z = dz * distance / dx;
if (z < item->pos.z + z_extent[0] - start->z) {
failure |= 1;
} else if (z > item->pos.z + z_extent[1] - start->z) {
failure |= 2;
} else {
return item_num;
}
}

distance = item->pos.x + x_extent[1] - start->x;
}

if (failure == 3) {
return item_num;
}
}
}
}

return NO_ITEM;
}
2 changes: 2 additions & 0 deletions src/game/los.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ int32_t __cdecl LOS_ClipTarget(
const FLOOR_INFO *floor);
int32_t __cdecl LOS_Check(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
int32_t __cdecl LOS_CheckSmashable(
const struct GAME_VECTOR *start, struct GAME_VECTOR *target);
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
#define Item_IsTriggerActive ((int32_t __cdecl (*)(struct ITEM_INFO *item))0x004158D0)
#define Room_GetCeiling ((int32_t __cdecl (*)(const struct FLOOR_INFO *floor, int32_t x, int32_t y, int32_t z))0x00415930)
#define Room_GetDoor ((int16_t __cdecl (*)(struct FLOOR_INFO *floor))0x00415B90)
#define LOS_ObjectOnLOS ((int32_t __cdecl (*)(const struct GAME_VECTOR *start, struct GAME_VECTOR *target))0x00416340)
#define Room_FlipMap ((void __cdecl (*)(void))0x00416640)
#define Room_RemoveFlipItems ((void __cdecl (*)(struct ROOM_INFO *r))0x00416700)
#define Room_AddFlipItems ((void __cdecl (*)(struct ROOM_INFO *r))0x004167A0)
Expand Down
7 changes: 7 additions & 0 deletions src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ typedef struct CINE_FRAME {
int16_t roll;
} CINE_FRAME;

typedef enum ITEM_STATUS {
IS_NOT_ACTIVE = 0,
IS_ACTIVE = 1,
IS_DEACTIVATED = 2,
IS_INVISIBLE = 3,
} ITEM_STATUS;

typedef enum INPUT_STATE {
IN_FORWARD = 0x00000001,
IN_BACK = 0x00000002,
Expand Down
2 changes: 1 addition & 1 deletion src/global/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
#define g_FlipStatus (*(int32_t*)0x00526240)
#define g_TriggerIndex (*(int16_t **)0x00526288)
#define g_LOSRooms (*(int32_t(*)[20])0x005262A0)
#define g_Items (*(struct ITEM_INFO(*)[])0x005262F0)
#define g_Items (*(struct ITEM_INFO **)0x005262F0)
#define g_NumCineFrames (*(int16_t*)0x005262F6)
#define g_CineData (*(CINE_FRAME **)0x005262F8) // = NULL
#define g_CinePos (*(struct PHD_3DPOS*)0x00526300)
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static void Inject_LOS(void)
INJECT(1, 0x00415C80, LOS_CheckZ);
INJECT(1, 0x00415F70, LOS_CheckX);
INJECT(1, 0x00416260, LOS_ClipTarget);
INJECT(1, 0x00416340, LOS_CheckSmashable);
}

static void Inject_Lara_Misc(void)
Expand Down

0 comments on commit a9ab1f8

Please sign in to comment.