TombEngine/TR5Main/Objects/Generic/Switches/cog_switch.cpp

161 lines
4.2 KiB
C++
Raw Normal View History

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"
#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,
2022-02-24 14:22:30 +11:00
-ANGLE(10.0f), ANGLE(10.0f),
-ANGLE(30.0f), ANGLE(30.0f),
-ANGLE(10.0f), ANGLE(10.0f)
2021-08-25 08:16:35 +02:00
};
PHD_VECTOR CogSwitchPos(0, 0, -856);
2021-08-25 08:16:35 +02:00
2022-02-24 14:22:30 +11:00
void CogSwitchCollision(short itemNum, ITEM_INFO* laraItem, COLL_INFO* coll)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
auto* laraInfo = GetLaraInfo(laraItem);
auto* switchItem = &g_Level.Items[itemNum];
auto* triggerIndex = GetTriggerIndex(switchItem);
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];
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
{
2022-02-24 14:22:30 +11:00
ObjectCollision(itemNum, laraItem, coll);
2021-09-15 10:12:42 +03:00
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-24 14:22:30 +11:00
if (switchItem->Status == ITEM_NOT_ACTIVE)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
if (!(switchItem->Flags & ONESHOT) &&
(TrInput & IN_ACTION &&
laraItem->ActiveState == LS_IDLE &&
laraItem->AnimNumber == LA_STAND_IDLE &&
laraInfo->Control.HandStatus == HandStatus::Free &&
!switchItem->Airborne ||
laraInfo->Control.IsMoving &&
laraInfo->interactedItem == itemNum))
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
if (TestLaraPosition(&CogSwitchBounds, switchItem, laraItem))
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
if (MoveLaraPosition(&CogSwitchPos, switchItem, laraItem))
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
ResetLaraFlex(laraItem);
laraItem->AnimNumber = LA_COGWHEEL_GRAB;
laraItem->TargetState = LS_COGWHEEL;
laraItem->ActiveState = LS_COGWHEEL;
laraItem->FrameNumber = g_Level.Anims[laraItem->AnimNumber].frameBase;
laraInfo->Control.IsMoving = false;
laraInfo->Control.HandStatus = HandStatus::Busy;
laraInfo->interactedItem = targetItemNum;
2021-08-25 08:16:35 +02:00
AddActiveItem(itemNum);
2022-02-24 14:22:30 +11:00
switchItem->TargetState = SWITCH_ON;
switchItem->Status = ITEM_ACTIVE;
2021-08-25 08:16:35 +02:00
if (door != NULL)
{
if (!door->opened)
{
AddActiveItem((target - g_Level.Items.data()));
target->Status = ITEM_ACTIVE;
2021-08-25 08:16:35 +02:00
}
}
}
else
2022-02-24 14:22:30 +11:00
laraInfo->interactedItem = itemNum;
2021-08-25 08:16:35 +02:00
return;
}
2022-02-24 14:22:30 +11:00
else if (laraInfo->Control.IsMoving && laraInfo->interactedItem == itemNum)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
laraInfo->Control.IsMoving = false;
laraInfo->Control.HandStatus = HandStatus::Free;
2021-08-25 08:16:35 +02:00
}
}
2022-02-24 14:22:30 +11:00
ObjectCollision(itemNum, laraItem, coll);
2021-08-25 08:16:35 +02:00
}
}
void CogSwitchControl(short itemNumber)
{
2022-02-24 14:22:30 +11:00
auto* switchItem = &g_Level.Items[itemNumber];
2021-08-25 08:16:35 +02:00
2022-02-24 14:22:30 +11:00
AnimateItem(switchItem);
2021-08-25 08:16:35 +02:00
2022-02-24 14:22:30 +11:00
if (switchItem->ActiveState == SWITCH_ON)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
if (switchItem->TargetState == SWITCH_ON && !(TrInput & IN_ACTION))
2021-08-25 08:16:35 +02:00
{
LaraItem->TargetState = LS_IDLE;
2022-02-24 14:22:30 +11:00
switchItem->TargetState = SWITCH_OFF;
2021-08-25 08:16:35 +02:00
}
if (LaraItem->AnimNumber == LA_COGWHEEL_PULL)
2021-08-25 08:16:35 +02:00
{
if (LaraItem->FrameNumber == g_Level.Anims[LaraItem->AnimNumber].frameBase + 10)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
auto* doorItem = &g_Level.Items[Lara.interactedItem];
doorItem->ItemFlags[0] = COG_DOOR_TURN;
2021-08-25 08:16:35 +02:00
}
}
}
else
{
2022-02-24 14:22:30 +11:00
if (switchItem->FrameNumber == g_Level.Anims[switchItem->AnimNumber].frameEnd)
2021-08-25 08:16:35 +02:00
{
2022-02-24 14:22:30 +11:00
switchItem->ActiveState = SWITCH_OFF;
switchItem->Status = ITEM_NOT_ACTIVE;
2021-08-25 08:16:35 +02:00
RemoveActiveItem(itemNumber);
LaraItem->AnimNumber = LA_STAND_SOLID;
LaraItem->FrameNumber = g_Level.Anims[LaraItem->AnimNumber].frameBase;
LaraItem->TargetState = LS_IDLE;
LaraItem->ActiveState = LS_IDLE;
Lara.Control.HandStatus = HandStatus::Free;
2021-08-25 08:16:35 +02:00
}
}
}
2022-02-24 14:22:30 +11:00
}