2011-12-25 13:33:05 +00:00
|
|
|
/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "plasma.h"
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/config.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/server.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
2011-01-29 00:59:50 +00:00
|
|
|
#include <game/server/gamemodes/DDRace.h>
|
2021-01-09 14:37:02 +00:00
|
|
|
#include <game/server/player.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <game/server/teams.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
|
2021-01-09 14:18:52 +00:00
|
|
|
#include "character.h"
|
|
|
|
|
2020-08-09 13:19:13 +00:00
|
|
|
const float PLASMA_ACCEL = 1.1f;
|
2010-07-29 05:21:18 +00:00
|
|
|
|
2011-12-25 13:51:04 +00:00
|
|
|
CPlasma::CPlasma(CGameWorld *pGameWorld, vec2 Pos, vec2 Dir, bool Freeze,
|
2020-09-26 19:41:58 +00:00
|
|
|
bool Explosive, int ResponsibleTeam) :
|
|
|
|
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-28 20:32:16 +00:00
|
|
|
m_Pos = Pos;
|
|
|
|
m_Core = Dir;
|
|
|
|
m_Freeze = Freeze;
|
|
|
|
m_Explosive = Explosive;
|
|
|
|
m_EvalTick = Server()->Tick();
|
2019-07-08 21:08:42 +00:00
|
|
|
m_LifeTime = Server()->TickSpeed() * 1.5f;
|
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;
|
2011-12-25 13:51:04 +00:00
|
|
|
CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos,
|
2020-09-26 19:41:58 +00:00
|
|
|
m_Pos + m_Core, 0.0f, To2);
|
|
|
|
if(!Hit)
|
2010-07-29 05:21:18 +00:00
|
|
|
return false;
|
2010-09-11 09:42:35 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(Hit->Team() != m_ResponsibleTeam)
|
2011-12-25 13:51:04 +00:00
|
|
|
return false;
|
2011-01-25 09:34:14 +00:00
|
|
|
m_Freeze ? Hit->Freeze() : Hit->UnFreeze();
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_Explosive)
|
2011-12-25 13:51:04 +00:00
|
|
|
GameServer()->CreateExplosion(m_Pos, -1, WEAPON_GRENADE, true,
|
2020-09-26 19:41:58 +00:00
|
|
|
m_ResponsibleTeam, Hit->Teams()->TeamMask(m_ResponsibleTeam));
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2010-07-29 05:21:18 +00:00
|
|
|
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;
|
2020-08-09 13:19:13 +00:00
|
|
|
m_Core *= PLASMA_ACCEL;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
void CPlasma::Reset()
|
|
|
|
{
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlasma::Tick()
|
|
|
|
{
|
2020-09-26 19:41:58 +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
|
|
|
|
2011-12-25 13:51:04 +00:00
|
|
|
int Res = 0;
|
|
|
|
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Pos + m_Core, 0,
|
2020-09-26 19:41:58 +00:00
|
|
|
0);
|
|
|
|
if(Res)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_Explosive)
|
2011-12-25 13:51:04 +00:00
|
|
|
GameServer()->CreateExplosion(
|
2020-09-26 19:41:58 +00:00
|
|
|
m_Pos,
|
|
|
|
-1,
|
|
|
|
WEAPON_GRENADE,
|
|
|
|
true,
|
|
|
|
m_ResponsibleTeam,
|
|
|
|
((CGameControllerDDRace *)GameServer()->m_pController)->m_Teams.TeamMask(m_ResponsibleTeam));
|
2010-07-29 05:21:18 +00:00
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
void CPlasma::Snap(int SnappingClient)
|
2011-12-25 13:51:04 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
2020-09-26 19:41:58 +00:00
|
|
|
CCharacter *SnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
CPlayer *SnapPlayer = SnappingClient > -1 ? GameServer()->m_apPlayers[SnappingClient] : 0;
|
2011-12-25 13:51:04 +00:00
|
|
|
int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11;
|
2011-04-20 14:05:05 +00:00
|
|
|
|
2021-01-20 19:00:16 +00:00
|
|
|
if(SnapChar && SnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && m_Number > 0 && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[SnapChar->Team()]) && (!Tick))
|
2011-04-20 14:05:05 +00:00
|
|
|
return;
|
2011-12-31 12:54:29 +00:00
|
|
|
|
2020-09-20 18:38:08 +00:00
|
|
|
if(SnapPlayer && (SnapPlayer->GetTeam() == TEAM_SPECTATORS || SnapPlayer->IsPaused()) && SnapPlayer->m_SpectatorID != -1 && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID) && GameServer()->GetPlayerChar(SnapPlayer->m_SpectatorID)->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != 1)
|
2011-12-31 12:54:29 +00:00
|
|
|
return;
|
|
|
|
|
2020-09-20 18:38:08 +00:00
|
|
|
if(SnapPlayer && SnapPlayer->GetTeam() != TEAM_SPECTATORS && !SnapPlayer->IsPaused() && SnapChar && SnapChar && SnapChar->Team() != m_ResponsibleTeam && SnapPlayer->m_ShowOthers != 1)
|
2011-04-20 14:05:05 +00:00
|
|
|
return;
|
2011-12-31 12:54:29 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(SnapPlayer && (SnapPlayer->GetTeam() == TEAM_SPECTATORS || SnapPlayer->IsPaused()) && SnapPlayer->m_SpectatorID == -1 && SnapChar && SnapChar->Team() != m_ResponsibleTeam && SnapPlayer->m_SpecTeam)
|
2014-08-09 17:53:38 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-25 13:51:04 +00:00
|
|
|
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(
|
2021-01-09 20:40:17 +00:00
|
|
|
NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
|
2014-01-13 16:00:49 +00:00
|
|
|
|
|
|
|
if(!pObj)
|
|
|
|
return;
|
|
|
|
|
2017-03-21 10:24:44 +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
|
|
|
}
|