TombEngine/TR5Main/Game/Lara/lara_collide.cpp

354 lines
8 KiB
C++
Raw Normal View History

#include "framework.h"
#include "lara.h"
#include "input.h"
2021-09-19 18:29:25 +03:00
#include "level.h"
#include "animation.h"
2021-09-19 18:29:25 +03:00
#include "effects/effects.h"
2021-08-28 13:27:58 +02:00
#include "collide.h"
2021-09-19 23:41:26 +03:00
#include "control/control.h"
#include "lara_collide.h"
2021-11-07 04:54:48 +03:00
#include "lara_tests.h"
2021-09-25 16:00:30 +03:00
#include "items.h"
2021-11-07 04:54:48 +03:00
#include "setup.h"
2021-09-25 11:27:47 +02:00
/*this file has all the generic **collision** test functions called in lara's state code*/
2021-02-03 01:50:59 -03:00
int LaraDeflectEdge(ITEM_INFO* item, COLL_INFO* coll)
{
2021-09-10 00:18:47 +03:00
if (coll->CollisionType == CT_FRONT || coll->CollisionType == CT_TOP_FRONT)
{
ShiftItem(item, coll);
item->goalAnimState = LS_STOP;
item->speed = 0;
item->gravityStatus = false;
return 1;
}
2021-09-10 00:18:47 +03:00
if (coll->CollisionType == CT_LEFT)
{
ShiftItem(item, coll);
item->pos.yRot += ANGLE(coll->DiagonalStepAtLeft() ? DEFLECT_DIAGONAL_ANGLE : DEFLECT_STRAIGHT_ANGLE);
}
2021-09-10 00:18:47 +03:00
else if (coll->CollisionType == CT_RIGHT)
{
ShiftItem(item, coll);
item->pos.yRot -= ANGLE(coll->DiagonalStepAtRight() ? DEFLECT_DIAGONAL_ANGLE : DEFLECT_STRAIGHT_ANGLE);
}
return 0;
}
2021-02-03 01:50:59 -03:00
void LaraDeflectEdgeJump(ITEM_INFO* item, COLL_INFO* coll)
{
ShiftItem(item, coll);
2021-09-10 00:18:47 +03:00
switch (coll->CollisionType)
{
case CT_FRONT:
case CT_TOP_FRONT:
if (!Lara.climbStatus || item->speed != 2)
{
2021-09-10 00:18:47 +03:00
if (coll->Middle.Floor <= 512)
{
2021-09-10 00:18:47 +03:00
if (coll->Middle.Floor <= 128)
{
item->goalAnimState = LS_GRAB_TO_FALL;
item->currentAnimState = LS_GRAB_TO_FALL;
item->animNumber = LA_JUMP_UP_LAND;
item->frameNumber = g_Level.Anims[LA_JUMP_UP_LAND].frameBase;
}
}
else
{
item->goalAnimState = LS_FREEFALL;
item->currentAnimState = LS_FREEFALL;
item->animNumber = LA_JUMP_WALL_SMASH_START;
item->frameNumber = g_Level.Anims[LA_JUMP_WALL_SMASH_START].frameBase + 1;
}
item->speed /= 4;
Lara.moveAngle += ANGLE(180);
if (item->fallspeed <= 0)
item->fallspeed = 1;
}
break;
case CT_TOP:
if (item->fallspeed <= 0)
item->fallspeed = 1;
break;
case CT_LEFT:
item->pos.yRot += ANGLE(5.0f);
break;
case CT_RIGHT:
item->pos.yRot -= ANGLE(5.0f);
break;
case CT_CLAMP:
2021-09-10 00:20:59 +03:00
item->pos.xPos -= 400 * phd_sin(coll->Setup.ForwardAngle);
item->pos.zPos -= 400 * phd_cos(coll->Setup.ForwardAngle);
item->speed = 0;
2021-09-10 00:18:47 +03:00
coll->Middle.Floor = 0;
if (item->fallspeed <= 0)
item->fallspeed = 16;
break;
}
}
2021-02-03 01:50:59 -03:00
int LaraDeflectEdgeDuck(ITEM_INFO* item, COLL_INFO* coll)
{
2021-09-10 00:18:47 +03:00
if (coll->CollisionType == CT_FRONT || coll->CollisionType == CT_TOP_FRONT)
{
ShiftItem(item, coll);
item->gravityStatus = false;
item->speed = 0;
return 1;
}
2021-09-10 00:18:47 +03:00
if (coll->CollisionType == CT_LEFT)
{
ShiftItem(item, coll);
item->pos.yRot += ANGLE(2.0f);
}
2021-09-10 00:18:47 +03:00
else if (coll->CollisionType == CT_RIGHT)
{
ShiftItem(item, coll);
item->pos.yRot -= ANGLE(2.0f);
}
return 0;
}
2021-02-03 01:50:59 -03:00
int LaraHitCeiling(ITEM_INFO* item, COLL_INFO* coll)
{
2021-09-10 00:18:47 +03:00
if (coll->CollisionType == CT_TOP || coll->CollisionType == CT_CLAMP)
{
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x;
item->pos.yPos = coll->Setup.OldPosition.y;
item->pos.zPos = coll->Setup.OldPosition.z;
item->goalAnimState = LS_STOP;
item->currentAnimState = LS_STOP;
item->animNumber = LA_STAND_SOLID;
item->frameNumber = g_Level.Anims[item->animNumber].frameBase;
item->speed = 0;
item->fallspeed = 0;
item->gravityStatus = false;
return 1;
}
return 0;
}
2021-02-03 01:50:59 -03:00
void LaraCollideStop(ITEM_INFO* item, COLL_INFO* coll)
{
2021-09-10 00:20:59 +03:00
switch (coll->Setup.OldAnimState)
{
case LS_STOP:
case LS_TURN_RIGHT_SLOW:
case LS_TURN_LEFT_SLOW:
case LS_TURN_FAST:
2021-09-10 00:20:59 +03:00
item->currentAnimState = coll->Setup.OldAnimState;
item->animNumber = coll->Setup.OldAnimNumber;
item->frameNumber = coll->Setup.OldFrameNumber;
if (TrInput & IN_LEFT)
{
item->goalAnimState = LS_TURN_LEFT_SLOW;
}
else if (TrInput & IN_RIGHT)
{
item->goalAnimState = LS_TURN_RIGHT_SLOW;
}
else
{
item->goalAnimState = LS_STOP;
}
AnimateLara(item);
break;
default:
item->goalAnimState = LS_STOP;
if (item->animNumber != LA_STAND_SOLID)
{
item->animNumber = LA_STAND_SOLID;
item->frameNumber = g_Level.Anims[LA_STAND_SOLID].frameBase;
}
break;
}
}
2021-09-25 13:00:14 +03:00
void LaraSnapToEdgeOfBlock(ITEM_INFO* item, COLL_INFO* coll, short angle)
{
if (item->currentAnimState == LS_SHIMMY_RIGHT)
{
switch (angle)
{
case NORTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFF90 | 0x390;
return;
case EAST:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFC70 | 0x70;
return;
case SOUTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFC70 | 0x70;
return;
case WEST:
default:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFF90 | 0x390;
return;
}
}
if (item->currentAnimState == LS_SHIMMY_LEFT)
{
switch (angle)
{
case NORTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFC70 | 0x70;
return;
case EAST:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFF90 | 0x390;
return;
case SOUTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFF90 | 0x390;
return;
case WEST:
default:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFC70 | 0x70;
return;
}
}
if (item->currentAnimState == LS_SHIMMY_FEET_RIGHT)
{
switch (angle)
{
case NORTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFF90 | 0x720;
return;
case EAST:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFC70 | 0xE0;
return;
case SOUTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFC70 | 0xE0;
return;
case WEST:
default:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFF90 | 0x720;
return;
}
}
if (item->currentAnimState == LS_SHIMMY_FEET_LEFT)
{
switch (angle)
{
case NORTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFC70 | 0xE0;
return;
case EAST:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFF90 | 0x720;
return;
case SOUTH:
2021-09-10 00:20:59 +03:00
item->pos.xPos = coll->Setup.OldPosition.x & 0xFFFFFF90 | 0x720;
return;
case WEST:
default:
2021-09-10 00:20:59 +03:00
item->pos.zPos = coll->Setup.OldPosition.z & 0xFFFFFC70 | 0xE0;
return;
}
}
}
2021-09-25 13:00:14 +03:00
void LaraResetGravityStatus(ITEM_INFO* item, COLL_INFO* coll)
{
// This routine cleans gravity status flag and fallspeed, making it
// impossible to perform bugs such as QWOP and flare jump. Found by Troye -- Lwmte, 25.09.2021
if (coll->Middle.Floor <= STEPUP_HEIGHT)
{
item->gravityStatus = false;
item->fallspeed = 0;
}
}
2021-11-07 04:54:48 +03:00
void LaraSnapToHeight(ITEM_INFO* item, COLL_INFO* coll)
{
if (TestLaraSwamp(item) && coll->Middle.Floor > 0)
item->pos.yPos += SWAMP_GRAVITY;
else if (coll->Middle.Floor != NO_HEIGHT)
item->pos.yPos += coll->Middle.Floor;
}
2021-02-03 01:50:59 -03:00
short GetDirOctant(int rot)
{
return abs(rot) >= ANGLE(45) && abs(rot) <= ANGLE(135.0f);
}
2021-02-03 01:50:59 -03:00
void GetLaraDeadlyBounds()
{
BOUNDING_BOX* bounds;
BOUNDING_BOX tbounds;
bounds = GetBoundsAccurate(LaraItem);
phd_RotBoundingBoxNoPersp(&LaraItem->pos, bounds, &tbounds);
DeadlyBounds[0] = LaraItem->pos.xPos + tbounds.X1;
DeadlyBounds[1] = LaraItem->pos.xPos + tbounds.X2;
DeadlyBounds[2] = LaraItem->pos.yPos + tbounds.Y1;
DeadlyBounds[3] = LaraItem->pos.yPos + tbounds.Y2;
DeadlyBounds[4] = LaraItem->pos.zPos + tbounds.Z1;
DeadlyBounds[5] = LaraItem->pos.zPos + tbounds.Z2;
}
void LaraSurfaceCollision(ITEM_INFO* item, COLL_INFO* coll)
{
coll->Setup.ForwardAngle = Lara.moveAngle;
GetCollisionInfo(coll, item, PHD_VECTOR(0, LARA_HEIGHT_SURFSWIM, 0));
ShiftItem(item, coll);
if (coll->CollisionType & (CT_FRONT | CT_TOP | CT_TOP_FRONT | CT_CLAMP) ||
coll->Middle.Floor < 0 && coll->Middle.Slope)
{
item->fallspeed = 0;
item->pos.xPos = coll->Setup.OldPosition.x;
item->pos.yPos = coll->Setup.OldPosition.y;
item->pos.zPos = coll->Setup.OldPosition.z;
}
else if (coll->CollisionType == CT_LEFT)
{
item->pos.yRot += ANGLE(5);
}
else if (coll->CollisionType == CT_RIGHT)
{
item->pos.yRot -= ANGLE(5);
}
if (GetWaterHeight(item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber) - item->pos.yPos > -100)
{
TestLaraWaterStepOut(item, coll);
}
else
{
item->goalAnimState = LS_UNDERWATER_FORWARD;
item->currentAnimState = LS_DIVE;
item->animNumber = LA_ONWATER_DIVE;
item->pos.xRot = -8190;
item->frameNumber = GF(LA_ONWATER_DIVE, 0);
item->fallspeed = 80;
Lara.waterStatus = LW_UNDERWATER;
}
}