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>
|
2010-08-21 17:32:42 +00:00
|
|
|
|
#include "dragger.h"
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////
|
2010-08-21 17:32:42 +00:00
|
|
|
|
// CDragger
|
2010-07-29 05:21:18 +00:00
|
|
|
|
//////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
const int LENGTH=700;
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW)
|
2010-09-21 19:09:11 +00:00
|
|
|
|
: CEntity(pGameWorld, NETOBJTYPE_LASER), m_Targets()
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
|
m_Pos = Pos;
|
|
|
|
|
m_Strength = Strength;
|
|
|
|
|
m_EvalTick = Server()->Tick();
|
|
|
|
|
m_NW = NW;
|
2010-09-21 19:09:11 +00:00
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
void CDragger::Move()
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
if (m_Targets.empty())
|
2010-07-29 05:21:18 +00:00
|
|
|
|
return;
|
2010-08-30 23:45:42 +00:00
|
|
|
|
CCharacter *Ents[16];
|
2010-09-21 19:09:11 +00:00
|
|
|
|
int IdInTeam[16];
|
|
|
|
|
int LenInTeam[16];
|
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
IdInTeam[i] = -1;
|
|
|
|
|
LenInTeam[i] = 0;
|
|
|
|
|
}
|
2010-08-30 23:45:42 +00:00
|
|
|
|
int Num = -1;
|
|
|
|
|
Num = GameServer()->m_World.FindEntities(m_Pos,LENGTH, (CEntity**)Ents, 16, NETOBJTYPE_CHARACTER);
|
|
|
|
|
for (int i = 0; i < Num; i++)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
CCharacter * Target = Ents[i];
|
|
|
|
|
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, Target->m_Pos, 0, 0) :
|
|
|
|
|
GameServer()->Collision()->IntersectNoLaser(m_Pos, Target->m_Pos, 0, 0);
|
2010-07-29 05:21:18 +00:00
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
if (Res==0)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
int Len=length(Target->m_Pos - m_Pos);
|
|
|
|
|
if (LenInTeam[Target->Team()] == 0 || LenInTeam[Target->Team()] > Len)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
LenInTeam[Target->Team()] = Len;
|
|
|
|
|
IdInTeam[Target->Team()] = i;
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-21 19:09:11 +00:00
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
|
if(IdInTeam[i] != -1) {
|
|
|
|
|
CCharacter *Target = Ents[IdInTeam[i]];
|
|
|
|
|
m_Targets.push_back(Target);
|
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
void CDragger::Drag()
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
if (!m_Targets.empty())
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
/*
|
|
|
|
|
int Res = m_NW ? GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0) :
|
|
|
|
|
GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
|
|
|
|
|
if (Res || length(m_Pos-m_Target->m_Pos)>700)//TODO: USE CONSTANTS IDIOT
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
m_Targets.clear();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
2010-09-21 19:09:11 +00:00
|
|
|
|
else {
|
|
|
|
|
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
|
|
|
|
|
CCharacter * Target = *i;
|
|
|
|
|
if (length(m_Pos-Target->m_Pos)>28) {
|
2010-09-21 23:41:23 +00:00
|
|
|
|
if(((m_Target->m_TileIndexL == TILE_STOPA || m_Target->m_TileFIndexL == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPL || m_Target->m_TileFIndex == TILE_STOPL || m_Target->m_TileFIndexL == TILE_STOPL || m_Target->m_TileIndexL == TILE_STOPH || m_Target->m_TileFIndexL == TILE_STOPH)) || ((m_Target->m_TileIndexR == TILE_STOPA || m_Target->m_TileFIndexR == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPR || m_Target->m_TileFIndex == TILE_STOPR || m_Target->m_TileFIndexR == TILE_STOPR || m_Target->m_TileIndexR == TILE_STOPH || m_Target->m_TileFIndexR == TILE_STOPH)))
|
2010-09-19 09:01:54 +00:00
|
|
|
|
{
|
|
|
|
|
m_Target->m_Core.m_Vel.y +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength).y;
|
2010-09-19 19:00:29 +00:00
|
|
|
|
//dbg_msg("","x");
|
2010-09-19 09:01:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2010-09-21 23:41:23 +00:00
|
|
|
|
if(((m_Target->m_TileIndexB == TILE_STOPA || m_Target->m_TileFIndexB == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPB || m_Target->m_TileIndexB == TILE_STOPB || m_Target->m_TileFIndex == TILE_STOPB || m_Target->m_TileFIndexB == TILE_STOPB|| m_Target->m_TileIndexB == TILE_STOPV || m_Target->m_TileFIndexB == TILE_STOPV)) || ((m_Target->m_TileIndexT == TILE_STOPA || m_Target->m_TileFIndexT == TILE_STOPA || m_Target->m_TileIndex == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPT || m_Target->m_TileFIndex == TILE_STOPT || m_Target->m_TileFIndexT == TILE_STOPT || m_Target->m_TileIndexT == TILE_STOPV || m_Target->m_TileFIndexT == TILE_STOPV)))
|
2010-09-19 09:01:54 +00:00
|
|
|
|
{
|
|
|
|
|
m_Target->m_Core.m_Vel.x +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength).x;
|
2010-09-19 19:00:29 +00:00
|
|
|
|
//dbg_msg("y","");
|
2010-09-19 09:01:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//m_Target->m_Core.m_Vel = Temp;
|
2010-09-21 23:41:23 +00:00
|
|
|
|
m_Target->m_Core.m_Vel +=(normalize(m_Pos-m_Target->m_Pos)*m_Strength);
|
2010-09-16 18:44:47 +00:00
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 17:32:42 +00:00
|
|
|
|
void CDragger::Reset()
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
m_Targets.clear();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-21 17:32:42 +00:00
|
|
|
|
void CDragger::Tick()
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
|
|
|
|
if (Server()->Tick()%int(Server()->TickSpeed()*0.15f)==0)
|
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
|
m_EvalTick=Server()->Tick();
|
|
|
|
|
int Index = GameServer()->Collision()->IsCp(m_Pos.x, m_Pos.y);
|
|
|
|
|
if (Index)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
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;
|
|
|
|
|
Move();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
2010-08-30 23:45:42 +00:00
|
|
|
|
Drag();
|
2010-07-29 05:21:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
void CDragger::Snap(int SnappingClient)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
/*
|
|
|
|
|
if (m_Targets.empty())
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-09-21 19:09:11 +00:00
|
|
|
|
for(std::list<CCharacter * >::iterator i = m_Targets.begin(); i != m_Targets.end(); ++i) {
|
|
|
|
|
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,(*i)->m_Pos))
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2010-08-30 23:45:42 +00:00
|
|
|
|
if(NetworkClipped(SnappingClient,m_Pos))
|
2010-07-29 05:21:18 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2010-09-08 16:22:11 +00:00
|
|
|
|
CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
|
if(Char && m_Target && !Char->GetPlayer()->m_ShowOthers && Char->Team() != m_Target->Team()) return;
|
|
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
|
CNetObj_Laser *obj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_Id, sizeof(CNetObj_Laser)));
|
|
|
|
|
|
|
|
|
|
obj->m_X = (int)m_Pos.x;
|
|
|
|
|
obj->m_Y = (int)m_Pos.y;
|
2010-08-30 23:45:42 +00:00
|
|
|
|
if (m_Target)
|
2010-07-29 05:21:18 +00:00
|
|
|
|
{
|
2010-08-30 23:45:42 +00:00
|
|
|
|
obj->m_FromX = (int)m_Target->m_Pos.x;
|
|
|
|
|
obj->m_FromY = (int)m_Target->m_Pos.y;
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
obj->m_FromX = (int)m_Pos.x;
|
|
|
|
|
obj->m_FromY = (int)m_Pos.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
|
int StartTick = m_EvalTick;
|
|
|
|
|
if (StartTick < Server()->Tick() - 4)
|
|
|
|
|
StartTick = Server()->Tick() - 4;
|
|
|
|
|
else if (StartTick>Server()->Tick())
|
|
|
|
|
StartTick = Server()->Tick();
|
|
|
|
|
obj->m_StartTick = StartTick;
|
2010-09-21 19:09:11 +00:00
|
|
|
|
*/
|
2010-07-29 05:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
//<2F> <20><><EFBFBD> <20><><EFBFBD>
|
|
|
|
|
//<2F> <20><><EFBFBD><EFBFBD>
|