TombEngine/TR5Main/Objects/TR3/Vehicles/biggun.cpp

301 lines
8.1 KiB
C++
Raw Normal View History

2020-08-25 18:14:18 -05:00
#include "framework.h"
2021-12-24 03:32:19 +03:00
#include "Objects/TR3/Vehicles/biggun.h"
2021-12-24 11:08:16 +03:00
#include "Game/animation.h"
#include "Game/camera.h"
2021-12-22 16:23:57 +03:00
#include "Game/collision/collide_room.h"
#include "Game/collision/collide_item.h"
2021-12-24 11:08:16 +03:00
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
#include "Game/items.h"
2021-12-22 16:23:57 +03:00
#include "Game/Lara/lara.h"
#include "Game/Lara/lara_flare.h"
#include "Game/Lara/lara_helpers.h"
2021-12-22 16:23:57 +03:00
#include "Game/Lara/lara_struct.h"
2021-12-24 03:32:19 +03:00
#include "Objects/TR3/Vehicles/biggun_info.h"
2021-12-24 11:08:16 +03:00
#include "Sound/sound.h"
#include "Specific/level.h"
#include "Specific/input.h"
#include "Specific/setup.h"
2021-09-25 11:27:47 +02:00
2022-01-09 13:44:37 +11:00
#define BGUN_TURN_RATE ANGLE(2.0f)
#define BGUN_TURN_MAX ANGLE(16.0f)
2020-10-25 00:35:31 -05:00
#define RECOIL_TIME 26
#define RECOIL_Z 25
2021-11-16 22:30:37 +11:00
#define BGUN_STATE_UP_DOWN_FRAMES 59
#define BGUN_DISMOUNT_FRAME 30
#define BGUN_IN_FIRE IN_ACTION
#define BGUN_IN_DISMOUNT (IN_ROLL | IN_JUMP)
#define BGUN_IN_UP IN_FORWARD
#define BGUN_IN_DOWN IN_BACK
#define BGUN_IN_LEFT IN_LEFT
#define BGUN_IN_RIGHT IN_RIGHT
2022-01-09 13:44:37 +11:00
enum BigGunState
{
2021-11-16 22:30:37 +11:00
BGUN_STATE_MOUNT = 0,
BGUN_STATE_DISMOUNT = 1,
BGUN_STATE_UP_DOWN = 2,
BGUN_STATE_RECOIL = 3
2020-10-25 00:35:31 -05:00
};
2020-08-25 18:14:18 -05:00
2022-01-09 13:44:37 +11:00
enum BigGunAnim
{
2021-11-16 22:30:37 +11:00
BGUN_ANIM_MOUNT = 0,
BGUN_ANIM_DISMOUNT = 1,
BGUN_ANIM_UP_DOWN = 2,
BGUN_ANIM_RECOIL = 3
};
2020-09-11 12:54:30 -05:00
2022-01-09 13:44:37 +11:00
enum BigGunFlags
{
2021-11-16 22:30:37 +11:00
BGUN_FLAG_UP_DOWN = 1,
BGUN_FLAG_AUTO_ROT = 2,
BGUN_FLAG_DISMOUNT = 4,
BGUN_FLAG_FIRE = 8
};
2020-08-25 18:14:18 -05:00
2021-11-16 22:30:37 +11:00
static long GunRotYAdd = 0;
bool barrelRotating;
2020-08-25 18:14:18 -05:00
2022-01-09 13:44:37 +11:00
void BigGunInitialise(short itemNum)
2021-11-16 22:30:37 +11:00
{
2022-01-09 13:44:37 +11:00
ITEM_INFO* bGunItem = &g_Level.Items[itemNum];
bGunItem->Data = BIGGUNINFO();
BIGGUNINFO* bigGunInfo = bGunItem->Data;
2020-09-11 12:54:30 -05:00
2022-01-09 13:44:37 +11:00
bigGunInfo->flags = 0;
bigGunInfo->fireCount = 0;
bigGunInfo->xRot = BGUN_DISMOUNT_FRAME;
bigGunInfo->yRot = 0;
bigGunInfo->startYRot = bGunItem->Position.yRot;
2020-08-25 18:14:18 -05:00
}
2022-01-09 13:44:37 +11:00
static bool BigGunTestMount(ITEM_INFO* bGunItem, ITEM_INFO* laraItem)
2020-08-25 18:14:18 -05:00
{
2022-01-09 13:44:37 +11:00
//LaraInfo*& laraInfo = lara->data; // If Lara global is not used, the game crashes upon level load. Not sure why. @Sezz 2022.01.09
2020-08-25 18:14:18 -05:00
2021-11-16 22:30:37 +11:00
if (!(TrInput & IN_ACTION) ||
Lara.Control.HandStatus != HandStatus::Free ||
laraItem->Airborne)
2021-11-16 22:30:37 +11:00
{
return false;
}
2020-08-25 18:14:18 -05:00
int x = laraItem->Position.xPos - bGunItem->Position.xPos;
int y = laraItem->Position.yPos - bGunItem->Position.yPos;
int z = laraItem->Position.zPos - bGunItem->Position.zPos;
2022-02-08 01:26:59 +11:00
int distance = pow(x, 2) + pow(y, 2) + pow(z, 2);
if (distance > 30000)
2021-11-16 22:30:37 +11:00
return false;
2020-10-25 00:35:31 -05:00
short deltaAngle = abs(laraItem->Position.yRot - bGunItem->Position.yRot);
2022-01-09 13:44:37 +11:00
if (deltaAngle > ANGLE(35.0f) || deltaAngle < -ANGLE(35.0f))
2021-11-16 22:30:37 +11:00
return false;
2020-10-25 00:35:31 -05:00
2021-11-16 22:30:37 +11:00
return true;
2020-08-25 18:14:18 -05:00
}
2022-01-09 13:44:37 +11:00
void BigGunFire(ITEM_INFO* bGunItem, ITEM_INFO* laraItem)
2020-08-25 18:14:18 -05:00
{
BIGGUNINFO* bGunInfo = bGunItem->Data;
2021-11-16 22:30:37 +11:00
2022-01-09 13:44:37 +11:00
short itemNum = CreateItem();
ITEM_INFO* projectileItem = &g_Level.Items[itemNum];
if (itemNum != NO_ITEM)
{
projectileItem->ObjectNumber = ID_ROCKET;
projectileItem->RoomNumber = laraItem->RoomNumber;
2022-01-09 13:44:37 +11:00
PHD_VECTOR pos = { 0, 0, CLICK(1) }; // CLICK(1) or 520?
GetJointAbsPosition(bGunItem, &pos, 2);
projectileItem->Position.xPos = pos.x;
projectileItem->Position.yPos = pos.y;
projectileItem->Position.zPos = pos.z;
2022-01-09 13:44:37 +11:00
InitialiseItem(itemNum);
projectileItem->Position.xRot = -((bGunInfo->xRot - 32) * ANGLE(1.0f));
projectileItem->Position.yRot = bGunItem->Position.yRot;
projectileItem->Position.zRot = 0;
projectileItem->Velocity = 16;
projectileItem->ItemFlags[0] = 1;
2022-01-09 13:44:37 +11:00
AddActiveItem(itemNum);
SmokeCountL = 32;
SmokeWeapon = WEAPON_ROCKET_LAUNCHER;
for (int i = 0; i < 5; i++)
TriggerGunSmoke(pos.x, pos.y, pos.z, 0, 0, 0, 1, WEAPON_ROCKET_LAUNCHER, 32);
SoundEffect(SFX_TR4_EXPLOSION1, 0, 0);
}
2020-08-25 18:14:18 -05:00
}
2022-01-09 13:44:37 +11:00
void BigGunCollision(short itemNum, ITEM_INFO* laraItem, COLL_INFO* coll)
2020-08-25 18:14:18 -05:00
{
2022-01-09 13:44:37 +11:00
ITEM_INFO* bGunItem = &g_Level.Items[itemNum];
BIGGUNINFO* bGunInfo = bGunItem->Data;
2022-02-14 17:05:52 +11:00
auto* laraInfo = GetLaraInfo(laraItem);
2020-08-25 18:14:18 -05:00
if (laraItem->HitPoints <= 0 || laraInfo->Vehicle != NO_ITEM)
2020-08-25 18:14:18 -05:00
return;
2022-01-09 13:44:37 +11:00
if (BigGunTestMount(laraItem, bGunItem))
2020-08-25 18:14:18 -05:00
{
2021-11-16 22:30:37 +11:00
laraInfo->Vehicle = itemNum;
2020-08-25 18:14:18 -05:00
if (laraInfo->Control.WeaponControl.GunType == WEAPON_FLARE)
2020-08-25 18:14:18 -05:00
{
2022-01-09 13:44:37 +11:00
CreateFlare(laraItem, ID_FLARE_ITEM, false);
UndrawFlareMeshes(laraItem);
2020-08-25 18:14:18 -05:00
laraInfo->Flare.ControlLeft = false;
laraInfo->Control.WeaponControl.RequestGunType = WEAPON_NONE;
laraInfo->Control.WeaponControl.GunType = WEAPON_NONE;
2021-11-16 22:30:37 +11:00
}
2020-08-25 18:14:18 -05:00
laraItem->AnimNumber = Objects[ID_BIGGUN_ANIMS].animIndex + BGUN_ANIM_MOUNT;
laraItem->FrameNumber = g_Level.Anims[Objects[ID_BIGGUN_ANIMS].animIndex + BGUN_ANIM_MOUNT].frameBase;
laraItem->TargetState = BGUN_STATE_MOUNT;
laraItem->ActiveState = BGUN_STATE_MOUNT;
laraItem->Position = bGunItem->Position;
laraItem->Airborne = false;
laraInfo->Control.HandStatus = HandStatus::Busy;
bGunItem->HitPoints = 1;
2022-01-09 13:44:37 +11:00
bGunInfo->flags = 0;
bGunInfo->xRot = BGUN_DISMOUNT_FRAME;
2020-08-25 18:14:18 -05:00
}
else
2022-01-09 13:44:37 +11:00
ObjectCollision(itemNum, laraItem, coll);
2020-08-25 18:14:18 -05:00
}
2022-01-09 13:44:37 +11:00
bool BigGunControl(ITEM_INFO* laraItem, COLL_INFO* coll)
2020-08-25 18:14:18 -05:00
{
2022-02-14 17:05:52 +11:00
auto* laraInfo = GetLaraInfo(laraItem);
2022-01-09 13:44:37 +11:00
ITEM_INFO* bGunItem = &g_Level.Items[laraInfo->Vehicle];
BIGGUNINFO* bGunInfo = bGunItem->Data;
2020-08-25 18:14:18 -05:00
2022-01-09 13:44:37 +11:00
if (bGunInfo->flags & BGUN_FLAG_UP_DOWN)
2020-08-25 18:14:18 -05:00
{
2020-10-25 00:35:31 -05:00
if (barrelRotating)
2022-01-09 13:44:37 +11:00
bGunInfo->barrelZ--;
2020-10-25 00:35:31 -05:00
2022-01-09 13:44:37 +11:00
if (!bGunInfo->barrelZ)
2020-10-25 00:35:31 -05:00
barrelRotating = false;
if (TrInput & BGUN_IN_DISMOUNT || laraItem->HitPoints <= 0)
2022-01-09 13:44:37 +11:00
bGunInfo->flags = BGUN_FLAG_AUTO_ROT;
2020-08-25 18:14:18 -05:00
else
{
2022-01-09 13:44:37 +11:00
if (TrInput & BGUN_IN_FIRE && bGunInfo->fireCount == 0)
2020-10-25 00:35:31 -05:00
{
2022-01-09 13:44:37 +11:00
BigGunFire(bGunItem, laraItem);
bGunInfo->fireCount = RECOIL_TIME;
bGunInfo->barrelZ = RECOIL_Z;
2020-10-25 00:35:31 -05:00
barrelRotating = true;
}
2021-11-16 22:30:37 +11:00
if (TrInput & BGUN_IN_LEFT)
2020-10-25 00:35:31 -05:00
{
if (GunRotYAdd > 0)
GunRotYAdd /= 2;
2022-01-09 13:44:37 +11:00
GunRotYAdd -= BGUN_TURN_RATE;
if (GunRotYAdd < -BGUN_TURN_MAX)
GunRotYAdd = -BGUN_TURN_MAX;
2020-10-25 00:35:31 -05:00
}
2022-01-09 13:44:37 +11:00
else if (TrInput & BGUN_IN_RIGHT)
2020-10-25 00:35:31 -05:00
{
if (GunRotYAdd < 0)
GunRotYAdd /= 2;
2020-08-25 22:55:23 -05:00
2022-01-09 13:44:37 +11:00
GunRotYAdd += BGUN_TURN_RATE;
if (GunRotYAdd > BGUN_TURN_MAX)
GunRotYAdd = BGUN_TURN_MAX;
2020-10-25 00:35:31 -05:00
}
else
{
GunRotYAdd -= GunRotYAdd / 4;
2022-01-09 13:44:37 +11:00
if (abs(GunRotYAdd) < BGUN_TURN_RATE)
2020-10-25 00:35:31 -05:00
GunRotYAdd = 0;
}
2022-01-09 13:44:37 +11:00
bGunInfo->yRot += GunRotYAdd / 4;
2020-10-25 00:35:31 -05:00
2022-01-09 13:44:37 +11:00
if (TrInput & BGUN_IN_UP && bGunInfo->xRot < BGUN_STATE_UP_DOWN_FRAMES)
bGunInfo->xRot++;
else if (TrInput & BGUN_IN_DOWN && bGunInfo->xRot)
bGunInfo->xRot--;
2020-08-25 18:14:18 -05:00
}
}
2020-09-11 00:44:48 -05:00
2022-01-09 13:44:37 +11:00
if (bGunInfo->flags & BGUN_FLAG_AUTO_ROT)
2020-08-25 18:14:18 -05:00
{
2022-01-09 13:44:37 +11:00
if (bGunInfo->xRot == BGUN_DISMOUNT_FRAME)
2020-08-25 18:14:18 -05:00
{
laraItem->AnimNumber = Objects[ID_BIGGUN_ANIMS].animIndex + BGUN_ANIM_DISMOUNT;
laraItem->FrameNumber = g_Level.Anims[Objects[ID_BIGGUN].animIndex + BGUN_ANIM_DISMOUNT].frameBase;
laraItem->ActiveState = BGUN_STATE_DISMOUNT;
laraItem->TargetState = BGUN_STATE_DISMOUNT;
2022-01-09 13:44:37 +11:00
bGunInfo->flags = BGUN_FLAG_DISMOUNT;
2020-08-25 18:14:18 -05:00
}
2022-01-09 13:44:37 +11:00
else if (bGunInfo->xRot > BGUN_DISMOUNT_FRAME)
bGunInfo->xRot--;
else if (bGunInfo->xRot < BGUN_DISMOUNT_FRAME)
bGunInfo->xRot++;
2020-08-25 18:14:18 -05:00
}
switch (laraItem->ActiveState)
2020-08-25 18:14:18 -05:00
{
2021-11-16 22:30:37 +11:00
case BGUN_STATE_MOUNT:
case BGUN_STATE_DISMOUNT:
2022-01-09 13:44:37 +11:00
AnimateItem(laraItem);
bGunItem->AnimNumber = Objects[ID_BIGGUN].animIndex + (laraItem->AnimNumber - Objects[ID_BIGGUN_ANIMS].animIndex);
bGunItem->FrameNumber = g_Level.Anims[bGunItem->AnimNumber].frameBase + (laraItem->FrameNumber - g_Level.Anims[laraItem->AnimNumber].frameBase);
2020-08-25 18:14:18 -05:00
2022-01-09 13:44:37 +11:00
if (bGunInfo->flags & BGUN_FLAG_DISMOUNT && TestLastFrame(laraItem))
2020-08-25 18:14:18 -05:00
{
2022-01-09 13:44:37 +11:00
SetAnimation(laraItem, LA_STAND_IDLE);
2021-11-16 22:30:37 +11:00
laraInfo->Vehicle = NO_ITEM;
laraInfo->Control.HandStatus = HandStatus::Free;
bGunItem->HitPoints = 0;
2020-08-25 18:14:18 -05:00
}
2021-11-16 22:30:37 +11:00
2020-08-25 18:14:18 -05:00
break;
2021-11-16 22:30:37 +11:00
case BGUN_STATE_UP_DOWN:
laraItem->AnimNumber = Objects[ID_BIGGUN_ANIMS].animIndex + BGUN_ANIM_UP_DOWN;
laraItem->FrameNumber = g_Level.Anims[Objects[ID_BIGGUN].animIndex + BGUN_ANIM_UP_DOWN].frameBase + bGunInfo->xRot;
bGunItem->AnimNumber = Objects[ID_BIGGUN].animIndex + (laraItem->AnimNumber - Objects[ID_BIGGUN_ANIMS].animIndex);
bGunItem->FrameNumber = g_Level.Anims[bGunItem->AnimNumber].frameBase + (laraItem->FrameNumber - g_Level.Anims[laraItem->AnimNumber].frameBase);
2021-11-16 22:30:37 +11:00
2022-01-09 13:44:37 +11:00
if (bGunInfo->fireCount > 0)
bGunInfo->fireCount--;
else
bGunInfo->fireCount = 0;
2020-08-25 18:14:18 -05:00
2022-01-09 13:44:37 +11:00
bGunInfo->flags = BGUN_FLAG_UP_DOWN;
2020-08-25 18:14:18 -05:00
break;
}
2021-11-16 22:30:37 +11:00
Camera.targetElevation = -ANGLE(15.0f);
2022-01-09 13:44:37 +11:00
bGunItem->Position.yRot = bGunInfo->startYRot + bGunInfo->yRot;
laraItem->Position.yRot = bGunItem->Position.yRot;
coll->Setup.EnableSpasm = false;
2021-09-10 00:20:59 +03:00
coll->Setup.EnableObjectPush = false;
2022-01-09 13:44:37 +11:00
DoObjectCollision(laraItem, coll);
2020-08-25 18:14:18 -05:00
2021-11-16 22:30:37 +11:00
return true;
2020-08-25 18:14:18 -05:00
}