mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add new method which find all characters on line. Fix bug of doors, need to test
This commit is contained in:
parent
4544b91d2f
commit
e396813e32
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -224,3 +224,32 @@ CCharacter *CGameWorld::ClosestCharacter(vec2 Pos, float Radius, CEntity *pNotTh
|
|||
|
||||
return pClosest;
|
||||
}
|
||||
|
||||
std::list<class CCharacter *> 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;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define GAME_SERVER_GAMEWORLD_H
|
||||
|
||||
#include <game/gamecore.h>
|
||||
#include <list>
|
||||
|
||||
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<class CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, class CEntity *pNotThis = 0);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue