2021-09-27 18:18:03 +10:00
|
|
|
#include "framework.h"
|
|
|
|
#include "collide.h"
|
2021-10-18 15:22:38 +11:00
|
|
|
#include "control/control.h"
|
2021-10-16 20:50:16 +11:00
|
|
|
#include "input.h"
|
2021-09-27 18:18:03 +10:00
|
|
|
#include "items.h"
|
|
|
|
#include "level.h"
|
|
|
|
#include "lara.h"
|
2021-10-16 20:50:16 +11:00
|
|
|
#include "lara_tests.h"
|
2021-11-03 21:44:48 +11:00
|
|
|
#include "lara_collide.h"
|
2021-11-07 21:55:38 +11:00
|
|
|
#include "setup.h"
|
2021-10-09 14:39:06 +11:00
|
|
|
|
2021-10-18 20:15:53 +11:00
|
|
|
// -----------------------------
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
// For State Control & Collision
|
|
|
|
// -----------------------------
|
|
|
|
|
2021-10-09 14:39:06 +11:00
|
|
|
// TODO: Some states can't make the most of this function due to missing step up/down animations.
|
|
|
|
// Try implementing leg IK as a substitute to make step animations obsolete. @Sezz 2021.10.09
|
|
|
|
void DoLaraStep(ITEM_INFO* item, COLL_INFO* coll)
|
|
|
|
{
|
2021-12-04 14:01:41 +11:00
|
|
|
if (!TestLaraSwamp(item))
|
2021-10-09 14:39:06 +11:00
|
|
|
{
|
2021-12-04 14:01:41 +11:00
|
|
|
if (TestLaraStepUp(item, coll))
|
2021-10-10 14:03:38 +11:00
|
|
|
{
|
2021-12-04 14:01:41 +11:00
|
|
|
item->goalAnimState = LS_STEP_UP;
|
|
|
|
if (GetChange(item, &g_Level.Anims[item->animNumber]))
|
|
|
|
{
|
|
|
|
item->pos.yPos += coll->Middle.Floor;
|
|
|
|
return;
|
|
|
|
}
|
2021-10-10 14:03:38 +11:00
|
|
|
}
|
2021-12-04 14:01:41 +11:00
|
|
|
else if (TestLaraStepDown(item, coll))
|
2021-10-10 14:03:38 +11:00
|
|
|
{
|
2021-12-04 14:01:41 +11:00
|
|
|
item->goalAnimState = LS_STEP_DOWN;
|
|
|
|
if (GetChange(item, &g_Level.Anims[item->animNumber]))
|
|
|
|
{
|
|
|
|
item->pos.yPos += coll->Middle.Floor;
|
|
|
|
return;
|
|
|
|
}
|
2021-10-10 14:03:38 +11:00
|
|
|
}
|
2021-10-09 14:39:06 +11:00
|
|
|
}
|
|
|
|
|
2021-11-25 21:08:51 +11:00
|
|
|
// Height difference is below threshold for step dispatch OR step animation doesn't exist; translate Lara to new floor height.
|
|
|
|
// TODO: This approach might cause underirable artefacts where an object pushes Lara rapidly up/down a slope or a platform rapidly ascends/descends.
|
2021-12-04 14:01:41 +11:00
|
|
|
int threshold = std::max(abs(item->speed) / 3 * 2, STEP_SIZE / 16);
|
2021-11-28 16:17:03 +11:00
|
|
|
int rate = 50;
|
|
|
|
int sign = std::copysign(1, coll->Middle.Floor);
|
2021-11-04 21:41:23 +11:00
|
|
|
if (coll->Middle.Floor != NO_HEIGHT)
|
2021-10-09 14:39:06 +11:00
|
|
|
{
|
2021-11-07 21:55:38 +11:00
|
|
|
if (TestLaraSwamp(item) &&
|
|
|
|
coll->Middle.Floor > 0)
|
2021-11-04 21:41:23 +11:00
|
|
|
{
|
2021-11-07 21:55:38 +11:00
|
|
|
item->pos.yPos += SWAMP_GRAVITY;
|
2021-11-04 21:41:23 +11:00
|
|
|
}
|
2021-12-01 13:26:28 +11:00
|
|
|
else if (abs(coll->Middle.Floor) > (STEPUP_HEIGHT / 2)) // Outer range.
|
|
|
|
item->pos.yPos += rate * sign;
|
|
|
|
else if (abs(coll->Middle.Floor) <= (STEPUP_HEIGHT / 2) && // Inner range.
|
|
|
|
abs(coll->Middle.Floor) >= threshold)
|
2021-11-07 21:55:38 +11:00
|
|
|
{
|
2021-12-01 19:38:28 +11:00
|
|
|
item->pos.yPos += std::max((int)abs(coll->Middle.Floor / 2.75), threshold) * sign;
|
2021-11-04 21:41:23 +11:00
|
|
|
}
|
|
|
|
else
|
|
|
|
item->pos.yPos += coll->Middle.Floor;
|
2021-10-09 16:56:07 +11:00
|
|
|
}
|
2021-10-09 14:39:06 +11:00
|
|
|
}
|
|
|
|
|
2021-10-16 20:50:16 +11:00
|
|
|
void DoLaraCrawlVault(ITEM_INFO* item, COLL_INFO* coll)
|
2021-09-29 18:35:21 +10:00
|
|
|
{
|
2021-12-02 23:45:19 +11:00
|
|
|
LaraInfo*& info = item->data;
|
|
|
|
|
|
|
|
info->torsoXrot = 0;
|
|
|
|
info->torsoYrot = 0;
|
|
|
|
info->torsoZrot = 0;
|
|
|
|
info->headXrot = 0;
|
|
|
|
info->headYrot = 0;
|
|
|
|
info->headZrot = 0;
|
|
|
|
|
2021-11-12 23:34:55 +11:00
|
|
|
if (TestLaraCrawlExitDownStep(item, coll))
|
2021-09-29 18:35:21 +10:00
|
|
|
{
|
2021-12-01 19:38:28 +11:00
|
|
|
if (TrInput & IN_DUCK && TestLaraCrawlDownStep(item, coll))
|
2021-11-12 23:34:55 +11:00
|
|
|
item->goalAnimState = LS_STEP_DOWN;
|
2021-10-18 00:33:46 +11:00
|
|
|
else [[likely]]
|
2021-11-12 23:34:55 +11:00
|
|
|
item->goalAnimState = LS_CRAWL_EXIT_DOWN_STEP;
|
2021-10-16 20:50:16 +11:00
|
|
|
|
|
|
|
return;
|
2021-09-29 18:35:21 +10:00
|
|
|
}
|
|
|
|
|
2021-11-12 23:34:55 +11:00
|
|
|
if (TestLaraCrawlExitJump(item, coll))
|
2021-10-16 20:50:16 +11:00
|
|
|
{
|
2021-11-12 23:34:55 +11:00
|
|
|
if (TrInput & IN_WALK)
|
|
|
|
item->goalAnimState = LS_CRAWL_EXIT_FLIP;
|
2021-10-18 00:33:46 +11:00
|
|
|
else [[likely]]
|
2021-11-12 23:34:55 +11:00
|
|
|
item->goalAnimState = LS_CRAWL_EXIT_JUMP;
|
2021-10-16 20:50:16 +11:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TestLaraCrawlUpStep(item, coll))
|
|
|
|
{
|
|
|
|
item->goalAnimState = LS_STEP_UP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TestLaraCrawlDownStep(item, coll))
|
|
|
|
{
|
|
|
|
item->goalAnimState = LS_STEP_DOWN;
|
|
|
|
return;
|
|
|
|
}
|
2021-09-29 18:35:21 +10:00
|
|
|
}
|
|
|
|
|
2021-10-18 15:22:38 +11:00
|
|
|
void DoLaraCrawlToHangSnap(ITEM_INFO* item, COLL_INFO* coll)
|
|
|
|
{
|
2021-12-04 12:54:01 +11:00
|
|
|
coll->Setup.ForwardAngle = item->pos.yRot + ANGLE(180.0f);
|
2021-11-03 21:44:48 +11:00
|
|
|
GetCollisionInfo(coll, item);
|
|
|
|
SnapItemToLedge(item, coll);
|
2021-12-04 12:54:01 +11:00
|
|
|
MoveItem(item, item->pos.yRot, -LARA_RAD_CRAWL);
|
2021-11-19 22:48:47 +11:00
|
|
|
item->pos.yRot += ANGLE(180.0f);
|
2021-11-03 21:44:48 +11:00
|
|
|
LaraResetGravityStatus(item, coll);
|
2021-10-18 15:22:38 +11:00
|
|
|
}
|
|
|
|
|
2021-10-22 00:07:24 +11:00
|
|
|
// TODO: Make lean rate proportional to the turn rate, allowing for nicer aesthetics with future analog stick input.
|
2021-11-17 15:59:51 +11:00
|
|
|
void DoLaraLean(ITEM_INFO* item, COLL_INFO* coll, int maxAngle, short rate)
|
2021-10-22 00:07:24 +11:00
|
|
|
{
|
2021-11-30 15:27:08 +11:00
|
|
|
int sign = copysign(1, maxAngle);
|
2021-11-17 15:59:51 +11:00
|
|
|
|
2021-11-30 15:27:08 +11:00
|
|
|
if (coll->CollisionType == CT_LEFT || coll->CollisionType == CT_RIGHT)
|
|
|
|
item->pos.zRot += std::min(rate, (short)(abs((maxAngle * 3) / 5 - item->pos.zRot) / 3)) * sign;
|
|
|
|
else
|
|
|
|
item->pos.zRot += std::min(rate, (short)(abs(maxAngle - item->pos.zRot) / 3)) * sign;
|
2021-10-22 00:07:24 +11:00
|
|
|
}
|
|
|
|
|
2021-11-27 20:35:16 +11:00
|
|
|
void DoLaraCrawlFlex(ITEM_INFO* item, COLL_INFO* coll, short maxAngle, short rate)
|
|
|
|
{
|
|
|
|
LaraInfo*& info = item->data;
|
|
|
|
|
|
|
|
int sign = copysign(1, maxAngle);
|
|
|
|
rate = copysign(rate, maxAngle);
|
|
|
|
|
|
|
|
info->torsoZrot += std::min(abs(rate), abs(maxAngle - info->torsoZrot) / 6) * sign;
|
|
|
|
|
|
|
|
if (!(TrInput & IN_LOOK) &&
|
|
|
|
item->currentAnimState != LS_CRAWL_BACK)
|
|
|
|
{
|
|
|
|
info->headZrot = info->torsoZrot / 2;
|
|
|
|
info->headYrot = info->headZrot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-28 00:01:53 +11:00
|
|
|
void ResetLaraFlex(ITEM_INFO* item, short rate)
|
2021-11-27 23:15:26 +11:00
|
|
|
{
|
|
|
|
LaraInfo*& info = item->data;
|
|
|
|
|
|
|
|
// Reset head.
|
|
|
|
if (abs(info->headXrot) > ANGLE(0.1f))
|
|
|
|
info->headXrot += info->headXrot / -rate;
|
|
|
|
else
|
|
|
|
info->headXrot = 0;
|
|
|
|
|
|
|
|
if (abs(info->headYrot) > ANGLE(0.1f))
|
|
|
|
info->headYrot += info->headYrot / -rate;
|
|
|
|
else
|
|
|
|
info->headYrot = 0;
|
|
|
|
|
|
|
|
if (abs(info->headZrot) > ANGLE(0.1f))
|
|
|
|
info->headZrot += info->headZrot / -rate;
|
|
|
|
else
|
|
|
|
info->headZrot = 0;
|
|
|
|
|
|
|
|
// Reset torso.
|
|
|
|
if (abs(info->torsoXrot) > ANGLE(0.1f))
|
|
|
|
info->torsoXrot += info->torsoXrot / -rate;
|
|
|
|
else
|
|
|
|
info->torsoXrot = 0;
|
|
|
|
|
|
|
|
if (abs(info->torsoYrot) > ANGLE(0.1f))
|
|
|
|
info->torsoYrot += info->torsoYrot / -rate;
|
|
|
|
else
|
|
|
|
info->torsoYrot = 0;
|
|
|
|
|
|
|
|
if (abs(info->torsoZrot) > ANGLE(0.1f))
|
|
|
|
info->torsoZrot += info->torsoZrot / -rate;
|
|
|
|
else
|
|
|
|
info->torsoZrot = 0;
|
|
|
|
}
|
|
|
|
|
2021-09-27 18:18:03 +10:00
|
|
|
void SetLaraFallState(ITEM_INFO* item)
|
|
|
|
{
|
2021-11-11 01:02:50 +11:00
|
|
|
SetAnimation(item, LA_FALL_START);
|
2021-09-27 18:18:03 +10:00
|
|
|
item->fallspeed = 0;
|
|
|
|
item->gravityStatus = true;
|
|
|
|
}
|
|
|
|
|
2021-10-14 19:58:29 +11:00
|
|
|
void SetLaraFallBackState(ITEM_INFO* item)
|
|
|
|
{
|
2021-11-11 01:02:50 +11:00
|
|
|
SetAnimation(item, LA_FALL_BACK);
|
2021-10-14 19:58:29 +11:00
|
|
|
item->fallspeed = 0;
|
|
|
|
item->gravityStatus = true;
|
|
|
|
}
|