TombEngine/TR5Main/Game/laraswim.cpp

855 lines
18 KiB
C++
Raw Normal View History

2019-11-21 07:43:34 +01:00
#include "laraswim.h"
#include "..\Global\global.h"
2019-12-01 08:13:19 +01:00
2019-11-21 07:43:34 +01:00
#include "control.h"
#include "camera.h"
#include "collide.h"
#include "items.h"
#include "box.h"
#include "Lara.h"
#include "larasurf.h"
2019-12-01 08:13:19 +01:00
#include "effects.h"
#include "effect2.h"
#include "larafire.h"
#include "laramisc.h"
2019-12-01 08:13:19 +01:00
extern LaraExtraInfo g_LaraExtra;
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
SUBSUIT_INFO Subsuit;
byte SubHitCount = 0;
2019-11-21 07:43:34 +01:00
void LaraWaterCurrent(COLL_INFO* coll)//4CD34, 4D198
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
// CHECK TOMB21 code
if (Lara.currentActive)
{
OBJECT_VECTOR* sink = &Cameras[Lara.currentActive - 1];
2019-12-02 09:11:21 +01:00
short angle = mGetAngle(sink->x, sink->z, LaraItem->pos.xPos, LaraItem->pos.zPos);
2019-12-01 08:13:19 +01:00
Lara.currentXvel += ((sink->data * SIN(angle - ANGLE(90)) >> 2) - Lara.currentXvel) >> 4;
Lara.currentZvel += ((sink->data * COS(angle - ANGLE(90)) >> 2) - Lara.currentZvel) >> 4; // ((v12 * rcossin_tbl[2 * v13 + 1] >> 2) - Lara.currentZvel) >> 4;
LaraItem->pos.yPos += (sink->y - LaraItem->pos.yPos) >> 4;
}
else
{
2019-12-02 09:11:21 +01:00
int shift = 0;
2019-12-01 08:13:19 +01:00
if (abs(Lara.currentXvel) <= 16)
shift = (abs(Lara.currentXvel) > 8) + 2;
else
shift = 4;
Lara.currentXvel -= Lara.currentXvel >> shift;
if (abs(Lara.currentXvel) < 4)
Lara.currentXvel = 0;
if (abs(Lara.currentZvel) <= 16)
shift = (abs(Lara.currentZvel) > 8) + 2;
else
shift = 4;
Lara.currentZvel -= Lara.currentZvel >> shift;
if (abs(Lara.currentZvel) < 4)
Lara.currentZvel = 0;
if (!Lara.currentXvel && !Lara.currentZvel)
return;
}
LaraItem->pos.xPos += Lara.currentXvel >> 8;
LaraItem->pos.zPos += Lara.currentZvel >> 8;
Lara.currentActive = 0;
coll->facing = ATAN(LaraItem->pos.zPos - coll->old.z, LaraItem->pos.xPos - coll->old.x);
GetCollisionInfo(coll, LaraItem->pos.xPos, LaraItem->pos.yPos + 200, LaraItem->pos.zPos, LaraItem->roomNumber, 400);
if (coll->collType == CT_FRONT)
{
if (LaraItem->pos.xRot > ANGLE(35))
LaraItem->pos.xRot += ANGLE(1);
else if (LaraItem->pos.xRot < -ANGLE(35))
LaraItem->pos.xRot -= ANGLE(1);
}
else
{
if (coll->collType == CT_TOP)
{
LaraItem->pos.xRot -= ANGLE(1);
}
else if (coll->collType != CT_TOP_FRONT)
{
if (coll->collType == CT_LEFT)
{
LaraItem->pos.yRot += ANGLE(5);
}
else if (coll->collType == CT_RIGHT)
{
LaraItem->pos.yRot -= ANGLE(5);
}
}
}
LaraItem->fallspeed = 0;
if (coll->midFloor < 0 && coll->midFloor != NO_HEIGHT)
LaraItem->pos.yPos += coll->midFloor;
ShiftItem(LaraItem, coll);
coll->old.x = LaraItem->pos.xPos;
coll->old.y = LaraItem->pos.yPos;
coll->old.z = LaraItem->pos.zPos;
2019-11-21 07:43:34 +01:00
}
int GetWaterDepth(int x, int y, int z, short roomNumber)//4CA38, 4CE9C
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
FLOOR_INFO* floor;
ROOM_INFO* r = &Rooms[roomNumber];
2019-12-02 09:11:21 +01:00
short roomIndex = NO_ROOM;
2019-12-01 08:13:19 +01:00
do
{
2019-12-02 09:11:21 +01:00
int zFloor = (z - r->z) >> WALL_SHIFT;
int xFloor = (x - r->x) >> WALL_SHIFT;
2019-12-01 08:13:19 +01:00
if (zFloor <= 0)
{
zFloor = 0;
if (xFloor < 1)
xFloor = 1;
else if (xFloor > r->ySize - 2)
xFloor = r->ySize - 2;
}
else if (zFloor >= r->xSize - 1)
{
zFloor = r->xSize - 1;
if (xFloor < 1)
xFloor = 1;
else if (xFloor > r->ySize - 2)
xFloor = r->ySize - 2;
}
else if (xFloor < 0)
xFloor = 0;
else if (xFloor >= r->ySize)
xFloor = r->ySize - 1;
floor = &r->floor[zFloor + xFloor * r->xSize];
roomIndex = GetDoor(floor);
if (roomIndex != NO_ROOM)
{
roomNumber = roomIndex;
r = &Rooms[roomIndex];
}
} while (roomIndex != NO_ROOM);
if (r->flags & ENV_FLAG_WATER)
{
while (floor->skyRoom != NO_ROOM)
{
r = &Rooms[floor->skyRoom];
if (!(r->flags & ENV_FLAG_WATER))
{
2019-12-02 09:11:21 +01:00
int wh = floor->ceiling << 8;
2019-12-01 08:13:19 +01:00
floor = GetFloor(x, y, z, &roomNumber);
return (GetFloorHeight(floor, x, y, z) - wh);
}
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->x);
2019-12-01 08:13:19 +01:00
}
return 0x7FFF;
2019-12-01 08:13:19 +01:00
}
else
{
while (floor->pitRoom != NO_ROOM)
{
r = &Rooms[floor->pitRoom];
if (r->flags & ENV_FLAG_WATER)
{
2019-12-02 09:11:21 +01:00
int wh = floor->floor << 8;
2019-12-01 08:13:19 +01:00
floor = GetFloor(x, y, z, &roomNumber);
return (GetFloorHeight(floor, x, y, z) - wh);
}
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->x);
2019-12-01 08:13:19 +01:00
}
return NO_HEIGHT;
}
2019-11-21 07:43:34 +01:00
}
void lara_col_waterroll(ITEM_INFO* item, COLL_INFO* coll)//4CA18(<), 4CE7C(<) (F)
2019-11-21 07:43:34 +01:00
{
LaraSwimCollision(item, coll);
}
void lara_col_uwdeath(ITEM_INFO* item, COLL_INFO* coll)//4C980(<), 4CDE4(<) (F)
2019-11-21 07:43:34 +01:00
{
item->hitPoints = -1;
Lara.air = -1;
Lara.gunStatus = LG_HANDS_BUSY;
2019-12-02 09:11:21 +01:00
int wh = GetWaterHeight(item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber);
2019-12-01 08:13:19 +01:00
if (wh != NO_HEIGHT)
2019-11-21 07:43:34 +01:00
{
if (wh < item->pos.yPos - 100)
item->pos.yPos -= 5;
}
LaraSwimCollision(item, coll);
}
void lara_col_dive(ITEM_INFO* item, COLL_INFO* coll)//4C960(<), 4CDC4(<) (F)
2019-11-21 07:43:34 +01:00
{
LaraSwimCollision(item, coll);
}
void lara_col_tread(ITEM_INFO* item, COLL_INFO* coll)//4C940(<), 4CDA4(<) (F)
2019-11-21 07:43:34 +01:00
{
LaraSwimCollision(item, coll);
}
void lara_col_glide(ITEM_INFO* item, COLL_INFO* coll)//4C920(<), 4CD84(<) (F)
2019-11-21 07:43:34 +01:00
{
LaraSwimCollision(item, coll);
}
void lara_col_swim(ITEM_INFO* item, COLL_INFO* coll)//4C900(<), 4CD64(<) (F)
2019-11-21 07:43:34 +01:00
{
LaraSwimCollision(item, coll);
}
void lara_as_waterroll(ITEM_INFO* item, COLL_INFO* coll)//4C8F8(<), 4CD5C(<) (F)
2019-11-21 07:43:34 +01:00
{
item->fallspeed = 0;
}
void lara_as_uwdeath(ITEM_INFO* item, COLL_INFO* coll)//4C884(<), 4CCE8(<) (F)
2019-11-21 07:43:34 +01:00
{
Lara.look = 0;
item->fallspeed -= 8;
if (item->fallspeed <= 0)
item->fallspeed = 0;
2019-12-01 08:13:19 +01:00
if (item->pos.xRot < -ANGLE(2) || item->pos.xRot > ANGLE(2))
2019-11-21 07:43:34 +01:00
{
if (item->pos.xRot >= 0)
item->pos.xRot -= ANGLE(2);
else
item->pos.xRot += ANGLE(2);
}
else
{
item->pos.xRot = 0;
}
}
void lara_as_dive(ITEM_INFO* item, COLL_INFO* coll)//4C854, 4CCB8 (F)
2019-11-21 07:43:34 +01:00
{
if (TrInput & IN_FORWARD)
{
item->pos.xRot -= ANGLE(1);
}
}
void lara_as_tread(ITEM_INFO* item, COLL_INFO* coll)//4C730, 4CB94 (F)
2019-11-21 07:43:34 +01:00
{
if (item->hitPoints <= 0)
{
item->goalAnimState = STATE_LARA_WATER_DEATH;
return;
}
if (TrInput & IN_ROLL && LaraDrawType != LARA_DIVESUIT)
{
item->currentAnimState = STATE_LARA_UNDERWATER_TURNAROUND;
item->animNumber = ANIMATION_LARA_UNDERWATER_ROLL_BEGIN;
2019-12-01 08:13:19 +01:00
item->frameNumber = Anims[item->animNumber].frameBase;
2019-11-21 07:43:34 +01:00
}
else
{
if (TrInput & IN_LOOK)
LookUpDown();
if (LaraDrawType == LARA_DIVESUIT)
SwimTurnSubsuit(item);
else
SwimTurn(item);
if (TrInput & IN_JUMP)
item->goalAnimState = STATE_LARA_UNDERWATER_FORWARD;
item->fallspeed -= 6;
if (item->fallspeed < 0)
item->fallspeed = 0;
if (Lara.gunStatus == LG_HANDS_BUSY)
Lara.gunStatus = LG_NO_ARMS;
}
}
void lara_as_glide(ITEM_INFO* item, COLL_INFO* coll)//4C634(<), 4CA98(<) (F)
2019-11-21 07:43:34 +01:00
{
if (item->hitPoints <= 0)
{
item->goalAnimState = STATE_LARA_WATER_DEATH;
return;
}
if (TrInput & IN_ROLL)
{
if (LaraDrawType != LARA_DIVESUIT)
{
item->currentAnimState = STATE_LARA_UNDERWATER_TURNAROUND;
item->animNumber = ANIMATION_LARA_UNDERWATER_ROLL_BEGIN;
2019-12-01 08:13:19 +01:00
item->frameNumber = Anims[item->animNumber].frameBase;
2019-11-21 07:43:34 +01:00
return;
}
}
else if (LaraDrawType != LARA_DIVESUIT)
{
SwimTurn(item);
}
else
{
SwimTurnSubsuit(item);
}
if (TrInput & IN_JUMP)
item->goalAnimState = STATE_LARA_UNDERWATER_FORWARD;
item->fallspeed -= 6;
if (item->fallspeed < 0)
item->fallspeed = 0;
if (item->fallspeed <= 133)
item->goalAnimState = STATE_LARA_UNDERWATER_STOP;
}
void lara_as_swim(ITEM_INFO* item, COLL_INFO* coll)//4C548(<), 4C9AC(<) (F)
2019-11-21 07:43:34 +01:00
{
if (item->hitPoints <= 0)
{
item->goalAnimState = STATE_LARA_WATER_DEATH;
return;
}
if (TrInput & IN_ROLL)
{
if (LaraDrawType != LARA_DIVESUIT)
{
item->currentAnimState = STATE_LARA_UNDERWATER_TURNAROUND;
item->animNumber = ANIMATION_LARA_UNDERWATER_ROLL_BEGIN;
2019-12-01 08:13:19 +01:00
item->frameNumber = Anims[item->animNumber].frameBase;
2019-11-21 07:43:34 +01:00
return;
}
}
else if (LaraDrawType != LARA_DIVESUIT)
{
SwimTurn(item);
}
else
{
SwimTurnSubsuit(item);
}
item->fallspeed += 8;
if (item->fallspeed > 200)
item->fallspeed = 200;
if (!(TrInput & IN_JUMP))
item->goalAnimState = STATE_LARA_UNDERWATER_INERTIA;
}
void lara_as_swimcheat(ITEM_INFO* item, COLL_INFO* coll)//4C3A8, 4C80C (F)
2019-11-21 07:43:34 +01:00
{
if (TrInput & IN_FORWARD)
{
item->pos.xRot -= ANGLE(3);
}
else if (TrInput & IN_BACK)
{
item->pos.xRot += ANGLE(3);
}
if (TrInput & IN_LEFT)
{
Lara.turnRate -= 613;
2019-12-01 08:13:19 +01:00
if (Lara.turnRate < -ANGLE(6))
Lara.turnRate = -ANGLE(6);
2019-11-21 07:43:34 +01:00
}
else if (TrInput & IN_RIGHT)
{
Lara.turnRate += 613;
if (Lara.turnRate > ANGLE(6))
Lara.turnRate = ANGLE(6);
}
if (TrInput & IN_ACTION)
{
2019-12-01 08:13:19 +01:00
TriggerDynamicLight(item->pos.xPos, item->pos.yPos, item->pos.zPos, 31, 255, 255, 255);
2019-11-21 07:43:34 +01:00
}
if (TrInput & IN_OPTION)
{
2019-12-01 08:13:19 +01:00
Lara.turnRate = -ANGLE(12);
2019-11-21 07:43:34 +01:00
}
if (TrInput & IN_JUMP)
{
item->fallspeed += 16;
if (item->fallspeed > 400)
item->fallspeed = 400;
}
else
{
if (item->fallspeed >= 8)
item->fallspeed -= item->fallspeed >> 3;
else
item->fallspeed = 0;
}
}
2019-12-01 08:13:19 +01:00
// CHECK all subsuit states
void LaraUnderWater(ITEM_INFO* item, COLL_INFO* coll)//4BFB4, 4C418 (F)
2019-11-21 07:43:34 +01:00
{
coll->badPos = 32512;
coll->badNeg = -400;
coll->badCeiling = 400;
coll->old.x = item->pos.xPos;
coll->old.y = item->pos.yPos;
coll->old.z = item->pos.zPos;
coll->slopesAreWalls = 0;
coll->slopesArePits = 0;
coll->lavaIsPit = 0;
2019-12-01 08:13:19 +01:00
coll->enableBaddiePush = true;
2019-11-21 07:43:34 +01:00
coll->enableSpaz = false;
coll->radius = 300;
2019-12-12 22:06:57 +01:00
coll->trigger = NULL;
2019-11-21 07:43:34 +01:00
if (TrInput & IN_LOOK && Lara.look)
LookLeftRight();
else
ResetLook();
2019-12-01 08:13:19 +01:00
Lara.look = true;
2019-11-21 07:43:34 +01:00
lara_control_routines[item->currentAnimState](item, coll);
if (LaraDrawType == LARA_DIVESUIT)
{
2019-12-01 08:13:19 +01:00
if (Lara.turnRate < -(ANGLE(1) / 2))
{
Lara.turnRate += (ANGLE(1) / 2);
}
else if (Lara.turnRate > (ANGLE(1) / 2))
{
Lara.turnRate -= (ANGLE(1) / 2);
}
else
{
Lara.turnRate = 0;
}
}
else if (Lara.turnRate < -ANGLE(2))
{
Lara.turnRate += ANGLE(2);
}
else if (Lara.turnRate > ANGLE(2))
{
Lara.turnRate -= ANGLE(2);
2019-11-21 07:43:34 +01:00
}
else
{
2019-12-01 08:13:19 +01:00
Lara.turnRate = 0;
2019-11-21 07:43:34 +01:00
}
item->pos.yRot += Lara.turnRate;
if (LaraDrawType == LARA_DIVESUIT)
UpdateSubsuitAngles();
2019-12-01 08:13:19 +01:00
if (item->pos.zRot < -ANGLE(2))
item->pos.zRot += ANGLE(2);
else if (item->pos.zRot > ANGLE(2))
item->pos.zRot -= ANGLE(2);
else
item->pos.zRot = 0;
if (item->pos.xRot < -ANGLE(85))
item->pos.xRot = -ANGLE(85);
2019-12-01 08:13:19 +01:00
else if (item->pos.xRot > ANGLE(85))
item->pos.xRot = ANGLE(85);
2019-11-21 07:43:34 +01:00
if (LaraDrawType == LARA_DIVESUIT)
{
2019-12-01 08:13:19 +01:00
if (item->pos.zRot > ANGLE(44))
item->pos.zRot = ANGLE(44);
else if (item->pos.zRot < -ANGLE(44))
item->pos.zRot = -ANGLE(44);
2019-11-21 07:43:34 +01:00
}
else
{
2019-12-01 08:13:19 +01:00
if (item->pos.zRot > ANGLE(22))
item->pos.zRot = ANGLE(22);
else if (item->pos.zRot < -ANGLE(22))
item->pos.zRot = -ANGLE(22);
2019-11-21 07:43:34 +01:00
}
if (Lara.currentActive && Lara.waterStatus != LW_FLYCHEAT)
LaraWaterCurrent(coll);
AnimateLara(item);
2019-12-01 08:13:19 +01:00
item->pos.xPos += COS(item->pos.xRot) * (item->fallspeed * SIN(item->pos.yRot) >> (W2V_SHIFT + 2)) >> W2V_SHIFT;
item->pos.yPos -= item->fallspeed * SIN(item->pos.xRot) >> (W2V_SHIFT + 2);
2019-12-01 08:13:19 +01:00
item->pos.zPos += COS(item->pos.xRot) * (item->fallspeed * COS(item->pos.yRot) >> (W2V_SHIFT + 2)) >> W2V_SHIFT;
2019-11-21 07:43:34 +01:00
LaraBaddieCollision(item, coll);
lara_collision_routines[item->currentAnimState](item, coll);
UpdateLaraRoom(item, 0);
LaraGun();
TestTriggers(coll->trigger, 0, 0);
}
void UpdateSubsuitAngles()//4BD20, 4C184 (F)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
if (Subsuit.YVel != 0)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
LaraItem->pos.yPos += Subsuit.YVel / 4;
Subsuit.YVel = ceil(0.9375 * Subsuit.YVel - 1); // YVel * (15/16)
2019-11-21 07:43:34 +01:00
}
2019-12-01 08:13:19 +01:00
Subsuit.Vel[0] = Subsuit.Vel[1] = -4 * LaraItem->fallspeed;
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot >= Subsuit.dXRot)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot > Subsuit.dXRot)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot > 0 && Subsuit.dXRot < 0)
Subsuit.XRot = ceil(0.75 * Subsuit.XRot);
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
Subsuit.XRot -= ANGLE(2);
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot < Subsuit.dXRot)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
Subsuit.XRot = Subsuit.dXRot;
2019-11-21 07:43:34 +01:00
}
}
}
else
{
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot < 0 && Subsuit.dXRot > 0)
Subsuit.XRot = ceil(0.75 * Subsuit.XRot);
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
Subsuit.XRot += ANGLE(2);
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (Subsuit.XRot > Subsuit.dXRot)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
Subsuit.XRot = Subsuit.dXRot;
2019-11-21 07:43:34 +01:00
}
}
2019-12-01 08:13:19 +01:00
if (Subsuit.dXRot != 0)
2019-11-21 07:43:34 +01:00
{
2019-12-02 09:11:21 +01:00
short rot = Subsuit.dXRot >> 3;
2019-12-01 08:13:19 +01:00
if (rot < -ANGLE(2))
rot = -ANGLE(2);
else if (rot > ANGLE(2))
rot = ANGLE(2);
LaraItem->pos.xRot += rot;
2019-11-21 07:43:34 +01:00
}
2019-12-01 08:13:19 +01:00
Subsuit.Vel[0] += abs(Subsuit.XRot >> 3);
Subsuit.Vel[1] += abs(Subsuit.XRot >> 3);
2019-11-21 07:43:34 +01:00
if (Lara.turnRate > 0)
{
2019-12-01 08:13:19 +01:00
Subsuit.Vel[0] += 2 * abs(Lara.turnRate);
2019-11-21 07:43:34 +01:00
}
else if (Lara.turnRate < 0)
{
2019-12-01 08:13:19 +01:00
Subsuit.Vel[1] += 2 * abs(Lara.turnRate);
2019-11-21 07:43:34 +01:00
}
2019-12-01 08:13:19 +01:00
if (Subsuit.Vel[0] > 1536)
Subsuit.Vel[0] = 1536;
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (Subsuit.Vel[1] > 1536)
Subsuit.Vel[1] = 1536;
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (Subsuit.Vel[0] != 0 || Subsuit.Vel[1] != 0)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
SoundEffect(SFX_LARA_UNDERWATER_ENGINE, &LaraItem->pos, (((Subsuit.Vel[0] + Subsuit.Vel[1]) * 4) & 0x1F00) + 10);
2019-11-21 07:43:34 +01:00
}
}
void SwimTurnSubsuit(ITEM_INFO* item)//4BBDC, 4C040 (F)
2019-11-21 07:43:34 +01:00
{
if (item->pos.yPos < 14080)
2019-12-01 08:13:19 +01:00
Subsuit.YVel += (14080 - item->pos.yPos) >> 4;
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (TrInput & IN_FORWARD && item->pos.xRot > -ANGLE(85))
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
Subsuit.dXRot = -ANGLE(45);
2019-11-21 07:43:34 +01:00
}
else if (TrInput & IN_BACK && item->pos.xRot < ANGLE(85))
{
2019-12-01 08:13:19 +01:00
Subsuit.dXRot = ANGLE(45);
2019-11-21 07:43:34 +01:00
}
else
{
2019-12-01 08:13:19 +01:00
Subsuit.dXRot = 0;
2019-11-21 07:43:34 +01:00
}
if (TrInput & IN_LEFT)
{
Lara.turnRate -= 136;
2019-12-01 08:13:19 +01:00
if (Lara.turnRate < -ANGLE(6))
Lara.turnRate = -ANGLE(6);
2019-11-21 07:43:34 +01:00
item->pos.zRot -= ANGLE(3);
}
else if (TrInput & IN_RIGHT)
{
Lara.turnRate += 136;
if (Lara.turnRate > ANGLE(6))
Lara.turnRate = ANGLE(6);
item->pos.zRot += ANGLE(3);
}
}
void SwimTurn(ITEM_INFO* item)//4BAF4(<), 4BF58(<) (F)
2019-11-21 07:43:34 +01:00
{
if (TrInput & IN_FORWARD)
{
item->pos.xRot -= ANGLE(2);
}
else if (TrInput & IN_BACK)
{
item->pos.xRot += ANGLE(2);
}
if (TrInput & IN_LEFT)
{
Lara.turnRate -= 409;
2019-12-01 08:13:19 +01:00
if (Lara.turnRate < -ANGLE(6))
Lara.turnRate = -ANGLE(6);
2019-11-21 07:43:34 +01:00
item->pos.zRot -= ANGLE(3);
}
else if (TrInput & IN_RIGHT)
{
Lara.turnRate += 409;
if (Lara.turnRate > ANGLE(6))
Lara.turnRate = ANGLE(6);
item->pos.zRot += ANGLE(3);
}
}
void LaraSwimCollision(ITEM_INFO* item, COLL_INFO* coll)//4B608, 4BA6C
2019-11-21 07:43:34 +01:00
{
2019-12-02 09:11:21 +01:00
int oldX = item->pos.xPos;
int oldY = item->pos.yPos;
int oldZ = item->pos.zPos;
short oldXrot = item->pos.xRot;
short oldYrot = item->pos.yRot;
short oldZrot = item->pos.zRot;
2019-12-01 08:13:19 +01:00
if (item->pos.xRot < -ANGLE(90) || item->pos.xRot > ANGLE(90))
{
Lara.moveAngle = item->pos.yRot - ANGLE(180);
coll->facing = item->pos.yRot - ANGLE(180);
}
else
{
Lara.moveAngle = item->pos.yRot;
coll->facing = item->pos.yRot;
}
2019-12-02 09:11:21 +01:00
short height = 762 * SIN(item->pos.xRot) >> W2V_SHIFT;
2019-12-12 22:06:57 +01:00
height = abs(height);
2019-12-01 08:13:19 +01:00
if (height < ((LaraDrawType == LARA_DIVESUIT) << 6) + 200)
height = ((LaraDrawType == LARA_DIVESUIT) << 6) + 200;
coll->badNeg = -64;
COLL_INFO c1;
COLL_INFO c2;
memcpy(&c1, coll, sizeof(COLL_INFO));
2019-12-12 22:06:57 +01:00
memcpy(&c2, coll, sizeof(COLL_INFO) - 2);
2019-12-01 08:13:19 +01:00
GetCollisionInfo(coll, item->pos.xPos, height / 2 + item->pos.yPos, item->pos.zPos, item->roomNumber, height);
c1.facing += ANGLE(45);
GetCollisionInfo(&c1, item->pos.xPos, height / 2 + item->pos.yPos, item->pos.zPos, item->roomNumber, height);
c2.facing -= ANGLE(45);
GetCollisionInfo(&c2, item->pos.xPos, height / 2 + item->pos.yPos, item->pos.zPos, item->roomNumber, height);
ShiftItem(item, coll);
2019-12-02 09:11:21 +01:00
int flag = 0;
2019-12-01 08:13:19 +01:00
switch (coll->collType)
{
case CT_FRONT:
if (item->pos.xRot <= ANGLE(25))
{
if (item->pos.xRot >= -ANGLE(25))
{
if (item->pos.xRot > ANGLE(5))
item->pos.xRot += ANGLE(1) / 2;
else if (item->pos.xRot < -ANGLE(5))
item->pos.xRot -= ANGLE(1) / 2;
else if (item->pos.xRot > 0)
item->pos.xRot += 45;
else if (item->pos.xRot < 0)
item->pos.xRot -= 45;
else
{
item->fallspeed = 0;
flag = 1;
}
}
else
{
item->pos.xRot -= ANGLE(1);
flag = 1;
}
}
else
{
item->pos.xRot += ANGLE(1);
flag = 1;
}
if (c1.collType == CT_LEFT)
{
item->pos.yRot += ANGLE(2);
}
else if (c1.collType == CT_RIGHT)
{
item->pos.yRot -= ANGLE(2);
}
else if (c2.collType == CT_LEFT)
{
item->pos.yRot += ANGLE(2);
}
else if (c2.collType == CT_RIGHT)
{
item->pos.yRot -= ANGLE(2);
}
break;
2019-12-12 22:06:57 +01:00
2019-12-01 08:13:19 +01:00
case CT_TOP:
2019-12-12 22:06:57 +01:00
if (item->pos.xRot >= -8190)
2019-12-01 08:13:19 +01:00
{
flag = 1;
item->pos.xRot -= ANGLE(1);
}
break;
2019-12-12 22:06:57 +01:00
2019-12-01 08:13:19 +01:00
case CT_TOP_FRONT:
item->fallspeed = 0;
flag = 1;
break;
2019-12-12 22:06:57 +01:00
2019-12-01 08:13:19 +01:00
case CT_LEFT:
item->pos.yRot += ANGLE(2);
flag = 1;
break;
2019-12-12 22:06:57 +01:00
2019-12-01 08:13:19 +01:00
case CT_RIGHT:
item->pos.yRot -= ANGLE(2);
flag = 1;
break;
2019-12-12 22:06:57 +01:00
2019-12-01 08:13:19 +01:00
case CT_CLAMP:
flag = 2;
item->pos.xPos = coll->old.x;
item->pos.yPos = coll->old.y;
item->pos.zPos = coll->old.z;
item->fallspeed = 0;
break;
}
if (coll->midFloor < 0 && coll->midFloor != NO_HEIGHT)
{
flag = 1;
item->pos.xRot += ANGLE(1);
item->pos.yPos += coll->midFloor;
}
if (oldX == item->pos.xPos
&& oldY == item->pos.yPos
&& oldZ == item->pos.zPos
2019-12-12 22:06:57 +01:00
&& oldXrot == item->pos.xRot
&& oldYrot == item->pos.yRot
/*|| (LOBYTE(v21) = byte_51CEE4) != 0*/
|| flag != 1)
2019-12-01 08:13:19 +01:00
{
2019-12-12 22:06:57 +01:00
if (flag == 2)
2019-12-01 08:13:19 +01:00
return;
}
2019-12-12 22:06:57 +01:00
else if (item->fallspeed > 100)
2019-12-01 08:13:19 +01:00
{
if (LaraDrawType == 5)
{
SoundEffect(SFX_SWIMSUIT_METAL_CLASH, &LaraItem->pos, ((2 * GetRandomControl() + 0x8000) << 8) | 6);
}
// CHECK related to cutscene?
//byte_51CEE4 = 30;
if (Lara.anxiety < 96)
{
Lara.anxiety += 16;
}
}
if (Lara.waterStatus != LW_FLYCHEAT && g_LaraExtra.ExtraAnim == -1)
LaraTestWaterDepth(item, coll);
2019-11-21 07:43:34 +01:00
}
void LaraTestWaterDepth(ITEM_INFO* item, COLL_INFO* coll)//4B4F8(<), 4B95C(<) (F)
2019-11-21 07:43:34 +01:00
{
2019-12-02 09:11:21 +01:00
short roomNumber = item->roomNumber;
2019-12-01 08:13:19 +01:00
FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &roomNumber);
2019-12-02 09:11:21 +01:00
int wd = GetWaterDepth(item->pos.xPos, item->pos.yPos, item->pos.zPos, roomNumber);
2019-11-21 07:43:34 +01:00
2019-12-01 08:13:19 +01:00
if (wd == NO_HEIGHT)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
item->fallspeed = 0;
2019-11-21 07:43:34 +01:00
item->pos.xPos = coll->old.x;
item->pos.yPos = coll->old.y;
item->pos.zPos = coll->old.z;
}
2019-12-01 08:13:19 +01:00
else if (wd <= 512)
2019-11-21 07:43:34 +01:00
{
2019-12-01 08:13:19 +01:00
item->animNumber = ANIMATION_LARA_UNDERWATER_TO_WADE;
item->currentAnimState = STATE_LARA_ONWATER_EXIT;
item->goalAnimState = STATE_LARA_STOP;
2019-11-21 07:43:34 +01:00
item->pos.zRot = 0;
item->pos.xRot = 0;
item->speed = 0;
item->fallspeed = 0;
2019-12-01 08:13:19 +01:00
item->gravityStatus = false;
item->frameNumber = Anims[item->animNumber].frameBase;
Lara.waterStatus = LW_WADE;
item->pos.yPos = GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos);
}
2019-11-21 07:43:34 +01:00
}