2018-08-19 09:46:58 +02:00
|
|
|
#include "collide.h"
|
2018-11-19 23:29:30 +01:00
|
|
|
#include "draw.h"
|
2019-11-21 07:43:34 +01:00
|
|
|
#include "Lara.h"
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
#include "..\Global\global.h"
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
#include <stdio.h>
|
2019-12-04 18:51:23 +01:00
|
|
|
#include "items.h"
|
2019-12-07 08:36:13 +01:00
|
|
|
#include "effects.h"
|
2019-12-08 07:38:22 +01:00
|
|
|
#include "sphere.h"
|
2019-12-17 17:37:53 +01:00
|
|
|
#include "misc.h"
|
2020-04-01 13:09:14 +02:00
|
|
|
#include "../Specific/setup.h"
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
char LM[] = {
|
2019-12-07 08:36:13 +01:00
|
|
|
LJ_HIPS,
|
|
|
|
LJ_LTHIGH,
|
|
|
|
LJ_LSHIN,
|
|
|
|
LJ_LFOOT,
|
|
|
|
LJ_RTHIGH,
|
|
|
|
LJ_RSHIN,
|
|
|
|
LJ_RFOOT,
|
|
|
|
LJ_TORSO,
|
|
|
|
LJ_RINARM,
|
|
|
|
LJ_ROUTARM,
|
|
|
|
LJ_RHAND,
|
|
|
|
LJ_LINARM,
|
|
|
|
LJ_LOUTARM,
|
|
|
|
LJ_LHAND,
|
|
|
|
LJ_HEAD,
|
|
|
|
};
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-12-08 07:38:22 +01:00
|
|
|
int XFront, ZFront;
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
int CollideStaticObjects(COLL_INFO* coll, int x, int y, int z, short roomNumber, int hite)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
ROOM_INFO* room;
|
|
|
|
MESH_INFO* mesh;
|
|
|
|
short roomList[255];
|
|
|
|
short numRooms = 0;
|
|
|
|
int xMin = 0, xMax = 0, zMin = 0, zMax = 0;
|
|
|
|
int inXmin, inXmax, inZmin, inZmax, inYmin;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
coll->hitStatic = false;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
inXmin = x - coll->radius;
|
|
|
|
inXmax = x + coll->radius;
|
|
|
|
inZmin = z - coll->radius;
|
|
|
|
inZmax = z + coll->radius;
|
|
|
|
inYmin = y - hite;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
// Collect all the rooms where to check
|
|
|
|
GetRoomList(roomNumber, roomList, &numRooms);
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
if (numRooms <= 0)
|
2019-12-17 17:37:53 +01:00
|
|
|
return 0;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
for (int i = 0; i < numRooms; i++)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
room = &Rooms[roomList[i]];
|
|
|
|
mesh = room->mesh;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
for (int j = room->numMeshes; j > 0; j--, mesh++)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
STATIC_INFO* sInfo = &StaticObjects[mesh->staticNumber];
|
|
|
|
if ((sInfo->flags & 1)) // No collision
|
|
|
|
continue;
|
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int yMin = mesh->y + sInfo->xMinc;
|
|
|
|
int yMax = mesh->y + sInfo->yMaxc;
|
|
|
|
short yRot = mesh->yRot;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-12-17 18:46:17 +01:00
|
|
|
if (yRot == ANGLE(180))
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
xMin = mesh->x - sInfo->xMaxc;
|
|
|
|
xMax = mesh->x - sInfo->xMinc;
|
|
|
|
zMin = mesh->z - sInfo->zMaxc;
|
|
|
|
zMax = mesh->z - sInfo->zMinc;
|
|
|
|
}
|
2019-12-17 17:37:53 +01:00
|
|
|
else if (yRot == -ANGLE(90))
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
xMin = mesh->x - sInfo->zMaxc;
|
|
|
|
xMax = mesh->x - sInfo->zMinc;
|
|
|
|
zMin = mesh->z + sInfo->xMinc;
|
|
|
|
zMax = mesh->z + sInfo->xMaxc;
|
|
|
|
}
|
2019-12-17 17:37:53 +01:00
|
|
|
else if (yRot == ANGLE(90))
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
xMin = mesh->x + sInfo->zMinc;
|
|
|
|
xMax = mesh->x + sInfo->zMaxc;
|
|
|
|
zMin = mesh->z - sInfo->xMaxc;
|
|
|
|
zMax = mesh->z - sInfo->xMinc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xMin = mesh->x + sInfo->xMinc;
|
|
|
|
xMax = mesh->x + sInfo->xMaxc;
|
|
|
|
zMin = mesh->z + sInfo->zMinc;
|
|
|
|
zMax = mesh->z + sInfo->zMaxc;
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (inXmax <= xMin
|
|
|
|
|| inXmin >= xMax
|
|
|
|
|| y <= yMin
|
|
|
|
|| inYmin >= yMax
|
|
|
|
|| inZmax <= zMin
|
|
|
|
|| inZmin >= zMax)
|
2018-08-19 09:46:58 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
coll->hitStatic = true;
|
2019-12-17 17:37:53 +01:00
|
|
|
return 1;
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return 0;
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
int GetCollidedObjects(ITEM_INFO* collidingItem, int radius, int onlyVisible, ITEM_INFO** collidedItems, MESH_INFO** collidedMeshes, int ignoreLara)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
ROOM_INFO* room;
|
|
|
|
short roomsArray[255];
|
|
|
|
short numRooms;
|
|
|
|
short numItems = 0, numMeshes = 0;
|
|
|
|
int c, s;
|
|
|
|
int rx, rz;
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
// Collect all the rooms where to check
|
|
|
|
GetRoomList(collidingItem->roomNumber, roomsArray, &numRooms);
|
2018-11-19 23:29:30 +01:00
|
|
|
|
|
|
|
if (collidedMeshes)
|
|
|
|
{
|
2019-11-27 15:12:35 +01:00
|
|
|
for (int i = 0; i < numRooms; i++)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
room = &Rooms[roomsArray[i]];
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
for (int j = 0; j < room->numMeshes; j++)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
|
|
|
MESH_INFO* mesh = &room->mesh[j];
|
|
|
|
STATIC_INFO* staticMesh = &StaticObjects[mesh->staticNumber];
|
|
|
|
|
|
|
|
if (mesh->Flags & 1)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if (collidingItem->pos.yPos + radius + STEP_SIZE/2 >= mesh->y + staticMesh->yMinc)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
|
|
|
if (collidingItem->pos.yPos <= mesh->y + staticMesh->yMaxc)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
s = SIN(mesh->yRot);
|
|
|
|
c = COS(mesh->yRot);
|
|
|
|
rx = ((collidingItem->pos.xPos - mesh->x) * c - s * (collidingItem->pos.zPos - mesh->z)) >> W2V_SHIFT;
|
|
|
|
rz = ((collidingItem->pos.zPos - mesh->z) * c + s * (collidingItem->pos.xPos - mesh->x)) >> W2V_SHIFT;
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (radius + rx + STEP_SIZE/2 >= staticMesh->xMinc && rx - radius - STEP_SIZE/2 <= staticMesh->xMaxc)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if (radius + rz + STEP_SIZE/2 >= staticMesh->zMinc && rz - radius - STEP_SIZE/2 <= staticMesh->zMaxc)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
|
|
|
collidedMeshes[numMeshes++] = mesh;
|
|
|
|
if (!radius)
|
|
|
|
{
|
|
|
|
collidedItems[0] = NULL;
|
2019-12-17 17:37:53 +01:00
|
|
|
return 1;
|
2018-11-19 23:29:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
collidedMeshes[numMeshes] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collidedItems)
|
|
|
|
{
|
2019-11-27 15:12:35 +01:00
|
|
|
for (int i = 0; i < numRooms; i++)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
|
|
|
ROOM_INFO* room = &Rooms[roomsArray[i]];
|
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int itemNumber = room->itemNumber;
|
2018-11-19 23:29:30 +01:00
|
|
|
if (itemNumber != NO_ITEM)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ITEM_INFO* item = &Items[itemNumber];
|
|
|
|
|
2018-11-21 09:34:01 +01:00
|
|
|
if (item == collidingItem || !ignoreLara && item == LaraItem)
|
2018-11-19 23:29:30 +01:00
|
|
|
{
|
|
|
|
itemNumber = item->nextItem;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->flags & 0x8000)
|
|
|
|
{
|
|
|
|
itemNumber = item->nextItem;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Objects[item->objectNumber].collision && item->objectNumber != ID_LARA)
|
|
|
|
{
|
|
|
|
itemNumber = item->nextItem;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int dx = collidingItem->pos.xPos - item->pos.xPos;
|
|
|
|
int dy = collidingItem->pos.yPos - item->pos.yPos;
|
|
|
|
int dz = collidingItem->pos.zPos - item->pos.zPos;
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
short* framePtr = GetBestFrame(item);
|
2018-11-19 23:29:30 +01:00
|
|
|
|
|
|
|
if (Objects[item->objectNumber].drawRoutine
|
|
|
|
&& item->meshBits
|
2018-11-21 09:34:01 +01:00
|
|
|
&& (!onlyVisible || item->status != ITEM_INVISIBLE)
|
2018-11-19 23:29:30 +01:00
|
|
|
&& dx >= -2048
|
|
|
|
&& dx <= 2048
|
|
|
|
&& dy >= -2048
|
|
|
|
&& dy <= 2048
|
|
|
|
&& dz >= -2048
|
|
|
|
&& dz <= 2048
|
|
|
|
&& collidingItem->pos.yPos + radius + 128 >= item->pos.yPos + framePtr[2]
|
|
|
|
&& collidingItem->pos.yPos - radius - 128 <= item->pos.yPos + framePtr[3])
|
|
|
|
{
|
2019-11-27 15:12:35 +01:00
|
|
|
int s = SIN(item->pos.yRot);
|
|
|
|
int c = COS(item->pos.yRot);
|
2018-11-19 23:29:30 +01:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int rx = (dx * c - s * dz) >> W2V_SHIFT;
|
|
|
|
int rz = (dz * c + s * dx) >> W2V_SHIFT;
|
2018-11-19 23:29:30 +01:00
|
|
|
|
|
|
|
if (item->objectNumber == ID_TURN_SWITCH)
|
|
|
|
{
|
|
|
|
// TODO: implement
|
|
|
|
/*v59 = -256;
|
|
|
|
v57 = -256;
|
|
|
|
v60 = 256;
|
|
|
|
v58 = 256;
|
|
|
|
bounds = &v57;*/
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radius + rx + 128 >= framePtr[0] && rx - radius - 128 <= framePtr[1])
|
|
|
|
{
|
|
|
|
if (radius + rz + 128 >= framePtr[4] && rz - radius - 128 <= framePtr[5])
|
|
|
|
{
|
|
|
|
collidedItems[numItems++] = item;
|
|
|
|
if (!radius)
|
2019-12-17 17:37:53 +01:00
|
|
|
return 1;
|
2018-11-19 23:29:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
itemNumber = item->nextItem;
|
|
|
|
|
|
|
|
} while (itemNumber != NO_ITEM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
collidedItems[numItems] = NULL;
|
|
|
|
}
|
2018-11-19 23:29:30 +01:00
|
|
|
|
|
|
|
return (numItems | numMeshes);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
int TestWithGlobalCollisionBounds(ITEM_INFO* item, ITEM_INFO* lara, COLL_INFO* coll)
|
2018-11-24 09:39:37 +01:00
|
|
|
{
|
2019-11-27 15:12:35 +01:00
|
|
|
short* framePtr = GetBestFrame(lara);
|
2018-11-24 09:39:37 +01:00
|
|
|
|
|
|
|
if (item->pos.yPos + GlobalCollisionBounds.Y2 <= lara->pos.yPos + framePtr[3])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (item->pos.yPos + GlobalCollisionBounds.Y1 >= framePtr[4])
|
|
|
|
return false;
|
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int s = SIN(item->pos.yRot);
|
|
|
|
int c = COS(item->pos.yRot);
|
2018-11-24 09:39:37 +01:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int dx = lara->pos.xPos - item->pos.xPos;
|
|
|
|
int dz = lara->pos.zPos - item->pos.zPos;
|
2018-11-24 09:39:37 +01:00
|
|
|
|
2019-11-27 15:12:35 +01:00
|
|
|
int x = (c * dx - s * dz) >> W2V_SHIFT;
|
|
|
|
int z = (c * dz + s * dx) >> W2V_SHIFT;
|
2018-11-24 09:39:37 +01:00
|
|
|
|
|
|
|
if (x < GlobalCollisionBounds.X1 - coll->radius ||
|
|
|
|
x > GlobalCollisionBounds.X2 + coll->radius ||
|
|
|
|
z < GlobalCollisionBounds.Z1 - coll->radius ||
|
|
|
|
z > GlobalCollisionBounds.Z2 + coll->radius)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
void TrapCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c)
|
2019-05-06 23:48:35 +02:00
|
|
|
{
|
|
|
|
ITEM_INFO* item = &Items[itemNumber];
|
|
|
|
|
|
|
|
if (item->status == ITEM_ACTIVE)
|
|
|
|
{
|
|
|
|
if (!TestBoundsCollide(item, l, c->radius))
|
|
|
|
return;
|
|
|
|
|
|
|
|
TestCollision(item, LaraItem);
|
|
|
|
|
2019-11-21 07:43:34 +01:00
|
|
|
/*if (item->object_number == FAN && item->currentAnimState == 1) // Is the fan moving slow ?
|
2019-05-06 23:48:35 +02:00
|
|
|
ObjectCollision(item_num, laraitem, coll);*/
|
|
|
|
}
|
|
|
|
else if (item->status != ITEM_INVISIBLE)
|
|
|
|
ObjectCollision(itemNumber, l, c);
|
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
void TestForObjectOnLedge(ITEM_INFO* item, COLL_INFO* coll)//2A940(<), 2AB68(<) (F)
|
2019-12-01 08:13:19 +01:00
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 0; i < 2; i++)
|
2019-12-01 08:13:19 +01:00
|
|
|
{
|
|
|
|
GAME_VECTOR s;
|
|
|
|
s.x = (i << 8) - 0x80;
|
|
|
|
s.y = -256;
|
|
|
|
s.z = 0;
|
|
|
|
|
|
|
|
GetLaraJointPosition((PHD_VECTOR*)&s, LJ_HEAD);
|
|
|
|
s.roomNumber = LaraItem->roomNumber;
|
|
|
|
|
|
|
|
GAME_VECTOR d;
|
|
|
|
d.x = 0;
|
|
|
|
d.x = (s.x + ((SIN(LaraItem->pos.yRot) << 1) + SIN(LaraItem->pos.yRot))) >> 4;
|
|
|
|
d.y = s.y;
|
|
|
|
d.z = (s.z + ((COS(LaraItem->pos.yRot) << 1) + COS(LaraItem->pos.yRot))) >> 4;
|
|
|
|
|
|
|
|
LOS(&s, &d);
|
|
|
|
|
|
|
|
PHD_VECTOR v;
|
|
|
|
MESH_INFO* mesh;
|
|
|
|
|
|
|
|
// CHECK
|
|
|
|
/*if (ObjectOnLOS2(&s, &d, &v, &mesh) != 999)
|
|
|
|
{
|
|
|
|
coll->hitStatic = true;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-02 14:49:19 +01:00
|
|
|
void ShiftItem(ITEM_INFO* item, COLL_INFO* coll)
|
2019-12-02 06:39:51 +01:00
|
|
|
{
|
|
|
|
item->pos.xPos += coll->shift.x;
|
|
|
|
item->pos.yPos += coll->shift.y;
|
|
|
|
item->pos.zPos += coll->shift.z;
|
|
|
|
coll->shift.z = 0;
|
|
|
|
coll->shift.y = 0;
|
|
|
|
coll->shift.x = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-04 18:51:23 +01:00
|
|
|
void UpdateLaraRoom(ITEM_INFO* item, int height)
|
|
|
|
{
|
|
|
|
int x = item->pos.xPos;
|
|
|
|
int y = height + item->pos.yPos;
|
|
|
|
int z = item->pos.zPos;
|
|
|
|
short roomNumber = item->roomNumber;
|
|
|
|
FLOOR_INFO* floor = GetFloor(x, y, z, &roomNumber);
|
|
|
|
item->floor = GetFloorHeight(floor, x, y, z);
|
|
|
|
if (item->roomNumber != roomNumber)
|
|
|
|
ItemNewRoom(Lara.itemNumber, roomNumber);
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
short GetTiltType(FLOOR_INFO* floor, int x, int y, int z)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
ROOM_INFO* r;
|
|
|
|
short* data;
|
|
|
|
short func;
|
|
|
|
int tilt, t0, t1, t2, t3;
|
|
|
|
int dx, dz;
|
|
|
|
short xOff, yOff;
|
|
|
|
|
2019-12-10 18:25:48 +01:00
|
|
|
while (floor->pitRoom != NO_ROOM)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if (CheckNoColFloorTriangle(floor, x, z) == TRUE)
|
2019-12-07 08:36:13 +01:00
|
|
|
break;
|
2019-12-17 17:37:53 +01:00
|
|
|
r = &Rooms[floor->pitRoom];
|
2019-12-10 18:25:48 +01:00
|
|
|
floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if ((y + CLICK(2)) < (floor->floor * CLICK(1)))
|
|
|
|
return FLOOR_TYPE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-10 18:25:48 +01:00
|
|
|
if (!floor->index)
|
2019-12-17 17:37:53 +01:00
|
|
|
return FLOOR_TYPE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
data = &FloorData[floor->index];
|
|
|
|
func = *data & DATA_TYPE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (func == TILT_TYPE)
|
2019-12-17 17:37:53 +01:00
|
|
|
return data[1];
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (func != SPLIT1
|
|
|
|
&& func != SPLIT2
|
|
|
|
&& func != NOCOLF1T
|
|
|
|
&& func != NOCOLF2T
|
|
|
|
&& func != NOCOLF1B
|
|
|
|
&& func != NOCOLF2B)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
return FLOOR_TYPE;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
tilt = data[1];
|
|
|
|
t0 = tilt & DATA_TILT;
|
|
|
|
t1 = (tilt >> 4) & DATA_TILT;
|
|
|
|
t2 = (tilt >> 8) & DATA_TILT;
|
|
|
|
t3 = (tilt >> 12) & DATA_TILT;
|
|
|
|
dx = x & (WALL_SIZE - 1);
|
|
|
|
dz = z & (WALL_SIZE - 1);
|
|
|
|
xOff = 0;
|
|
|
|
yOff = 0;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (func == SPLIT1 || func == NOCOLF1T || func == NOCOLF1B)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if (dx > (SECTOR(1) - dz))
|
2019-12-14 08:43:34 +01:00
|
|
|
{
|
|
|
|
xOff = t3 - t0;
|
|
|
|
yOff = t3 - t2;
|
|
|
|
}
|
2019-12-07 08:36:13 +01:00
|
|
|
else
|
2019-12-14 08:43:34 +01:00
|
|
|
{
|
|
|
|
xOff = t2 - t1;
|
|
|
|
yOff = t0 - t1;
|
|
|
|
}
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
else if (dx > dz)
|
|
|
|
{
|
2019-12-14 08:43:34 +01:00
|
|
|
xOff = t3 - t0;
|
|
|
|
yOff = t0 - t1;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-14 08:43:34 +01:00
|
|
|
xOff = t2 - t1;
|
|
|
|
yOff = t3 - t2;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return ((xOff << 8) | (yOff & DATA_STATIC));
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int FindGridShift(int x, int z)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if ((x >> WALL_SHIFT) == (z >> WALL_SHIFT))
|
2019-12-07 08:36:13 +01:00
|
|
|
return 0;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if ((z >> WALL_SHIFT) <= (x >> WALL_SHIFT))
|
|
|
|
return (-1 - (x & (WALL_SIZE - 1)));
|
2019-12-07 08:36:13 +01:00
|
|
|
else
|
2019-12-17 17:37:53 +01:00
|
|
|
return ((WALL_SIZE + 1) - (x & (WALL_SIZE - 1)));
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int TestBoundsCollideStatic(short* bounds, PHD_3DPOS* pos, int radius)
|
|
|
|
{
|
|
|
|
if (!(bounds[5] | bounds[4] | bounds[0] | bounds[1] | bounds[2] | bounds[3]))
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
short* frame = GetBestFrame(LaraItem);
|
|
|
|
if (pos->yPos + bounds[3] <= LaraItem->pos.yPos + frame[2])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (pos->yPos + bounds[2] >= LaraItem->pos.yPos + frame[3])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
int c, s;
|
|
|
|
int x, z, dx, dz;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
c = COS(pos->yRot);
|
|
|
|
s = SIN(pos->yRot);
|
|
|
|
x = LaraItem->pos.xPos - pos->xPos;
|
|
|
|
z = LaraItem->pos.zPos - pos->zPos;
|
|
|
|
dx = (c * x - s * z) >> W2V_SHIFT;
|
|
|
|
dz = (c * z + s * x) >> W2V_SHIFT;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (dx <= radius + bounds[1]
|
|
|
|
&& dx >= bounds[0] - radius
|
|
|
|
&& dz <= radius + bounds[5]
|
|
|
|
&& dz >= bounds[4] - radius)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-12-07 08:36:13 +01:00
|
|
|
else
|
2019-12-17 17:37:53 +01:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ItemPushLaraStatic(ITEM_INFO* item, short* bounds, PHD_3DPOS* pos, COLL_INFO* coll)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int c, s;
|
|
|
|
int dx, dz, rx, rz, minX, maxX, minZ, maxZ;
|
|
|
|
int left, right, top, bottom;
|
|
|
|
short oldFacing;
|
|
|
|
|
|
|
|
c = COS(pos->yRot);
|
|
|
|
s = SIN(pos->yRot);
|
|
|
|
dx = LaraItem->pos.xPos - pos->xPos;
|
|
|
|
dz = LaraItem->pos.zPos - pos->zPos;
|
|
|
|
rx = (c * dx - s * dz) >> W2V_SHIFT;
|
|
|
|
rz = (c * dz + s * dx) >> W2V_SHIFT;
|
|
|
|
minX = bounds[0] - coll->radius;
|
|
|
|
maxX = bounds[1] + coll->radius;
|
|
|
|
minZ = bounds[4] - coll->radius;
|
|
|
|
maxZ = bounds[5] + coll->radius;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (abs(dx) > 4608
|
2019-12-17 17:37:53 +01:00
|
|
|
|| abs(dz) > 4608
|
|
|
|
|| rx <= minX
|
|
|
|
|| rx >= maxX
|
|
|
|
|| rz <= minZ
|
|
|
|
|| rz >= maxZ)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
left = rx - minX;
|
|
|
|
top = maxZ - rz;
|
|
|
|
bottom = rz - minZ;
|
|
|
|
right = maxX - rx;
|
|
|
|
|
|
|
|
if (right <= left && right <= top && right <= bottom)
|
2019-12-07 08:36:13 +01:00
|
|
|
rx += right;
|
2019-12-17 17:37:53 +01:00
|
|
|
else if (left <= right && left <= top && left <= bottom)
|
|
|
|
rx -= left;
|
2019-12-07 08:36:13 +01:00
|
|
|
else if (top <= left && top <= right && top <= bottom)
|
|
|
|
rz += top;
|
|
|
|
else
|
|
|
|
rz -= bottom;
|
|
|
|
|
|
|
|
item->pos.xPos = pos->xPos + ((c * rx + s * rz) >> W2V_SHIFT);
|
|
|
|
item->pos.zPos = pos->zPos + ((c * rz - s * rx) >> W2V_SHIFT);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
coll->badPos = NO_BAD_POS;
|
|
|
|
coll->badNeg = -STEPUP_HEIGHT;
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->badCeiling = 0;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
oldFacing = coll->facing;
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->facing = ATAN(item->pos.zPos - coll->old.z, item->pos.xPos - coll->old.x);
|
2019-12-17 17:37:53 +01:00
|
|
|
GetCollisionInfo(coll, item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber, LARA_HITE);
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->facing = oldFacing;
|
|
|
|
|
|
|
|
if (coll->collType == CT_NONE)
|
|
|
|
{
|
|
|
|
coll->old.x = item->pos.xPos;
|
|
|
|
coll->old.y = item->pos.yPos;
|
|
|
|
coll->old.z = item->pos.zPos;
|
|
|
|
|
|
|
|
UpdateLaraRoom(item, -10);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item->pos.xPos = coll->old.x;
|
|
|
|
item->pos.zPos = coll->old.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item == LaraItem && Lara.isMoving && Lara.moveCount > 15)
|
|
|
|
{
|
|
|
|
Lara.isMoving = false;
|
|
|
|
Lara.gunStatus = LG_NO_ARMS;
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return TRUE;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ItemPushLara(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int c, s;
|
|
|
|
int dx, dz, rx, rz, minX, maxX, minZ, maxZ;
|
|
|
|
int left, right, bottom, top;
|
2019-12-07 08:36:13 +01:00
|
|
|
short* bounds;
|
2019-12-17 17:37:53 +01:00
|
|
|
short facing;
|
|
|
|
|
|
|
|
c = COS(item->pos.yRot);
|
|
|
|
s = SIN(item->pos.yRot);
|
|
|
|
dx = LaraItem->pos.xPos - item->pos.xPos;
|
|
|
|
dz = LaraItem->pos.zPos - item->pos.zPos;
|
|
|
|
rx = (c * dx - s * dz) >> W2V_SHIFT;
|
|
|
|
rz = (c * dz + s * dx) >> W2V_SHIFT;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (bigpush & 2)
|
|
|
|
bounds = (short*)&GlobalCollisionBounds;
|
|
|
|
else
|
|
|
|
bounds = GetBestFrame(item);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
minX = bounds[0];
|
|
|
|
maxX = bounds[1];
|
|
|
|
minZ = bounds[4];
|
|
|
|
maxZ = bounds[5];
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (bigpush & 1)
|
|
|
|
{
|
|
|
|
minX -= coll->radius;
|
|
|
|
maxX += coll->radius;
|
|
|
|
minZ -= coll->radius;
|
|
|
|
maxZ += coll->radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (abs(dx) > 4608
|
2019-12-17 17:37:53 +01:00
|
|
|
|| abs(dz) > 4608
|
|
|
|
|| rx <= minX
|
|
|
|
|| rx >= maxX
|
|
|
|
|| rz <= minZ
|
|
|
|
|| rz >= maxZ)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
left = rx - minX;
|
|
|
|
top = maxZ - rz;
|
|
|
|
bottom = rz - minZ;
|
|
|
|
right = maxX - rx;
|
|
|
|
|
|
|
|
if (right <= left && right <= top && right <= bottom)
|
2019-12-07 08:36:13 +01:00
|
|
|
rx += right;
|
2019-12-17 17:37:53 +01:00
|
|
|
else if (left <= right && left <= top && left <= bottom)
|
|
|
|
rx -= left;
|
2019-12-07 08:36:13 +01:00
|
|
|
else if (top <= left && top <= right && top <= bottom)
|
|
|
|
rz += top;
|
|
|
|
else
|
|
|
|
rz -= bottom;
|
|
|
|
|
|
|
|
l->pos.xPos = item->pos.xPos + ((c * rx + s * rz) >> W2V_SHIFT);
|
|
|
|
l->pos.zPos = item->pos.zPos + ((c * rz - s * rx) >> W2V_SHIFT);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (spazon && bounds[3] - bounds[2] > STEP_SIZE)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
|
|
|
rx = (bounds[0] + bounds[1]) / 2;
|
|
|
|
rz = (bounds[4] + bounds[5]) / 2;
|
|
|
|
|
|
|
|
dx -= (c * rx + s * rz) >> W2V_SHIFT;
|
|
|
|
dz -= (c * rz - s * rx) >> W2V_SHIFT;
|
|
|
|
|
|
|
|
Lara.hitDirection = (l->pos.yRot - ATAN(dz, dz) - ANGLE(135)) >> W2V_SHIFT;
|
|
|
|
|
|
|
|
if (!Lara.hitFrame)
|
|
|
|
SoundEffect(SFX_LARA_INJURY_RND, &l->pos, 0);
|
|
|
|
|
|
|
|
Lara.hitFrame++;
|
|
|
|
if (Lara.hitFrame > 34)
|
|
|
|
Lara.hitFrame = 34;
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
coll->badPos = NO_BAD_POS;
|
|
|
|
coll->badNeg = -STEPUP_HEIGHT;
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->badCeiling = 0;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
facing = coll->facing;
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->facing = ATAN(l->pos.zPos - coll->old.z, l->pos.xPos - coll->old.x);
|
2019-12-17 17:37:53 +01:00
|
|
|
GetCollisionInfo(coll, l->pos.xPos, l->pos.yPos, l->pos.zPos, l->roomNumber, LARA_HITE);
|
2019-12-07 08:36:13 +01:00
|
|
|
coll->facing = facing;
|
|
|
|
|
|
|
|
if (coll->collType == CT_NONE)
|
|
|
|
{
|
|
|
|
coll->old.x = l->pos.xPos;
|
|
|
|
coll->old.y = l->pos.yPos;
|
|
|
|
coll->old.z = l->pos.zPos;
|
|
|
|
|
|
|
|
UpdateLaraRoom(l, -10);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
l->pos.xPos = coll->old.x;
|
|
|
|
l->pos.zPos = coll->old.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Lara.isMoving && Lara.moveCount > 15)
|
|
|
|
{
|
|
|
|
Lara.isMoving = false;
|
|
|
|
Lara.gunStatus = LG_NO_ARMS;
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return TRUE;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
2020-01-12 08:02:48 +01:00
|
|
|
void AIPickupCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
|
|
|
ITEM_INFO* item = &Items[itemNumber];
|
|
|
|
if (item->objectNumber == ID_SHOOT_SWITCH1 && !(item->meshBits & 1))
|
|
|
|
item->status = ITEM_INVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c)
|
|
|
|
{
|
|
|
|
ITEM_INFO* item = &Items[itemNumber];
|
|
|
|
|
|
|
|
if (TestBoundsCollide(item, l, c->radius))
|
|
|
|
{
|
|
|
|
if (TestCollision(item, l))
|
|
|
|
{
|
|
|
|
if (c->enableBaddiePush)
|
2019-12-17 17:37:53 +01:00
|
|
|
ItemPushLara(item, l, c, FALSE, TRUE);
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* l)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int x, y, z;
|
|
|
|
|
2019-12-07 08:36:13 +01:00
|
|
|
l->pos.xRot = item->pos.xRot;
|
|
|
|
l->pos.yRot = item->pos.yRot;
|
|
|
|
l->pos.zRot = item->pos.zRot;
|
|
|
|
|
|
|
|
phd_PushUnitMatrix();
|
|
|
|
phd_RotYXZ(item->pos.yRot, item->pos.xRot, item->pos.zRot);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
x = item->pos.xPos + ((MatrixPtr[M00] * vec->x + MatrixPtr[M01] * vec->y + MatrixPtr[M02] * vec->z) >> W2V_SHIFT);
|
|
|
|
y = item->pos.yPos + ((MatrixPtr[M10] * vec->x + MatrixPtr[M11] * vec->y + MatrixPtr[M12] * vec->z) >> W2V_SHIFT);
|
|
|
|
z = item->pos.zPos + ((MatrixPtr[M20] * vec->x + MatrixPtr[M21] * vec->y + MatrixPtr[M22] * vec->z) >> W2V_SHIFT);
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
phd_PopMatrix();
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
l->pos.xPos = x;
|
|
|
|
l->pos.yPos = y;
|
|
|
|
l->pos.zPos = z;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TriggerLaraBlood()
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int i;
|
2019-12-07 08:36:13 +01:00
|
|
|
int node = 1;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
for (i = 0; i < 14; i++)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
|
|
|
if (node & LaraItem->touchBits)
|
|
|
|
{
|
|
|
|
PHD_VECTOR vec;
|
2019-12-17 17:37:53 +01:00
|
|
|
vec.x = (GetRandomControl() & 31) - 16;
|
|
|
|
vec.y = (GetRandomControl() & 31) - 16;
|
|
|
|
vec.z = (GetRandomControl() & 31) - 16;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
GetLaraJointPosition(&vec, LM[i]);
|
|
|
|
DoBloodSplat(vec.x, vec.y, vec.z, (GetRandomControl() & 7) + 8, 2 * GetRandomControl(), LaraItem->roomNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
node <<= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
int TestLaraPosition(short* bounds, ITEM_INFO* item, ITEM_INFO* l)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int x, y, z, rx, ry, rz;
|
|
|
|
short xRotRel, yRotRel, zRotRel;
|
|
|
|
|
|
|
|
xRotRel = l->pos.xRot - item->pos.xRot;
|
|
|
|
yRotRel = l->pos.yRot - item->pos.yRot;
|
|
|
|
zRotRel = l->pos.zRot - item->pos.zRot;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (xRotRel < bounds[6])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
if (xRotRel > bounds[7])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
if (yRotRel < bounds[8])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
if (yRotRel > bounds[9])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
if (zRotRel < bounds[10])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
if (zRotRel > bounds[11])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
phd_PushUnitMatrix();
|
|
|
|
phd_RotYXZ(item->pos.yRot, item->pos.xRot, item->pos.zRot);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
x = l->pos.xPos - item->pos.xPos;
|
|
|
|
y = l->pos.yPos - item->pos.yPos;
|
|
|
|
z = l->pos.zPos - item->pos.zPos;
|
|
|
|
rx = (x * MatrixPtr[M00] + y * MatrixPtr[M10] + z * MatrixPtr[M20]) >> W2V_SHIFT;
|
|
|
|
ry = (x * MatrixPtr[M01] + y * MatrixPtr[M11] + z * MatrixPtr[M21]) >> W2V_SHIFT;
|
|
|
|
rz = (x * MatrixPtr[M02] + y * MatrixPtr[M12] + z * MatrixPtr[M22]) >> W2V_SHIFT;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
phd_PopMatrix();
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (rx < bounds[0] || rx > bounds[1] || ry < bounds[2] || ry > bounds[3] || rz < bounds[4] || rz > bounds[5])
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return TRUE;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Move3DPosTo3DPos(PHD_3DPOS* src, PHD_3DPOS* dest, int velocity, short angAdd)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int x, y, z;
|
|
|
|
int distance, direction;
|
|
|
|
int angle;
|
|
|
|
|
|
|
|
x = dest->xPos - src->xPos;
|
|
|
|
y = dest->yPos - src->yPos;
|
|
|
|
z = dest->zPos - src->zPos;
|
|
|
|
distance = SQRT_ASM(SQUARE(x) + SQUARE(y) + SQUARE(z));
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (velocity < distance)
|
|
|
|
{
|
|
|
|
src->xPos += x * velocity / distance;
|
|
|
|
src->yPos += y * velocity / distance;
|
|
|
|
src->zPos += z * velocity / distance;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src->xPos = dest->xPos;
|
|
|
|
src->yPos = dest->yPos;
|
|
|
|
src->zPos = dest->zPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Lara.isMoving)
|
|
|
|
{
|
|
|
|
if (Lara.waterStatus != LW_UNDERWATER)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
angle = mGetAngle(dest->xPos, dest->zPos, src->xPos, src->zPos);
|
2019-12-19 15:13:13 -03:00
|
|
|
direction = ((unsigned short) (angle + ANGLE(45)) / ANGLE(90) - (unsigned short) (dest->yRot + ANGLE(45)) / ANGLE(90)) & 3;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
LaraItem->animNumber = ANIMATION_LARA_WALK_LEFT;
|
2019-12-17 17:37:53 +01:00
|
|
|
LaraItem->frameNumber = GF(ANIMATION_LARA_WALK_LEFT, 0);
|
2019-12-07 08:36:13 +01:00
|
|
|
LaraItem->goalAnimState = STATE_LARA_WALK_LEFT;
|
|
|
|
LaraItem->currentAnimState = STATE_LARA_WALK_LEFT;
|
|
|
|
Lara.gunStatus = LG_HANDS_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
LaraItem->animNumber = ANIMATION_LARA_WALK_FORWARD;
|
2019-12-17 17:37:53 +01:00
|
|
|
LaraItem->frameNumber = GF(ANIMATION_LARA_WALK_FORWARD, 0);
|
2019-12-07 08:36:13 +01:00
|
|
|
LaraItem->goalAnimState = STATE_LARA_WALK_FORWARD;
|
|
|
|
LaraItem->currentAnimState = STATE_LARA_WALK_FORWARD;
|
|
|
|
Lara.gunStatus = LG_HANDS_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
LaraItem->animNumber = ANIMATION_LARA_WALK_RIGHT;
|
2019-12-17 17:37:53 +01:00
|
|
|
LaraItem->frameNumber = GF(ANIMATION_LARA_WALK_RIGHT, 0);
|
2019-12-07 08:36:13 +01:00
|
|
|
LaraItem->goalAnimState = STATE_LARA_WALK_RIGHT;
|
|
|
|
LaraItem->currentAnimState = STATE_LARA_WALK_RIGHT;
|
|
|
|
Lara.gunStatus = LG_HANDS_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
LaraItem->animNumber = ANIMATION_LARA_WALK_BACK;
|
2019-12-17 17:37:53 +01:00
|
|
|
LaraItem->frameNumber = GF(ANIMATION_LARA_WALK_BACK, 0);
|
2019-12-07 08:36:13 +01:00
|
|
|
LaraItem->goalAnimState = STATE_LARA_WALK_BACK;
|
|
|
|
LaraItem->currentAnimState = STATE_LARA_WALK_BACK;
|
|
|
|
Lara.gunStatus = LG_HANDS_BUSY;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Lara.isMoving = true;
|
|
|
|
Lara.moveCount = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->xRot - src->xRot) <= angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->xRot - src->xRot) >= -angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
src->xRot = dest->xRot;
|
|
|
|
else
|
|
|
|
src->xRot = src->xRot - angAdd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src->xRot = angAdd + src->xRot;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->yRot - src->yRot) <= angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->yRot - src->yRot) >= -angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
src->yRot = dest->yRot;
|
|
|
|
else
|
|
|
|
src->yRot = src->yRot - angAdd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src->yRot = angAdd + src->yRot;
|
|
|
|
}
|
|
|
|
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->zRot - src->zRot) <= angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-19 15:13:13 -03:00
|
|
|
if ((short) (dest->zRot - src->zRot) >= -angAdd)
|
2019-12-07 08:36:13 +01:00
|
|
|
src->zRot = dest->zRot;
|
|
|
|
else
|
|
|
|
src->zRot = src->zRot - angAdd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
src->zRot = angAdd + src->zRot;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (src->xPos == dest->xPos
|
2019-12-17 17:37:53 +01:00
|
|
|
&& src->yPos == dest->yPos
|
|
|
|
&& src->zPos == dest->zPos
|
|
|
|
&& src->xRot == dest->xRot
|
|
|
|
&& src->yRot == dest->yRot
|
|
|
|
&& src->zRot == dest->zRot);
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int MoveLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* l)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
FLOOR_INFO* floor;
|
2019-12-07 08:36:13 +01:00
|
|
|
PHD_3DPOS dest;
|
2019-12-17 17:37:53 +01:00
|
|
|
int height;
|
|
|
|
short roomNumber;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
dest.xRot = item->pos.xRot;
|
|
|
|
dest.yRot = item->pos.yRot;
|
|
|
|
dest.zRot = item->pos.zRot;
|
|
|
|
|
|
|
|
phd_PushUnitMatrix();
|
|
|
|
phd_RotYXZ(item->pos.yRot, item->pos.xRot, item->pos.zRot);
|
|
|
|
|
|
|
|
dest.xPos = item->pos.xPos + ((MatrixPtr[M00] * vec->x + MatrixPtr[M01] * vec->y + MatrixPtr[M02] * vec->z) >> W2V_SHIFT);
|
|
|
|
dest.yPos = item->pos.yPos + ((MatrixPtr[M10] * vec->x + MatrixPtr[M11] * vec->y + MatrixPtr[M12] * vec->z) >> W2V_SHIFT);
|
|
|
|
dest.zPos = item->pos.zPos + ((MatrixPtr[M20] * vec->x + MatrixPtr[M21] * vec->y + MatrixPtr[M22] * vec->z) >> W2V_SHIFT);
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
phd_PopMatrix();
|
2019-12-07 08:36:13 +01:00
|
|
|
|
|
|
|
if (item->objectNumber != ID_FLARE_ITEM && item->objectNumber != ID_BURNING_TORCH_ITEM)
|
2019-12-17 17:37:53 +01:00
|
|
|
return Move3DPosTo3DPos(&l->pos, &dest, LARA_VELOCITY, ANGLE(2));
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
roomNumber = l->roomNumber;
|
|
|
|
floor = GetFloor(dest.xPos, dest.yPos, dest.zPos, &roomNumber);
|
|
|
|
height = GetFloorHeight(floor, dest.xPos, dest.yPos, dest.zPos);
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (abs(height - l->pos.yPos) <= CLICK(2))
|
2019-12-07 08:36:13 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
if (SQRT_ASM(SQUARE(dest.xPos - l->pos.xPos) + SQUARE(dest.yPos - l->pos.yPos) + SQUARE(dest.zPos - l->pos.zPos)) < (STEP_SIZE/2))
|
|
|
|
return TRUE;
|
2019-12-07 08:36:13 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return Move3DPosTo3DPos(&l->pos, &dest, LARA_VELOCITY, ANGLE(2));
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Lara.isMoving)
|
|
|
|
{
|
|
|
|
Lara.isMoving = false;
|
|
|
|
Lara.gunStatus = LG_NO_ARMS;
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 08:36:13 +01:00
|
|
|
}
|
|
|
|
|
2019-12-07 09:51:50 +01:00
|
|
|
int TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* l, int radius)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
short* bounds;
|
|
|
|
short* laraBounds;
|
|
|
|
int c, s;
|
|
|
|
int x, z;
|
|
|
|
int dx, dz;
|
|
|
|
|
|
|
|
bounds = GetBestFrame(item);
|
|
|
|
laraBounds = GetBestFrame(l);
|
2019-12-07 09:51:50 +01:00
|
|
|
|
|
|
|
if (item->pos.yPos + bounds[3] > l->pos.yPos + laraBounds[2])
|
|
|
|
{
|
|
|
|
if (item->pos.yPos + bounds[2] < l->pos.yPos + laraBounds[3])
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
c = COS(item->pos.yRot);
|
|
|
|
s = SIN(item->pos.yRot);
|
|
|
|
x = l->pos.xPos - item->pos.xPos;
|
|
|
|
z = l->pos.zPos - item->pos.zPos;
|
|
|
|
dx = (c * x - s * z) >> W2V_SHIFT;
|
|
|
|
dz = (c * z + s * x) >> W2V_SHIFT;
|
2019-12-07 09:51:50 +01:00
|
|
|
|
|
|
|
if (dx >= bounds[0] - radius
|
2019-12-17 17:37:53 +01:00
|
|
|
&& dx <= radius + bounds[1]
|
|
|
|
&& dz >= bounds[4] - radius
|
|
|
|
&& dz <= radius + bounds[5])
|
2019-12-07 09:51:50 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
return TRUE;
|
2019-12-07 09:51:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
return FALSE;
|
2019-12-07 09:51:50 +01:00
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
void CreatureCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll)
|
2019-12-07 09:51:50 +01:00
|
|
|
{
|
|
|
|
ITEM_INFO* item = &Items[itemNum];
|
2019-12-17 17:37:53 +01:00
|
|
|
int c, s;
|
|
|
|
int x, z, rx, rz;
|
|
|
|
short* frame;
|
2019-12-07 09:51:50 +01:00
|
|
|
|
|
|
|
if (item->objectNumber != ID_HITMAN || item->currentAnimState != STATE_LARA_INSERT_PUZZLE)
|
|
|
|
{
|
|
|
|
if (TestBoundsCollide(item, l, coll->radius))
|
|
|
|
{
|
|
|
|
if (TestCollision(item, l))
|
|
|
|
{
|
|
|
|
if (coll->enableBaddiePush || Lara.waterStatus == LW_UNDERWATER || Lara.waterStatus == LW_SURFACE)
|
|
|
|
{
|
|
|
|
ItemPushLara(item, l, coll, coll->enableSpaz, 0);
|
|
|
|
}
|
|
|
|
else if (coll->enableSpaz)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
x = l->pos.xPos - item->pos.xPos;
|
|
|
|
z = l->pos.zPos - item->pos.zPos;
|
|
|
|
c = COS(item->pos.yRot);
|
|
|
|
s = SIN(item->pos.yRot);
|
|
|
|
frame = GetBestFrame(item);
|
|
|
|
rx = (frame[0] + frame[1]) / 2;
|
|
|
|
rz = (frame[4] + frame[5]) / 2;
|
2019-12-07 09:51:50 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (frame[3] - frame[2] > STEP_SIZE)
|
2019-12-07 09:51:50 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
int angle = (l->pos.yRot - ATAN(z - ((c * rx - s * rz) >> W2V_SHIFT), x - ((c * rx + s * rz) >> W2V_SHIFT)) - ANGLE(135)) >> W2V_SHIFT;
|
2019-12-07 09:51:50 +01:00
|
|
|
Lara.hitDirection = (short)angle;
|
2019-12-17 17:37:53 +01:00
|
|
|
// TODO: check if a second Lara.hitFrame++; is required there !
|
2019-12-07 09:51:50 +01:00
|
|
|
Lara.hitFrame++;
|
|
|
|
if (Lara.hitFrame > 30)
|
|
|
|
Lara.hitFrame = 30;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-27 00:13:39 -03:00
|
|
|
void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight) // (F) (D)
|
2019-12-08 07:38:22 +01:00
|
|
|
{
|
|
|
|
int resetRoom;
|
|
|
|
if (objectHeight >= 0)
|
|
|
|
{
|
|
|
|
resetRoom = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objectHeight = -objectHeight;
|
|
|
|
resetRoom = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
coll->collType = 0;
|
|
|
|
coll->shift.x = 0;
|
|
|
|
coll->shift.y = 0;
|
|
|
|
coll->shift.z = 0;
|
2019-12-11 18:09:44 -03:00
|
|
|
coll->quadrant = (unsigned short) (coll->facing + ANGLE(45)) / ANGLE(90);
|
2019-12-08 07:38:22 +01:00
|
|
|
|
|
|
|
int x = xPos;
|
|
|
|
int y = yPos - objectHeight;
|
|
|
|
int yTop = y - 160;
|
|
|
|
int z = zPos;
|
|
|
|
|
|
|
|
short tRoomNumber = roomNumber;
|
2019-12-29 01:40:55 -03:00
|
|
|
FLOOR_INFO* floor = GetFloor(x, yTop, z, &tRoomNumber);
|
2019-12-08 07:38:22 +01:00
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
int height = GetFloorHeight(floor, x, yTop, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
int ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->midCeiling = ceiling;
|
|
|
|
coll->midFloor = height;
|
|
|
|
coll->midType = HeightType;
|
|
|
|
|
|
|
|
coll->trigger = TriggerIndex;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
int tilt = GetTiltType(floor, x, LaraItem->pos.yPos, z);
|
|
|
|
coll->tiltX = tilt;
|
|
|
|
coll->tiltZ = tilt >> 8;
|
2019-12-08 07:38:22 +01:00
|
|
|
|
|
|
|
int xright, xleft, zright, zleft;
|
|
|
|
|
|
|
|
switch (coll->quadrant)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
XFront = (SIN(coll->facing) * coll->radius) >> (W2V_SHIFT);
|
|
|
|
ZFront = coll->radius;
|
|
|
|
xleft = -(coll->radius);
|
|
|
|
zleft = coll->radius;
|
|
|
|
xright = coll->radius;
|
|
|
|
zright = coll->radius;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
XFront = coll->radius;
|
|
|
|
ZFront = (COS(coll->facing) * coll->radius) >> (W2V_SHIFT);
|
|
|
|
xleft = coll->radius;
|
|
|
|
zleft = coll->radius;
|
|
|
|
xright = coll->radius;
|
|
|
|
zright = -(coll->radius);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
XFront = (SIN(coll->facing) * coll->radius) >> (W2V_SHIFT);
|
|
|
|
ZFront = -coll->radius;
|
|
|
|
xleft = coll->radius;
|
|
|
|
zleft = -(coll->radius);
|
|
|
|
xright = -(coll->radius);
|
|
|
|
zright = -(coll->radius);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
XFront = -(coll->radius);
|
|
|
|
ZFront = (COS(coll->facing) * coll->radius) >> (W2V_SHIFT);
|
|
|
|
xleft = -(coll->radius);
|
|
|
|
zleft = -(coll->radius);
|
|
|
|
xright = -(coll->radius);
|
|
|
|
zright = coll->radius;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
xleft = zleft = 0;
|
|
|
|
xright = zright = 0;
|
|
|
|
XFront = ZFront = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = XFront + xPos;
|
|
|
|
z = ZFront + zPos;
|
|
|
|
|
|
|
|
if (resetRoom)
|
|
|
|
tRoomNumber = roomNumber;
|
|
|
|
|
|
|
|
floor = GetFloor(x, yTop, z, &tRoomNumber);
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
height = GetFloorHeight(floor, x, yTop, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->frontCeiling = ceiling;
|
|
|
|
coll->frontFloor = height;
|
|
|
|
coll->frontType = HeightType;
|
|
|
|
|
|
|
|
floor = GetFloor(x + XFront, yTop, z + ZFront, &tRoomNumber);
|
|
|
|
height = GetFloorHeight(floor, x + XFront, yTop, z + ZFront);
|
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
|
|
|
if ((coll->slopesAreWalls)
|
|
|
|
&& ((coll->frontType == BIG_SLOPE) || (coll->frontType == DIAGONAL))
|
|
|
|
&& (coll->frontFloor < coll->midFloor)
|
|
|
|
&& (height < coll->frontFloor)
|
|
|
|
&& (coll->frontFloor < 0))
|
|
|
|
{
|
|
|
|
coll->frontFloor = -32767;
|
|
|
|
}
|
|
|
|
else if (coll->slopesArePits
|
|
|
|
&& ((coll->frontType == BIG_SLOPE) || (coll->frontType == DIAGONAL))
|
|
|
|
&& (coll->frontFloor > coll->midFloor))
|
|
|
|
{
|
|
|
|
coll->frontFloor = 512;
|
|
|
|
}
|
|
|
|
else if ((coll->lavaIsPit)
|
|
|
|
&& (coll->frontFloor > 0)
|
|
|
|
&& (TriggerIndex)
|
|
|
|
&& ((*(TriggerIndex) & DATA_TYPE) == LAVA_TYPE))
|
|
|
|
{
|
|
|
|
coll->frontFloor = 512;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = xPos + xleft;
|
|
|
|
z = zPos + zleft;
|
|
|
|
short lrRoomNumber = roomNumber;
|
|
|
|
floor = GetFloor(x, yTop, z, &lrRoomNumber);
|
|
|
|
|
|
|
|
height = GetFloorHeight(floor, x, yTop, z);
|
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->leftFloor = height;
|
|
|
|
coll->leftCeiling = ceiling;
|
|
|
|
coll->leftType = HeightType;
|
|
|
|
|
|
|
|
if (coll->slopesAreWalls == 1 && (coll->leftType == BIG_SLOPE || coll->leftType == DIAGONAL) && coll->leftFloor < 0)
|
|
|
|
coll->leftFloor = -32767;
|
|
|
|
else if (coll->slopesArePits && (coll->leftType == BIG_SLOPE || coll->leftType == DIAGONAL) && coll->leftFloor > 0)
|
|
|
|
coll->leftFloor = 512;
|
|
|
|
else if (coll->lavaIsPit && coll->leftFloor > 0 && TriggerIndex && (*(TriggerIndex)& DATA_TYPE) == LAVA_TYPE)
|
|
|
|
coll->leftFloor = 512;
|
|
|
|
|
|
|
|
floor = GetFloor(x, yTop, z, &tRoomNumber);
|
|
|
|
|
|
|
|
height = GetFloorHeight(floor, x, yTop, z);
|
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->leftFloor2 = height;
|
|
|
|
coll->leftCeiling2 = ceiling;
|
|
|
|
coll->leftType2 = HeightType;
|
|
|
|
|
|
|
|
if (coll->slopesAreWalls == 1 && (coll->leftType2 == BIG_SLOPE || coll->leftType2 == DIAGONAL) && coll->leftFloor2 < 0)
|
|
|
|
coll->leftFloor2 = -32767;
|
|
|
|
else if (coll->slopesArePits && (coll->leftType2 == BIG_SLOPE || coll->leftType2 == DIAGONAL) && coll->leftFloor2 > 0)
|
|
|
|
coll->leftFloor2 = 512;
|
|
|
|
else if (coll->lavaIsPit && coll->leftFloor2 > 0 && TriggerIndex && (*(TriggerIndex)& DATA_TYPE) == LAVA_TYPE)
|
|
|
|
coll->leftFloor2 = 512;
|
|
|
|
|
|
|
|
x = xPos + xright;
|
|
|
|
z = zPos + zright;
|
|
|
|
lrRoomNumber = roomNumber;
|
|
|
|
floor = GetFloor(x, yTop, z, &lrRoomNumber);
|
|
|
|
|
|
|
|
height = GetFloorHeight(floor, x, yTop, z);
|
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->rightFloor = height;
|
|
|
|
coll->rightCeiling = ceiling;
|
|
|
|
coll->rightType = HeightType;
|
|
|
|
|
|
|
|
if (coll->slopesAreWalls == 1 && (coll->rightType == BIG_SLOPE || coll->rightType == DIAGONAL) && coll->rightFloor < 0)
|
|
|
|
coll->rightFloor = -32767;
|
|
|
|
else if (coll->slopesArePits && (coll->rightType == BIG_SLOPE || coll->rightType == DIAGONAL) && coll->rightFloor > 0)
|
|
|
|
coll->rightFloor = 512;
|
|
|
|
else if (coll->lavaIsPit && coll->rightFloor > 0 && TriggerIndex && (*(TriggerIndex)& DATA_TYPE) == LAVA_TYPE)
|
|
|
|
coll->rightFloor = 512;
|
|
|
|
|
|
|
|
floor = GetFloor(x, yTop, z, &tRoomNumber);
|
|
|
|
|
|
|
|
height = GetFloorHeight(floor, x, yTop, z);
|
|
|
|
if (height != NO_HEIGHT)
|
|
|
|
height -= yPos;
|
|
|
|
|
2019-12-29 01:40:55 -03:00
|
|
|
ceiling = GetCeiling(floor, x, yTop - LaraItem->fallspeed, z);
|
2019-12-08 07:38:22 +01:00
|
|
|
if (ceiling != NO_HEIGHT)
|
|
|
|
ceiling -= y;
|
|
|
|
|
|
|
|
coll->rightFloor2 = height;
|
|
|
|
coll->rightCeiling2 = ceiling;
|
|
|
|
coll->rightType2 = HeightType;
|
|
|
|
|
|
|
|
if (coll->slopesAreWalls == 1 && (coll->rightType2 == BIG_SLOPE || coll->rightType2 == DIAGONAL) && coll->rightFloor2 < 0)
|
|
|
|
coll->rightFloor2 = -32767;
|
|
|
|
else if (coll->slopesArePits && (coll->rightType2 == BIG_SLOPE || coll->rightType2 == DIAGONAL) && coll->rightFloor2 > 0)
|
|
|
|
coll->rightFloor2 = 512;
|
|
|
|
else if (coll->lavaIsPit && coll->rightFloor2 > 0 && TriggerIndex && (*(TriggerIndex)& DATA_TYPE) == LAVA_TYPE)
|
|
|
|
coll->rightFloor2 = 512;
|
|
|
|
|
|
|
|
CollideStaticObjects(coll, xPos, yPos, zPos, tRoomNumber, objectHeight);
|
|
|
|
|
|
|
|
if (coll->midFloor == NO_HEIGHT)
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.y = coll->old.y - yPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
coll->collType = CT_FRONT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->midFloor - coll->midCeiling <= 0)
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.y = coll->old.y - yPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
coll->collType = CT_CLAMP;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->midCeiling >= 0)
|
|
|
|
{
|
|
|
|
coll->shift.y = coll->midCeiling;
|
|
|
|
coll->collType = CT_TOP;
|
|
|
|
coll->hitCeiling = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((coll->frontFloor > coll->badPos)
|
|
|
|
|| (coll->frontFloor < coll->badNeg)
|
|
|
|
|| (coll->frontCeiling > coll->badCeiling))
|
|
|
|
{
|
|
|
|
if ((coll->frontType == DIAGONAL)
|
|
|
|
|| (coll->frontType == SPLIT_TRI))
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (coll->quadrant)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.z = FindGridShift(zPos + ZFront, zPos);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
coll->shift.x = FindGridShift(xPos + XFront, xPos);
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
coll->collType = CT_FRONT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->frontCeiling >= coll->badCeiling)
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.y = coll->old.y - yPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
coll->collType = CT_TOP_FRONT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->leftFloor > coll->badPos ||
|
|
|
|
coll->leftFloor < coll->badNeg ||
|
|
|
|
coll->leftCeiling > coll->badCeiling)
|
|
|
|
{
|
|
|
|
if (coll->leftType == SPLIT_TRI)
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (coll->quadrant)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
coll->shift.x = FindGridShift(xPos + xleft, xPos + XFront);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
coll->shift.z = FindGridShift(zPos + zleft, zPos + ZFront);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
coll->collType = CT_LEFT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->rightFloor > coll->badPos ||
|
|
|
|
coll->rightFloor < coll->badNeg ||
|
|
|
|
coll->rightCeiling > coll->badCeiling)
|
|
|
|
{
|
|
|
|
if (coll->rightType == SPLIT_TRI)
|
|
|
|
{
|
|
|
|
coll->shift.x = coll->old.x - xPos;
|
|
|
|
coll->shift.z = coll->old.z - zPos;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (coll->quadrant)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
coll->shift.x = FindGridShift(xPos + xright, xPos + XFront);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
case 3:
|
|
|
|
coll->shift.z = FindGridShift(zPos + zright, zPos + ZFront);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
coll->collType = CT_RIGHT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-08 08:01:55 +01:00
|
|
|
void LaraBaddieCollision(ITEM_INFO* l, COLL_INFO* coll)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
ITEM_INFO* item;
|
|
|
|
OBJECT_INFO* obj;
|
|
|
|
|
2019-12-08 08:01:55 +01:00
|
|
|
l->hitStatus = false;
|
|
|
|
Lara.hitDirection = -1;
|
|
|
|
|
|
|
|
if (l->hitPoints > 0)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
// Crash when using GetRoomList() with vector there but work without :x
|
|
|
|
vector<short> roomsList;
|
|
|
|
short* door, numDoors;
|
2019-12-08 08:01:55 +01:00
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
roomsList.push_back(l->roomNumber);
|
|
|
|
door = Rooms[l->roomNumber].door;
|
|
|
|
if (door)
|
2019-12-08 08:01:55 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
numDoors = *door;
|
|
|
|
door++;
|
2019-12-17 18:46:17 +01:00
|
|
|
for (int i = 0; i < numDoors; i++)
|
2019-12-08 08:01:55 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
roomsList.push_back(*door);
|
2019-12-08 08:01:55 +01:00
|
|
|
door += 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
for (int i = 0; i < roomsList.size(); i++)
|
2019-12-08 08:01:55 +01:00
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
short itemNumber = Rooms[roomsList[i]].itemNumber;
|
2019-12-08 08:01:55 +01:00
|
|
|
while (itemNumber != NO_ITEM)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
item = &Items[itemNumber];
|
2019-12-08 08:01:55 +01:00
|
|
|
if (item->collidable && item->status != ITEM_INVISIBLE)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
obj = &Objects[item->objectNumber];
|
|
|
|
if (obj->collision)
|
2019-12-08 08:01:55 +01:00
|
|
|
{
|
|
|
|
int x = l->pos.xPos - item->pos.xPos;
|
|
|
|
int y = l->pos.yPos - item->pos.yPos;
|
|
|
|
int z = l->pos.zPos - item->pos.zPos;
|
|
|
|
|
2019-12-17 17:37:53 +01:00
|
|
|
if (x > -3072 && x < 3072 && z > -3072 && z < 3072 && y > -3072 && y < 3072)
|
2019-12-08 08:01:55 +01:00
|
|
|
(*obj->collision)(itemNumber, l, coll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itemNumber = item->nextItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (coll->enableSpaz)
|
|
|
|
{
|
2019-12-17 17:37:53 +01:00
|
|
|
MESH_INFO* mesh = Rooms[roomsList[i]].mesh;
|
|
|
|
int numMeshes = Rooms[roomsList[i]].numMeshes;
|
2019-12-08 08:01:55 +01:00
|
|
|
|
|
|
|
for (int j = 0; j < numMeshes; j++)
|
|
|
|
{
|
|
|
|
if (mesh->Flags & 1)
|
|
|
|
{
|
|
|
|
int x = l->pos.xPos - mesh->x;
|
|
|
|
int y = l->pos.yPos - mesh->y;
|
|
|
|
int z = l->pos.zPos - mesh->z;
|
|
|
|
|
|
|
|
if (x > -3072 && x < 3072 && y > -3072 && y < 3072 && z > -3072 && z < 3072)
|
|
|
|
{
|
|
|
|
PHD_3DPOS pos;
|
|
|
|
pos.xPos = mesh->x;
|
|
|
|
pos.yPos = mesh->y;
|
|
|
|
pos.zPos = mesh->z;
|
|
|
|
pos.yRot = mesh->yRot;
|
|
|
|
|
|
|
|
if (TestBoundsCollideStatic(&StaticObjects[mesh->staticNumber].xMinc, &pos, coll->radius))
|
|
|
|
ItemPushLaraStatic(l, &StaticObjects[mesh->staticNumber].xMinc, &pos, coll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Lara.hitDirection == -1)
|
|
|
|
Lara.hitFrame = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
void Inject_Collide()
|
|
|
|
{
|
|
|
|
INJECT(0x00411DB0, CollideStaticObjects);
|
2018-11-19 23:29:30 +01:00
|
|
|
INJECT(0x00413CF0, GetCollidedObjects);
|
2019-12-10 18:25:48 +01:00
|
|
|
INJECT(0x00410EF0, GetTiltType);
|
2019-12-29 01:40:55 -03:00
|
|
|
INJECT(0x00411100, GetCollisionInfo);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|