2021-08-25 09:42:17 +02:00
|
|
|
#include "framework.h"
|
2021-12-24 11:08:16 +03:00
|
|
|
#include "Objects/Generic/Switches/rail_switch.h"
|
2021-12-22 16:23:57 +03:00
|
|
|
#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 "Specific/level.h"
|
|
|
|
#include "Game/collision/collide_item.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
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
|
|
|
PHD_VECTOR RailSwitchPos = { 0, 0, -550 };
|
|
|
|
|
|
|
|
OBJECT_COLLISION_BOUNDS RailSwitchBounds =
|
|
|
|
{
|
|
|
|
-256, 256,
|
|
|
|
0, 0,
|
|
|
|
-768, -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 09:42:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
PHD_VECTOR RailSwitchPos2 = { 0, 0, 550 };
|
|
|
|
|
|
|
|
OBJECT_COLLISION_BOUNDS RailSwitchBounds2 =
|
|
|
|
{
|
|
|
|
-256, 256,
|
|
|
|
0, 0,
|
|
|
|
512, 768,
|
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 09:42:17 +02:00
|
|
|
};
|
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
void RailSwitchCollision(short itemNumber, ITEM_INFO* laraItem, COLL_INFO* coll)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
auto* laraInfo = GetLaraInfo(laraItem);
|
|
|
|
auto* switchItem = &g_Level.Items[itemNumber];
|
|
|
|
|
2021-08-25 09:42:17 +02:00
|
|
|
int flag = 0;
|
|
|
|
|
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) &&
|
|
|
|
(!laraInfo->Control.IsMoving ||
|
2022-03-08 18:22:14 +11:00
|
|
|
laraInfo->InteractedItem != itemNumber))
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
ObjectCollision(itemNumber, laraItem, coll);
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
2022-02-24 14:22:30 +11:00
|
|
|
else if (switchItem->ActiveState)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
if (switchItem->ActiveState == SWITCH_ON)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
laraItem->Position.yRot ^= (short)ANGLE(180.0f);
|
2021-08-25 09:42:17 +02:00
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
if (TestLaraPosition(&RailSwitchBounds2, switchItem, laraItem))
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
if (MoveLaraPosition(&RailSwitchPos2, switchItem, laraItem))
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
switchItem->TargetState = SWITCH_OFF;
|
2021-08-25 09:42:17 +02:00
|
|
|
flag = 1;
|
|
|
|
}
|
|
|
|
else
|
2022-03-08 18:22:14 +11:00
|
|
|
laraInfo->InteractedItem = itemNumber;
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
2022-03-08 18:22:14 +11:00
|
|
|
else if (laraInfo->Control.IsMoving && laraInfo->InteractedItem == itemNumber)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
laraInfo->Control.IsMoving = false;
|
|
|
|
laraInfo->Control.HandStatus = HandStatus::Free;
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
laraItem->Position.yRot ^= (short)ANGLE(180.0f);
|
2021-08-25 09:42:17 +02:00
|
|
|
|
|
|
|
if (flag)
|
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
ResetLaraFlex(laraItem);
|
|
|
|
laraItem->AnimNumber = LA_LEVER_PUSH;
|
|
|
|
laraItem->FrameNumber = g_Level.Anims[laraItem->AnimNumber].frameBase;
|
|
|
|
laraItem->TargetState = LS_LEVERSWITCH_PUSH;
|
|
|
|
laraItem->ActiveState = LS_LEVERSWITCH_PUSH;
|
|
|
|
laraInfo->Control.IsMoving = false;
|
|
|
|
laraInfo->Control.HandStatus = HandStatus::Busy;
|
|
|
|
switchItem->Status = ITEM_ACTIVE;
|
2021-08-25 09:42:17 +02:00
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
AddActiveItem(itemNumber);
|
|
|
|
AnimateItem(switchItem);
|
2021-08-25 09:42:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
ObjectCollision(itemNumber, laraItem, coll);
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
if (TestLaraPosition(&RailSwitchBounds, switchItem, laraItem))
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
if (MoveLaraPosition(&RailSwitchPos, switchItem, laraItem))
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
ResetLaraFlex(laraItem);
|
|
|
|
laraItem->AnimNumber = LA_LEVER_PUSH;
|
|
|
|
laraItem->FrameNumber = g_Level.Anims[laraItem->AnimNumber].frameBase;
|
|
|
|
laraItem->TargetState = LS_LEVERSWITCH_PUSH;
|
|
|
|
laraItem->ActiveState = LS_LEVERSWITCH_PUSH;
|
|
|
|
laraInfo->Control.IsMoving = false;
|
|
|
|
laraInfo->Control.HandStatus = HandStatus::Busy;
|
|
|
|
switchItem->TargetState = SWITCH_ON;
|
|
|
|
switchItem->Status = ITEM_ACTIVE;
|
2021-08-25 09:42:17 +02:00
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
AddActiveItem(itemNumber);
|
|
|
|
AnimateItem(switchItem);
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
|
|
|
else
|
2022-03-08 18:22:14 +11:00
|
|
|
laraInfo->InteractedItem = itemNumber;
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
2022-02-24 14:22:30 +11:00
|
|
|
else if (laraInfo->Control.IsMoving)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-03-08 18:22:14 +11:00
|
|
|
if (laraInfo->InteractedItem == itemNumber)
|
2021-08-25 09:42:17 +02:00
|
|
|
{
|
2022-02-24 14:22:30 +11:00
|
|
|
laraInfo->Control.IsMoving = false;
|
|
|
|
laraInfo->Control.HandStatus = HandStatus::Free;
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-24 14:22:30 +11:00
|
|
|
ObjectCollision(itemNumber, laraItem, coll);
|
2021-08-25 09:42:17 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-24 14:22:30 +11:00
|
|
|
}
|