TombEngine/TR5Main/Objects/Generic/Doors/pushpull_kick_door.cpp

158 lines
3.4 KiB
C++
Raw Normal View History

2021-09-05 05:52:50 +02:00
#include "framework.h"
#include "generic_doors.h"
#include "level.h"
#include "control.h"
#include "box.h"
#include "items.h"
#include "lot.h"
#include "newinv2.h"
#include "input.h"
2021-09-11 09:41:29 +03:00
#include "pickup\pickup.h"
2021-09-05 05:52:50 +02:00
#include "sound.h"
#include "draw.h"
#include "sphere.h"
#include "lara_struct.h"
#include "lara.h"
#include "trmath.h"
#include "misc.h"
#include "pushpull_kick_door.h"
#include "collide.h"
#include "door_data.h"
2021-09-05 05:52:50 +02:00
namespace TEN::Entities::Doors
{
2021-09-07 06:04:09 +02:00
enum STATES_PUSHPULL_KICK_DOOR
{
STATE_PUSHPULL_KICK_DOOR_OPEN = 0,
STATE_PUSHPULL_KICK_DOOR_CLOSED = 1,
STATE_PUSHPULL_KICK_DOOR_PUSH = 2,
STATE_PUSHPULL_KICK_DOOR_PULL = 3
};
2021-09-05 05:52:50 +02:00
PHD_VECTOR PullDoorPos(-201, 0, 322);
PHD_VECTOR PushDoorPos(201, 0, -702);
PHD_VECTOR KickDoorPos(0, 0, -917);
OBJECT_COLLISION_BOUNDS PushPullKickDoorBounds =
{
-384, 384,
0, 0,
-1024, 512,
-ANGLE(10), ANGLE(10),
-ANGLE(30), ANGLE(30),
-ANGLE(10), ANGLE(10),
};
void PushPullKickDoorCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll)
{
ITEM_INFO* item = &g_Level.Items[itemNum];
2021-09-07 06:04:09 +02:00
2021-09-05 05:52:50 +02:00
if (TrInput & IN_ACTION
&& l->currentAnimState == LS_STOP
&& l->animNumber == LA_STAND_IDLE
&& item->status != ITEM_ACTIVE
&& !(l->hitStatus)
&& !Lara.gunStatus
|| Lara.isMoving && Lara.interactedItem == itemNum)
2021-09-05 05:52:50 +02:00
{
2021-09-07 06:04:09 +02:00
bool pull = false;
2021-09-05 05:52:50 +02:00
if (l->roomNumber == item->roomNumber)
{
item->pos.yRot ^= ANGLE(180);
2021-09-07 06:04:09 +02:00
pull = true;
2021-09-05 05:52:50 +02:00
}
2021-09-07 06:04:09 +02:00
if (TestLaraPosition(&PushPullKickDoorBounds, item, l))
2021-09-05 05:52:50 +02:00
{
2021-09-07 06:04:09 +02:00
bool openTheDoor = false;
if (pull)
2021-09-05 05:52:50 +02:00
{
2021-09-07 06:04:09 +02:00
if (MoveLaraPosition(&PullDoorPos, item, l))
{
l->animNumber = LA_DOOR_OPEN_PULL;
l->frameNumber = GF(LA_DOOR_OPEN_PULL, 0);
item->goalAnimState = STATE_PUSHPULL_KICK_DOOR_PULL;
openTheDoor = true;
}
else
{
Lara.interactedItem = itemNum;
2021-09-07 06:04:09 +02:00
}
2021-09-05 05:52:50 +02:00
}
2021-09-07 06:04:09 +02:00
else
2021-09-05 05:52:50 +02:00
{
2021-09-07 06:04:09 +02:00
if (item->objectNumber >= ID_KICK_DOOR1)
{
if (MoveLaraPosition(&KickDoorPos, item, l))
{
l->animNumber = LA_DOOR_OPEN_KICK;
l->frameNumber = GF(LA_DOOR_OPEN_KICK, 0);
item->goalAnimState = STATE_PUSHPULL_KICK_DOOR_PUSH;
openTheDoor = true;
}
else
{
Lara.interactedItem = itemNum;
2021-09-07 06:04:09 +02:00
}
}
else
{
if (MoveLaraPosition(&PushDoorPos, item, l))
{
l->animNumber = LA_DOOR_OPEN_PUSH;
l->frameNumber = GF(LA_DOOR_OPEN_PUSH, 0);
item->goalAnimState = STATE_PUSHPULL_KICK_DOOR_PUSH;
openTheDoor = true;
}
else
{
Lara.interactedItem = itemNum;
2021-09-07 06:04:09 +02:00
}
}
2021-09-05 05:52:50 +02:00
}
2021-09-07 06:04:09 +02:00
if (openTheDoor)
2021-09-05 05:52:50 +02:00
{
AddActiveItem(itemNum);
item->status = ITEM_ACTIVE;
l->currentAnimState = LS_MISC_CONTROL;
l->goalAnimState = LS_STOP;
Lara.isMoving = false;
Lara.gunStatus = LG_HANDS_BUSY;
}
}
else if (Lara.isMoving && Lara.interactedItem == itemNum)
2021-09-05 05:52:50 +02:00
{
2021-09-07 06:04:09 +02:00
Lara.isMoving = false;
Lara.gunStatus = LG_NO_ARMS;
2021-09-05 05:52:50 +02:00
}
2021-09-07 06:04:09 +02:00
if (pull)
item->pos.yRot ^= ANGLE(180);
2021-09-05 05:52:50 +02:00
}
2021-09-07 06:04:09 +02:00
else if (item->currentAnimState <= STATE_PUSHPULL_KICK_DOOR_CLOSED)
2021-09-05 05:52:50 +02:00
DoorCollision(itemNum, l, coll);
}
void PushPullKickDoorControl(short itemNumber)
{
ITEM_INFO* item;
DOOR_DATA* door;
item = &g_Level.Items[itemNumber];
door = (DOOR_DATA*)item->data;
if (!door->opened)
{
OpenThatDoor(&door->d1, door);
OpenThatDoor(&door->d2, door);
OpenThatDoor(&door->d1flip, door);
OpenThatDoor(&door->d2flip, door);
door->opened = true;
}
AnimateItem(item);
}
}