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

109 lines
2.8 KiB
C++
Raw Normal View History

2021-08-28 06:37:22 +02:00
#include "framework.h"
2021-12-24 03:32:19 +03:00
#include "Objects/Generic/Switches/fullblock_switch.h"
2021-12-22 16:23:57 +03:00
#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 "Specific/setup.h"
#include "Game/collision/collide_item.h"
#include "Specific/level.h"
#include "Game/animation.h"
#include "Game/items.h"
2021-09-25 11:27:47 +02:00
2021-08-28 06:37:22 +02:00
namespace TEN::Entities::Switches
{
OBJECT_COLLISION_BOUNDS FullBlockSwitchBounds =
{
-384, 384,
0, 256,
0, 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-28 06:37:22 +02:00
};
PHD_VECTOR FullBlockSwitchPos = { 0, 0, 0 };
byte SequenceUsed[6];
byte SequenceResults[3][3][3];
byte Sequences[3];
byte CurrentSequence;
2022-02-24 14:22:30 +11:00
void FullBlockSwitchCollision(short itemNumber, ITEM_INFO* laraItem, COLL_INFO* coll)
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
auto* laraInfo = GetLaraInfo(laraItem);
auto* switchItem = &g_Level.Items[itemNumber];
2021-08-28 06:37:22 +02:00
2022-02-24 14:22:30 +11:00
if ((!(TrInput & IN_ACTION) ||
laraItem->ActiveState != LS_IDLE ||
laraItem->AnimNumber != LA_STAND_IDLE ||
laraInfo->Control.HandStatus != HandStatus::Free ||
switchItem->Status ||
switchItem->Flags & 0x100 ||
CurrentSequence >= 3) &&
(!laraInfo->Control.IsMoving || laraInfo->interactedItem !=itemNumber))
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
ObjectCollision(itemNumber, laraItem, coll);
2021-08-28 06:37:22 +02:00
return;
}
2022-02-24 14:22:30 +11:00
if (TestLaraPosition(&FullBlockSwitchBounds, switchItem, laraItem))
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
if (MoveLaraPosition(&FullBlockSwitchPos, switchItem, laraItem))
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
if (switchItem->ActiveState == 1)
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
laraItem->ActiveState = LS_SWITCH_DOWN;
laraItem->AnimNumber = LA_BUTTON_GIANT_PUSH;
switchItem->TargetState = 0;
2021-08-28 06:37:22 +02:00
}
2022-02-24 14:22:30 +11:00
laraItem->TargetState = LS_IDLE;
laraItem->FrameNumber = g_Level.Anims[laraItem->AnimNumber].frameBase;
switchItem->Status = ITEM_ACTIVE;
2021-08-28 06:37:22 +02:00
2022-02-24 14:22:30 +11:00
AddActiveItem(itemNumber);
AnimateItem(switchItem);
ResetLaraFlex(laraItem);
laraInfo->Control.IsMoving = false;
laraInfo->Control.HandStatus = HandStatus::Busy;
2021-08-28 06:37:22 +02:00
}
else
2022-02-24 14:22:30 +11:00
laraInfo->interactedItem = itemNumber;
2021-08-28 06:37:22 +02:00
}
2022-02-24 14:22:30 +11:00
else if (laraInfo->Control.IsMoving && laraInfo->interactedItem == itemNumber)
2021-08-28 06:37:22 +02:00
{
2022-02-24 14:22:30 +11:00
laraInfo->Control.IsMoving = false;
laraInfo->Control.HandStatus = HandStatus::Free;
2021-08-28 06:37:22 +02:00
}
}
void FullBlockSwitchControl(short itemNumber)
{
2022-02-24 14:22:30 +11:00
ITEM_INFO* switchItem = &g_Level.Items[itemNumber];
2021-08-28 06:37:22 +02:00
2022-02-24 14:22:30 +11:00
if (switchItem->AnimNumber != Objects[switchItem->ObjectNumber].animIndex + 2 ||
CurrentSequence >= 3 ||
switchItem->ItemFlags[0])
2021-08-28 06:37:22 +02:00
{
if (CurrentSequence >= 4)
{
2022-02-24 14:22:30 +11:00
switchItem->ItemFlags[0] = 0;
switchItem->TargetState = SWITCH_ON;
switchItem->Status = ITEM_NOT_ACTIVE;
2021-08-28 06:37:22 +02:00
if (++CurrentSequence >= 7)
CurrentSequence = 0;
}
}
else
{
2022-02-24 14:22:30 +11:00
switchItem->ItemFlags[0] = 1;
Sequences[CurrentSequence++] = switchItem->TriggerFlags;
2021-08-28 06:37:22 +02:00
}
2022-02-24 14:22:30 +11:00
AnimateItem(switchItem);
2021-08-28 06:37:22 +02:00
}
2022-02-24 14:22:30 +11:00
}