From e706c092f3b28ff4e5bd229ce3a00e604828ce89 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 19 Aug 2009 18:49:33 +0200 Subject: Performance improvement of range calculation (suggested by Octalot) --- src/game-server/being.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp index e5983ee7..3993154e 100644 --- a/src/game-server/being.cpp +++ b/src/game-server/being.cpp @@ -19,7 +19,6 @@ */ #include -#include #include "game-server/being.hpp" @@ -242,11 +241,12 @@ void Being::performAttack(Being *target, unsigned range, const Damage &damage) getType() == OBJECT_CHARACTER) return; - // check if target is in range + // check if target is in range using the pythagorean theorem int distx = this->getPosition().x - target->getPosition().x; int disty = this->getPosition().y - target->getPosition().y; - int dist = std::sqrt(distx * distx + disty * disty); // pythagoras - if (range + target->getSize() < dist ) + int distSquare = (distx * distx + disty * disty); + int maxDist = range + target->getSize(); + if (maxDist * maxDist < distSquare) return; mTarget->damage(this, damage); -- cgit v1.2.3-70-g09d2