about summary refs log tree commit diff
path: root/src/game/server/entities
diff options
context:
space:
mode:
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