This commit is contained in:
Trxye 2021-06-15 14:09:56 -05:00
commit cec71ac156
2 changed files with 131 additions and 38 deletions

View file

@ -7,6 +7,7 @@
#include "objectslist.h"
#include "sound.h"
#include "camera.h"
#include "lara.h"
void InitialiseExpandingPlatform(short itemNumber)
{
@ -29,6 +30,130 @@ void InitialiseExpandingPlatform(short itemNumber)
T5M::Floordata::AddBridge(itemNumber);
}
bool IsOnExpandingPlatform(ITEM_INFO item, int x, int z)
{
if (item.itemFlags[1] <= 0)
return false;
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 (item.pos.yRot == ANGLE(90))
{
auto xBorder = item.pos.xPos + CLICK(2) - SECTOR(1) * item.itemFlags[1] / 4096;
if (x < xBorder || zb != itemzb || xb != itemxb)
return false;
}
else if (item.pos.yRot == ANGLE(270))
{
auto xBorder = item.pos.xPos - CLICK(2) + SECTOR(1) * item.itemFlags[1] / 4096;
if (x > xBorder || zb != itemzb || xb != itemxb)
return false;
}
else if (item.pos.yRot == 0)
{
auto zBorder = item.pos.zPos + CLICK(2) - SECTOR(1) * item.itemFlags[1] / 4096;
if (z < zBorder || zb != itemzb || xb != itemxb)
return false;
}
else if (item.pos.yRot == ANGLE(180))
{
auto zBorder = item.pos.zPos - CLICK(2) + SECTOR(1) * item.itemFlags[1] / 4096;
if (z > zBorder || zb != itemzb || xb != itemxb)
return false;
}
return true;
}
bool IsInFrontOfExpandingPlatform(ITEM_INFO item, int x, int y, int z, int margin)
{
if (item.itemFlags[1] <= 0)
return false;
const auto topHeight = item.pos.yPos - item.itemFlags[7] + CLICK(2);
const auto bottomHeight = item.pos.yPos + CLICK(2);
if (LaraItem->pos.yPos < topHeight - 32 || LaraItem->pos.yPos > bottomHeight + 32)
return false;
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 (item.pos.yRot == ANGLE(90))
{
auto xBorder = item.pos.xPos + CLICK(2) - margin - SECTOR(1) * item.itemFlags[1] / 4096;
auto xBorder2 = item.pos.xPos + CLICK(2);
if (x < xBorder || zb != itemzb || x > xBorder2)
return false;
}
else if (item.pos.yRot == ANGLE(270))
{
auto xBorder = item.pos.xPos - CLICK(2) + margin + SECTOR(1) * item.itemFlags[1] / 4096;
auto xBorder2 = item.pos.xPos - CLICK(2);
if (x > xBorder || zb != itemzb || x < xBorder2)
return false;
}
else if (item.pos.yRot == 0)
{
auto zBorder = item.pos.zPos + CLICK(2) - margin - SECTOR(1) * item.itemFlags[1] / 4096;
auto zBorder2 = item.pos.zPos + CLICK(2);
if (z < zBorder || xb != itemxb || z > zBorder2)
return false;
}
else if (item.pos.yRot == ANGLE(180))
{
auto zBorder = item.pos.zPos - CLICK(2) + margin + SECTOR(1) * item.itemFlags[1] / 4096;
auto zBorder2 = item.pos.zPos - CLICK(2);
if (z > zBorder || xb != itemxb || z < zBorder2)
return false;
}
return true;
}
void ShiftLaraOnPlatform(short itemNumber, bool isExpanding)
{
ITEM_INFO item = g_Level.Items[itemNumber];
short angle = item.pos.yRot;
int xShift = 0;
int zShift = 0;
if (item.itemFlags[1] <= 0)
return;
const auto height = item.pos.yPos - item.itemFlags[7] + CLICK(2);
if (IsOnExpandingPlatform(item, LaraItem->pos.xPos, LaraItem->pos.zPos))
{
//Slide Lara if on top of platform
if (LaraItem->pos.yPos < height - 32 || LaraItem->pos.yPos > height + 32)
return;
if (angle == ANGLE(0))
zShift = isExpanding ? -16 : 16;
else if (angle == ANGLE(180))
zShift = isExpanding ? 16 : -16;
else if (angle == ANGLE(90))
xShift = isExpanding ? -16 : 16;
else if (angle == -ANGLE(90))
xShift = isExpanding ? 16 : -16;
} else if (isExpanding && IsInFrontOfExpandingPlatform(item, LaraItem->pos.xPos, LaraItem->pos.yPos, LaraItem->pos.zPos,64))
{
//Push Lara if in front of expanding platform
if (angle == ANGLE(0))
zShift = -16;
else if (angle == ANGLE(180))
zShift = 16;
else if (angle == ANGLE(90))
xShift = -16;
else if (angle == -ANGLE(90))
xShift = 16;
}
auto coll = lara_coll;
GetCollisionInfo(&coll, LaraItem->pos.xPos + xShift, LaraItem->pos.yPos, LaraItem->pos.zPos + zShift, LaraItem->roomNumber, LARA_HITE);
if (coll.midCeiling >= 0 || coll.hitStatic)
return;
if (zShift != 0)
LaraItem->pos.zPos += zShift;
if (xShift != 0)
LaraItem->pos.xPos += xShift;
}
void ControlExpandingPlatform(short itemNumber)
{
ITEM_INFO* item = &g_Level.Items[itemNumber];
@ -49,7 +174,7 @@ void ControlExpandingPlatform(short itemNumber)
SoundEffect(SFX_TR4_BLK_PLAT_RAISE_AND_LOW, &item->pos, 0);
item->itemFlags[1] += 64;
ShiftLaraOnPlatform(itemNumber, true);
if (item->triggerFlags > 0)
{
if (abs(item->pos.xPos - Camera.pos.x) < 10240 &&
@ -69,19 +194,6 @@ void ControlExpandingPlatform(short itemNumber)
if (item->itemFlags[2])
{
item->itemFlags[1] = 0;
if (item->objectNumber == ID_RAISING_BLOCK1)
{
if (item->triggerFlags == -1)
{
item->itemFlags[2] = 0;
}
else if (item->triggerFlags == -3)
{
item->itemFlags[2] = 0;
}
}
item->itemFlags[2] = 0;
}
}
@ -103,36 +215,15 @@ void ControlExpandingPlatform(short itemNumber)
}
item->itemFlags[1] -= 64;
ShiftLaraOnPlatform(itemNumber, false);
}
}
std::optional<int> ExpandingPlatformFloor(short itemNumber, int x, int y, int z)
{
const auto& item = g_Level.Items[itemNumber];
if (item.itemFlags[1] <= 0)
if (!IsOnExpandingPlatform(item, x, z))
return std::nullopt;
if (item.pos.yRot == ANGLE(90))
{
auto xBorder = item.pos.xPos + CLICK(2) - SECTOR(1) * item.itemFlags[1] / 4096;
if(x < xBorder)
return std::nullopt;
} else if (item.pos.yRot == ANGLE(270))
{
auto xBorder = item.pos.xPos - CLICK(2) + SECTOR(1) * item.itemFlags[1] / 4096;
if (x > xBorder)
return std::nullopt;
} else if (item.pos.yRot == 0)
{
auto zBorder = item.pos.zPos + CLICK(2) - SECTOR(1) * item.itemFlags[1] / 4096;
if (z < zBorder)
return std::nullopt;
}
else if (item.pos.yRot == ANGLE(180))
{
auto zBorder = item.pos.zPos - CLICK(2) + SECTOR(1) * item.itemFlags[1] / 4096;
if (z > zBorder)
return std::nullopt;
}
const auto height = item.pos.yPos - item.itemFlags[7] + CLICK(2);
return std::optional{ height };
}
@ -140,6 +231,8 @@ std::optional<int> ExpandingPlatformFloor(short itemNumber, int x, int y, int z)
std::optional<int> ExpandingPlatformCeiling(short itemNumber, int x, int y, int z)
{
const auto& item = g_Level.Items[itemNumber];
if (!IsOnExpandingPlatform(item, x, z))
return std::nullopt;
return std::optional{ item.pos.yPos + CLICK(2) + 1 };
}

View file

@ -5,4 +5,4 @@ void ControlExpandingPlatform(short itemNumber);
std::optional<int> ExpandingPlatformFloor(short itemNumber, int x, int y, int z);
std::optional<int> ExpandingPlatformCeiling(short itemNumber, int x, int y, int z);
int ExpandingPlatformFloorBorder(short itemNumber);
int ExpandingPlatformCeilingBorder(short itemNumber);
int ExpandingPlatformCeilingBorder(short itemNumber);