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. */
|
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>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "projectile.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
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
CProjectile::CProjectile
|
|
|
|
(
|
2010-08-23 21:40:23 +00:00
|
|
|
CGameWorld *pGameWorld,
|
|
|
|
int Type,
|
|
|
|
int Owner,
|
|
|
|
vec2 Pos,
|
|
|
|
vec2 Dir,
|
|
|
|
int Span,
|
|
|
|
bool Freeze,
|
|
|
|
bool Explosive,
|
|
|
|
float Force,
|
|
|
|
int SoundImpact,
|
2010-11-13 13:22:19 +00:00
|
|
|
int Weapon,
|
|
|
|
int Layer,
|
|
|
|
int Number
|
2010-08-30 23:45:42 +00:00
|
|
|
)
|
2011-01-19 17:27:50 +00:00
|
|
|
: 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;
|
2010-07-29 05:21:18 +00:00
|
|
|
//m_Damage = Damage;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_SoundImpact = SoundImpact;
|
|
|
|
m_Weapon = Weapon;
|
|
|
|
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;
|
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)
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
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
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
case WEAPON_GRENADE:
|
|
|
|
Curvature = GameServer()->Tuning()->m_GrenadeCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_GrenadeSpeed;
|
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
case WEAPON_SHOTGUN:
|
|
|
|
Curvature = GameServer()->Tuning()->m_ShotgunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_ShotgunSpeed;
|
|
|
|
break;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
case WEAPON_GUN:
|
|
|
|
Curvature = GameServer()->Tuning()->m_GunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->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
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float Pt = (Server()->Tick()-m_StartTick-1)/(float)Server()->TickSpeed();
|
|
|
|
float Ct = (Server()->Tick()-m_StartTick)/(float)Server()->TickSpeed();
|
|
|
|
vec2 PrevPos = GetPos(Pt);
|
|
|
|
vec2 CurPos = GetPos(Ct);
|
2010-07-29 05:21:18 +00:00
|
|
|
vec2 ColPos;
|
|
|
|
vec2 NewPos;
|
2010-09-06 22:06:43 +00:00
|
|
|
int Collide = GameServer()->Collision()->IntersectLine(PrevPos, CurPos, &ColPos, &NewPos, false);
|
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
|
|
|
|
2011-07-21 01:13:59 +00:00
|
|
|
CCharacter *pTargetChr = GameServer()->m_World.IntersectCharacter(PrevPos, ColPos, m_Freeze ? 1.0f : 6.0f, ColPos, pOwnerChar);
|
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
|
|
|
|
2010-09-22 19:01:09 +00:00
|
|
|
int TeamMask = -1;
|
2010-08-31 12:29:03 +00:00
|
|
|
bool isWeaponCollide = false;
|
2010-10-02 01:25:42 +00:00
|
|
|
if
|
|
|
|
(
|
2011-07-21 01:13:59 +00:00
|
|
|
pOwnerChar &&
|
|
|
|
pTargetChr &&
|
|
|
|
pOwnerChar->IsAlive() &&
|
|
|
|
pTargetChr->IsAlive() &&
|
|
|
|
!pTargetChr->CanCollide(m_Owner)
|
2010-10-02 01:25:42 +00:00
|
|
|
)
|
|
|
|
{
|
2010-09-22 19:01:09 +00:00
|
|
|
isWeaponCollide = true;
|
2010-10-23 12:15:29 +00:00
|
|
|
//TeamMask = OwnerChar->Teams()->TeamMask( OwnerChar->Team());
|
2010-09-22 19:01:09 +00:00
|
|
|
}
|
2011-07-21 01:13:59 +00:00
|
|
|
if (pOwnerChar && pOwnerChar->IsAlive())
|
2010-10-02 01:25:42 +00:00
|
|
|
{
|
2011-09-02 18:04:18 +00:00
|
|
|
TeamMask = pOwnerChar->Teams()->TeamMask(pOwnerChar->Team(), -1, m_Owner);
|
2010-10-02 01:25:42 +00:00
|
|
|
}
|
2011-12-26 09:56:12 +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
|
|
|
{
|
2011-07-21 01:13:59 +00:00
|
|
|
if(m_Explosive/*??*/ && (!pTargetChr || (pTargetChr && !m_Freeze)))
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2011-07-21 01:13:59 +00:00
|
|
|
GameServer()->CreateExplosion(ColPos, m_Owner, m_Weapon, m_Owner == -1, (!pTargetChr ? -1 : pTargetChr->Team()),
|
2010-09-22 19:01:09 +00:00
|
|
|
(m_Owner != -1)? TeamMask : -1);
|
2011-04-09 06:41:31 +00:00
|
|
|
GameServer()->CreateSound(ColPos, m_SoundImpact,
|
2010-09-22 19:01:09 +00:00
|
|
|
(m_Owner != -1)? TeamMask : -1);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2011-07-21 01:13:59 +00:00
|
|
|
else if(pTargetChr && m_Freeze && ((m_Layer == LAYER_SWITCH && GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pTargetChr->Team()]) || m_Layer != LAYER_SWITCH))
|
|
|
|
pTargetChr->Freeze();
|
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();
|
2010-10-11 18:19:13 +00:00
|
|
|
m_Pos = NewPos+(-(m_Direction*4));
|
2010-07-29 05:21:18 +00:00
|
|
|
if (m_Bouncing == 1)
|
2010-09-06 22:06:43 +00:00
|
|
|
m_Direction.x = -m_Direction.x;
|
|
|
|
else if(m_Bouncing == 2)
|
2010-08-23 23:21:35 +00:00
|
|
|
m_Direction.y =- m_Direction.y;
|
2013-01-06 04:37:19 +00:00
|
|
|
if (fabs(m_Direction.x) < 1e-6)
|
|
|
|
m_Direction.x = 0;
|
|
|
|
if (fabs(m_Direction.y) < 1e-6)
|
|
|
|
m_Direction.y = 0;
|
2010-07-29 05:21:18 +00:00
|
|
|
m_Pos += m_Direction;
|
|
|
|
}
|
|
|
|
else if (m_Weapon == WEAPON_GUN)
|
|
|
|
{
|
2010-10-02 01:25:42 +00:00
|
|
|
GameServer()->CreateDamageInd(CurPos, -atan2(m_Direction.x, m_Direction.y), 10, (m_Owner != -1)? TeamMask : -1);
|
2010-07-29 05:21:18 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!m_Freeze)
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
2011-04-11 22:27:52 +00:00
|
|
|
if(m_LifeSpan == -1)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
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;
|
|
|
|
if (g_Config.m_SvOldTeleportWeapons)
|
|
|
|
z = GameServer()->Collision()->IsTeleport(x);
|
|
|
|
else
|
|
|
|
z = GameServer()->Collision()->IsTeleportWeapon(x);
|
|
|
|
if (z && ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleOuts[z-1].size())
|
2013-07-18 22:27:08 +00:00
|
|
|
{
|
|
|
|
int Num = ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleOuts[z-1].size();
|
|
|
|
m_Pos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleOuts[z-1][(!Num)?Num:rand() % Num];
|
|
|
|
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;
|
|
|
|
pProj->m_VelX = (int)(m_Direction.x*100.0f);
|
|
|
|
pProj->m_VelY = (int)(m_Direction.y*100.0f);
|
|
|
|
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
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float Ct = (Server()->Tick()-m_StartTick)/(float)Server()->TickSpeed();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NetworkClipped(SnappingClient, GetPos(Ct)))
|
2008-08-14 18:25:44 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-21 01:13:59 +00:00
|
|
|
CCharacter* pSnapChar = GameServer()->GetPlayerChar(SnappingClient);
|
2010-11-14 10:13:11 +00:00
|
|
|
int Tick = (Server()->Tick()%Server()->TickSpeed())%((m_Explosive)?6:20);
|
2011-07-21 01:13:59 +00:00
|
|
|
if (pSnapChar && pSnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pSnapChar->Team()] && (!Tick)))
|
2011-04-19 13:15:40 +00:00
|
|
|
return;
|
2010-11-14 09:36:00 +00:00
|
|
|
|
2011-07-21 01:13:59 +00:00
|
|
|
if(pSnapChar && m_Owner != -1 && !pSnapChar->CanCollide(m_Owner))
|
2010-10-02 01:25:42 +00:00
|
|
|
return;
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-02-12 10:40:36 +00:00
|
|
|
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, m_ID, sizeof(CNetObj_Projectile)));
|
2010-12-16 02:29:08 +00:00
|
|
|
if(pProj)
|
|
|
|
FillInfo(pProj);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2011-04-09 06:41:31 +00:00
|
|
|
|
|
|
|
// DDRace
|
|
|
|
|
|
|
|
void CProjectile::SetBouncing(int Value)
|
|
|
|
{
|
|
|
|
m_Bouncing = Value;
|
|
|
|
}
|