2010-07-29 05:21:18 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
|
|
|
#include <engine/server.h>
|
|
|
|
#include <engine/config.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
2010-09-08 16:22:11 +00:00
|
|
|
#include <game/server/teams.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include "plasma.h"
|
|
|
|
|
|
|
|
const float ACCEL=1.1f;
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// turret
|
|
|
|
//////////////////////////////////////////////////
|
2010-09-08 16:22:11 +00:00
|
|
|
CPlasma::CPlasma(CGameWorld *pGameWorld, vec2 Pos, vec2 Dir, bool Freeze, bool Explosive, int ResponsibleTeam)
|
2010-07-29 05:21:18 +00:00
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_LASER)
|
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Pos = Pos;
|
|
|
|
m_Core = Dir;
|
|
|
|
m_Freeze = Freeze;
|
|
|
|
m_Explosive = Explosive;
|
|
|
|
m_EvalTick = Server()->Tick();
|
|
|
|
m_LifeTime = Server()->TickSpeed() * 1.5;
|
2010-09-08 16:22:11 +00:00
|
|
|
m_ResponsibleTeam = ResponsibleTeam;
|
2010-07-29 05:21:18 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
}
|
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
bool CPlasma::HitCharacter()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
vec2 To2;
|
|
|
|
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, m_Pos+m_Core, 0.0f,To2);
|
|
|
|
if(!Hit)
|
2010-07-29 05:21:18 +00:00
|
|
|
return false;
|
2010-09-08 16:22:11 +00:00
|
|
|
if(Hit->Team() != m_ResponsibleTeam) return false;
|
2010-08-28 20:32:16 +00:00
|
|
|
if(m_Freeze)
|
|
|
|
Hit->Freeze(Server()->TickSpeed()*3);
|
2010-08-29 01:35:14 +00:00
|
|
|
if(!m_Freeze || (m_Freeze && m_Explosive))
|
2010-09-08 16:22:11 +00:00
|
|
|
GameServer()->CreateExplosion(m_Pos, -1, WEAPON_GRENADE, true, Hit->Teams()->TeamMask(m_ResponsibleTeam));
|
2010-07-29 05:21:18 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
void CPlasma::Move()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Pos += m_Core;
|
|
|
|
m_Core *= ACCEL;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlasma::Reset()
|
|
|
|
{
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlasma::Tick()
|
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
if (m_LifeTime==0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
2010-08-28 20:32:16 +00:00
|
|
|
m_LifeTime--;
|
|
|
|
Move();
|
|
|
|
HitCharacter();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
int Res=0;
|
|
|
|
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Pos+m_Core,0, 0);
|
|
|
|
if(Res)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
if(m_Explosive)
|
2010-08-29 02:00:21 +00:00
|
|
|
GameServer()->CreateExplosion(m_Pos, -1, WEAPON_GRENADE, true);
|
2010-07-29 05:21:18 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
void CPlasma::Snap(int SnappingClient)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2010-07-29 05:21:18 +00:00
|
|
|
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;
|
|
|
|
pObj->m_FromX = (int)m_Pos.x;
|
|
|
|
pObj->m_FromY = (int)m_Pos.y;
|
2010-08-28 20:32:16 +00:00
|
|
|
pObj->m_StartTick = m_EvalTick;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|