TombEngine/TombEngine/Objects/TR4/Object/tr4_element_puzzle.cpp
Lwmte aded24fa10 Vehicles cleanup before impacts were broken (#575)
* Enhance big gun rotation; vehicle cleanup

* Determine defaults for vehicle info members; keep camera elevation aligned with line of sight on big gun

* Organise constants

* Fix jeep/bike floor tilts

* Unify vehicle height calcs, fix bridges for vehicles

* Fix water vehicles

* Fix typo

* Introduce unified vehicle mounting mechanism and use it for the skidoo

* Ensure vehicle mounting occurs from correct side; modify skidoo and speedboat control inputs

* Update VehicleHelpers.cpp

* Fix kayak

* Standardise vehicle inputs

* Update vehicle acceleration input

* Make vehicle inputs constants

* Rename Airborne to IsAirborne

* Move generic vehicle functions to VehicleHelpers.cpp

* Also move constants

* Remove inaccurate vehicle mount condition

* Move vehicle constants to header; redo quad bike input replacement (further adjustment required)

* Establish vehicle mount constants for later; convert vehicle macros to constants

* Add condition to level start mount

* Organise and demagic some vehicle constants

* More cleanup and demagicking of vehicle constants

* Demagic and simplify UPV garbage

* Organise UPV angle macros and constants to make sense

* Organise a little more

* Final cleanup of UPV constants

* Add temporary vehicle velocity scale constant for easier removal later; demagic rubber boat velocity and turn rate values

* Cleanup, demagicking

* Cleanup

* Organisation

* Prototype vehicle turn rate modulation with skidoo and UPV

* Tentatively simplify UPV turn rate deceleration

* Fix UPV turning

* Tweak UPV turn rate macros

* Tweak UPV turn rate macros

* Complete vehicle mount function

* Use new vehicle mount function with quad bike

* Use new vehicle mount function with motorbike

* Add oneshot check to GetVehicleMountType()

* Prepare mechanism to allow starting a level already mounted on any vehicle

* Fix typo

* Cleanup and organisation

* Remove use of Lara global

* Use new vehicle mount function with minecart

* Fix spike deaths on vehicles

* Use new vehicle mount function with jeep

* Assess 2D distance for vehicle mounts instead of 3D for better fidelity around steps

* Cleanup

* Use new vehicle mount function with speedboat

* Fix mounts on boats

* Use new vehicle mount function with rubber boat

* Use new vehicle mount function with kayak

* Cleanup

* Use new mount function with UPV

* Fix motorbike nitro and remove useless flag checks

* Fix bike nitro, rotate wheels for vehicles

* Fix ItemPushStatic not to corrupt non-Lara items room number

* Remove unneeded clamps

* Fix typo

* Jeep: comply to tomb4 decompilation order

* Uncomment drift code for jeep, rename unknown2 to Gear

* Fix flag meanings

* Further backport of jeep from tomb4 project

* Use JeepBrakeLightJoints

* Update jeep.cpp

* Fix vehicle static collisions

* Add disabled option to insert nitro into motorbike

* Simplify UPV collision check

* Update comment

* Make vehicle function parameter ordering consistent

* Rotate UPV rudders when turning the vehicle

* Lean UPV when turning

* Simplify condition

* Simplify skidoo turn rate modulation

* Fix UPV turbine rotation

* Fix merge error

* Tentatively invert turning when moving in reverse on skidoo

* Add function to discard flares on vehicles to avoid copy-paste

* Add big reminder comment for savegames

* Fix another "epic" typo by me, convert enum hex values to shifts

* lara_struct.h cleanup

* UPV cleanup

* #include cleanup in vehicle headers

* Also brake quadbike with brake button

Co-authored-by: Sezz <seb.zych@outlook.com>
2022-07-02 21:12:40 +03:00

302 lines
10 KiB
C++

#include "framework.h"
#include "tr4_element_puzzle.h"
#include "Specific/level.h"
#include "Game/control/control.h"
#include "Sound/sound.h"
#include "Game/animation.h"
#include "Game/Lara/lara.h"
#include "Game/Lara/lara_helpers.h"
#include "Game/collision/sphere.h"
#include "Game/effects/effects.h"
#include "Game/effects/tomb4fx.h"
#include "Specific/input.h"
#include "Objects/Generic/Switches/generic_switch.h"
#include "Game/collision/collide_room.h"
#include "Game/collision/collide_item.h"
#include "Game/items.h"
using namespace TEN::Input;
using namespace TEN::Entities::Switches;
namespace TEN::Entities::TR4
{
OBJECT_COLLISION_BOUNDS ElementPuzzleBounds =
{
0, 0,
-64, 0,
0, 0,
-ANGLE(10.0f), ANGLE(10.0f),
-ANGLE(30.0f), ANGLE(30.0f),
-ANGLE(10.0f), ANGLE(10.0f)
};
void ElementPuzzleControl(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
if (!TriggerActive(item))
return;
if (item->TriggerFlags == 1)
{
SoundEffect(SFX_TR4_LOOP_FOR_SMALL_FIRES, &item->Pose);
byte r = (GetRandomControl() & 0x3F) + 192;
byte g = (GetRandomControl() & 0x1F) + 96;
byte b = 0;
short fade = 0;
if (item->ItemFlags[3])
{
item->ItemFlags[3]--;
fade = 255 - GetRandomControl() % (4 * (91 - item->ItemFlags[3]));
if (fade < 1)
{
fade = 1;
r = (r * fade) / 256;
g = (g * fade) / 256;
}
else if (fade <= 255)
{
r = (r * fade) / 256;
g = (g * fade) / 256;
}
}
else
fade = 0;
AddFire(item->Pose.Position.x, item->Pose.Position.y - 620, item->Pose.Position.z, item->RoomNumber, 0.5f, fade);
TriggerDynamicLight(item->Pose.Position.x, item->Pose.Position.y - 768, item->Pose.Position.z, 12, r, g, b);
return;
}
if (item->TriggerFlags != 3)
return;
if (item->ItemFlags[1] > 90)
SoundEffect(SFX_TR4_WIND, &item->Pose);
if (item->ItemFlags[1] < 60)
{
item->ItemFlags[1]++;
return;
}
item->ItemFlags[0]++;
if (item->ItemFlags[0] == 90)
{
short itemNos[256];
int sw = GetSwitchTrigger(item, itemNos, 0);
if (sw > 0)
{
for (int i = 0; i < sw; i++)
{
AddActiveItem(itemNos[i]);
g_Level.Items[itemNos[i]].Status = ITEM_ACTIVE;
g_Level.Items[itemNos[i]].Flags |= 0x3E00;
}
}
KillItem(itemNumber);
return;
}
short currentItemNumber = g_Level.Rooms[item->RoomNumber].itemNumber;
if (currentItemNumber == NO_ITEM)
return;
while (currentItemNumber != NO_ITEM)
{
auto* currentItem = &g_Level.Items[currentItemNumber];
if (currentItem->ObjectNumber != ID_FLAME_EMITTER2)
{
if (currentItem->ObjectNumber == ID_ELEMENT_PUZZLE &&
currentItem->TriggerFlags == 1 &&
!currentItem->ItemFlags[3])
{
currentItem->ItemFlags[3] = 90;
}
currentItemNumber = currentItem->NextItem;
continue;
}
if (item->ItemFlags[0] != 89)
{
currentItem->ItemFlags[3] = 255 - GetRandomControl() % (4 * item->ItemFlags[0]);
if (currentItem->ItemFlags[3] >= 2)
{
currentItemNumber = currentItem->NextItem;
continue;
}
currentItem->ItemFlags[3] = 2;
}
RemoveActiveItem(currentItemNumber);
currentItem->Status = ITEM_NOT_ACTIVE;
}
}
void ElementPuzzleDoCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* coll)
{
auto* item = &g_Level.Items[itemNumber];
if (TestBoundsCollide(item, laraItem, coll->Setup.Radius))
{
if (TestCollision(item, laraItem))
{
if (coll->Setup.EnableObjectPush)
ItemPushItem(item, laraItem, coll, 0, 0);
}
}
}
void ElementPuzzleCollision(short itemNumber, ItemInfo* laraItem, CollisionInfo* coll)
{
auto* laraInfo = GetLaraInfo(laraItem);
auto* puzzleItem = &g_Level.Items[itemNumber];
int flags = 0;
if (puzzleItem->TriggerFlags)
{
if (puzzleItem->TriggerFlags == 1)
flags = 26;
else
{
if (puzzleItem->TriggerFlags != 2)
return;
flags = 27;
}
}
else
flags = 25;
if ((laraItem->Animation.AnimNumber == LA_WATERSKIN_POUR_LOW ||
laraItem->Animation.AnimNumber == LA_WATERSKIN_POUR_HIGH) &&
!puzzleItem->ItemFlags[0])
{
auto* box = GetBoundsAccurate(puzzleItem);
ElementPuzzleBounds.boundingBox.X1 = box->X1;
ElementPuzzleBounds.boundingBox.X2 = box->X2;
ElementPuzzleBounds.boundingBox.Z1 = box->Z1 - 200;
ElementPuzzleBounds.boundingBox.Z2 = box->Z2 + 200;
short oldRot = puzzleItem->Pose.Orientation.y;
puzzleItem->Pose.Orientation.y = laraItem->Pose.Orientation.y;
if (TestLaraPosition(&ElementPuzzleBounds, puzzleItem, laraItem))
{
if (laraItem->Animation.AnimNumber == LA_WATERSKIN_POUR_LOW && LaraItem->ItemFlags[2] == flags)
{
laraItem->Animation.AnimNumber = LA_WATERSKIN_POUR_HIGH;
laraItem->Animation.FrameNumber = g_Level.Anims[laraItem->Animation.AnimNumber].frameBase;
}
if (laraItem->Animation.FrameNumber == g_Level.Anims[LA_WATERSKIN_POUR_HIGH].frameBase + 74 &&
LaraItem->ItemFlags[2] == flags)
{
if (!puzzleItem->TriggerFlags)
{
puzzleItem->MeshBits = 48;
TestTriggers(puzzleItem, true, puzzleItem->Flags & IFLAG_ACTIVATION_MASK);
puzzleItem->ItemFlags[0] = 1;
puzzleItem->Pose.Orientation.y = oldRot;
return;
}
if (puzzleItem->TriggerFlags == 1)
{
puzzleItem->MeshBits = 3;
laraInfo->Inventory.Pickups[1]--;
puzzleItem->ItemFlags[0] = 1;
puzzleItem->Pose.Orientation.y = oldRot;
return;
}
puzzleItem->MeshBits = 12;
TestTriggers(puzzleItem, true, puzzleItem->Flags & IFLAG_ACTIVATION_MASK);
laraInfo->Inventory.Pickups[0]--;
puzzleItem->ItemFlags[0] = 1;
}
}
puzzleItem->Pose.Orientation.y = oldRot;
}
else
{
if (laraInfo->Control.Weapon.GunType != LaraWeaponType::Torch ||
laraInfo->Control.HandStatus != HandStatus::WeaponReady ||
laraInfo->LeftArm.Locked ||
!(TrInput & IN_ACTION) ||
puzzleItem->TriggerFlags != 1 ||
puzzleItem->ItemFlags[0] != 1 ||
laraItem->Animation.ActiveState != LS_IDLE ||
laraItem->Animation.AnimNumber != LA_STAND_IDLE ||
!laraInfo->Torch.IsLit ||
laraItem->Animation.IsAirborne)
{
if (laraItem->Animation.AnimNumber != LA_TORCH_LIGHT_3 ||
g_Level.Anims[LA_TORCH_LIGHT_3].frameBase + 16 ||
puzzleItem->ItemFlags[0] != 2)
{
ElementPuzzleDoCollision(itemNumber, laraItem, coll);
}
else
{
TestTriggers(puzzleItem, true, puzzleItem->Flags & IFLAG_ACTIVATION_MASK);
AddActiveItem(itemNumber);
puzzleItem->Status = ITEM_ACTIVE;
puzzleItem->ItemFlags[0] = 3;
puzzleItem->Flags |= 0x3E00;
}
}
else
{
auto* box = GetBoundsAccurate(puzzleItem);
ElementPuzzleBounds.boundingBox.X1 = box->X1;
ElementPuzzleBounds.boundingBox.X2 = box->X2;
ElementPuzzleBounds.boundingBox.Z1 = box->Z1 - 200;
ElementPuzzleBounds.boundingBox.Z2 = box->Z2 + 200;
short oldRot = puzzleItem->Pose.Orientation.y;
puzzleItem->Pose.Orientation.y = laraItem->Pose.Orientation.y;
if (TestLaraPosition(&ElementPuzzleBounds, puzzleItem, laraItem))
{
laraItem->Animation.AnimNumber = (abs(puzzleItem->Pose.Position.y - laraItem->Pose.Position.y) >> 8) + LA_TORCH_LIGHT_3;
laraItem->Animation.FrameNumber = g_Level.Anims[puzzleItem->Animation.AnimNumber].frameBase;
laraItem->Animation.ActiveState = LS_MISC_CONTROL;
laraInfo->Flare.ControlLeft = false;
laraInfo->LeftArm.Locked = true;
puzzleItem->ItemFlags[0] = 2;
}
puzzleItem->Pose.Orientation.y = oldRot;
}
}
}
void InitialiseElementPuzzle(short itemNumber)
{
auto* item = &g_Level.Items[itemNumber];
if (item->TriggerFlags)
{
if (item->TriggerFlags == 1)
item->MeshBits = 65;
else if (item->TriggerFlags == 2)
item->MeshBits = 68;
else
item->MeshBits = 0;
}
else
item->MeshBits = 80;
}
}