diff options
author | Joseph Botosh <rumly111@gmail.com> | 2015-08-19 01:54:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-08-20 19:04:36 +0300 |
commit | f23abf81cd21907117bf4edf0d814d8bef950e13 (patch) | |
tree | 209a9b308a0aebfd26ee7d2aa963a82f1994a1fb /src/actormanager.cpp | |
parent | 2b0936e4eafee4da5e2ff3c0a7b7fd0df8a9f5c4 (diff) | |
download | ManaVerse-f23abf81cd21907117bf4edf0d814d8bef950e13.tar.gz ManaVerse-f23abf81cd21907117bf4edf0d814d8bef950e13.tar.bz2 ManaVerse-f23abf81cd21907117bf4edf0d814d8bef950e13.tar.xz ManaVerse-f23abf81cd21907117bf4edf0d814d8bef950e13.zip |
/atkhuman now checks teamId and map pvp flag
Diffstat (limited to 'src/actormanager.cpp')
-rw-r--r-- | src/actormanager.cpp | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp index b83a08a0d..43330a7c5 100644 --- a/src/actormanager.cpp +++ b/src/actormanager.cpp @@ -22,6 +22,7 @@ #include "actormanager.h" +#include "game.h" #include "configuration.h" #include "settings.h" @@ -52,6 +53,8 @@ #include "resources/chatobject.h" #include "resources/iteminfo.h" +#include "resources/map/map.h" + #include "resources/db/itemdb.h" #include <algorithm> @@ -905,6 +908,62 @@ void ActorManager::clear() mActors.insert(localPlayer); } +Being *ActorManager::findNearestPvpPlayer() const +{ + if (!localPlayer) + return nullptr; + + // don't attack players + if (settings.pvpAttackType == 3) + return nullptr; + + const Game *const game = Game::instance(); + if (!game) + return nullptr; + + const Map *const map = game->getCurrentMap(); + if (!map) + return nullptr; + + const int mapPvpMode = map->getPvpMode(); + Being *target = nullptr; + int minDistSquared = 20000; + + for_actors + { + if ((*it)->getType() != ActorType::Player) + continue; + + Being *const being = static_cast<Being*>(*it); + + if (!being || !being->isAlive() || + localPlayer == being) + { + continue; + } + + const int teamId = being->getTeamId(); + // this condition is very TMW-specific + if (!(mapPvpMode || teamId)) + continue; + + if (!localPlayer->checAttackPermissions(being)) + continue; + + const int dx = being->getTileX() - localPlayer->getTileX(); + const int dy = being->getTileY() - localPlayer->getTileY(); + const int distSquared = dx * dx + dy * dy; + if (distSquared < minDistSquared) + { + minDistSquared = distSquared; + target = being; + } + } + + return target; +} + + Being *ActorManager::findNearestLivingBeing(const int x, const int y, const int maxTileDist, const ActorTypeT type, @@ -1321,10 +1380,10 @@ Being* ActorManager::findMostDamagedPlayer(const int maxTileDist) const Being *const being = static_cast<Being*>(*it); - if ((!being) || (!being->isAlive()) || // don't heal dead - (player_relations.getRelation(being->getName()) == - Relation::ENEMY2) || // don't heal enemy - (localPlayer == being)) // don't heal self + if (!being || !being->isAlive() || // don't heal dead + player_relations.getRelation(being->getName()) == + Relation::ENEMY2 || // don't heal enemy + localPlayer == being) // don't heal self { continue; } |