From e396813e328188a12348e1d59acd184ea644d643 Mon Sep 17 00:00:00 2001 From: btd Date: Tue, 31 Aug 2010 15:01:46 +0400 Subject: [PATCH] Add new method which find all characters on line. Fix bug of doors, need to test --- src/game/server/entities/door.cpp | 11 ++++++----- src/game/server/gameworld.cpp | 29 +++++++++++++++++++++++++++++ src/game/server/gameworld.h | 17 +++++++++++++++++ 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/game/server/entities/door.cpp b/src/game/server/entities/door.cpp index 5c0b947e3..080fabd73 100644 --- a/src/game/server/entities/door.cpp +++ b/src/game/server/entities/door.cpp @@ -31,11 +31,12 @@ void CDoor::Close() bool CDoor::HitCharacter() { vec2 At; - CCharacter *Hit = GameServer()->m_World.IntersectCharacter(m_Pos, m_To, 1.f, At, 0); - if(!Hit) - return false; - Hit->m_Doored = true; - //hit->reset_pos(); + std::list < CCharacter * > hittedCharacters = GameServer()->m_World.IntersectedCharacters(m_Pos, m_To, 1.f, At, 0); + if(hittedCharacters.empty()) return false; + for(std::list < CCharacter * >::iterator i = hittedCharacters.begin(); i != hittedCharacters.end(); i++) { + CCharacter * Char = *i; + Char->m_Doored = true; + } return true; } diff --git a/src/game/server/gameworld.cpp b/src/game/server/gameworld.cpp index 9e8a25d1f..a3fcaae13 100644 --- a/src/game/server/gameworld.cpp +++ b/src/game/server/gameworld.cpp @@ -224,3 +224,32 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh return pClosest; } + +std::list CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CEntity *pNotThis) +{ + std::list< CCharacter * > listOfChars; + // Find other players + float ClosestLen = distance(Pos0, Pos1) * 100.0f; + vec2 LineDir = normalize(Pos1-Pos0); + + CCharacter *p = (CCharacter *)FindFirst(NETOBJTYPE_CHARACTER); + for(; p; p = (CCharacter *)p->TypeNext()) + { + if(p == pNotThis) + continue; + + vec2 IntersectPos = closest_point_on_line(Pos0, Pos1, p->m_Pos); + float Len = distance(p->m_Pos, IntersectPos); + if(Len < p->m_ProximityRadius+Radius) + { + if(Len < ClosestLen) + { + NewPos = IntersectPos; + ClosestLen = Len; + listOfChars.push_back(p); + } + } + } + + return listOfChars; +} diff --git a/src/game/server/gameworld.h b/src/game/server/gameworld.h index 2d1cc4bec..b3c937638 100644 --- a/src/game/server/gameworld.h +++ b/src/game/server/gameworld.h @@ -2,6 +2,7 @@ #define GAME_SERVER_GAMEWORLD_H #include +#include class CEntity; class CCharacter; @@ -136,6 +137,22 @@ public: */ void Tick(); + + /* + Function: interserct_CCharacter + Finds all CCharacters that intersect the line. + + Arguments: + pos0 - Start position + pos2 - End position + radius - How for from the line the CCharacter is allowed to be. + new_pos - Intersection position + notthis - Entity to ignore intersecting with + + Returns: + Returns list with all Characters on line. + */ + std::list IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CEntity *pNotThis = 0); }; #endif