blob: 3fae22f22cb8f5b6e14b814a0063f3c8c9d57f4f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/* (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. */
#include "entity.h"
#include "gamecontext.h"
//////////////////////////////////////////////////
// Entity
//////////////////////////////////////////////////
CEntity::CEntity(CGameWorld *pGameWorld, int ObjType)
{
m_pGameWorld = pGameWorld;
m_ObjType = ObjType;
m_Pos = vec2(0,0);
m_ProximityRadius = 0;
m_MarkedForDestroy = false;
m_ID = Server()->SnapNewID();
m_pPrevTypeEntity = 0;
m_pNextTypeEntity = 0;
}
CEntity::~CEntity()
{
GameWorld()->RemoveEntity(this);
Server()->SnapFreeID(m_ID);
}
int CEntity::NetworkClipped(int SnappingClient)
{
return NetworkClipped(SnappingClient, m_Pos);
}
int CEntity::NetworkClipped(int SnappingClient, vec2 CheckPos)
{
if(SnappingClient == -1)
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;
if(distance(GameServer()->m_apPlayers[SnappingClient]->m_ViewPos, CheckPos) > 1100.0f)
return 1;
return 0;
}
bool CEntity::GameLayerClipped(vec2 CheckPos)
{
return round(CheckPos.x)/32 < -200 || round(CheckPos.x)/32 > GameServer()->Collision()->GetWidth()+200 ||
round(CheckPos.y)/32 < -200 || round(CheckPos.y)/32 > GameServer()->Collision()->GetHeight()+200 ? true : false;
}
void CEntity::SetCharactersNearby()
{
CCharacter *c;
for(int i = 0; i < MAX_CLIENTS; ++i)
if((c = GameServer()->GetPlayerChar(i)))
m_CharactersNearby[i] = (absolute(c->m_Pos.x - m_Pos.x) <= 900.0f && absolute(c->m_Pos.y - m_Pos.y) <= 700.0f && distance(c->m_Pos, m_Pos) <= 900.0f);
m_CharactersNearbyInitialized = true;
}
|