summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoseph Botosh <rumly111@gmail.com>2015-07-24 15:55:30 +0300
committerAndrei Karas <akaras@inbox.ru>2015-07-25 21:39:05 +0300
commit60906e87e854f6420804839db7b2afadb69662bb (patch)
treefee04d39cef15dc48ba6e55dcdeac74d4ee8fe59 /src
parentf5d2e707df5171146af3fe1366ecb8fa17b56eea (diff)
downloadplus-60906e87e854f6420804839db7b2afadb69662bb.tar.gz
plus-60906e87e854f6420804839db7b2afadb69662bb.tar.bz2
plus-60906e87e854f6420804839db7b2afadb69662bb.tar.xz
plus-60906e87e854f6420804839db7b2afadb69662bb.zip
healmd checks healing radius
Diffstat (limited to 'src')
-rw-r--r--src/actions/actions.cpp17
-rw-r--r--src/actormanager.cpp9
-rw-r--r--src/actormanager.h3
-rw-r--r--src/utils/mathutils.h62
4 files changed, 88 insertions, 3 deletions
diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp
index aaa71848f..4f78bc375 100644
--- a/src/actions/actions.cpp
+++ b/src/actions/actions.cpp
@@ -98,6 +98,7 @@
#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/timer.h"
+#include "utils/mathutils.h"
#ifdef ANDROID
#ifndef USE_SDL2
@@ -531,7 +532,21 @@ impHandler0(healmd)
{
if (actorManager)
{
- Being *target = actorManager->findMostDamagedPlayer();
+ const int matk = PlayerInfo::getStatEffective(Attributes::MATK);
+ int maxHealingRadius;
+
+ // magic levels < 2
+ if (PlayerInfo::getSkillLevel(340) < 2
+ || PlayerInfo::getSkillLevel(341) < 2)
+ {
+ maxHealingRadius = matk / 100 + 1;
+ }
+ else
+ {
+ maxHealingRadius = (12 * fastSqrtInt(matk) + matk) / 100 + 1;
+ }
+
+ Being *target = actorManager->findMostDamagedPlayer(maxHealingRadius);
if (target)
actorManager->heal(target);
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index fe4892f4a..8bd4ed638 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -40,6 +40,7 @@
#include "input/inputmanager.h"
#include "utils/checkutils.h"
+#include "utils/mathutils.h"
#include "utils/gettext.h"
#include "net/beinghandler.h"
@@ -1288,7 +1289,7 @@ void ActorManager::heal(const Being *const target) const
}
}
-Being* ActorManager::findMostDamagedPlayer() const
+Being* ActorManager::findMostDamagedPlayer(const int maxTileDist) const
{
if (!localPlayer)
return nullptr;
@@ -1311,6 +1312,12 @@ Being* ActorManager::findMostDamagedPlayer() const
continue;
}
+ const int dx = being->getTileX() - localPlayer->getTileX();
+ const int dy = being->getTileY() - localPlayer->getTileY();
+ const int distance = fastSqrtInt(dx * dx + dy * dy);
+
+ if (distance > maxTileDist)
+ continue;
if (being->getDamageTaken() > maxDamageTaken)
{
diff --git a/src/actormanager.h b/src/actormanager.h
index 324a4d2ab..a29e2ae11 100644
--- a/src/actormanager.h
+++ b/src/actormanager.h
@@ -183,8 +183,9 @@ class ActorManager final: public ConfigListener
/**
* Finds most damaged player, non-enemy and alive
+ * \param maxTileDist maximal distance.
*/
- Being *findMostDamagedPlayer() const A_WARN_UNUSED;
+ Being *findMostDamagedPlayer(const int maxTileDist) const A_WARN_UNUSED;
/**
* Heal all players in distance.
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 69267186c..3fa7ad002 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -24,6 +24,7 @@
#define UTILS_MATHUTILS_H
#include <string>
+#include <cmath>
#include "localconsts.h"
@@ -63,6 +64,60 @@ static const uint16_t crc_table[256] =
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
+static const int square_roots[1000] =
+{
+ 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4,
+ 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+ 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+ 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
+ 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
+ 11,11,11,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
+ 12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13,13,
+ 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,14,14,14,14,
+ 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
+ 14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
+ 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
+ 16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
+ 17,17,17,17,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
+ 18,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
+ 20,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,21,
+ 21,21,21,21,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,
+ 22,22,22,22,22,22,22,22,22,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,
+ 23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,
+ 24,24,24,24,24,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,
+ 25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,
+ 26,26,26,26,26,26,26,26,26,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,
+ 27,27,27,27,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,
+ 28,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
+ 30,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,
+ 31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31
+};
+
inline uint16_t getCrc16(const std::string &str) A_WARN_UNUSED;
inline float fastInvSqrt(float x) A_WARN_UNUSED;
inline float fastSqrt(const float x) A_WARN_UNUSED;
@@ -130,4 +185,11 @@ inline int powerOfTwo(const unsigned int input)
return value;
}
+inline int fastSqrtInt(const unsigned int n)
+{
+ if (n < 1000)
+ return square_roots[n];
+ return sqrt(n);
+}
+
#endif // UTILS_MATHUTILS_H