From 6fb11efa40f923eec08ea733b40429021595ab05 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 19 Jul 2013 01:06:48 +0200 Subject: [PATCH] Make lasers go through teleporters --- src/game/server/entities/laser.cpp | 26 +++++++++++++++++++++++--- src/game/server/entities/laser.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 12efc6de2..57b3358e5 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -2,6 +2,7 @@ /* If you are missing that file, acquire a complete release at teeworlds.com. */ #include #include +#include #include "laser.h" #include @@ -16,6 +17,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner m_Dir = Direction; m_Bounces = 0; m_EvalTick = 0; + m_TelePos = vec2(0,0); m_Type = Type; GameWorld()->InsertEntity(this); DoBounce(); @@ -73,11 +75,20 @@ void CLaser::DoBounce() return; } m_PrevPos = m_Pos; - vec2 To = m_Pos + m_Dir * m_Energy; vec2 Coltile; int Res; - Res = GameServer()->Collision()->IntersectLine(m_Pos, To, &Coltile, &To,false); + int z; + + if (m_TelePos[0] != 0 || m_TelePos[1] != 0) + { + m_Pos = m_TelePos; + m_TelePos = vec2(0,0); + } + + vec2 To = m_Pos + m_Dir * m_Energy; + + Res = GameServer()->Collision()->IntersectLineTele(m_Pos, To, &Coltile, &To, &z, false); if(Res) { @@ -105,7 +116,16 @@ void CLaser::DoBounce() m_Dir = normalize(TempDir); m_Energy -= distance(m_From, m_Pos) + GameServer()->Tuning()->m_LaserBounceCost; - m_Bounces++; + + if (Res&CCollision::COLFLAG_TELE) + { + 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]; + } + else + { + m_Bounces++; + } if(m_Bounces > GameServer()->Tuning()->m_LaserBounceNum) m_Energy = -1; diff --git a/src/game/server/entities/laser.h b/src/game/server/entities/laser.h index db178d34d..5a18c15b3 100644 --- a/src/game/server/entities/laser.h +++ b/src/game/server/entities/laser.h @@ -22,6 +22,7 @@ protected: private: vec2 m_From; vec2 m_Dir; + vec2 m_TelePos; float m_Energy; int m_Bounces; int m_EvalTick;