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-11-13 13:22:19 +00:00
|
|
|
CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW, int CatchedTeam, int Layer, int Number)
|
2011-01-20 20:01:21 +00:00
|
|
|
: CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-11-13 13:22:19 +00:00
|
|
|
m_Layer = Layer;
|
|
|
|
m_Number = Number;
|
2010-08-30 23:45:42 +00:00
|
|
|
m_Pos = Pos;
|
|
|
|
m_Strength = Strength;
|
|
|
|
m_EvalTick = Server()->Tick();
|
|
|
|
m_NW = NW;
|
2010-09-22 10:43:59 +00:00
|
|
|
m_CatchedTeam = CatchedTeam;
|
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
|
|
|
{
|
2011-01-29 00:59:50 +00:00
|
|
|
if(m_Target && m_Target->IsAlive() && (m_Target->m_Super || (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[m_Target->Team()])))
|
2010-11-13 13:22:19 +00:00
|
|
|
m_Target = 0;
|
|
|
|
if(m_Target)
|
2010-07-29 05:21:18 +00:00
|
|
|
return;
|
2010-08-30 23:45:42 +00:00
|
|
|
CCharacter *Ents[16];
|
2011-01-20 20:01:21 +00:00
|
|
|
int Num = GameServer()->m_World.FindEntities(m_Pos,LENGTH, (CEntity**)Ents, 16, CGameWorld::ENTTYPE_CHARACTER);
|
2010-09-22 00:03:14 +00:00
|
|
|
int Id=-1;
|
|
|
|
int MinLen=0;
|
2010-08-30 23:45:42 +00:00
|
|
|
for (int i = 0; i < Num; i++)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-22 00:03:14 +00:00
|
|
|
m_Target = Ents[i];
|
2010-09-22 10:43:59 +00:00
|
|
|
if(m_Target->Team() != m_CatchedTeam) continue;
|
2010-11-13 13:22:19 +00:00
|
|
|
if(m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[m_Target->Team()]) continue;
|
2010-09-22 17:36:13 +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);
|
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-22 17:36:13 +00:00
|
|
|
int Len=length(m_Target->m_Pos - m_Pos);
|
2010-09-22 00:03:14 +00:00
|
|
|
if (MinLen==0 || MinLen>Len)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-22 00:03:14 +00:00
|
|
|
MinLen=Len;
|
|
|
|
Id=i;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-09-22 17:36:13 +00:00
|
|
|
m_Target = Id != -1 ? Ents[Id] : 0;
|
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-22 00:03:14 +00:00
|
|
|
if (m_Target)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-22 00:03:14 +00:00
|
|
|
|
|
|
|
int Res = 0;
|
|
|
|
if (!m_NW)
|
|
|
|
Res = GameServer()->Collision()->IntersectNoLaser(m_Pos, m_Target->m_Pos, 0, 0);
|
|
|
|
else
|
|
|
|
Res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, m_Target->m_Pos, 0, 0);
|
|
|
|
if (Res || length(m_Pos-m_Target->m_Pos)>700)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-22 00:03:14 +00:00
|
|
|
m_Target=0;
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-09-22 00:03:14 +00:00
|
|
|
else
|
|
|
|
if (length(m_Pos-m_Target->m_Pos)>28)
|
|
|
|
{
|
2011-01-29 00:59:50 +00:00
|
|
|
vec2 Temp = m_Target->Core()->m_Vel +(normalize(m_Pos-m_Target->m_Pos)*m_Strength);
|
2010-11-01 01:51:17 +00:00
|
|
|
if(Temp.x > 0 && ((m_Target->m_TileIndex == TILE_STOP && m_Target->m_TileFlags == ROTATION_270) || (m_Target->m_TileIndexL == TILE_STOP && m_Target->m_TileFlagsL == ROTATION_270) || (m_Target->m_TileIndexL == TILE_STOPS && (m_Target->m_TileFlagsL == ROTATION_90 || m_Target->m_TileFlagsL ==ROTATION_270)) || (m_Target->m_TileIndexL == TILE_STOPA) || (m_Target->m_TileFIndex == TILE_STOP && m_Target->m_TileFFlags == ROTATION_270) || (m_Target->m_TileFIndexL == TILE_STOP && m_Target->m_TileFFlagsL == ROTATION_270) || (m_Target->m_TileFIndexL == TILE_STOPS && (m_Target->m_TileFFlagsL == ROTATION_90 || m_Target->m_TileFFlagsL == ROTATION_270)) || (m_Target->m_TileFIndexL == TILE_STOPA) || (m_Target->m_TileSIndex == TILE_STOP && m_Target->m_TileSFlags == ROTATION_270) || (m_Target->m_TileSIndexL == TILE_STOP && m_Target->m_TileSFlagsL == ROTATION_270) || (m_Target->m_TileSIndexL == TILE_STOPS && (m_Target->m_TileSFlagsL == ROTATION_90 || m_Target->m_TileSFlagsL == ROTATION_270)) || (m_Target->m_TileSIndexL == TILE_STOPA)))
|
2010-09-22 14:25:32 +00:00
|
|
|
Temp.x = 0;
|
2010-11-01 01:51:17 +00:00
|
|
|
if(Temp.x < 0 && ((m_Target->m_TileIndex == TILE_STOP && m_Target->m_TileFlags == ROTATION_90) || (m_Target->m_TileIndexR == TILE_STOP && m_Target->m_TileFlagsR == ROTATION_90) || (m_Target->m_TileIndexR == TILE_STOPS && (m_Target->m_TileFlagsR == ROTATION_90 || m_Target->m_TileFlagsR == ROTATION_270)) || (m_Target->m_TileIndexR == TILE_STOPA) || (m_Target->m_TileFIndex == TILE_STOP && m_Target->m_TileFFlags == ROTATION_90) || (m_Target->m_TileFIndexR == TILE_STOP && m_Target->m_TileFFlagsR == ROTATION_90) || (m_Target->m_TileFIndexR == TILE_STOPS && (m_Target->m_TileFFlagsR == ROTATION_90 || m_Target->m_TileFFlagsR == ROTATION_270)) || (m_Target->m_TileFIndexR == TILE_STOPA) || (m_Target->m_TileSIndex == TILE_STOP && m_Target->m_TileSFlags == ROTATION_90) || (m_Target->m_TileSIndexR == TILE_STOP && m_Target->m_TileSFlagsR == ROTATION_90) || (m_Target->m_TileSIndexR == TILE_STOPS && (m_Target->m_TileSFlagsR == ROTATION_90 || m_Target->m_TileSFlagsR == ROTATION_270)) || (m_Target->m_TileSIndexR == TILE_STOPA)))
|
2010-09-22 14:25:32 +00:00
|
|
|
Temp.x = 0;
|
2010-11-01 01:51:17 +00:00
|
|
|
if(Temp.y < 0 && ((m_Target->m_TileIndex == TILE_STOP && m_Target->m_TileFlags == ROTATION_180) || (m_Target->m_TileIndexB == TILE_STOP && m_Target->m_TileFlagsB == ROTATION_180) || (m_Target->m_TileIndexB == TILE_STOPS && (m_Target->m_TileFlagsB == ROTATION_0 || m_Target->m_TileFlagsB == ROTATION_180)) || (m_Target->m_TileIndexB == TILE_STOPA) || (m_Target->m_TileFIndex == TILE_STOP && m_Target->m_TileFFlags == ROTATION_180) || (m_Target->m_TileFIndexB == TILE_STOP && m_Target->m_TileFFlagsB == ROTATION_180) || (m_Target->m_TileFIndexB == TILE_STOPS && (m_Target->m_TileFFlagsB == ROTATION_0 || m_Target->m_TileFFlagsB == ROTATION_180)) || (m_Target->m_TileFIndexB == TILE_STOPA) || (m_Target->m_TileSIndex == TILE_STOP && m_Target->m_TileSFlags == ROTATION_180) || (m_Target->m_TileSIndexB == TILE_STOP && m_Target->m_TileSFlagsB == ROTATION_180) || (m_Target->m_TileSIndexB == TILE_STOPS && (m_Target->m_TileSFlagsB == ROTATION_0 || m_Target->m_TileSFlagsB == ROTATION_180)) || (m_Target->m_TileSIndexB == TILE_STOPA)))
|
2010-09-22 14:25:32 +00:00
|
|
|
Temp.y = 0;
|
2010-11-01 01:51:17 +00:00
|
|
|
if(Temp.y > 0 && ((m_Target->m_TileIndex == TILE_STOP && m_Target->m_TileFlags == ROTATION_0) || (m_Target->m_TileIndexT == TILE_STOP && m_Target->m_TileFlagsT == ROTATION_0) || (m_Target->m_TileIndexT == TILE_STOPS && (m_Target->m_TileFlagsT == ROTATION_0 || m_Target->m_TileFlagsT == ROTATION_180)) || (m_Target->m_TileIndexT == TILE_STOPA) || (m_Target->m_TileFIndex == TILE_STOP && m_Target->m_TileFFlags == ROTATION_0) || (m_Target->m_TileFIndexT == TILE_STOP && m_Target->m_TileFFlagsT == ROTATION_0) || (m_Target->m_TileFIndexT == TILE_STOPS && (m_Target->m_TileFFlagsT == ROTATION_0 || m_Target->m_TileFFlagsT == ROTATION_180)) || (m_Target->m_TileFIndexT == TILE_STOPA) || (m_Target->m_TileSIndex == TILE_STOP && m_Target->m_TileSFlags == ROTATION_0) || (m_Target->m_TileSIndexT == TILE_STOP && m_Target->m_TileSFlagsT == ROTATION_0) || (m_Target->m_TileSIndexT == TILE_STOPS && (m_Target->m_TileSFlagsT == ROTATION_0 || m_Target->m_TileSFlagsT == ROTATION_180)) || (m_Target->m_TileSIndexT == TILE_STOPA)))
|
2010-09-22 14:25:32 +00:00
|
|
|
Temp.y = 0;
|
2011-01-29 00:59:50 +00:00
|
|
|
m_Target->Core()->m_Vel = Temp;
|
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
|
|
|
{
|
|
|
|
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-11-01 01:51:17 +00:00
|
|
|
int Flags;
|
2010-08-30 23:45:42 +00:00
|
|
|
m_EvalTick=Server()->Tick();
|
2011-01-21 13:18:50 +00:00
|
|
|
int index = GameServer()->Collision()->IsMover(m_Pos.x,m_Pos.y, &Flags);
|
2010-11-01 01:51:17 +00:00
|
|
|
if (index)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-11-01 01:51:17 +00:00
|
|
|
m_Core=GameServer()->Collision()->CpSpeed(index, Flags);
|
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-22 00:03:14 +00:00
|
|
|
if (m_Target)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-09-22 00:03:14 +00:00
|
|
|
if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient,m_Target->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);
|
2010-11-14 10:01:42 +00:00
|
|
|
int Tick = (Server()->Tick()%Server()->TickSpeed())%11;
|
2011-01-29 00:59:50 +00:00
|
|
|
if (Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()] && (!Tick))) return;
|
|
|
|
if(Char && Char->IsAlive() && m_Target && m_Target->IsAlive() && Char->Team() != m_Target->Team()) return;
|
2010-09-08 16:22:11 +00:00
|
|
|
|
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-07-29 05:21:18 +00:00
|
|
|
}
|
2010-09-22 10:43:59 +00:00
|
|
|
|
2010-11-13 13:22:19 +00:00
|
|
|
CDraggerTeam::CDraggerTeam(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW, int Layer, int Number){
|
2010-09-22 10:43:59 +00:00
|
|
|
for(int i = 0; i < MAX_CLIENTS; ++i) {
|
2010-11-13 13:22:19 +00:00
|
|
|
m_Draggers[i] = new CDragger(pGameWorld, Pos, Strength, NW, i, Layer, Number);
|
2010-09-22 10:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-22 10:49:48 +00:00
|
|
|
//CDraggerTeam::~CDraggerTeam() {
|
2010-09-22 10:49:19 +00:00
|
|
|
//for(int i = 0; i < MAX_CLIENTS; ++i) {
|
|
|
|
// delete m_Draggers[i];
|
|
|
|
//}
|
2010-09-22 10:49:48 +00:00
|
|
|
//}
|