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. */
|
2008-08-14 18:42:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "entity.h"
|
|
|
|
#include "gamecontext.h"
|
2008-08-14 18:42:47 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// Entity
|
|
|
|
//////////////////////////////////////////////////
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity::CEntity(CGameWorld *pGameWorld, int ObjType)
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pGameWorld = pGameWorld;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-01-19 17:27:50 +00:00
|
|
|
m_ObjType = ObjType;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Pos = vec2(0,0);
|
|
|
|
m_ProximityRadius = 0;
|
2008-08-14 18:42:47 +00:00
|
|
|
|
2011-04-13 18:37:12 +00:00
|
|
|
m_MarkedForDestroy = false;
|
2011-02-12 10:40:36 +00:00
|
|
|
m_ID = Server()->SnapNewID();
|
2008-08-14 18:42:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pPrevTypeEntity = 0;
|
|
|
|
m_pNextTypeEntity = 0;
|
2008-08-14 18:42:47 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CEntity::~CEntity()
|
2008-08-14 18:42:47 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameWorld()->RemoveEntity(this);
|
2011-02-12 10:40:36 +00:00
|
|
|
Server()->SnapFreeID(m_ID);
|
2008-08-14 18:42:47 +00:00
|
|
|
}
|
2008-10-06 18:05:01 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CEntity::NetworkClipped(int SnappingClient)
|
2008-10-06 18:05:01 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
return NetworkClipped(SnappingClient, m_Pos);
|
2008-10-06 18:05:01 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos)
|
2008-10-06 18:05:01 +00:00
|
|
|
{
|
2013-12-24 22:59:06 +00:00
|
|
|
if(SnappingClient == -1)
|
2013-12-24 22:54:53 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x-CheckPos.x;
|
|
|
|
float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y-CheckPos.y;
|
|
|
|
|
|
|
|
if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f)
|
|
|
|
return 1;
|
|
|
|
|
2013-12-27 17:29:56 +00:00
|
|
|
if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 4000.0f)
|
2013-12-24 22:54:53 +00:00
|
|
|
return 1;
|
2008-10-06 18:05:01 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2011-01-08 10:34:19 +00:00
|
|
|
|
|
|
|
bool CEntity::GameLayerClipped(vec2 CheckPos)
|
|
|
|
{
|
2014-04-22 21:46:55 +00:00
|
|
|
return round_to_int(CheckPos.x)/32 < -200 || round_to_int(CheckPos.x)/32 > GameServer()->Collision()->GetWidth()+200 ||
|
|
|
|
round_to_int(CheckPos.y)/32 < -200 || round_to_int(CheckPos.y)/32 > GameServer()->Collision()->GetHeight()+200 ? true : false;
|
2011-01-08 10:34:19 +00:00
|
|
|
}
|
2018-02-14 15:27:26 +00:00
|
|
|
|
2018-07-15 09:58:12 +00:00
|
|
|
bool CEntity::GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2* pOutPos)
|
2018-07-14 23:04:26 +00:00
|
|
|
{
|
2018-07-15 09:58:12 +00:00
|
|
|
while (GameServer()->Collision()->CheckPoint(Pos))
|
|
|
|
{
|
|
|
|
Pos -= normalize(PrevPos - Pos);
|
2018-07-14 23:04:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec2 PosInBlock = vec2(round_to_int(Pos.x) % 32, round_to_int(Pos.y) % 32);
|
|
|
|
vec2 BlockCenter = vec2(round_to_int(Pos.x), round_to_int(Pos.y)) - PosInBlock + vec2(16.0f, 16.0f);
|
|
|
|
|
|
|
|
*pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f), Pos.y);
|
|
|
|
if (!GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
*pOutPos = vec2(Pos.x, BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
|
|
|
|
if (!GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
*pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f),
|
|
|
|
BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
|
|
|
|
if (!GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f)))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-14 15:27:26 +00:00
|
|
|
bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2* OutPos)
|
|
|
|
{
|
2018-07-16 16:57:33 +00:00
|
|
|
for (int dist = 5; dist >= -1; dist--)
|
2018-02-14 15:27:26 +00:00
|
|
|
{
|
|
|
|
*OutPos = vec2(PlayerPos.x, PlayerPos.y - dist);
|
|
|
|
if (!GameServer()->Collision()->TestBox(*OutPos, vec2(28.0f, 28.0f)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|