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;
|
|
|
|
|
|
|
|
m_Objtype = ObjType;
|
|
|
|
m_Pos = vec2(0,0);
|
|
|
|
m_ProximityRadius = 0;
|
2008-08-14 18:42:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_MarkedForDestroy = false;
|
|
|
|
m_Id = Server()->SnapNewID();
|
2008-08-14 18:42:47 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pNextEntity = 0;
|
|
|
|
m_pPrevEntity = 0;
|
|
|
|
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);
|
|
|
|
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
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(SnappingClient == -1)
|
2008-10-06 18:05:01 +00:00
|
|
|
return 0;
|
2008-10-25 11:32:29 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float dx = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.x-CheckPos.x;
|
|
|
|
float dy = GameServer()->m_apPlayers[SnappingClient]->m_ViewPos.y-CheckPos.y;
|
2008-10-25 11:32:29 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(absolute(dx) > 1000.0f || absolute(dy) > 800.0f)
|
2008-10-25 11:32:29 +00:00
|
|
|
return 1;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 1100.0f)
|
2008-10-06 18:05:01 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|