about summary refs log tree commit diff
path: root/src/game/server/entities
diff options
context:
space:
mode:
authorMarius "Teelevision" Neugebauer <marius@teele.eu>2014-04-02 20:51:25 +0200
committerMarius "Teelevision" Neugebauer <marius@teele.eu>2014-04-02 20:51:25 +0200
commit7fe316d31a7340a64ebc4f5e8eb30a685d7e23bd (patch)
treee02bdf2a006924ea2bded8cbdaa8421f238bc720 /src/game/server/entities
parent461e9be9a6dc90e9ef5c1b365205906c1d6c8431 (diff)
downloadzcatch-7fe316d31a7340a64ebc4f5e8eb30a685d7e23bd.tar.gz
zcatch-7fe316d31a7340a64ebc4f5e8eb30a685d7e23bd.zip
added detection for fast aiming bots
Diffstat (limited to 'src/game/server/entities')
-rw-r--r--src/game/server/entities/character.cpp18
-rw-r--r--src/game/server/entities/character.h1
2 files changed, 19 insertions, 0 deletions
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