2010-07-29 05:21:18 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
|
|
|
#include <engine/server.h>
|
2011-04-20 13:47:55 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include "gun.h"
|
|
|
|
#include "plasma.h"
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// CGun
|
|
|
|
//////////////////////////////////////////////////
|
2010-11-13 13:22:19 +00:00
|
|
|
CGun::CGun(CGameWorld *pGameWorld, vec2 Pos, bool Freeze, bool Explosive, int Layer, int Number)
|
2011-01-20 20:01:21 +00:00
|
|
|
: CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-11-13 13:22:19 +00:00
|
|
|
m_Layer = Layer;
|
|
|
|
m_Number = Number;
|
2011-04-20 13:47:55 +00:00
|
|
|
m_LastFire = Server()->Tick();
|
2010-08-28 20:32:16 +00:00
|
|
|
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
|
|
|
{
|
2014-01-01 21:34:10 +00:00
|
|
|
CCharacter *Ents[MAX_CLIENTS];
|
|
|
|
int IdInTeam[MAX_CLIENTS];
|
|
|
|
int LenInTeam[MAX_CLIENTS];
|
|
|
|
for (int i = 0; i < MAX_CLIENTS; i++)
|
2011-04-20 13:47:55 +00:00
|
|
|
{
|
2010-08-31 17:14:33 +00:00
|
|
|
IdInTeam[i] = -1;
|
|
|
|
LenInTeam[i] = 0;
|
|
|
|
}
|
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
int Num = -1;
|
2014-01-01 21:37:18 +00:00
|
|
|
Num = GameServer()->m_World.FindEntities(m_Pos, g_Config.m_SvPlasmaRange, (CEntity**)Ents, 16, CGameWorld::ENTTYPE_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-10-23 18:11:42 +00:00
|
|
|
//now gun doesn't affect on super
|
2011-04-20 13:47:55 +00:00
|
|
|
if(Target->Team() == TEAM_SUPER)
|
|
|
|
continue;
|
|
|
|
if(m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Target->Team()])
|
|
|
|
continue;
|
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-09-08 16:22:11 +00:00
|
|
|
int Len = length(Target->m_Pos - m_Pos);
|
|
|
|
if (LenInTeam[Target->Team()] == 0 || 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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-01 21:34:10 +00:00
|
|
|
for (int i = 0; i < MAX_CLIENTS; i++)
|
2011-04-20 13:47:55 +00:00
|
|
|
{
|
|
|
|
if(IdInTeam[i] != -1)
|
|
|
|
{
|
2010-08-31 17:14:33 +00:00
|
|
|
CCharacter *Target = Ents[IdInTeam[i]];
|
2010-09-08 16:22:11 +00:00
|
|
|
new CPlasma(&GameServer()->m_World, m_Pos, normalize(Target->m_Pos - m_Pos), m_Freeze, m_Explosive, i);
|
2011-04-20 13:47:55 +00:00
|
|
|
m_LastFire = Server()->Tick();
|
2010-08-31 17:14:33 +00:00
|
|
|
}
|
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-11-01 01:51:17 +00:00
|
|
|
int Flags;
|
2010-08-28 20:32:16 +00:00
|
|
|
m_EvalTick=Server()->Tick();
|
2011-01-21 13:18:50 +00:00
|
|
|
int index = GameServer()->Collision()->IsMover(m_Pos.x,m_Pos.y, &Flags);
|
2010-11-01 01:51:17 +00:00
|
|
|
if (index)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-11-01 01:51:17 +00:00
|
|
|
m_Core=GameServer()->Collision()->CpSpeed(index, Flags);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Pos+=m_Core;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2011-04-20 13:47:55 +00:00
|
|
|
if (m_LastFire + Server()->TickSpeed() / g_Config.m_SvPlasmaPerSec <= Server()->Tick())
|
|
|
|
Fire();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-14 10:01:42 +00:00
|
|
|
void CGun::Snap(int SnappingClient)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-11-14 10:01:42 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
|
|
|
|
2010-11-14 10:01:42 +00:00
|
|
|
CCharacter * SnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
int Tick = (Server()->Tick()%Server()->TickSpeed())%11;
|
2011-01-29 00:59:50 +00:00
|
|
|
if (SnapChar && SnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[SnapChar->Team()]) && (!Tick)) return;
|
2011-02-13 05:35:13 +00:00
|
|
|
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser)));
|
2010-07-29 05:21:18 +00:00
|
|
|
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
|
|
|
}
|