Skip to content

Commit

Permalink
gun: fix holsters and back mesh problems
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Aug 14, 2024
1 parent 826464b commit a1e72ac
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 214 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
- fixed the ingame timer being skewed upon inventory open (#1420, regression from 4.1)
- fixed Lara able to reach triggers through closed doors (#1419, regression from 1.1.4)
- fixed Lara voiding when loading the game on a closed door (#1419)
- fixed underwater caustics not resumed smoothly when unpausing (#1423, regression 3.2)
- fixed underwater caustics not resumed smoothly when unpausing (#1423, regression from 3.2)
- fixed collision issues with drawbridges, trapdoors, and bridges when stacked over each other, over slopes, and near the ground (#606)
- fixed an issue with a missing Spanish config tool translation for the target mode (#1439)
- fixed carrying over unexpected guns in holsters to the next level under rare scenarios (#1437, regression from 2.4)
- fixed item cheats not updating Lara holster and backpack meshes (#1437)
- improved initial level load time by lazy-loading audio samples (LostArtefacts/TR2X#114)

## [4.2](https://github.com/LostArtefacts/TR1X/compare/4.1.2...4.2) - 2024-07-14
Expand Down
16 changes: 4 additions & 12 deletions src/game/gameflow.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,6 +1115,10 @@ GameFlow_InterpretSequence(int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type)
break;

case GFS_LOOP_GAME:
if (level_type != GFL_SAVED
&& level_num != g_GameFlow.first_level_num) {
Lara_RevertToPistolsIfNeeded();
}
Phase_Set(PHASE_GAME, NULL);
ret = Phase_Run();
if (ret.command != GF_PHASE_CONTINUE) {
Expand Down Expand Up @@ -1258,18 +1262,6 @@ GameFlow_InterpretSequence(int32_t level_num, GAMEFLOW_LEVEL_TYPE level_type)
(const GAMEFLOW_GIVE_ITEM_DATA *)seq->data;
Inv_AddItemNTimes(
give_item_data->object_num, give_item_data->quantity);
if (g_Lara.gun_type == LGT_UNARMED) {
if (Inv_RequestItem(O_PISTOL_ITEM)) {
g_GameInfo.current[level_num].gun_type = LGT_PISTOLS;
} else if (Inv_RequestItem(O_SHOTGUN_ITEM)) {
g_GameInfo.current[level_num].gun_type = LGT_SHOTGUN;
} else if (Inv_RequestItem(O_MAGNUM_ITEM)) {
g_GameInfo.current[level_num].gun_type = LGT_MAGNUMS;
} else if (Inv_RequestItem(O_UZI_ITEM)) {
g_GameInfo.current[level_num].gun_type = LGT_UZIS;
}
Lara_InitialiseMeshes(level_num);
}
}
break;

Expand Down
9 changes: 7 additions & 2 deletions src/game/gun.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ int32_t Gun_FireWeapon(
void Gun_HitTarget(ITEM_INFO *item, GAME_VECTOR *hitpos, int16_t damage);
void Gun_DrawFlash(LARA_GUN_TYPE weapon_type, int32_t clip);
GAME_OBJECT_ID Gun_GetLaraAnim(LARA_GUN_TYPE gun_type);
GAME_OBJECT_ID Gun_GetPistolsAnim(LARA_GUN_TYPE gun_type);
GAME_OBJECT_ID Gun_GetRifleAnim(LARA_GUN_TYPE gun_type);
GAME_OBJECT_ID Gun_GetWeaponAnim(LARA_GUN_TYPE gun_type);
void Gun_UpdateLaraMeshes(GAME_OBJECT_ID object_id);
void Gun_SetLaraBackMesh(LARA_GUN_TYPE weapon_type);
void Gun_SetLaraHandLMesh(LARA_GUN_TYPE weapon_type);
void Gun_SetLaraHandRMesh(LARA_GUN_TYPE weapon_type);
void Gun_SetLaraHolsterLMesh(LARA_GUN_TYPE weapon_type);
void Gun_SetLaraHolsterRMesh(LARA_GUN_TYPE weapon_type);
115 changes: 94 additions & 21 deletions src/game/gun/gun.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include "game/gun/gun_rifle.h"
#include "game/input.h"
#include "game/inventory.h"
#include "game/lara.h"
#include "game/output.h"
#include "game/random.h"
#include "global/const.h"
#include "global/vars.h"
#include "math/matrix.h"

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>

Expand Down Expand Up @@ -73,6 +75,9 @@ void Gun_Control(void)
g_Lara.gun_status = LGS_UNDRAW;
}
break;

default:
break;
}
}

Expand All @@ -94,12 +99,15 @@ void Gun_Control(void)
}
Gun_Rifle_Draw(g_Lara.gun_type);
break;

default:
break;
}
break;

case LGS_UNDRAW:
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_LARA);

switch (g_Lara.gun_type) {
case LGT_PISTOLS:
case LGT_MAGNUMS:
Expand All @@ -110,17 +118,19 @@ void Gun_Control(void)
case LGT_SHOTGUN:
Gun_Rifle_Undraw(g_Lara.gun_type);
break;

default:
break;
}
break;

case LGS_READY:
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_LARA);

switch (g_Lara.gun_type) {
case LGT_PISTOLS:
if (g_Lara.pistols.ammo && g_Input.action) {
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_UZI_ANIM].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_UZI_ANIM);
}
if (g_Camera.type != CAM_CINEMATIC && g_Camera.type != CAM_LOOK) {
g_Camera.type = CAM_COMBAT;
Expand All @@ -130,8 +140,7 @@ void Gun_Control(void)

case LGT_MAGNUMS:
if (g_Lara.magnums.ammo && g_Input.action) {
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_UZI_ANIM].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_UZI_ANIM);
}
if (g_Camera.type != CAM_CINEMATIC && g_Camera.type != CAM_LOOK) {
g_Camera.type = CAM_COMBAT;
Expand All @@ -141,8 +150,7 @@ void Gun_Control(void)

case LGT_UZIS:
if (g_Lara.uzis.ammo && g_Input.action) {
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_UZI_ANIM].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_UZI_ANIM);
}
if (g_Camera.type != CAM_CINEMATIC && g_Camera.type != CAM_LOOK) {
g_Camera.type = CAM_COMBAT;
Expand All @@ -152,14 +160,16 @@ void Gun_Control(void)

case LGT_SHOTGUN:
if (g_Lara.shotgun.ammo && g_Input.action) {
g_Lara.mesh_ptrs[LM_HEAD] =
g_Meshes[g_Objects[O_UZI_ANIM].mesh_index + LM_HEAD];
Lara_SwapSingleMesh(LM_HEAD, O_UZI_ANIM);
}
if (g_Camera.type != CAM_CINEMATIC && g_Camera.type != CAM_LOOK) {
g_Camera.type = CAM_COMBAT;
}
Gun_Rifle_Control(g_Lara.gun_type);
break;

default:
break;
}
break;
}
Expand Down Expand Up @@ -208,7 +218,7 @@ GAME_OBJECT_ID Gun_GetLaraAnim(const LARA_GUN_TYPE gun_type)
}
}

GAME_OBJECT_ID Gun_GetPistolsAnim(const LARA_GUN_TYPE gun_type)
GAME_OBJECT_ID Gun_GetWeaponAnim(const LARA_GUN_TYPE gun_type)
{
switch (gun_type) {
case LGT_PISTOLS:
Expand All @@ -217,14 +227,6 @@ GAME_OBJECT_ID Gun_GetPistolsAnim(const LARA_GUN_TYPE gun_type)
return O_MAGNUM_ANIM;
case LGT_UZIS:
return O_UZI_ANIM;
default:
return NO_OBJECT;
}
}

GAME_OBJECT_ID Gun_GetRifleAnim(const LARA_GUN_TYPE gun_type)
{
switch (gun_type) {
case LGT_SHOTGUN:
return O_SHOTGUN_ANIM;
default:
Expand Down Expand Up @@ -271,3 +273,74 @@ void Gun_DrawFlash(LARA_GUN_TYPE weapon_type, int32_t clip)
Output_DrawPolygons(g_Meshes[g_Objects[O_GUN_FLASH].mesh_index], clip);
}
}

void Gun_UpdateLaraMeshes(const GAME_OBJECT_ID object_id)
{
const bool lara_has_pistols = Inv_RequestItem(O_PISTOL_ITEM)
|| Inv_RequestItem(O_MAGNUM_ITEM) || Inv_RequestItem(O_UZI_ITEM);

LARA_GUN_TYPE back_gun_type = LGT_UNARMED;
LARA_GUN_TYPE holsters_gun_type = LGT_UNARMED;

if (!Inv_RequestItem(O_SHOTGUN_ITEM) && object_id == O_SHOTGUN_ITEM) {
back_gun_type = LGT_SHOTGUN;
} else if (!lara_has_pistols && object_id == O_PISTOL_ITEM) {
holsters_gun_type = LGT_PISTOLS;
} else if (!lara_has_pistols && object_id == O_MAGNUM_ITEM) {
holsters_gun_type = LGT_MAGNUMS;
} else if (!lara_has_pistols && object_id == O_UZI_ITEM) {
holsters_gun_type = LGT_UZIS;
}

if (back_gun_type != LGT_UNARMED) {
Gun_SetLaraBackMesh(back_gun_type);
}

if (holsters_gun_type != LGT_UNARMED) {
Gun_SetLaraHolsterLMesh(holsters_gun_type);
Gun_SetLaraHolsterRMesh(holsters_gun_type);
}
}

void Gun_SetLaraHandLMesh(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id =
weapon_type == LGT_UNARMED ? O_LARA : Gun_GetWeaponAnim(weapon_type);
assert(object_id != NO_OBJECT);
Lara_SwapSingleMesh(LM_HAND_L, object_id);
}

void Gun_SetLaraHandRMesh(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id =
weapon_type == LGT_UNARMED ? O_LARA : Gun_GetWeaponAnim(weapon_type);
assert(object_id != NO_OBJECT);
Lara_SwapSingleMesh(LM_HAND_R, object_id);
}

void Gun_SetLaraBackMesh(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id =
weapon_type == LGT_UNARMED ? O_LARA : Gun_GetWeaponAnim(weapon_type);
assert(object_id != NO_OBJECT);
Lara_SwapSingleMesh(LM_TORSO, object_id);
g_Lara.back_gun_type = weapon_type;
}

void Gun_SetLaraHolsterLMesh(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id =
weapon_type == LGT_UNARMED ? O_LARA : Gun_GetWeaponAnim(weapon_type);
assert(object_id != NO_OBJECT);
Lara_SwapSingleMesh(LM_THIGH_L, object_id);
g_Lara.holsters_gun_type = weapon_type;
}

void Gun_SetLaraHolsterRMesh(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id =
weapon_type == LGT_UNARMED ? O_LARA : Gun_GetWeaponAnim(weapon_type);
assert(object_id != NO_OBJECT);
Lara_SwapSingleMesh(LM_THIGH_R, object_id);
g_Lara.holsters_gun_type = weapon_type;
}
36 changes: 8 additions & 28 deletions src/game/gun/gun_pistols.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,43 +110,23 @@ void Gun_Pistols_Ready(const LARA_GUN_TYPE weapon_type)

void Gun_Pistols_DrawMeshes(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id = Gun_GetPistolsAnim(weapon_type);
if (object_id == NO_OBJECT) {
return;
}
g_Lara.mesh_ptrs[LM_HAND_L] =
g_Meshes[g_Objects[object_id].mesh_index + LM_HAND_L];
g_Lara.mesh_ptrs[LM_HAND_R] =
g_Meshes[g_Objects[object_id].mesh_index + LM_HAND_R];
g_Lara.mesh_ptrs[LM_THIGH_L] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_THIGH_L];
g_Lara.mesh_ptrs[LM_THIGH_R] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_THIGH_R];
Gun_SetLaraHandLMesh(weapon_type);
Gun_SetLaraHandRMesh(weapon_type);
Gun_SetLaraHolsterLMesh(LGT_UNARMED);
Gun_SetLaraHolsterRMesh(LGT_UNARMED);
}

void Gun_Pistols_UndrawMeshLeft(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id = Gun_GetPistolsAnim(weapon_type);
if (object_id == NO_OBJECT) {
return;
}
g_Lara.mesh_ptrs[LM_THIGH_L] =
g_Meshes[g_Objects[object_id].mesh_index + LM_THIGH_L];
g_Lara.mesh_ptrs[LM_HAND_L] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HAND_L];
Gun_SetLaraHandLMesh(LGT_UNARMED);
Gun_SetLaraHolsterLMesh(weapon_type);
Sound_Effect(SFX_LARA_HOLSTER, &g_LaraItem->pos, SPM_NORMAL);
}

void Gun_Pistols_UndrawMeshRight(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id = Gun_GetPistolsAnim(weapon_type);
if (object_id == NO_OBJECT) {
return;
}
g_Lara.mesh_ptrs[LM_THIGH_R] =
g_Meshes[g_Objects[object_id].mesh_index + LM_THIGH_R];
g_Lara.mesh_ptrs[LM_HAND_R] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HAND_R];
Gun_SetLaraHandRMesh(LGT_UNARMED);
Gun_SetLaraHolsterRMesh(weapon_type);
Sound_Effect(SFX_LARA_HOLSTER, &g_LaraItem->pos, SPM_NORMAL);
}

Expand Down
26 changes: 6 additions & 20 deletions src/game/gun/gun_rifle.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,16 @@ void Gun_Rifle_Undraw(const LARA_GUN_TYPE weapon_type)

void Gun_Rifle_DrawMeshes(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id = Gun_GetRifleAnim(weapon_type);
if (object_id == NO_OBJECT) {
return;
}
g_Lara.mesh_ptrs[LM_HAND_L] =
g_Meshes[g_Objects[object_id].mesh_index + LM_HAND_L];
g_Lara.mesh_ptrs[LM_HAND_R] =
g_Meshes[g_Objects[object_id].mesh_index + LM_HAND_R];
g_Lara.mesh_ptrs[LM_TORSO] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_TORSO];
Gun_SetLaraHandLMesh(weapon_type);
Gun_SetLaraHandRMesh(weapon_type);
Gun_SetLaraBackMesh(LGT_UNARMED);
}

void Gun_Rifle_UndrawMeshes(const LARA_GUN_TYPE weapon_type)
{
const GAME_OBJECT_ID object_id = Gun_GetRifleAnim(weapon_type);
if (object_id == NO_OBJECT) {
return;
}
g_Lara.mesh_ptrs[LM_HAND_L] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HAND_L];
g_Lara.mesh_ptrs[LM_HAND_R] =
g_Meshes[g_Objects[O_LARA].mesh_index + LM_HAND_R];
g_Lara.mesh_ptrs[LM_TORSO] =
g_Meshes[g_Objects[object_id].mesh_index + LM_TORSO];
Gun_SetLaraHandLMesh(LGT_UNARMED);
Gun_SetLaraHandRMesh(LGT_UNARMED);
Gun_SetLaraBackMesh(weapon_type);
}

void Gun_Rifle_Ready(const LARA_GUN_TYPE weapon_type)
Expand Down
5 changes: 5 additions & 0 deletions src/game/inventory/inventory_func.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "game/gun.h"
#include "game/inventory.h"
#include "game/inventory/inventory_vars.h"
#include "game/items.h"
Expand All @@ -11,6 +12,10 @@

bool Inv_AddItem(const GAME_OBJECT_ID object_id)
{
if (Object_IsObjectType(object_id, g_GunObjects)) {
Gun_UpdateLaraMeshes(object_id);
}

const GAME_OBJECT_ID inv_object_id = Inv_GetItemOption(object_id);
if (!g_Objects[inv_object_id].loaded) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions src/game/lara.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void Lara_InitialiseInventory(int32_t level_num);
void Lara_InitialiseMeshes(int32_t level_num);

void Lara_SwapMeshExtra(void);
void Lara_SwapSingleMesh(LARA_MESH mesh, GAME_OBJECT_ID);
bool Lara_IsNearItem(const XYZ_32 *pos, int32_t distance);
void Lara_UseItem(GAME_OBJECT_ID object_num);
int16_t Lara_GetNearestEnemy(void);
Expand All @@ -30,3 +31,5 @@ bool Lara_MovePosition(ITEM_INFO *item, XYZ_32 *vec);
void Lara_Push(ITEM_INFO *item, COLL_INFO *coll, bool spaz_on, bool big_push);

void Lara_TakeDamage(int16_t damage, bool hit_status);

void Lara_RevertToPistolsIfNeeded(void);
Loading

0 comments on commit a1e72ac

Please sign in to comment.