From cccd7a048b98ccfa278a345b0ff08d5260577897 Mon Sep 17 00:00:00 2001 From: Lwmte Date: Thu, 2 Sep 2021 11:32:08 +0300 Subject: [PATCH 1/5] Clarify function names # Conflicts: # TR5Main/Game/collide.cpp --- TR5Main/Game/collide.cpp | 42 +++++++++---------- TR5Main/Game/collide.h | 4 +- TR5Main/Game/door.cpp | 4 +- TR5Main/Game/flmtorch.cpp | 2 +- TR5Main/Game/traps.cpp | 2 +- .../Objects/Generic/Switches/turn_switch.cpp | 4 +- TR5Main/Objects/TR2/Entity/tr2_dragon.cpp | 2 +- TR5Main/Objects/TR2/Entity/tr2_skidman.cpp | 4 +- TR5Main/Objects/TR3/Vehicles/upv.cpp | 2 +- .../Objects/TR4/Object/tr4_element_puzzle.cpp | 2 +- TR5Main/Objects/TR4/Object/tr4_scales.cpp | 6 +-- TR5Main/Objects/TR4/Trap/tr4_blade.cpp | 2 +- TR5Main/Objects/TR4/Trap/tr4_stargate.cpp | 4 +- .../Objects/TR5/Object/tr5_rollingball.cpp | 2 +- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index 804255170..ef6b572f2 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -388,7 +388,7 @@ int TestBoundsCollideStatic(BOUNDING_BOX* bounds, PHD_3DPOS* pos, int radius) } } -int ItemPushLaraStatic(ITEM_INFO* item, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll) +int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll) { float c, s; int dx, dz, rx, rz, minX, maxX, minZ, maxZ; @@ -397,8 +397,8 @@ int ItemPushLaraStatic(ITEM_INFO* item, BOUNDING_BOX* bounds, PHD_3DPOS* pos, CO c = phd_cos(pos->yRot); s = phd_sin(pos->yRot); - dx = LaraItem->pos.xPos - pos->xPos; - dz = LaraItem->pos.zPos - pos->zPos; + dx = l->pos.xPos - pos->xPos; + dz = l->pos.zPos - pos->zPos; rx = c * dx - s * dz; rz = c * dz + s * dx; minX = bounds->X1 - coll->radius; @@ -428,40 +428,40 @@ int ItemPushLaraStatic(ITEM_INFO* item, BOUNDING_BOX* bounds, PHD_3DPOS* pos, CO else rz -= bottom; - item->pos.xPos = pos->xPos + c * rx + s * rz; - item->pos.zPos = pos->zPos + c * rz - s * rx; + l->pos.xPos = pos->xPos + c * rx + s * rz; + l->pos.zPos = pos->zPos + c * rz - s * rx; coll->badPos = NO_BAD_POS; coll->badNeg = -STEPUP_HEIGHT; coll->badCeiling = 0; oldFacing = coll->facing; - coll->facing = phd_atan(item->pos.zPos - coll->old.z, item->pos.xPos - coll->old.x); - if (item == LaraItem) + coll->facing = phd_atan(l->pos.zPos - coll->old.z, l->pos.xPos - coll->old.x); + if (l == LaraItem) { - GetCollisionInfo(coll, item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber, LARA_HEIGHT); + GetCollisionInfo(coll, l->pos.xPos, l->pos.yPos, l->pos.zPos, l->roomNumber, LARA_HEIGHT); } else { - GetObjectCollisionInfo(coll, item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber, LARA_HEIGHT); + GetObjectCollisionInfo(coll, l->pos.xPos, l->pos.yPos, l->pos.zPos, l->roomNumber, LARA_HEIGHT); } 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; + coll->old.x = l->pos.xPos; + coll->old.y = l->pos.yPos; + coll->old.z = l->pos.zPos; - UpdateLaraRoom(item, -10); + UpdateLaraRoom(l, -10); } else { - item->pos.xPos = coll->old.x; - item->pos.zPos = coll->old.z; + l->pos.xPos = coll->old.x; + l->pos.zPos = coll->old.z; } - if (item == LaraItem && Lara.isMoving && Lara.moveCount > 15) + if (l == LaraItem && Lara.isMoving && Lara.moveCount > 15) { Lara.isMoving = false; Lara.gunStatus = LG_NO_ARMS; @@ -470,7 +470,7 @@ int ItemPushLaraStatic(ITEM_INFO* item, BOUNDING_BOX* bounds, PHD_3DPOS* pos, CO return true; } -int ItemPushLara(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush) +int ItemPushItem(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush) { float c, s; int dx, dz, rx, rz, minX, maxX, minZ, maxZ; @@ -618,7 +618,7 @@ void ObjectCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c) if (TestCollision(item, l)) { if (c->enableBaddiePush) - ItemPushLara(item, l, c, false, true); + ItemPushItem(item, l, c, false, true); } } } @@ -902,7 +902,7 @@ void CreatureCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) { if (coll->enableBaddiePush || Lara.waterStatus == LW_UNDERWATER || Lara.waterStatus == LW_SURFACE) { - ItemPushLara(item, l, coll, coll->enableSpaz, 0); + ItemPushItem(item, l, coll, coll->enableSpaz, 0); } else if (coll->enableSpaz) { @@ -2585,7 +2585,7 @@ void LaraBaddieCollision(ITEM_INFO* l, COLL_INFO* coll) pos.yRot = mesh->yRot; if (TestBoundsCollideStatic(&StaticObjects[mesh->staticNumber].collisionBox, &pos, coll->radius)) - ItemPushLaraStatic(l, &StaticObjects[mesh->staticNumber].collisionBox, &pos, coll); + ItemPushStatic(l, &StaticObjects[mesh->staticNumber].collisionBox, &pos, coll); } } @@ -2639,7 +2639,7 @@ void GenericSphereBoxCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) int y = l->pos.yPos; int z = l->pos.zPos; - if (ItemPushLara(item, l, coll, ((deadlyBits & 1) & coll->enableSpaz), 3) && (deadlyBits & 1)) + if (ItemPushItem(item, l, coll, ((deadlyBits & 1) & coll->enableSpaz), 3) && (deadlyBits & 1)) { l->hitPoints -= item->itemFlags[3]; diff --git a/TR5Main/Game/collide.h b/TR5Main/Game/collide.h index 0973fd4c4..05d20aa7e 100644 --- a/TR5Main/Game/collide.h +++ b/TR5Main/Game/collide.h @@ -98,11 +98,11 @@ COLL_RESULT GetCollisionResult(int x, int y, int z, short roomNumber); COLL_RESULT GetCollisionResult(ITEM_INFO* item); int FindGridShift(int x, int z); int TestBoundsCollideStatic(BOUNDING_BOX* bounds, PHD_3DPOS* pos, int radius); -int ItemPushLaraStatic(ITEM_INFO* item, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll); +int ItemPushItem(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush); +int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll); void AIPickupCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c); void ObjectCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c); void AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* l); -int ItemPushLara(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush); int TestLaraPosition(OBJECT_COLLISION_BOUNDS* bounds, ITEM_INFO* item, ITEM_INFO* l); int Move3DPosTo3DPos(PHD_3DPOS* src, PHD_3DPOS* dest, int velocity, short angAdd); int MoveLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* l); diff --git a/TR5Main/Game/door.cpp b/TR5Main/Game/door.cpp index 47e864b30..0ab962188 100644 --- a/TR5Main/Game/door.cpp +++ b/TR5Main/Game/door.cpp @@ -440,7 +440,7 @@ void DoorCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) { if (!(item->objectNumber >= ID_LIFT_DOORS1 && item->objectNumber <= ID_LIFT_DOORS2) || item->itemFlags[0]) { - ItemPushLara(item, l, coll, FALSE, TRUE); + ItemPushItem(item, l, coll, FALSE, TRUE); } } } @@ -981,7 +981,7 @@ void SteelDoorCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll) if (TestCollision(item, l)) { if (coll->enableBaddiePush) - ItemPushLara(item, l, coll, 0, 1); + ItemPushItem(item, l, coll, 0, 1); } } } diff --git a/TR5Main/Game/flmtorch.cpp b/TR5Main/Game/flmtorch.cpp index 423f6e405..80238e988 100644 --- a/TR5Main/Game/flmtorch.cpp +++ b/TR5Main/Game/flmtorch.cpp @@ -240,7 +240,7 @@ void TorchControl(short itemNumber) pos.yPos = CollidedMeshes[0]->y; pos.zPos = CollidedMeshes[0]->z; pos.yRot = CollidedMeshes[0]->yRot; - ItemPushLaraStatic(item, &sobj->collisionBox, &pos, &lara_coll); + ItemPushStatic(item, &sobj->collisionBox, &pos, &lara_coll); } item->speed /= 2; } diff --git a/TR5Main/Game/traps.cpp b/TR5Main/Game/traps.cpp index 727b7bcee..f9413bc74 100644 --- a/TR5Main/Game/traps.cpp +++ b/TR5Main/Game/traps.cpp @@ -501,7 +501,7 @@ void WreckingBallCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* coll) z = l->pos.zPos; test = (x & 1023) > 256 && (x & 1023) < 768 && (z & 1023) > 256 && (z & 1023) < 768; damage = item->fallspeed > 0 ? 96 : 0; - if (ItemPushLara(item, l, coll, coll->enableSpaz, 1)) + if (ItemPushItem(item, l, coll, coll->enableSpaz, 1)) { if (test) l->hitPoints = 0; diff --git a/TR5Main/Objects/Generic/Switches/turn_switch.cpp b/TR5Main/Objects/Generic/Switches/turn_switch.cpp index 9b71f9493..148461625 100644 --- a/TR5Main/Objects/Generic/Switches/turn_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/turn_switch.cpp @@ -158,14 +158,14 @@ namespace TEN::Entities::Switches GlobalCollisionBounds.Z1 = -512; GlobalCollisionBounds.Z2 = 512; - ItemPushLara(item, l, coll, 0, 2); + ItemPushItem(item, l, coll, 0, 2); GlobalCollisionBounds.X1 = 256; GlobalCollisionBounds.X2 = 1024; GlobalCollisionBounds.Z1 = -128; GlobalCollisionBounds.Z2 = 128; - ItemPushLara(item, l, coll, 0, 2); + ItemPushItem(item, l, coll, 0, 2); } } diff --git a/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp b/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp index 344cc1554..3155b16b2 100644 --- a/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp +++ b/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp @@ -229,7 +229,7 @@ void DragonCollision(short itemNum, ITEM_INFO* laraitem, COLL_INFO* coll) } } - ItemPushLara(item, laraitem, coll, 1, 0); + ItemPushItem(item, laraitem, coll, 1, 0); } void DragonControl(short backNum) diff --git a/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp b/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp index 1a422c2e6..876f99eb9 100644 --- a/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp +++ b/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp @@ -67,9 +67,9 @@ void SkidManCollision(short itemNum, ITEM_INFO* laraitem, COLL_INFO* coll) if (coll->enableBaddiePush) { if (item->speed > 0) - ItemPushLara(item, laraitem, coll, coll->enableSpaz, 0); + ItemPushItem(item, laraitem, coll, coll->enableSpaz, 0); else - ItemPushLara(item, laraitem, coll, 0, 0); + ItemPushItem(item, laraitem, coll, 0, 0); } if (Lara.Vehicle == NO_ITEM && item->speed > 0) diff --git a/TR5Main/Objects/TR3/Vehicles/upv.cpp b/TR5Main/Objects/TR3/Vehicles/upv.cpp index b5ea4ccc0..ce4b67d35 100644 --- a/TR5Main/Objects/TR3/Vehicles/upv.cpp +++ b/TR5Main/Objects/TR3/Vehicles/upv.cpp @@ -850,7 +850,7 @@ void NoGetOnCollision(short item_num, ITEM_INFO *laraitem, COLL_INFO *coll) return; if (!TestCollision(item, laraitem)) return; - ItemPushLara(item, laraitem, coll, 0, 0); + ItemPushItem(item, laraitem, coll, 0, 0); } void SubCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) diff --git a/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp b/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp index 342bb56e4..b41e92549 100644 --- a/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp +++ b/TR5Main/Objects/TR4/Object/tr4_element_puzzle.cpp @@ -141,7 +141,7 @@ void ElementPuzzleDoCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c) { if (c->enableBaddiePush) { - ItemPushLara(item, l, c, 0, 0); + ItemPushItem(item, l, c, 0, 0); } } } diff --git a/TR5Main/Objects/TR4/Object/tr4_scales.cpp b/TR5Main/Objects/TR4/Object/tr4_scales.cpp index d8310d6e4..4818ad5aa 100644 --- a/TR5Main/Objects/TR4/Object/tr4_scales.cpp +++ b/TR5Main/Objects/TR4/Object/tr4_scales.cpp @@ -97,17 +97,17 @@ void ScalesCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) GlobalCollisionBounds.Z1 = -256; GlobalCollisionBounds.Z2 = 384; - ItemPushLara(item, l, coll, 0, 2); + ItemPushItem(item, l, coll, 0, 2); GlobalCollisionBounds.X1 = -256; GlobalCollisionBounds.X2 = 256; - ItemPushLara(item, l, coll, 0, 2); + ItemPushItem(item, l, coll, 0, 2); GlobalCollisionBounds.X1 = -1280; GlobalCollisionBounds.X2 = -640; - ItemPushLara(item, l, coll, 0, 2); + ItemPushItem(item, l, coll, 0, 2); } else { diff --git a/TR5Main/Objects/TR4/Trap/tr4_blade.cpp b/TR5Main/Objects/TR4/Trap/tr4_blade.cpp index 78c488b95..4235c0bf7 100644 --- a/TR5Main/Objects/TR4/Trap/tr4_blade.cpp +++ b/TR5Main/Objects/TR4/Trap/tr4_blade.cpp @@ -25,7 +25,7 @@ void BladeCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) int dy = 0; int dz = 0; - if (ItemPushLara(item, l, coll, 1, 1)) + if (ItemPushItem(item, l, coll, 1, 1)) { LaraItem->hitPoints -= item->itemFlags[3]; diff --git a/TR5Main/Objects/TR4/Trap/tr4_stargate.cpp b/TR5Main/Objects/TR4/Trap/tr4_stargate.cpp index d5199a673..4bbfa425e 100644 --- a/TR5Main/Objects/TR4/Trap/tr4_stargate.cpp +++ b/TR5Main/Objects/TR4/Trap/tr4_stargate.cpp @@ -48,7 +48,7 @@ void StargateCollision(short itemNum, ITEM_INFO* l, COLL_INFO* c) GlobalCollisionBounds.Z1 = StargateBounds[3 * i + 2]; if (TestWithGlobalCollisionBounds(item, l, c)) - ItemPushLara(item, l, c, 0, 2); + ItemPushItem(item, l, c, 0, 2); } int result = TestCollision(item, l); @@ -75,7 +75,7 @@ void StargateCollision(short itemNum, ITEM_INFO* l, COLL_INFO* c) int oldY = LaraItem->pos.yPos; int oldZ = LaraItem->pos.zPos; - if (ItemPushLara(item, l, c, flags & 1, 2)) + if (ItemPushItem(item, l, c, flags & 1, 2)) { if ((flags & 1) && (oldX != LaraItem->pos.xPos || oldY != LaraItem->pos.yPos || oldZ != LaraItem->pos.zPos) && diff --git a/TR5Main/Objects/TR5/Object/tr5_rollingball.cpp b/TR5Main/Objects/TR5/Object/tr5_rollingball.cpp index d6173f7c5..5075cb58d 100644 --- a/TR5Main/Objects/TR5/Object/tr5_rollingball.cpp +++ b/TR5Main/Objects/TR5/Object/tr5_rollingball.cpp @@ -312,7 +312,7 @@ void ClassicRollingBallCollision(short itemNum, ITEM_INFO* lara, COLL_INFO* coll if (lara->gravityStatus) { if (coll->enableBaddiePush) - ItemPushLara(item, lara, coll, coll->enableSpaz, 1); + ItemPushItem(item, lara, coll, coll->enableSpaz, 1); lara->hitPoints -= 100; x = lara->pos.xPos - item->pos.xPos; y = (lara->pos.yPos - 350) - (item->pos.yPos - 512); From fb65e6819155fcdd2d043a5ab5718c048b670cd7 Mon Sep 17 00:00:00 2001 From: Lwmte Date: Thu, 2 Sep 2021 11:20:41 +0300 Subject: [PATCH 2/5] Remove broken CollideStaticObjects function # Conflicts: # TR5Main/Game/collide.cpp --- TR5Main/Game/Lara/lara.cpp | 6 +- TR5Main/Game/collide.cpp | 91 ++--------------------- TR5Main/Game/collide.h | 3 +- TR5Main/Objects/TR3/Vehicles/biggun.cpp | 2 +- TR5Main/Objects/TR3/Vehicles/minecart.cpp | 4 +- 5 files changed, 13 insertions(+), 93 deletions(-) diff --git a/TR5Main/Game/Lara/lara.cpp b/TR5Main/Game/Lara/lara.cpp index b5270fec6..ab0c7a134 100644 --- a/TR5Main/Game/Lara/lara.cpp +++ b/TR5Main/Game/Lara/lara.cpp @@ -911,7 +911,7 @@ void LaraAboveWater(ITEM_INFO* item, COLL_INFO* coll) //hmmmm if (Lara.ExtraAnim == -1) { // Check for collision with items - LaraBaddieCollision(item, coll); + DoObjectCollision(item, coll); // Handle Lara collision if (Lara.Vehicle == NO_ITEM) @@ -1029,7 +1029,7 @@ void LaraUnderWater(ITEM_INFO* item, COLL_INFO* coll) item->pos.yPos -= item->fallspeed * phd_sin(item->pos.xRot) / 4; item->pos.zPos += phd_cos(item->pos.xRot) * item->fallspeed * phd_cos(item->pos.yRot) / 4; - LaraBaddieCollision(item, coll); + DoObjectCollision(item, coll); if (/*Lara.ExtraAnim == -1 &&*/ Lara.Vehicle == NO_ITEM) lara_collision_routines[item->currentAnimState](item, coll); @@ -1087,7 +1087,7 @@ void LaraSurface(ITEM_INFO* item, COLL_INFO* coll) item->pos.xPos += item->fallspeed * phd_sin(Lara.moveAngle) / 4; item->pos.zPos += item->fallspeed * phd_cos(Lara.moveAngle) / 4; - LaraBaddieCollision(item, coll); + DoObjectCollision(item, coll); if (Lara.Vehicle == NO_ITEM) lara_collision_routines[item->currentAnimState](item, coll); diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index ef6b572f2..834577a78 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -20,87 +20,6 @@ BOUNDING_BOX GlobalCollisionBounds; ITEM_INFO* CollidedItems[MAX_COLLIDED_OBJECTS]; MESH_INFO* CollidedMeshes[MAX_COLLIDED_OBJECTS]; -int CollideStaticObjects(COLL_INFO* coll, int x, int y, int z, short roomNumber, int hite) -{ - 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; - - coll->hitStatic = false; - - inXmin = x - coll->radius; - inXmax = x + coll->radius; - inZmin = z - coll->radius; - inZmax = z + coll->radius; - inYmin = y - hite; - - // Collect all the rooms where to check - GetRoomList(roomNumber, roomList, &numRooms); - - for (int i = 0; i < numRooms; i++) - { - room = &g_Level.Rooms[roomList[i]]; - for (int j = 0; j < room->mesh.size(); j++, mesh++) - { - mesh = &room->mesh[j]; - STATIC_INFO* sInfo = &StaticObjects[mesh->staticNumber]; - - if ((sInfo->flags & 1)) // No collision - continue; - - int yMin = mesh->y + sInfo->collisionBox.Y1; - int yMax = mesh->y + sInfo->collisionBox.Y2; - short yRot = mesh->yRot; - - if (yRot == ANGLE(180)) - { - xMin = mesh->x - sInfo->collisionBox.X2; - xMax = mesh->x - sInfo->collisionBox.X1; - zMin = mesh->z - sInfo->collisionBox.Z2; - zMax = mesh->z - sInfo->collisionBox.Z1; - } - else if (yRot == -ANGLE(90)) - { - xMin = mesh->x - sInfo->collisionBox.Z2; - xMax = mesh->x - sInfo->collisionBox.Z1; - zMin = mesh->z + sInfo->collisionBox.X1; - zMax = mesh->z + sInfo->collisionBox.X2; - } - else if (yRot == ANGLE(90)) - { - - xMin = mesh->x + sInfo->collisionBox.Z1; - xMax = mesh->x + sInfo->collisionBox.Z2; - zMin = mesh->z - sInfo->collisionBox.X2; - zMax = mesh->z - sInfo->collisionBox.X1; - } - else - { - xMin = mesh->x + sInfo->collisionBox.X1; - xMax = mesh->x + sInfo->collisionBox.X2; - zMin = mesh->z + sInfo->collisionBox.Z1; - zMax = mesh->z + sInfo->collisionBox.Z2; - } - - if (inXmax <= xMin - || inXmin >= xMax - || y <= yMin - || inYmin >= yMax - || inZmax <= zMin - || inZmin >= zMax) - continue; - - coll->hitStatic = true; - return 1; - } - } - - return 0; -} - int GetCollidedObjects(ITEM_INFO* collidingItem, int radius, int onlyVisible, ITEM_INFO** collidedItems, MESH_INFO** collidedMeshes, int ignoreLara) { ROOM_INFO* room; @@ -414,6 +333,8 @@ int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO || rz >= maxZ) return false; + coll->hitStatic = true; + left = rx - minX; top = maxZ - rz; bottom = rz - minZ; @@ -1413,8 +1334,6 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum else if (coll->lavaIsPit && coll->frontRight.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->frontRight.Floor = STOP_SIZE; - CollideStaticObjects(coll, xPos, yPos, zPos, topRoomNumber, objectHeight); - if (coll->middle.Floor == NO_HEIGHT) { coll->shift.x = coll->old.x - xPos; @@ -1853,8 +1772,6 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r coll->frontRight.Floor = STOP_SIZE; else if (coll->lavaIsPit && coll->frontRight.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->frontRight.Floor = STOP_SIZE; - - CollideStaticObjects(coll, xPos, yPos, zPos, topRoomNumber, objectHeight); if (coll->middle.Floor == NO_HEIGHT) { @@ -2521,7 +2438,7 @@ void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, ItemNewRoom(itemNumber, collResult.RoomNumber); } -void LaraBaddieCollision(ITEM_INFO* l, COLL_INFO* coll) +void DoObjectCollision(ITEM_INFO* l, COLL_INFO* coll) { ITEM_INFO* item; OBJECT_INFO* obj; @@ -2564,6 +2481,8 @@ void LaraBaddieCollision(ITEM_INFO* l, COLL_INFO* coll) itemNumber = item->nextItem; } + coll->hitStatic = false; + if (coll->enableBaddiePush) { for (int j = 0; j < g_Level.Rooms[roomsToCheck[i]].mesh.size(); j++) diff --git a/TR5Main/Game/collide.h b/TR5Main/Game/collide.h index 05d20aa7e..08860f3d0 100644 --- a/TR5Main/Game/collide.h +++ b/TR5Main/Game/collide.h @@ -86,7 +86,6 @@ extern ITEM_INFO* CollidedItems[MAX_ITEMS]; extern MESH_INFO* CollidedMeshes[MAX_ITEMS]; void GenericSphereBoxCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -int CollideStaticObjects(COLL_INFO* coll, int x, int y, int z, short roomNumber, int hite); int GetCollidedObjects(ITEM_INFO* collidingItem, int radius, int flag1, ITEM_INFO** collidedItems, MESH_INFO** collidedMeshes, int flag2); int TestWithGlobalCollisionBounds(ITEM_INFO* item, ITEM_INFO* lara, COLL_INFO* coll); void TrapCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c); @@ -111,7 +110,7 @@ void CreatureCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight); void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight); void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, int zv); -void LaraBaddieCollision(ITEM_INFO* item, COLL_INFO* coll); +void DoObjectCollision(ITEM_INFO* item, COLL_INFO* coll); bool ItemNearLara(PHD_3DPOS* pos, int radius); bool ItemNearTarget(PHD_3DPOS* src, ITEM_INFO* target, int radius); bool SnapToQuadrant(short& angle, int interval); diff --git a/TR5Main/Objects/TR3/Vehicles/biggun.cpp b/TR5Main/Objects/TR3/Vehicles/biggun.cpp index 1ca748a82..feb5f484f 100644 --- a/TR5Main/Objects/TR3/Vehicles/biggun.cpp +++ b/TR5Main/Objects/TR3/Vehicles/biggun.cpp @@ -302,7 +302,7 @@ int BigGunControl(COLL_INFO *coll) coll->enableSpaz = false; coll->enableBaddiePush = false; - LaraBaddieCollision(lara, coll); + DoObjectCollision(lara, coll); Camera.targetElevation = -ANGLE(15); return 1; diff --git a/TR5Main/Objects/TR3/Vehicles/minecart.cpp b/TR5Main/Objects/TR3/Vehicles/minecart.cpp index 343508f3e..5b4cfbda7 100644 --- a/TR5Main/Objects/TR3/Vehicles/minecart.cpp +++ b/TR5Main/Objects/TR3/Vehicles/minecart.cpp @@ -733,7 +733,9 @@ static void DoUserInput(ITEM_INFO* v, ITEM_INFO* l, CART_INFO* cart) coll.quadrant = short((v->pos.yRot + 0x2000) / 0x4000); coll.radius = CART_RADIUS; - if (CollideStaticObjects(&coll, v->pos.xPos, v->pos.yPos, v->pos.zPos, v->roomNumber, CART_HEIGHT)) + DoObjectCollision(v, &coll); + + if (coll.hitStatic) { int hits; From 7e3e4856e09420a40362db92365d59b20b500843 Mon Sep 17 00:00:00 2001 From: Lwmte Date: Thu, 2 Sep 2021 22:28:55 +0300 Subject: [PATCH 3/5] Fix two collision bugs --- TR5Main/Game/Lara/lara_crawl.cpp | 1 + TR5Main/Game/collide.cpp | 45 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/TR5Main/Game/Lara/lara_crawl.cpp b/TR5Main/Game/Lara/lara_crawl.cpp index 2797ab4b2..f05269041 100644 --- a/TR5Main/Game/Lara/lara_crawl.cpp +++ b/TR5Main/Game/Lara/lara_crawl.cpp @@ -431,6 +431,7 @@ void lara_col_all4s(ITEM_INFO* item, COLL_INFO* coll) } auto collResult = LaraCollisionFront(item, item->pos.yRot, -300); + height = collResult.FloorHeight; if (abs(height) >= 255 || collResult.HeightType == BIG_SLOPE) { diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index 834577a78..cbc68d6a7 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -333,8 +333,6 @@ int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO || rz >= maxZ) return false; - coll->hitStatic = true; - left = rx - minX; top = maxZ - rz; bottom = rz - minZ; @@ -2444,7 +2442,10 @@ void DoObjectCollision(ITEM_INFO* l, COLL_INFO* coll) OBJECT_INFO* obj; l->hitStatus = false; - Lara.hitDirection = -1; + coll->hitStatic = false; + + if (l == LaraItem) + Lara.hitDirection = -1; if (l->hitPoints > 0) { @@ -2481,39 +2482,39 @@ void DoObjectCollision(ITEM_INFO* l, COLL_INFO* coll) itemNumber = item->nextItem; } - coll->hitStatic = false; - - if (coll->enableBaddiePush) + for (int j = 0; j < g_Level.Rooms[roomsToCheck[i]].mesh.size(); j++) { - for (int j = 0; j < g_Level.Rooms[roomsToCheck[i]].mesh.size(); j++) + MESH_INFO* mesh = &g_Level.Rooms[roomsToCheck[i]].mesh[j]; + + if (mesh->flags & 1) { - MESH_INFO* mesh = &g_Level.Rooms[roomsToCheck[i]].mesh[j]; + int x = l->pos.xPos - mesh->x; + int y = l->pos.yPos - mesh->y; + int z = l->pos.zPos - mesh->z; - if (mesh->flags & 1) + if (x > -3072 && x < 3072 && y > -3072 && y < 3072 && z > -3072 && z < 3072) { - int x = l->pos.xPos - mesh->x; - int y = l->pos.yPos - mesh->y; - int z = l->pos.zPos - mesh->z; + PHD_3DPOS pos; + pos.xPos = mesh->x; + pos.yPos = mesh->y; + pos.zPos = mesh->z; + pos.yRot = mesh->yRot; - if (x > -3072 && x < 3072 && y > -3072 && y < 3072 && z > -3072 && z < 3072) + if (TestBoundsCollideStatic(&StaticObjects[mesh->staticNumber].collisionBox, &pos, coll->radius)) { - PHD_3DPOS pos; - pos.xPos = mesh->x; - pos.yPos = mesh->y; - pos.zPos = mesh->z; - pos.yRot = mesh->yRot; + coll->hitStatic = true; - if (TestBoundsCollideStatic(&StaticObjects[mesh->staticNumber].collisionBox, &pos, coll->radius)) + if (coll->enableBaddiePush) ItemPushStatic(l, &StaticObjects[mesh->staticNumber].collisionBox, &pos, coll); + else + break; } } - - mesh++; } } } - if (Lara.hitDirection == -1) + if (l == LaraItem && Lara.hitDirection == -1) Lara.hitFrame = 0; } } From 14e189db8492c38d3550b0ec78e6b390f51877ce Mon Sep 17 00:00:00 2001 From: Lwmte Date: Thu, 2 Sep 2021 22:40:33 +0300 Subject: [PATCH 4/5] Add comments with previous function names --- TR5Main/Game/collide.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index cbc68d6a7..fb6353212 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -307,7 +307,7 @@ int TestBoundsCollideStatic(BOUNDING_BOX* bounds, PHD_3DPOS* pos, int radius) } } -int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll) +int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO* coll) // previously ItemPushLaraStatic { float c, s; int dx, dz, rx, rz, minX, maxX, minZ, maxZ; @@ -389,7 +389,7 @@ int ItemPushStatic(ITEM_INFO* l, BOUNDING_BOX* bounds, PHD_3DPOS* pos, COLL_INFO return true; } -int ItemPushItem(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush) +int ItemPushItem(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, int spazon, char bigpush) // previously ItemPushLara { float c, s; int dx, dz, rx, rz, minX, maxX, minZ, maxZ; @@ -1947,7 +1947,7 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r } } -void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, int zv) +void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, int zv) // previously DoProperDetection { int bs, yang; @@ -2436,7 +2436,7 @@ void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, ItemNewRoom(itemNumber, collResult.RoomNumber); } -void DoObjectCollision(ITEM_INFO* l, COLL_INFO* coll) +void DoObjectCollision(ITEM_INFO* l, COLL_INFO* coll) // previously LaraBaddieCollision { ITEM_INFO* item; OBJECT_INFO* obj; From ea13ab0aaa9ca85ced5f2f336f75b58d7c1a7897 Mon Sep 17 00:00:00 2001 From: MontyTRC89 Date: Sat, 4 Sep 2021 07:53:21 +0200 Subject: [PATCH 5/5] Cleaned collision code; Cleaning AI code; Usin visibility for for statics culling; Fixed Lara crawling; --- TR5Main/Game/Lara/lara_crawl.cpp | 2 +- TR5Main/Game/box.cpp | 100 ++++++++++++++++----------- TR5Main/Game/collide.cpp | 82 ++-------------------- TR5Main/Game/items.cpp | 4 +- TR5Main/Renderer/Renderer11Frame.cpp | 4 +- 5 files changed, 71 insertions(+), 121 deletions(-) diff --git a/TR5Main/Game/Lara/lara_crawl.cpp b/TR5Main/Game/Lara/lara_crawl.cpp index f05269041..5065da89d 100644 --- a/TR5Main/Game/Lara/lara_crawl.cpp +++ b/TR5Main/Game/Lara/lara_crawl.cpp @@ -481,7 +481,7 @@ void lara_col_all4s(ITEM_INFO* item, COLL_INFO* coll) } } } - else if (!(abs(height) >= 127)) + else if (!(abs(height) >= STEP_SIZE)) { item->goalAnimState = LS_CRAWL_BACK; } diff --git a/TR5Main/Game/box.cpp b/TR5Main/Game/box.cpp index fb7d51d13..4357e4d27 100644 --- a/TR5Main/Game/box.cpp +++ b/TR5Main/Game/box.cpp @@ -1026,7 +1026,10 @@ int SearchLOT(LOT_INFO* LOT, int depth) continue; delta = g_Level.Boxes[boxNumber].height - box->height; - if ((delta > LOT->step || delta < LOT->drop) && !((flags & BOX_MONKEY) && LOT->canMonkey)) + if ((delta > LOT->step || delta < LOT->drop) && (!(flags & BOX_MONKEY) || !LOT->canMonkey)) + continue; + + if ((flags & BOX_JUMP) && !LOT->canJump) continue; expand = &LOT->node[boxNumber]; @@ -1119,9 +1122,8 @@ int StalkBox(ITEM_INFO* item, ITEM_INFO* enemy, int boxNumber) if (x > xrange || x < -xrange || z > zrange || z < -zrange) return false; - enemyQuad = enemy->pos.yRot / 16384 + 2; + enemyQuad = enemy->pos.yRot / ANGLE(90) + 2; - // boxQuad = (z <= 0 ? (x <= 0 ? 0 : 3) : (x > 0) + 1); if (z > 0) boxQuad = (x > 0) ? 2 : 1; else @@ -1157,13 +1159,20 @@ int CreatureVault(short itemNum, short angle, int vault, int shift) CreatureAnimation(itemNum, angle, 0); - if (item->floor > y + CHECK_CLICK(13) && creature->LOT.drop == -1792) - vault = -7; + if (item->floor > y + CHECK_CLICK(9)) + vault = 0; else if (item->floor > y + CHECK_CLICK(7)) vault = -4; - else if (item->floor > y + CHECK_CLICK(5)) + // FIXME: edit assets adding climb down animations for Von Croy and baddies? + else if (item->floor > y + CHECK_CLICK(5) + && item->objectNumber != ID_VON_CROY + && item->objectNumber != ID_BADDY1 + && item->objectNumber != ID_BADDY2) vault = -3; - else if (item->floor > y + CHECK_CLICK(3) && item->objectNumber != ID_BADDY1 && item->objectNumber != ID_BADDY2) // Baddy 1&2 don't have some climb down animations + else if (item->floor > y + CHECK_CLICK(3) + && item->objectNumber != ID_VON_CROY + && item->objectNumber != ID_BADDY1 + && item->objectNumber != ID_BADDY2) vault = -2; else if (item->pos.yPos > y - CHECK_CLICK(3)) return 0; @@ -1171,11 +1180,10 @@ int CreatureVault(short itemNum, short angle, int vault, int shift) vault = 2; else if (item->pos.yPos > y - CHECK_CLICK(7)) vault = 3; - else if (item->pos.yPos > y - CHECK_CLICK(15) && creature->LOT.step == 1792) - vault = 7; else vault = 4; + // Jump newXblock = item->pos.xPos / SECTOR(1); newZblock = item->pos.zPos / SECTOR(1); @@ -1233,7 +1241,7 @@ void GetAITarget(CREATURE_INFO* creature) enemyObjectNumber = NO_ITEM; item = &g_Level.Items[creature->itemNum]; - + if (item->aiBits & GUARD) { creature->enemy = LaraItem; @@ -1243,7 +1251,7 @@ void GetAITarget(CREATURE_INFO* creature) if (item->aiBits & AMBUSH) item->aiBits |= MODIFY; } - } + } else if (item->aiBits & PATROL1) { if (creature->alerted || creature->hurtByLara) @@ -1252,20 +1260,24 @@ void GetAITarget(CREATURE_INFO* creature) if (item->aiBits & AMBUSH) { item->aiBits |= MODIFY; - item->itemFlags[3] = (item->TOSSPAD & 0xFF); + // NOTE: added in TR5 + //item->itemFlags[3] = (item->TOSSPAD & 0xFF); } } - else if (!creature->patrol2 && enemyObjectNumber != ID_AI_PATROL1) + else if (!creature->patrol2) { - FindAITargetObject(creature, ID_AI_PATROL1); + if (enemyObjectNumber != ID_AI_PATROL1) + { + FindAITargetObject(creature, ID_AI_PATROL1); + } } - else if (creature->patrol2 && enemyObjectNumber != ID_AI_PATROL2) + else if (enemyObjectNumber != ID_AI_PATROL2) { FindAITargetObject(creature, ID_AI_PATROL2); } else if (abs(enemy->pos.xPos - item->pos.xPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS + abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS && + abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS || Objects[item->objectNumber].waterCreature) { TestTriggers(enemy, true, NULL); @@ -1274,29 +1286,33 @@ void GetAITarget(CREATURE_INFO* creature) } else if (item->aiBits & AMBUSH) { - if (!(item->aiBits & MODIFY) && !creature->hurtByLara) + // First if was removed probably after TR3 and was it used by monkeys? + /*if (!(item->aiBits & MODIFY) && !creature->hurtByLara) { creature->enemy = LaraItem; } - else if (enemyObjectNumber != ID_AI_AMBUSH) + else*/ if (enemyObjectNumber != ID_AI_AMBUSH) { FindAITargetObject(creature, ID_AI_AMBUSH); } - else if (item->objectNumber == ID_MONKEY) + /*else if (item->objectNumber == ID_MONKEY) { return; - } + }*/ else if (abs(enemy->pos.xPos - item->pos.xPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS) + abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS && + abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS) { TestTriggers(enemy, true, NULL); creature->reachedGoal = true; creature->enemy = LaraItem; - item->aiBits &= ~(AMBUSH|MODIFY); - item->aiBits |= GUARD; - creature->alerted = false; + item->aiBits &= ~(AMBUSH /* | MODIFY*/); + if (item->aiBits != MODIFY) + { + item->aiBits |= GUARD; + creature->alerted = false; + } } } else if (item->aiBits & FOLLOW) @@ -1315,15 +1331,15 @@ void GetAITarget(CREATURE_INFO* creature) { FindAITargetObject(creature, ID_AI_FOLLOW); } - else if (abs(enemy->pos.xPos - item->pos.xPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS && - abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS) + else if (abs(enemy->pos.xPos - item->pos.xPos) < REACHED_GOAL_RADIUS && + abs(enemy->pos.yPos - item->pos.yPos) < REACHED_GOAL_RADIUS && + abs(enemy->pos.zPos - item->pos.zPos) < REACHED_GOAL_RADIUS) { creature->reachedGoal = true; item->aiBits &= ~FOLLOW; } } - else if (item->objectNumber == ID_MONKEY && item->carriedItem == NO_ITEM) + /*else if (item->objectNumber == ID_MONKEY && item->carriedItem == NO_ITEM) { if (item->aiBits != MODIFY) { @@ -1339,10 +1355,10 @@ void GetAITarget(CREATURE_INFO* creature) FindAITargetObject(creature, ID_KEY_ITEM4); } } - } + }*/ } -// tr3 old way.. +// TR3 old way.. void FindAITarget(CREATURE_INFO* creature, short objectNumber) { ITEM_INFO* item = &g_Level.Items[creature->itemNum]; @@ -1384,6 +1400,11 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber) r = &g_Level.Rooms[aiObject->roomNumber]; aiObject->boxNumber = XZ_GET_SECTOR(r, aiObject->x - r->x, aiObject->z - r->z).box; + if (item->boxNumber == NO_BOX || aiObject->boxNumber == NO_BOX) + { + return; + } + if (zone[item->boxNumber] == zone[aiObject->boxNumber]) { foundObject = aiObject; @@ -1491,11 +1512,12 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info) } info->angle = angle - item->pos.yRot; - info->enemyFacing = -ANGLE(180) + angle - enemy->pos.yRot; + info->enemyFacing = 0x8000 + angle - enemy->pos.yRot; x = abs(x); z = abs(z); + // Makes Lara smaller if (enemy == LaraItem) { short laraState = LaraItem->currentAnimState; @@ -1511,9 +1533,9 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info) } if (x > z) - info->xAngle = phd_atan(x + (z / 2), y); + info->xAngle = phd_atan(x + (z >> 1), y); else - info->xAngle = phd_atan(z + (x / 2), y); + info->xAngle = phd_atan(z + (x >> 1), y); info->ahead = (info->angle > -FRONT_ARC && info->angle < FRONT_ARC); info->bite = (info->ahead && enemy->hitPoints > 0 && abs(enemy->pos.yPos - item->pos.yPos) <= (STEP_SIZE * 2)); @@ -1537,7 +1559,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) switch (creature->mood) { case BORED_MOOD: - boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount / 32768].boxNumber; + boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount >> 15].boxNumber; if (ValidBox(item, info->zoneNumber, boxNumber) && !(GetRandomControl() & 0x0F)) { @@ -1567,7 +1589,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) break; case ESCAPE_MOOD: - boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount / 32768].boxNumber; + boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount >> 15].boxNumber; if (ValidBox(item, info->zoneNumber, boxNumber) && LOT->requiredBox == NO_BOX) { if (EscapeBox(item, enemy, boxNumber)) @@ -1585,7 +1607,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) case STALK_MOOD: if (LOT->requiredBox == NO_BOX || !StalkBox(item, enemy, LOT->requiredBox)) { - boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount / 32768].boxNumber; + boxNumber = LOT->node[GetRandomControl() * LOT->zoneCount >> 15].boxNumber; if (ValidBox(item, info->zoneNumber, boxNumber)) { if (StalkBox(item, enemy, boxNumber)) @@ -1625,7 +1647,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) { nextBox = g_Level.Overlaps[overlapIndex].box; flags = g_Level.Overlaps[overlapIndex++].flags; - } while (nextBox != NO_BOX && ((flags & BOX_END_BIT) == FALSE) && (nextBox != startBox)); + } while (nextBox != NO_BOX && ((flags & BOX_END_BIT) == false) && (nextBox != startBox)); } if (nextBox == startBox) diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index fb6353212..39e63dde3 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -1067,17 +1067,15 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum int yTop = y - LARA_HEADROOM; int z = zPos; - ROOM_VECTOR tfLocation = GetRoom(LaraItem->location, x, yTop, z); - auto collResult = GetCollisionResult(x, yTop, z, roomNumber); auto topRoomNumber = collResult.RoomNumber; // Keep top room number as we need it to re-probe from origin room + ROOM_VECTOR tfLocation = GetRoom(LaraItem->location, x, yTop, z); int height = GetFloorHeight(tfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; ROOM_VECTOR tcLocation = GetRoom(LaraItem->location, x, yTop - LaraItem->fallspeed, z); - int ceiling = GetCeilingHeight(tcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1139,13 +1137,6 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum break; } - //XFront = phd_sin(coll->facing) * coll->radius; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //ZFront = phd_cos(coll->facing) * coll->radius; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //xleft = -ZFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //zleft = XFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //xright = ZFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //zright = -XFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - x = xfront + xPos; z = zfront + zPos; @@ -1156,18 +1147,14 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum topRoomNumber = roomNumber; } - tfLocation = GetRoom(tfLocation, x, yTop, z); - - //floor = GetFloor(x, yTop, z, &tRoomNumber); - //DoFloorThings(floor, x, yTop, z); collResult = GetCollisionResult(x, yTop, z, topRoomNumber); + tfLocation = GetRoom(tfLocation, x, yTop, z); height = GetFloorHeight(tfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; tcLocation = GetRoom(tcLocation, x, yTop - LaraItem->fallspeed, z); - ceiling = GetCeilingHeight(tcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1178,8 +1165,6 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum coll->front.SplitFloor = collResult.SplitFloor; coll->front.SplitCeiling = collResult.SplitCeiling; - //floor = GetFloor(x + XFront, yTop, z + ZFront, &tRoomNumber); - //DoFloorThings(floor, x + XFront, yTop, z + ZFront); collResult = GetCollisionResult(x + xfront, yTop, z + zfront, topRoomNumber); tfLocation = GetRoom(tfLocation, x + xfront, yTop, z + zfront); @@ -1211,19 +1196,14 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum x = xPos + xleft; z = zPos + zleft; - ROOM_VECTOR lrfLocation = GetRoom(LaraItem->location, x, yTop, z); - - //short lrRoomNumber = roomNumber; - //floor = GetFloor(x, yTop, z, &lrRoomNumber); - //DoFloorThings(floor, x, yTop, z); collResult = GetCollisionResult(x, yTop, z, roomNumber); + ROOM_VECTOR lrfLocation = GetRoom(LaraItem->location, x, yTop, z); height = GetFloorHeight(lrfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; ROOM_VECTOR lrcLocation = GetRoom(LaraItem->location, x, yTop - LaraItem->fallspeed, z); - ceiling = GetCeilingHeight(lrcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1241,18 +1221,14 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum else if (coll->lavaIsPit && coll->middleLeft.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->middleLeft.Floor = STOP_SIZE; - tfLocation = GetRoom(tfLocation, x, yTop, z); - - //floor = GetFloor(x + XFront, yTop, z + ZFront, &tRoomNumber); // WRONG COPYPASTE BY CHOCO - //DoFloorThings(floor, x, yTop, z); collResult = GetCollisionResult(x, yTop, z, topRoomNumber); // We use plain x/z values here, proposed by Choco + tfLocation = GetRoom(tfLocation, x, yTop, z); height = GetFloorHeight(tfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; tcLocation = GetRoom(tcLocation, x, yTop - LaraItem->fallspeed, z); - ceiling = GetCeilingHeight(tcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1273,19 +1249,14 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum x = xPos + xright; z = zPos + zright; - lrfLocation = GetRoom(LaraItem->location, x, yTop, z); - - //lrRoomNumber = roomNumber; - //floor = GetFloor(x, yTop, z, &lrRoomNumber); - //DoFloorThings(floor, x, yTop, z); collResult = GetCollisionResult(x, yTop, z, roomNumber); + lrfLocation = GetRoom(LaraItem->location, x, yTop, z); height = GetFloorHeight(lrfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; lrcLocation = GetRoom(LaraItem->location, x, yTop - LaraItem->fallspeed, z); - ceiling = GetCeilingHeight(lrcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1303,18 +1274,14 @@ void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNum else if (coll->lavaIsPit && coll->middleRight.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->middleRight.Floor = STOP_SIZE; - tfLocation = GetRoom(tfLocation, x, yTop, z); - - //floor = GetFloor(x, yTop, z, &tRoomNumber); - //DoFloorThings(floor, x, yTop, z); collResult = GetCollisionResult(x, yTop, z, topRoomNumber); + tfLocation = GetRoom(tfLocation, x, yTop, z); height = GetFloorHeight(tfLocation, x, z).value_or(NO_HEIGHT); if (height != NO_HEIGHT) height -= yPos; tcLocation = GetRoom(tcLocation, x, yTop - LaraItem->fallspeed, z); - ceiling = GetCeilingHeight(tcLocation, x, z).value_or(NO_HEIGHT); if (ceiling != NO_HEIGHT) ceiling -= y; @@ -1532,9 +1499,6 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r int yTop = y - LARA_HEADROOM; int z = zPos; - //short tRoomNumber = roomNumber; - //FLOOR_INFO* floor = GetFloor(x, yTop, z, &tRoomNumber); - //int height = GetFloorHeight(floor, x, yTop, z); auto collResult = GetCollisionResult(x, yTop, z, roomNumber); auto topRoomNumber = collResult.RoomNumber; @@ -1602,23 +1566,12 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r break; } - //XFront = phd_sin(coll->facing) * coll->radius; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //ZFront = phd_cos(coll->facing) * coll->radius; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //xleft = -ZFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //zleft = XFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //xright = ZFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - //zright = -XFront; // WAS COMMENTED BEFORE LWMTE FLOORDATA REFACTOR! - x = xfront + xPos; z = zfront + zPos; if (resetRoom) topRoomNumber = roomNumber; - //floor = GetFloor(x, yTop, z, &tRoomNumber); - // - //height = GetFloorHeight(floor, x, yTop, z); - collResult = GetCollisionResult(x, yTop, z, topRoomNumber); if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; @@ -1633,10 +1586,7 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r coll->front.SplitFloor = collResult.SplitFloor; coll->front.SplitCeiling = collResult.SplitCeiling; - //floor = GetFloor(x + XFront, yTop, z + ZFront, &tRoomNumber); - //height = GetFloorHeight(floor, x + XFront, yTop, z + ZFront); collResult = GetCollisionResult(x + xfront, yTop, z + zfront, topRoomNumber); - if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; @@ -1664,11 +1614,6 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r x = xPos + xleft; z = zPos + zleft; - //short lrRoomNumber = roomNumber; - //floor = GetFloor(x, yTop, z, &lrRoomNumber); - // - //height = GetFloorHeight(floor, x, yTop, z); - collResult = GetCollisionResult(x + xfront, yTop, z + zfront, roomNumber); if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; @@ -1690,10 +1635,6 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r else if (coll->lavaIsPit && coll->middleLeft.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->middleLeft.Floor = STOP_SIZE; - //floor = GetFloor(x, yTop, z, &tRoomNumber); - // - //height = GetFloorHeight(floor, x, yTop, z); - collResult = GetCollisionResult(x, yTop, z, topRoomNumber); if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; @@ -1718,13 +1659,7 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r x = xPos + xright; z = zPos + zright; - //lrRoomNumber = roomNumber; - //floor = GetFloor(x, yTop, z, &lrRoomNumber); - // - //height = GetFloorHeight(floor, x, yTop, z); - collResult = GetCollisionResult(x, yTop, z, roomNumber); - if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; @@ -1745,12 +1680,7 @@ void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int r else if (coll->lavaIsPit && coll->middleRight.Floor > 0 && collResult.BottomBlock->Flags.Death) coll->middleRight.Floor = STOP_SIZE; - //floor = GetFloor(x, yTop, z, &tRoomNumber); - // - //height = GetFloorHeight(floor, x, yTop, z); - collResult = GetCollisionResult(x, yTop, z, topRoomNumber); - if (collResult.FloorHeight != NO_HEIGHT) collResult.FloorHeight -= yPos; diff --git a/TR5Main/Game/items.cpp b/TR5Main/Game/items.cpp index a70ea4110..4176fda69 100644 --- a/TR5Main/Game/items.cpp +++ b/TR5Main/Game/items.cpp @@ -14,9 +14,7 @@ void ClearItem(short itemNum) item->collidable = true; item->data = NULL; - item->drawRoom = (((item->pos.zPos - room->z) / SECTOR(1)) & 0xFF) | ((((item->pos.xPos - room->x) / SECTOR(1)) & 0xFF) * 256); - item->TOSSPAD = item->pos.yRot & 0xE000; - item->itemFlags[2] = item->roomNumber | ((item->pos.yPos - room->minfloor) & 0xFF00); + item->startPos = item->pos; } void KillItem(short itemNum) diff --git a/TR5Main/Renderer/Renderer11Frame.cpp b/TR5Main/Renderer/Renderer11Frame.cpp index 571783c10..f7c4fec3d 100644 --- a/TR5Main/Renderer/Renderer11Frame.cpp +++ b/TR5Main/Renderer/Renderer11Frame.cpp @@ -87,8 +87,8 @@ namespace TEN::Renderer { RendererStatic* newStatic = &room.Statics[i]; STATIC_INFO* sinfo = &StaticObjects[mesh->staticNumber]; - Vector3 min = Vector3(sinfo->collisionBox.X1, sinfo->collisionBox.Y1, sinfo->collisionBox.Z1); - Vector3 max = Vector3(sinfo->collisionBox.X2, sinfo->collisionBox.Y2, sinfo->collisionBox.Z2); + Vector3 min = Vector3(sinfo->visibilityBox.X1, sinfo->visibilityBox.Y1, sinfo->visibilityBox.Z1); + Vector3 max = Vector3(sinfo->visibilityBox.X2, sinfo->visibilityBox.Y2, sinfo->visibilityBox.Z2); min += Vector3(mesh->x, mesh->y, mesh->z); max += Vector3(mesh->x, mesh->y, mesh->z); if (!renderView.camera.frustum.AABBInFrustum(min, max))