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>
|
|
|
|
#include "gun.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
|
|
|
|
|
|
|
|
const int RANGE=700;
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// CGun
|
|
|
|
//////////////////////////////////////////////////
|
2010-08-28 20:32:16 +00:00
|
|
|
CGun::CGun(CGameWorld *pGameWorld, vec2 Pos, bool Freeze, bool Explosive)
|
2010-07-29 05:21:18 +00:00
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_LASER)
|
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Delay = Server()->TickSpeed()*0.3f;
|
|
|
|
m_Pos = Pos;
|
|
|
|
m_EvalTick = Server()->Tick();
|
|
|
|
m_Freeze = Freeze;
|
|
|
|
m_Explosive = Explosive;
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
void CGun::Fire()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
CCharacter *Ents[16];
|
2010-08-31 17:14:33 +00:00
|
|
|
int IdInTeam[16];
|
|
|
|
int LenInTeam[16];
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
IdInTeam[i] = -1;
|
|
|
|
LenInTeam[i] = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
int Num = -1;
|
2010-09-01 08:52:59 +00:00
|
|
|
Num = GameServer()->m_World.FindEntities(m_Pos, RANGE, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
|
2010-08-31 17:14:33 +00:00
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
for (int i = 0; i < Num; i++)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
CCharacter *Target = Ents[i];
|
2010-08-31 17:32:25 +00:00
|
|
|
int res = GameServer()->Collision()->IntersectLine(m_Pos, Target->m_Pos,0,0,false);
|
2010-07-29 05:21:18 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
2010-08-31 17:14:33 +00:00
|
|
|
int Len=length(Target->m_Pos - m_Pos);
|
|
|
|
if (LenInTeam[Target->Team()] == 0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-31 17:14:33 +00:00
|
|
|
LenInTeam[Target->Team()] = Len;
|
|
|
|
IdInTeam[Target->Team()] = i;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-08-31 17:14:33 +00:00
|
|
|
else if(LenInTeam[Target->Team()] > Len)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-31 17:14:33 +00:00
|
|
|
LenInTeam[Target->Team()] = Len;
|
|
|
|
IdInTeam[Target->Team()] = i;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-31 17:14:33 +00:00
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
if(IdInTeam[i] != -1) {
|
|
|
|
CCharacter *Target = Ents[IdInTeam[i]];
|
|
|
|
vec2 Fdir = normalize(Target->m_Pos - m_Pos);
|
|
|
|
new CPlasma(&GameServer()->m_World, m_Pos, Fdir, m_Freeze, m_Explosive);
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGun::Reset()
|
|
|
|
{
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGun::Tick()
|
|
|
|
{
|
|
|
|
if (Server()->Tick()%int(Server()->TickSpeed()*0.15f)==0)
|
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_EvalTick=Server()->Tick();
|
|
|
|
int Index = GameServer()->Collision()->IsCp(m_Pos.x,m_Pos.y);
|
|
|
|
if (Index)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Core=GameServer()->Collision()->CpSpeed(Index);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Pos+=m_Core;
|
|
|
|
Fire();
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGun::Snap(int snapping_client)
|
|
|
|
{
|
|
|
|
if(NetworkClipped(snapping_client))
|
|
|
|
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
|
|
|
}
|