2010-05-29 07:25:38 +00:00
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/shared/config.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "projectile.h"
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-08-23 21:40:23 +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 Weapon)
|
2010-05-29 07:25:38 +00:00
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_PROJECTILE)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Type = Type;
|
|
|
|
m_Pos = Pos;
|
2010-08-26 17:55:22 +00:00
|
|
|
m_StartPos = Pos;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Direction = Dir;
|
2010-08-26 17:55:22 +00:00
|
|
|
m_StartDir = Dir;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_LifeSpan = Span;
|
|
|
|
m_Owner = Owner;
|
|
|
|
m_Force = Force;
|
2010-07-29 05:21:18 +00:00
|
|
|
//m_Damage = Damage;
|
|
|
|
m_Freeze = Freeze;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_SoundImpact = SoundImpact;
|
|
|
|
m_Weapon = Weapon;
|
|
|
|
m_StartTick = Server()->Tick();
|
|
|
|
m_Explosive = Explosive;
|
2010-08-23 21:40:23 +00:00
|
|
|
m_BouncePos=vec2(0,0);
|
|
|
|
m_ReBouncePos=vec2(0,0);
|
|
|
|
m_LastBounce=vec2(0,0);
|
|
|
|
m_PrevLastBounce=vec2(0,0);
|
2010-08-26 17:55:22 +00:00
|
|
|
m_LastRestart = 0;
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
case WEAPON_SHOTGUN:
|
|
|
|
Curvature = GameServer()->Tuning()->m_ShotgunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_ShotgunSpeed;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WEAPON_GUN:
|
|
|
|
Curvature = GameServer()->Tuning()->m_GunCurvature;
|
|
|
|
Speed = GameServer()->Tuning()->m_GunSpeed;
|
|
|
|
break;
|
2008-08-14 18:25:44 +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-08-23 21:40:23 +00:00
|
|
|
void CProjectile::SetBouncing(int Value)
|
|
|
|
{
|
2010-08-14 10:46:54 +00:00
|
|
|
m_Bouncing = Value;
|
|
|
|
}
|
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;
|
|
|
|
vec2 Speed = CurPos - PrevPos;
|
2010-08-21 02:20:01 +00:00
|
|
|
int Collide = GameServer()->Collision()->IntersectLine(PrevPos, CurPos, &ColPos, &NewPos,false);
|
2010-07-29 05:21:18 +00:00
|
|
|
CCharacter *OwnerChar;
|
2008-08-14 18:25:44 +00:00
|
|
|
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
|
|
if(m_Owner >= 0)
|
|
|
|
OwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
|
|
|
|
2010-08-14 10:46:54 +00:00
|
|
|
CCharacter *TargetChr = GameServer()->m_World.IntersectCharacter(PrevPos, ColPos, (m_Freeze) ? 1.0f : 6.0f, ColPos, OwnerChar);
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
if(m_LifeSpan > -1)
|
|
|
|
m_LifeSpan--;
|
|
|
|
|
2010-08-29 12:28:21 +00:00
|
|
|
if( (TargetChr && (g_Config.m_SvHit || m_Owner == -1 || TargetChr == OwnerChar)) || Collide)//TODO:TEAM
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-29 12:28:21 +00:00
|
|
|
//if(OwnerChar != 0 && OwnerChar->Team() != TargetChr->Team()) return;
|
2010-07-29 05:21:18 +00:00
|
|
|
if(m_Explosive/*??*/ && (!TargetChr || (TargetChr && !m_Freeze)))
|
|
|
|
{
|
2010-08-29 02:24:43 +00:00
|
|
|
GameServer()->CreateExplosion(ColPos, m_Owner, m_Weapon, (m_Owner == -1)?true:false);
|
2010-07-29 05:21:18 +00:00
|
|
|
GameServer()->CreateSound(ColPos, m_SoundImpact);
|
|
|
|
}
|
|
|
|
else if(TargetChr && m_Freeze)
|
|
|
|
TargetChr->Freeze(Server()->TickSpeed()*3);
|
|
|
|
if (Collide && m_Bouncing != 0)
|
|
|
|
{
|
|
|
|
m_StartTick = Server()->Tick();
|
|
|
|
m_Pos = NewPos;
|
2010-08-26 17:55:22 +00:00
|
|
|
if(g_Config.m_SvShotgunReset > m_LastRestart)
|
|
|
|
{
|
|
|
|
m_Pos = m_StartPos;
|
|
|
|
m_Direction = m_StartDir;
|
|
|
|
m_StartTick = Server()->Tick();
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
if (m_Bouncing == 1)
|
2010-08-23 21:40:23 +00:00
|
|
|
{
|
2010-08-23 23:21:35 +00:00
|
|
|
m_PrevLastBounce.x = m_LastBounce.x;
|
|
|
|
m_LastBounce.x = m_Pos.x;
|
2010-08-23 21:40:23 +00:00
|
|
|
if(!m_BouncePos.x)
|
2010-08-23 23:21:35 +00:00
|
|
|
m_BouncePos.x=m_Pos.x;
|
2010-08-23 21:40:23 +00:00
|
|
|
else if (!m_ReBouncePos.x)
|
2010-08-23 23:21:35 +00:00
|
|
|
m_ReBouncePos.x=m_Pos.x;
|
2010-08-26 17:55:22 +00:00
|
|
|
m_Direction.x =- m_Direction.x;
|
2010-08-23 23:21:35 +00:00
|
|
|
if(!((m_PrevLastBounce.x+1 == m_BouncePos.x || m_PrevLastBounce.x-1 == m_BouncePos.x || m_PrevLastBounce.x == m_BouncePos.x) && (m_LastBounce.x == m_ReBouncePos.x || m_LastBounce.x+1 == m_ReBouncePos.x || m_LastBounce.x-1 == m_ReBouncePos.x)) && !((m_LastBounce.x == m_BouncePos.x || m_LastBounce.x+1 == m_BouncePos.x || m_LastBounce.x-1 == m_BouncePos.x) && (m_PrevLastBounce.x+1 == m_ReBouncePos.x || m_PrevLastBounce.x-1 == m_ReBouncePos.x || m_PrevLastBounce.x == m_ReBouncePos.x)))
|
|
|
|
{
|
|
|
|
/*int bx=(int)m_BouncePos.x;
|
|
|
|
int rbx=(int)m_ReBouncePos.x;
|
|
|
|
int lbx=(int)m_LastBounce.x;
|
|
|
|
int plbx=(int)m_PrevLastBounce.x;
|
|
|
|
dbg_msg("m_BouncePos","%d",bx);
|
|
|
|
dbg_msg("m_ReBouncePos","%d",rbx);
|
|
|
|
dbg_msg("m_LastBounce","%d",lbx);
|
|
|
|
dbg_msg("m_PrevLastBounce","%d",plbx);
|
|
|
|
m_Pos.x=m_AvgPos.x;*/
|
2010-08-26 17:55:22 +00:00
|
|
|
g_Config.m_SvShotgunReset++;
|
2010-08-23 23:21:35 +00:00
|
|
|
dbg_msg("CrazyShotgun","Warning Horizontal Crazy Shotgun Out of bounds");
|
|
|
|
/*int x=(int)m_Pos.x;
|
|
|
|
dbg_msg("RePos","%d",x);*/
|
|
|
|
}
|
2010-08-23 21:40:23 +00:00
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
else if (m_Bouncing == 2)
|
2010-08-23 21:40:23 +00:00
|
|
|
{
|
2010-08-23 23:21:35 +00:00
|
|
|
m_PrevLastBounce.y = m_LastBounce.y;
|
|
|
|
m_LastBounce.y = m_Pos.y;
|
2010-08-23 21:40:23 +00:00
|
|
|
if(!m_BouncePos.y)
|
2010-08-23 23:21:35 +00:00
|
|
|
m_BouncePos.y=m_Pos.y;
|
2010-08-23 21:40:23 +00:00
|
|
|
else if (!m_ReBouncePos.y)
|
2010-08-23 23:21:35 +00:00
|
|
|
m_ReBouncePos.y=m_Pos.y;
|
|
|
|
m_Direction.y =- m_Direction.y;
|
2010-08-26 17:55:22 +00:00
|
|
|
if(!((m_PrevLastBounce.y+1 == m_BouncePos.y || m_PrevLastBounce.y-1 == m_BouncePos.y || m_PrevLastBounce.y == m_BouncePos.y) && (m_LastBounce.y == m_ReBouncePos.y || m_LastBounce.y+1 == m_ReBouncePos.y || m_LastBounce.y-1 == m_ReBouncePos.y)) && !((m_LastBounce.y == m_BouncePos.y || m_LastBounce.y+1 == m_BouncePos.y || m_LastBounce.y-1 == m_BouncePos.y) && (m_PrevLastBounce.y+1 == m_ReBouncePos.y || m_PrevLastBounce.y-1 == m_ReBouncePos.y || m_PrevLastBounce.y == m_ReBouncePos.y)))
|
2010-08-23 23:21:35 +00:00
|
|
|
{
|
|
|
|
/*int by=(int)m_BouncePos.y;
|
|
|
|
int rby=(int)m_ReBouncePos.y;
|
|
|
|
int lby=(int)m_LastBounce.y;
|
|
|
|
int plby=(int)m_PrevLastBounce.y;
|
|
|
|
dbg_msg("m_BouncePos","%d",by);
|
|
|
|
dbg_msg("m_ReBouncePos","%d",rby);
|
|
|
|
dbg_msg("m_LastBounce","%d",lby);
|
2010-08-26 17:55:22 +00:00
|
|
|
dbg_msg("m_PrevLastBounce","%d",plby);
|
|
|
|
m_Pos=m_AvgPos;*/
|
|
|
|
g_Config.m_SvShotgunReset++;
|
2010-08-23 23:21:35 +00:00
|
|
|
dbg_msg("CrazyShotgun","Warning Vertical Crazy Shotgun Out of bounds");
|
|
|
|
/*int y=(int)m_Pos.y;
|
|
|
|
dbg_msg("RePos","%d",y);*/
|
|
|
|
}
|
2010-08-23 21:40:23 +00:00
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
m_Pos += m_Direction;
|
|
|
|
}
|
|
|
|
else if (m_Weapon == WEAPON_GUN)
|
|
|
|
{
|
|
|
|
GameServer()->CreateDamageInd(CurPos, -atan2(m_Direction.x, m_Direction.y), 10);
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (!m_Freeze)
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
if (m_LifeSpan == -1)
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2010-08-23 21:40:23 +00:00
|
|
|
|
2010-08-23 23:21:35 +00:00
|
|
|
|
|
|
|
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
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();
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NetworkClipped(SnappingClient, GetPos(Ct)))
|
2008-08-14 18:25:44 +00:00
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, m_Id, sizeof(CNetObj_Projectile)));
|
|
|
|
FillInfo(pProj);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|