TombEngine/TR5Main/Game/lara2gun.cpp

494 lines
11 KiB
C++
Raw Normal View History

2019-12-01 08:13:19 +01:00
#include "lara2gun.h"
#include "..\Global\global.h"
#include "larafire.h"
#include "lara.h"
#include "effect2.h"
#include "tomb4fx.h"
2019-12-01 08:13:19 +01:00
PISTOL_DEF PistolsTable[4] =
{
{ ID_LARA, 0, 0, 0, 0 },
{ ID_PISTOLS_ANIM, 4, 5, 13, 24 },
{ ID_REVOLVER_ANIM , 7, 8, 15, 29 },
{ ID_UZI_ANIM, 4, 5, 13, 24 }
2019-12-01 08:13:19 +01:00
};
bool UziLeft;
bool UziRight;
2019-12-01 08:13:19 +01:00
void AnimatePistols(int weaponType)
2019-12-01 08:13:19 +01:00
{
PISTOL_DEF* p = &PistolsTable[Lara.gunType];
WEAPON_INFO* weapon = &Weapons[weaponType];
2019-12-02 09:11:21 +01:00
int soundPlayed = false;
short angleLeft[2], angleRight[2];
2019-12-01 08:13:19 +01:00
if (LaraItem->meshBits)
{
if (SmokeCountL)
{
PHD_VECTOR pos;
2019-12-01 08:13:19 +01:00
switch (SmokeWeapon)
{
case WEAPON_PISTOLS:
pos.x = 4;
pos.y = 128;
pos.z = 40;
break;
case WEAPON_REVOLVER:
pos.x = 16;
pos.y = 160;
pos.z = 56;
break;
case WEAPON_UZI:
pos.x = 8;
pos.y = 140;
pos.z = 48;
break;
}
2019-12-01 08:13:19 +01:00
GetLaraJointPosition(&pos, LJ_LHAND);
TriggerGunSmoke(pos.x, pos.y, pos.z, 0, 0, 0, (byte)0, SmokeWeapon, SmokeCountL);
2019-12-01 08:13:19 +01:00
}
if (SmokeCountR)
{
PHD_VECTOR pos;
2019-12-01 08:13:19 +01:00
switch (SmokeWeapon)
{
case WEAPON_PISTOLS:
pos.x = -16;
pos.y = 128;
pos.z = 40;
break;
case WEAPON_REVOLVER:
pos.x = -32;
pos.y = 160;
pos.z = 56;
break;
case WEAPON_UZI:
pos.x = -16;
pos.y = 140;
pos.z = 48;
break;
}
2019-12-01 08:13:19 +01:00
GetLaraJointPosition(&pos, LJ_RHAND);
TriggerGunSmoke(pos.x, pos.y, pos.z, 0, 0, 0, (byte)0, SmokeWeapon, SmokeCountR);
2019-12-01 08:13:19 +01:00
}
}
2019-12-02 09:11:21 +01:00
short frameRight = Lara.rightArm.frameNumber;
if (Lara.rightArm.lock || (TrInput & IN_ACTION && !Lara.target))
2019-12-01 08:13:19 +01:00
{
if ((frameRight >= 0) && (frameRight < p->draw1Anim2))
{
frameRight++;
}
else if (frameRight == p->draw1Anim2)
2019-12-01 08:13:19 +01:00
{
if (TrInput & IN_ACTION)
2019-12-01 08:13:19 +01:00
{
if (weaponType != WEAPON_REVOLVER)
2019-12-01 08:13:19 +01:00
{
angleRight[0] = Lara.rightArm.yRot + LaraItem->pos.yRot;
angleRight[1] = Lara.rightArm.xRot;
2019-12-01 08:13:19 +01:00
if (FireWeapon(weaponType, Lara.target, LaraItem, angleRight))
{
SmokeCountR = 28;
SmokeWeapon = weaponType;
TriggerGunShell(1, ID_GUNSHELL, weaponType); // Right Hand
2019-12-01 08:13:19 +01:00
Lara.rightArm.flash_gun = weapon->flashTime;
2019-12-01 08:13:19 +01:00
SoundEffect(SFX_EXPLOSION1, &LaraItem->pos, PITCH_SHIFT | 0x2000000);
SoundEffect(weapon->sampleNum, &LaraItem->pos, 0);
soundPlayed = true;
2019-12-01 08:13:19 +01:00
if (weaponType == WEAPON_UZI)
UziRight = true;
2019-12-01 08:13:19 +01:00
Savegame.Game.AmmoUsed++;
2019-12-01 08:13:19 +01:00
}
}
frameRight = p->recoilAnim;
2019-12-01 08:13:19 +01:00
}
else if (UziRight)
2019-12-01 08:13:19 +01:00
{
SoundEffect(weapon->sampleNum + 1, &LaraItem->pos, 0);
UziRight = false;
2019-12-01 08:13:19 +01:00
}
}
else if (frameRight >= p->recoilAnim)
2019-12-01 08:13:19 +01:00
{
if (weaponType == WEAPON_UZI)
{
SoundEffect(weapon->sampleNum, &LaraItem->pos, 0);
UziRight = true;
}
2019-12-01 08:13:19 +01:00
frameRight++;
if (frameRight == (p->recoilAnim + weapon->recoilFrame))
frameRight = p->draw1Anim2;
2019-12-01 08:13:19 +01:00
}
}
else
{
if (frameRight >= p->recoilAnim)
frameRight = p->draw1Anim2;
else if ((frameRight > 0) && (frameRight <= p->draw1Anim2))
2019-12-01 08:13:19 +01:00
frameRight--;
if (UziRight)
{
SoundEffect(weapon->sampleNum + 1, &LaraItem->pos, 0);
UziRight = false;
}
}
set_arm_info(&Lara.rightArm, frameRight);
short frameLeft = Lara.leftArm.frameNumber;
if (Lara.leftArm.lock || (TrInput & IN_ACTION && !Lara.target))
2019-12-01 08:13:19 +01:00
{
if ((frameLeft >= 0) && (frameLeft < p->draw1Anim2))
2019-12-01 08:13:19 +01:00
{
frameLeft++;
}
else if (frameLeft == p->draw1Anim2)
{
if (TrInput & IN_ACTION)
{
angleLeft[0] = Lara.leftArm.yRot + LaraItem->pos.yRot;
angleLeft[1] = Lara.leftArm.xRot;
2019-12-01 08:13:19 +01:00
if (FireWeapon(weaponType, Lara.target, LaraItem, angleLeft))
2019-12-01 08:13:19 +01:00
{
if (weaponType == WEAPON_REVOLVER)
{
SmokeCountR = 28;
SmokeWeapon = WEAPON_REVOLVER;
Lara.rightArm.flash_gun = weapon->flashTime;
}
else
{
SmokeCountL = 28;
SmokeWeapon = weaponType;
TriggerGunShell(0, ID_GUNSHELL, weaponType); // left hand
2019-12-01 08:13:19 +01:00
Lara.leftArm.flash_gun = weapon->flashTime;
}
if (!soundPlayed)
{
SoundEffect(SFX_EXPLOSION1, &LaraItem->pos, PITCH_SHIFT | 0x2000000);
SoundEffect(weapon->sampleNum, &LaraItem->pos, 0);
}
if (weaponType == WEAPON_UZI)
UziLeft = true;
Savegame.Game.AmmoUsed++;
}
2019-12-02 19:36:35 +01:00
frameLeft = p->recoilAnim;
2019-12-01 08:13:19 +01:00
}
else if (UziLeft)
{
SoundEffect(weapon->sampleNum + 1, &LaraItem->pos, 0);
UziLeft = false;
}
}
2019-12-02 19:36:35 +01:00
else if (frameLeft >= p->recoilAnim)
{
if (weaponType == WEAPON_UZI)
{
SoundEffect(weapon->sampleNum, &LaraItem->pos, 0);
UziLeft = true;
}
frameLeft++;
if (frameLeft == (p->recoilAnim + weapon->recoilFrame))
frameLeft = p->draw1Anim2;
}
2019-12-01 08:13:19 +01:00
}
else // Havent GOT a LOCK ON..
2019-12-01 08:13:19 +01:00
{
2019-12-02 19:36:35 +01:00
if (frameLeft >= p->recoilAnim) // If Gun is Recoiling Stop it now...
frameLeft = p->draw1Anim2;
2019-12-01 08:13:19 +01:00
else if (frameLeft > 0 && frameLeft <= p->draw1Anim2)
2019-12-02 19:36:35 +01:00
frameLeft--; // UnLock ARM
2019-12-01 08:13:19 +01:00
if (UziLeft)
{
SoundEffect(weapon->sampleNum + 1, &LaraItem->pos, 0);
UziLeft = false;
}
}
set_arm_info(&Lara.leftArm, frameLeft);
}
void PistolHandler(int weaponType)
2019-12-01 08:13:19 +01:00
{
WEAPON_INFO* weapon = &Weapons[weaponType];
LaraGetNewTarget(weapon);
if (TrInput & IN_ACTION)
LaraTargetInfo(weapon);
AimWeapon(weapon, &Lara.leftArm);
AimWeapon(weapon, &Lara.rightArm);
if (Lara.leftArm.lock && !Lara.rightArm.lock)
2019-12-01 08:13:19 +01:00
{
Lara.torsoYrot = Lara.leftArm.yRot / 2;
Lara.torsoXrot = Lara.leftArm.xRot / 2;
if (Camera.oldType != LOOK_CAMERA)
2019-12-01 08:13:19 +01:00
{
Lara.headYrot = Lara.torsoYrot;
Lara.headXrot = Lara.torsoXrot;
2019-12-01 08:13:19 +01:00
}
}
else if (!Lara.leftArm.lock && Lara.rightArm.lock)
2019-12-01 08:13:19 +01:00
{
Lara.torsoYrot = Lara.rightArm.yRot / 2;
Lara.torsoXrot = Lara.rightArm.xRot / 2;
if (Camera.oldType != LOOK_CAMERA)
{
Lara.headYrot = Lara.torsoYrot;
Lara.headXrot = Lara.torsoXrot;
}
}
else if (Lara.leftArm.lock && Lara.rightArm.lock)
{
Lara.torsoYrot = (Lara.leftArm.yRot + Lara.rightArm.yRot) / 4;
Lara.torsoXrot = (Lara.leftArm.xRot + Lara.rightArm.xRot) / 4;
2019-12-01 08:13:19 +01:00
if (Camera.oldType != LOOK_CAMERA)
{
Lara.headYrot = Lara.torsoYrot;
Lara.headXrot = Lara.torsoXrot;
}
}
AnimatePistols(weaponType);
if (Lara.leftArm.flash_gun || Lara.rightArm.flash_gun)
{
PHD_VECTOR pos;
pos.x = GetRandomControl() - 128;
pos.y = (GetRandomControl() & 0x7F) - 63;
pos.z = GetRandomControl() - 128;
GetLaraJointPosition(&pos, Lara.leftArm.flash_gun != 0 ? LJ_LHAND : LJ_RHAND);
/*if (gfLevelFlags & 0x2000 && LaraItem->room_number == gfMirrorRoom)
{
v8 = GetRandomControl() & 0x3F;
v9 = (GetRandomControl() & 0x1F) + 128;
v10 = GetRandomControl();
sub_4015A5(v14, v15, v16, 10, (v10 & 0x3F) + 192, v9, v8); // TODO: TriggerDynamicLightMirror !
2019-12-01 08:13:19 +01:00
}
else
{*/
TriggerDynamicLight(pos.x, pos.y, pos.z, 10, (GetRandomControl() & 0x3F) + 192, (GetRandomControl() & 0x1F) + 128, GetRandomControl() & 0x3F);
//}
}
}
void undraw_pistol_mesh_right(int weaponType)
2019-12-01 08:13:19 +01:00
{
2019-12-15 16:19:01 +01:00
LARA_MESHES(ID_LARA, LM_RHAND);
2019-12-01 08:13:19 +01:00
switch (weaponType)
{
case WEAPON_PISTOLS:
Lara.holster = ID_LARA_HOLSTERS_PISTOLS;
break;
case WEAPON_UZI:
Lara.holster = ID_LARA_HOLSTERS_UZIS;
break;
case WEAPON_REVOLVER:
Lara.holster = ID_LARA_HOLSTERS_REVOLVER;
break;
2019-12-01 08:13:19 +01:00
}
}
void undraw_pistol_mesh_left(int weaponType)
2019-12-01 08:13:19 +01:00
{
if (weaponType != WEAPON_REVOLVER)
{
2019-12-15 16:19:01 +01:00
LARA_MESHES(ID_LARA, LM_LHAND);
switch (weaponType)
2019-12-01 08:13:19 +01:00
{
case WEAPON_PISTOLS:
Lara.holster = ID_LARA_HOLSTERS_PISTOLS;
break;
case WEAPON_UZI:
Lara.holster = ID_LARA_HOLSTERS_UZIS;
break;
2019-12-01 08:13:19 +01:00
}
}
}
void draw_pistol_meshes(int weaponType)
2019-12-01 08:13:19 +01:00
{
2019-12-02 19:36:35 +01:00
Lara.holster = ID_LARA_HOLSTERS;
2019-12-15 16:19:01 +01:00
LARA_MESHES(WeaponObjectMesh(weaponType), LM_RHAND);
2019-12-01 08:13:19 +01:00
if (weaponType != WEAPON_REVOLVER)
2019-12-15 16:19:01 +01:00
LARA_MESHES(WeaponObjectMesh(weaponType), LM_LHAND);
2019-12-01 08:13:19 +01:00
}
void ready_pistols(int weaponType)
2019-12-01 08:13:19 +01:00
{
Lara.gunStatus = LG_READY;
Lara.leftArm.zRot = 0;
Lara.leftArm.yRot = 0;
Lara.leftArm.xRot = 0;
Lara.rightArm.zRot = 0;
Lara.rightArm.yRot = 0;
Lara.rightArm.xRot = 0;
Lara.rightArm.frameNumber = 0;
Lara.leftArm.frameNumber = 0;
Lara.target = NULL;
Lara.rightArm.lock = 0;
Lara.leftArm.lock = 0;
Lara.rightArm.frameBase = Objects[WeaponObject(weaponType)].frameBase;
Lara.leftArm.frameBase = Objects[WeaponObject(weaponType)].frameBase;
}
void undraw_pistols(int weaponType)
2019-12-01 08:13:19 +01:00
{
PISTOL_DEF* p = &PistolsTable[Lara.gunType];
short frameLeft = Lara.leftArm.frameNumber;
2019-12-01 08:13:19 +01:00
if (frameLeft >= p->recoilAnim)
{
2019-12-02 19:36:35 +01:00
frameLeft = p->draw1Anim2;
2019-12-01 08:13:19 +01:00
}
else if (frameLeft > 0 && frameLeft < p->draw1Anim)
{
Lara.leftArm.xRot -= Lara.leftArm.xRot / frameLeft;
Lara.leftArm.yRot -= Lara.leftArm.yRot / frameLeft;
frameLeft--;
}
else if (frameLeft == 0)
{
Lara.leftArm.zRot = 0;
Lara.leftArm.yRot = 0;
Lara.leftArm.xRot = 0;
frameLeft = p->recoilAnim - 1;
}
else if (frameLeft > p->draw1Anim && (frameLeft < p->recoilAnim))
2019-12-01 08:13:19 +01:00
{
frameLeft--;
if (frameLeft == p->draw2Anim - 1)
{
undraw_pistol_mesh_left(weaponType);
SoundEffect(SFX_LARA_HOLSTER_AWAY, &LaraItem->pos, 0);
}
}
set_arm_info(&Lara.leftArm, frameLeft);
short frameRight = Lara.rightArm.frameNumber;
if (frameRight >= p->recoilAnim)
2019-12-01 08:13:19 +01:00
{
frameRight = p->draw1Anim2;
2019-12-01 08:13:19 +01:00
}
else if (frameRight > 0 && frameRight < p->draw1Anim)
2019-12-01 08:13:19 +01:00
{
Lara.rightArm.xRot -= Lara.rightArm.xRot / frameRight;
Lara.rightArm.yRot -= Lara.rightArm.yRot / frameRight;
frameRight--;
}
else if (frameRight == 0)
{
Lara.rightArm.zRot = 0;
Lara.rightArm.yRot = 0;
Lara.rightArm.xRot = 0;
frameRight = p->recoilAnim - 1;
2019-12-01 08:13:19 +01:00
}
else if (frameRight > p->draw1Anim && (frameRight < p->recoilAnim))
{
frameRight--;
2019-12-01 08:13:19 +01:00
if (frameRight == p->draw2Anim - 1)
{
undraw_pistol_mesh_right(weaponType);
SoundEffect(SFX_LARA_HOLSTER_AWAY, &LaraItem->pos, 0);
}
}
2019-12-01 08:13:19 +01:00
set_arm_info(&Lara.rightArm, frameRight);
if (frameLeft == p->draw1Anim && frameRight == p->draw1Anim)
{
Lara.gunStatus = LG_NO_ARMS;
Lara.leftArm.frameNumber = 0;
Lara.rightArm.frameNumber = 0;
Lara.target = NULL;
Lara.rightArm.lock = 0;
Lara.leftArm.lock = 0;
}
if (!(TrInput & IN_LOOK))
{
Lara.headYrot = (Lara.leftArm.yRot + Lara.rightArm.yRot) / 4;
Lara.torsoYrot = (Lara.leftArm.yRot + Lara.rightArm.yRot) / 4;
Lara.headXrot = (Lara.leftArm.xRot + Lara.rightArm.xRot) / 4;
Lara.torsoXrot = (Lara.leftArm.xRot + Lara.rightArm.xRot) / 4;
}
}
void set_arm_info(LARA_ARM* arm, int frame)
2019-12-01 08:13:19 +01:00
{
PISTOL_DEF* p = &PistolsTable[Lara.gunType];
2019-12-02 09:11:21 +01:00
short animBase = Objects[p->objectNum].animIndex;
2019-12-01 08:13:19 +01:00
if (frame < p->draw1Anim)
arm->animNumber = animBase;
else if (frame < p->draw2Anim)
arm->animNumber = animBase + 1;
else if (frame < p->recoilAnim)
arm->animNumber = animBase + 2;
else
arm->animNumber = animBase + 3;
arm->frameNumber = frame;
arm->frameBase = Anims[arm->animNumber].framePtr;
2019-12-01 08:13:19 +01:00
}
void draw_pistols(int weaponType)
2019-12-01 08:13:19 +01:00
{
2019-12-02 09:11:21 +01:00
short frame = Lara.leftArm.frameNumber + 1;
2019-12-01 08:13:19 +01:00
PISTOL_DEF* p = &PistolsTable[Lara.gunType];
if (frame < p->draw1Anim || frame > p->recoilAnim - 1)
2019-12-01 08:13:19 +01:00
{
frame = p->draw1Anim;
}
else if (frame == p->draw2Anim)
{
draw_pistol_meshes(weaponType);
SoundEffect(SFX_LARA_HOLSTER_DRAW, &LaraItem->pos, 0);
}
else if (frame == p->recoilAnim - 1)
{
ready_pistols(weaponType);
frame = 0;
}
set_arm_info(&Lara.rightArm, frame);
set_arm_info(&Lara.leftArm, frame);
}