diff --git a/src/game/collision.cpp b/src/game/collision.cpp index f76553b2f..ec67c84ee 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -293,6 +293,32 @@ int CCollision::IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 return 0; } +int CCollision::IntersectNoLaser(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) +{ + float d = distance(Pos0, Pos1); + vec2 Last = Pos0; + + for(float f = 0; f < d; f++) + { + float a = f/d; + vec2 Pos = mix(Pos0, Pos1, a); + if(IsNoLaser(round(Pos.x), round(Pos.y))) + { + if(pOutCollision) + *pOutCollision = Pos; + if(pOutBeforeCollision) + *pOutBeforeCollision = Last; + return GetCollisionAt(Pos.x, Pos.y); + } + Last = Pos; + } + if(pOutCollision) + *pOutCollision = Pos1; + if(pOutBeforeCollision) + *pOutBeforeCollision = Pos1; + return 0; +} + int CCollision::IntersectAir(vec2 Pos0, vec2 Pos1, vec2 *pOutCollision, vec2 *pOutBeforeCollision) { float d = distance(Pos0, Pos1); diff --git a/src/game/server/entities/drager.cpp b/src/game/server/entities/dragger.cpp similarity index 88% rename from src/game/server/entities/drager.cpp rename to src/game/server/entities/dragger.cpp index 4ea14b91f..fc7e7b932 100644 --- a/src/game/server/entities/drager.cpp +++ b/src/game/server/entities/dragger.cpp @@ -3,15 +3,15 @@ #include #include #include -#include "drager.h" +#include "dragger.h" ////////////////////////////////////////////////// -// CDrager +// CDragger ////////////////////////////////////////////////// const int LENGTH=700; -CDrager::CDrager(CGameWorld *pGameWorld, vec2 pos, float strength, bool nw) +CDragger::CDragger(CGameWorld *pGameWorld, vec2 pos, float strength, bool nw) : CEntity(pGameWorld, NETOBJTYPE_LASER) { this->m_Pos = pos; @@ -21,7 +21,7 @@ CDrager::CDrager(CGameWorld *pGameWorld, vec2 pos, float strength, bool nw) GameWorld()->InsertEntity(this); } -void CDrager::move() +void CDragger::move() { if (target) return; @@ -35,6 +35,8 @@ void CDrager::move() target = ents[i]; int res=0; if (!nw) + res = GameServer()->Collision()->IntersectNoLaserNW(m_Pos, target->m_Pos, 0, 0); + else res = GameServer()->Collision()->IntersectNoLaser(m_Pos, target->m_Pos, 0, 0); if (res==0) @@ -57,7 +59,7 @@ void CDrager::move() } } -void CDrager::drag() +void CDragger::drag() { if (target) { @@ -78,12 +80,12 @@ void CDrager::drag() } } -void CDrager::Reset() +void CDragger::Reset() { GameServer()->m_World.DestroyEntity(this); } -void CDrager::Tick() +void CDragger::Tick() { if (Server()->Tick()%int(Server()->TickSpeed()*0.15f)==0) { @@ -102,7 +104,7 @@ void CDrager::Tick() } -void CDrager::Snap(int snapping_client) +void CDragger::Snap(int snapping_client) { if (target) { diff --git a/src/game/server/entities/drager.h b/src/game/server/entities/dragger.h similarity index 65% rename from src/game/server/entities/drager.h rename to src/game/server/entities/dragger.h index 0fdf48869..df1e95dd5 100644 --- a/src/game/server/entities/drager.h +++ b/src/game/server/entities/dragger.h @@ -1,13 +1,13 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#ifndef GAME_SERVER_ENTITY_DRAGER_H -#define GAME_SERVER_ENTITY_DRAGER_H +#ifndef GAME_SERVER_ENTITY_DRAGGER_H +#define GAME_SERVER_ENTITY_DRAGGER_H #include class CCharacter; -class CDrager : public CEntity +class CDragger : public CEntity { vec2 core; float strength; @@ -19,7 +19,7 @@ class CDrager : public CEntity public: - CDrager(CGameWorld *pGameWorld, vec2 pos, float strength, bool nw=false); + CDragger(CGameWorld *pGameWorld, vec2 pos, float strength, bool nw=false); virtual void Reset(); virtual void Tick(); diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 709ffd7fb..53702c6de 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -9,7 +9,7 @@ #include "gamecontext.h" #include "entities/light.h" -#include "entities/drager.h" +#include "entities/dragger.h" #include "entities/gun.h" #include "entities/projectile.h" #include "entities/plasma.h" @@ -293,11 +293,11 @@ bool IGameController::OnEntity(int Index, vec2 Pos, bool Front) } else if(Index>=ENTITY_DRAGGER_WEAK && Index <=ENTITY_DRAGGER_STRONG) { - new CDrager(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1); + new CDragger(&GameServer()->m_World,Pos,Index-ENTITY_DRAGGER_WEAK+1); } else if(Index>=ENTITY_DRAGGER_WEAK_NW && Index <=ENTITY_DRAGGER_STRONG_NW) { - new CDrager(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); + new CDragger(&GameServer()->m_World, Pos,Index-ENTITY_DRAGGER_WEAK_NW+1,true); } else if(Index==ENTITY_PLASMA) {