Skip to content

Commit

Permalink
tr2: port MovableBlock_TestPush
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 17, 2024
1 parent 947ea2b commit fa7e293
Show file tree
Hide file tree
Showing 6 changed files with 71 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 @@ -3527,7 +3527,7 @@ typedef enum {
0x00433920 0x0148 + void __cdecl MovableBlock_Control(int16_t item_num);
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);
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);
0x004340B0 0x00BB + void __cdecl Room_AlterFloorHeight(ITEM *item, int32_t height);
0x00434170 0x0022 - void __cdecl MovableBlock_Draw(const ITEM *item);
Expand Down
58 changes: 58 additions & 0 deletions src/tr2/game/objects/general/movable_block.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "game/objects/general/movable_block.h"

#include "game/collide.h"
#include "game/input.h"
#include "game/items.h"
#include "game/lara/control.h"
Expand Down Expand Up @@ -29,6 +30,63 @@ int32_t __cdecl MovableBlock_TestDestination(
return floor == NO_HEIGHT || (floor == item->pos.y - block_height);
}

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

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

switch (quadrant) {
case DIR_NORTH:
z += WALL_L;
break;
case DIR_EAST:
x += WALL_L;
break;
case DIR_SOUTH:
z -= WALL_L;
break;
case DIR_WEST:
x -= WALL_L;
break;
default:
break;
}

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;
}

Room_GetHeight(sector, x, y, z);
if (g_HeightType != HT_WALL) {
return false;
}

const int32_t y_max = y - block_height + 100;
sector = Room_GetSector(x, y_max, z, &room_num);
if (Room_GetCeiling(sector, x, y_max, z) > y_max) {
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 @@ -5,6 +5,9 @@
int32_t __cdecl MovableBlock_TestDestination(
const ITEM *item, int32_t block_height);

int32_t __cdecl MovableBlock_TestPush(
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_TestPush ((int32_t __cdecl (*)(ITEM *item, int32_t block_height, uint16_t quadrant))0x00433D20)
#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)
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 @@ -974,6 +974,7 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x00433920, MovableBlock_Control);
INJECT(enable, 0x00433A70, MovableBlock_Collision);
INJECT(enable, 0x00433CD0, MovableBlock_TestDestination);
INJECT(enable, 0x00433D20, MovableBlock_TestPush);
INJECT(enable, 0x00434400, FinalLevelCounter_Control);
INJECT(enable, 0x00434800, GongBonger_Control);
INJECT(enable, 0x004348C0, Zipline_Collision);
Expand Down

0 comments on commit fa7e293

Please sign in to comment.