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,
|
2022-05-04 17:33:48 +00:00
|
|
|
bool Explosive, int ForClientID) :
|
2020-09-26 19:41:58 +00:00
|
|
|
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;
|
2022-05-04 17:33:48 +00:00
|
|
|
m_ForClientID = ForClientID;
|
2010-08-28 20:32:16 +00:00
|
|
|
m_EvalTick = Server()->Tick();
|
2019-07-08 21:08:42 +00:00
|
|
|
m_LifeTime = Server()->TickSpeed() * 1.5f;
|
2011-12-25 13:51:04 +00:00
|
|
|
|
2022-05-04 17:33:48 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CPlasma::Tick()
|
|
|
|
{
|
2022-05-09 11:56:06 +00:00
|
|
|
// A plasma bullet has only a limited lifetime
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_LifeTime == 0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
2022-05-04 17:33:48 +00:00
|
|
|
CCharacter *pTarget = GameServer()->GetPlayerChar(m_ForClientID);
|
2022-05-09 11:56:06 +00:00
|
|
|
// Without a target, a plasma bullet has no reason to live
|
2022-05-04 17:33:48 +00:00
|
|
|
if(!pTarget)
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
return;
|
|
|
|
}
|
2010-08-28 20:32:16 +00:00
|
|
|
m_LifeTime--;
|
|
|
|
Move();
|
2022-05-17 12:28:37 +00:00
|
|
|
HitCharacter(pTarget);
|
|
|
|
// Plasma bullets may explode twice if they would hit both a player and an obstacle in the next move step
|
|
|
|
HitObstacle(pTarget);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
2022-05-04 17:33:48 +00:00
|
|
|
void CPlasma::Move()
|
2011-12-25 13:51:04 +00:00
|
|
|
{
|
2022-05-04 17:33:48 +00:00
|
|
|
m_Pos += m_Core;
|
|
|
|
m_Core *= PLASMA_ACCEL;
|
|
|
|
}
|
2011-04-20 14:05:05 +00:00
|
|
|
|
2022-05-04 17:33:48 +00:00
|
|
|
bool CPlasma::HitCharacter(CCharacter *pTarget)
|
|
|
|
{
|
|
|
|
vec2 IntersectPos;
|
|
|
|
CCharacter *HitPlayer = GameServer()->m_World.IntersectCharacter(
|
|
|
|
m_Pos, m_Pos + m_Core, 0.0f, IntersectPos, 0, m_ForClientID);
|
|
|
|
if(!HitPlayer)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-31 12:54:29 +00:00
|
|
|
|
2022-05-09 11:56:06 +00:00
|
|
|
// Super player should not be able to stop the plasma bullets
|
2022-05-04 17:33:48 +00:00
|
|
|
if(HitPlayer->Team() == TEAM_SUPER)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2011-12-31 12:54:29 +00:00
|
|
|
|
2022-05-04 17:33:48 +00:00
|
|
|
m_Freeze ? HitPlayer->Freeze() : HitPlayer->UnFreeze();
|
|
|
|
if(m_Explosive)
|
|
|
|
{
|
|
|
|
// Plasma Turrets are very precise weapons only one tee gets speed from it,
|
|
|
|
// other tees near the explosion remain unaffected
|
|
|
|
GameServer()->CreateExplosion(
|
|
|
|
m_Pos, m_ForClientID, WEAPON_GRENADE, true, pTarget->Team(), pTarget->TeamMask());
|
|
|
|
}
|
2022-05-09 11:56:06 +00:00
|
|
|
Reset();
|
2022-05-04 17:33:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2022-05-17 12:28:37 +00:00
|
|
|
bool CPlasma::HitObstacle(CCharacter *pTarget)
|
|
|
|
{
|
|
|
|
// Check if the plasma bullet is stopped by a solid block or a laser stopper
|
|
|
|
int HasIntersection = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Pos + m_Core, 0, 0);
|
|
|
|
if(HasIntersection)
|
|
|
|
{
|
|
|
|
if(m_Explosive)
|
|
|
|
{
|
|
|
|
// Even in the case of an explosion due to a collision with obstacles, only one player is affected
|
|
|
|
GameServer()->CreateExplosion(
|
|
|
|
m_Pos, m_ForClientID, WEAPON_GRENADE, true, pTarget->Team(), pTarget->TeamMask());
|
|
|
|
}
|
|
|
|
Reset();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-04 17:33:48 +00:00
|
|
|
void CPlasma::Reset()
|
|
|
|
{
|
|
|
|
m_MarkedForDestroy = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPlasma::Snap(int SnappingClient)
|
|
|
|
{
|
2022-05-09 11:56:06 +00:00
|
|
|
// Only players who can see the targeted player can see the plasma bullet
|
2022-05-04 17:33:48 +00:00
|
|
|
CCharacter *pTarget = GameServer()->GetPlayerChar(m_ForClientID);
|
2022-05-25 14:27:19 +00:00
|
|
|
if(!pTarget || !pTarget->CanSnapCharacter(SnappingClient))
|
2022-05-04 17:33:48 +00:00
|
|
|
{
|
2011-04-20 14:05:05 +00:00
|
|
|
return;
|
2022-05-04 17:33:48 +00:00
|
|
|
}
|
2011-12-31 12:54:29 +00:00
|
|
|
|
2022-05-09 11:56:06 +00:00
|
|
|
// Only players with the plasma bullet in their field of view or who want to see everything will receive the snap
|
2022-05-04 17:33:48 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
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
|
|
|
}
|