2010-07-29 05:21:18 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
|
|
|
#include <engine/config.h>
|
|
|
|
#include <engine/server.h>
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/server/gamecontext.h>
|
|
|
|
#include "light.h"
|
|
|
|
#include <game/mapitems.h>
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
// CLight
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
CLight::CLight(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length)
|
2010-07-29 05:21:18 +00:00
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_LASER)
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
m_Tick=(Server()->TickSpeed()*0.15f);
|
|
|
|
m_Pos = Pos;
|
|
|
|
m_Rotation = Rotation;
|
|
|
|
m_Length = Length;
|
|
|
|
m_EvalTick = Server()->Tick();
|
2010-07-29 05:21:18 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
2010-08-30 23:45:42 +00:00
|
|
|
Step();
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
bool CLight::HitCharacter()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-10 06:55:04 +00:00
|
|
|
std::list < CCharacter * > HitCharacters = GameServer()->m_World.IntersectedCharacters(m_Pos, m_To, 0.0f, 0);
|
|
|
|
if(HitCharacters.empty()) return false;
|
|
|
|
for(std::list < CCharacter * >::iterator i = HitCharacters.begin(); i != HitCharacters.end(); i++) {
|
2010-08-31 17:32:25 +00:00
|
|
|
CCharacter * Char = *i;
|
|
|
|
Char->Freeze(Server()->TickSpeed()*3);
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
void CLight::Move()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
if (m_Speed != 0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
if ((m_CurveLength>=m_Length && m_Speed>0) || (m_CurveLength<=0 && m_Speed<0))
|
|
|
|
m_Speed=-m_Speed;
|
|
|
|
m_CurveLength+=m_Speed*m_Tick + m_LengthL;
|
|
|
|
m_LengthL=0;
|
|
|
|
if (m_CurveLength>m_Length)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
m_LengthL=m_CurveLength-m_Length;
|
|
|
|
m_CurveLength=m_Length;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-08-30 23:45:42 +00:00
|
|
|
else if(m_CurveLength<0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
m_LengthL=0+m_CurveLength;
|
|
|
|
m_CurveLength=0;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
2010-10-07 13:28:29 +00:00
|
|
|
|
|
|
|
m_Rotation+=m_AngularSpeed*m_Tick;
|
2010-08-30 23:45:42 +00:00
|
|
|
if (m_Rotation>pi*2)
|
|
|
|
m_Rotation-=pi*2;
|
|
|
|
else if(m_Rotation<0)
|
|
|
|
m_Rotation+=pi*2;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
void CLight::Step()
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
Move();
|
|
|
|
vec2 dir(sin(m_Rotation), cos(m_Rotation));
|
|
|
|
vec2 to2 = m_Pos + normalize(dir)*m_CurveLength;
|
|
|
|
GameServer()->Collision()->IntersectNoLaser(m_Pos, to2, &m_To,0 );
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLight::Reset()
|
|
|
|
{
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLight::Tick()
|
|
|
|
{
|
|
|
|
|
2010-10-07 13:28:29 +00:00
|
|
|
if (Server()->Tick()%int(Server()->TickSpeed()*0.15f)==0)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
m_EvalTick=Server()->Tick();
|
2010-07-29 05:21:18 +00:00
|
|
|
int index = GameServer()->Collision()->IsCp(m_Pos.x,m_Pos.y);
|
|
|
|
if (index)
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
m_Core=GameServer()->Collision()->CpSpeed(index);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-08-30 23:45:42 +00:00
|
|
|
m_Pos+=m_Core;
|
|
|
|
Step();
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-10-07 13:28:29 +00:00
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
HitCharacter();
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLight::Snap(int snapping_client)
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
if(NetworkClipped(snapping_client,m_Pos) && NetworkClipped(snapping_client,m_To))
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_Id, sizeof(CNetObj_Laser)));
|
|
|
|
pObj->m_X = (int)m_Pos.x;
|
|
|
|
pObj->m_Y = (int)m_Pos.y;
|
2010-08-30 23:45:42 +00:00
|
|
|
pObj->m_FromX = (int)m_To.x;
|
|
|
|
pObj->m_FromY = (int)m_To.y;
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
|
|
|
2010-10-07 13:28:29 +00:00
|
|
|
int start_tick = m_EvalTick;
|
|
|
|
if (start_tick<Server()->Tick()-4)
|
|
|
|
start_tick=Server()->Tick()-4;
|
|
|
|
else if (start_tick>Server()->Tick())
|
|
|
|
start_tick=Server()->Tick();
|
|
|
|
pObj->m_StartTick = start_tick;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|