Skip to content

Commit

Permalink
tr2: port MovableBlock_TestPull
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 17, 2024
1 parent fa7e293 commit bd27a64
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
16 changes: 8 additions & 8 deletions docs/tr2/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/tr2/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3528,7 +3528,7 @@ typedef enum {
0x00433A70 0x0239 + void __cdecl MovableBlock_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
0x00433CD0 0x004E + int32_t __cdecl MovableBlock_TestDestination(ITEM *item, int32_t block_height);
0x00433D20 0x0137 + int32_t __cdecl MovableBlock_TestPush(ITEM *item, int32_t block_height, uint16_t quadrant);
0x00433E70 0x0225 - int32_t __cdecl MovableBlock_TestPull(ITEM *item, int32_t block_height, uint16_t quadrant);
0x00433E70 0x0225 + int32_t __cdecl MovableBlock_TestPull(ITEM *item, int32_t block_height, uint16_t quadrant);
0x004340B0 0x00BB + void __cdecl Room_AlterFloorHeight(ITEM *item, int32_t height);
0x00434170 0x0022 - void __cdecl MovableBlock_Draw(const ITEM *item);
0x004341A0 0x006B - void __cdecl Object_DrawUnclippedItem(const ITEM *item);
Expand Down
78 changes: 78 additions & 0 deletions src/tr2/game/objects/general/movable_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,84 @@ int32_t __cdecl MovableBlock_TestPush(
return true;
}

int32_t __cdecl MovableBlock_TestPull(
const ITEM *const item, const int32_t block_height, const uint16_t quadrant)
{
if (!MovableBlock_TestDestination(item, block_height)) {
return false;
}

int32_t x_add = 0;
int32_t z_add = 0;
switch (quadrant) {
case DIR_NORTH:
z_add = -WALL_L;
break;
case DIR_EAST:
x_add = -WALL_L;
break;
case DIR_SOUTH:
z_add = WALL_L;
break;
case DIR_WEST:
x_add = WALL_L;
break;
default:
break;
}

int32_t x = item->pos.x + x_add;
int32_t y = item->pos.y;
int32_t z = item->pos.z + z_add;
int16_t room_num = item->room_num;

COLL_INFO coll = {
.quadrant = quadrant,
.radius = 500,
0,
};
if (Collide_CollideStaticObjects(&coll, x, y, z, room_num, 1000)) {
return false;
}

const SECTOR *sector = Room_GetSector(x, y, z, &room_num);
if ((sector->floor << 8) != y) {
return false;
}

const int32_t y_min = y - block_height;
sector = Room_GetSector(x, y_min, z, &room_num);
if ((sector->ceiling << 8) > y_min) {
return false;
}

x += x_add;
z += z_add;
room_num = item->room_num;
sector = Room_GetSector(x, y, z, &room_num);
if ((sector->floor << 8) != y) {
return false;
}

sector = Room_GetSector(x, y - LARA_HEIGHT, z, &room_num);
if ((sector->ceiling << 8) > y - LARA_HEIGHT) {
return false;
}

x = g_LaraItem->pos.x + x_add;
z = g_LaraItem->pos.z + z_add;
y = g_LaraItem->pos.y;
room_num = g_LaraItem->room_num;
Room_GetSector(x, y, z, &room_num);
coll.quadrant = (quadrant + 2) & 3;
coll.radius = LARA_RADIUS;
if (Collide_CollideStaticObjects(&coll, x, y, z, room_num, LARA_HEIGHT)) {
return false;
}

return true;
}

void __cdecl MovableBlock_Initialise(const int16_t item_num)
{
ITEM *item = &g_Items[item_num];
Expand Down
3 changes: 3 additions & 0 deletions src/tr2/game/objects/general/movable_block.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ int32_t __cdecl MovableBlock_TestDestination(
int32_t __cdecl MovableBlock_TestPush(
const ITEM *item, int32_t block_height, uint16_t quadrant);

int32_t __cdecl MovableBlock_TestPull(
const ITEM *item, int32_t block_height, uint16_t quadrant);

void __cdecl MovableBlock_Initialise(int16_t item_num);

void __cdecl MovableBlock_Control(int16_t item_num);
Expand Down
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@
#define ControlMissile ((void __cdecl (*)(int16_t fx_num))0x00432FE0)
#define ShootAtLara ((void __cdecl (*)(FX *fx))0x004332B0)
#define BodyPart_Control ((void __cdecl (*)(int16_t fx_num))0x004336F0)
#define MovableBlock_TestPull ((int32_t __cdecl (*)(ITEM *item, int32_t block_height, uint16_t quadrant))0x00433E70)
#define MovableBlock_Draw ((void __cdecl (*)(const ITEM *item))0x00434170)
#define Object_DrawUnclippedItem ((void __cdecl (*)(const ITEM *item))0x004341A0)
#define EarthQuake ((void __cdecl (*)(int16_t item_num))0x00434210)
Expand Down
1 change: 1 addition & 0 deletions src/tr2/inject_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x00433A70, MovableBlock_Collision);
INJECT(enable, 0x00433CD0, MovableBlock_TestDestination);
INJECT(enable, 0x00433D20, MovableBlock_TestPush);
INJECT(enable, 0x00433E70, MovableBlock_TestPull);
INJECT(enable, 0x00434400, FinalLevelCounter_Control);
INJECT(enable, 0x00434800, GongBonger_Control);
INJECT(enable, 0x004348C0, Zipline_Collision);
Expand Down

0 comments on commit bd27a64

Please sign in to comment.