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-08 16:22:11 +00:00
|
|
|
if(ActivatedTeam[i]) 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
|
|
|
}
|
|
|
|
|
2010-09-01 10:22:15 +00:00
|
|
|
void CDoor::Close(int Team)
|
2010-08-11 10:33:37 +00:00
|
|
|
{
|
2010-09-01 10:22:15 +00:00
|
|
|
m_Opened[Team] = 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
|
|
|
{
|
2010-09-10 06:55:04 +00:00
|
|
|
std::list < CCharacter * > HitCharacters = GameServer()->m_World.IntersectedCharacters(m_Pos, m_To, 1.f, 0);
|
|
|
|
if(HitCharacters.empty()) return false;
|
|
|
|
for(std::list < CCharacter * >::iterator i = HitCharacters.begin(); i != HitCharacters.end(); i++)
|
|
|
|
{
|
2010-08-31 11:01:46 +00:00
|
|
|
CCharacter * Char = *i;
|
2010-09-01 08:52:59 +00:00
|
|
|
if(Char->Team() == Team)
|
2010-09-10 06:55:04 +00:00
|
|
|
{
|
|
|
|
//DoDoored(Char);
|
2010-09-08 16:22:11 +00:00
|
|
|
Char->m_Doored = true;
|
2010-09-10 06:55:04 +00:00
|
|
|
}
|
2010-08-31 11:01:46 +00:00
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-10 06:55:04 +00:00
|
|
|
bool CDoor::DoDoored(CCharacter* pChar)
|
|
|
|
{
|
|
|
|
vec2 Pos = closest_point_on_line(m_Pos,m_To,pChar->m_Intersection);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-11 10:33:37 +00:00
|
|
|
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-08 16:22:11 +00:00
|
|
|
} else if (m_EvalTick[i] + 10 < Server()->Tick()) {
|
2010-09-01 10:22:15 +00:00
|
|
|
Close(i);
|
2010-09-08 16:22:11 +00:00
|
|
|
}
|
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-08 16:22:11 +00:00
|
|
|
CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
if(Char == 0) return;
|
|
|
|
|
|
|
|
if (!m_Opened[Char->Team()])
|
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();
|
|
|
|
}
|