TombEngine/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp

318 lines
9.3 KiB
C++
Raw Normal View History

2020-08-21 10:56:03 +02:00
#include "framework.h"
#include "tr4_element_puzzle.h"
#include "level.h"
2021-09-19 23:41:26 +03:00
#include "control/control.h"
2021-09-08 18:31:35 +03:00
#include "Sound\sound.h"
#include "animation.h"
2020-08-21 10:56:03 +02:00
#include <lara.h>
#include <sphere.h>
#include <effects\effects.h>
#include <effects\tomb4fx.h>
#include <switch.h>
#include <input.h>
2021-08-28 06:37:22 +02:00
#include "generic_switch.h"
2021-08-28 13:27:58 +02:00
#include "collide.h"
2021-09-24 07:53:42 +02:00
#include "item.h"
2021-09-25 11:27:47 +02:00
using namespace TEN::Entities::Switches;
2020-08-21 10:56:03 +02:00
namespace TEN::Entities::TR4
2020-08-21 10:56:03 +02:00
{
OBJECT_COLLISION_BOUNDS ElementPuzzleBounds = {
0, 0,
-64, 0,
0, 0,
-ANGLE(10), ANGLE(10),
-ANGLE(30), ANGLE(30),
-ANGLE(10), ANGLE(10)
};
2020-08-21 10:56:03 +02:00
void ElementPuzzleControl(short itemNumber)
2020-08-21 10:56:03 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
2020-08-21 10:56:03 +02:00
if (!TriggerActive(item))
return;
2020-08-21 10:56:03 +02:00
if (item->triggerFlags == 1)
2020-08-21 10:56:03 +02:00
{
SoundEffect(SFX_TR4_LOOP_FOR_SMALL_FIRES, &item->pos, 0);
byte r = (GetRandomControl() & 0x3F) + 192;
byte g = (GetRandomControl() & 0x1F) + 96;
byte b = 0;
int on = 0;
if (item->itemFlags[3])
2020-08-21 10:56:03 +02:00
{
item->itemFlags[3]--;
on = 255 - GetRandomControl() % (4 * (91 - item->itemFlags[3]));
if (on < 1)
{
on = 1;
r = (r * on) / 256;
g = (g * on) / 256;
}
else if (on <= 255)
{
r = (r * on) / 256;
g = (g * on) / 256;
}
2020-08-21 10:56:03 +02:00
}
else
{
on = 0;
}
AddFire(item->pos.xPos, item->pos.yPos - 620, item->pos.zPos, 1, item->roomNumber, on);
TriggerDynamicLight(item->pos.xPos, item->pos.yPos - 768, item->pos.zPos, 12, r, g, b);
return;
2020-08-21 10:56:03 +02:00
}
if (item->triggerFlags != 3)
2020-08-21 10:56:03 +02:00
{
return;
2020-08-21 10:56:03 +02:00
}
if (item->itemFlags[1] > 90)
{
SoundEffect(SFX_TR4_JOBY_WIND, &item->pos, 0);
}
2020-08-21 10:56:03 +02:00
if (item->itemFlags[1] < 60)
{
item->itemFlags[1]++;
return;
}
2020-08-21 10:56:03 +02:00
item->itemFlags[0]++;
2020-08-21 10:56:03 +02:00
if (item->itemFlags[0] == 90)
2020-08-21 10:56:03 +02:00
{
short itemNos[256];
int sw = GetSwitchTrigger(item, itemNos, 0);
if (sw > 0)
2020-08-21 10:56:03 +02:00
{
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;
}
2020-08-21 10:56:03 +02:00
}
KillItem(itemNumber);
return;
}
2020-08-21 10:56:03 +02:00
short currentItemNumber = g_Level.Rooms[item->roomNumber].itemNumber;
if (currentItemNumber == NO_ITEM)
2020-08-21 10:56:03 +02:00
{
return;
2020-08-21 10:56:03 +02:00
}
while (currentItemNumber != NO_ITEM)
2020-08-21 10:56:03 +02:00
{
ITEM_INFO* currentItem = &g_Level.Items[currentItemNumber];
if (currentItem->objectNumber != ID_FLAME_EMITTER2)
2020-08-21 10:56:03 +02:00
{
if (currentItem->objectNumber == ID_ELEMENT_PUZZLE && currentItem->triggerFlags == 1 && !currentItem->itemFlags[3])
{
currentItem->itemFlags[3] = 90;
}
2020-08-21 10:56:03 +02:00
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;
}
2020-08-21 10:56:03 +02:00
RemoveActiveItem(currentItemNumber);
currentItem->status = ITEM_NOT_ACTIVE;
}
}
2020-08-21 10:56:03 +02:00
void ElementPuzzleDoCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll)
2020-08-21 10:56:03 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
if (TestBoundsCollide(item, l, coll->Setup.Radius))
2020-08-21 10:56:03 +02:00
{
if (TestCollision(item, l))
2020-08-21 10:56:03 +02:00
{
if (coll->Setup.EnableObjectPush)
{
ItemPushItem(item, l, coll, 0, 0);
}
2020-08-21 10:56:03 +02:00
}
}
}
void ElementPuzzleCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c)
2020-08-21 10:56:03 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
int flags = 0;
if (item->triggerFlags)
2020-08-21 10:56:03 +02:00
{
if (item->triggerFlags == 1)
{
flags = 26;
}
else
{
if (item->triggerFlags != 2)
{
return;
}
flags = 27;
}
2020-08-21 10:56:03 +02:00
}
else
{
flags = 25;
2020-08-21 10:56:03 +02:00
}
if ((l->animNumber == LA_WATERSKIN_POUR_LOW
|| l->animNumber == LA_WATERSKIN_POUR_HIGH)
&& !item->itemFlags[0])
2020-08-21 10:56:03 +02:00
{
BOUNDING_BOX* box = GetBoundsAccurate(item);
ElementPuzzleBounds.boundingBox.X1 = box->X1;
ElementPuzzleBounds.boundingBox.X2 = box->X2;
ElementPuzzleBounds.boundingBox.Z1 = box->Z1 - 200;
ElementPuzzleBounds.boundingBox.Z2 = box->Z2 + 200;
2020-08-21 10:56:03 +02:00
short oldRot = item->pos.yRot;
item->pos.yRot = l->pos.yRot;
if (TestLaraPosition(&ElementPuzzleBounds, item, l))
2020-08-21 10:56:03 +02:00
{
if (l->animNumber == LA_WATERSKIN_POUR_LOW && LaraItem->itemFlags[2] == flags)
2020-08-21 10:56:03 +02:00
{
l->animNumber = LA_WATERSKIN_POUR_HIGH;
l->frameNumber = g_Level.Anims[l->animNumber].frameBase;
2020-08-21 10:56:03 +02:00
}
if (l->frameNumber == g_Level.Anims[LA_WATERSKIN_POUR_HIGH].frameBase + 74
&& LaraItem->itemFlags[2] == flags)
2020-08-21 10:56:03 +02:00
{
if (!item->triggerFlags)
{
item->meshBits = 48;
TestTriggers(item, true, item->flags & IFLAG_ACTIVATION_MASK);
item->itemFlags[0] = 1;
item->pos.yRot = oldRot;
return;
}
if (item->triggerFlags == 1)
{
item->meshBits = 3;
Lara.Pickups[1]--;
item->itemFlags[0] = 1;
item->pos.yRot = oldRot;
return;
}
item->meshBits = 12;
TestTriggers(item, true, item->flags & IFLAG_ACTIVATION_MASK);
Lara.Pickups[0]--;
2020-08-21 10:56:03 +02:00
item->itemFlags[0] = 1;
2020-08-21 10:56:03 +02:00
}
}
item->pos.yRot = oldRot;
2020-08-21 10:56:03 +02:00
}
else
{
if (Lara.gunType != WEAPON_TORCH
|| Lara.gunStatus != LG_READY
|| Lara.leftArm.lock
|| !(TrInput & IN_ACTION)
|| item->triggerFlags != 1
|| item->itemFlags[0] != 1
|| l->currentAnimState != LS_STOP
|| l->animNumber != LA_STAND_IDLE
|| !Lara.litTorch
|| l->gravityStatus)
{
if (l->animNumber != LA_TORCH_LIGHT_3
|| g_Level.Anims[LA_TORCH_LIGHT_3].frameBase + 16
|| item->itemFlags[0] != 2)
{
ElementPuzzleDoCollision(itemNumber, l, c);
}
else
{
TestTriggers(item, true, item->flags & IFLAG_ACTIVATION_MASK);
AddActiveItem(itemNumber);
item->status = ITEM_ACTIVE;
item->itemFlags[0] = 3;
item->flags |= 0x3E00;
}
}
else
{
BOUNDING_BOX* box = GetBoundsAccurate(item);
2020-08-21 10:56:03 +02:00
ElementPuzzleBounds.boundingBox.X1 = box->X1;
ElementPuzzleBounds.boundingBox.X2 = box->X2;
ElementPuzzleBounds.boundingBox.Z1 = box->Z1 - 200;
ElementPuzzleBounds.boundingBox.Z2 = box->Z2 + 200;
2020-08-21 10:56:03 +02:00
short oldRot = item->pos.yRot;
item->pos.yRot = l->pos.yRot;
2020-08-21 10:56:03 +02:00
if (TestLaraPosition(&ElementPuzzleBounds, item, l))
{
l->animNumber = (abs(item->pos.yPos - l->pos.yPos) >> 8) + LA_TORCH_LIGHT_3;
l->frameNumber = g_Level.Anims[item->animNumber].frameBase;
l->currentAnimState = LS_MISC_CONTROL;
Lara.flareControlLeft = false;
Lara.leftArm.lock = 3;
item->itemFlags[0] = 2;
}
item->pos.yRot = oldRot;
}
2020-08-21 10:56:03 +02:00
}
}
void InitialiseElementPuzzle(short itemNumber)
2020-08-21 10:56:03 +02:00
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
if (item->triggerFlags)
2020-08-21 10:56:03 +02:00
{
if (item->triggerFlags == 1)
{
item->meshBits = 65;
}
else if (item->triggerFlags == 2)
{
item->meshBits = 68;
}
else
{
item->meshBits = 0;
}
2020-08-21 10:56:03 +02:00
}
else
{
item->meshBits = 80;
2020-08-21 10:56:03 +02:00
}
}
}