ddnet/src/game/server/entities/door.cpp

116 lines
2.8 KiB
C++
Raw Normal View History

/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
#include <game/generated/protocol.h>
#include <game/server/gamecontext.h>
#include <engine/shared/config.h>
#include <game/server/gamemodes/DDRace.h>
#include "door.h"
CDoor::CDoor(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length,
int Number) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
{
m_Number = Number;
m_Pos = Pos;
2010-09-25 16:39:52 +00:00
m_Length = Length;
m_Direction = vec2(sin(Rotation), cos(Rotation));
vec2 To = Pos + normalize(m_Direction) * m_Length;
GameServer()->Collision()->IntersectNoLaser(Pos, To, &this->m_To, 0);
2010-09-25 16:39:52 +00:00
ResetCollision();
GameWorld()->InsertEntity(this);
}
void CDoor::Open(int Tick, bool ActivatedTeam[])
{
m_EvalTick = Server()->Tick();
}
2010-09-25 16:39:52 +00:00
void CDoor::ResetCollision()
{
for (int i = 0; i < m_Length - 1; i++)
2010-09-25 16:39:52 +00:00
{
vec2 CurrentPos(m_Pos.x + (m_Direction.x * i),
m_Pos.y + (m_Direction.y * i));
if (GameServer()->Collision()->CheckPoint(CurrentPos)
|| GameServer()->Collision()->GetTile(m_Pos.x, m_Pos.y)
|| GameServer()->Collision()->GetFTile(m_Pos.x, m_Pos.y))
break;
else
GameServer()->Collision()->SetDCollisionAt(
m_Pos.x + (m_Direction.x * i),
m_Pos.y + (m_Direction.y * i), TILE_STOPA, 0/*Flags*/,
m_Number);
2010-09-25 16:39:52 +00:00
}
}
2010-09-25 16:39:52 +00:00
void CDoor::Open(int Team)
{
2010-09-25 16:39:52 +00:00
}
2010-09-25 16:39:52 +00:00
void CDoor::Close(int Team)
{
}
void CDoor::Reset()
{
}
void CDoor::Tick()
{
}
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)));
2014-01-13 16:00:49 +00:00
if (!pObj)
return;
2017-03-21 10:24:44 +00:00
pObj->m_X = (int)m_Pos.x;
pObj->m_Y = (int)m_Pos.y;
CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient);
int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11;
2014-01-13 16:00:49 +00:00
if(SnappingClient > -1 && (GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1
2017-04-08 22:20:41 +00:00
|| GameServer()->m_apPlayers[SnappingClient]->IsPaused())
2014-01-13 16:00:49 +00:00
&& GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW)
Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID);
if (Char == 0)
return;
2014-01-13 16:00:49 +00:00
2015-05-18 18:36:30 +00:00
if (Char->IsAlive() && GameServer()->Collision()->m_NumSwitchers > 0
&& !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]
&& (!Tick))
return;
if (Char->Team() == TEAM_SUPER)
{
2017-03-21 10:24:44 +00:00
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
2015-05-18 18:36:30 +00:00
else if (Char->IsAlive() && GameServer()->Collision()->m_NumSwitchers > 0
&& GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()])
{
2017-03-21 10:24:44 +00:00
pObj->m_FromX = (int)m_To.x;
pObj->m_FromY = (int)m_To.y;
}
else
{
2017-03-21 10:24:44 +00:00
pObj->m_FromX = (int)m_Pos.x;
pObj->m_FromY = (int)m_Pos.y;
}
pObj->m_StartTick = Server()->Tick();
}