Skip to content

Commit

Permalink
tr2: port Zipline_Control
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Oct 16, 2024
1 parent 58ce1e9 commit 6ba1493
Show file tree
Hide file tree
Showing 6 changed files with 98 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 @@ -3543,7 +3543,7 @@ typedef enum {
0x00434770 0x0087 -R void __cdecl DyingMonk(int16_t item_num);
0x00434800 0x00BD + void __cdecl GongBonger_Control(int16_t item_num);
0x004348C0 0x00BF + void __cdecl Zipline_Collision(int16_t item_num, ITEM *lara_item, COLL_INFO *coll);
0x00434980 0x028F -R void __cdecl Zipline_Control(int16_t item_num);
0x00434980 0x028F + void __cdecl Zipline_Control(int16_t item_num);
0x00434C10 0x00E3 -R void __cdecl BigBowlControl(int16_t item_num);
0x00434D00 0x007E -R void __cdecl BellControl(int16_t item_num);
0x00434D80 0x0075 -R void __cdecl InitialiseWindow(int16_t item_num);
Expand Down
86 changes: 86 additions & 0 deletions src/tr2/game/objects/general/zipline.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@

#include "game/input.h"
#include "game/items.h"
#include "game/lara/control.h"
#include "game/math.h"
#include "game/room.h"
#include "game/sound.h"
#include "global/vars.h"

#define ZIPLINE_MAX_SPEED 100
#define ZIPLINE_ACCELERATION 5

typedef enum {
ZIPLINE_EMPTY = 0,
ZIPLINE_GRAB = 1,
ZIPLINE_HANG = 2,
} ZIPLINE_STATUS;

void __cdecl Zipline_Collision(
const int16_t item_num, ITEM *const lara_item, COLL_INFO *const coll)
{
Expand Down Expand Up @@ -36,3 +49,76 @@ void __cdecl Zipline_Collision(
item->status = IS_ACTIVE;
item->flags |= IF_ONE_SHOT;
}

void __cdecl Zipline_Control(const int16_t item_num)
{
ITEM *const item = &g_Items[item_num];
if (item->status != IS_ACTIVE) {
return;
}

if (!(item->flags & IF_ONE_SHOT)) {
const GAME_VECTOR *const old = item->data;
item->pos = old->pos;
if (old->room_num != item->room_num) {
Item_NewRoom(item_num, old->room_num);
}
item->status = IS_INACTIVE;
item->goal_anim_state = ZIPLINE_GRAB;
item->current_anim_state = ZIPLINE_GRAB;
item->anim_num = g_Objects[item->object_id].anim_idx;
item->frame_num = g_Anims[item->anim_num].frame_base;
Item_RemoveActive(item_num);
return;
}

if (item->current_anim_state == ZIPLINE_GRAB) {
Item_Animate(item);
return;
}

Item_Animate(item);
if (item->fall_speed < ZIPLINE_MAX_SPEED) {
item->fall_speed += ZIPLINE_ACCELERATION;
}

const int32_t c = Math_Cos(item->rot.y);
const int32_t s = Math_Sin(item->rot.y);
item->pos.x += (item->fall_speed * s) >> W2V_SHIFT;
item->pos.z += (item->fall_speed * c) >> W2V_SHIFT;
item->pos.y += item->fall_speed >> 2;

int16_t room_num = item->room_num;
Room_GetSector(item->pos.x, item->pos.y, item->pos.z, &room_num);
if (room_num != item->room_num) {
Item_NewRoom(item_num, room_num);
}

const bool lara_on_zipline = g_LaraItem->current_anim_state == LS_ZIPLINE;
if (lara_on_zipline) {
g_LaraItem->pos = item->pos;
}

const int32_t x = item->pos.x + ((s * WALL_L) >> W2V_SHIFT);
const int32_t z = item->pos.z + ((c * WALL_L) >> W2V_SHIFT);
const int32_t y = item->pos.y + (STEP_L >> 2);

const SECTOR *const sector = Room_GetSector(x, y, z, &room_num);
if (Room_GetHeight(sector, x, y, z) > y + STEP_L
&& Room_GetCeiling(sector, x, y, z) < y - STEP_L) {
Sound_Effect(SFX_ZIPLINE_GO, &item->pos, SPM_ALWAYS);
return;
}

if (lara_on_zipline) {
g_LaraItem->goal_anim_state = LS_FORWARD_JUMP;
Lara_Animate(g_LaraItem);
g_LaraItem->gravity = 1;
g_LaraItem->speed = item->fall_speed;
g_LaraItem->fall_speed = item->fall_speed >> 2;
}
Sound_Effect(SFX_ZIPLINE_STOP, &item->pos, SPM_ALWAYS);
Item_RemoveActive(item_num);
item->status = IS_INACTIVE;
item->flags &= ~IF_ONE_SHOT;
}
2 changes: 2 additions & 0 deletions src/tr2/game/objects/general/zipline.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@

void __cdecl Zipline_Collision(
int16_t item_num, ITEM *lara_item, COLL_INFO *coll);

void __cdecl Zipline_Control(int16_t item_num);
1 change: 0 additions & 1 deletion src/tr2/global/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
#define MiniCopterControl ((void __cdecl (*)(int16_t item_num))0x00434610)
#define InitialiseDyingMonk ((void __cdecl (*)(int16_t item_num))0x004346F0)
#define DyingMonk ((void __cdecl (*)(int16_t item_num))0x00434770)
#define Zipline_Control ((void __cdecl (*)(int16_t item_num))0x00434980)
#define BigBowlControl ((void __cdecl (*)(int16_t item_num))0x00434C10)
#define BellControl ((void __cdecl (*)(int16_t item_num))0x00434D00)
#define InitialiseWindow ((void __cdecl (*)(int16_t item_num))0x00434D80)
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 @@ -972,6 +972,7 @@ static void M_Objects(const bool enable)
INJECT(enable, 0x00434400, FinalLevelCounter_Control);
INJECT(enable, 0x00434800, GongBonger_Control);
INJECT(enable, 0x004348C0, Zipline_Collision);
INJECT(enable, 0x00434980, Zipline_Control);
INJECT(enable, 0x00435D70, Detonator_Control);
INJECT(enable, 0x00437E70, Pickup_Collision);
INJECT(enable, 0x004382F0, Switch_Collision);
Expand Down

0 comments on commit 6ba1493

Please sign in to comment.