From 6c3974a46c659e558b2b5f249b7b000a5b39fe25 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 19 Oct 2013 16:27:33 +0300 Subject: Rename actorspritemanager into actormanager. --- manaplus.cbp | 2 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/actionmanager.cpp | 24 +- src/actormanager.cpp | 1670 +++++++++++++++++++++++++++++ src/actormanager.h | 357 +++++++ src/actorspritemanager.cpp | 1676 ------------------------------ src/actorspritemanager.h | 357 ------- src/being/being.cpp | 14 +- src/being/localplayer.cpp | 38 +- src/being/playerrelations.cpp | 10 +- src/commands.cpp | 68 +- src/game.cpp | 26 +- src/gui/popups/popupmenu.cpp | 166 +-- src/gui/viewport.cpp | 30 +- src/gui/viewport.h | 2 +- src/gui/widgets/avatarlistbox.cpp | 10 +- src/gui/widgets/tabs/setup_relations.cpp | 6 +- src/gui/windows/botcheckerwindow.cpp | 10 +- src/gui/windows/chatwindow.cpp | 18 +- src/gui/windows/killstats.cpp | 6 +- src/gui/windows/minimap.cpp | 6 +- src/gui/windows/npcdialog.cpp | 6 +- src/gui/windows/questswindow.cpp | 6 +- src/gui/windows/shopwindow.cpp | 10 +- src/gui/windows/socialwindow.cpp | 24 +- src/gui/windows/whoisonline.cpp | 18 +- src/guild.cpp | 6 +- src/guildmanager.cpp | 18 +- src/net/ea/beinghandler.cpp | 84 +- src/net/ea/chathandler.cpp | 14 +- src/net/ea/guildhandler.cpp | 28 +- src/net/ea/itemhandler.cpp | 16 +- src/net/ea/partyhandler.cpp | 14 +- src/net/eathena/beinghandler.cpp | 30 +- src/net/eathena/guildhandler.cpp | 6 +- src/net/eathena/partyhandler.cpp | 6 +- src/net/tmwa/beinghandler.cpp | 20 +- src/net/tmwa/guildhandler.cpp | 6 +- src/net/tmwa/partyhandler.cpp | 6 +- src/party.cpp | 6 +- 41 files changed, 2411 insertions(+), 2417 deletions(-) create mode 100644 src/actormanager.cpp create mode 100644 src/actormanager.h delete mode 100644 src/actorspritemanager.cpp delete mode 100644 src/actorspritemanager.h diff --git a/manaplus.cbp b/manaplus.cbp index fa8bf393e..98fd52500 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -88,7 +88,7 @@ - + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a45793802..254704a88 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -569,8 +569,8 @@ SET(SRCS being/actorsprite.cpp being/actorsprite.h being/actorspritelistener.h - actorspritemanager.cpp - actorspritemanager.h + actormanager.cpp + actormanager.h animatedsprite.cpp animatedsprite.h animationdelayload.cpp diff --git a/src/Makefile.am b/src/Makefile.am index f032777d7..9f07e72f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -582,8 +582,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ being/actorsprite.cpp \ being/actorsprite.h \ being/actorspritelistener.h \ - actorspritemanager.cpp \ - actorspritemanager.h \ + actormanager.cpp \ + actormanager.h \ animatedsprite.cpp \ animatedsprite.h \ animationdelayload.cpp \ diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index d415f93ab..e34482c13 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -20,7 +20,7 @@ #include "actionmanager.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "dropshortcut.h" #include "emoteshortcut.h" #include "game.h" @@ -371,21 +371,21 @@ impHandler0(switchQuickDrop) impHandler0(heal) { - if (actorSpriteManager) + if (actorManager) { if (inputManager.isActionActive(Input::KEY_MOD)) { Being *target = player_node->getTarget(); if (!target || target->getType() != ActorSprite::PLAYER) { - target = actorSpriteManager->findNearestLivingBeing( + target = actorManager->findNearestLivingBeing( player_node, 10, ActorSprite::PLAYER); if (target) player_node->setTarget(target); } } - actorSpriteManager->healTarget(); + actorManager->healTarget(); if (Game::instance()) Game::instance()->setValidSpeed(); return true; @@ -405,12 +405,12 @@ impHandler0(crazyMoves) impHandler0(itenplz) { - if (actorSpriteManager) + if (actorManager) { if (Net::getPlayerHandler() && Net::getPlayerHandler()->canUseMagic() && PlayerInfo::getAttribute(PlayerInfo::MP) >= 3) { - actorSpriteManager->itenplz(); + actorManager->itenplz(); } return true; } @@ -962,9 +962,9 @@ impHandler0(talk) if (player_node) { Being *target = player_node->getTarget(); - if (!target && actorSpriteManager) + if (!target && actorManager) { - target = actorSpriteManager->findNearestLivingBeing( + target = actorManager->findNearestLivingBeing( player_node, 1, ActorSprite::NPC); // ignore closest target if distance in each direction more than 1 if (target) @@ -1025,7 +1025,7 @@ impHandler0(attack) impHandler0(targetAttack) { - if (player_node && actorSpriteManager) + if (player_node && actorManager) { Being *target = nullptr; @@ -1035,7 +1035,7 @@ impHandler0(targetAttack) if (!player_node->getTarget()) { // Only auto target Monsters - target = actorSpriteManager->findNearestLivingBeing( + target = actorManager->findNearestLivingBeing( player_node, 90, ActorSprite::MONSTER); } else @@ -1051,9 +1051,9 @@ impHandler0(targetAttack) static bool setTarget(const ActorSprite::Type type) { - if (actorSpriteManager && player_node) + if (actorManager && player_node) { - Being *const target = actorSpriteManager->findNearestLivingBeing( + Being *const target = actorManager->findNearestLivingBeing( player_node, 20, type); if (target && target != player_node->getTarget()) diff --git a/src/actormanager.cpp b/src/actormanager.cpp new file mode 100644 index 000000000..f37cc9a18 --- /dev/null +++ b/src/actormanager.cpp @@ -0,0 +1,1670 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "actormanager.h" + +#include "client.h" +#include "configuration.h" +#include "main.h" + +#include "being/localplayer.h" +#include "being/playerinfo.h" +#include "being/playerrelations.h" + +#include "gui/viewport.h" + +#include "gui/widgets/tabs/chattab.h" + +#include "gui/windows/equipmentwindow.h" +#include "gui/windows/socialwindow.h" + +#include "utils/checkutils.h" +#include "utils/gettext.h" + +#include "net/net.h" +#include "net/playerhandler.h" + +#include +#include + +#include "debug.h" + +#define for_actors for (ActorSpritesConstIterator it = mActors.begin(), \ + it_end = mActors.end() ; it != it_end; ++it) + +#define for_actorsm for (ActorSpritesIterator it = mActors.begin(), \ + it_end = mActors.end() ; it != it_end; ++it) + +class FindBeingFunctor final +{ + public: + bool operator() (const ActorSprite *const actor) const + { + if (!actor || actor->getType() == ActorSprite::FLOOR_ITEM + || actor->getType() == ActorSprite::PORTAL) + { + return false; + } + const Being *const b = static_cast(actor); + + const unsigned other_y = y + ((b->getType() + == ActorSprite::NPC) ? 1 : 0); + const Vector &pos = b->getPosition(); + return (static_cast(pos.x) / mapTileSize == x && + (static_cast(pos.y) / mapTileSize == y + || static_cast(pos.y) / mapTileSize == other_y) && + b->isAlive() && (type == ActorSprite::UNKNOWN + || b->getType() == type)); + } + + uint16_t x, y; + ActorSprite::Type type; +} beingActorFinder; + +class FindBeingEqualFunctor final +{ + public: + bool operator() (const Being *const being) const + { + if (!being || !findBeing) + return false; + return being->getId() == findBeing->getId(); + } + + Being *findBeing; +} beingEqualActorFinder; + +class SortBeingFunctor final +{ + public: + bool operator() (const Being *const being1, + const Being *const being2) const + { + if (!being1 || !being2) + return false; + + if (priorityBeings) + { + int w1 = defaultPriorityIndex; + int w2 = defaultPriorityIndex; + const std::map::const_iterator it1 + = priorityBeings->find(being1->getName()); + const std::map::const_iterator it2 + = priorityBeings->find(being2->getName()); + if (it1 != priorityBeings->end()) + w1 = (*it1).second; + if (it2 != priorityBeings->end()) + w2 = (*it2).second; + + if (w1 != w2) + return w1 < w2; + } + if (being1->getDistance() != being2->getDistance()) + { + if (specialDistance && being1->getDistance() <= 2 + && being2->getDistance() <= attackRange + && being2->getDistance() > 2) + { + return false; + } + else if (specialDistance && being2->getDistance() <= 2 + && being1->getDistance() <= attackRange + && being1->getDistance() > 2) + { + return true; + } + return being1->getDistance() < being2->getDistance(); + } + + int d1, d2; +#ifdef MANASERV_SUPPORT + if (Net::getNetworkType() == ServerInfo::MANASERV) + { + const Vector &pos1 = being1->getPosition(); + d1 = abs((static_cast(pos1.x)) - x) + + abs((static_cast(pos1.y)) - y); + const Vector &pos2 = being2->getPosition(); + d2 = abs((static_cast(pos2.x)) - x) + + abs((static_cast(pos2.y)) - y); + } + else +#endif + { + d1 = abs(being1->getTileX() - x) + abs(being1->getTileY() - y); + d2 = abs(being2->getTileX() - x) + abs(being2->getTileY() - y); + } + + if (d1 != d2) + return d1 < d2; + if (attackBeings) + { + int w1 = defaultAttackIndex; + int w2 = defaultAttackIndex; + const std::map::const_iterator it1 + = attackBeings->find(being1->getName()); + const std::map::const_iterator it2 + = attackBeings->find(being2->getName()); + if (it1 != attackBeings->end()) + w1 = (*it1).second; + if (it2 != attackBeings->end()) + w2 = (*it2).second; + + if (w1 != w2) + return w1 < w2; + } + + return (being1->getName() < being2->getName()); + } + std::map *attackBeings; + std::map *priorityBeings; + int x; + int y; + int defaultAttackIndex; + int defaultPriorityIndex; + int attackRange; + bool specialDistance; +} beingActorSorter; + +ActorManager::ActorManager() : + mActors(), + mDeleteActors(), + mBlockedBeings(), + mMap(nullptr), + mSpellHeal1(serverConfig.getValue("spellHeal1", "#lum")), + mSpellHeal2(serverConfig.getValue("spellHeal2", "#inma")), + mSpellItenplz(serverConfig.getValue("spellItenplz", "#itenplz")), + mTargetDeadPlayers(config.getBoolValue("targetDeadPlayers")), + mTargetOnlyReachable(config.getBoolValue("targetOnlyReachable")), + mCyclePlayers(config.getBoolValue("cyclePlayers")), + mCycleMonsters(config.getBoolValue("cycleMonsters")), + mCycleNPC(config.getBoolValue("cycleNPC")), + mExtMouseTargeting(config.getBoolValue("extMouseTargeting")) +{ + config.addListener("targetDeadPlayers", this); + config.addListener("targetOnlyReachable", this); + config.addListener("cyclePlayers", this); + config.addListener("cycleMonsters", this); + config.addListener("cycleNPC", this); + config.addListener("extMouseTargeting", this); + + loadAttackList(); +} + +ActorManager::~ActorManager() +{ + config.removeListeners(this); + storeAttackList(); + clear(); +} + +void ActorManager::setMap(Map *const map) +{ + mMap = map; + + if (player_node) + player_node->setMap(map); +} + +void ActorManager::setPlayer(LocalPlayer *const player) +{ + player_node = player; + mActors.insert(player); + if (socialWindow) + socialWindow->updateAttackFilter(); + if (socialWindow) + socialWindow->updatePickupFilter(); +} + +Being *ActorManager::createBeing(const int id, + const ActorSprite::Type type, + const uint16_t subtype) +{ + Being *const being = new Being(id, type, subtype, mMap); + + mActors.insert(being); + return being; +} + +FloorItem *ActorManager::createItem(const int id, const int itemId, + const int x, const int y, + const int amount, + const unsigned char color, + const int subX, const int subY) +{ + FloorItem *const floorItem = new FloorItem(id, itemId, + x, y, amount, color); + floorItem->postInit(mMap, subX, subY); + + if (!checkForPickup(floorItem)) + floorItem->disableHightlight(); + mActors.insert(floorItem); + return floorItem; +} + +void ActorManager::destroy(ActorSprite *const actor) +{ + if (!actor || actor == player_node) + return; + + mDeleteActors.insert(actor); +} + +void ActorManager::erase(ActorSprite *const actor) +{ + if (!actor || actor == player_node) + return; + + mActors.erase(actor); +} + +void ActorManager::undelete(const ActorSprite *const actor) +{ + if (!actor || actor == player_node) + return; + + FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) + { + if (*it == actor) + { + mDeleteActors.erase(*it); + return; + } + } +} + +Being *ActorManager::findBeing(const int id) const +{ + for_actors + { + ActorSprite *const actor = *it; + if (actor->getId() == id && + actor->getType() != ActorSprite::FLOOR_ITEM) + { + return static_cast(actor); + } + } + + return nullptr; +} + +Being *ActorManager::findBeing(const int x, const int y, + const ActorSprite::Type type) const +{ + beingActorFinder.x = static_cast(x); + beingActorFinder.y = static_cast(y); + beingActorFinder.type = type; + + const ActorSpritesConstIterator it = std::find_if( + mActors.begin(), mActors.end(), beingActorFinder); + + return (it == mActors.end()) ? nullptr : static_cast(*it); +} + +Being *ActorManager::findBeingByPixel(const int x, const int y, + const bool allPlayers) const +{ + if (!mMap) + return nullptr; + + const bool targetDead = mTargetDeadPlayers; + + if (mExtMouseTargeting) + { + Being *tempBeing = nullptr; + bool noBeing(false); + + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::PORTAL) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + { + if (!noBeing) + { + const FloorItem *const floor + = static_cast(*it); + if ((floor->getPixelX() - mapTileSize <= x) && + (floor->getPixelX() + mapTileSize > x) && + (floor->getPixelY() - mapTileSize * 2 <= y) && + (floor->getPixelY() + mapTileSize / 2 > y)) + { + noBeing = true; + } + } + continue; + } + + Being *const being = static_cast(*it); + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + + if ((being->isAlive() + || (targetDead && being->getType() == Being::PLAYER)) + && (allPlayers || being != player_node)) + { + if ((being->getPixelX() - mapTileSize / 2 <= x) && + (being->getPixelX() + mapTileSize / 2 > x) && + (being->getPixelY() - mapTileSize <= y) && + (being->getPixelY() > y)) + { + return being; + } + else if (!noBeing && (being->getPixelX() - mapTileSize <= x) && + (being->getPixelX() + mapTileSize > x) && + (being->getPixelY() - mapTileSize * 2 <= y) && + (being->getPixelY() + mapTileSize / 2 > y)) + { + if (tempBeing) + noBeing = true; + else + tempBeing = being; + } + } + } + + if (noBeing) + return nullptr; + return tempBeing; + } + else + { + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::PORTAL || + (*it)->getType() == ActorSprite::FLOOR_ITEM) + { + continue; + } + + Being *const being = static_cast(*it); + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + + if ((being->getPixelX() - mapTileSize / 2 <= x) && + (being->getPixelX() + mapTileSize / 2 > x) && + (being->getPixelY() - mapTileSize <= y) && + (being->getPixelY() > y)) + { + return being; + } + } + return nullptr; + } +} + +void ActorManager::findBeingsByPixel(std::vector &beings, + const int x, const int y, + const bool allPlayers) const +{ + if (!mMap) + return; + + const int xtol = mapTileSize / 2; + const int uptol = mapTileSize; + + for_actors + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::PORTAL) + continue; + + const Being *const being = dynamic_cast(*it); + + if (being && being->getInfo() + && !being->getInfo()->isTargetSelection()) + { + continue; + } + + ActorSprite *const actor = *it; + + if ((being && (being->isAlive() + || (mTargetDeadPlayers && being->getType() == Being::PLAYER)) + && (allPlayers || being != player_node)) + || actor->getType() == ActorSprite::FLOOR_ITEM) + { + if ((actor->getPixelX() - xtol <= x) && + (actor->getPixelX() + xtol > x) && + (actor->getPixelY() - uptol <= y) && + (actor->getPixelY() > y)) + { + beings.push_back(actor); + } + } + } +} + +Being *ActorManager::findPortalByTile(const int x, const int y) const +{ + if (!mMap) + return nullptr; + + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() != ActorSprite::PORTAL) + continue; + + Being *const being = static_cast(*it); + + if (being->getTileX() == x && being->getTileY() == y) + return being; + } + + return nullptr; +} + +FloorItem *ActorManager::findItem(const int id) const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getId() == id && + (*it)->getType() == ActorSprite::FLOOR_ITEM) + { + return static_cast(*it); + } + } + + return nullptr; +} + +FloorItem *ActorManager::findItem(const int x, const int y) const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getTileX() == x && (*it)->getTileY() == y && + (*it)->getType() == ActorSprite::FLOOR_ITEM) + { + return static_cast(*it); + } + } + + return nullptr; +} + +bool ActorManager::pickUpAll(const int x1, const int y1, + const int x2, const int y2, + const bool serverBuggy) +{ + if (!player_node) + return false; + + bool finded(false); + const bool allowAll = mPickupItemsSet.find("") != mPickupItemsSet.end(); + if (!serverBuggy) + { + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) + && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) + { + FloorItem *const item = static_cast(*it); + if (allowAll) + { + if (mIgnorePickupItemsSet.find(item->getName()) + == mIgnorePickupItemsSet.end()) + { + if (player_node->pickUp(item)) + finded = true; + } + } + else + { + if (mPickupItemsSet.find(item->getName()) + != mPickupItemsSet.end()) + { + if (player_node->pickUp(item)) + finded = true; + } + } + } + } + } + else if (client->checkPackets(PACKET_PICKUP)) + { + FloorItem *item = nullptr; + unsigned cnt = 65535; + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) + && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) + { + FloorItem *const tempItem = static_cast(*it); + if (tempItem->getPickupCount() < cnt) + { + if (allowAll) + { + if (mIgnorePickupItemsSet.find(tempItem->getName()) + == mIgnorePickupItemsSet.end()) + { + item = tempItem; + cnt = item->getPickupCount(); + if (cnt == 0) + { + item->incrementPickup(); + player_node->pickUp(item); + return true; + } + } + } + else + { + if (mPickupItemsSet.find(tempItem->getName()) + != mPickupItemsSet.end()) + { + item = tempItem; + cnt = item->getPickupCount(); + if (cnt == 0) + { + item->incrementPickup(); + player_node->pickUp(item); + return true; + } + } + } + } + } + } + if (item && player_node->pickUp(item)) + finded = true; + } + return finded; +} + +bool ActorManager::pickUpNearest(const int x, const int y, + int maxdist) const +{ + if (!player_node) + return false; + + maxdist = maxdist * maxdist; + FloorItem *closestItem = nullptr; + int dist = 0; + const bool allowAll = mPickupItemsSet.find("") != mPickupItemsSet.end(); + + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + { + FloorItem *const item = static_cast(*it); + + const int d = (item->getTileX() - x) * (item->getTileX() - x) + + (item->getTileY() - y) * (item->getTileY() - y); + + if ((d < dist || !closestItem) && (!mTargetOnlyReachable + || player_node->isReachable(item->getTileX(), + item->getTileY(), false))) + { + if (allowAll) + { + if (mIgnorePickupItemsSet.find(item->getName()) + == mIgnorePickupItemsSet.end()) + { + dist = d; + closestItem = item; + } + } + else + { + if (mPickupItemsSet.find(item->getName()) + != mPickupItemsSet.end()) + { + dist = d; + closestItem = item; + } + } + } + } + } + if (closestItem && dist <= maxdist) + return player_node->pickUp(closestItem); + + return false; +} + +Being *ActorManager::findBeingByName(const std::string &name, + const ActorSprite::Type type) const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*it); + if (being->getName() == name && + (type == ActorSprite::UNKNOWN || type == being->getType())) + { + return being; + } + } + return nullptr; +} + +Being *ActorManager::findNearestByName(const std::string &name, + const Being::Type &type) const +{ + if (!player_node) + return nullptr; + + int dist = 0; + Being* closestBeing = nullptr; + int x, y; + + x = player_node->getTileX(); + y = player_node->getTileY(); + + for_actorsm + { + if (reportTrue(!*it)) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*it); + + if (being && being->getName() == name && + (type == Being::UNKNOWN || type == being->getType())) + { + if (being->getType() == Being::PLAYER) + { + return being; + } + else + { + const int d = (being->getTileX() - x) * (being->getTileX() - x) + + (being->getTileY() - y) * (being->getTileY() - y); + + if (validateBeing(nullptr, being, type, nullptr, 50) + && (d < dist || closestBeing == nullptr)) + { + dist = d; + closestBeing = being; + } + } + } + } + return closestBeing; +} + +const ActorSprites &ActorManager::getAll() const +{ + return mActors; +} + +void ActorManager::logic() +{ + BLOCK_START("ActorManager::logic") + for_actors + { + if (*it) + (*it)->logic(); + } + + if (mDeleteActors.empty()) + { + BLOCK_END("ActorManager::logic") + return; + } + + BLOCK_START("ActorManager::logic 1") + FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) + { + if (!*it) + continue; + + if ((*it) && (*it)->getType() == Being::PLAYER) + { + const Being *const being = static_cast(*it); + being->addToCache(); + if (beingEquipmentWindow) + beingEquipmentWindow->resetBeing(being); + } + if (player_node) + { + if (player_node->getTarget() == *it) + player_node->setTarget(nullptr); + if (player_node->getPickUpTarget() == *it) + player_node->unSetPickUpTarget(); + } + if (viewport) + viewport->clearHover(*it); + } + + FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) + { + mActors.erase(*it); + delete *it; + } + + mDeleteActors.clear(); + BLOCK_END("ActorManager::logic 1") + BLOCK_END("ActorManager::logic") +} + +void ActorManager::clear() +{ + if (beingEquipmentWindow) + beingEquipmentWindow->setBeing(nullptr); + + if (player_node) + { + player_node->setTarget(nullptr); + player_node->unSetPickUpTarget(); + mActors.erase(player_node); + } + + for_actors + { + delete *it; + } + mActors.clear(); + mDeleteActors.clear(); + + if (player_node) + mActors.insert(player_node); +} + +Being *ActorManager::findNearestLivingBeing(const int x, const int y, + const int maxTileDist, + const ActorSprite::Type type, + const Being *const excluded) const +{ + const int maxDist = maxTileDist * mapTileSize; + + return findNearestLivingBeing(nullptr, maxDist, type, x, y, excluded); +} + +Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, + const int maxDist, + const Being::Type type) const +{ + if (!aroundBeing) + return nullptr; + + return findNearestLivingBeing(aroundBeing, maxDist, type, + aroundBeing->getTileX(), aroundBeing->getTileY(), aroundBeing); +} + +Being *ActorManager::findNearestLivingBeing(const Being *const aroundBeing, + int maxDist, + const Being::Type &type, + const int x, const int y, + const Being *const excluded) const +{ + if (!aroundBeing || !player_node) + return nullptr; + + std::set attackMobs; + std::set priorityMobs; + std::set ignoreAttackMobs; + std::map attackMobsMap; + std::map priorityMobsMap; + int defaultAttackIndex = 10000; + int defaultPriorityIndex = 10000; + const int attackRange = player_node->getAttackRange(); + + bool specialDistance = false; + if (player_node->getMoveToTargetType() == 7 + && player_node->getAttackRange() > 2) + { + specialDistance = true; + } + + maxDist = maxDist * maxDist; + + const bool cycleSelect = (mCyclePlayers && type == Being::PLAYER) + || (mCycleMonsters && type == Being::MONSTER) + || (mCycleNPC && type == Being::NPC); + + const bool filtered = config.getBoolValue("enableAttackFilter") + && type == Being::MONSTER; + + bool ignoreDefault = false; + if (filtered) + { + attackMobs = mAttackMobsSet; + priorityMobs = mPriorityAttackMobsSet; + ignoreAttackMobs = mIgnoreAttackMobsSet; + attackMobsMap = mAttackMobsMap; + priorityMobsMap = mPriorityAttackMobsMap; + beingActorSorter.attackBeings = &attackMobsMap; + beingActorSorter.priorityBeings = &priorityMobsMap; + beingActorSorter.specialDistance = specialDistance; + beingActorSorter.attackRange = attackRange; + if (ignoreAttackMobs.find("") != ignoreAttackMobs.end()) + ignoreDefault = true; + std::map::const_iterator + itr = attackMobsMap.find(""); + if (itr != attackMobsMap.end()) + defaultAttackIndex = (*itr).second; + itr = priorityMobsMap.find(""); + if (itr != priorityMobsMap.end()) + defaultPriorityIndex = (*itr).second; + } + + if (cycleSelect) + { + std::vector sortedBeings; + + FOR_EACH (ActorSprites::iterator, i, mActors) + { + if (!*i) + continue; + + if ((*i)->getType() == ActorSprite::FLOOR_ITEM + || (*i)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*i); + + if (filtered) + { + if (ignoreAttackMobs.find(being->getName()) + != ignoreAttackMobs.end()) + { + continue; + } + if (ignoreDefault && attackMobs.find(being->getName()) + == attackMobs.end() && priorityMobs.find(being->getName()) + == priorityMobs.end()) + { + continue; + } + } + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + + if (validateBeing(aroundBeing, being, type, nullptr, maxDist)) + { + if (being != excluded) + sortedBeings.push_back(being); + } + } + + // no selectable beings + if (sortedBeings.empty()) + return nullptr; + + beingActorSorter.x = x; + beingActorSorter.y = y; + if (filtered) + { + beingActorSorter.attackBeings = &attackMobsMap; + beingActorSorter.defaultAttackIndex = defaultAttackIndex; + beingActorSorter.priorityBeings = &priorityMobsMap; + beingActorSorter.defaultPriorityIndex = defaultPriorityIndex; + } + else + { + beingActorSorter.attackBeings = nullptr; + beingActorSorter.priorityBeings = nullptr; + } + std::sort(sortedBeings.begin(), sortedBeings.end(), beingActorSorter); + if (filtered) + { + beingActorSorter.attackBeings = nullptr; + beingActorSorter.priorityBeings = nullptr; + } + + if (player_node->getTarget() == nullptr) + { + Being *const target = sortedBeings.at(0); + + if (specialDistance && target->getType() == Being::MONSTER + && target->getDistance() <= 2) + { + return nullptr; + } + // if no selected being in vector, return first nearest being + return target; + } + + beingEqualActorFinder.findBeing = player_node->getTarget(); + std::vector::const_iterator i = std::find_if( + sortedBeings.begin(), sortedBeings.end(), beingEqualActorFinder); + + if (i == sortedBeings.end() || ++i == sortedBeings.end()) + { + // if no selected being in vector, return first nearest being + return sortedBeings.at(0); + } + + // we find next being after target + return *i; + } + else + { + int dist = 0; + int index = defaultPriorityIndex; + Being *closestBeing = nullptr; + + FOR_EACH (ActorSprites::iterator, i, mActors) + { + if (!*i) + continue; + + if ((*i)->getType() == ActorSprite::FLOOR_ITEM + || (*i)->getType() == ActorSprite::PORTAL) + { + continue; + } + Being *const being = static_cast(*i); + + if (filtered) + { + if (ignoreAttackMobs.find(being->getName()) + != ignoreAttackMobs.end()) + { + continue; + } + if (ignoreDefault && attackMobs.find(being->getName()) + == attackMobs.end() && priorityMobs.find(being->getName()) + == priorityMobs.end()) + { + continue; + } + } + + if (being->getInfo() && !being->getInfo()->isTargetSelection()) + continue; + + const bool valid = validateBeing(aroundBeing, being, + type, excluded, 50); + int d = being->getDistance(); + if (being->getType() != Being::MONSTER || !mTargetOnlyReachable) + { // if distance not calculated, use old distance + d = (being->getTileX() - x) * (being->getTileX() - x) + + (being->getTileY() - y) * (being->getTileY() - y); + } + + if (!valid) + continue; + + if (specialDistance && being->getDistance() <= 2 + && being->getType() == type) + { + continue; + } + +// logger->log("being name:" + being->getName()); +// logger->log("index:" + toString(index)); +// logger->log("d:" + toString(d)); + + if (!filtered && (d <= dist || !closestBeing)) + { + dist = d; + closestBeing = being; + } + else if (filtered) + { + int w2 = defaultPriorityIndex; + if (closestBeing) + { + const std::map::const_iterator it2 + = priorityMobsMap.find(being->getName()); + if (it2 != priorityMobsMap.end()) + w2 = (*it2).second; + + if (w2 < index) + { + dist = d; + closestBeing = being; + index = w2; + continue; + } + if (w2 == index && d <= dist) + { + dist = d; + closestBeing = being; + index = w2; + continue; + } + } + + if (!closestBeing) + { + dist = d; + closestBeing = being; + const std::map::const_iterator it1 + = priorityMobsMap.find(being->getName()); + if (it1 != priorityMobsMap.end()) + index = (*it1).second; + else + index = defaultPriorityIndex; + } + } + } + return (maxDist >= dist) ? closestBeing : nullptr; + } +} + +bool ActorManager::validateBeing(const Being *const aroundBeing, + Being *const being, + const Being::Type &type, + const Being* const excluded, + const int maxCost) const +{ + if (!player_node) + return false; + return being && ((being->getType() == type + || type == Being::UNKNOWN) && (being->isAlive() + || (mTargetDeadPlayers && type == Being::PLAYER)) + && being != aroundBeing) && being != excluded + && (type != Being::MONSTER || !mTargetOnlyReachable + || player_node->isReachable(being, maxCost)); +} + +void ActorManager::healTarget() const +{ + if (!player_node) + return; + + heal(player_node->getTarget()); +} + +void ActorManager::heal(const Being *const target) const +{ + if (!player_node || !chatWindow || !player_node->isAlive() + || !Net::getPlayerHandler()->canUseMagic()) + { + return; + } + + // self + if (target && player_node->getName() == target->getName()) + { + if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 6 + && PlayerInfo::getAttribute(PlayerInfo::HP) + != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal1); + } + } + // magic levels < 2 + else if (PlayerInfo::getSkillLevel(340) < 2 + || PlayerInfo::getSkillLevel(341) < 2) + { + if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 6) + { + if (target && target->getType() != Being::MONSTER) + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal1 + " " + + target->getName()); + } + else if (PlayerInfo::getAttribute(PlayerInfo::HP) + != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal1); + } + } + } + // magic level >= 2 and not self + else + { + // mp > 10 and target not monster + if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 10 && target + && target->getType() != Being::MONSTER) + { + // target not enemy + if (player_relations.getRelation(target->getName()) != + PlayerRelation::ENEMY2) + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal2 + " " + + target->getName()); + } + // target enemy + else + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal1); + } + } + // heal self if selected monster or selection empty + else if ((!target || target->getType() == Being::MONSTER) + && PlayerInfo::getAttribute(PlayerInfo::MP) >= 6 + && PlayerInfo::getAttribute(PlayerInfo::HP) + != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) + { + if (!client->limitPackets(PACKET_CHAT)) + return; + chatWindow->localChatInput(mSpellHeal1); + } + } +} + +void ActorManager::itenplz() const +{ + if (!player_node || !chatWindow || !player_node->isAlive() + || !Net::getPlayerHandler()->canUseMagic()) + { + return; + } + + if (!client->limitPackets(PACKET_CHAT)) + return; + + chatWindow->localChatInput(mSpellItenplz); +} + +bool ActorManager::hasActorSprite(const ActorSprite *const actor) const +{ + for_actors + { + if (actor == *it) + return true; + } + + return false; +} + +void ActorManager::addBlock(const uint32_t id) +{ + mBlockedBeings.insert(id); +} + +void ActorManager::deleteBlock(const uint32_t id) +{ + mBlockedBeings.erase(id); +} + +bool ActorManager::isBlocked(const uint32_t id) const +{ + return mBlockedBeings.find(id) != mBlockedBeings.end(); +} + +void ActorManager::printAllToChat() const +{ + // TRANSLATORS: visible beings on map + printBeingsToChat(getAll(), _("Visible on map")); +} + +void ActorManager::printBeingsToChat(const ActorSprites &beings, + const std::string &header) const +{ + if (!debugChatTab) + return; + + debugChatTab->chatLog("---------------------------------------"); + debugChatTab->chatLog(header); + FOR_EACH (std::set::const_iterator, it, beings) + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM) + continue; + + const Being *const being = static_cast(*it); + + debugChatTab->chatLog(strprintf("%s (%d,%d) %d", + being->getName().c_str(), being->getTileX(), being->getTileY(), + being->getSubType()), BY_SERVER); + } + debugChatTab->chatLog("---------------------------------------"); +} + +void ActorManager::printBeingsToChat(const std::vector &beings, + const std::string &header) const +{ + if (!debugChatTab) + return; + + debugChatTab->chatLog("---------------------------------------"); + debugChatTab->chatLog(header); + + FOR_EACH (std::vector::const_iterator, i, beings) + { + if (!*i) + continue; + + const Being *const being = *i; + + debugChatTab->chatLog(strprintf("%s (%d,%d) %d", + being->getName().c_str(), being->getTileX(), being->getTileY(), + being->getSubType()), BY_SERVER); + } + debugChatTab->chatLog("---------------------------------------"); +} + +void ActorManager::getPlayerNames(StringVect &names, + const bool npcNames) const +{ + names.clear(); + + for_actors + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + const Being *const being = static_cast(*it); + if ((being->getType() == ActorSprite::PLAYER + || (being->getType() == ActorSprite::NPC && npcNames)) + && being->getName() != "") + { + names.push_back(being->getName()); + } + } +} + +void ActorManager::getMobNames(StringVect &names) const +{ + names.clear(); + + for_actors + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + const Being *const being = static_cast(*it); + if (being->getType() == ActorSprite::MONSTER && being->getName() != "") + names.push_back(being->getName()); + } +} + +void ActorManager::updatePlayerNames() const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*it); + being->setGoodStatus(-1); + if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + being->updateName(); + } +} + +void ActorManager::updatePlayerColors() const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*it); + if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + being->updateColors(); + } +} + +void ActorManager::updatePlayerGuild() const +{ + for_actorsm + { + if (!*it) + continue; + + if ((*it)->getType() == ActorSprite::FLOOR_ITEM + || (*it)->getType() == ActorSprite::PORTAL) + { + continue; + } + + Being *const being = static_cast(*it); + if (being->getType() == ActorSprite::PLAYER && being->getName() != "") + being->updateGuild(); + } +} + +void ActorManager::parseLevels(std::string levels) const +{ + levels.append(", "); + size_t f = 0; + const std::string brkEnd("), "); + size_t pos = levels.find(brkEnd, f); + + while (pos != std::string::npos) + { + std::string part = levels.substr(f, pos - f); + if (part.empty()) + break; + const size_t bktPos = part.rfind("("); + if (bktPos != std::string::npos) + { + Being *const being = findBeingByName(part.substr(0, bktPos), + Being::PLAYER); + if (being) + { + being->setLevel(atoi(part.substr(bktPos + 1).c_str())); + being->addToCache(); + } + } + f = static_cast(pos + brkEnd.length()); + pos = levels.find(brkEnd, f); + } + updatePlayerNames(); +} + +void ActorManager::optionChanged(const std::string &name) +{ + if (name == "targetDeadPlayers") + mTargetDeadPlayers = config.getBoolValue("targetDeadPlayers"); + else if (name == "targetOnlyReachable") + mTargetOnlyReachable = config.getBoolValue("targetOnlyReachable"); + else if (name == "cyclePlayers") + mCyclePlayers = config.getBoolValue("cyclePlayers"); + else if (name == "cycleMonsters") + mCycleMonsters = config.getBoolValue("cycleMonsters"); + else if (name == "cycleNPC") + mCycleNPC = config.getBoolValue("cycleNPC"); + else if (name == "extMouseTargeting") + mExtMouseTargeting = config.getBoolValue("extMouseTargeting"); +} + +void ActorManager::removeAttackMob(const std::string &name) +{ + mPriorityAttackMobs.remove(name); + mAttackMobs.remove(name); + mIgnoreAttackMobs.remove(name); + mPriorityAttackMobsSet.erase(name); + mAttackMobsSet.erase(name); + mIgnoreAttackMobsSet.erase(name); + rebuildAttackMobs(); + rebuildPriorityAttackMobs(); +} + +void ActorManager::removePickupItem(const std::string &name) +{ + mPickupItems.remove(name); + mPickupItemsSet.erase(name); + mIgnorePickupItems.remove(name); + mIgnorePickupItemsSet.erase(name); + rebuildPickupItems(); +} + +#define addMobToList(name, mob) \ +{\ + const int size = get##mob##sSize();\ + if (size > 0)\ + {\ + const int idx = get##mob##Index("");\ + if (idx + 1 == size)\ + {\ + std::list::iterator itr = m##mob##s.end();\ + -- itr;\ + m##mob##s.insert(itr, name);\ + }\ + else\ + {\ + m##mob##s.push_back(name);\ + }\ + }\ + else\ + {\ + m##mob##s.push_back(name);\ + }\ + m##mob##sSet.insert(name);\ + rebuild##mob##s();\ +} + +#define rebuildMobsList(mob) \ +{\ + m##mob##sMap.clear();\ + std::list::const_iterator i = m##mob##s.begin();\ + int cnt = 0;\ + while (i != m##mob##s.end())\ + {\ + m##mob##sMap[*i] = cnt;\ + ++ i;\ + ++ cnt;\ + }\ +} + +void ActorManager::addAttackMob(const std::string &name) +{ + addMobToList(name, AttackMob); + rebuildPriorityAttackMobs(); +} + +void ActorManager::addPriorityAttackMob(const std::string &name) +{ + addMobToList(name, PriorityAttackMob); +} + +void ActorManager::addIgnoreAttackMob(const std::string &name) +{ + mIgnoreAttackMobs.push_back(name); + mIgnoreAttackMobsSet.insert(name); + rebuildAttackMobs(); + rebuildPriorityAttackMobs(); +} + +void ActorManager::addPickupItem(const std::string &name) +{ + addMobToList(name, PickupItem); + rebuildPickupItems(); +} + +void ActorManager::addIgnorePickupItem(const std::string &name) +{ + mIgnorePickupItems.push_back(name); + mIgnorePickupItemsSet.insert(name); + rebuildPickupItems(); +} + +void ActorManager::rebuildPriorityAttackMobs() +{ + rebuildMobsList(PriorityAttackMob); +} + +void ActorManager::rebuildAttackMobs() +{ + rebuildMobsList(AttackMob); +} + +void ActorManager::rebuildPickupItems() +{ + rebuildMobsList(PickupItem); +} + +int ActorManager::getIndexByName(const std::string &name, + const std::map &map) const +{ + const std::map::const_iterator + i = map.find(name); + if (i == map.end()) + return -1; + + return (*i).second; +} + +int ActorManager::getPriorityAttackMobIndex(const std::string &name) const +{ + return getIndexByName(name, mPriorityAttackMobsMap); +} + +int ActorManager::getAttackMobIndex(const std::string &name) const +{ + return getIndexByName(name, mAttackMobsMap); +} + +int ActorManager::getPickupItemIndex(const std::string &name) const +{ + return getIndexByName(name, mPickupItemsMap); +} + +#define loadList(key, mob) \ +{\ + list = unpackList(serverConfig.getValue(key, ""));\ + i = list.begin();\ + i_end = list.end();\ + while (i != i_end)\ + {\ + if (*i == "")\ + empty = true;\ + m##mob##s.push_back(*i);\ + m##mob##sSet.insert(*i);\ + ++ i;\ + }\ +} + +void ActorManager::loadAttackList() +{ + bool empty = false; + std::list list; + std::list::const_iterator i; + std::list::const_iterator i_end; + + loadList("attackPriorityMobs", PriorityAttackMob); + loadList("attackMobs", AttackMob); + loadList("ignoreAttackMobs", IgnoreAttackMob); + if (!empty) + { + mAttackMobs.push_back(""); + mAttackMobsSet.insert(""); + } + empty = false; + + loadList("pickupItems", PickupItem); + loadList("ignorePickupItems", IgnorePickupItem); + if (!empty) + { + mPickupItems.push_back(""); + mPickupItemsSet.insert(""); + } + + rebuildAttackMobs(); + rebuildPriorityAttackMobs(); + rebuildPickupItems(); +} + +void ActorManager::storeAttackList() const +{ + serverConfig.setValue("attackPriorityMobs", packList(mPriorityAttackMobs)); + serverConfig.setValue("attackMobs", packList(mAttackMobs)); + serverConfig.setValue("ignoreAttackMobs", packList(mIgnoreAttackMobs)); + + serverConfig.setValue("pickupItems", packList(mPickupItems)); + serverConfig.setValue("ignorePickupItems", packList(mIgnorePickupItems)); +} + +bool ActorManager::checkForPickup(const FloorItem *const item) const +{ + if (mPickupItemsSet.find("") != mPickupItemsSet.end()) + { + if (mIgnorePickupItemsSet.find(item->getName()) + == mIgnorePickupItemsSet.end()) + { + return true; + } + } + else if (item && mPickupItemsSet.find(item->getName()) + != mPickupItemsSet.end()) + { + return true; + } + return false; +} + +void ActorManager::updateEffects(const std::map &addEffects, + const std::set &removeEffects) const +{ + for_actorsm + { + if (!*it || (*it)->getType() != ActorSprite::NPC) + continue; + Being *const being = static_cast(*it); + const int type = being->getSubType(); + if (removeEffects.find(type) != removeEffects.end()) + being->removeSpecialEffect(); + const std::map::const_iterator idAdd = addEffects.find(type); + if (idAdd != addEffects.end()) + being->addSpecialEffect((*idAdd).second); + } +} diff --git a/src/actormanager.h b/src/actormanager.h new file mode 100644 index 000000000..93068b8c8 --- /dev/null +++ b/src/actormanager.h @@ -0,0 +1,357 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef ACTORMANAGER_H +#define ACTORMANAGER_H + +#include "flooritem.h" + +#include "being/being.h" + +#include "localconsts.h" + +class LocalPlayer; +class Map; + +typedef std::set ActorSprites; +typedef ActorSprites::iterator ActorSpritesIterator; +typedef ActorSprites::const_iterator ActorSpritesConstIterator; + +class ActorManager final: public ConfigListener +{ + public: + ActorManager(); + + A_DELETE_COPY(ActorManager) + + ~ActorManager(); + + /** + * Sets the map on which ActorSprites are created. + */ + void setMap(Map *const map); + + /** + * Sets the current player. + */ + void setPlayer(LocalPlayer *const player); + + /** + * Create a Being and add it to the list of ActorSprites. + */ + Being *createBeing(const int id, const ActorSprite::Type type, + const uint16_t subtype) A_WARN_UNUSED; + + /** + * Create a FloorItem and add it to the list of ActorSprites. + */ + FloorItem *createItem(const int id, const int itemId, + const int x, const int y, + const int amount, const unsigned char color, + const int subX, const int subY); + + /** + * Destroys the given ActorSprite at the end of + * ActorManager::logic. + */ + void destroy(ActorSprite *const actor); + + void erase(ActorSprite *const actor); + + void undelete(const ActorSprite *const actor); + + /** + * Returns a specific Being, by id; + */ + Being *findBeing(const int id) const A_WARN_UNUSED; + + /** + * Returns a being at specific coordinates. + */ + Being *findBeing(const int x, const int y, const ActorSprite::Type + type = ActorSprite::UNKNOWN) const A_WARN_UNUSED; + + /** + * Returns a being at the specific pixel. + */ + Being *findBeingByPixel(const int x, const int y, + const bool allPlayers = false) + const A_WARN_UNUSED; + + /** + * Returns a beings at the specific pixel. + */ + void findBeingsByPixel(std::vector &beings, + const int x, const int y, + const bool allPlayers) const; + + /** + * Returns a portal at the specific tile. + */ + Being *findPortalByTile(const int x, const int y) const A_WARN_UNUSED; + + /** + * Returns a specific FloorItem, by id. + */ + FloorItem *findItem(const int id) const A_WARN_UNUSED; + + /** + * Returns a FloorItem at specific coordinates. + */ + FloorItem *findItem(const int x, const int y) const A_WARN_UNUSED; + + /** + * Returns a being nearest to specific coordinates. + * + * @param x X coordinate in pixels. + * @param y Y coordinate in pixels. + * @param maxTileDist Maximal distance in tiles. If minimal distance is + * larger, no being is returned. + * @param type The type of being to look for. + */ + Being *findNearestLivingBeing(const int x, const int y, + int maxTileDist, + const ActorSprite::Type + type = Being::UNKNOWN, + const Being *const + excluded = nullptr) const A_WARN_UNUSED; + + /** + * Returns a being nearest to another being. + * + * @param aroundBeing The being to search around. + * @param maxTileDist Maximal distance in tiles. If minimal distance is + * larger, no being is returned. + * @param type The type of being to look for. + */ + Being *findNearestLivingBeing(const Being *const aroundBeing, + const int maxTileDist, + const ActorSprite::Type + type = Being::UNKNOWN) + const A_WARN_UNUSED; + + /** + * Finds a being by name and (optionally) by type. + */ + Being *findBeingByName(const std::string &name, + const ActorSprite::Type + type = Being::UNKNOWN) const A_WARN_UNUSED; + + /** + * Finds a nearest being by name and (optionally) by type. + */ + Being *findNearestByName(const std::string &name, + const Being::Type &type = Being::UNKNOWN) + const A_WARN_UNUSED; + + /** + * Heal all players in distance. + * + * \param maxdist maximal distance. If minimal distance is larger, + * no being is returned + */ +// void HealAllTargets(Being *aroundBeing, int maxdist, +// Being::Type type) const; + + void healTarget() const; + + void heal(const Being *const target) const; + + void itenplz() const; + + /** + * Returns the whole list of beings. + */ + const ActorSprites &getAll() const; + + /** + * Returns true if the given ActorSprite is in the manager's list, + * false otherwise. + * + * \param actor the ActorSprite to search for + */ + bool hasActorSprite(const ActorSprite *const actor) + const A_WARN_UNUSED; + + /** + * Performs ActorSprite logic and deletes ActorSprite scheduled to be + * deleted. + */ + void logic(); + + /** + * Destroys all ActorSprites except the local player + */ + void clear(); + + void addBlock(const uint32_t id); + + void deleteBlock(const uint32_t id); + + bool isBlocked(const uint32_t id) const; + + void printAllToChat() const; + + void printBeingsToChat(const ActorSprites &beings, + const std::string &header) const; + + void printBeingsToChat(const std::vector &beings, + const std::string &header) const; + + void getPlayerNames(StringVect &names, + const bool npcNames) const; + + void getMobNames(StringVect &names) const; + + void updatePlayerNames() const; + + void updatePlayerColors() const; + + void updatePlayerGuild() const; + + void parseLevels(std::string levels) const; + + bool pickUpAll(const int x1, const int y1, const int x2, const int y2, + const bool serverBuggy = false); + + bool pickUpNearest(const int x, const int y, int maxdist) const; + + void optionChanged(const std::string &name) override; + + void removeAttackMob(const std::string &name); + + void removePickupItem(const std::string &name); + + void addPriorityAttackMob(const std::string &name); + + void addAttackMob(const std::string &name); + + void addIgnoreAttackMob(const std::string &name); + + void addPickupItem(const std::string &name); + + void addIgnorePickupItem(const std::string &name); + + void setPriorityAttackMobs(std::list mobs) + { mPriorityAttackMobs = mobs; } + + void setAttackMobs(std::list mobs) + { mAttackMobs = mobs; } + + int getPriorityAttackMobsSize() const A_WARN_UNUSED + { return static_cast(mPriorityAttackMobs.size()); } + + int getAttackMobsSize() const A_WARN_UNUSED + { return static_cast(mAttackMobs.size()); } + + int getPickupItemsSize() const A_WARN_UNUSED + { return static_cast(mPickupItems.size()); } + +#define defList(list1, mob) \ + bool isIn##list1##List(const std::string &name) const A_WARN_UNUSED\ + { return m##list1##mob##Set.find(name) != m##list1##mob##Set.end(); }\ + void rebuild##list1##mob();\ + std::set get##list1##mob##Set() const A_WARN_UNUSED\ + { return m##list1##mob##Set; }\ + std::list get##list1##mob() const A_WARN_UNUSED\ + { return m##list1##mob; } + + defList(Attack, Mobs) + defList(PriorityAttack, Mobs) + defList(IgnoreAttack, Mobs) + defList(Pickup, Items) + defList(IgnorePickup, Items) + + const std::map &getAttackMobsMap() + const A_WARN_UNUSED + { return mAttackMobsMap; } + + const std::map &getPriorityAttackMobsMap() + const A_WARN_UNUSED + { return mPriorityAttackMobsMap; } + + int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED; + + int getPriorityAttackMobIndex(const std::string &name) + const A_WARN_UNUSED; + + int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED; + + int getIndexByName(const std::string &name, const std::map &map) const A_WARN_UNUSED; + + bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED; + + void updateEffects(const std::map &addEffects, + const std::set &removeEffects) const; + + protected: + bool validateBeing(const Being *const aroundBeing, + Being *const being, + const Being::Type &type, + const Being *const excluded = nullptr, + const int maxCost = 20) const A_WARN_UNUSED; + + Being *findNearestLivingBeing(const Being *const aroundBeing, + const int maxdist, + const Being::Type &type, + const int x, const int y, + const Being *const + excluded = nullptr) const A_WARN_UNUSED; + + void loadAttackList(); + void storeAttackList() const; + + ActorSprites mActors; + ActorSprites mDeleteActors; + std::set mBlockedBeings; + Map *mMap; + std::string mSpellHeal1; + std::string mSpellHeal2; + std::string mSpellItenplz; + bool mTargetDeadPlayers; + bool mTargetOnlyReachable; + bool mCyclePlayers; + bool mCycleMonsters; + bool mCycleNPC; + bool mExtMouseTargeting; + +#define defVarsP(mob) \ + std::list mPriority##mob;\ + std::set mPriority##mob##Set;\ + std::map mPriority##mob##Map; + +#define defVars(mob) \ + std::list m##mob;\ + std::set m##mob##Set;\ + std::map m##mob##Map;\ + std::list mIgnore##mob;\ + std::set mIgnore##mob##Set; + + defVarsP(AttackMobs) + defVars(AttackMobs) + defVars(PickupItems) +}; + +extern ActorManager *actorManager; + +#endif // ACTORMANAGER_H diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp deleted file mode 100644 index 0ea7a7295..000000000 --- a/src/actorspritemanager.cpp +++ /dev/null @@ -1,1676 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "actorspritemanager.h" - -#include "client.h" -#include "configuration.h" -#include "main.h" - -#include "being/localplayer.h" -#include "being/playerinfo.h" -#include "being/playerrelations.h" - -#include "gui/viewport.h" - -#include "gui/widgets/tabs/chattab.h" - -#include "gui/windows/equipmentwindow.h" -#include "gui/windows/socialwindow.h" - -#include "utils/checkutils.h" -#include "utils/gettext.h" - -#include "net/net.h" -#include "net/playerhandler.h" - -#include -#include - -#include "debug.h" - -#define for_actors for (ActorSpritesConstIterator it = mActors.begin(), \ - it_end = mActors.end() ; it != it_end; ++it) - -#define for_actorsm for (ActorSpritesIterator it = mActors.begin(), \ - it_end = mActors.end() ; it != it_end; ++it) - -class FindBeingFunctor final -{ - public: - bool operator() (const ActorSprite *const actor) const - { - if (!actor || actor->getType() == ActorSprite::FLOOR_ITEM - || actor->getType() == ActorSprite::PORTAL) - { - return false; - } - const Being *const b = static_cast(actor); - - const unsigned other_y = y + ((b->getType() - == ActorSprite::NPC) ? 1 : 0); - const Vector &pos = b->getPosition(); - return (static_cast(pos.x) / mapTileSize == x && - (static_cast(pos.y) / mapTileSize == y - || static_cast(pos.y) / mapTileSize == other_y) && - b->isAlive() && (type == ActorSprite::UNKNOWN - || b->getType() == type)); - } - - uint16_t x, y; - ActorSprite::Type type; -} beingActorFinder; - -class FindBeingEqualFunctor final -{ - public: - bool operator() (const Being *const being) const - { - if (!being || !findBeing) - return false; - return being->getId() == findBeing->getId(); - } - - Being *findBeing; -} beingEqualActorFinder; - -class SortBeingFunctor final -{ - public: - bool operator() (const Being *const being1, - const Being *const being2) const - { - if (!being1 || !being2) - return false; - - if (priorityBeings) - { - int w1 = defaultPriorityIndex; - int w2 = defaultPriorityIndex; - const std::map::const_iterator it1 - = priorityBeings->find(being1->getName()); - const std::map::const_iterator it2 - = priorityBeings->find(being2->getName()); - if (it1 != priorityBeings->end()) - w1 = (*it1).second; - if (it2 != priorityBeings->end()) - w2 = (*it2).second; - - if (w1 != w2) - return w1 < w2; - } - if (being1->getDistance() != being2->getDistance()) - { - if (specialDistance && being1->getDistance() <= 2 - && being2->getDistance() <= attackRange - && being2->getDistance() > 2) - { - return false; - } - else if (specialDistance && being2->getDistance() <= 2 - && being1->getDistance() <= attackRange - && being1->getDistance() > 2) - { - return true; - } - return being1->getDistance() < being2->getDistance(); - } - - int d1, d2; -#ifdef MANASERV_SUPPORT - if (Net::getNetworkType() == ServerInfo::MANASERV) - { - const Vector &pos1 = being1->getPosition(); - d1 = abs((static_cast(pos1.x)) - x) - + abs((static_cast(pos1.y)) - y); - const Vector &pos2 = being2->getPosition(); - d2 = abs((static_cast(pos2.x)) - x) - + abs((static_cast(pos2.y)) - y); - } - else -#endif - { - d1 = abs(being1->getTileX() - x) + abs(being1->getTileY() - y); - d2 = abs(being2->getTileX() - x) + abs(being2->getTileY() - y); - } - - if (d1 != d2) - return d1 < d2; - if (attackBeings) - { - int w1 = defaultAttackIndex; - int w2 = defaultAttackIndex; - const std::map::const_iterator it1 - = attackBeings->find(being1->getName()); - const std::map::const_iterator it2 - = attackBeings->find(being2->getName()); - if (it1 != attackBeings->end()) - w1 = (*it1).second; - if (it2 != attackBeings->end()) - w2 = (*it2).second; - - if (w1 != w2) - return w1 < w2; - } - - return (being1->getName() < being2->getName()); - } - std::map *attackBeings; - std::map *priorityBeings; - int x; - int y; - int defaultAttackIndex; - int defaultPriorityIndex; - int attackRange; - bool specialDistance; -} beingActorSorter; - -ActorSpriteManager::ActorSpriteManager() : - mActors(), - mDeleteActors(), - mBlockedBeings(), - mMap(nullptr), - mSpellHeal1(serverConfig.getValue("spellHeal1", "#lum")), - mSpellHeal2(serverConfig.getValue("spellHeal2", "#inma")), - mSpellItenplz(serverConfig.getValue("spellItenplz", "#itenplz")), - mTargetDeadPlayers(config.getBoolValue("targetDeadPlayers")), - mTargetOnlyReachable(config.getBoolValue("targetOnlyReachable")), - mCyclePlayers(config.getBoolValue("cyclePlayers")), - mCycleMonsters(config.getBoolValue("cycleMonsters")), - mCycleNPC(config.getBoolValue("cycleNPC")), - mExtMouseTargeting(config.getBoolValue("extMouseTargeting")) -{ - config.addListener("targetDeadPlayers", this); - config.addListener("targetOnlyReachable", this); - config.addListener("cyclePlayers", this); - config.addListener("cycleMonsters", this); - config.addListener("cycleNPC", this); - config.addListener("extMouseTargeting", this); - - loadAttackList(); -} - -ActorSpriteManager::~ActorSpriteManager() -{ - config.removeListeners(this); - storeAttackList(); - clear(); -} - -void ActorSpriteManager::setMap(Map *const map) -{ - mMap = map; - - if (player_node) - player_node->setMap(map); -} - -void ActorSpriteManager::setPlayer(LocalPlayer *const player) -{ - player_node = player; - mActors.insert(player); - if (socialWindow) - socialWindow->updateAttackFilter(); - if (socialWindow) - socialWindow->updatePickupFilter(); -} - -Being *ActorSpriteManager::createBeing(const int id, - const ActorSprite::Type type, - const uint16_t subtype) -{ - Being *const being = new Being(id, type, subtype, mMap); - - mActors.insert(being); - return being; -} - -FloorItem *ActorSpriteManager::createItem(const int id, const int itemId, - const int x, const int y, - const int amount, - const unsigned char color, - const int subX, const int subY) -{ - FloorItem *const floorItem = new FloorItem(id, itemId, - x, y, amount, color); - floorItem->postInit(mMap, subX, subY); - - if (!checkForPickup(floorItem)) - floorItem->disableHightlight(); - mActors.insert(floorItem); - return floorItem; -} - -void ActorSpriteManager::destroy(ActorSprite *const actor) -{ - if (!actor || actor == player_node) - return; - - mDeleteActors.insert(actor); -} - -void ActorSpriteManager::erase(ActorSprite *const actor) -{ - if (!actor || actor == player_node) - return; - - mActors.erase(actor); -} - -void ActorSpriteManager::undelete(const ActorSprite *const actor) -{ - if (!actor || actor == player_node) - return; - - FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) - { - if (*it == actor) - { - mDeleteActors.erase(*it); - return; - } - } -} - -Being *ActorSpriteManager::findBeing(const int id) const -{ - for_actors - { - ActorSprite *const actor = *it; - if (actor->getId() == id && - actor->getType() != ActorSprite::FLOOR_ITEM) - { - return static_cast(actor); - } - } - - return nullptr; -} - -Being *ActorSpriteManager::findBeing(const int x, const int y, - const ActorSprite::Type type) const -{ - beingActorFinder.x = static_cast(x); - beingActorFinder.y = static_cast(y); - beingActorFinder.type = type; - - const ActorSpritesConstIterator it = std::find_if( - mActors.begin(), mActors.end(), beingActorFinder); - - return (it == mActors.end()) ? nullptr : static_cast(*it); -} - -Being *ActorSpriteManager::findBeingByPixel(const int x, const int y, - const bool allPlayers) const -{ - if (!mMap) - return nullptr; - - const bool targetDead = mTargetDeadPlayers; - - if (mExtMouseTargeting) - { - Being *tempBeing = nullptr; - bool noBeing(false); - - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::PORTAL) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) - { - if (!noBeing) - { - const FloorItem *const floor - = static_cast(*it); - if ((floor->getPixelX() - mapTileSize <= x) && - (floor->getPixelX() + mapTileSize > x) && - (floor->getPixelY() - mapTileSize * 2 <= y) && - (floor->getPixelY() + mapTileSize / 2 > y)) - { - noBeing = true; - } - } - continue; - } - - Being *const being = static_cast(*it); - - if (being->getInfo() && !being->getInfo()->isTargetSelection()) - continue; - - if ((being->isAlive() - || (targetDead && being->getType() == Being::PLAYER)) - && (allPlayers || being != player_node)) - { - if ((being->getPixelX() - mapTileSize / 2 <= x) && - (being->getPixelX() + mapTileSize / 2 > x) && - (being->getPixelY() - mapTileSize <= y) && - (being->getPixelY() > y)) - { - return being; - } - else if (!noBeing && (being->getPixelX() - mapTileSize <= x) && - (being->getPixelX() + mapTileSize > x) && - (being->getPixelY() - mapTileSize * 2 <= y) && - (being->getPixelY() + mapTileSize / 2 > y)) - { - if (tempBeing) - noBeing = true; - else - tempBeing = being; - } - } - } - - if (noBeing) - return nullptr; - return tempBeing; - } - else - { - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::PORTAL || - (*it)->getType() == ActorSprite::FLOOR_ITEM) - { - continue; - } - - Being *const being = static_cast(*it); - - if (being->getInfo() && !being->getInfo()->isTargetSelection()) - continue; - - if ((being->getPixelX() - mapTileSize / 2 <= x) && - (being->getPixelX() + mapTileSize / 2 > x) && - (being->getPixelY() - mapTileSize <= y) && - (being->getPixelY() > y)) - { - return being; - } - } - return nullptr; - } -} - -void ActorSpriteManager::findBeingsByPixel(std::vector &beings, - const int x, const int y, - const bool allPlayers) const -{ - if (!mMap) - return; - - const int xtol = mapTileSize / 2; - const int uptol = mapTileSize; - - for_actors - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::PORTAL) - continue; - - const Being *const being = dynamic_cast(*it); - - if (being && being->getInfo() - && !being->getInfo()->isTargetSelection()) - { - continue; - } - - ActorSprite *const actor = *it; - - if ((being && (being->isAlive() - || (mTargetDeadPlayers && being->getType() == Being::PLAYER)) - && (allPlayers || being != player_node)) - || actor->getType() == ActorSprite::FLOOR_ITEM) - { - if ((actor->getPixelX() - xtol <= x) && - (actor->getPixelX() + xtol > x) && - (actor->getPixelY() - uptol <= y) && - (actor->getPixelY() > y)) - { - beings.push_back(actor); - } - } - } -} - -Being *ActorSpriteManager::findPortalByTile(const int x, const int y) const -{ - if (!mMap) - return nullptr; - - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() != ActorSprite::PORTAL) - continue; - - Being *const being = static_cast(*it); - - if (being->getTileX() == x && being->getTileY() == y) - return being; - } - - return nullptr; -} - -FloorItem *ActorSpriteManager::findItem(const int id) const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getId() == id && - (*it)->getType() == ActorSprite::FLOOR_ITEM) - { - return static_cast(*it); - } - } - - return nullptr; -} - -FloorItem *ActorSpriteManager::findItem(const int x, const int y) const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getTileX() == x && (*it)->getTileY() == y && - (*it)->getType() == ActorSprite::FLOOR_ITEM) - { - return static_cast(*it); - } - } - - return nullptr; -} - -bool ActorSpriteManager::pickUpAll(const int x1, const int y1, - const int x2, const int y2, - const bool serverBuggy) -{ - if (!player_node) - return false; - - bool finded(false); - const bool allowAll = mPickupItemsSet.find("") != mPickupItemsSet.end(); - if (!serverBuggy) - { - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) - && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) - { - FloorItem *const item = static_cast(*it); - if (allowAll) - { - if (mIgnorePickupItemsSet.find(item->getName()) - == mIgnorePickupItemsSet.end()) - { - if (player_node->pickUp(item)) - finded = true; - } - } - else - { - if (mPickupItemsSet.find(item->getName()) - != mPickupItemsSet.end()) - { - if (player_node->pickUp(item)) - finded = true; - } - } - } - } - } - else if (client->checkPackets(PACKET_PICKUP)) - { - FloorItem *item = nullptr; - unsigned cnt = 65535; - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - && ((*it)->getTileX() >= x1 && (*it)->getTileX() <= x2) - && ((*it)->getTileY() >= y1 && (*it)->getTileY() <= y2)) - { - FloorItem *const tempItem = static_cast(*it); - if (tempItem->getPickupCount() < cnt) - { - if (allowAll) - { - if (mIgnorePickupItemsSet.find(tempItem->getName()) - == mIgnorePickupItemsSet.end()) - { - item = tempItem; - cnt = item->getPickupCount(); - if (cnt == 0) - { - item->incrementPickup(); - player_node->pickUp(item); - return true; - } - } - } - else - { - if (mPickupItemsSet.find(tempItem->getName()) - != mPickupItemsSet.end()) - { - item = tempItem; - cnt = item->getPickupCount(); - if (cnt == 0) - { - item->incrementPickup(); - player_node->pickUp(item); - return true; - } - } - } - } - } - } - if (item && player_node->pickUp(item)) - finded = true; - } - return finded; -} - -bool ActorSpriteManager::pickUpNearest(const int x, const int y, - int maxdist) const -{ - if (!player_node) - return false; - - maxdist = maxdist * maxdist; - FloorItem *closestItem = nullptr; - int dist = 0; - const bool allowAll = mPickupItemsSet.find("") != mPickupItemsSet.end(); - - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) - { - FloorItem *const item = static_cast(*it); - - const int d = (item->getTileX() - x) * (item->getTileX() - x) - + (item->getTileY() - y) * (item->getTileY() - y); - - if ((d < dist || !closestItem) && (!mTargetOnlyReachable - || player_node->isReachable(item->getTileX(), - item->getTileY(), false))) - { - if (allowAll) - { - if (mIgnorePickupItemsSet.find(item->getName()) - == mIgnorePickupItemsSet.end()) - { - dist = d; - closestItem = item; - } - } - else - { - if (mPickupItemsSet.find(item->getName()) - != mPickupItemsSet.end()) - { - dist = d; - closestItem = item; - } - } - } - } - } - if (closestItem && dist <= maxdist) - return player_node->pickUp(closestItem); - - return false; -} - -Being *ActorSpriteManager::findBeingByName(const std::string &name, - const ActorSprite::Type type) const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*it); - if (being->getName() == name && - (type == ActorSprite::UNKNOWN || type == being->getType())) - { - return being; - } - } - return nullptr; -} - -Being *ActorSpriteManager::findNearestByName(const std::string &name, - const Being::Type &type) const -{ - if (!player_node) - return nullptr; - - int dist = 0; - Being* closestBeing = nullptr; - int x, y; - - x = player_node->getTileX(); - y = player_node->getTileY(); - - for_actorsm - { - if (reportTrue(!*it)) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*it); - - if (being && being->getName() == name && - (type == Being::UNKNOWN || type == being->getType())) - { - if (being->getType() == Being::PLAYER) - { - return being; - } - else - { - const int d = (being->getTileX() - x) * (being->getTileX() - x) - + (being->getTileY() - y) * (being->getTileY() - y); - - if (validateBeing(nullptr, being, type, nullptr, 50) - && (d < dist || closestBeing == nullptr)) - { - dist = d; - closestBeing = being; - } - } - } - } - return closestBeing; -} - -const ActorSprites &ActorSpriteManager::getAll() const -{ - return mActors; -} - -void ActorSpriteManager::logic() -{ - BLOCK_START("ActorSpriteManager::logic") - for_actors - { - if (*it) - (*it)->logic(); - } - - if (mDeleteActors.empty()) - { - BLOCK_END("ActorSpriteManager::logic") - return; - } - - BLOCK_START("ActorSpriteManager::logic 1") - FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) - { - if (!*it) - continue; - - if ((*it) && (*it)->getType() == Being::PLAYER) - { - const Being *const being = static_cast(*it); - being->addToCache(); - if (beingEquipmentWindow) - beingEquipmentWindow->resetBeing(being); - } - if (player_node) - { - if (player_node->getTarget() == *it) - player_node->setTarget(nullptr); - if (player_node->getPickUpTarget() == *it) - player_node->unSetPickUpTarget(); - } - if (viewport) - viewport->clearHover(*it); - } - - FOR_EACH (ActorSpritesConstIterator, it, mDeleteActors) - { - mActors.erase(*it); - delete *it; - } - - mDeleteActors.clear(); - BLOCK_END("ActorSpriteManager::logic 1") - BLOCK_END("ActorSpriteManager::logic") -} - -void ActorSpriteManager::clear() -{ - if (beingEquipmentWindow) - beingEquipmentWindow->setBeing(nullptr); - - if (player_node) - { - player_node->setTarget(nullptr); - player_node->unSetPickUpTarget(); - mActors.erase(player_node); - } - - for_actors - { - delete *it; - } - mActors.clear(); - mDeleteActors.clear(); - - if (player_node) - mActors.insert(player_node); -} - -Being *ActorSpriteManager::findNearestLivingBeing(const int x, const int y, - const int maxTileDist, - const ActorSprite::Type type, - const Being *const - excluded) const -{ - const int maxDist = maxTileDist * mapTileSize; - - return findNearestLivingBeing(nullptr, maxDist, type, x, y, excluded); -} - -Being *ActorSpriteManager::findNearestLivingBeing(const Being *const - aroundBeing, - const int maxDist, - const Being::Type type) const -{ - if (!aroundBeing) - return nullptr; - - return findNearestLivingBeing(aroundBeing, maxDist, type, - aroundBeing->getTileX(), aroundBeing->getTileY(), aroundBeing); -} - -Being *ActorSpriteManager::findNearestLivingBeing(const Being *const - aroundBeing, int maxDist, - const Being::Type &type, - const int x, const int y, - const Being *const - excluded) const -{ - if (!aroundBeing || !player_node) - return nullptr; - - std::set attackMobs; - std::set priorityMobs; - std::set ignoreAttackMobs; - std::map attackMobsMap; - std::map priorityMobsMap; - int defaultAttackIndex = 10000; - int defaultPriorityIndex = 10000; - const int attackRange = player_node->getAttackRange(); - - bool specialDistance = false; - if (player_node->getMoveToTargetType() == 7 - && player_node->getAttackRange() > 2) - { - specialDistance = true; - } - - maxDist = maxDist * maxDist; - - const bool cycleSelect = (mCyclePlayers && type == Being::PLAYER) - || (mCycleMonsters && type == Being::MONSTER) - || (mCycleNPC && type == Being::NPC); - - const bool filtered = config.getBoolValue("enableAttackFilter") - && type == Being::MONSTER; - - bool ignoreDefault = false; - if (filtered) - { - attackMobs = mAttackMobsSet; - priorityMobs = mPriorityAttackMobsSet; - ignoreAttackMobs = mIgnoreAttackMobsSet; - attackMobsMap = mAttackMobsMap; - priorityMobsMap = mPriorityAttackMobsMap; - beingActorSorter.attackBeings = &attackMobsMap; - beingActorSorter.priorityBeings = &priorityMobsMap; - beingActorSorter.specialDistance = specialDistance; - beingActorSorter.attackRange = attackRange; - if (ignoreAttackMobs.find("") != ignoreAttackMobs.end()) - ignoreDefault = true; - std::map::const_iterator - itr = attackMobsMap.find(""); - if (itr != attackMobsMap.end()) - defaultAttackIndex = (*itr).second; - itr = priorityMobsMap.find(""); - if (itr != priorityMobsMap.end()) - defaultPriorityIndex = (*itr).second; - } - - if (cycleSelect) - { - std::vector sortedBeings; - - FOR_EACH (ActorSprites::iterator, i, mActors) - { - if (!*i) - continue; - - if ((*i)->getType() == ActorSprite::FLOOR_ITEM - || (*i)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*i); - - if (filtered) - { - if (ignoreAttackMobs.find(being->getName()) - != ignoreAttackMobs.end()) - { - continue; - } - if (ignoreDefault && attackMobs.find(being->getName()) - == attackMobs.end() && priorityMobs.find(being->getName()) - == priorityMobs.end()) - { - continue; - } - } - - if (being->getInfo() && !being->getInfo()->isTargetSelection()) - continue; - - if (validateBeing(aroundBeing, being, type, nullptr, maxDist)) - { - if (being != excluded) - sortedBeings.push_back(being); - } - } - - // no selectable beings - if (sortedBeings.empty()) - return nullptr; - - beingActorSorter.x = x; - beingActorSorter.y = y; - if (filtered) - { - beingActorSorter.attackBeings = &attackMobsMap; - beingActorSorter.defaultAttackIndex = defaultAttackIndex; - beingActorSorter.priorityBeings = &priorityMobsMap; - beingActorSorter.defaultPriorityIndex = defaultPriorityIndex; - } - else - { - beingActorSorter.attackBeings = nullptr; - beingActorSorter.priorityBeings = nullptr; - } - std::sort(sortedBeings.begin(), sortedBeings.end(), beingActorSorter); - if (filtered) - { - beingActorSorter.attackBeings = nullptr; - beingActorSorter.priorityBeings = nullptr; - } - - if (player_node->getTarget() == nullptr) - { - Being *const target = sortedBeings.at(0); - - if (specialDistance && target->getType() == Being::MONSTER - && target->getDistance() <= 2) - { - return nullptr; - } - // if no selected being in vector, return first nearest being - return target; - } - - beingEqualActorFinder.findBeing = player_node->getTarget(); - std::vector::const_iterator i = std::find_if( - sortedBeings.begin(), sortedBeings.end(), beingEqualActorFinder); - - if (i == sortedBeings.end() || ++i == sortedBeings.end()) - { - // if no selected being in vector, return first nearest being - return sortedBeings.at(0); - } - - // we find next being after target - return *i; - } - else - { - int dist = 0; - int index = defaultPriorityIndex; - Being *closestBeing = nullptr; - - FOR_EACH (ActorSprites::iterator, i, mActors) - { - if (!*i) - continue; - - if ((*i)->getType() == ActorSprite::FLOOR_ITEM - || (*i)->getType() == ActorSprite::PORTAL) - { - continue; - } - Being *const being = static_cast(*i); - - if (filtered) - { - if (ignoreAttackMobs.find(being->getName()) - != ignoreAttackMobs.end()) - { - continue; - } - if (ignoreDefault && attackMobs.find(being->getName()) - == attackMobs.end() && priorityMobs.find(being->getName()) - == priorityMobs.end()) - { - continue; - } - } - - if (being->getInfo() && !being->getInfo()->isTargetSelection()) - continue; - - const bool valid = validateBeing(aroundBeing, being, - type, excluded, 50); - int d = being->getDistance(); - if (being->getType() != Being::MONSTER || !mTargetOnlyReachable) - { // if distance not calculated, use old distance - d = (being->getTileX() - x) * (being->getTileX() - x) - + (being->getTileY() - y) * (being->getTileY() - y); - } - - if (!valid) - continue; - - if (specialDistance && being->getDistance() <= 2 - && being->getType() == type) - { - continue; - } - -// logger->log("being name:" + being->getName()); -// logger->log("index:" + toString(index)); -// logger->log("d:" + toString(d)); - - if (!filtered && (d <= dist || !closestBeing)) - { - dist = d; - closestBeing = being; - } - else if (filtered) - { - int w2 = defaultPriorityIndex; - if (closestBeing) - { - const std::map::const_iterator it2 - = priorityMobsMap.find(being->getName()); - if (it2 != priorityMobsMap.end()) - w2 = (*it2).second; - - if (w2 < index) - { - dist = d; - closestBeing = being; - index = w2; - continue; - } - if (w2 == index && d <= dist) - { - dist = d; - closestBeing = being; - index = w2; - continue; - } - } - - if (!closestBeing) - { - dist = d; - closestBeing = being; - const std::map::const_iterator it1 - = priorityMobsMap.find(being->getName()); - if (it1 != priorityMobsMap.end()) - index = (*it1).second; - else - index = defaultPriorityIndex; - } - } - } - return (maxDist >= dist) ? closestBeing : nullptr; - } -} - -bool ActorSpriteManager::validateBeing(const Being *const aroundBeing, - Being *const being, - const Being::Type &type, - const Being* const excluded, - const int maxCost) const -{ - if (!player_node) - return false; - return being && ((being->getType() == type - || type == Being::UNKNOWN) && (being->isAlive() - || (mTargetDeadPlayers && type == Being::PLAYER)) - && being != aroundBeing) && being != excluded - && (type != Being::MONSTER || !mTargetOnlyReachable - || player_node->isReachable(being, maxCost)); -} - -void ActorSpriteManager::healTarget() const -{ - if (!player_node) - return; - - heal(player_node->getTarget()); -} - -void ActorSpriteManager::heal(const Being *const target) const -{ - if (!player_node || !chatWindow || !player_node->isAlive() - || !Net::getPlayerHandler()->canUseMagic()) - { - return; - } - - // self - if (target && player_node->getName() == target->getName()) - { - if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 6 - && PlayerInfo::getAttribute(PlayerInfo::HP) - != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal1); - } - } - // magic levels < 2 - else if (PlayerInfo::getSkillLevel(340) < 2 - || PlayerInfo::getSkillLevel(341) < 2) - { - if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 6) - { - if (target && target->getType() != Being::MONSTER) - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal1 + " " - + target->getName()); - } - else if (PlayerInfo::getAttribute(PlayerInfo::HP) - != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal1); - } - } - } - // magic level >= 2 and not self - else - { - // mp > 10 and target not monster - if (PlayerInfo::getAttribute(PlayerInfo::MP) >= 10 && target - && target->getType() != Being::MONSTER) - { - // target not enemy - if (player_relations.getRelation(target->getName()) != - PlayerRelation::ENEMY2) - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal2 + " " - + target->getName()); - } - // target enemy - else - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal1); - } - } - // heal self if selected monster or selection empty - else if ((!target || target->getType() == Being::MONSTER) - && PlayerInfo::getAttribute(PlayerInfo::MP) >= 6 - && PlayerInfo::getAttribute(PlayerInfo::HP) - != PlayerInfo::getAttribute(PlayerInfo::MAX_HP)) - { - if (!client->limitPackets(PACKET_CHAT)) - return; - chatWindow->localChatInput(mSpellHeal1); - } - } -} - -void ActorSpriteManager::itenplz() const -{ - if (!player_node || !chatWindow || !player_node->isAlive() - || !Net::getPlayerHandler()->canUseMagic()) - { - return; - } - - if (!client->limitPackets(PACKET_CHAT)) - return; - - chatWindow->localChatInput(mSpellItenplz); -} - -bool ActorSpriteManager::hasActorSprite(const ActorSprite *const actor) const -{ - for_actors - { - if (actor == *it) - return true; - } - - return false; -} - -void ActorSpriteManager::addBlock(const uint32_t id) -{ - mBlockedBeings.insert(id); -} - -void ActorSpriteManager::deleteBlock(const uint32_t id) -{ - mBlockedBeings.erase(id); -} - -bool ActorSpriteManager::isBlocked(const uint32_t id) const -{ - return mBlockedBeings.find(id) != mBlockedBeings.end(); -} - -void ActorSpriteManager::printAllToChat() const -{ - // TRANSLATORS: visible beings on map - printBeingsToChat(getAll(), _("Visible on map")); -} - -void ActorSpriteManager::printBeingsToChat(const ActorSprites &beings, - const std::string &header) const -{ - if (!debugChatTab) - return; - - debugChatTab->chatLog("---------------------------------------"); - debugChatTab->chatLog(header); - FOR_EACH (std::set::const_iterator, it, beings) - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM) - continue; - - const Being *const being = static_cast(*it); - - debugChatTab->chatLog(strprintf("%s (%d,%d) %d", - being->getName().c_str(), being->getTileX(), being->getTileY(), - being->getSubType()), BY_SERVER); - } - debugChatTab->chatLog("---------------------------------------"); -} - -void ActorSpriteManager::printBeingsToChat(const std::vector &beings, - const std::string &header) const -{ - if (!debugChatTab) - return; - - debugChatTab->chatLog("---------------------------------------"); - debugChatTab->chatLog(header); - - FOR_EACH (std::vector::const_iterator, i, beings) - { - if (!*i) - continue; - - const Being *const being = *i; - - debugChatTab->chatLog(strprintf("%s (%d,%d) %d", - being->getName().c_str(), being->getTileX(), being->getTileY(), - being->getSubType()), BY_SERVER); - } - debugChatTab->chatLog("---------------------------------------"); -} - -void ActorSpriteManager::getPlayerNames(StringVect &names, - const bool npcNames) const -{ - names.clear(); - - for_actors - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - const Being *const being = static_cast(*it); - if ((being->getType() == ActorSprite::PLAYER - || (being->getType() == ActorSprite::NPC && npcNames)) - && being->getName() != "") - { - names.push_back(being->getName()); - } - } -} - -void ActorSpriteManager::getMobNames(StringVect &names) const -{ - names.clear(); - - for_actors - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - const Being *const being = static_cast(*it); - if (being->getType() == ActorSprite::MONSTER && being->getName() != "") - names.push_back(being->getName()); - } -} - -void ActorSpriteManager::updatePlayerNames() const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*it); - being->setGoodStatus(-1); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") - being->updateName(); - } -} - -void ActorSpriteManager::updatePlayerColors() const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*it); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") - being->updateColors(); - } -} - -void ActorSpriteManager::updatePlayerGuild() const -{ - for_actorsm - { - if (!*it) - continue; - - if ((*it)->getType() == ActorSprite::FLOOR_ITEM - || (*it)->getType() == ActorSprite::PORTAL) - { - continue; - } - - Being *const being = static_cast(*it); - if (being->getType() == ActorSprite::PLAYER && being->getName() != "") - being->updateGuild(); - } -} - -void ActorSpriteManager::parseLevels(std::string levels) const -{ - levels.append(", "); - size_t f = 0; - const std::string brkEnd("), "); - size_t pos = levels.find(brkEnd, f); - - while (pos != std::string::npos) - { - std::string part = levels.substr(f, pos - f); - if (part.empty()) - break; - const size_t bktPos = part.rfind("("); - if (bktPos != std::string::npos) - { - Being *const being = findBeingByName(part.substr(0, bktPos), - Being::PLAYER); - if (being) - { - being->setLevel(atoi(part.substr(bktPos + 1).c_str())); - being->addToCache(); - } - } - f = static_cast(pos + brkEnd.length()); - pos = levels.find(brkEnd, f); - } - updatePlayerNames(); -} - -void ActorSpriteManager::optionChanged(const std::string &name) -{ - if (name == "targetDeadPlayers") - mTargetDeadPlayers = config.getBoolValue("targetDeadPlayers"); - else if (name == "targetOnlyReachable") - mTargetOnlyReachable = config.getBoolValue("targetOnlyReachable"); - else if (name == "cyclePlayers") - mCyclePlayers = config.getBoolValue("cyclePlayers"); - else if (name == "cycleMonsters") - mCycleMonsters = config.getBoolValue("cycleMonsters"); - else if (name == "cycleNPC") - mCycleNPC = config.getBoolValue("cycleNPC"); - else if (name == "extMouseTargeting") - mExtMouseTargeting = config.getBoolValue("extMouseTargeting"); -} - -void ActorSpriteManager::removeAttackMob(const std::string &name) -{ - mPriorityAttackMobs.remove(name); - mAttackMobs.remove(name); - mIgnoreAttackMobs.remove(name); - mPriorityAttackMobsSet.erase(name); - mAttackMobsSet.erase(name); - mIgnoreAttackMobsSet.erase(name); - rebuildAttackMobs(); - rebuildPriorityAttackMobs(); -} - -void ActorSpriteManager::removePickupItem(const std::string &name) -{ - mPickupItems.remove(name); - mPickupItemsSet.erase(name); - mIgnorePickupItems.remove(name); - mIgnorePickupItemsSet.erase(name); - rebuildPickupItems(); -} - -#define addMobToList(name, mob) \ -{\ - const int size = get##mob##sSize();\ - if (size > 0)\ - {\ - const int idx = get##mob##Index("");\ - if (idx + 1 == size)\ - {\ - std::list::iterator itr = m##mob##s.end();\ - -- itr;\ - m##mob##s.insert(itr, name);\ - }\ - else\ - {\ - m##mob##s.push_back(name);\ - }\ - }\ - else\ - {\ - m##mob##s.push_back(name);\ - }\ - m##mob##sSet.insert(name);\ - rebuild##mob##s();\ -} - -#define rebuildMobsList(mob) \ -{\ - m##mob##sMap.clear();\ - std::list::const_iterator i = m##mob##s.begin();\ - int cnt = 0;\ - while (i != m##mob##s.end())\ - {\ - m##mob##sMap[*i] = cnt;\ - ++ i;\ - ++ cnt;\ - }\ -} - -void ActorSpriteManager::addAttackMob(const std::string &name) -{ - addMobToList(name, AttackMob); - rebuildPriorityAttackMobs(); -} - -void ActorSpriteManager::addPriorityAttackMob(const std::string &name) -{ - addMobToList(name, PriorityAttackMob); -} - -void ActorSpriteManager::addIgnoreAttackMob(const std::string &name) -{ - mIgnoreAttackMobs.push_back(name); - mIgnoreAttackMobsSet.insert(name); - rebuildAttackMobs(); - rebuildPriorityAttackMobs(); -} - -void ActorSpriteManager::addPickupItem(const std::string &name) -{ - addMobToList(name, PickupItem); - rebuildPickupItems(); -} - -void ActorSpriteManager::addIgnorePickupItem(const std::string &name) -{ - mIgnorePickupItems.push_back(name); - mIgnorePickupItemsSet.insert(name); - rebuildPickupItems(); -} - -void ActorSpriteManager::rebuildPriorityAttackMobs() -{ - rebuildMobsList(PriorityAttackMob); -} - -void ActorSpriteManager::rebuildAttackMobs() -{ - rebuildMobsList(AttackMob); -} - -void ActorSpriteManager::rebuildPickupItems() -{ - rebuildMobsList(PickupItem); -} - -int ActorSpriteManager::getIndexByName(const std::string &name, - const std::map &map) - const -{ - const std::map::const_iterator - i = map.find(name); - if (i == map.end()) - return -1; - - return (*i).second; -} - -int ActorSpriteManager::getPriorityAttackMobIndex(const std::string &name) - const -{ - return getIndexByName(name, mPriorityAttackMobsMap); -} - -int ActorSpriteManager::getAttackMobIndex(const std::string &name) const -{ - return getIndexByName(name, mAttackMobsMap); -} - -int ActorSpriteManager::getPickupItemIndex(const std::string &name) const -{ - return getIndexByName(name, mPickupItemsMap); -} - -#define loadList(key, mob) \ -{\ - list = unpackList(serverConfig.getValue(key, ""));\ - i = list.begin();\ - i_end = list.end();\ - while (i != i_end)\ - {\ - if (*i == "")\ - empty = true;\ - m##mob##s.push_back(*i);\ - m##mob##sSet.insert(*i);\ - ++ i;\ - }\ -} - -void ActorSpriteManager::loadAttackList() -{ - bool empty = false; - std::list list; - std::list::const_iterator i; - std::list::const_iterator i_end; - - loadList("attackPriorityMobs", PriorityAttackMob); - loadList("attackMobs", AttackMob); - loadList("ignoreAttackMobs", IgnoreAttackMob); - if (!empty) - { - mAttackMobs.push_back(""); - mAttackMobsSet.insert(""); - } - empty = false; - - loadList("pickupItems", PickupItem); - loadList("ignorePickupItems", IgnorePickupItem); - if (!empty) - { - mPickupItems.push_back(""); - mPickupItemsSet.insert(""); - } - - rebuildAttackMobs(); - rebuildPriorityAttackMobs(); - rebuildPickupItems(); -} - -void ActorSpriteManager::storeAttackList() const -{ - serverConfig.setValue("attackPriorityMobs", packList(mPriorityAttackMobs)); - serverConfig.setValue("attackMobs", packList(mAttackMobs)); - serverConfig.setValue("ignoreAttackMobs", packList(mIgnoreAttackMobs)); - - serverConfig.setValue("pickupItems", packList(mPickupItems)); - serverConfig.setValue("ignorePickupItems", packList(mIgnorePickupItems)); -} - -bool ActorSpriteManager::checkForPickup(const FloorItem *const item) const -{ - if (mPickupItemsSet.find("") != mPickupItemsSet.end()) - { - if (mIgnorePickupItemsSet.find(item->getName()) - == mIgnorePickupItemsSet.end()) - { - return true; - } - } - else if (item && mPickupItemsSet.find(item->getName()) - != mPickupItemsSet.end()) - { - return true; - } - return false; -} - -void ActorSpriteManager::updateEffects(const std::map &addEffects, - const std::set &removeEffects) - const -{ - for_actorsm - { - if (!*it || (*it)->getType() != ActorSprite::NPC) - continue; - Being *const being = static_cast(*it); - const int type = being->getSubType(); - if (removeEffects.find(type) != removeEffects.end()) - being->removeSpecialEffect(); - const std::map::const_iterator idAdd = addEffects.find(type); - if (idAdd != addEffects.end()) - being->addSpecialEffect((*idAdd).second); - } -} diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h deleted file mode 100644 index ef0cf6875..000000000 --- a/src/actorspritemanager.h +++ /dev/null @@ -1,357 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2004-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011-2013 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef ACTORSPRITEMANAGER_H -#define ACTORSPRITEMANAGER_H - -#include "flooritem.h" - -#include "being/being.h" - -#include "localconsts.h" - -class LocalPlayer; -class Map; - -typedef std::set ActorSprites; -typedef ActorSprites::iterator ActorSpritesIterator; -typedef ActorSprites::const_iterator ActorSpritesConstIterator; - -class ActorSpriteManager final: public ConfigListener -{ - public: - ActorSpriteManager(); - - A_DELETE_COPY(ActorSpriteManager) - - ~ActorSpriteManager(); - - /** - * Sets the map on which ActorSprites are created. - */ - void setMap(Map *const map); - - /** - * Sets the current player. - */ - void setPlayer(LocalPlayer *const player); - - /** - * Create a Being and add it to the list of ActorSprites. - */ - Being *createBeing(const int id, const ActorSprite::Type type, - const uint16_t subtype) A_WARN_UNUSED; - - /** - * Create a FloorItem and add it to the list of ActorSprites. - */ - FloorItem *createItem(const int id, const int itemId, - const int x, const int y, - const int amount, const unsigned char color, - const int subX, const int subY); - - /** - * Destroys the given ActorSprite at the end of - * ActorSpriteManager::logic. - */ - void destroy(ActorSprite *const actor); - - void erase(ActorSprite *const actor); - - void undelete(const ActorSprite *const actor); - - /** - * Returns a specific Being, by id; - */ - Being *findBeing(const int id) const A_WARN_UNUSED; - - /** - * Returns a being at specific coordinates. - */ - Being *findBeing(const int x, const int y, const ActorSprite::Type - type = ActorSprite::UNKNOWN) const A_WARN_UNUSED; - - /** - * Returns a being at the specific pixel. - */ - Being *findBeingByPixel(const int x, const int y, - const bool allPlayers = false) - const A_WARN_UNUSED; - - /** - * Returns a beings at the specific pixel. - */ - void findBeingsByPixel(std::vector &beings, - const int x, const int y, - const bool allPlayers) const; - - /** - * Returns a portal at the specific tile. - */ - Being *findPortalByTile(const int x, const int y) const A_WARN_UNUSED; - - /** - * Returns a specific FloorItem, by id. - */ - FloorItem *findItem(const int id) const A_WARN_UNUSED; - - /** - * Returns a FloorItem at specific coordinates. - */ - FloorItem *findItem(const int x, const int y) const A_WARN_UNUSED; - - /** - * Returns a being nearest to specific coordinates. - * - * @param x X coordinate in pixels. - * @param y Y coordinate in pixels. - * @param maxTileDist Maximal distance in tiles. If minimal distance is - * larger, no being is returned. - * @param type The type of being to look for. - */ - Being *findNearestLivingBeing(const int x, const int y, - int maxTileDist, - const ActorSprite::Type - type = Being::UNKNOWN, - const Being *const - excluded = nullptr) const A_WARN_UNUSED; - - /** - * Returns a being nearest to another being. - * - * @param aroundBeing The being to search around. - * @param maxTileDist Maximal distance in tiles. If minimal distance is - * larger, no being is returned. - * @param type The type of being to look for. - */ - Being *findNearestLivingBeing(const Being *const aroundBeing, - const int maxTileDist, - const ActorSprite::Type - type = Being::UNKNOWN) - const A_WARN_UNUSED; - - /** - * Finds a being by name and (optionally) by type. - */ - Being *findBeingByName(const std::string &name, - const ActorSprite::Type - type = Being::UNKNOWN) const A_WARN_UNUSED; - - /** - * Finds a nearest being by name and (optionally) by type. - */ - Being *findNearestByName(const std::string &name, - const Being::Type &type = Being::UNKNOWN) - const A_WARN_UNUSED; - - /** - * Heal all players in distance. - * - * \param maxdist maximal distance. If minimal distance is larger, - * no being is returned - */ -// void HealAllTargets(Being *aroundBeing, int maxdist, -// Being::Type type) const; - - void healTarget() const; - - void heal(const Being *const target) const; - - void itenplz() const; - - /** - * Returns the whole list of beings. - */ - const ActorSprites &getAll() const; - - /** - * Returns true if the given ActorSprite is in the manager's list, - * false otherwise. - * - * \param actor the ActorSprite to search for - */ - bool hasActorSprite(const ActorSprite *const actor) - const A_WARN_UNUSED; - - /** - * Performs ActorSprite logic and deletes ActorSprite scheduled to be - * deleted. - */ - void logic(); - - /** - * Destroys all ActorSprites except the local player - */ - void clear(); - - void addBlock(const uint32_t id); - - void deleteBlock(const uint32_t id); - - bool isBlocked(const uint32_t id) const; - - void printAllToChat() const; - - void printBeingsToChat(const ActorSprites &beings, - const std::string &header) const; - - void printBeingsToChat(const std::vector &beings, - const std::string &header) const; - - void getPlayerNames(StringVect &names, - const bool npcNames) const; - - void getMobNames(StringVect &names) const; - - void updatePlayerNames() const; - - void updatePlayerColors() const; - - void updatePlayerGuild() const; - - void parseLevels(std::string levels) const; - - bool pickUpAll(const int x1, const int y1, const int x2, const int y2, - const bool serverBuggy = false); - - bool pickUpNearest(const int x, const int y, int maxdist) const; - - void optionChanged(const std::string &name) override; - - void removeAttackMob(const std::string &name); - - void removePickupItem(const std::string &name); - - void addPriorityAttackMob(const std::string &name); - - void addAttackMob(const std::string &name); - - void addIgnoreAttackMob(const std::string &name); - - void addPickupItem(const std::string &name); - - void addIgnorePickupItem(const std::string &name); - - void setPriorityAttackMobs(std::list mobs) - { mPriorityAttackMobs = mobs; } - - void setAttackMobs(std::list mobs) - { mAttackMobs = mobs; } - - int getPriorityAttackMobsSize() const A_WARN_UNUSED - { return static_cast(mPriorityAttackMobs.size()); } - - int getAttackMobsSize() const A_WARN_UNUSED - { return static_cast(mAttackMobs.size()); } - - int getPickupItemsSize() const A_WARN_UNUSED - { return static_cast(mPickupItems.size()); } - -#define defList(list1, mob) \ - bool isIn##list1##List(const std::string &name) const A_WARN_UNUSED\ - { return m##list1##mob##Set.find(name) != m##list1##mob##Set.end(); }\ - void rebuild##list1##mob();\ - std::set get##list1##mob##Set() const A_WARN_UNUSED\ - { return m##list1##mob##Set; }\ - std::list get##list1##mob() const A_WARN_UNUSED\ - { return m##list1##mob; } - - defList(Attack, Mobs) - defList(PriorityAttack, Mobs) - defList(IgnoreAttack, Mobs) - defList(Pickup, Items) - defList(IgnorePickup, Items) - - const std::map &getAttackMobsMap() - const A_WARN_UNUSED - { return mAttackMobsMap; } - - const std::map &getPriorityAttackMobsMap() - const A_WARN_UNUSED - { return mPriorityAttackMobsMap; } - - int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED; - - int getPriorityAttackMobIndex(const std::string &name) - const A_WARN_UNUSED; - - int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED; - - int getIndexByName(const std::string &name, const std::map &map) const A_WARN_UNUSED; - - bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED; - - void updateEffects(const std::map &addEffects, - const std::set &removeEffects) const; - - protected: - bool validateBeing(const Being *const aroundBeing, - Being *const being, - const Being::Type &type, - const Being *const excluded = nullptr, - const int maxCost = 20) const A_WARN_UNUSED; - - Being *findNearestLivingBeing(const Being *const aroundBeing, - const int maxdist, - const Being::Type &type, - const int x, const int y, - const Being *const - excluded = nullptr) const A_WARN_UNUSED; - - void loadAttackList(); - void storeAttackList() const; - - ActorSprites mActors; - ActorSprites mDeleteActors; - std::set mBlockedBeings; - Map *mMap; - std::string mSpellHeal1; - std::string mSpellHeal2; - std::string mSpellItenplz; - bool mTargetDeadPlayers; - bool mTargetOnlyReachable; - bool mCyclePlayers; - bool mCycleMonsters; - bool mCycleNPC; - bool mExtMouseTargeting; - -#define defVarsP(mob) \ - std::list mPriority##mob;\ - std::set mPriority##mob##Set;\ - std::map mPriority##mob##Map; - -#define defVars(mob) \ - std::list m##mob;\ - std::set m##mob##Set;\ - std::map m##mob##Map;\ - std::list mIgnore##mob;\ - std::set mIgnore##mob##Set; - - defVarsP(AttackMobs) - defVars(AttackMobs) - defVars(PickupItems) -}; - -extern ActorSpriteManager *actorSpriteManager; - -#endif // ACTORSPRITEMANAGER_H diff --git a/src/being/being.cpp b/src/being/being.cpp index 556341062..fdd706bbe 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -22,7 +22,7 @@ #include "being/being.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "animatedsprite.h" #include "beingequipbackend.h" #include "client.h" @@ -1572,8 +1572,8 @@ void Being::logic() && static_cast ((static_cast(get_elapsed_time(mActionTime)) / mSpeed)) >= frameCount) { - if (mType != PLAYER && actorSpriteManager) - actorSpriteManager->destroy(this); + if (mType != PLAYER && actorManager) + actorManager->destroy(this); } const SoundInfo *const sound = mNextSound.sound; @@ -2991,11 +2991,11 @@ void Being::addEffect(const std::string &name) void Being::addPet(const int id) { - if (!actorSpriteManager) + if (!actorManager) return; removePet(); - Being *const being = actorSpriteManager->createBeing( + Being *const being = actorManager->createBeing( id, ActorSprite::PET, 0); if (being) { @@ -3008,14 +3008,14 @@ void Being::addPet(const int id) void Being::removePet() { - if (!actorSpriteManager) + if (!actorManager) return; mPetId = 0; if (mPet) { mPet->setOwner(nullptr); - actorSpriteManager->destroy(mPet); + actorManager->destroy(mPet); mPet = nullptr; } } diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index 4bff1320e..6df48dec7 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -22,7 +22,7 @@ #include "being/localplayer.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "dropshortcut.h" @@ -902,7 +902,7 @@ bool LocalPlayer::pickUp(FloorItem *const item) if (dx * dx + dy * dy < dist) { - if (actorSpriteManager && actorSpriteManager->checkForPickup(item)) + if (actorManager && actorManager->checkForPickup(item)) { PlayerInfo::pickUpItem(item, true); mPickUpTarget = nullptr; @@ -1354,9 +1354,9 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, const int amount, { if (fail) { - if (actorSpriteManager && floorItemId) + if (actorManager && floorItemId) { - FloorItem *const item = actorSpriteManager->findItem(floorItemId); + FloorItem *const item = actorManager->findItem(floorItemId); if (item) { if (!item->getShowMsg()) @@ -3068,7 +3068,7 @@ bool LocalPlayer::isReachable(const int x, const int y, bool LocalPlayer::pickUpItems(int pickUpType) { - if (!actorSpriteManager) + if (!actorManager) return false; bool status = false; @@ -3077,7 +3077,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) // first pick up item on player position FloorItem *item = - actorSpriteManager->findItem(x, y); + actorManager->findItem(x, y); if (item) status = pickUp(item); @@ -3099,7 +3099,7 @@ bool LocalPlayer::pickUpItems(int pickUpType) case RIGHT: ++x; break; default: break; } - item = actorSpriteManager->findItem(x, y); + item = actorManager->findItem(x, y); if (item) status = pickUp(item); break; @@ -3112,18 +3112,18 @@ bool LocalPlayer::pickUpItems(int pickUpType) case RIGHT: x1 = x; y1 = y - 1; x2 = x + 1; y2 = y + 1; break; default: x1 = x; x2 = x; y1 = y; y2 = y; break; } - if (actorSpriteManager->pickUpAll(x1, y1, x2, y2)) + if (actorManager->pickUpAll(x1, y1, x2, y2)) status = true; break; case 3: - if (actorSpriteManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) + if (actorManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) status = true; break; case 4: - if (!actorSpriteManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) + if (!actorManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) { - if (actorSpriteManager->pickUpNearest(x, y, 4)) + if (actorManager->pickUpNearest(x, y, 4)) status = true; } else @@ -3133,9 +3133,9 @@ bool LocalPlayer::pickUpItems(int pickUpType) break; case 5: - if (!actorSpriteManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) + if (!actorManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) { - if (actorSpriteManager->pickUpNearest(x, y, 8)) + if (actorManager->pickUpNearest(x, y, 8)) status = true; } else @@ -3145,9 +3145,9 @@ bool LocalPlayer::pickUpItems(int pickUpType) break; case 6: - if (!actorSpriteManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) + if (!actorManager->pickUpAll(x - 1, y - 1, x + 1, y + 1)) { - if (actorSpriteManager->pickUpNearest(x, y, 90)) + if (actorManager->pickUpNearest(x, y, 90)) status = true; } else @@ -3701,13 +3701,13 @@ void LocalPlayer::updateCoords() / mapTileSize; if (mNavigateId) { - if (!actorSpriteManager) + if (!actorManager) { navigateClean(); return; } - const Being *const being = actorSpriteManager + const Being *const being = actorManager ->findBeing(mNavigateId); if (!being) { @@ -4052,9 +4052,9 @@ void LocalPlayer::followMoveTo(const Being *const being, case 3: if (!mTarget || mTarget->getName() != mPlayerFollowed) { - if (actorSpriteManager) + if (actorManager) { - Being *const b = actorSpriteManager->findBeingByName( + Being *const b = actorManager->findBeingByName( mPlayerFollowed, Being::PLAYER); setTarget(b); } diff --git a/src/being/playerrelations.cpp b/src/being/playerrelations.cpp index fc4889951..b06539ea0 100644 --- a/src/being/playerrelations.cpp +++ b/src/being/playerrelations.cpp @@ -22,7 +22,7 @@ #include "being/playerrelations.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "being/localplayer.h" @@ -244,9 +244,9 @@ void PlayerRelationsManager::signalUpdate(const std::string &name) FOR_EACH (PlayerRelationListenersCIter, it, mListeners) (*it)->updatedPlayer(name); - if (actorSpriteManager) + if (actorManager) { - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being && being->getType() == Being::PLAYER) @@ -306,7 +306,7 @@ bool PlayerRelationsManager::hasPermission(const Being *const being, bool PlayerRelationsManager::hasPermission(const std::string &name, const unsigned int flags) const { - if (!actorSpriteManager) + if (!actorManager) return false; const unsigned int rejections = flags @@ -318,7 +318,7 @@ bool PlayerRelationsManager::hasPermission(const std::string &name, // execute `ignore' strategy, if possible if (mIgnoreStrategy) { - Being *const b = actorSpriteManager->findBeingByName( + Being *const b = actorManager->findBeingByName( name, ActorSprite::PLAYER); if (b && b->getType() == ActorSprite::PLAYER) diff --git a/src/commands.cpp b/src/commands.cpp index 3dd4175eb..36ea69a0c 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -23,7 +23,7 @@ #include "commands.h" #include "auctionmanager.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "game.h" @@ -622,8 +622,8 @@ impHandler0(quit) impHandler0(showAll) { - if (actorSpriteManager) - actorSpriteManager->printAllToChat(); + if (actorManager) + actorManager->printAllToChat(); } impHandler1(move) @@ -651,20 +651,20 @@ impHandler1(navigate) impHandler1(target) { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; - Being *const target = actorSpriteManager->findNearestByName(args); + Being *const target = actorManager->findNearestByName(args); if (target) player_node->setTarget(target); } impHandler0(attackHuman) { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; - Being *const target = actorSpriteManager->findNearestLivingBeing( + Being *const target = actorManager->findNearestLivingBeing( player_node, 10, ActorSprite::PLAYER); if (target) { @@ -763,19 +763,19 @@ impHandler(imitation) impHandler1(heal) { - if (!actorSpriteManager) + if (!actorManager) return; if (!args.empty()) { - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( args, Being::PLAYER); if (being) - actorSpriteManager->heal(being); + actorManager->heal(being); } else { - actorSpriteManager->heal(player_node); + actorManager->heal(player_node); } } @@ -809,20 +809,20 @@ impHandler0(disconnect) impHandler1(undress) { - if (!actorSpriteManager) + if (!actorManager) return; - Being *const target = actorSpriteManager->findNearestByName(args); + Being *const target = actorManager->findNearestByName(args); if (target) Net::getBeingHandler()->undress(target); } impHandler1(attack) { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; - Being *const target = actorSpriteManager->findNearestByName(args); + Being *const target = actorManager->findNearestByName(args); if (target) player_node->setTarget(target); player_node->attack2(player_node->getTarget(), true); @@ -830,10 +830,10 @@ impHandler1(attack) impHandler1(trade) { - if (!actorSpriteManager) + if (!actorManager) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( args, Being::PLAYER); if (being) { @@ -954,14 +954,14 @@ impHandler0(uptime) impHandler1(addPriorityAttack) { - if (!actorSpriteManager - || actorSpriteManager->isInPriorityAttackList(args)) + if (!actorManager + || actorManager->isInPriorityAttackList(args)) { return; } - actorSpriteManager->removeAttackMob(args); - actorSpriteManager->addPriorityAttackMob(args); + actorManager->removeAttackMob(args); + actorManager->addPriorityAttackMob(args); if (socialWindow) socialWindow->updateAttackFilter(); @@ -969,11 +969,11 @@ impHandler1(addPriorityAttack) impHandler1(addAttack) { - if (!actorSpriteManager || actorSpriteManager->isInAttackList(args)) + if (!actorManager || actorManager->isInAttackList(args)) return; - actorSpriteManager->removeAttackMob(args); - actorSpriteManager->addAttackMob(args); + actorManager->removeAttackMob(args); + actorManager->addAttackMob(args); if (socialWindow) socialWindow->updateAttackFilter(); @@ -981,13 +981,13 @@ impHandler1(addAttack) impHandler1(removeAttack) { - if (!actorSpriteManager || args.empty() - || !actorSpriteManager->isInAttackList(args)) + if (!actorManager || args.empty() + || !actorManager->isInAttackList(args)) { return; } - actorSpriteManager->removeAttackMob(args); + actorManager->removeAttackMob(args); if (socialWindow) socialWindow->updateAttackFilter(); @@ -995,11 +995,11 @@ impHandler1(removeAttack) impHandler1(addIgnoreAttack) { - if (!actorSpriteManager || actorSpriteManager->isInIgnoreAttackList(args)) + if (!actorManager || actorManager->isInIgnoreAttackList(args)) return; - actorSpriteManager->removeAttackMob(args); - actorSpriteManager->addIgnoreAttackMob(args); + actorManager->removeAttackMob(args); + actorManager->addIgnoreAttackMob(args); if (socialWindow) socialWindow->updateAttackFilter(); @@ -1395,7 +1395,7 @@ impHandler0(dumpOGL) void replaceVars(std::string &str) { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; if (str.find("") != std::string::npos) @@ -1403,7 +1403,7 @@ void replaceVars(std::string &str) const Being *target = player_node->getTarget(); if (!target || target->getType() != ActorSprite::PLAYER) { - target = actorSpriteManager->findNearestLivingBeing( + target = actorManager->findNearestLivingBeing( player_node, 20, ActorSprite::PLAYER); } if (target) @@ -1416,7 +1416,7 @@ void replaceVars(std::string &str) const Being *target = player_node->getTarget(); if (!target || target->getType() != ActorSprite::MONSTER) { - target = actorSpriteManager->findNearestLivingBeing( + target = actorManager->findNearestLivingBeing( player_node, 20, ActorSprite::MONSTER); } if (target) @@ -1428,7 +1428,7 @@ void replaceVars(std::string &str) { StringVect names; std::string newStr; - actorSpriteManager->getPlayerNames(names, false); + actorManager->getPlayerNames(names, false); FOR_EACH (StringVectCIter, it, names) { if (*it != player_node->getName()) diff --git a/src/game.cpp b/src/game.cpp index 262d1bb69..9b6b5a339 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -24,7 +24,7 @@ #include "main.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "auctionmanager.h" #include "animatedsprite.h" #include "client.h" @@ -150,7 +150,7 @@ SocialWindow *socialWindow = nullptr; QuestsWindow *questsWindow = nullptr; WindowMenu *windowMenu = nullptr; -ActorSpriteManager *actorSpriteManager = nullptr; +ActorManager *actorManager = nullptr; CommandHandler *commandHandler = nullptr; #ifdef USE_MUMBLE MumbleManager *mumbleManager = nullptr; @@ -176,7 +176,7 @@ const unsigned adjustDelay = 10; */ static void initEngines() { - actorSpriteManager = new ActorSpriteManager; + actorManager = new ActorManager; commandHandler = new CommandHandler; effectManager = new EffectManager; AuctionManager::init(); @@ -441,8 +441,8 @@ Game::Game(): initEngines(); // Initialize beings - if (actorSpriteManager) - actorSpriteManager->setPlayer(player_node); + if (actorManager) + actorManager->setPlayer(player_node); Net::getGameHandler()->ping(tick_time); @@ -467,7 +467,7 @@ Game::~Game() AnimatedSprite::setEnableCache(false); - del_0(actorSpriteManager) + del_0(actorManager) if (client->getState() != STATE_CHANGE_MAP) del_0(player_node) del_0(commandHandler) @@ -578,8 +578,8 @@ void Game::logic() // Handle all necessary game logic ActorSprite::actorLogic(); - if (actorSpriteManager) - actorSpriteManager->logic(); + if (actorManager) + actorManager->logic(); if (particleEngine) particleEngine->update(); if (mCurrentMap) @@ -955,8 +955,8 @@ void Game::changeMap(const std::string &mapPath) viewport->clearPopup(); // Clean up floor items, beings and particles - if (actorSpriteManager) - actorSpriteManager->clear(); + if (actorManager) + actorManager->clear(); // Close the popup menu on map change so that invalid options can't be // executed. @@ -996,11 +996,11 @@ void Game::changeMap(const std::string &mapPath) if (socialWindow) socialWindow->setMap(newMap); - // Notify the minimap and actorSpriteManager about the map change + // Notify the minimap and actorManager about the map change if (minimap) minimap->setMap(newMap); - if (actorSpriteManager) - actorSpriteManager->setMap(newMap); + if (actorManager) + actorManager->setMap(newMap); if (particleEngine) particleEngine->setMap(newMap); if (viewport) diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp index 67310deef..4f6bb3372 100644 --- a/src/gui/popups/popupmenu.cpp +++ b/src/gui/popups/popupmenu.cpp @@ -22,7 +22,7 @@ #include "gui/popups/popupmenu.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "commandhandler.h" #include "configuration.h" #include "dropshortcut.h" @@ -129,7 +129,7 @@ void PopupMenu::postInit() void PopupMenu::showPopup(const int x, const int y, const Being *const being) { - if (!being || !player_node || !actorSpriteManager) + if (!being || !player_node || !actorManager) return; mBeingId = being->getId(); @@ -260,9 +260,9 @@ void PopupMenu::showPopup(const int x, const int y, const Being *const being) if (config.getBoolValue("enableAttackFilter")) { mBrowserBox->addRow("##3---"); - if (actorSpriteManager->isInAttackList(name) - || actorSpriteManager->isInIgnoreAttackList(name) - || actorSpriteManager->isInPriorityAttackList(name)) + if (actorManager->isInAttackList(name) + || actorManager->isInIgnoreAttackList(name) + || actorManager->isInPriorityAttackList(name)) { mBrowserBox->addRow("remove attack", // TRANSLATORS: remove monster from attack list @@ -460,9 +460,9 @@ void PopupMenu::showPopup(const int x, const int y, if (config.getBoolValue("enablePickupFilter")) { - if (actorSpriteManager->isInPickupList(name) - || (actorSpriteManager->isInPickupList("") - && !actorSpriteManager->isInIgnorePickupList(name))) + if (actorManager->isInPickupList(name) + || (actorManager->isInPickupList("") + && !actorManager->isInIgnorePickupList(name))) { // TRANSLATORS: popup menu item // TRANSLATORS: pickup item from ground @@ -602,7 +602,7 @@ void PopupMenu::showSpellPopup(const int x, const int y, void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) { - if (!tab || !actorSpriteManager || !player_node) + if (!tab || !actorManager || !player_node) return; mTab = tab; @@ -677,7 +677,7 @@ void PopupMenu::showChatPopup(const int x, const int y, ChatTab *const tab) const WhisperTab *const wTab = static_cast(tab); std::string name = wTab->getNick(); - const Being* const being = actorSpriteManager->findBeingByName( + const Being* const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) @@ -843,8 +843,8 @@ void PopupMenu::handleLink(const std::string &link, gcn::MouseEvent *event A_UNUSED) { Being *being = nullptr; - if (actorSpriteManager) - being = actorSpriteManager->findBeing(mBeingId); + if (actorManager) + being = actorManager->findBeing(mBeingId); // Talk To action if (link == "talk" && being && being->canTalk()) @@ -889,8 +889,8 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "heal" && being && being->getType() != Being::MONSTER) { - if (actorSpriteManager) - actorSpriteManager->heal(being); + if (actorManager) + actorManager->heal(being); } else if (link == "unignore" && being && being->getType() == ActorSprite::PLAYER) @@ -979,11 +979,11 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "nuke" && being) { - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->addBlock(static_cast( + actorManager->addBlock(static_cast( being->getId())); - actorSpriteManager->destroy(being); + actorManager->destroy(being); } } // Follow Player action @@ -1000,9 +1000,9 @@ void PopupMenu::handleLink(const std::string &link, // Pick Up Floor Item action else if ((link == "pickup") && mFloorItemId) { - if (player_node && actorSpriteManager) + if (player_node && actorManager) { - FloorItem *const item = actorSpriteManager->findItem( + FloorItem *const item = actorManager->findItem( mFloorItemId); if (item) player_node->pickUp(item); @@ -1044,9 +1044,9 @@ void PopupMenu::handleLink(const std::string &link, chatWindow->addItemText(mItem->getInfo().getName()); } } - else if (mFloorItemId && actorSpriteManager) + else if (mFloorItemId && actorManager) { - const FloorItem *const item = actorSpriteManager->findItem( + const FloorItem *const item = actorManager->findItem( mFloorItemId); if (item) @@ -1427,76 +1427,76 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "remove attack" && being) { - if (actorSpriteManager && being->getType() == Being::MONSTER) + if (actorManager && being->getType() == Being::MONSTER) { - actorSpriteManager->removeAttackMob(being->getName()); + actorManager->removeAttackMob(being->getName()); if (socialWindow) socialWindow->updateAttackFilter(); } } else if (link == "add attack" && being) { - if (actorSpriteManager && being->getType() == Being::MONSTER) + if (actorManager && being->getType() == Being::MONSTER) { - actorSpriteManager->addAttackMob(being->getName()); + actorManager->addAttackMob(being->getName()); if (socialWindow) socialWindow->updateAttackFilter(); } } else if (link == "add attack priority" && being) { - if (actorSpriteManager && being->getType() == Being::MONSTER) + if (actorManager && being->getType() == Being::MONSTER) { - actorSpriteManager->addPriorityAttackMob(being->getName()); + actorManager->addPriorityAttackMob(being->getName()); if (socialWindow) socialWindow->updateAttackFilter(); } } else if (link == "add attack ignore" && being) { - if (actorSpriteManager && being->getType() == Being::MONSTER) + if (actorManager && being->getType() == Being::MONSTER) { - actorSpriteManager->addIgnoreAttackMob(being->getName()); + actorManager->addIgnoreAttackMob(being->getName()); if (socialWindow) socialWindow->updateAttackFilter(); } } else if (link == "remove pickup" && !mNick.empty()) { - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->removePickupItem(mNick); + actorManager->removePickupItem(mNick); if (socialWindow) socialWindow->updatePickupFilter(); } } else if (link == "add pickup" && !mNick.empty()) { - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->addPickupItem(mNick); + actorManager->addPickupItem(mNick); if (socialWindow) socialWindow->updatePickupFilter(); } } else if (link == "add pickup ignore" && !mNick.empty()) { - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->addIgnorePickupItem(mNick); + actorManager->addIgnorePickupItem(mNick); if (socialWindow) socialWindow->updatePickupFilter(); } } else if (link == "attack moveup") { - if (actorSpriteManager) + if (actorManager) { - const int idx = actorSpriteManager->getAttackMobIndex(mNick); + const int idx = actorManager->getAttackMobIndex(mNick); if (idx > 0) { std::list mobs - = actorSpriteManager->getAttackMobs(); + = actorManager->getAttackMobs(); std::list::iterator it = mobs.begin(); std::list::iterator it2 = mobs.begin(); while (it != mobs.end()) @@ -1505,8 +1505,8 @@ void PopupMenu::handleLink(const std::string &link, { -- it2; mobs.splice(it2, mobs, it); - actorSpriteManager->setAttackMobs(mobs); - actorSpriteManager->rebuildAttackMobs(); + actorManager->setAttackMobs(mobs); + actorManager->rebuildAttackMobs(); break; } ++ it; @@ -1520,14 +1520,14 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "priority moveup") { - if (actorSpriteManager) + if (actorManager) { - const int idx = actorSpriteManager-> + const int idx = actorManager-> getPriorityAttackMobIndex(mNick); if (idx > 0) { std::list mobs - = actorSpriteManager->getPriorityAttackMobs(); + = actorManager->getPriorityAttackMobs(); std::list::iterator it = mobs.begin(); std::list::iterator it2 = mobs.begin(); while (it != mobs.end()) @@ -1536,8 +1536,8 @@ void PopupMenu::handleLink(const std::string &link, { -- it2; mobs.splice(it2, mobs, it); - actorSpriteManager->setPriorityAttackMobs(mobs); - actorSpriteManager->rebuildPriorityAttackMobs(); + actorManager->setPriorityAttackMobs(mobs); + actorManager->rebuildPriorityAttackMobs(); break; } ++ it; @@ -1551,14 +1551,14 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "attack movedown") { - if (actorSpriteManager) + if (actorManager) { - const int idx = actorSpriteManager->getAttackMobIndex(mNick); - const int size = actorSpriteManager->getAttackMobsSize(); + const int idx = actorManager->getAttackMobIndex(mNick); + const int size = actorManager->getAttackMobsSize(); if (idx + 1 < size) { std::list mobs - = actorSpriteManager->getAttackMobs(); + = actorManager->getAttackMobs(); std::list::iterator it = mobs.begin(); std::list::iterator it2 = mobs.begin(); while (it != mobs.end()) @@ -1570,8 +1570,8 @@ void PopupMenu::handleLink(const std::string &link, break; mobs.splice(it, mobs, it2); - actorSpriteManager->setAttackMobs(mobs); - actorSpriteManager->rebuildAttackMobs(); + actorManager->setAttackMobs(mobs); + actorManager->rebuildAttackMobs(); break; } ++ it; @@ -1587,13 +1587,13 @@ void PopupMenu::handleLink(const std::string &link, { if (player_node) { - const int idx = actorSpriteManager + const int idx = actorManager ->getPriorityAttackMobIndex(mNick); - const int size = actorSpriteManager->getPriorityAttackMobsSize(); + const int size = actorManager->getPriorityAttackMobsSize(); if (idx + 1 < size) { std::list mobs - = actorSpriteManager->getPriorityAttackMobs(); + = actorManager->getPriorityAttackMobs(); std::list::iterator it = mobs.begin(); std::list::iterator it2 = mobs.begin(); while (it != mobs.end()) @@ -1605,8 +1605,8 @@ void PopupMenu::handleLink(const std::string &link, break; mobs.splice(it, mobs, it2); - actorSpriteManager->setPriorityAttackMobs(mobs); - actorSpriteManager->rebuildPriorityAttackMobs(); + actorManager->setPriorityAttackMobs(mobs); + actorManager->rebuildPriorityAttackMobs(); break; } ++ it; @@ -1620,24 +1620,24 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "attack remove") { - if (actorSpriteManager) + if (actorManager) { if (mNick.empty()) { - if (actorSpriteManager->isInAttackList(mNick)) + if (actorManager->isInAttackList(mNick)) { - actorSpriteManager->removeAttackMob(mNick); - actorSpriteManager->addIgnoreAttackMob(mNick); + actorManager->removeAttackMob(mNick); + actorManager->addIgnoreAttackMob(mNick); } else { - actorSpriteManager->removeAttackMob(mNick); - actorSpriteManager->addAttackMob(mNick); + actorManager->removeAttackMob(mNick); + actorManager->addAttackMob(mNick); } } else { - actorSpriteManager->removeAttackMob(mNick); + actorManager->removeAttackMob(mNick); } if (socialWindow) socialWindow->updateAttackFilter(); @@ -1645,24 +1645,24 @@ void PopupMenu::handleLink(const std::string &link, } else if (link == "pickup remove") { - if (actorSpriteManager) + if (actorManager) { if (mNick.empty()) { - if (actorSpriteManager->isInPickupList(mNick)) + if (actorManager->isInPickupList(mNick)) { - actorSpriteManager->removePickupItem(mNick); - actorSpriteManager->addIgnorePickupItem(mNick); + actorManager->removePickupItem(mNick); + actorManager->addIgnorePickupItem(mNick); } else { - actorSpriteManager->removePickupItem(mNick); - actorSpriteManager->addPickupItem(mNick); + actorManager->removePickupItem(mNick); + actorManager->addPickupItem(mNick); } } else { - actorSpriteManager->removePickupItem(mNick); + actorManager->removePickupItem(mNick); } if (socialWindow) socialWindow->updatePickupFilter(); @@ -1762,10 +1762,10 @@ void PopupMenu::handleLink(const std::string &link, } else if (!link.compare(0, 7, "player_")) { - if (actorSpriteManager) + if (actorManager) { mBeingId = atoi(link.substr(7).c_str()); - being = actorSpriteManager->findBeing(mBeingId); + being = actorManager->findBeing(mBeingId); if (being) { showPopup(getX(), getY(), being); @@ -1775,12 +1775,12 @@ void PopupMenu::handleLink(const std::string &link, } else if (!link.compare(0, 10, "flooritem_")) { - if (actorSpriteManager) + if (actorManager) { const int id = atoi(link.substr(10).c_str()); if (id) { - const FloorItem *const item = actorSpriteManager->findItem(id); + const FloorItem *const item = actorManager->findItem(id); if (item) { mFloorItemId = item->getId(); @@ -2198,7 +2198,7 @@ void PopupMenu::showPopup(const int x, const int y, const ProgressBar *const b) void PopupMenu::showAttackMonsterPopup(const int x, const int y, const std::string &name, const int type) { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; mNick = name; @@ -2221,8 +2221,8 @@ void PopupMenu::showAttackMonsterPopup(const int x, const int y, { case MapItem::ATTACK: { - const int idx = actorSpriteManager->getAttackMobIndex(name); - const int size = actorSpriteManager->getAttackMobsSize(); + const int idx = actorManager->getAttackMobIndex(name); + const int size = actorManager->getAttackMobsSize(); if (idx > 0) { // TRANSLATORS: popup menu item @@ -2239,9 +2239,9 @@ void PopupMenu::showAttackMonsterPopup(const int x, const int y, } case MapItem::PRIORITY: { - const int idx = actorSpriteManager-> + const int idx = actorManager-> getPriorityAttackMobIndex(name); - const int size = actorSpriteManager->getPriorityAttackMobsSize(); + const int size = actorManager->getPriorityAttackMobsSize(); if (idx > 0) { // TRANSLATORS: popup menu item @@ -2276,7 +2276,7 @@ void PopupMenu::showAttackMonsterPopup(const int x, const int y, void PopupMenu::showPickupItemPopup(const int x, const int y, const std::string &name) { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; mNick = name; @@ -2661,8 +2661,8 @@ void PopupMenu::addPlayerMisc() void PopupMenu::addPickupFilter(const std::string &name) { - if (actorSpriteManager->isInPickupList(name) - || actorSpriteManager->isInIgnorePickupList(name)) + if (actorManager->isInPickupList(name) + || actorManager->isInIgnorePickupList(name)) { mBrowserBox->addRow("remove pickup", // TRANSLATORS: popup menu item @@ -2896,7 +2896,7 @@ void PlayerListener::action(const gcn::ActionEvent &event) if (event.getId() == "ok" && !mNick.empty() && mDialog) { std::string comment = mDialog->getText(); - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( mNick, static_cast(mType)); if (being) being->setComment(comment); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 96f34062a..05807126f 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -22,7 +22,7 @@ #include "gui/viewport.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "game.h" #include "maplayer.h" @@ -245,7 +245,7 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) textManager->draw(graphics, mPixelViewX, mPixelViewY); // Draw player names, speech, and emotion sprite as needed - const ActorSprites &actors = actorSpriteManager->getAll(); + const ActorSprites &actors = actorManager->getAll(); FOR_EACH (ActorSpritesIterator, it, actors) { if ((*it)->getType() == ActorSprite::FLOOR_ITEM) @@ -296,7 +296,7 @@ void Viewport::_followMouse() void Viewport::_drawDebugPath(Graphics *const graphics) { - if (!player_node || !userPalette || !actorSpriteManager || !mMap) + if (!player_node || !userPalette || !actorManager || !mMap) return; SDL_GetMouseState(&mMouseX, &mMouseY); @@ -323,7 +323,7 @@ void Viewport::_drawDebugPath(Graphics *const graphics) _drawPath(graphics, debugPath, userPalette->getColorWithAlpha( UserPalette::ROAD_POINT)); - const ActorSprites &actors = actorSpriteManager->getAll(); + const ActorSprites &actors = actorManager->getAll(); FOR_EACH (ActorSpritesConstIterator, it, actors) { const Being *const being = dynamic_cast(*it); @@ -411,12 +411,12 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (mHoverBeing) { validateSpeed(); - if (actorSpriteManager) + if (actorManager) { std::vector beings; const int x = mMouseX + mPixelViewX; const int y = mMouseY + mPixelViewY; - actorSpriteManager->findBeingsByPixel(beings, x, y, true); + actorManager->findBeingsByPixel(beings, x, y, true); if (beings.size() > 1) { mPopupMenu->showPopup(eventX, eventY, beings); @@ -478,10 +478,10 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (mHoverBeing->getType() == ActorSprite::PLAYER) { validateSpeed(); - if (actorSpriteManager) + if (actorManager) { if (player_node != mHoverBeing || mSelfMouseHeal) - actorSpriteManager->heal(mHoverBeing); + actorManager->heal(mHoverBeing); if (player_node == mHoverBeing && mHoverItem) player_node->pickUp(mHoverItem); return; @@ -536,9 +536,9 @@ void Viewport::mousePressed(gcn::MouseEvent &event) mPlayerFollowMouse = false; validateSpeed(); // Find the being nearest to the clicked position - if (actorSpriteManager) + if (actorManager) { - Being *const target = actorSpriteManager->findNearestLivingBeing( + Being *const target = actorManager->findNearestLivingBeing( pixelX, pixelY, 20, ActorSprite::MONSTER); if (target) @@ -840,13 +840,13 @@ void Viewport::optionChanged(const std::string &name) void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED) { // Check if we are on the map - if (!mMap || !player_node || !actorSpriteManager) + if (!mMap || !player_node || !actorManager) return; const int x = mMouseX + mPixelViewX; const int y = mMouseY + mPixelViewY; - mHoverBeing = actorSpriteManager->findBeingByPixel(x, y, true); + mHoverBeing = actorManager->findBeingByPixel(x, y, true); if (mHoverBeing && (mHoverBeing->getType() == Being::PLAYER || mHoverBeing->getType() == Being::NPC)) { @@ -859,7 +859,7 @@ void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED) mBeingPopup->setVisible(false); } - mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(), + mHoverItem = actorManager->findItem(x / mMap->getTileWidth(), y / mMap->getTileHeight()); if (!mHoverBeing && !mHoverItem) @@ -991,10 +991,10 @@ bool Viewport::isPopupMenuVisible() const void Viewport::moveCameraToActor(const int actorId, const int x, const int y) { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; - const Actor *const actor = actorSpriteManager->findBeing(actorId); + const Actor *const actor = actorManager->findBeing(actorId); if (!actor) return; const Vector &actorPos = actor->getPosition(); diff --git a/src/gui/viewport.h b/src/gui/viewport.h index c308603c6..b47716ac2 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -279,7 +279,7 @@ class Viewport final : public WindowContainer, void clearPopup(); protected: - friend class ActorSpriteManager; + friend class ActorManager; /// Clears any matching hovers void clearHover(const ActorSprite *const actor); diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index f39fbc02d..d4eefe69c 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -21,7 +21,7 @@ #include "gui/widgets/avatarlistbox.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "graphicsvertexes.h" #include "maplayer.h" @@ -313,7 +313,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) void AvatarListBox::mousePressed(gcn::MouseEvent &event) { - if (!actorSpriteManager || !player_node || !viewport + if (!actorManager || !player_node || !viewport || !getFont()->getHeight()) { return; @@ -339,10 +339,10 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event) { if (ava->getType() == AVATAR_PLAYER) { - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( ava->getName(), Being::PLAYER); if (being) - actorSpriteManager->heal(being); + actorManager->heal(being); } else { @@ -359,7 +359,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event) const Avatar *const avatar = model->getAvatarAt(selected); if (avatar) { - const Being *const being = actorSpriteManager + const Being *const being = actorManager ->findBeingByName(avatar->getName(), Being::PLAYER); if (being) viewport->showPopup(being); diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp index 01fb873d4..c837f1cf7 100644 --- a/src/gui/widgets/tabs/setup_relations.cpp +++ b/src/gui/widgets/tabs/setup_relations.cpp @@ -22,7 +22,7 @@ #include "gui/widgets/tabs/setup_relations.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "being/localplayer.h" @@ -358,8 +358,8 @@ void Setup_Relations::apply() | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); - if (actorSpriteManager) - actorSpriteManager->updatePlayerNames(); + if (actorManager) + actorManager->updatePlayerNames(); if (player_node) player_node->setCheckNameSetting(true); diff --git a/src/gui/windows/botcheckerwindow.cpp b/src/gui/windows/botcheckerwindow.cpp index 2ce0bce25..b502dd01d 100644 --- a/src/gui/windows/botcheckerwindow.cpp +++ b/src/gui/windows/botcheckerwindow.cpp @@ -27,7 +27,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/guitable.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "being/localplayer.h" @@ -100,10 +100,10 @@ public: freeWidgets(); mPlayers.clear(); - if (actorSpriteManager && botCheckerWindow + if (actorManager && botCheckerWindow && botCheckerWindow->mEnabled) { - std::set beings = actorSpriteManager->getAll(); + std::set beings = actorManager->getAll(); FOR_EACH (ActorSprites::iterator, i, beings) { Being *const being = dynamic_cast(*i); @@ -389,9 +389,9 @@ void BotCheckerWindow::updateList() void BotCheckerWindow::reset() { - if (actorSpriteManager) + if (actorManager) { - std::set beings = actorSpriteManager->getAll(); + std::set beings = actorManager->getAll(); FOR_EACH (ActorSprites::iterator, i, beings) { Being *const being = dynamic_cast(*i); diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp index f50ea6876..2c254ad62 100644 --- a/src/gui/windows/chatwindow.cpp +++ b/src/gui/windows/chatwindow.cpp @@ -22,7 +22,7 @@ #include "gui/windows/chatwindow.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "commandhandler.h" #include "configuration.h" @@ -671,10 +671,10 @@ void ChatWindow::localChatInput(const std::string &msg) const void ChatWindow::doPresent() const { - if (!actorSpriteManager) + if (!actorManager) return; - const ActorSprites &actors = actorSpriteManager->getAll(); + const ActorSprites &actors = actorManager->getAll(); std::string response; int playercount = 0; @@ -1255,9 +1255,9 @@ void ChatWindow::autoComplete() if (!newName.empty()) needSecure = true; - if (newName.empty() && actorSpriteManager) + if (newName.empty() && actorManager) { - actorSpriteManager->getPlayerNames(nameList, true); + actorManager->getPlayerNames(nameList, true); newName = autoComplete(nameList, name); if (!newName.empty()) needSecure = true; @@ -1268,9 +1268,9 @@ void ChatWindow::autoComplete() newName = spellManager->autoComplete(name); if (newName.empty()) newName = autoComplete(name, &mCommands); - if (newName.empty() && actorSpriteManager) + if (newName.empty() && actorManager) { - actorSpriteManager->getMobNames(nameList); + actorManager->getMobNames(nameList); newName = autoComplete(nameList, name); } if (newName.empty()) @@ -1523,9 +1523,9 @@ void ChatWindow::updateOnline(std::set &onlinePlayers) const else { const std::string nick = tab->getNick(); - if (actorSpriteManager) + if (actorManager) { - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( nick, ActorSprite::PLAYER); if (being) { diff --git a/src/gui/windows/killstats.cpp b/src/gui/windows/killstats.cpp index ee265e2b9..821577d25 100644 --- a/src/gui/windows/killstats.cpp +++ b/src/gui/windows/killstats.cpp @@ -26,7 +26,7 @@ #include "gui/widgets/label.h" #include "gui/widgets/layout.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "game.h" #include "being/localplayer.h" @@ -453,7 +453,7 @@ void KillStats::jackoAlive(const int id) void KillStats::validateJacko() { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; const Map *const currentMap = Game::instance()->getCurrentMap(); @@ -468,7 +468,7 @@ void KillStats::validateJacko() && player_node->getTileY() <= 46) { const Being *const dstBeing - = actorSpriteManager->findBeingByName( + = actorManager->findBeingByName( "Jack O", Being::MONSTER); if (mIsJackoAlive && !dstBeing) { diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp index d268addf6..9ac4a9e26 100644 --- a/src/gui/windows/minimap.cpp +++ b/src/gui/windows/minimap.cpp @@ -22,7 +22,7 @@ #include "gui/windows/minimap.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "party.h" @@ -249,7 +249,7 @@ void Minimap::draw(gcn::Graphics *graphics) graphics->pushClipArea(a); - if (!actorSpriteManager) + if (!actorManager) { BLOCK_END("Minimap::draw") return; @@ -288,7 +288,7 @@ void Minimap::draw(gcn::Graphics *graphics) graph->drawImage(mMapImage, mMapOriginX, mMapOriginY); } - const ActorSprites &actors = actorSpriteManager->getAll(); + const ActorSprites &actors = actorManager->getAll(); FOR_EACH (ActorSpritesConstIterator, it, actors) { if (!(*it) || (*it)->getType() == ActorSprite::FLOOR_ITEM) diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index e8caa0722..3b5d0d772 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -22,7 +22,7 @@ #include "gui/windows/npcdialog.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "client.h" #include "inventory.h" @@ -193,9 +193,9 @@ void NpcDialog::postInit() enableVisibleSound(true); soundManager.playGuiSound(SOUND_SHOW_WINDOW); - if (actorSpriteManager) + if (actorManager) { - const Being *const being = actorSpriteManager->findBeing(mNpcId); + const Being *const being = actorManager->findBeing(mNpcId); if (being) { showAvatar(NPCDB::getAvatarFor(being->getSubType())); diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp index ce0c1a796..42a7b0bf4 100644 --- a/src/gui/windows/questswindow.cpp +++ b/src/gui/windows/questswindow.cpp @@ -20,7 +20,7 @@ #include "gui/windows/questswindow.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "effectmanager.h" @@ -509,7 +509,7 @@ void QuestsWindow::updateEffects() } } } - if (!actorSpriteManager) + if (!actorManager) return; std::set removeEffects; @@ -549,7 +549,7 @@ void QuestsWindow::updateEffects() addEffects[id] = effect->effectId; } if (!removeEffects.empty() || !addEffects.empty()) - actorSpriteManager->updateEffects(addEffects, removeEffects); + actorManager->updateEffects(addEffects, removeEffects); } void QuestsWindow::addEffect(Being *const being) diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp index aceb872fc..c4facdc02 100644 --- a/src/gui/windows/shopwindow.cpp +++ b/src/gui/windows/shopwindow.cpp @@ -37,7 +37,7 @@ #include "gui/widgets/tabs/chattab.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "auctionmanager.h" #include "client.h" #include "configuration.h" @@ -287,10 +287,10 @@ void ShopWindow::action(const gcn::ActionEvent &event) void ShopWindow::startTrade() { - if (!actorSpriteManager || !tradeWindow) + if (!actorManager || !tradeWindow) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( mTradeNick, Being::PLAYER); tradeWindow->clear(); if (mTradeMoney) @@ -694,8 +694,8 @@ void ShopWindow::processRequest(const std::string &nick, std::string data, const int mode) { if (!player_node || !mTradeNick.empty() || PlayerInfo::isTrading() - || !actorSpriteManager - || !actorSpriteManager->findBeingByName(nick, Being::PLAYER)) + || !actorManager + || !actorManager->findBeingByName(nick, Being::PLAYER)) { return; } diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp index 97f0211d8..aa9d4d328 100644 --- a/src/gui/windows/socialwindow.cpp +++ b/src/gui/windows/socialwindow.cpp @@ -21,7 +21,7 @@ #include "gui/windows/socialwindow.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "guild.h" #include "guildmanager.h" @@ -572,7 +572,7 @@ public: void updateAvatar(const std::string &name) override { - if (!actorSpriteManager) + if (!actorManager) return; Avatar *const avatar = findAvatarbyName(name); @@ -587,7 +587,7 @@ public: avatar->setHp(pm->getHp()); } } - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { @@ -600,14 +600,14 @@ public: void resetDamage(const std::string &name) override { - if (!actorSpriteManager) + if (!actorManager) return; Avatar *const avatar = findAvatarbyName(name); if (!avatar) return; avatar->setDamageHp(0); - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) @@ -642,10 +642,10 @@ public: if (!avatars) return; - if (actorSpriteManager) + if (actorManager) { StringVect names; - actorSpriteManager->getPlayerNames(names, false); + actorManager->getPlayerNames(names, false); std::vector::iterator ai = avatars->begin(); while (ai != avatars->end()) @@ -792,7 +792,7 @@ public: if (config.getBoolValue("drawHotKeys") && idx < 80 && outfitWindow) { - Being *const being = actorSpriteManager + Being *const being = actorManager ->findPortalByTile(x, y); if (being) { @@ -985,7 +985,7 @@ private: ava->setX(0);\ ava->setY(0);\ avatars->push_back(ava);\ - mobs = actorSpriteManager->get##mob##s();\ + mobs = actorManager->get##mob##s();\ i = mobs.begin();\ i_end = mobs.end();\ while (i != i_end)\ @@ -1013,7 +1013,7 @@ private: } #define updateAtkListStart() \ - if (!socialWindow || !player_node || !actorSpriteManager)\ + if (!socialWindow || !player_node || !actorManager)\ return;\ std::vector *const avatars = mBeings->getMembers();\ std::vector::iterator ia = avatars->begin();\ @@ -1160,7 +1160,7 @@ public: void getPlayersAvatars() { - if (!actorSpriteManager) + if (!actorManager) return; std::vector *const avatars = mBeings->getMembers(); @@ -1189,7 +1189,7 @@ public: FOR_EACHP (StringVectCIter, it, players) { Avatar *const ava = new Avatar(*it); - if (actorSpriteManager->findBeingByName(*it, Being::PLAYER) + if (actorManager->findBeingByName(*it, Being::PLAYER) || players2.find(*it) != players2.end()) { ava->setOnline(true); diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp index e97ae3095..c4f096c72 100644 --- a/src/gui/windows/whoisonline.cpp +++ b/src/gui/windows/whoisonline.cpp @@ -34,7 +34,7 @@ #include "gui/widgets/browserbox.h" #include "gui/widgets/scrollarea.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "main.h" @@ -183,10 +183,10 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event) if (viewport) { - if (actorSpriteManager) + if (actorManager) { const std::string text = decodeLinkText(link); - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( text, Being::PLAYER); if (being && viewport) @@ -408,9 +408,9 @@ void WhoIsOnline::loadWebList() if (!lineStr.empty()) level = atoi(lineStr.c_str()); - if (actorSpriteManager) + if (actorManager) { - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( nick, Being::PLAYER); if (being) { @@ -762,7 +762,7 @@ void WhoIsOnline::setNeutralColor(OnlinePlayer *const player) if (!player) return; - if (actorSpriteManager && player_node) + if (actorManager && player_node) { const std::string &nick = player->getNick(); if (nick == player_node->getName()) @@ -783,7 +783,7 @@ void WhoIsOnline::setNeutralColor(OnlinePlayer *const player) } } - const Being *const being = actorSpriteManager->findBeingByName(nick); + const Being *const being = actorManager->findBeingByName(nick); if (being) { const Guild *const guild2 = player_node->getGuild(); @@ -827,9 +827,9 @@ void OnlinePlayer::setText(std::string color) { mText.clear(); - if (mStatus != 255 && actorSpriteManager) + if (mStatus != 255 && actorManager) { - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( mNick, Being::PLAYER); if (being) { diff --git a/src/guild.cpp b/src/guild.cpp index 6b0e5ec2d..f53739e2f 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -22,7 +22,7 @@ #include "guild.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "utils/stringutils.h" @@ -233,7 +233,7 @@ void Guild::removeMember(const std::string &name) void Guild::removeFromMembers() { - if (!actorSpriteManager) + if (!actorManager) return; MemberList::const_iterator itr = mMembers.begin(); @@ -242,7 +242,7 @@ void Guild::removeFromMembers() { if (*itr) { - Being *const b = actorSpriteManager->findBeing((*itr)->getID()); + Being *const b = actorManager->findBeing((*itr)->getID()); if (b) b->removeGuild(mId); } diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 4917ab68e..1eae0b0eb 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -20,7 +20,7 @@ #include "guildmanager.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "guild.h" @@ -208,10 +208,10 @@ void GuildManager::updateList() } guild->sort(); createTab(guild); - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->updatePlayerGuild(); - actorSpriteManager->updatePlayerColors(); + actorManager->updatePlayerGuild(); + actorManager->updatePlayerColors(); } if (socialWindow) socialWindow->updateGuildCounter(); @@ -405,9 +405,9 @@ bool GuildManager::process(std::string msg) if (msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); - if (actorSpriteManager) + if (actorManager) { - Being *const b = actorSpriteManager->findBeingByName( + Being *const b = actorManager->findBeingByName( msg, Being::PLAYER); if (b) @@ -523,10 +523,10 @@ bool GuildManager::afterRemove() if (socialWindow) socialWindow->removeTab(guild); - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->updatePlayerGuild(); - actorSpriteManager->updatePlayerColors(); + actorManager->updatePlayerGuild(); + actorManager->updatePlayerColors(); } reload(); return true; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 4e08f5466..4938ea525 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -24,7 +24,7 @@ #include "net/ea/eaprotocol.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "configuration.h" #include "effectmanager.h" @@ -64,7 +64,7 @@ BeingHandler::BeingHandler(const bool enableSync) : Being *BeingHandler::createBeing(const int id, const int16_t job) const { - if (!actorSpriteManager) + if (!actorManager) return nullptr; ActorSprite::Type type = ActorSprite::UNKNOWN; @@ -77,7 +77,7 @@ Being *BeingHandler::createBeing(const int id, const int16_t job) const else if (job == 45) type = ActorSprite::PORTAL; - Being *const being = actorSpriteManager->createBeing(id, type, job); + Being *const being = actorManager->createBeing(id, type, job); if (type == ActorSprite::PLAYER || type == ActorSprite::NPC) { @@ -115,7 +115,7 @@ void BeingHandler::setSprite(Being *const being, const unsigned int slot, void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, const bool visible) { - if (!actorSpriteManager) + if (!actorManager) return; int spawnId; @@ -136,13 +136,13 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, if (id == player_node->getId() && job >= 1000) disguiseId = job; - Being *dstBeing = actorSpriteManager->findBeing(id); + Being *dstBeing = actorManager->findBeing(id); if (dstBeing && dstBeing->getType() == Being::MONSTER && !dstBeing->isAlive()) { - actorSpriteManager->destroy(dstBeing); - actorSpriteManager->erase(dstBeing); + actorManager->destroy(dstBeing); + actorManager->erase(dstBeing); dstBeing = nullptr; } @@ -153,7 +153,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, if (job == 0 && id >= 110000000) return; - if (actorSpriteManager->isBlocked(id) == true) + if (actorManager->isBlocked(id) == true) return; dstBeing = createBeing(id, job); @@ -168,7 +168,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, { if (dstBeing->getType() == Being::NPC) { - actorSpriteManager->undelete(dstBeing); + actorManager->undelete(dstBeing); if (serverVersion < 1) requestNameById(id); } @@ -341,7 +341,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, void BeingHandler::processBeingMove2(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; /* @@ -349,7 +349,7 @@ void BeingHandler::processBeingMove2(Net::MessageIn &msg) const * later versions of eAthena for both mobs and * players */ - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); /* * This packet doesn't have enough info to actually @@ -384,13 +384,13 @@ void BeingHandler::processBeingSpawn(Net::MessageIn &msg) void BeingHandler::processBeingRemove(Net::MessageIn &msg) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; // A being should be removed or has died const int id = msg.readInt32(); - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -420,19 +420,19 @@ void BeingHandler::processBeingRemove(Net::MessageIn &msg) const if (socialWindow) socialWindow->updateActiveList(); } - actorSpriteManager->destroy(dstBeing); + actorManager->destroy(dstBeing); } } void BeingHandler::processBeingResurrect(Net::MessageIn &msg) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; // A being changed mortality status const int id = msg.readInt32(); - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -447,12 +447,12 @@ void BeingHandler::processBeingResurrect(Net::MessageIn &msg) const void BeingHandler::processSkillDamage(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; const int id = msg.readInt16(); // Skill Id - Being *const srcBeing = actorSpriteManager->findBeing(msg.readInt32()); - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const srcBeing = actorManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); msg.readInt32(); // Server tick msg.readInt32(); // src speed msg.readInt32(); // dst speed @@ -468,11 +468,11 @@ void BeingHandler::processSkillDamage(Net::MessageIn &msg) const void BeingHandler::processBeingAction(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; - Being *const srcBeing = actorSpriteManager->findBeing(msg.readInt32()); - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const srcBeing = actorManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); msg.readInt32(); // server tick const int srcSpeed = msg.readInt32(); // src speed @@ -549,11 +549,11 @@ void BeingHandler::processBeingAction(Net::MessageIn &msg) const void BeingHandler::processBeingSelfEffect(Net::MessageIn &msg) const { - if (!effectManager || !actorSpriteManager) + if (!effectManager || !actorManager) return; const int id = static_cast(msg.readInt32()); - Being *const being = actorSpriteManager->findBeing(id); + Being *const being = actorManager->findBeing(id); if (!being) return; @@ -572,10 +572,10 @@ void BeingHandler::processBeingSelfEffect(Net::MessageIn &msg) const void BeingHandler::processBeingEmotion(Net::MessageIn &msg) const { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (!dstBeing) return; @@ -594,11 +594,11 @@ void BeingHandler::processBeingEmotion(Net::MessageIn &msg) const void BeingHandler::processNameResponse(Net::MessageIn &msg) const { - if (!player_node || !actorSpriteManager) + if (!player_node || !actorManager) return; const int beingId = msg.readInt32(); - Being *const dstBeing = actorSpriteManager->findBeing(beingId); + Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) { @@ -634,20 +634,20 @@ void BeingHandler::processNameResponse(Net::MessageIn &msg) const void BeingHandler::processIpResponse(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (dstBeing) dstBeing->setIp(ipToString(msg.readInt32())); } void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (dstBeing) { @@ -668,10 +668,10 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) const void BeingHandler::processBeingChangeDirection(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (!dstBeing) return; @@ -686,7 +686,7 @@ void BeingHandler::processBeingChangeDirection(Net::MessageIn &msg) const void BeingHandler::processPlayerStop(Net::MessageIn &msg) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; /* @@ -705,7 +705,7 @@ void BeingHandler::processPlayerStop(Net::MessageIn &msg) const if (mSync || id != player_node->getId()) { - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) { const uint16_t x = msg.readInt16(); @@ -732,12 +732,12 @@ void BeingHandler::processPlayerMoveToAttack(Net::MessageIn &msg A_UNUSED) void BeingHandler::processPlaterStatusChange(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; // Change in players' flags const int id = msg.readInt32(); - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (!dstBeing) return; @@ -755,7 +755,7 @@ void BeingHandler::processPlaterStatusChange(Net::MessageIn &msg) const void BeingHandler::processBeingStatusChange(Net::MessageIn &msg) const { - if (!actorSpriteManager) + if (!actorManager) return; // Status change @@ -763,7 +763,7 @@ void BeingHandler::processBeingStatusChange(Net::MessageIn &msg) const const int id = msg.readInt32(); const int flag = msg.readInt8(); // 0: stop, 1: start - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) dstBeing->setStatusEffect(status, flag); } @@ -804,9 +804,9 @@ void BeingHandler::processPvpSet(Net::MessageIn &msg) const const int id = msg.readInt32(); // id const int rank = msg.readInt32(); // rank msg.readInt32(); // num - if (actorSpriteManager) + if (actorManager) { - Being *const dstBeing = actorSpriteManager->findBeing(id); + Being *const dstBeing = actorManager->findBeing(id); if (dstBeing) dstBeing->setPvpRank(rank); } diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index 1497e41aa..90c6be5bc 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/chathandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "guildmanager.h" #include "notifications.h" @@ -243,12 +243,12 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) const void ChatHandler::processBeingChat(Net::MessageIn &msg, const bool channels) const { - if (!actorSpriteManager) + if (!actorManager) return; BLOCK_START("ChatHandler::processBeingChat") int chatMsgLength = msg.readInt16() - 8; - Being *const being = actorSpriteManager->findBeing(msg.readInt32()); + Being *const being = actorManager->findBeing(msg.readInt32()); if (!being) { BLOCK_END("ChatHandler::processBeingChat") @@ -342,9 +342,9 @@ void ChatHandler::processChat(Net::MessageIn &msg, const bool normalChat, if (channel.empty()) { const std::string senseStr("You sense the following: "); - if (actorSpriteManager && !chatMsg.find(senseStr)) + if (actorManager && !chatMsg.find(senseStr)) { - actorSpriteManager->parseLevels( + actorManager->parseLevels( chatMsg.substr(senseStr.size())); } } @@ -370,9 +370,9 @@ void ChatHandler::processMVP(Net::MessageIn &msg) const BLOCK_START("ChatHandler::processMVP") // Display MVP player const int id = msg.readInt32(); // id - if (localChatTab && actorSpriteManager && config.getBoolValue("showMVP")) + if (localChatTab && actorManager && config.getBoolValue("showMVP")) { - const Being *const being = actorSpriteManager->findBeing(id); + const Being *const being = actorManager->findBeing(id); if (!being) NotifyManager::notify(NotifyManager::MVP_PLAYER, ""); else diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 7e46438d2..10663db57 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -21,7 +21,7 @@ #include "net/ea/guildhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "notifications.h" #include "notifymanager.h" @@ -266,9 +266,9 @@ void GuildHandler::processGuildMemberList(Net::MessageIn &msg) const m->setExp(exp); m->setPos(pos); m->setRace(race); - if (actorSpriteManager) + if (actorManager) { - Being *const being = actorSpriteManager->findBeingByName( + Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { @@ -286,10 +286,10 @@ void GuildHandler::processGuildMemberList(Net::MessageIn &msg) const } } taGuild->sort(); - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->updatePlayerGuild(); - actorSpriteManager->updatePlayerColors(); + actorManager->updatePlayerGuild(); + actorManager->updatePlayerColors(); } if (socialWindow) socialWindow->updateGuildCounter(onlineNum, totalNum); @@ -463,15 +463,15 @@ void GuildHandler::processGuildLeave(Net::MessageIn &msg) const if (socialWindow && taGuild) socialWindow->removeTab(taGuild); - if (actorSpriteManager) - actorSpriteManager->updatePlayerColors(); + if (actorManager) + actorManager->updatePlayerColors(); } else { NotifyManager::notify(NotifyManager::GUILD_USER_LEFT, nick); - if (actorSpriteManager) + if (actorManager) { - Being *const b = actorSpriteManager->findBeingByName( + Being *const b = actorManager->findBeingByName( nick, Being::PLAYER); if (b) @@ -507,15 +507,15 @@ void GuildHandler::processGuildExpulsion(Net::MessageIn &msg) const if (socialWindow && taGuild) socialWindow->removeTab(taGuild); - if (actorSpriteManager) - actorSpriteManager->updatePlayerColors(); + if (actorManager) + actorManager->updatePlayerColors(); } else { NotifyManager::notify(NotifyManager::GUILD_USER_KICKED, nick); - if (actorSpriteManager) + if (actorManager) { - Being *const b = actorSpriteManager->findBeingByName( + Being *const b = actorManager->findBeingByName( nick, Being::PLAYER); if (b) diff --git a/src/net/ea/itemhandler.cpp b/src/net/ea/itemhandler.cpp index 9c9a74b2d..ccc8c92cd 100644 --- a/src/net/ea/itemhandler.cpp +++ b/src/net/ea/itemhandler.cpp @@ -22,7 +22,7 @@ #include "net/ea/itemhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "debug.h" @@ -48,9 +48,9 @@ void ItemHandler::processItemVisible(Net::MessageIn &msg) const const int subX = msg.readInt8(); const int subY = msg.readInt8(); - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->createItem(id, itemId, + actorManager->createItem(id, itemId, x, y, amount, identify, subX, subY); } } @@ -66,21 +66,21 @@ void ItemHandler::processItemDropped(Net::MessageIn &msg) const const int subY = msg.readInt8(); const int amount = msg.readInt16(); - if (actorSpriteManager) + if (actorManager) { - actorSpriteManager->createItem(id, itemId, + actorManager->createItem(id, itemId, x, y, amount, identify, subX, subY); } } void ItemHandler::processItemRemove(Net::MessageIn &msg) const { - if (actorSpriteManager) + if (actorManager) { - if (FloorItem *const item = actorSpriteManager + if (FloorItem *const item = actorManager ->findItem(msg.readInt32())) { - actorSpriteManager->destroy(item); + actorManager->destroy(item); } } } diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index 6b2462450..73e2569ab 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -21,7 +21,7 @@ #include "net/ea/partyhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "configuration.h" #include "notifications.h" #include "notifymanager.h" @@ -211,9 +211,9 @@ void PartyHandler::processPartyInvited(Net::MessageIn &msg) const const std::string partyName = msg.readString(24); std::string nick; - if (actorSpriteManager) + if (actorManager) { - const Being *const being = actorSpriteManager->findBeing(id); + const Being *const being = actorManager->findBeing(id); if (being) { if (being->getType() == Being::PLAYER) @@ -352,9 +352,9 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) const else { NotifyManager::notify(NotifyManager::PARTY_USER_LEFT, nick); - if (actorSpriteManager) + if (actorManager) { - Being *const b = actorSpriteManager->findBeing(id); + Being *const b = actorManager->findBeing(id); if (b && b->getType() == Being::PLAYER) { b->setParty(nullptr); @@ -382,9 +382,9 @@ void PartyHandler::processPartyUpdateHp(Net::MessageIn &msg) const // The server only sends this when the member is in range, so // lets make sure they get the party hilight. - if (actorSpriteManager && Ea::taParty) + if (actorManager && Ea::taParty) { - if (Being *const b = actorSpriteManager->findBeing(id)) + if (Being *const b = actorManager->findBeing(id)) b->setParty(Ea::taParty); } } diff --git a/src/net/eathena/beinghandler.cpp b/src/net/eathena/beinghandler.cpp index 739e2397d..ab0af709e 100644 --- a/src/net/eathena/beinghandler.cpp +++ b/src/net/eathena/beinghandler.cpp @@ -22,7 +22,7 @@ #include "net/eathena/beinghandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "guild.h" #include "guildmanager.h" @@ -244,7 +244,7 @@ void BeingHandler::undress(Being *const being) const void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, const bool look2) const { - if (!actorSpriteManager) + if (!actorManager) return; /* @@ -259,7 +259,7 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, * 16 bit value will be 0. */ - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (!dstBeing) return; @@ -379,13 +379,13 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, void BeingHandler::processNameResponse2(Net::MessageIn &msg) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; const int len = msg.readInt16(); const int beingId = msg.readInt32(); const std::string str = msg.readString(len - 8); - Being *const dstBeing = actorSpriteManager->findBeing(beingId); + Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) { if (beingId == player_node->getId()) @@ -421,7 +421,7 @@ void BeingHandler::processNameResponse2(Net::MessageIn &msg) const void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, const int msgType) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; // An update about a player, potentially including movement. @@ -436,11 +436,11 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, if (id < 110000000 && job >= 1000) disguiseId = job; - Being *dstBeing = actorSpriteManager->findBeing(id); + Being *dstBeing = actorManager->findBeing(id); if (!dstBeing) { - if (actorSpriteManager->isBlocked(id) == true) + if (actorManager->isBlocked(id) == true) return; dstBeing = createBeing(id, job); @@ -450,7 +450,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, } else if (disguiseId) { - actorSpriteManager->undelete(dstBeing); + actorManager->undelete(dstBeing); if (serverVersion < 1) requestNameById(id); } @@ -625,7 +625,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, const bool visible) { - if (!actorSpriteManager) + if (!actorManager) return; if (visible) @@ -645,13 +645,13 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, statusEffects |= (static_cast(msg.readInt16())) << 16; // option const int16_t job = msg.readInt16(); // class - Being *dstBeing = actorSpriteManager->findBeing(id); + Being *dstBeing = actorManager->findBeing(id); if (dstBeing && dstBeing->getType() == Being::MONSTER && !dstBeing->isAlive()) { - actorSpriteManager->destroy(dstBeing); - actorSpriteManager->erase(dstBeing); + actorManager->destroy(dstBeing); + actorManager->erase(dstBeing); dstBeing = nullptr; } @@ -662,7 +662,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, if (job == 0 && id >= 110000000) return; - if (actorSpriteManager->isBlocked(id) == true) + if (actorManager->isBlocked(id) == true) return; dstBeing = createBeing(id, job); @@ -677,7 +677,7 @@ void BeingHandler::processBeingVisibleOrMove(Net::MessageIn &msg, { // undeleting marked for deletion being if (dstBeing->getType() == Being::NPC) - actorSpriteManager->undelete(dstBeing); + actorManager->undelete(dstBeing); } if (dstBeing->getType() == Being::PLAYER) diff --git a/src/net/eathena/guildhandler.cpp b/src/net/eathena/guildhandler.cpp index 63b5aaea2..7a682105f 100644 --- a/src/net/eathena/guildhandler.cpp +++ b/src/net/eathena/guildhandler.cpp @@ -21,7 +21,7 @@ #include "net/eathena/guildhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "being/localplayer.h" #include "being/playerinfo.h" @@ -202,10 +202,10 @@ void GuildHandler::create(const std::string &name) const void GuildHandler::invite(const int guildId A_UNUSED, const std::string &name A_UNUSED) const { - if (!actorSpriteManager) + if (!actorManager) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { diff --git a/src/net/eathena/partyhandler.cpp b/src/net/eathena/partyhandler.cpp index 2508c8556..8af0e4aaa 100644 --- a/src/net/eathena/partyhandler.cpp +++ b/src/net/eathena/partyhandler.cpp @@ -21,7 +21,7 @@ #include "net/eathena/partyhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "notifications.h" #include "notifymanager.h" @@ -120,10 +120,10 @@ void PartyHandler::invite(Being *const being) const void PartyHandler::invite(const std::string &name) const { - if (!actorSpriteManager) + if (!actorManager) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 0f668d162..8f91371b1 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -22,7 +22,7 @@ #include "net/tmwa/beinghandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "client.h" #include "guild.h" #include "guildmanager.h" @@ -245,7 +245,7 @@ void BeingHandler::undress(Being *const being) const void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, const bool look2) const { - if (!actorSpriteManager) + if (!actorManager) return; /* @@ -260,7 +260,7 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, * 16 bit value will be 0. */ - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (!dstBeing) return; @@ -387,14 +387,14 @@ void BeingHandler::processBeingChangeLook(Net::MessageIn &msg, void BeingHandler::processNameResponse2(Net::MessageIn &msg) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; const int len = msg.readInt16(); const int beingId = msg.readInt32(); const std::string str = msg.readString(len - 8); - Being *const dstBeing = actorSpriteManager->findBeing(beingId); + Being *const dstBeing = actorManager->findBeing(beingId); if (dstBeing) { if (beingId == player_node->getId()) @@ -430,7 +430,7 @@ void BeingHandler::processNameResponse2(Net::MessageIn &msg) const void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, const int msgType) const { - if (!actorSpriteManager || !player_node) + if (!actorManager || !player_node) return; // An update about a player, potentially including movement. @@ -445,10 +445,10 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, if (id < 110000000 && job >= 1000) disguiseId = job; - Being *dstBeing = actorSpriteManager->findBeing(id); + Being *dstBeing = actorManager->findBeing(id); if (!dstBeing) { - if (actorSpriteManager->isBlocked(id) == true) + if (actorManager->isBlocked(id) == true) return; dstBeing = createBeing(id, job); @@ -458,7 +458,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, } else if (disguiseId) { - actorSpriteManager->undelete(dstBeing); + actorManager->undelete(dstBeing); if (serverVersion < 1) requestNameById(id); } @@ -658,7 +658,7 @@ void BeingHandler::processBeingMove3(Net::MessageIn &msg) const static const int diry[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const int len = msg.readInt16() - 14; - Being *const dstBeing = actorSpriteManager->findBeing(msg.readInt32()); + Being *const dstBeing = actorManager->findBeing(msg.readInt32()); if (!dstBeing) return; const int16_t speed = msg.readInt16(); diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index 862c437ed..60747685d 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -21,7 +21,7 @@ #include "net/tmwa/guildhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "being/localplayer.h" #include "being/playerinfo.h" @@ -208,10 +208,10 @@ void GuildHandler::create(const std::string &name) const void GuildHandler::invite(const int guildId A_UNUSED, const std::string &name) const { - if (!actorSpriteManager) + if (!actorManager) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { diff --git a/src/net/tmwa/partyhandler.cpp b/src/net/tmwa/partyhandler.cpp index 92c79d447..d3a49d75a 100644 --- a/src/net/tmwa/partyhandler.cpp +++ b/src/net/tmwa/partyhandler.cpp @@ -21,7 +21,7 @@ #include "net/tmwa/partyhandler.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "notifications.h" #include "notifymanager.h" @@ -122,10 +122,10 @@ void PartyHandler::invite(Being *const being) const void PartyHandler::invite(const std::string &name) const { - if (!actorSpriteManager) + if (!actorManager) return; - const Being *const being = actorSpriteManager->findBeingByName( + const Being *const being = actorManager->findBeingByName( name, Being::PLAYER); if (being) { diff --git a/src/party.cpp b/src/party.cpp index 4cd4ff147..fb96a9423 100644 --- a/src/party.cpp +++ b/src/party.cpp @@ -21,7 +21,7 @@ #include "party.h" -#include "actorspritemanager.h" +#include "actormanager.h" #include "utils/stringutils.h" @@ -192,7 +192,7 @@ void Party::removeMember(const std::string &name) void Party::removeFromMembers() { - if (!actorSpriteManager) + if (!actorManager) return; MemberList::const_iterator itr = mMembers.begin(); @@ -200,7 +200,7 @@ void Party::removeFromMembers() while (itr != itr_end) { - Being *const b = actorSpriteManager->findBeing((*itr)->getID()); + Being *const b = actorManager->findBeing((*itr)->getID()); if (b) b->setParty(nullptr); ++itr; -- cgit v1.2.3-60-g2f50