2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef GAME_COLLISION_H
|
|
|
|
#define GAME_COLLISION_H
|
|
|
|
|
|
|
|
#include <base/vmath.h>
|
2014-01-01 21:34:10 +00:00
|
|
|
#include <engine/shared/protocol.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2010-09-26 02:25:05 +00:00
|
|
|
#include <list>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2018-08-15 15:47:07 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
CANTMOVE_LEFT=1<<0,
|
|
|
|
CANTMOVE_RIGHT=1<<1,
|
|
|
|
CANTMOVE_UP=1<<2,
|
|
|
|
CANTMOVE_DOWN=1<<3,
|
|
|
|
};
|
|
|
|
|
|
|
|
vec2 ClampVel(int MoveRestriction, vec2 Vel);
|
|
|
|
|
|
|
|
typedef bool (*CALLBACK_SWITCHACTIVE)(int Number, void *pUser);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class CCollision
|
|
|
|
{
|
|
|
|
class CTile *m_pTiles;
|
|
|
|
int m_Width;
|
|
|
|
int m_Height;
|
|
|
|
class CLayers *m_pLayers;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CCollision();
|
2017-07-21 14:02:24 +00:00
|
|
|
~CCollision();
|
2010-05-29 07:25:38 +00:00
|
|
|
void Init(class CLayers *pLayers);
|
2014-04-22 21:46:55 +00:00
|
|
|
bool CheckPoint(float x, float y) { return IsSolid(round_to_int(x), round_to_int(y)); }
|
2011-02-13 06:47:51 +00:00
|
|
|
bool CheckPoint(vec2 Pos) { return CheckPoint(Pos.x, Pos.y); }
|
2014-04-22 21:46:55 +00:00
|
|
|
int GetCollisionAt(float x, float y) { return GetTile(round_to_int(x), round_to_int(y)); }
|
2010-05-29 07:25:38 +00:00
|
|
|
int GetWidth() { return m_Width; };
|
|
|
|
int GetHeight() { return m_Height; };
|
2015-11-08 09:20:44 +00:00
|
|
|
int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
|
|
|
|
int IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr);
|
|
|
|
int IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr);
|
2011-02-12 09:30:47 +00:00
|
|
|
void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces);
|
2018-08-22 06:33:28 +00:00
|
|
|
void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, float Elasticity);
|
2010-05-29 07:25:38 +00:00
|
|
|
bool TestBox(vec2 Pos, vec2 Size);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
|
|
|
void Dest();
|
2015-11-08 09:20:10 +00:00
|
|
|
void SetCollisionAt(float x, float y, int id);
|
2010-11-13 13:22:19 +00:00
|
|
|
void SetDTile(float x, float y, bool State);
|
|
|
|
void SetDCollisionAt(float x, float y, int Type, int Flags, int Number);
|
|
|
|
int GetDTileIndex(int Index);
|
|
|
|
int GetDTileFlags(int Index);
|
|
|
|
int GetDTileNumber(int Index);
|
2014-04-22 21:46:55 +00:00
|
|
|
int GetFCollisionAt(float x, float y) { return GetFTile(round_to_int(x), round_to_int(y)); }
|
2010-08-10 04:28:17 +00:00
|
|
|
int IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
|
2010-08-21 17:34:33 +00:00
|
|
|
int IntersectNoLaserNW(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
|
2010-08-10 04:28:17 +00:00
|
|
|
int IntersectAir(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision);
|
2010-11-05 11:56:44 +00:00
|
|
|
int GetIndex(int x, int y);
|
2013-07-18 22:27:17 +00:00
|
|
|
int GetIndex(vec2 PrevPos, vec2 Pos);
|
2010-11-05 11:56:44 +00:00
|
|
|
int GetFIndex(int x, int y);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2019-10-06 11:51:16 +00:00
|
|
|
int GetMoveRestrictions(CALLBACK_SWITCHACTIVE pfnSwitchActive, void *pUser, vec2 Pos, float Distance = 18.0f, int OverrideCenterTileIndex = -1);
|
2018-08-15 15:47:07 +00:00
|
|
|
int GetMoveRestrictions(vec2 Pos, float Distance = 18.0f)
|
|
|
|
{
|
|
|
|
return GetMoveRestrictions(0, 0, Pos, Distance);
|
|
|
|
}
|
|
|
|
|
2010-08-10 04:28:17 +00:00
|
|
|
int GetTile(int x, int y);
|
2010-08-21 19:48:47 +00:00
|
|
|
int GetFTile(int x, int y);
|
2010-11-13 13:22:19 +00:00
|
|
|
int Entity(int x, int y, int Layer);
|
2015-11-08 09:20:44 +00:00
|
|
|
int GetPureMapIndex(float x, float y);
|
|
|
|
int GetPureMapIndex(vec2 Pos) { return GetPureMapIndex(Pos.x, Pos.y); }
|
2010-10-26 23:17:11 +00:00
|
|
|
std::list<int> GetMapIndices(vec2 PrevPos, vec2 Pos, unsigned MaxIndices = 0);
|
2011-01-29 23:58:47 +00:00
|
|
|
int GetMapIndex(vec2 Pos);
|
2011-02-06 18:38:24 +00:00
|
|
|
bool TileExists(int Index);
|
2011-02-10 00:08:13 +00:00
|
|
|
bool TileExistsNext(int Index);
|
2010-08-10 04:28:17 +00:00
|
|
|
vec2 GetPos(int Index);
|
2010-09-22 15:07:45 +00:00
|
|
|
int GetTileIndex(int Index);
|
|
|
|
int GetFTileIndex(int Index);
|
2010-11-01 01:51:17 +00:00
|
|
|
int GetTileFlags(int Index);
|
|
|
|
int GetFTileFlags(int Index);
|
2010-09-22 12:03:59 +00:00
|
|
|
int IsTeleport(int Index);
|
|
|
|
int IsEvilTeleport(int Index);
|
2011-05-17 23:12:39 +00:00
|
|
|
int IsCheckTeleport(int Index);
|
2014-02-01 21:20:41 +00:00
|
|
|
int IsCheckEvilTeleport(int Index);
|
2013-08-13 02:59:25 +00:00
|
|
|
int IsTeleportWeapon(int Index);
|
|
|
|
int IsTeleportHook(int Index);
|
2011-05-17 23:12:39 +00:00
|
|
|
int IsTCheckpoint(int Index);
|
2010-09-22 12:17:00 +00:00
|
|
|
int IsSpeedup(int Index);
|
2014-03-12 22:12:50 +00:00
|
|
|
int IsTune(int Index);
|
2010-09-22 17:43:23 +00:00
|
|
|
void GetSpeedup(int Index, vec2 *Dir, int *Force, int *MaxSpeed);
|
2010-11-13 13:22:19 +00:00
|
|
|
int IsSwitch(int Index);
|
2010-11-22 20:43:22 +00:00
|
|
|
int GetSwitchNumber(int Index);
|
|
|
|
int GetSwitchDelay(int Index);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-08-10 04:28:17 +00:00
|
|
|
int IsSolid(int x, int y);
|
2015-11-12 18:46:27 +00:00
|
|
|
bool IsThrough(int x, int y, int xoff, int yoff, vec2 pos0, vec2 pos1);
|
2015-11-12 18:46:52 +00:00
|
|
|
bool IsHookBlocker(int x, int y, vec2 pos0, vec2 pos1);
|
2014-06-21 16:14:22 +00:00
|
|
|
int IsWallJump(int Index);
|
2010-08-10 04:28:17 +00:00
|
|
|
int IsNoLaser(int x, int y);
|
2010-08-21 19:48:47 +00:00
|
|
|
int IsFNoLaser(int x, int y);
|
2010-10-30 18:48:30 +00:00
|
|
|
|
2010-08-23 19:37:27 +00:00
|
|
|
int IsCheckpoint(int Index);
|
2010-10-30 18:48:30 +00:00
|
|
|
int IsFCheckpoint(int Index);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2017-03-21 10:24:44 +00:00
|
|
|
int IsMover(int x, int y, int *pFlags);
|
2010-08-10 04:28:17 +00:00
|
|
|
|
2010-11-01 01:51:17 +00:00
|
|
|
vec2 CpSpeed(int index, int Flags = 0);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2010-08-27 23:30:50 +00:00
|
|
|
class CTeleTile *TeleLayer() { return m_pTele; }
|
2010-11-13 13:22:19 +00:00
|
|
|
class CSwitchTile *SwitchLayer() { return m_pSwitch; }
|
2014-03-12 22:12:50 +00:00
|
|
|
class CTuneTile *TuneLayer() { return m_pTune; }
|
2010-08-10 04:28:17 +00:00
|
|
|
class CLayers *Layers() { return m_pLayers; }
|
2010-11-22 20:43:22 +00:00
|
|
|
int m_NumSwitchers;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
class CTeleTile *m_pTele;
|
|
|
|
class CSpeedupTile *m_pSpeedup;
|
|
|
|
class CTile *m_pFront;
|
|
|
|
class CSwitchTile *m_pSwitch;
|
2014-03-12 22:12:50 +00:00
|
|
|
class CTuneTile *m_pTune;
|
2011-04-09 06:41:31 +00:00
|
|
|
class CDoorTile *m_pDoor;
|
|
|
|
struct SSwitchers
|
|
|
|
{
|
2014-01-01 21:34:10 +00:00
|
|
|
bool m_Status[MAX_CLIENTS];
|
2015-07-22 21:31:50 +00:00
|
|
|
bool m_Initial;
|
2014-01-01 21:34:10 +00:00
|
|
|
int m_EndTick[MAX_CLIENTS];
|
|
|
|
int m_Type[MAX_CLIENTS];
|
2011-04-09 06:41:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2017-03-21 10:24:44 +00:00
|
|
|
SSwitchers *m_pSwitchers;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2011-01-07 23:26:17 +00:00
|
|
|
void ThroughOffset(vec2 Pos0, vec2 Pos1, int *Ox, int *Oy);
|
2010-05-29 07:25:38 +00:00
|
|
|
#endif
|