Skip to content

Commit

Permalink
tr1/lara: add wading support
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
lahm86 committed Oct 19, 2024
1 parent dd61414 commit 94ad856
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 95 deletions.
Binary file modified data/tr1/ship/data/injections/lara_animations.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions src/libtrx/include/libtrx/game/collision.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ typedef struct __PACKING {
int32_t bad_ceiling;
XYZ_32 shift;
XYZ_32 old;
int16_t old_anim_state;
int16_t old_anim_num;
int16_t old_frame_num;
int16_t facing;
DIRECTION quadrant;
int16_t coll_type;
Expand Down
2 changes: 0 additions & 2 deletions src/libtrx/include/libtrx/game/lara/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ typedef enum {
LWS_UNDERWATER = 1,
LWS_SURFACE = 2,
LWS_CHEAT = 3,
#if TR_VERSION == 2
LWS_WADE = 4,
#endif
} LARA_WATER_STATE;
// clang-format on

Expand Down
10 changes: 10 additions & 0 deletions src/libtrx/include/libtrx/game/lara/enum_tr1.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ typedef enum {
LA_HANG = 96,
LA_STOP_HANG = 28,
LA_SLIDE = 70,
LA_STAND_IDLE = 103,
LA_SLIDE_BACK = 104,
LA_TREAD = 108,
LA_SURF_TREAD = 114,
LA_SURF_SWIM_FORWARD = 116,
LA_SURF_DIVE = 119,
LA_SURF_CLIMB_HIGH = 111,
LA_JUMP_IN = 112,
LA_PUSHABLE_GRAB = 120,
LA_SURF_SWIM_BACK = 140,
LA_SURF_SWIM_LEFT = 143,
LA_SURF_SWIM_RIGHT = 144,
LA_ROLL = 146,
LA_PICKUP_UW = 130,
LA_PICKUP = 135,
Expand All @@ -91,6 +96,10 @@ typedef enum {
LA_SPAZ_RIGHT = 127,
LA_SPAZ_LEFT = 128,
LA_SURF_CLIMB_MEDIUM = 169,
LA_WADE = 170,
LA_SURF_TO_WADE = 178,
LA_SURF_TO_WADE_LOW = 179,
LA_UNDERWATER_TO_STAND = 180,
} LARA_ANIMATION;

// clang-format off
Expand Down Expand Up @@ -154,6 +163,7 @@ typedef enum {
LS_CONTROLLED = 56,
LS_TWIST = 57,
LS_UW_ROLL = 58,
LS_WADE = 59,
} LARA_STATE;
// clang-format on

Expand Down
1 change: 1 addition & 0 deletions src/libtrx/include/libtrx/game/sound/ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef enum {
SFX_BEAR_SNARL = 14,
SFX_LARA_WET_FEET = 15,
SFX_BEAR_HURT = 16,
SFX_LARA_WADE = 17,
SFX_BEAR_DEATH = 18,
SFX_WOLF_JUMP = 19,
SFX_WOLF_HURT = 20,
Expand Down
106 changes: 100 additions & 6 deletions src/tr1/game/lara/col.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "game/lara/col.h"

#include "config.h"
#include "game/anim.h"
#include "game/collide.h"
#include "game/input.h"
#include "game/items.h"
Expand Down Expand Up @@ -54,11 +55,12 @@ void (*g_LaraCollisionRoutines[])(ITEM *item, COLL_INFO *coll) = {
Lara_Col_SurfLeft, Lara_Col_SurfRight, Lara_Col_UseMidas,
Lara_Col_DieMidas, Lara_Col_SwanDive, Lara_Col_FastDive,
Lara_Col_Gymnast, Lara_Col_WaterOut, Lara_Col_Controlled,
Lara_Col_Twist, Lara_Col_UWRoll,
Lara_Col_Twist, Lara_Col_UWRoll, Lara_Col_Wade,
};

static void M_Default(ITEM *item, COLL_INFO *coll);
static void M_Jumper(ITEM *item, COLL_INFO *coll);
static void M_CollideStop(ITEM *item, const COLL_INFO *coll);

static void M_Default(ITEM *item, COLL_INFO *coll)
{
Expand Down Expand Up @@ -92,6 +94,34 @@ static void M_Jumper(ITEM *item, COLL_INFO *coll)
}
}

static void M_CollideStop(ITEM *const item, const COLL_INFO *const coll)
{
switch (coll->old_anim_state) {
case LS_STOP:
case LS_TURN_R:
case LS_TURN_L:
case LS_FAST_TURN:
item->current_anim_state = coll->old_anim_state;
item->anim_num = coll->old_anim_num;
item->frame_num = coll->old_frame_num;
if (g_Input.left) {
item->goal_anim_state = LS_TURN_L;
} else if (g_Input.right) {
item->goal_anim_state = LS_TURN_R;
} else {
item->goal_anim_state = LS_STOP;
}
Lara_Animate(item);
break;

default:
if (!Item_TestAnimEqual(item, LA_STAND_IDLE)) {
Item_SwitchToAnim(item, LA_STAND_IDLE, 0);
}
break;
}
}

void Lara_Col_Walk(ITEM *item, COLL_INFO *coll)
{
g_Lara.move_angle = item->rot.y;
Expand Down Expand Up @@ -276,7 +306,9 @@ void Lara_Col_ForwardJump(ITEM *item, COLL_INFO *coll)
if (item->fall_speed > 0 && coll->mid_floor <= 0) {
if (Lara_LandedBad(item, coll)) {
item->goal_anim_state = LS_DEATH;
} else if (g_Input.forward && !g_Input.slow) {
} else if (
g_Lara.water_status != LWS_WADE && g_Input.forward
&& !g_Input.slow) {
item->goal_anim_state = LS_RUN;
} else {
item->goal_anim_state = LS_STOP;
Expand Down Expand Up @@ -485,7 +517,11 @@ void Lara_Col_Back(ITEM *item, COLL_INFO *coll)
g_Lara.move_angle = item->rot.y - PHD_180;
item->gravity = 0;
item->fall_speed = 0;
coll->bad_pos = STEPUP_HEIGHT;
if (g_Lara.water_status == LWS_WADE) {
coll->bad_pos = NO_BAD_POS;
} else {
coll->bad_pos = STEPUP_HEIGHT;
}
coll->bad_neg = -STEPUP_HEIGHT;
coll->bad_ceiling = 0;
coll->slopes_are_walls = 1;
Expand Down Expand Up @@ -535,7 +571,11 @@ void Lara_Col_StepRight(ITEM *item, COLL_INFO *coll)
g_Lara.move_angle = item->rot.y + PHD_90;
item->gravity = 0;
item->fall_speed = 0;
coll->bad_pos = STEP_L / 2;
if (g_Lara.water_status == LWS_WADE) {
coll->bad_pos = NO_BAD_POS;
} else {
coll->bad_pos = STEP_L / 2;
}
coll->bad_neg = -STEP_L / 2;
coll->bad_ceiling = 0;
coll->slopes_are_walls = 1;
Expand Down Expand Up @@ -566,8 +606,12 @@ void Lara_Col_StepLeft(ITEM *item, COLL_INFO *coll)
g_Lara.move_angle = item->rot.y - PHD_90;
item->gravity = 0;
item->fall_speed = 0;
coll->bad_pos = 128;
coll->bad_neg = -128;
if (g_Lara.water_status == LWS_WADE) {
coll->bad_pos = NO_BAD_POS;
} else {
coll->bad_pos = STEP_L / 2;
}
coll->bad_neg = -STEP_L / 2;
coll->bad_ceiling = 0;
coll->slopes_are_walls = 1;
coll->slopes_are_pits = 1;
Expand Down Expand Up @@ -891,6 +935,7 @@ void Lara_Col_SurfSwim(ITEM *item, COLL_INFO *coll)
{
g_Lara.move_angle = item->rot.y;
Lara_SurfaceCollision(item, coll);
Lara_TestWaterClimbOut(item, coll);
}

void Lara_Col_SurfTread(ITEM *item, COLL_INFO *coll)
Expand Down Expand Up @@ -949,3 +994,52 @@ void Lara_Col_UWDeath(ITEM *item, COLL_INFO *coll)
}
Lara_SwimCollision(item, coll);
}

void Lara_Col_Wade(ITEM *item, COLL_INFO *coll)
{
g_Lara.move_angle = item->rot.y;
coll->slopes_are_walls = 1;
coll->bad_pos = NO_BAD_POS;
coll->bad_neg = -STEPUP_HEIGHT;
coll->bad_ceiling = 0;

Lara_GetCollisionInfo(item, coll);
if (Lara_HitCeiling(item, coll) || Lara_TestVault(item, coll)) {
return;
}

if (Lara_DeflectEdge(item, coll)) {
item->rot.z = 0;
if (coll->front_type != COLL_NONE
&& coll->front_floor < -STEP_L * 5 / 2) {
item->current_anim_state = LS_SPLAT;
if (Anim_TestAbsFrameRange(item->frame_num, 0, 9)) {
Item_SwitchToAnim(item, LA_HIT_WALL_LEFT, 0);
return;
}
if (Anim_TestAbsFrameRange(item->frame_num, 10, 21)) {
Item_SwitchToAnim(item, LA_HIT_WALL_RIGHT, 0);
return;
}
}
M_CollideStop(item, coll); // does this fix wall issues?
}

if (Lara_Fallen(item, coll)) {
return;
}

if (coll->mid_floor >= -STEPUP_HEIGHT && coll->mid_floor < -STEP_L / 2) {
if (Anim_TestAbsFrameRange(item->frame_num, 3, 14)) {
Item_SwitchToAnim(item, LA_RUN_STEP_UP_LEFT, 0);
} else {
Item_SwitchToAnim(item, LA_RUN_STEP_UP_RIGHT, 0);
}
}

if (Lara_TestSlide(item, coll)) {
return;
}

item->pos.y += MIN(coll->mid_floor, 50);
}
1 change: 1 addition & 0 deletions src/tr1/game/lara/col.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,4 @@ void Lara_Col_Gymnast(ITEM *item, COLL_INFO *coll);
void Lara_Col_WaterOut(ITEM *item, COLL_INFO *coll);
void Lara_Col_Twist(ITEM *item, COLL_INFO *coll);
void Lara_Col_UWRoll(ITEM *item, COLL_INFO *coll);
void Lara_Col_Wade(ITEM *item, COLL_INFO *coll);
Loading

0 comments on commit 94ad856

Please sign in to comment.