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 23:06:48 +00:00
|
|
|
#include <game/server/gamemodes/DDRace.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
#include "laser.h"
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-07-29 05:21:18 +00:00
|
|
|
#include <engine/shared/config.h>
|
2011-01-29 00:59:50 +00:00
|
|
|
#include <game/server/teams.h>
|
2008-08-14 18:25:44 +00:00
|
|
|
|
2010-08-30 23:45:42 +00:00
|
|
|
CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type)
|
2011-01-19 17:27:50 +00:00
|
|
|
: CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Pos = Pos;
|
|
|
|
m_Owner = Owner;
|
|
|
|
m_Energy = StartEnergy;
|
|
|
|
m_Dir = Direction;
|
|
|
|
m_Bounces = 0;
|
|
|
|
m_EvalTick = 0;
|
2013-07-18 23:06:48 +00:00
|
|
|
m_TelePos = vec2(0,0);
|
2013-07-20 12:16:41 +00:00
|
|
|
m_WasTele = false;
|
2011-01-07 18:37:21 +00:00
|
|
|
m_Type = Type;
|
2010-05-29 07:25:38 +00:00
|
|
|
GameWorld()->InsertEntity(this);
|
|
|
|
DoBounce();
|
2011-09-02 18:04:18 +00:00
|
|
|
m_TeamMask = GameServer()->GetPlayerChar(Owner) ? GameServer()->GetPlayerChar(Owner)->Teams()->TeamMask(GameServer()->GetPlayerChar(Owner)->Team(), -1, m_Owner) : 0;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
bool CLaser::HitCharacter(vec2 From, vec2 To)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 At;
|
2011-03-19 20:21:42 +00:00
|
|
|
CCharacter *pOwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
|
|
|
CCharacter *pHit;
|
2013-07-20 12:16:41 +00:00
|
|
|
bool pDontHitSelf = g_Config.m_SvOldLaser || (m_Bounces == 0 && !m_WasTele);
|
2011-03-19 20:21:42 +00:00
|
|
|
|
2011-07-25 20:16:20 +00:00
|
|
|
if(pOwnerChar ? (!(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_RIFLE) && m_Type == WEAPON_RIFLE) || (!(pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_SHOTGUN) && m_Type == WEAPON_SHOTGUN) : g_Config.m_SvHit)
|
2013-07-20 12:06:56 +00:00
|
|
|
pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner);
|
2011-03-19 20:21:42 +00:00
|
|
|
else
|
2013-07-20 12:06:56 +00:00
|
|
|
pHit = GameServer()->m_World.IntersectCharacter(m_Pos, To, 0.f, At, pDontHitSelf ? pOwnerChar : 0, m_Owner, pOwnerChar);
|
2011-03-19 20:21:42 +00:00
|
|
|
|
2011-07-25 20:16:20 +00:00
|
|
|
if(!pHit || (pHit == pOwnerChar && g_Config.m_SvOldLaser) || (pHit != pOwnerChar && pOwnerChar ? (pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_RIFLE && m_Type == WEAPON_RIFLE) || (pOwnerChar->m_Hit&CCharacter::DISABLE_HIT_SHOTGUN && m_Type == WEAPON_SHOTGUN) : !g_Config.m_SvHit))
|
2008-08-14 18:25:44 +00:00
|
|
|
return false;
|
2010-05-29 07:25:38 +00:00
|
|
|
m_From = From;
|
|
|
|
m_Pos = At;
|
2010-07-29 05:21:18 +00:00
|
|
|
m_Energy = -1;
|
2011-07-25 20:16:20 +00:00
|
|
|
if (m_Type == WEAPON_SHOTGUN)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2010-12-01 22:06:28 +00:00
|
|
|
vec2 Temp;
|
|
|
|
if(!g_Config.m_SvOldLaser)
|
2011-03-19 20:21:42 +00:00
|
|
|
Temp = pHit->Core()->m_Vel + normalize(m_PrevPos - pHit->Core()->m_Pos) * 10;
|
2010-12-01 22:06:28 +00:00
|
|
|
else
|
2011-03-19 20:21:42 +00:00
|
|
|
Temp = pHit->Core()->m_Vel + normalize(pOwnerChar->Core()->m_Pos - pHit->Core()->m_Pos) * 10;
|
|
|
|
if(Temp.x > 0 && ((pHit->m_TileIndex == TILE_STOP && pHit->m_TileFlags == ROTATION_270) || (pHit->m_TileIndexL == TILE_STOP && pHit->m_TileFlagsL == ROTATION_270) || (pHit->m_TileIndexL == TILE_STOPS && (pHit->m_TileFlagsL == ROTATION_90 || pHit->m_TileFlagsL ==ROTATION_270)) || (pHit->m_TileIndexL == TILE_STOPA) || (pHit->m_TileFIndex == TILE_STOP && pHit->m_TileFFlags == ROTATION_270) || (pHit->m_TileFIndexL == TILE_STOP && pHit->m_TileFFlagsL == ROTATION_270) || (pHit->m_TileFIndexL == TILE_STOPS && (pHit->m_TileFFlagsL == ROTATION_90 || pHit->m_TileFFlagsL == ROTATION_270)) || (pHit->m_TileFIndexL == TILE_STOPA) || (pHit->m_TileSIndex == TILE_STOP && pHit->m_TileSFlags == ROTATION_270) || (pHit->m_TileSIndexL == TILE_STOP && pHit->m_TileSFlagsL == ROTATION_270) || (pHit->m_TileSIndexL == TILE_STOPS && (pHit->m_TileSFlagsL == ROTATION_90 || pHit->m_TileSFlagsL == ROTATION_270)) || (pHit->m_TileSIndexL == TILE_STOPA)))
|
2010-11-01 12:08:48 +00:00
|
|
|
Temp.x = 0;
|
2011-03-19 20:21:42 +00:00
|
|
|
if(Temp.x < 0 && ((pHit->m_TileIndex == TILE_STOP && pHit->m_TileFlags == ROTATION_90) || (pHit->m_TileIndexR == TILE_STOP && pHit->m_TileFlagsR == ROTATION_90) || (pHit->m_TileIndexR == TILE_STOPS && (pHit->m_TileFlagsR == ROTATION_90 || pHit->m_TileFlagsR == ROTATION_270)) || (pHit->m_TileIndexR == TILE_STOPA) || (pHit->m_TileFIndex == TILE_STOP && pHit->m_TileFFlags == ROTATION_90) || (pHit->m_TileFIndexR == TILE_STOP && pHit->m_TileFFlagsR == ROTATION_90) || (pHit->m_TileFIndexR == TILE_STOPS && (pHit->m_TileFFlagsR == ROTATION_90 || pHit->m_TileFFlagsR == ROTATION_270)) || (pHit->m_TileFIndexR == TILE_STOPA) || (pHit->m_TileSIndex == TILE_STOP && pHit->m_TileSFlags == ROTATION_90) || (pHit->m_TileSIndexR == TILE_STOP && pHit->m_TileSFlagsR == ROTATION_90) || (pHit->m_TileSIndexR == TILE_STOPS && (pHit->m_TileSFlagsR == ROTATION_90 || pHit->m_TileSFlagsR == ROTATION_270)) || (pHit->m_TileSIndexR == TILE_STOPA)))
|
2010-11-01 12:08:48 +00:00
|
|
|
Temp.x = 0;
|
2011-03-19 20:21:42 +00:00
|
|
|
if(Temp.y < 0 && ((pHit->m_TileIndex == TILE_STOP && pHit->m_TileFlags == ROTATION_180) || (pHit->m_TileIndexB == TILE_STOP && pHit->m_TileFlagsB == ROTATION_180) || (pHit->m_TileIndexB == TILE_STOPS && (pHit->m_TileFlagsB == ROTATION_0 || pHit->m_TileFlagsB == ROTATION_180)) || (pHit->m_TileIndexB == TILE_STOPA) || (pHit->m_TileFIndex == TILE_STOP && pHit->m_TileFFlags == ROTATION_180) || (pHit->m_TileFIndexB == TILE_STOP && pHit->m_TileFFlagsB == ROTATION_180) || (pHit->m_TileFIndexB == TILE_STOPS && (pHit->m_TileFFlagsB == ROTATION_0 || pHit->m_TileFFlagsB == ROTATION_180)) || (pHit->m_TileFIndexB == TILE_STOPA) || (pHit->m_TileSIndex == TILE_STOP && pHit->m_TileSFlags == ROTATION_180) || (pHit->m_TileSIndexB == TILE_STOP && pHit->m_TileSFlagsB == ROTATION_180) || (pHit->m_TileSIndexB == TILE_STOPS && (pHit->m_TileSFlagsB == ROTATION_0 || pHit->m_TileSFlagsB == ROTATION_180)) || (pHit->m_TileSIndexB == TILE_STOPA)))
|
2010-11-01 12:08:48 +00:00
|
|
|
Temp.y = 0;
|
2011-03-19 20:21:42 +00:00
|
|
|
if(Temp.y > 0 && ((pHit->m_TileIndex == TILE_STOP && pHit->m_TileFlags == ROTATION_0) || (pHit->m_TileIndexT == TILE_STOP && pHit->m_TileFlagsT == ROTATION_0) || (pHit->m_TileIndexT == TILE_STOPS && (pHit->m_TileFlagsT == ROTATION_0 || pHit->m_TileFlagsT == ROTATION_180)) || (pHit->m_TileIndexT == TILE_STOPA) || (pHit->m_TileFIndex == TILE_STOP && pHit->m_TileFFlags == ROTATION_0) || (pHit->m_TileFIndexT == TILE_STOP && pHit->m_TileFFlagsT == ROTATION_0) || (pHit->m_TileFIndexT == TILE_STOPS && (pHit->m_TileFFlagsT == ROTATION_0 || pHit->m_TileFFlagsT == ROTATION_180)) || (pHit->m_TileFIndexT == TILE_STOPA) || (pHit->m_TileSIndex == TILE_STOP && pHit->m_TileSFlags == ROTATION_0) || (pHit->m_TileSIndexT == TILE_STOP && pHit->m_TileSFlagsT == ROTATION_0) || (pHit->m_TileSIndexT == TILE_STOPS && (pHit->m_TileSFlagsT == ROTATION_0 || pHit->m_TileSFlagsT == ROTATION_180)) || (pHit->m_TileSIndexT == TILE_STOPA)))
|
2010-11-01 12:08:48 +00:00
|
|
|
Temp.y = 0;
|
2011-03-19 20:21:42 +00:00
|
|
|
pHit->Core()->m_Vel = Temp;
|
2010-08-27 23:30:50 +00:00
|
|
|
}
|
2011-07-25 20:16:20 +00:00
|
|
|
else if (m_Type == WEAPON_RIFLE)
|
2010-07-29 05:21:18 +00:00
|
|
|
{
|
2011-07-22 14:23:03 +00:00
|
|
|
pHit->UnFreeze();
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2008-08-14 18:25:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLaser::DoBounce()
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_EvalTick = Server()->Tick();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Energy < 0)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
2008-08-14 18:25:44 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-07-29 05:21:18 +00:00
|
|
|
m_PrevPos = m_Pos;
|
|
|
|
vec2 Coltile;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-04 10:16:30 +00:00
|
|
|
int Res;
|
2013-07-18 23:06:48 +00:00
|
|
|
int z;
|
|
|
|
|
2013-07-20 12:16:41 +00:00
|
|
|
if (m_WasTele)
|
2013-07-18 23:06:48 +00:00
|
|
|
{
|
2013-07-19 00:04:40 +00:00
|
|
|
m_PrevPos = m_TelePos;
|
2013-07-18 23:06:48 +00:00
|
|
|
m_Pos = m_TelePos;
|
|
|
|
m_TelePos = vec2(0,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec2 To = m_Pos + m_Dir * m_Energy;
|
|
|
|
|
2013-07-18 23:23:48 +00:00
|
|
|
if (g_Config.m_SvTeleportWeapons)
|
|
|
|
Res = GameServer()->Collision()->IntersectLineTele(m_Pos, To, &Coltile, &To, &z, false);
|
|
|
|
else
|
|
|
|
Res = GameServer()->Collision()->IntersectLine(m_Pos, To, &Coltile, &To, false);
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-03-04 10:16:30 +00:00
|
|
|
if(Res)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!HitCharacter(m_Pos, To))
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
|
|
|
// intersected
|
2010-05-29 07:25:38 +00:00
|
|
|
m_From = m_Pos;
|
|
|
|
m_Pos = To;
|
2009-01-11 10:26:17 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
vec2 TempPos = m_Pos;
|
|
|
|
vec2 TempDir = m_Dir * 4.0f;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-09-01 00:14:05 +00:00
|
|
|
int f = 0;
|
2011-03-04 10:16:30 +00:00
|
|
|
if(Res == -1)
|
|
|
|
{
|
2011-04-09 06:41:31 +00:00
|
|
|
f = GameServer()->Collision()->GetTile(round(Coltile.x), round(Coltile.y));
|
|
|
|
GameServer()->Collision()->SetCollisionAt(round(Coltile.x), round(Coltile.y), CCollision::COLFLAG_SOLID);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->Collision()->MovePoint(&TempPos, &TempDir, 1.0f, 0);
|
2011-03-04 10:16:30 +00:00
|
|
|
if(Res == -1)
|
|
|
|
{
|
2011-04-09 06:41:31 +00:00
|
|
|
GameServer()->Collision()->SetCollisionAt(round(Coltile.x), round(Coltile.y), f);
|
2010-07-29 05:21:18 +00:00
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Pos = TempPos;
|
|
|
|
m_Dir = normalize(TempDir);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
m_Energy -= distance(m_From, m_Pos) + GameServer()->Tuning()->m_LaserBounceCost;
|
2013-07-18 23:06:48 +00:00
|
|
|
|
2013-07-18 23:23:48 +00:00
|
|
|
if (g_Config.m_SvTeleportWeapons && Res&CCollision::COLFLAG_TELE)
|
2013-07-18 23:06:48 +00:00
|
|
|
{
|
|
|
|
int Num = ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleOuts[z-1].size();
|
|
|
|
m_TelePos = ((CGameControllerDDRace*)GameServer()->m_pController)->m_TeleOuts[z-1][(!Num)?Num:rand() % Num];
|
2013-07-20 12:16:41 +00:00
|
|
|
m_WasTele = true;
|
2013-07-18 23:06:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_Bounces++;
|
2013-07-20 12:16:41 +00:00
|
|
|
m_WasTele = false;
|
2013-07-18 23:06:48 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
if(m_Bounces > GameServer()->Tuning()->m_LaserBounceNum)
|
|
|
|
m_Energy = -1;
|
2011-07-22 12:58:06 +00:00
|
|
|
|
2011-07-22 14:15:39 +00:00
|
|
|
GameServer()->CreateSound(m_Pos, SOUND_RIFLE_BOUNCE, m_TeamMask);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(!HitCharacter(m_Pos, To))
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
m_From = m_Pos;
|
|
|
|
m_Pos = To;
|
|
|
|
m_Energy = -1;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-08 16:22:11 +00:00
|
|
|
//m_Owner = -1;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLaser::Reset()
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
GameServer()->m_World.DestroyEntity(this);
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLaser::Tick()
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Server()->Tick() > m_EvalTick+(Server()->TickSpeed()*GameServer()->Tuning()->m_LaserBounceDelay)/1000.0f)
|
|
|
|
DoBounce();
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 23:49:31 +00:00
|
|
|
void CLaser::TickPaused()
|
|
|
|
{
|
|
|
|
++m_EvalTick;
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CLaser::Snap(int SnappingClient)
|
2008-08-14 18:25:44 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(NetworkClipped(SnappingClient))
|
2008-08-14 18:25:44 +00:00
|
|
|
return;
|
2010-12-04 16:35:41 +00:00
|
|
|
CCharacter * SnappingChar = GameServer()->GetPlayerChar(SnappingClient);
|
|
|
|
CCharacter * OwnerChar = 0;
|
2010-12-04 21:51:03 +00:00
|
|
|
if(m_Owner >= 0)
|
2010-12-04 16:35:41 +00:00
|
|
|
OwnerChar = GameServer()->GetPlayerChar(m_Owner);
|
2011-04-19 13:15:21 +00:00
|
|
|
if(!OwnerChar)
|
2010-12-04 16:51:14 +00:00
|
|
|
return;
|
2011-04-19 13:15:21 +00:00
|
|
|
if(SnappingChar && !SnappingChar->CanCollide(m_Owner))
|
2010-12-04 16:35:41 +00:00
|
|
|
return;
|
2011-02-12 10:40:36 +00:00
|
|
|
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser)));
|
2010-12-16 02:29:08 +00:00
|
|
|
if(!pObj)
|
|
|
|
return;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
pObj->m_X = (int)m_Pos.x;
|
|
|
|
pObj->m_Y = (int)m_Pos.y;
|
|
|
|
pObj->m_FromX = (int)m_From.x;
|
|
|
|
pObj->m_FromY = (int)m_From.y;
|
|
|
|
pObj->m_StartTick = m_EvalTick;
|
2008-08-14 18:25:44 +00:00
|
|
|
}
|