TombEngine/TR5Main/Game/collide.h

164 lines
5.2 KiB
C
Raw Normal View History

2020-12-21 13:16:29 -03:00
#pragma once
2021-09-08 18:31:35 +03:00
#include "Specific\phd_global.h"
Merge branch 'master' into item_data # Conflicts: # TR5Main/Game/Lara/lara.cpp # TR5Main/Game/Lara/lara_collide.cpp # TR5Main/Game/Lara/lara_monkey.cpp # TR5Main/Game/Lara/lara_struct.h # TR5Main/Game/Lara/lara_tests.cpp # TR5Main/Game/collide.h # TR5Main/Game/control.h # TR5Main/Game/effect.h # TR5Main/Game/effect2.cpp # TR5Main/Game/flipeffect.cpp # TR5Main/Game/floordata.h # TR5Main/Game/hair.cpp # TR5Main/Game/health.cpp # TR5Main/Game/items.cpp # TR5Main/Game/newinv2.cpp # TR5Main/Game/spotcam.cpp # TR5Main/Objects/Effects/tr4_bubbles.cpp # TR5Main/Objects/TR1/Entity/tr1_ape.cpp # TR5Main/Objects/TR1/Entity/tr1_bigrat.cpp # TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp # TR5Main/Objects/TR2/Entity/tr2_birdmonster.cpp # TR5Main/Objects/TR2/Entity/tr2_shark.cpp # TR5Main/Objects/TR2/Entity/tr2_spider.cpp # TR5Main/Objects/TR2/Entity/tr2_yeti.cpp # TR5Main/Objects/TR3/Entity/tr3_fishemitter.cpp # TR5Main/Objects/TR3/Entity/tr3_flamethrower.cpp # TR5Main/Objects/TR3/Entity/tr3_monkey.cpp # TR5Main/Objects/TR3/Entity/tr3_raptor.cpp # TR5Main/Objects/TR3/Entity/tr3_scuba.cpp # TR5Main/Objects/TR3/Entity/tr3_trex.cpp # TR5Main/Objects/TR3/Vehicles/kayak.cpp # TR5Main/Objects/TR3/Vehicles/minecart.cpp # TR5Main/Objects/TR4/Entity/tr4_bat.cpp # TR5Main/Objects/TR4/Entity/tr4_big_beetle.cpp # TR5Main/Objects/TR4/Entity/tr4_bigscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_demigod.cpp # TR5Main/Objects/TR4/Entity/tr4_dog.cpp # TR5Main/Objects/TR4/Entity/tr4_hammerhead.cpp # TR5Main/Objects/TR4/Entity/tr4_harpy.cpp # TR5Main/Objects/TR4/Entity/tr4_mutant.cpp # TR5Main/Objects/TR4/Entity/tr4_smallscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_troops.cpp # TR5Main/Objects/TR4/Entity/tr4_wildboar.cpp # TR5Main/Objects/TR4/Trap/tr4_joby_spikes.cpp # TR5Main/Objects/TR4/Vehicles/motorbike.cpp # TR5Main/Objects/TR5/Entity/tr5_doberman.cpp # TR5Main/Objects/TR5/Entity/tr5_imp.cpp # TR5Main/Objects/TR5/Entity/tr5_larson.cpp # TR5Main/Objects/TR5/Entity/tr5_lion.cpp # TR5Main/Objects/TR5/Entity/tr5_reaper.cpp # TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp # TR5Main/Objects/TR5/Object/tr5_rollingball.cpp # TR5Main/Objects/TR5/Trap/tr5_fallingceiling.cpp # TR5Main/Renderer/Renderer11Draw2D.cpp # TR5Main/Specific/input.cpp # TR5Main/Specific/level.cpp # TR5Main/TombEngine.vcxproj.filters
2021-08-31 17:37:15 +02:00
#include "trmath.h"
2021-09-10 18:29:13 +03:00
2021-08-28 13:27:58 +02:00
struct ITEM_INFO;
struct COLL_INFO;
Merge branch 'master' into item_data # Conflicts: # TR5Main/Game/Lara/lara.cpp # TR5Main/Game/Lara/lara_collide.cpp # TR5Main/Game/Lara/lara_monkey.cpp # TR5Main/Game/Lara/lara_struct.h # TR5Main/Game/Lara/lara_tests.cpp # TR5Main/Game/collide.h # TR5Main/Game/control.h # TR5Main/Game/effect.h # TR5Main/Game/effect2.cpp # TR5Main/Game/flipeffect.cpp # TR5Main/Game/floordata.h # TR5Main/Game/hair.cpp # TR5Main/Game/health.cpp # TR5Main/Game/items.cpp # TR5Main/Game/newinv2.cpp # TR5Main/Game/spotcam.cpp # TR5Main/Objects/Effects/tr4_bubbles.cpp # TR5Main/Objects/TR1/Entity/tr1_ape.cpp # TR5Main/Objects/TR1/Entity/tr1_bigrat.cpp # TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp # TR5Main/Objects/TR2/Entity/tr2_birdmonster.cpp # TR5Main/Objects/TR2/Entity/tr2_shark.cpp # TR5Main/Objects/TR2/Entity/tr2_spider.cpp # TR5Main/Objects/TR2/Entity/tr2_yeti.cpp # TR5Main/Objects/TR3/Entity/tr3_fishemitter.cpp # TR5Main/Objects/TR3/Entity/tr3_flamethrower.cpp # TR5Main/Objects/TR3/Entity/tr3_monkey.cpp # TR5Main/Objects/TR3/Entity/tr3_raptor.cpp # TR5Main/Objects/TR3/Entity/tr3_scuba.cpp # TR5Main/Objects/TR3/Entity/tr3_trex.cpp # TR5Main/Objects/TR3/Vehicles/kayak.cpp # TR5Main/Objects/TR3/Vehicles/minecart.cpp # TR5Main/Objects/TR4/Entity/tr4_bat.cpp # TR5Main/Objects/TR4/Entity/tr4_big_beetle.cpp # TR5Main/Objects/TR4/Entity/tr4_bigscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_demigod.cpp # TR5Main/Objects/TR4/Entity/tr4_dog.cpp # TR5Main/Objects/TR4/Entity/tr4_hammerhead.cpp # TR5Main/Objects/TR4/Entity/tr4_harpy.cpp # TR5Main/Objects/TR4/Entity/tr4_mutant.cpp # TR5Main/Objects/TR4/Entity/tr4_smallscorpion.cpp # TR5Main/Objects/TR4/Entity/tr4_troops.cpp # TR5Main/Objects/TR4/Entity/tr4_wildboar.cpp # TR5Main/Objects/TR4/Trap/tr4_joby_spikes.cpp # TR5Main/Objects/TR4/Vehicles/motorbike.cpp # TR5Main/Objects/TR5/Entity/tr5_doberman.cpp # TR5Main/Objects/TR5/Entity/tr5_imp.cpp # TR5Main/Objects/TR5/Entity/tr5_larson.cpp # TR5Main/Objects/TR5/Entity/tr5_lion.cpp # TR5Main/Objects/TR5/Entity/tr5_reaper.cpp # TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp # TR5Main/Objects/TR5/Object/tr5_rollingball.cpp # TR5Main/Objects/TR5/Trap/tr5_fallingceiling.cpp # TR5Main/Renderer/Renderer11Draw2D.cpp # TR5Main/Specific/input.cpp # TR5Main/Specific/level.cpp # TR5Main/TombEngine.vcxproj.filters
2021-08-31 17:37:15 +02:00
struct FLOOR_INFO;
struct MESH_INFO;
2020-12-21 13:16:29 -03:00
2021-09-10 18:29:13 +03:00
constexpr auto NO_BAD_POS = (-NO_HEIGHT); // used by coll->Setup.BadHeightUp
constexpr auto NO_BAD_NEG = NO_HEIGHT; // used by coll->Setup.BadHeightDown
constexpr auto MAX_COLLIDED_OBJECTS = 1024;
constexpr auto COLLISION_CHECK_DISTANCE = 6144;
constexpr auto ITEM_RADIUS_YMAX = SECTOR(3);
2021-09-10 18:29:13 +03:00
extern BOUNDING_BOX GlobalCollisionBounds;
extern ITEM_INFO* CollidedItems[MAX_COLLIDED_OBJECTS];
extern MESH_INFO* CollidedMeshes[MAX_COLLIDED_OBJECTS];
2021-09-07 20:37:31 +03:00
2021-09-10 00:18:47 +03:00
enum COLL_TYPE
{
CT_NONE = 0, // 0x00
CT_FRONT = (1 << 0), // 0x01
CT_LEFT = (1 << 1), // 0x02
CT_RIGHT = (1 << 2), // 0x04
CT_TOP = (1 << 3), // 0x08
CT_TOP_FRONT = (1 << 4), // 0x10
CT_CLAMP = (1 << 5) // 0x20
};
2021-09-13 03:20:53 +03:00
enum SPLIT_COLL
{
SPLIT_NONE,
SPLIT_SOLID,
SPLIT_PORTAL
};
2021-09-13 23:44:52 +03:00
enum SPLAT_COLL
{
SPLAT_NONE,
SPLAT_WALL,
SPLAT_STEP
};
2021-09-10 00:43:26 +03:00
enum HEIGHT_TYPE
{
2021-09-10 00:43:26 +03:00
WALL,
SMALL_SLOPE,
BIG_SLOPE,
DIAGONAL,
SPLIT_TRI
};
2021-08-26 19:00:50 +03:00
struct COLL_POSITION
2020-12-21 13:16:29 -03:00
{
2021-08-25 06:54:17 +03:00
int Floor;
int Ceiling;
2021-09-10 00:43:26 +03:00
HEIGHT_TYPE Type;
};
struct COLL_RESULT
{
int RoomNumber;
FLOOR_INFO* Block;
FLOOR_INFO* BottomBlock;
COLL_POSITION Position;
int TiltX;
int TiltZ;
2020-12-21 13:16:29 -03:00
};
2021-09-10 00:18:47 +03:00
struct COLL_SETUP
{
bool SlopesAreWalls; // Treat steep slopes as walls
bool SlopesArePits; // Treat steep slopes as pits
bool DeathFlagIsPit; // Treat death sectors as pits
2021-09-10 00:18:47 +03:00
bool EnableObjectPush; // Can be pushed by objects
bool EnableSpaz; // Push is treated as hurt
int Radius; // Collision bounds horizontal size
short ForwardAngle; // Forward angle direction
int BadHeightUp; // Borderline step-up height
int BadHeightDown; // Borderline step-down height
int BadCeilingHeight; // Borderline ceiling height
PHD_VECTOR OldPosition; // Preserve old parameters to restore later
short OldAnimState;
short OldAnimNumber;
short OldFrameNumber;
};
2020-12-21 13:16:29 -03:00
struct COLL_INFO
{
2021-09-10 00:43:26 +03:00
COLL_SETUP Setup; // In parameters
2021-09-10 00:18:47 +03:00
COLL_POSITION Middle;
COLL_POSITION MiddleLeft;
COLL_POSITION MiddleRight;
COLL_POSITION Front;
COLL_POSITION FrontLeft;
COLL_POSITION FrontRight;
PHD_VECTOR Shift;
COLL_TYPE CollisionType;
int TiltX;
int TiltZ;
bool HitStatic;
bool HitTallBounds;
int ObjectHeadroom;
2020-12-21 13:16:29 -03:00
};
struct OBJECT_COLLISION_BOUNDS
{
BOUNDING_BOX boundingBox;
short rotX1;
short rotX2;
short rotY1;
short rotY2;
short rotZ1;
short rotZ2;
};
void GenericSphereBoxCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll);
2021-09-13 10:15:53 +03:00
bool GetCollidedObjects(ITEM_INFO* collidingItem, int radius, int flag1, ITEM_INFO** collidedItems, MESH_INFO** collidedMeshes, int flag2);
bool TestWithGlobalCollisionBounds(ITEM_INFO* item, ITEM_INFO* lara, COLL_INFO* coll);
2020-12-21 13:16:29 -03:00
void TrapCollision(short itemNumber, ITEM_INFO* l, COLL_INFO* c);
void TestForObjectOnLedge(ITEM_INFO* item, COLL_INFO* coll);
void ShiftItem(ITEM_INFO* item, COLL_INFO* coll);
void UpdateLaraRoom(ITEM_INFO* item, int height);
2021-09-13 03:20:53 +03:00
SPLIT_COLL CheckNoColCeilingTriangle(FLOOR_INFO* floor, int x, int z);
SPLIT_COLL CheckNoColFloorTriangle(FLOOR_INFO* floor, int x, int z);
COLL_RESULT GetCollisionResult(FLOOR_INFO* floor, int x, int y, int z);
COLL_RESULT GetCollisionResult(int x, int y, int z, short roomNumber);
COLL_RESULT GetCollisionResult(ITEM_INFO* item);
2021-09-07 20:37:31 +03:00
int FindGridShift(int x, int z);
2021-09-13 10:15:53 +03:00
bool TestBoundsCollideStatic(ITEM_INFO* item, MESH_INFO* mesh, int radius);
bool ItemPushItem(ITEM_INFO* item, ITEM_INFO* l, COLL_INFO* coll, bool spazon, char bigpush);
bool ItemPushStatic(ITEM_INFO* l, MESH_INFO* mesh, COLL_INFO* coll);
2020-12-21 13:16:29 -03:00
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);
2021-09-13 10:15:53 +03:00
bool TestLaraPosition(OBJECT_COLLISION_BOUNDS* bounds, ITEM_INFO* item, ITEM_INFO* l);
bool Move3DPosTo3DPos(PHD_3DPOS* src, PHD_3DPOS* dest, int velocity, short angAdd);
bool MoveLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* l);
bool TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* l, int radius);
2020-12-21 13:16:29 -03:00
void CreatureCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll);
2021-09-10 12:14:28 +03:00
void GetCollisionInfo(COLL_INFO* coll, ITEM_INFO* item, PHD_VECTOR offset, int objectHeight);
void GetCollisionInfo(COLL_INFO* coll, ITEM_INFO* item, int objectHeight);
void GetObjectCollisionInfo(COLL_INFO* coll, ITEM_INFO* item, PHD_VECTOR offset, int objectHeight);
void GetObjectCollisionInfo(COLL_INFO* coll, ITEM_INFO* item, int objectHeight);
void DoProjectileDynamics(short itemNumber, int x, int y, int z, int xv, int yv, int zv);
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);
2020-12-21 13:16:29 -03:00
bool SnapToQuadrant(short& angle, int interval);
int GetQuadrant(short angle);
bool SnapToDiagonal(short& angle, int interval);
void CalcItemToFloorRotation(ITEM_INFO* item, int radiusDivide = 1);
Vector2 GetOrthogonalIntersect(int xPos, int zPos, int radius, short yRot); // find xPos, zPos near sector bound, offset by radius;
bool CollideSolidBounds(ITEM_INFO* item, BOUNDING_BOX box, PHD_3DPOS pos, COLL_INFO* coll);
2021-09-07 20:37:31 +03:00
void CollideSolidStatics(ITEM_INFO* item, COLL_INFO* coll);