1 | /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ |
2 | /* If you are missing that file, acquire a complete release at teeworlds.com. */ |
3 | #ifndef GAME_COLLISION_H |
4 | #define GAME_COLLISION_H |
5 | |
6 | #include <base/vmath.h> |
7 | #include <engine/shared/protocol.h> |
8 | |
9 | #include <map> |
10 | #include <vector> |
11 | |
12 | enum |
13 | { |
14 | CANTMOVE_LEFT = 1 << 0, |
15 | CANTMOVE_RIGHT = 1 << 1, |
16 | CANTMOVE_UP = 1 << 2, |
17 | CANTMOVE_DOWN = 1 << 3, |
18 | }; |
19 | |
20 | vec2 ClampVel(int MoveRestriction, vec2 Vel); |
21 | |
22 | typedef bool (*CALLBACK_SWITCHACTIVE)(int Number, void *pUser); |
23 | struct CAntibotMapData; |
24 | |
25 | class CCollision |
26 | { |
27 | class CTile *m_pTiles; |
28 | int m_Width; |
29 | int m_Height; |
30 | class CLayers *m_pLayers; |
31 | |
32 | public: |
33 | CCollision(); |
34 | ~CCollision(); |
35 | void Init(class CLayers *pLayers); |
36 | void FillAntibot(CAntibotMapData *pMapData); |
37 | bool CheckPoint(float x, float y) const { return IsSolid(x: round_to_int(f: x), y: round_to_int(f: y)); } |
38 | bool CheckPoint(vec2 Pos) const { return CheckPoint(x: Pos.x, y: Pos.y); } |
39 | int GetCollisionAt(float x, float y) const { return GetTile(x: round_to_int(f: x), y: round_to_int(f: y)); } |
40 | int GetWidth() const { return m_Width; } |
41 | int GetHeight() const { return m_Height; } |
42 | int IntersectLine(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const; |
43 | int IntersectLineTeleWeapon(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr = nullptr) const; |
44 | int IntersectLineTeleHook(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision, int *pTeleNr = nullptr) const; |
45 | void MovePoint(vec2 *pInoutPos, vec2 *pInoutVel, float Elasticity, int *pBounces) const; |
46 | void MoveBox(vec2 *pInoutPos, vec2 *pInoutVel, vec2 Size, vec2 Elasticity, bool *pGrounded = nullptr) const; |
47 | bool TestBox(vec2 Pos, vec2 Size) const; |
48 | |
49 | // DDRace |
50 | |
51 | void Dest(); |
52 | void SetCollisionAt(float x, float y, int id); |
53 | void SetDTile(float x, float y, bool State); |
54 | void SetDCollisionAt(float x, float y, int Type, int Flags, int Number); |
55 | int GetDTileIndex(int Index) const; |
56 | int GetDTileFlags(int Index) const; |
57 | int GetDTileNumber(int Index) const; |
58 | int GetFCollisionAt(float x, float y) const { return GetFTile(x: round_to_int(f: x), y: round_to_int(f: y)); } |
59 | int IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const; |
60 | int IntersectNoLaserNW(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const; |
61 | int IntersectAir(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) const; |
62 | int GetIndex(int x, int y) const; |
63 | int GetIndex(vec2 PrevPos, vec2 Pos) const; |
64 | int GetFIndex(int x, int y) const; |
65 | |
66 | int GetMoveRestrictions(CALLBACK_SWITCHACTIVE pfnSwitchActive, void *pUser, vec2 Pos, float Distance = 18.0f, int OverrideCenterTileIndex = -1) const; |
67 | int GetMoveRestrictions(vec2 Pos, float Distance = 18.0f) |
68 | { |
69 | return GetMoveRestrictions(pfnSwitchActive: nullptr, pUser: nullptr, Pos, Distance); |
70 | } |
71 | |
72 | int GetTile(int x, int y) const; |
73 | int GetFTile(int x, int y) const; |
74 | int Entity(int x, int y, int Layer) const; |
75 | int GetPureMapIndex(float x, float y) const; |
76 | int GetPureMapIndex(vec2 Pos) const { return GetPureMapIndex(x: Pos.x, y: Pos.y); } |
77 | std::vector<int> GetMapIndices(vec2 PrevPos, vec2 Pos, unsigned MaxIndices = 0) const; |
78 | int GetMapIndex(vec2 Pos) const; |
79 | bool TileExists(int Index) const; |
80 | bool TileExistsNext(int Index) const; |
81 | vec2 GetPos(int Index) const; |
82 | int GetTileIndex(int Index) const; |
83 | int GetFTileIndex(int Index) const; |
84 | int GetTileFlags(int Index) const; |
85 | int GetFTileFlags(int Index) const; |
86 | int IsTeleport(int Index) const; |
87 | int IsEvilTeleport(int Index) const; |
88 | bool IsCheckTeleport(int Index) const; |
89 | bool IsCheckEvilTeleport(int Index) const; |
90 | int IsTeleportWeapon(int Index) const; |
91 | int IsTeleportHook(int Index) const; |
92 | int IsTeleCheckpoint(int Index) const; |
93 | int IsSpeedup(int Index) const; |
94 | int IsTune(int Index) const; |
95 | void GetSpeedup(int Index, vec2 *pDir, int *pForce, int *pMaxSpeed) const; |
96 | int GetSwitchType(int Index) const; |
97 | int GetSwitchNumber(int Index) const; |
98 | int GetSwitchDelay(int Index) const; |
99 | |
100 | int IsSolid(int x, int y) const; |
101 | bool IsThrough(int x, int y, int xoff, int yoff, vec2 pos0, vec2 pos1) const; |
102 | bool IsHookBlocker(int x, int y, vec2 pos0, vec2 pos1) const; |
103 | int IsWallJump(int Index) const; |
104 | int IsNoLaser(int x, int y) const; |
105 | int IsFNoLaser(int x, int y) const; |
106 | |
107 | int IsTimeCheckpoint(int Index) const; |
108 | int IsFTimeCheckpoint(int Index) const; |
109 | |
110 | int IsMover(int x, int y, int *pFlags) const; |
111 | |
112 | vec2 CpSpeed(int index, int Flags = 0) const; |
113 | |
114 | class CTeleTile *TeleLayer() { return m_pTele; } |
115 | class CSwitchTile *SwitchLayer() { return m_pSwitch; } |
116 | class CTuneTile *TuneLayer() { return m_pTune; } |
117 | class CLayers *Layers() { return m_pLayers; } |
118 | int m_HighestSwitchNumber; |
119 | |
120 | const std::vector<vec2> &TeleIns(int Number) { return m_TeleIns[Number]; } |
121 | const std::vector<vec2> &TeleOuts(int Number) { return m_TeleOuts[Number]; } |
122 | const std::vector<vec2> &TeleCheckOuts(int Number) { return m_TeleCheckOuts[Number]; } |
123 | |
124 | private: |
125 | std::map<int, std::vector<vec2>> m_TeleIns; |
126 | std::map<int, std::vector<vec2>> m_TeleOuts; |
127 | std::map<int, std::vector<vec2>> m_TeleCheckOuts; |
128 | |
129 | class CTeleTile *m_pTele; |
130 | class CSpeedupTile *m_pSpeedup; |
131 | class CTile *m_pFront; |
132 | class CSwitchTile *m_pSwitch; |
133 | class CTuneTile *m_pTune; |
134 | class CDoorTile *m_pDoor; |
135 | }; |
136 | |
137 | void ThroughOffset(vec2 Pos0, vec2 Pos1, int *pOffsetX, int *pOffsetY); |
138 | #endif |
139 | |