Skip to content

Commit

Permalink
items: introduce Item_GetIndex
Browse files Browse the repository at this point in the history
This provides a common function to retrieve an item index.
  • Loading branch information
lahm86 committed Feb 6, 2025
1 parent c3559cc commit b1b3068
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/libtrx/game/items.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ void Item_TakeDamage(
}
}

int16_t Item_GetIndex(const ITEM *const item)
{
return item - Item_Get(0);
}

ITEM *Item_Find(const GAME_OBJECT_ID obj_id)
{
for (int32_t item_num = 0; item_num < Item_GetTotalCount(); item_num++) {
Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/items/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "./types.h"

ITEM *Item_Get(int16_t num);
int16_t Item_GetIndex(const ITEM *item);
ITEM *Item_Find(GAME_OBJECT_ID obj_id);
int32_t Item_GetTotalCount(void);
int32_t Item_GetDistance(const ITEM *item, const XYZ_32 *target);
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/lara/cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ bool Lara_Cheat_Teleport(int32_t x, int32_t y, int32_t z)
g_LaraItem->floor = height;

if (g_LaraItem->room_num != room_num) {
const int16_t item_num = g_LaraItem - Item_Get(0);
const int16_t item_num = Item_GetIndex(g_LaraItem);
Item_NewRoom(item_num, room_num);
}

Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/overlay.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ static void M_BarDrawEnemy(void)
break;

case BSM_BOSS_ONLY:
m_EnemyBar.show = Creature_IsBoss(g_Lara.target - Item_Get(0));
m_EnemyBar.show = Creature_IsBoss(Item_GetIndex(g_Lara.target));
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tr2/game/lara/cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ bool Lara_Cheat_Teleport(int32_t x, int32_t y, int32_t z)
g_LaraItem->floor = height;

if (g_LaraItem->room_num != room_num) {
const int16_t item_num = g_LaraItem - Item_Get(0);
const int16_t item_num = Item_GetIndex(g_LaraItem);
Item_NewRoom(item_num, room_num);
}

Expand Down
5 changes: 2 additions & 3 deletions src/tr2/game/objects/creatures/skidoo_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ static int16_t M_ControlAlive(ITEM *driver_item, ITEM *skidoo_item);

static void M_KillDriver(ITEM *const driver_item)
{
// TODO: Item_GetIndex(const ITEM *item)
const int32_t driver_item_num = driver_item - Item_Get(0);
const int32_t driver_item_num = Item_GetIndex(driver_item);
Item_RemoveActive(driver_item_num);
driver_item->collidable = 0;
driver_item->flags |= IF_ONE_SHOT;
Expand All @@ -50,7 +49,7 @@ static void M_KillDriver(ITEM *const driver_item)

static void M_MakeMountable(ITEM *const skidoo_item)
{
const int32_t skidoo_item_num = skidoo_item - Item_Get(0);
const int32_t skidoo_item_num = Item_GetIndex(skidoo_item);
LOT_DisableBaddieAI(skidoo_item_num);
skidoo_item->object_id = O_SKIDOO_FAST;
skidoo_item->status = IS_DEACTIVATED;
Expand Down

0 comments on commit b1b3068

Please sign in to comment.