TombEngine/TR5Main/Objects/TR5/Object/tr5_twoblockplatform.cpp

161 lines
3.8 KiB
C++
Raw Normal View History

#include "framework.h"
#include "tr5_twoblockplatform.h"
#include "level.h"
#include "control.h"
#include "items.h"
#include "lara.h"
#include "sound.h"
void InitialiseTwoBlocksPlatform(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
item->itemFlags[0] = item->pos.yPos;
item->itemFlags[1] = 1;
T5M::Floordata::AddBridge(itemNumber);
}
BOOL IsOnTwoBlocksPlatform(ITEM_INFO* item, int x, int z)
{
if (!item->meshBits)
2020-07-07 07:32:33 +02:00
return false;
short angle = item->pos.yRot;
int xb = x / SECTOR(1);
int zb = z / SECTOR(1);
int itemxb = item->pos.xPos / SECTOR(1);
int itemzb = item->pos.zPos / SECTOR(1);
if (!angle && (xb == itemxb || xb == itemxb - 1) && (zb == itemzb || zb == itemzb + 1))
2020-07-07 07:32:33 +02:00
return true;
if (angle == -ANGLE(180) && (xb == itemxb || xb == itemxb + 1) && (zb == itemzb || zb == itemzb - 1))
2020-07-07 07:32:33 +02:00
return true;
if (angle == ANGLE(90) && (zb == itemzb || zb == itemzb - 1) && (xb == itemxb || xb == itemxb + 1))
2020-07-07 07:32:33 +02:00
return true;
if (angle == -ANGLE(90) && (zb == itemzb || zb == itemzb - 1) && (xb == itemxb || xb == itemxb - 1))
2020-07-07 07:32:33 +02:00
return true;
2020-07-07 07:32:33 +02:00
return false;
}
std::optional<int> TwoBlocksPlatformFloor(short itemNumber, int x, int y, int z)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
ROOM_INFO* r = &g_Level.Rooms[item->roomNumber];
FLOOR_INFO* floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
int height = floor->FloorHeight(x, z);
if (IsOnTwoBlocksPlatform(item, x, z))
{
if (y <= (item->pos.yPos + 32) && item->pos.yPos < height)
{
height = item->pos.yPos;
OnObject = true;
HeightType = WALL;
}
}
return std::optional{ height };
}
void TwoBlocksPlatformControl(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
if (TriggerActive(item))
{
if (item->triggerFlags)
{
if (item->pos.yPos > (item->itemFlags[0] - 16 * (item->triggerFlags & 0xFFFFFFF0)))
{
item->pos.yPos -= item->triggerFlags & 0xF;
}
short roomNumber = item->roomNumber;
FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &roomNumber);
item->floor = GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos);
if (roomNumber != item->roomNumber)
ItemNewRoom(itemNumber, roomNumber);
}
else
{
OnObject = false;
int height = LaraItem->pos.yPos + 1;
if (IsOnTwoBlocksPlatform(item, LaraItem->pos.xPos, LaraItem->pos.zPos))
{
if (LaraItem->pos.yPos <= item->pos.yPos + 32)
{
if (item->pos.yPos < height)
{
OnObject = true;
}
}
}
if (OnObject && LaraItem->animNumber != LA_HOP_BACK_CONTINUE)
item->itemFlags[1] = 1;
else
item->itemFlags[1] = -1;
if (item->itemFlags[1] < 0)
{
if (item->pos.yPos <= item->itemFlags[0])
{
item->itemFlags[1] = 1;
}
else
{
SoundEffect(SFX_TR4_RUMBLE_NEXTDOOR, &item->pos, 0);
item->pos.yPos -= 4;
}
}
else if (item->itemFlags[1] > 0)
{
if (item->pos.yPos >= item->itemFlags[0] + 128)
{
item->itemFlags[1] = -1;
}
else
{
SoundEffect(SFX_TR4_RUMBLE_NEXTDOOR, &item->pos, 0);
item->pos.yPos += 4;
}
}
}
}
}
std::optional<int> TwoBlocksPlatformCeiling(short itemNumber, int x, int y, int z)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
ROOM_INFO* r = &g_Level.Rooms[item->roomNumber];
FLOOR_INFO* floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z);
int height = floor->FloorHeight(x, z);
if (IsOnTwoBlocksPlatform(item, x, z))
{
if (y > item->pos.yPos + 32 && item->pos.yPos > height)
{
height = item->pos.yPos + 256;
}
}
return std::optional{ height };
}
int TwoBlocksPlatformFloorBorder(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
return item->pos.yPos;
}
int TwoBlocksPlatformCeilingBorder(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
return (item->pos.yPos + 256);
}