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>
|
2014-05-07 22:53:21 +00:00
|
|
|
#include <game/server/teams.h>
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
#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;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
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];
|
2015-07-09 00:08:14 +00:00
|
|
|
int IdInTeam[MAX_CLIENTS];
|
2014-01-01 21:34:10 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2010-08-28 20:32:16 +00:00
|
|
|
int Num = -1;
|
2014-01-02 00:56:09 +00:00
|
|
|
Num = GameServer()->m_World.FindEntities(m_Pos, g_Config.m_SvPlasmaRange, (CEntity**)Ents, MAX_CLIENTS, 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;
|
2015-11-08 09:20:44 +00:00
|
|
|
int res = GameServer()->Collision()->IntersectLine(m_Pos, Target->m_Pos,0,0);
|
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
|
|
|
}
|
2014-05-07 22:53:21 +00:00
|
|
|
for (int i = 0; i < Num; i++)
|
|
|
|
{
|
|
|
|
CCharacter *Target = Ents[i];
|
2014-09-22 16:56:59 +00:00
|
|
|
if (Target->IsAlive() && Target->Teams()->m_Core.GetSolo(Target->GetPlayer()->GetCID()))
|
2014-05-07 22:53:21 +00:00
|
|
|
{
|
|
|
|
if (IdInTeam[Target->Team()] != i)
|
|
|
|
{
|
2015-11-08 09:20:44 +00:00
|
|
|
int res = GameServer()->Collision()->IntersectLine(m_Pos, Target->m_Pos,0,0);
|
2014-05-07 22:53:21 +00:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
new CPlasma(&GameServer()->m_World, m_Pos, normalize(Target->m_Pos - m_Pos), m_Freeze, m_Explosive, Target->Team());
|
|
|
|
m_LastFire = Server()->Tick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2015-07-09 00:08:14 +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)
|
2015-07-09 00:08:14 +00:00
|
|
|
{
|
2010-11-14 10:01:42 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
|
|
|
|
2014-01-13 16:00:49 +00:00
|
|
|
CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
|
2014-09-26 01:20:47 +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);
|
|
|
|
|
2010-11-14 10:01:42 +00:00
|
|
|
int Tick = (Server()->Tick()%Server()->TickSpeed())%11;
|
2014-01-13 16:00:49 +00:00
|
|
|
if (Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->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)));
|
2014-01-13 16:00:49 +00:00
|
|
|
|
|
|
|
if (!pObj)
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|