Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tr1/lara: add wading support #1728

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/tr1/ship/data/injections/lara_animations.bin
Binary file not shown.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## [Unreleased](https://github.com/LostArtefacts/TRX/compare/tr1-4.5.1...develop) - ××××-××-××
- added support for wading, similar to TR2+ (#1537)
- fixed missing pushblock SFX in Natla's Mines (#1714)
- improved enemy item drops by supporting the TR2+ approach of having drops defined in level data (#1713)

Expand Down
1 change: 1 addition & 0 deletions docs/tr1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ Not all options are turned on by default. Refer to `TR1X_ConfigTool.exe` for det
- added ability to automatically walk to items when nearby
- added ability to roll while underwater like in TR2+
- added ability to use Lara's underwater swimming physics from TR2+
- added ability to wade, similar to TR2+
- added Lara's exit-water-to-medium-height animation from TR2+
- added a pause screen
- added a choice whether to play NG or NG+ without having to play the entire game
Expand Down
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/lara/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct __PACKING {
int16_t dive_timer;
int16_t death_timer;
int16_t current_active;
int32_t water_surface_dist;
int16_t spaz_effect_count;
FX *spaz_effect;
int32_t mesh_effects;
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
1 change: 1 addition & 0 deletions src/tr1/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ typedef struct {
bool enable_swing_cancel;
bool enable_tr2_jumping;
bool enable_tr2_swimming;
bool enable_wading;
bool load_current_music;
bool load_music_triggers;
bool fix_item_rots;
Expand Down
1 change: 1 addition & 0 deletions src/tr1/config_map.def
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ CFG_BOOL(g_Config, fix_texture_issues, true)
CFG_BOOL(g_Config, enable_swing_cancel, true)
CFG_BOOL(g_Config, enable_tr2_jumping, false)
CFG_BOOL(g_Config, enable_tr2_swimming, false)
CFG_BOOL(g_Config, enable_wading, true)
CFG_BOOL(g_Config, load_current_music, true)
CFG_BOOL(g_Config, load_music_triggers, true)
CFG_BOOL(g_Config, fix_item_rots, true)
Expand Down
12 changes: 10 additions & 2 deletions src/tr1/game/gun/gun.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "game/gun.h"

#include "game/gun/gun_misc.h"
#include "game/gun/gun_pistols.h"
#include "game/gun/gun_rifle.h"
#include "game/input.h"
Expand Down Expand Up @@ -27,7 +28,11 @@ void Gun_Control(void)
bool draw = false;
if (g_LaraItem->hit_points <= 0) {
g_Lara.gun_status = LGS_ARMLESS;
} else if (g_Lara.water_status == LWS_ABOVE_WATER) {
} else if (
g_Lara.water_status == LWS_ABOVE_WATER
|| (g_Lara.water_status == LWS_WADE
&& g_Lara.water_surface_dist
> -g_Weapons[g_Lara.gun_type].gun_height)) {
if (g_Lara.request_gun_type != LGT_UNARMED
&& (g_Lara.request_gun_type != g_Lara.gun_type
|| g_Lara.gun_status == LGS_ARMLESS)) {
Expand All @@ -49,7 +54,10 @@ void Gun_Control(void)
g_Lara.request_gun_type = LGT_UNARMED;
}
} else if (g_Lara.gun_status == LGS_READY) {
draw = true;
draw = g_Lara.water_status != LWS_ABOVE_WATER
&& (g_Lara.water_status != LWS_WADE
|| g_Lara.water_surface_dist
< -g_Weapons[g_Lara.gun_type].gun_height);
}

if (draw && g_Lara.gun_type != LGT_UNARMED) {
Expand Down
2 changes: 1 addition & 1 deletion src/tr1/game/lara/cheat.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ bool Lara_Cheat_EnterFlyMode(void)
}

if (g_Lara.water_status != LWS_UNDERWATER || g_LaraItem->hit_points <= 0) {
g_LaraItem->pos.y -= 0x80;
g_LaraItem->pos.y -= STEP_L;
g_LaraItem->current_anim_state = LS_SWIM;
g_LaraItem->goal_anim_state = LS_SWIM;
Item_SwitchToAnim(g_LaraItem, LA_SWIM_GLIDE, 0);
Expand Down
116 changes: 110 additions & 6 deletions src/tr1/game/lara/col.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#define LF_BACK_R_START 26
#define LF_BACK_R_END 55

#define LF_WADE_L_START 0
#define LF_WADE_L_END 9
#define LF_WADE_R_START 10
#define LF_WADE_R_END 21

#define LF_WADE_STEP_L_START 3
#define LF_WADE_STEP_L_END 14

void (*g_LaraCollisionRoutines[])(ITEM *item, COLL_INFO *coll) = {
Lara_Col_Walk, Lara_Col_Run, Lara_Col_Stop,
Lara_Col_ForwardJump, Lara_Col_Pose, Lara_Col_FastBack,
Expand All @@ -54,11 +62,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 +101,32 @@ 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:
Item_SwitchToAnim(item, LA_STOP, 0);
break;
}
}

void Lara_Col_Walk(ITEM *item, COLL_INFO *coll)
{
g_Lara.move_angle = item->rot.y;
Expand Down Expand Up @@ -276,7 +311,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 +522,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 +576,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 +611,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 @@ -889,8 +938,12 @@ void Lara_Col_WaterOut(ITEM *item, COLL_INFO *coll)

void Lara_Col_SurfSwim(ITEM *item, COLL_INFO *coll)
{
coll->bad_neg = -STEPUP_HEIGHT;
g_Lara.move_angle = item->rot.y;
Lara_SurfaceCollision(item, coll);
if (g_Config.enable_wading) {
Lara_TestWaterClimbOut(item, coll);
}
}

void Lara_Col_SurfTread(ITEM *item, COLL_INFO *coll)
Expand Down Expand Up @@ -949,3 +1002,54 @@ 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 == HT_WALL && coll->front_floor < -STEP_L * 5 / 2
&& coll->old_anim_state == LS_WADE
&& Item_TestAnimEqual(item, LA_WADE)) {
item->current_anim_state = LS_SPLAT;
if (Item_TestFrameRange(item, LF_WADE_L_START, LF_WADE_L_END)) {
Item_SwitchToAnim(item, LA_HIT_WALL_LEFT, 0);
return;
}
if (Item_TestFrameRange(item, LF_WADE_R_START, LF_WADE_R_END)) {
Item_SwitchToAnim(item, LA_HIT_WALL_RIGHT, 0);
return;
}
}
M_CollideStop(item, coll);
}

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

if (coll->mid_floor >= -STEPUP_HEIGHT && coll->mid_floor < -STEP_L / 2) {
if (Item_TestFrameRange(
item, LF_WADE_STEP_L_START, LF_WADE_STEP_L_END)) {
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