2010-08-11 10:33:37 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include <engine/shared/config.h>
|
|
|
|
|
|
|
|
#include "door.h"
|
|
|
|
|
2010-08-11 18:29:08 +00:00
|
|
|
CDoor::CDoor(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length, bool Opened)
|
2010-08-11 10:33:37 +00:00
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_LASER)
|
|
|
|
{
|
|
|
|
m_Pos = Pos;
|
2010-09-01 08:52:59 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_Opened[i] = false;
|
|
|
|
}//TODO: Check this
|
|
|
|
|
2010-08-11 10:33:37 +00:00
|
|
|
|
2010-08-11 18:29:08 +00:00
|
|
|
vec2 Dir = vec2(sin(Rotation), cos(Rotation));
|
2010-08-11 10:33:37 +00:00
|
|
|
vec2 To = Pos + normalize(Dir)*Length;
|
|
|
|
|
2010-08-11 18:29:08 +00:00
|
|
|
GameServer()->Collision()->IntersectNoLaser(Pos, To, &this->m_To, 0);
|
2010-08-11 10:33:37 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
}
|
|
|
|
|
2010-09-01 08:52:59 +00:00
|
|
|
void CDoor::Open(int Tick, bool ActivatedTeam[])
|
2010-08-11 10:33:37 +00:00
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-09-01 09:50:42 +00:00
|
|
|
m_EvalTick[i] = Tick;
|
2010-09-01 08:52:59 +00:00
|
|
|
m_Opened[i] = ActivatedTeam[i];
|
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDoor::Close()
|
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_Opened[i] = false;
|
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
2010-09-01 08:52:59 +00:00
|
|
|
bool CDoor::HitCharacter(int Team)
|
2010-08-11 10:33:37 +00:00
|
|
|
{
|
|
|
|
vec2 At;
|
2010-08-31 11:01:46 +00:00
|
|
|
std::list < CCharacter * > hittedCharacters = GameServer()->m_World.IntersectedCharacters(m_Pos, m_To, 1.f, At, 0);
|
|
|
|
if(hittedCharacters.empty()) return false;
|
|
|
|
for(std::list < CCharacter * >::iterator i = hittedCharacters.begin(); i != hittedCharacters.end(); i++) {
|
|
|
|
CCharacter * Char = *i;
|
2010-09-01 08:52:59 +00:00
|
|
|
if(Char->Team() == Team)
|
|
|
|
Char = false;
|
2010-08-31 11:01:46 +00:00
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDoor::Reset()
|
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_Opened[i] = false;
|
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDoor::Tick()
|
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
if(!m_Opened[i]) {
|
|
|
|
HitCharacter(i);
|
2010-09-01 09:50:42 +00:00
|
|
|
} else if (m_EvalTick[i] + 10 < Server()->Tick())
|
|
|
|
Close();
|
2010-09-01 08:52:59 +00:00
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDoor::Snap(int SnappingClient)
|
|
|
|
{
|
|
|
|
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To))
|
|
|
|
return;
|
|
|
|
|
|
|
|
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_Id, sizeof(CNetObj_Laser)));
|
|
|
|
pObj->m_X = (int)m_Pos.x;
|
|
|
|
pObj->m_Y = (int)m_Pos.y;
|
|
|
|
|
2010-09-01 08:52:59 +00:00
|
|
|
if (!m_Opened[SnappingClient])
|
2010-08-11 10:33:37 +00:00
|
|
|
{
|
|
|
|
pObj->m_FromX = (int)m_To.x;
|
|
|
|
pObj->m_FromY = (int)m_To.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pObj->m_FromX = (int)m_Pos.x;
|
|
|
|
pObj->m_FromY = (int)m_Pos.y;
|
|
|
|
}
|
|
|
|
pObj->m_StartTick = Server()->Tick();
|
|
|
|
}
|