Skip to content

Commit

Permalink
tr1/carrier: reorder function implementations
Browse files Browse the repository at this point in the history
This puts static functions first in the carrier module, followed by
public.
  • Loading branch information
lahm86 committed Oct 15, 2024
1 parent bec26d1 commit 78f7807
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions src/tr1/game/carrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,70 @@ static const GAME_OBJECT_PAIR m_LegacyMap[] = {
{ NO_OBJECT, NO_OBJECT },
};

static ITEM *M_GetCarrier(int16_t item_num)
{
if (item_num < 0 || item_num >= g_LevelItemCount) {
return NULL;
}

// Allow carried items to be allocated to holder objects (pods/statues),
// but then have those items dropped by the actual creatures within.
ITEM *item = &g_Items[item_num];
if (Object_IsObjectType(item->object_id, g_PlaceholderObjects)) {
int16_t child_item_num = *(int16_t *)item->data;
item = &g_Items[child_item_num];
}

if (!g_Objects[item->object_id].loaded) {
return NULL;
}

return item;
}

static void M_AnimateDrop(CARRIED_ITEM *item)
{
if (item->status != DS_FALLING) {
return;
}

ITEM *const pickup = &g_Items[item->spawn_num];
int16_t room_num = pickup->room_num;
const SECTOR *const sector =
Room_GetSector(pickup->pos.x, pickup->pos.y, pickup->pos.z, &room_num);
const int16_t height =
Room_GetHeight(sector, pickup->pos.x, pickup->pos.y, pickup->pos.z);
const bool in_water = g_RoomInfo[pickup->room_num].flags & RF_UNDERWATER;

if (sector->portal_room.pit == NO_ROOM && pickup->pos.y >= height) {
item->status = DS_DROPPED;
pickup->pos.y = height;
pickup->fall_speed = 0;
m_AnimatingCount--;
} else {
pickup->fall_speed += (!in_water && pickup->fall_speed < FASTFALL_SPEED)
? DROP_FAST_RATE
: DROP_SLOW_RATE;
pickup->pos.y += pickup->fall_speed;
pickup->rot.y += in_water ? DROP_SLOW_TURN : DROP_FAST_TURN;

if (sector->portal_room.pit != NO_ROOM
&& pickup->pos.y > sector->floor.height) {
room_num = sector->portal_room.pit;
}
}

if (room_num != pickup->room_num) {
Item_NewRoom(item->spawn_num, room_num);
}

// Track animating status in the carrier for saving/loading.
item->pos = pickup->pos;
item->rot = pickup->rot;
item->room_num = pickup->room_num;
item->fall_speed = pickup->fall_speed;
}

void Carrier_InitialiseLevel(int32_t level_num)
{
m_AnimatingCount = 0;
Expand Down Expand Up @@ -92,27 +156,6 @@ void Carrier_InitialiseLevel(int32_t level_num)
}
}

static ITEM *M_GetCarrier(int16_t item_num)
{
if (item_num < 0 || item_num >= g_LevelItemCount) {
return NULL;
}

// Allow carried items to be allocated to holder objects (pods/statues),
// but then have those items dropped by the actual creatures within.
ITEM *item = &g_Items[item_num];
if (Object_IsObjectType(item->object_id, g_PlaceholderObjects)) {
int16_t child_item_num = *(int16_t *)item->data;
item = &g_Items[child_item_num];
}

if (!g_Objects[item->object_id].loaded) {
return NULL;
}

return item;
}

int32_t Carrier_GetItemCount(int16_t item_num)
{
ITEM *carrier = M_GetCarrier(item_num);
Expand Down Expand Up @@ -232,46 +275,3 @@ void Carrier_AnimateDrops(void)
}
}
}

static void M_AnimateDrop(CARRIED_ITEM *item)
{
if (item->status != DS_FALLING) {
return;
}

ITEM *const pickup = &g_Items[item->spawn_num];
int16_t room_num = pickup->room_num;
const SECTOR *const sector =
Room_GetSector(pickup->pos.x, pickup->pos.y, pickup->pos.z, &room_num);
const int16_t height =
Room_GetHeight(sector, pickup->pos.x, pickup->pos.y, pickup->pos.z);
const bool in_water = g_RoomInfo[pickup->room_num].flags & RF_UNDERWATER;

if (sector->portal_room.pit == NO_ROOM && pickup->pos.y >= height) {
item->status = DS_DROPPED;
pickup->pos.y = height;
pickup->fall_speed = 0;
m_AnimatingCount--;
} else {
pickup->fall_speed += (!in_water && pickup->fall_speed < FASTFALL_SPEED)
? DROP_FAST_RATE
: DROP_SLOW_RATE;
pickup->pos.y += pickup->fall_speed;
pickup->rot.y += in_water ? DROP_SLOW_TURN : DROP_FAST_TURN;

if (sector->portal_room.pit != NO_ROOM
&& pickup->pos.y > sector->floor.height) {
room_num = sector->portal_room.pit;
}
}

if (room_num != pickup->room_num) {
Item_NewRoom(item->spawn_num, room_num);
}

// Track animating status in the carrier for saving/loading.
item->pos = pickup->pos;
item->rot = pickup->rot;
item->room_num = pickup->room_num;
item->fall_speed = pickup->fall_speed;
}

0 comments on commit 78f7807

Please sign in to comment.