2021-08-25 08:16:35 +02:00
|
|
|
#include "framework.h"
|
2021-12-24 11:08:16 +03:00
|
|
|
#include "Objects/Generic/Switches/cog_switch.h"
|
2021-12-22 16:23:57 +03:00
|
|
|
#include "Game/control/control.h"
|
|
|
|
#include "Specific/input.h"
|
|
|
|
#include "Game/Lara/lara.h"
|
2022-02-08 20:45:21 +11:00
|
|
|
#include "Game/Lara/lara_helpers.h"
|
2021-12-24 03:32:19 +03:00
|
|
|
#include "Objects/Generic/Switches/generic_switch.h"
|
2021-12-22 16:23:57 +03:00
|
|
|
#include "Game/itemdata/door_data.h"
|
|
|
|
#include "Game/control/box.h"
|
2021-12-24 03:32:19 +03:00
|
|
|
#include "Objects/Generic/Doors/generic_doors.h"
|
2021-12-22 16:23:57 +03:00
|
|
|
#include "Game/collision/collide_item.h"
|
|
|
|
#include "Game/animation.h"
|
|
|
|
#include "Game/items.h"
|
2021-09-25 11:27:47 +02:00
|
|
|
|
2021-09-05 05:52:50 +02:00
|
|
|
using namespace TEN::Entities::Doors;
|
2021-08-25 08:16:35 +02:00
|
|
|
|
2021-08-28 06:37:22 +02:00
|
|
|
namespace TEN::Entities::Switches
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
|
|
|
OBJECT_COLLISION_BOUNDS CogSwitchBounds =
|
|
|
|
{
|
|
|
|
-512, 512,
|
|
|
|
0, 0,
|
|
|
|
-1536, -512,
|
|
|
|
-ANGLE(10), ANGLE(10),
|
|
|
|
-ANGLE(30), ANGLE(30),
|
|
|
|
-ANGLE(10), ANGLE(10)
|
|
|
|
};
|
2021-08-26 10:41:07 +03:00
|
|
|
PHD_VECTOR CogSwitchPos(0, 0, -856);
|
2021-08-25 08:16:35 +02:00
|
|
|
|
|
|
|
void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll)
|
|
|
|
{
|
2021-08-26 10:31:58 +03:00
|
|
|
auto item = &g_Level.Items[itemNum];
|
|
|
|
auto triggerIndex = GetTriggerIndex(item);
|
2021-08-25 08:16:35 +02:00
|
|
|
|
2021-09-16 02:39:25 +03:00
|
|
|
int targetItemNum;
|
|
|
|
ITEM_INFO* target = nullptr;
|
|
|
|
DOOR_DATA* door = nullptr;
|
|
|
|
|
|
|
|
// Try to find first item in a trigger list, and if it is a door,
|
|
|
|
// attach it to cog. If no object found or object is not door,
|
|
|
|
// bypass further processing and do ordinary object collision.
|
|
|
|
|
|
|
|
if (triggerIndex)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2021-09-16 02:39:25 +03:00
|
|
|
short* trigger = triggerIndex;
|
|
|
|
targetItemNum = trigger[3] & VALUE_BITS;
|
|
|
|
|
|
|
|
if (targetItemNum < g_Level.Items.size())
|
|
|
|
{
|
|
|
|
target = &g_Level.Items[targetItemNum];
|
2022-02-09 16:55:46 +11:00
|
|
|
if (target->Data.is<DOOR_DATA>())
|
|
|
|
door = (DOOR_DATA*)target->Data;
|
2021-09-16 02:39:25 +03:00
|
|
|
}
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 02:39:25 +03:00
|
|
|
// Door was not found, do ordinary collision and exit.
|
2021-09-15 10:12:42 +03:00
|
|
|
|
2021-09-16 02:39:25 +03:00
|
|
|
if (door == nullptr)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2021-09-15 10:12:42 +03:00
|
|
|
ObjectCollision(itemNum, l, coll);
|
|
|
|
return;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
2021-09-15 10:12:42 +03:00
|
|
|
|
2021-09-16 02:39:25 +03:00
|
|
|
// Door is found, attach to it.
|
2021-08-25 08:16:35 +02:00
|
|
|
|
2022-02-09 16:55:46 +11:00
|
|
|
if (item->Status == ITEM_NOT_ACTIVE)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
if (!(item->Flags & ONESHOT)
|
2021-08-25 08:16:35 +02:00
|
|
|
&& (TrInput & IN_ACTION
|
2022-02-11 01:31:54 +11:00
|
|
|
&& Lara.Control.HandStatus == HandStatus::Free
|
2022-02-09 13:20:57 +11:00
|
|
|
&& !item->Airborne
|
2022-02-09 16:55:46 +11:00
|
|
|
&& l->ActiveState == LS_IDLE
|
|
|
|
&& l->AnimNumber == LA_STAND_IDLE
|
2022-02-10 01:38:32 +11:00
|
|
|
|| Lara.Control.IsMoving
|
2021-09-05 11:18:37 +02:00
|
|
|
&& Lara.interactedItem == itemNum))
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
|
|
|
if (TestLaraPosition(&CogSwitchBounds, item, l))
|
|
|
|
{
|
|
|
|
if (MoveLaraPosition(&CogSwitchPos, item, l))
|
|
|
|
{
|
2022-02-10 01:38:32 +11:00
|
|
|
Lara.Control.IsMoving = false;
|
2022-02-08 20:45:21 +11:00
|
|
|
ResetLaraFlex(l);
|
2022-02-11 01:31:54 +11:00
|
|
|
Lara.Control.HandStatus = HandStatus::Busy;
|
2021-09-05 11:18:37 +02:00
|
|
|
Lara.interactedItem = targetItemNum;
|
2022-02-09 16:55:46 +11:00
|
|
|
l->AnimNumber = LA_COGWHEEL_GRAB;
|
|
|
|
l->TargetState = LS_COGWHEEL;
|
|
|
|
l->ActiveState = LS_COGWHEEL;
|
|
|
|
l->FrameNumber = g_Level.Anims[l->AnimNumber].frameBase;
|
2021-08-25 08:16:35 +02:00
|
|
|
|
|
|
|
AddActiveItem(itemNum);
|
2022-02-09 16:55:46 +11:00
|
|
|
item->TargetState = SWITCH_ON;
|
|
|
|
item->Status = ITEM_ACTIVE;
|
2021-08-25 08:16:35 +02:00
|
|
|
|
|
|
|
if (door != NULL)
|
|
|
|
{
|
|
|
|
if (!door->opened)
|
|
|
|
{
|
|
|
|
AddActiveItem((target - g_Level.Items.data()));
|
2022-02-09 16:55:46 +11:00
|
|
|
target->Status = ITEM_ACTIVE;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-05 11:18:37 +02:00
|
|
|
Lara.interactedItem = itemNum;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2022-02-10 01:38:32 +11:00
|
|
|
else if (Lara.Control.IsMoving && Lara.interactedItem == itemNum)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-10 01:38:32 +11:00
|
|
|
Lara.Control.IsMoving = false;
|
2022-02-11 01:31:54 +11:00
|
|
|
Lara.Control.HandStatus = HandStatus::Free;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectCollision(itemNum, l, coll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CogSwitchControl(short itemNumber)
|
|
|
|
{
|
|
|
|
ITEM_INFO* item = &g_Level.Items[itemNumber];
|
|
|
|
|
|
|
|
AnimateItem(item);
|
|
|
|
|
2022-02-09 16:55:46 +11:00
|
|
|
if (item->ActiveState == SWITCH_ON)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
if (item->TargetState == SWITCH_ON && !(TrInput & IN_ACTION))
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
LaraItem->TargetState = LS_IDLE;
|
|
|
|
item->TargetState = SWITCH_OFF;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
|
2022-02-09 16:55:46 +11:00
|
|
|
if (LaraItem->AnimNumber == LA_COGWHEEL_PULL)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
if (LaraItem->FrameNumber == g_Level.Anims[LaraItem->AnimNumber].frameBase + 10)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2021-09-05 11:18:37 +02:00
|
|
|
ITEM_INFO* doorItem = &g_Level.Items[Lara.interactedItem];
|
2022-02-09 16:55:46 +11:00
|
|
|
doorItem->ItemFlags[0] = COG_DOOR_TURN;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
if (item->FrameNumber == g_Level.Anims[item->AnimNumber].frameEnd)
|
2021-08-25 08:16:35 +02:00
|
|
|
{
|
2022-02-09 16:55:46 +11:00
|
|
|
item->ActiveState = SWITCH_OFF;
|
|
|
|
item->Status = ITEM_NOT_ACTIVE;
|
2021-08-25 08:16:35 +02:00
|
|
|
|
|
|
|
RemoveActiveItem(itemNumber);
|
|
|
|
|
2022-02-09 16:55:46 +11:00
|
|
|
LaraItem->AnimNumber = LA_STAND_SOLID;
|
|
|
|
LaraItem->FrameNumber = g_Level.Anims[LaraItem->AnimNumber].frameBase;
|
|
|
|
LaraItem->TargetState = LS_IDLE;
|
|
|
|
LaraItem->ActiveState = LS_IDLE;
|
2022-02-11 01:31:54 +11:00
|
|
|
Lara.Control.HandStatus = HandStatus::Free;
|
2021-08-25 08:16:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|