From 7fe316d31a7340a64ebc4f5e8eb30a685d7e23bd Mon Sep 17 00:00:00 2001 From: "Marius \"Teelevision\" Neugebauer" Date: Wed, 2 Apr 2014 20:51:25 +0200 Subject: added detection for fast aiming bots --- src/game/server/entities/character.cpp | 18 ++++++++++++++++++ src/game/server/entities/character.h | 1 + 2 files changed, 19 insertions(+) (limited to 'src/game/server/entities') diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 547eabce..27be82f8 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -158,6 +158,24 @@ bool CCharacter::AimedAtCharRecently(float aimX, float aimY, const CCharacter *c return false; } +float CCharacter::HowCloseToXRecently(vec2 x, const LastPosition *&pos, int firstTick) +{ + float lowest = 1000.0; + // start with the most recent position + firstTick = max(firstTick, Server()->Tick() - m_LastPositionsSize); + for(int lastTick = Server()->Tick(); lastTick > firstTick; --lastTick) + { + int i = lastTick % m_LastPositionsSize; + float d = distance(x, vec2(m_LastPositions[i].x, m_LastPositions[i].y)); + if(d < lowest) + { + pos = &m_LastPositions[i]; + lowest = d; + } + } + return lowest; +} + void CCharacter::SetWeapon(int W) { if(W == m_ActiveWeapon) diff --git a/src/game/server/entities/character.h b/src/game/server/entities/character.h index 4d615324..7b949e29 100644 --- a/src/game/server/entities/character.h +++ b/src/game/server/entities/character.h @@ -75,6 +75,7 @@ public: }; bool HasBeenThereRecently(float x, float y, const LastPosition *&pos, int firstTick, int lastTick) const; bool AimedAtCharRecently(float aimX, float aimY, const CCharacter *c, const LastPosition *&pos, const LastPosition *&posVictim, int firstTick); + float HowCloseToXRecently(vec2 x, const LastPosition *&pos, int firstTick); private: // player controlling this character -- cgit 1.4.1