2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "projectile.h"
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
2013-07-18 22:27:08 +00:00
|
|
|
#include <game/server/gamemodes/DDRace.h>
|
2021-01-09 14:37:02 +00:00
|
|
|
#include <game/server/player.h>
|
2021-01-17 16:18:08 +00:00
|
|
|
#include <game/version.h>
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-09-08 16:22:11 +00:00
|
|
|
#include <game/server/teams.h>
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2021-01-09 14:18:52 +00:00
|
|
|
#include "character.h"
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
CProjectile::CProjectile(
|
|
|
|
CGameWorld *pGameWorld,
|
|
|
|
int Type,
|
|
|
|
int Owner,
|
|
|
|
vec2 Pos,
|
|
|
|
vec2 Dir,
|
|
|
|
int Span,
|
|
|
|
bool Freeze,
|
|
|
|
bool Explosive,
|
|
|
|
float Force,
|
|
|
|
int SoundImpact,
|
|
|
|
int Layer,
|
|
|
|
int Number) :
|
|
|
|
CEntity(pGameWorld, CGameWorld::ENTTYPE_PROJECTILE)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Type = Type;
|
|
|
|
m_Pos = Pos;
|
|
|
|
m_Direction = Dir;
|
|
|
|
m_LifeSpan = Span;
|
|
|
|
m_Owner = Owner;
|
|
|
|
m_Force = Force;
|
2014-04-02 17:55:42 +00:00
|
|
|
//m_Damage = Damage;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_SoundImpact = SoundImpact;
|
|
|
|
m_StartTick = Server()->Tick();
|
|
|
|
m_Explosive = Explosive;
|
2011-04-11 22:27:52 +00:00
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
m_Layer = Layer;
|
|
|
|
m_Number = Number;
|
|
|
|
m_Freeze = Freeze;
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2014-03-15 16:48:25 +00:00
|
|
|
m_TuneZone = GameServer()->Collision()->IsTune(GameServer()->Collision()->GetMapIndex(m_Pos));
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2022-02-11 09:56:34 +00:00
|
|
|
CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
|
|
|
m_BelongsToPracticeTeam = pOwnerChar && pOwnerChar->Teams()->IsPractice(pOwnerChar->Team());
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CProjectile::Reset()
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-07-29 05:21:18 +00:00
|
|
|
if(m_LifeSpan > -2)
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 CProjectile::GetPos(float Time)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float Curvature = 0;
|
|
|
|
float Speed = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
switch(m_Type)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
case WEAPON_GRENADE:
|
|
|
|
if(!m_TuneZone)
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->Tuning()->m_GrenadeCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_GrenadeSpeed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->TuningList()[m_TuneZone].m_GrenadeCurvature;
|
|
|
|
Speed = GameServer()->TuningList()[m_TuneZone].m_GrenadeSpeed;
|
|
|
|
}
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
case WEAPON_SHOTGUN:
|
|
|
|
if(!m_TuneZone)
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->Tuning()->m_ShotgunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_ShotgunSpeed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->TuningList()[m_TuneZone].m_ShotgunCurvature;
|
|
|
|
Speed = GameServer()->TuningList()[m_TuneZone].m_ShotgunSpeed;
|
|
|
|
}
|
2015-07-09 00:08:14 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
case WEAPON_GUN:
|
|
|
|
if(!m_TuneZone)
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->Tuning()->m_GunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_GunSpeed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Curvature = GameServer()->TuningList()[m_TuneZone].m_GunCurvature;
|
|
|
|
Speed = GameServer()->TuningList()[m_TuneZone].m_GunSpeed;
|
|
|
|
}
|
|
|
|
break;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
return CalcPos(m_Pos, m_Direction, Curvature, Speed, Time);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CProjectile::Tick()
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
float Pt = (Server()->Tick() - m_StartTick - 1) / (float)Server()->TickSpeed();
|
|
|
|
float Ct = (Server()->Tick() - m_StartTick) / (float)Server()->TickSpeed();
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 PrevPos = GetPos(Pt);
|
|
|
|
vec2 CurPos = GetPos(Ct);
|
2010-07-29 05:21:18 +00:00
|
|
|
vec2 ColPos;
|
|
|
|
vec2 NewPos;
|
2015-11-08 09:20:44 +00:00
|
|
|
int Collide = GameServer()->Collision()->IntersectLine(PrevPos, CurPos, &ColPos, &NewPos);
|
2011-07-21 01:13:59 +00:00
|
|
|
CCharacter *pOwnerChar = 0;
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
if(m_Owner >= 0)
|
2011-07-21 01:13:59 +00:00
|
|
|
pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2018-07-17 17:25:38 +00:00
|
|
|
CCharacter *pTargetChr = 0;
|
2018-07-14 23:04:26 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pOwnerChar ? !(pOwnerChar->m_Hit & CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit)
|
2018-07-14 23:04:26 +00:00
|
|
|
pTargetChr = GameServer()->m_World.IntersectCharacter(PrevPos, ColPos, m_Freeze ? 1.0f : 6.0f, ColPos, pOwnerChar, m_Owner);
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
if(m_LifeSpan > -1)
|
|
|
|
m_LifeSpan--;
|
2011-04-13 23:27:49 +00:00
|
|
|
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t TeamMask = -1LL;
|
2017-03-21 10:24:44 +00:00
|
|
|
bool IsWeaponCollide = false;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(
|
|
|
|
pOwnerChar &&
|
|
|
|
pTargetChr &&
|
|
|
|
pOwnerChar->IsAlive() &&
|
|
|
|
pTargetChr->IsAlive() &&
|
|
|
|
!pTargetChr->CanCollide(m_Owner))
|
2010-10-02 01:25:42 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
IsWeaponCollide = true;
|
2010-09-22 19:01:09 +00:00
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pOwnerChar && pOwnerChar->IsAlive())
|
2010-10-02 01:25:42 +00:00
|
|
|
{
|
2022-05-04 12:34:58 +00:00
|
|
|
TeamMask = pOwnerChar->TeamMask();
|
2010-10-02 01:25:42 +00:00
|
|
|
}
|
2022-02-11 09:56:34 +00:00
|
|
|
else if(m_Owner >= 0 && (m_Type != WEAPON_GRENADE || g_Config.m_SvDestroyBulletsOnDeath || m_BelongsToPracticeTeam))
|
2014-03-29 22:15:45 +00:00
|
|
|
{
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2018-01-22 13:15:53 +00:00
|
|
|
return;
|
2014-03-29 22:15:45 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(((pTargetChr && (pOwnerChar ? !(pOwnerChar->m_Hit & CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit || m_Owner == -1 || pTargetChr == pOwnerChar)) || Collide || GameLayerClipped(CurPos)) && !IsWeaponCollide)
|
2010-08-31 12:29:03 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(m_Explosive /*??*/ && (!pTargetChr || (pTargetChr && (!m_Freeze || (m_Type == WEAPON_SHOTGUN && Collide)))))
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2018-03-24 13:01:01 +00:00
|
|
|
int Number = 1;
|
2019-10-14 00:28:24 +00:00
|
|
|
if(GameServer()->EmulateBug(BUG_GRENADE_DOUBLEEXPLOSION) && m_LifeSpan == -1)
|
2018-03-24 13:01:01 +00:00
|
|
|
{
|
|
|
|
Number = 2;
|
|
|
|
}
|
|
|
|
for(int i = 0; i < Number; i++)
|
|
|
|
{
|
2019-06-02 20:04:11 +00:00
|
|
|
GameServer()->CreateExplosion(ColPos, m_Owner, m_Type, m_Owner == -1, (!pTargetChr ? -1 : pTargetChr->Team()),
|
2020-09-26 19:41:58 +00:00
|
|
|
(m_Owner != -1) ? TeamMask : -1LL);
|
2018-03-24 13:01:01 +00:00
|
|
|
GameServer()->CreateSound(ColPos, m_SoundImpact,
|
2020-09-26 19:41:58 +00:00
|
|
|
(m_Owner != -1) ? TeamMask : -1LL);
|
2018-03-24 13:01:01 +00:00
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2019-05-29 14:28:38 +00:00
|
|
|
else if(m_Freeze)
|
|
|
|
{
|
|
|
|
CCharacter *apEnts[MAX_CLIENTS];
|
2020-09-26 19:41:58 +00:00
|
|
|
int Num = GameWorld()->FindEntities(CurPos, 1.0f, (CEntity **)apEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
|
2019-05-29 14:30:44 +00:00
|
|
|
for(int i = 0; i < Num; ++i)
|
2021-01-20 19:00:16 +00:00
|
|
|
if(apEnts[i] && (m_Layer != LAYER_SWITCH || (m_Layer == LAYER_SWITCH && m_Number > 0 && GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[apEnts[i]->Team()])))
|
2019-05-29 14:28:38 +00:00
|
|
|
apEnts[i]->Freeze();
|
|
|
|
}
|
2018-02-14 15:27:26 +00:00
|
|
|
|
2020-11-20 11:14:04 +00:00
|
|
|
if(pOwnerChar && !GameLayerClipped(ColPos) &&
|
2019-08-19 08:09:53 +00:00
|
|
|
((m_Type == WEAPON_GRENADE && pOwnerChar->HasTelegunGrenade()) || (m_Type == WEAPON_GUN && pOwnerChar->HasTelegunGun())))
|
2018-02-14 15:27:26 +00:00
|
|
|
{
|
2018-07-15 22:43:54 +00:00
|
|
|
int MapIndex = GameServer()->Collision()->GetPureMapIndex(pTargetChr ? pTargetChr->m_Pos : ColPos);
|
2018-07-14 23:04:26 +00:00
|
|
|
int TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex);
|
2021-12-19 11:05:51 +00:00
|
|
|
bool IsSwitchTeleGun = GameServer()->Collision()->GetSwitchType(MapIndex) == TILE_ALLOW_TELE_GUN;
|
|
|
|
bool IsBlueSwitchTeleGun = GameServer()->Collision()->GetSwitchType(MapIndex) == TILE_ALLOW_BLUE_TELE_GUN;
|
2018-02-14 15:27:26 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(IsSwitchTeleGun || IsBlueSwitchTeleGun)
|
|
|
|
{
|
2018-10-26 15:05:21 +00:00
|
|
|
// Delay specifies which weapon the tile should work for.
|
|
|
|
// Delay = 0 means all.
|
|
|
|
int delay = GameServer()->Collision()->GetSwitchDelay(MapIndex);
|
|
|
|
|
|
|
|
if(delay == 1 && m_Type != WEAPON_GUN)
|
2018-11-02 23:02:20 +00:00
|
|
|
IsSwitchTeleGun = IsBlueSwitchTeleGun = false;
|
2018-10-26 15:05:21 +00:00
|
|
|
if(delay == 2 && m_Type != WEAPON_GRENADE)
|
2018-11-02 23:02:20 +00:00
|
|
|
IsSwitchTeleGun = IsBlueSwitchTeleGun = false;
|
2019-11-22 14:37:18 +00:00
|
|
|
if(delay == 3 && m_Type != WEAPON_LASER)
|
2018-11-02 23:02:20 +00:00
|
|
|
IsSwitchTeleGun = IsBlueSwitchTeleGun = false;
|
2018-10-26 15:05:21 +00:00
|
|
|
}
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(TileFIndex == TILE_ALLOW_TELE_GUN || TileFIndex == TILE_ALLOW_BLUE_TELE_GUN || IsSwitchTeleGun || IsBlueSwitchTeleGun || pTargetChr)
|
2018-02-14 15:27:26 +00:00
|
|
|
{
|
2018-07-14 23:04:26 +00:00
|
|
|
bool Found;
|
|
|
|
vec2 PossiblePos;
|
2018-02-14 15:27:26 +00:00
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!Collide)
|
2020-10-12 14:23:09 +00:00
|
|
|
Found = GetNearestAirPosPlayer(pTargetChr ? pTargetChr->m_Pos : ColPos, &PossiblePos);
|
2018-07-14 23:04:26 +00:00
|
|
|
else
|
|
|
|
Found = GetNearestAirPos(NewPos, CurPos, &PossiblePos);
|
2018-02-14 15:27:26 +00:00
|
|
|
|
2020-11-20 11:14:04 +00:00
|
|
|
if(Found)
|
2018-02-14 15:27:26 +00:00
|
|
|
{
|
2018-07-15 09:58:12 +00:00
|
|
|
pOwnerChar->m_TeleGunPos = PossiblePos;
|
|
|
|
pOwnerChar->m_TeleGunTeleport = true;
|
2018-11-13 12:05:15 +00:00
|
|
|
pOwnerChar->m_IsBlueTeleGunTeleport = TileFIndex == TILE_ALLOW_BLUE_TELE_GUN || IsBlueSwitchTeleGun;
|
2018-02-14 15:27:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-06 22:06:43 +00:00
|
|
|
if(Collide && m_Bouncing != 0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
|
|
|
m_StartTick = Server()->Tick();
|
2020-09-26 19:41:58 +00:00
|
|
|
m_Pos = NewPos + (-(m_Direction * 4));
|
|
|
|
if(m_Bouncing == 1)
|
2010-09-06 22:06:43 +00:00
|
|
|
m_Direction.x = -m_Direction.x;
|
|
|
|
else if(m_Bouncing == 2)
|
2015-04-18 20:29:28 +00:00
|
|
|
m_Direction.y = -m_Direction.y;
|
2022-03-21 06:10:44 +00:00
|
|
|
if(fabs(m_Direction.x) < 1e-6f)
|
2013-01-06 04:37:19 +00:00
|
|
|
m_Direction.x = 0;
|
2022-03-21 06:10:44 +00:00
|
|
|
if(fabs(m_Direction.y) < 1e-6f)
|
2013-01-06 04:37:19 +00:00
|
|
|
m_Direction.y = 0;
|
2010-07-29 05:21:18 +00:00
|
|
|
m_Pos += m_Direction;
|
|
|
|
}
|
2020-09-26 19:41:58 +00:00
|
|
|
else if(m_Type == WEAPON_GUN)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
GameServer()->CreateDamageInd(CurPos, -atan2(m_Direction.x, m_Direction.y), 10, (m_Owner != -1) ? TeamMask : -1LL);
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2018-01-22 13:15:53 +00:00
|
|
|
return;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
else
|
2018-03-24 13:01:01 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
if(!m_Freeze)
|
2018-01-22 13:15:53 +00:00
|
|
|
{
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2018-01-22 13:15:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-24 13:01:01 +00:00
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2011-04-11 22:27:52 +00:00
|
|
|
if(m_LifeSpan == -1)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2014-05-18 14:19:05 +00:00
|
|
|
if(m_Explosive)
|
|
|
|
{
|
|
|
|
if(m_Owner >= 0)
|
|
|
|
pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
|
|
|
|
2022-03-20 11:57:50 +00:00
|
|
|
TeamMask = -1LL;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pOwnerChar && pOwnerChar->IsAlive())
|
2014-05-18 14:19:05 +00:00
|
|
|
{
|
2022-05-04 12:34:58 +00:00
|
|
|
TeamMask = pOwnerChar->TeamMask();
|
2014-05-18 14:19:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-02 20:04:11 +00:00
|
|
|
GameServer()->CreateExplosion(ColPos, m_Owner, m_Type, m_Owner == -1, (!pOwnerChar ? -1 : pOwnerChar->Team()),
|
2020-09-26 19:41:58 +00:00
|
|
|
(m_Owner != -1) ? TeamMask : -1LL);
|
2014-05-18 14:19:05 +00:00
|
|
|
GameServer()->CreateSound(ColPos, m_SoundImpact,
|
2020-09-26 19:41:58 +00:00
|
|
|
(m_Owner != -1) ? TeamMask : -1LL);
|
2014-05-18 14:19:05 +00:00
|
|
|
}
|
2021-05-22 18:02:00 +00:00
|
|
|
m_MarkedForDestroy = true;
|
2018-01-22 13:15:53 +00:00
|
|
|
return;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2013-07-18 22:27:08 +00:00
|
|
|
|
|
|
|
int x = GameServer()->Collision()->GetIndex(PrevPos, CurPos);
|
2013-08-13 02:59:25 +00:00
|
|
|
int z;
|
2020-09-26 19:41:58 +00:00
|
|
|
if(g_Config.m_SvOldTeleportWeapons)
|
2013-08-13 02:59:25 +00:00
|
|
|
z = GameServer()->Collision()->IsTeleport(x);
|
|
|
|
else
|
|
|
|
z = GameServer()->Collision()->IsTeleportWeapon(x);
|
2020-05-25 13:08:24 +00:00
|
|
|
CGameControllerDDRace *pControllerDDRace = (CGameControllerDDRace *)GameServer()->m_pController;
|
2022-01-22 12:54:25 +00:00
|
|
|
if(z && !pControllerDDRace->m_TeleOuts[z - 1].empty())
|
2013-07-18 22:27:08 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
int TeleOut = GameServer()->m_World.m_Core.RandomOr0(pControllerDDRace->m_TeleOuts[z - 1].size());
|
|
|
|
m_Pos = pControllerDDRace->m_TeleOuts[z - 1][TeleOut];
|
2013-07-18 22:27:08 +00:00
|
|
|
m_StartTick = Server()->Tick();
|
|
|
|
}
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 23:49:31 +00:00
|
|
|
void CProjectile::TickPaused()
|
|
|
|
{
|
|
|
|
++m_StartTick;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CProjectile::FillInfo(CNetObj_Projectile *pProj)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
pProj->m_X = (int)m_Pos.x;
|
|
|
|
pProj->m_Y = (int)m_Pos.y;
|
2020-09-26 19:41:58 +00:00
|
|
|
pProj->m_VelX = (int)(m_Direction.x * 100.0f);
|
|
|
|
pProj->m_VelY = (int)(m_Direction.y * 100.0f);
|
2010-05-29 07:25:38 +00:00
|
|
|
pProj->m_StartTick = m_StartTick;
|
|
|
|
pProj->m_Type = m_Type;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CProjectile::Snap(int SnappingClient)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
float Ct = (Server()->Tick() - m_StartTick) / (float)Server()->TickSpeed();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-10-25 00:34:28 +00:00
|
|
|
if(NetworkClipped(SnappingClient, GetPos(Ct)))
|
|
|
|
return;
|
|
|
|
|
2021-08-30 22:05:56 +00:00
|
|
|
if(m_LifeSpan == -2)
|
|
|
|
{
|
|
|
|
CNetObj_EntityEx *pEntData = static_cast<CNetObj_EntityEx *>(Server()->SnapNewItem(NETOBJTYPE_ENTITYEX, GetID(), sizeof(CNetObj_EntityEx)));
|
|
|
|
if(!pEntData)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pEntData->m_SwitchNumber = m_Number;
|
|
|
|
pEntData->m_Layer = m_Layer;
|
|
|
|
pEntData->m_EntityClass = ENTITYCLASS_PROJECTILE;
|
|
|
|
}
|
|
|
|
|
2022-03-04 20:23:32 +00:00
|
|
|
int SnappingClientVersion = SnappingClient != SERVER_DEMO_CLIENT ? GameServer()->GetClientVersion(SnappingClient) : CLIENT_VERSIONNR;
|
2021-09-19 12:14:00 +00:00
|
|
|
if(SnappingClientVersion < VERSION_DDNET_SWITCH)
|
|
|
|
{
|
|
|
|
CCharacter *pSnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
int Tick = (Server()->Tick() % Server()->TickSpeed()) % ((m_Explosive) ? 6 : 20);
|
|
|
|
if(pSnapChar && pSnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && m_Number > 0 && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pSnapChar->Team()] && (!Tick)))
|
|
|
|
return;
|
|
|
|
}
|
2010-11-14 09:36:00 +00:00
|
|
|
|
2014-01-12 14:48:53 +00:00
|
|
|
CCharacter *pOwnerChar = 0;
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t TeamMask = -1LL;
|
2014-01-12 14:48:53 +00:00
|
|
|
|
|
|
|
if(m_Owner >= 0)
|
|
|
|
pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
if(pOwnerChar && pOwnerChar->IsAlive())
|
2022-05-04 12:34:58 +00:00
|
|
|
TeamMask = pOwnerChar->TeamMask();
|
2014-01-12 14:48:53 +00:00
|
|
|
|
2022-03-04 20:23:32 +00:00
|
|
|
if(SnappingClient != SERVER_DEMO_CLIENT && m_Owner != -1 && !CmaskIsSet(TeamMask, SnappingClient))
|
2010-10-02 01:25:42 +00:00
|
|
|
return;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2021-01-17 16:18:08 +00:00
|
|
|
CNetObj_DDNetProjectile DDNetProjectile;
|
|
|
|
if(SnappingClientVersion >= VERSION_DDNET_ANTIPING_PROJECTILE && FillExtraInfo(&DDNetProjectile))
|
2014-12-01 00:31:58 +00:00
|
|
|
{
|
2021-02-24 16:09:39 +00:00
|
|
|
int Type = SnappingClientVersion < VERSION_DDNET_MSG_LEGACY ? (int)NETOBJTYPE_PROJECTILE : NETOBJTYPE_DDNETPROJECTILE;
|
2021-01-17 16:18:08 +00:00
|
|
|
void *pProj = Server()->SnapNewItem(Type, GetID(), sizeof(DDNetProjectile));
|
|
|
|
if(!pProj)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mem_copy(pProj, &DDNetProjectile, sizeof(DDNetProjectile));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, GetID(), sizeof(CNetObj_Projectile)));
|
|
|
|
if(!pProj)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FillInfo(pProj);
|
2014-12-01 00:31:58 +00:00
|
|
|
}
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2021-12-14 09:35:00 +00:00
|
|
|
void CProjectile::SwapClients(int Client1, int Client2)
|
|
|
|
{
|
|
|
|
m_Owner = m_Owner == Client1 ? Client2 : m_Owner == Client2 ? Client1 : m_Owner;
|
|
|
|
}
|
|
|
|
|
2011-04-09 06:41:31 +00:00
|
|
|
// DDRace
|
|
|
|
|
|
|
|
void CProjectile::SetBouncing(int Value)
|
|
|
|
{
|
|
|
|
m_Bouncing = Value;
|
|
|
|
}
|
2014-12-01 00:31:58 +00:00
|
|
|
|
2021-01-17 16:18:08 +00:00
|
|
|
bool CProjectile::FillExtraInfo(CNetObj_DDNetProjectile *pProj)
|
2014-12-01 00:31:58 +00:00
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
const int MaxPos = 0x7fffffff / 100;
|
|
|
|
if(abs((int)m_Pos.y) + 1 >= MaxPos || abs((int)m_Pos.x) + 1 >= MaxPos)
|
2014-12-02 00:08:52 +00:00
|
|
|
{
|
|
|
|
//If the modified data would be too large to fit in an integer, send normal data instead
|
2021-01-17 16:18:08 +00:00
|
|
|
return false;
|
2014-12-02 00:08:52 +00:00
|
|
|
}
|
2014-12-01 00:31:58 +00:00
|
|
|
//Send additional/modified info, by modifiying the fields of the netobj
|
|
|
|
float Angle = -atan2f(m_Direction.x, m_Direction.y);
|
|
|
|
|
|
|
|
int Data = 0;
|
2020-09-26 19:41:58 +00:00
|
|
|
Data |= (abs(m_Owner) & 255) << 0;
|
2014-12-01 00:31:58 +00:00
|
|
|
if(m_Owner < 0)
|
2021-01-17 16:18:08 +00:00
|
|
|
Data |= PROJECTILEFLAG_NO_OWNER;
|
|
|
|
//This bit tells the client to use the extra info
|
|
|
|
Data |= PROJECTILEFLAG_IS_DDNET;
|
|
|
|
// PROJECTILEFLAG_BOUNCE_HORIZONTAL, PROJECTILEFLAG_BOUNCE_VERTICAL
|
2020-09-26 19:41:58 +00:00
|
|
|
Data |= (m_Bouncing & 3) << 10;
|
2014-12-01 00:31:58 +00:00
|
|
|
if(m_Explosive)
|
2021-01-17 16:18:08 +00:00
|
|
|
Data |= PROJECTILEFLAG_EXPLOSIVE;
|
2014-12-01 00:31:58 +00:00
|
|
|
if(m_Freeze)
|
2021-01-17 16:18:08 +00:00
|
|
|
Data |= PROJECTILEFLAG_FREEZE;
|
2014-12-01 00:31:58 +00:00
|
|
|
|
2014-12-02 00:08:52 +00:00
|
|
|
pProj->m_X = (int)(m_Pos.x * 100.0f);
|
|
|
|
pProj->m_Y = (int)(m_Pos.y * 100.0f);
|
2021-01-17 16:18:08 +00:00
|
|
|
pProj->m_Angle = (int)(Angle * 1000000.0f);
|
|
|
|
pProj->m_Data = Data;
|
2014-12-01 00:31:58 +00:00
|
|
|
pProj->m_StartTick = m_StartTick;
|
|
|
|
pProj->m_Type = m_Type;
|
2021-01-17 16:18:08 +00:00
|
|
|
return true;
|
2014-12-01 00:31:58 +00:00
|
|
|
}
|