2010-08-11 10:33:37 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include "trigger.h"
|
|
|
|
#include "door.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// DOOR
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
CTrigger::CTrigger(CGameWorld *pGameWorld, vec2 Pos, CEntity *Target)
|
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_PICKUP)
|
|
|
|
{
|
|
|
|
m_Pos = Pos;
|
|
|
|
m_Target = Target;
|
2010-09-01 08:52:59 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_TeamActivated[i] = false;
|
|
|
|
}
|
2010-09-25 16:39:52 +00:00
|
|
|
|
2010-08-11 10:33:37 +00:00
|
|
|
|
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CTrigger::HitCharacter()
|
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
CCharacter *Ents[16];
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
int Num = GameServer()->m_World.FindEntities(m_Pos, 20.0f, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
|
|
|
|
if(Num <= 0) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < Num; i++)
|
|
|
|
{
|
|
|
|
m_TeamActivated[Ents[i]->Team()] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTrigger::OpenDoor(int Tick)
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
CDoor *ConnectedDoor = (CDoor*) m_Target;
|
2010-09-01 08:52:59 +00:00
|
|
|
ConnectedDoor->Open(Tick, m_TeamActivated);
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTrigger::Reset()
|
|
|
|
{
|
2010-09-01 08:52:59 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
m_TeamActivated[i] = false;
|
|
|
|
}
|
2010-08-11 10:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CTrigger::Tick()
|
|
|
|
{
|
|
|
|
if (Server()->Tick() % 10 == 0)
|
|
|
|
{
|
|
|
|
if (HitCharacter())
|
|
|
|
OpenDoor(Server()->Tick());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CTrigger::Snap(int SnappingClient)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|