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

Commit

Permalink
port Item_Kill
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Nov 6, 2023
1 parent 0b97bfe commit 2e91821
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 15 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.
2 changes: 1 addition & 1 deletion docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ typedef enum LARA_MESH {

# game/items.c
00426CF0 00000052 + void __cdecl Item_InitialiseArray(int32_t num_items);
00426D50 0000011E - void __cdecl Item_Kill(int16_t item_num);
00426D50 0000011E + void __cdecl Item_Kill(int16_t item_num);
00426E70 00000039 - int16_t __cdecl Item_Create(void);
00426EB0 000001B3 - void __cdecl Item_Initialise(int16_t item_num);
00427070 0000008A - void __cdecl Item_RemoveActive(int16_t item_num);
Expand Down
8 changes: 4 additions & 4 deletions src/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void __cdecl Camera_SmartShift(
if (good_left) {
camera_box = good_left->box;
edge = (int32_t)g_Boxes[camera_box].left << WALL_SHIFT;
if (camera_box != NO_ITEM && edge < left) {
if (camera_box != NO_BOX && edge < left) {
left = edge;
}
} else {
Expand All @@ -275,7 +275,7 @@ void __cdecl Camera_SmartShift(
if (good_right) {
camera_box = good_right->box;
edge = ((int32_t)g_Boxes[camera_box].right << WALL_SHIFT) - 1;
if (camera_box != NO_ITEM && edge > right) {
if (camera_box != NO_BOX && edge > right) {
right = edge;
}
} else {
Expand All @@ -288,7 +288,7 @@ void __cdecl Camera_SmartShift(
if (good_top) {
camera_box = good_top->box;
edge = (int32_t)g_Boxes[camera_box].top << WALL_SHIFT;
if (camera_box != NO_ITEM && edge < top) {
if (camera_box != NO_BOX && edge < top) {
top = edge;
}
} else {
Expand All @@ -301,7 +301,7 @@ void __cdecl Camera_SmartShift(
if (good_bottom) {
camera_box = good_bottom->box;
edge = ((int32_t)g_Boxes[camera_box].bottom << WALL_SHIFT) - 1;
if (camera_box != NO_ITEM && edge > bottom) {
if (camera_box != NO_BOX && edge > bottom) {
bottom = edge;
}
} else {
Expand Down
45 changes: 45 additions & 0 deletions src/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,51 @@ void __cdecl Item_InitialiseArray(const int32_t num_items)
g_Items[num_items - 1].next_item = NO_ITEM;
}

void __cdecl Item_Kill(const int16_t item_num)
{
struct ITEM_INFO *const item = &g_Items[item_num];
item->active = 0;

int16_t link_num = g_NextItemActive;
if (link_num == item_num) {
g_NextItemActive = item->next_active;
} else {
while (link_num != NO_ITEM) {
if (g_Items[link_num].next_active == item_num) {
g_Items[link_num].next_active = item->next_active;
break;
}
link_num = g_Items[link_num].next_active;
}
}

if (item->room_num != NO_ROOM) {
link_num = g_Rooms[item->room_num].item_num;
if (link_num == item_num) {
g_Rooms[item->room_num].item_num = item->next_item;
} else {
while (link_num != NO_ITEM) {
if (g_Items[link_num].next_item == item_num) {
g_Items[link_num].next_item = item->next_item;
break;
}
link_num = g_Items[link_num].next_item;
}
}
}

if (item == g_Lara.target) {
g_Lara.target = NULL;
}

if (item_num < g_LevelItemCount) {
item->flags |= IF_KILLED_ITEM;
} else {
item->next_item = g_NextItemFree;
g_NextItemFree = item_num;
}
}

bool Item_IsSmashable(const struct ITEM_INFO *item)
{
return (item->object_num == O_WINDOW_1 || item->object_num == O_BELL);
Expand Down
1 change: 1 addition & 0 deletions src/game/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
#include "global/types.h"

void __cdecl Item_InitialiseArray(int32_t num_items);
void __cdecl Item_Kill(int16_t item_num);

bool Item_IsSmashable(const struct ITEM_INFO *item);
1 change: 1 addition & 0 deletions src/global/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define MIN_SQUARE SQUARE(WALL_L / 3)
#define NO_BOX (-1)
#define NO_ITEM (-1)
#define NO_ROOM (-1)
#define NO_CAMERA (-1)

#define GRAVITY 6
Expand Down
1 change: 0 additions & 1 deletion src/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@
#define ShowGymStatsText ((void __cdecl (*)(char *time_str, int32_t type))0x00426340)
#define ShowStatsText ((void __cdecl (*)(char *time_str, int32_t type))0x00426520)
#define ShowEndStatsText ((void __cdecl (*)(void))0x004268C0)
#define Item_Kill ((void __cdecl (*)(int16_t item_num))0x00426D50)
#define Item_Create ((int16_t __cdecl (*)(void))0x00426E70)
#define Item_Initialise ((void __cdecl (*)(int16_t item_num))0x00426EB0)
#define Item_RemoveActive ((void __cdecl (*)(int16_t item_num))0x00427070)
Expand Down
9 changes: 8 additions & 1 deletion src/global/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ typedef struct TEXTSTRING {
uint32_t bottom : 1;
uint32_t background : 1;
uint32_t outline : 1;
uint32_t multiline : 1;
};
} flags;
uint16_t text_flags;
Expand Down Expand Up @@ -995,6 +994,14 @@ typedef struct CINE_FRAME {
int16_t roll;
} CINE_FRAME;

typedef enum ITEM_FLAG {
IF_ONESHOT = 0x0100,
IF_CODE_BITS = 0x3E00,
IF_REVERSE = 0x4000,
IF_NOT_VISIBLE = 0x0100,
IF_KILLED_ITEM = 0x8000,
} ITEM_FLAG;

typedef enum ITEM_STATUS {
IS_NOT_ACTIVE = 0,
IS_ACTIVE = 1,
Expand Down
1 change: 1 addition & 0 deletions src/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static void Inject_Sound(void)
static void Inject_Items(void)
{
INJECT(1, 0x00426CF0, Item_InitialiseArray);
INJECT(1, 0x00426D50, Item_Kill);
}

static void Inject_LOS(void)
Expand Down

0 comments on commit 2e91821

Please sign in to comment.