summaryrefslogtreecommitdiff
path: root/src/actorspritemanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-05-06 19:37:58 +0300
committerAndrei Karas <akaras@inbox.ru>2011-05-06 21:57:13 +0300
commite26b64efb9c6b79bbd5d9426af6887e83651e466 (patch)
treeaf915bda2a533558cfecaf363e331d59145e1224 /src/actorspritemanager.cpp
parent0f58a82314ca88b059674c98236f229358f6a80a (diff)
downloadmanaplus-e26b64efb9c6b79bbd5d9426af6887e83651e466.tar.gz
manaplus-e26b64efb9c6b79bbd5d9426af6887e83651e466.tar.bz2
manaplus-e26b64efb9c6b79bbd5d9426af6887e83651e466.tar.xz
manaplus-e26b64efb9c6b79bbd5d9426af6887e83651e466.zip
Move attack filter arrays and methods from localplayer to actorspritemanager class.
Diffstat (limited to 'src/actorspritemanager.cpp')
-rw-r--r--src/actorspritemanager.cpp137
1 files changed, 129 insertions, 8 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index 3f37ce99f..d193c4ab1 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -29,12 +29,14 @@
#include "playerinfo.h"
#include "playerrelations.h"
-#include "gui/widgets/chattab.h"
-#include "gui/killstats.h"
#include "gui/chatwindow.h"
+#include "gui/killstats.h"
#include "gui/skilldialog.h"
+#include "gui/socialwindow.h"
#include "gui/viewport.h"
+#include "gui/widgets/chattab.h"
+
#include "utils/dtor.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -177,6 +179,8 @@ ActorSpriteManager::ActorSpriteManager() :
config.addListener("targetOnlyReachable", this);
config.addListener("cyclePlayers", this);
config.addListener("cycleMonsters", this);
+
+ addAttackMob("");
}
ActorSpriteManager::~ActorSpriteManager()
@@ -200,6 +204,8 @@ void ActorSpriteManager::setPlayer(LocalPlayer *player)
{
player_node = player;
mActors.insert(player);
+ if (socialWindow)
+ socialWindow->updateAttackFilter();
}
Being *ActorSpriteManager::createBeing(int id, ActorSprite::Type type,
@@ -665,11 +671,11 @@ Being *ActorSpriteManager::findNearestLivingBeing(Being *aroundBeing,
bool ignoreDefault = false;
if (filtered)
{
- attackMobs = player_node->getAttackMobsSet();
- priorityMobs = player_node->getPriorityAttackMobsSet();
- ignoreAttackMobs = player_node->getIgnoreAttackMobsSet();
- attackMobsMap = player_node->getAttackMobsMap();
- priorityMobsMap = player_node->getPriorityAttackMobsMap();
+ attackMobs = mAttackMobsSet;
+ priorityMobs = mPriorityAttackMobsSet;
+ ignoreAttackMobs = mIgnoreAttackMobsSet;
+ attackMobsMap = mAttackMobsMap;
+ priorityMobsMap = mPriorityAttackMobsMap;
beingSorter.attackBeings = &attackMobsMap;
beingSorter.priorityBeings = &priorityMobsMap;
if (ignoreAttackMobs.find("") != ignoreAttackMobs.end())
@@ -1190,4 +1196,119 @@ void ActorSpriteManager::optionChanged(const std::string &name)
mCyclePlayers = config.getBoolValue("cyclePlayers");
else if (name == "cycleMonsters")
mCycleMonsters = config.getBoolValue("cycleMonsters");
-} \ No newline at end of file
+}
+
+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::addAttackMob(std::string name)
+{
+ int size = getAttackMobsSize();
+ if (size > 0)
+ {
+ int idx = getAttackMobIndex("");
+ if (idx + 1 == size)
+ {
+ std::list<std::string>::iterator itr = mAttackMobs.end();
+ -- itr;
+ mAttackMobs.insert(itr, name);
+ }
+ else
+ {
+ mAttackMobs.push_back(name);
+ }
+ }
+ else
+ {
+ mAttackMobs.push_back(name);
+ }
+ mAttackMobsSet.insert(name);
+ rebuildAttackMobs();
+ rebuildPriorityAttackMobs();
+}
+
+void ActorSpriteManager::addPriorityAttackMob(std::string name)
+{
+ int size = getPriorityAttackMobsSize();
+ if (size > 0)
+ {
+ int idx = getPriorityAttackMobIndex("");
+ if (idx + 1 == size)
+ {
+ std::list<std::string>::iterator itr = mPriorityAttackMobs.end();
+ -- itr;
+ mPriorityAttackMobs.insert(itr, name);
+ }
+ else
+ {
+ mPriorityAttackMobs.push_back(name);
+ }
+ }
+ else
+ {
+ mPriorityAttackMobs.push_back(name);
+ }
+ mPriorityAttackMobsSet.insert(name);
+ rebuildPriorityAttackMobs();
+}
+
+void ActorSpriteManager::addIgnoreAttackMob(std::string name)
+{
+ mIgnoreAttackMobs.push_back(name);
+ mIgnoreAttackMobsSet.insert(name);
+ rebuildAttackMobs();
+ rebuildPriorityAttackMobs();
+}
+
+void ActorSpriteManager::rebuildPriorityAttackMobs()
+{
+ mPriorityAttackMobsMap.clear();
+ std::list<std::string>::iterator i = mPriorityAttackMobs.begin();
+ int cnt = 0;
+ while (i != mPriorityAttackMobs.end())
+ {
+ mPriorityAttackMobsMap[*i] = cnt;
+ ++ i;
+ ++ cnt;
+ }
+}
+
+void ActorSpriteManager::rebuildAttackMobs()
+{
+ mAttackMobsMap.clear();
+ std::list<std::string>::iterator i = mAttackMobs.begin();
+ int cnt = 0;
+ while (i != mAttackMobs.end())
+ {
+ mAttackMobsMap[*i] = cnt;
+ ++ i;
+ ++ cnt;
+ }
+}
+
+int ActorSpriteManager::getPriorityAttackMobIndex(std::string name)
+{
+ std::map<std::string, int>::iterator i = mPriorityAttackMobsMap.find(name);
+ if (i == mPriorityAttackMobsMap.end())
+ return -1;
+
+ return (*i).second;
+}
+
+int ActorSpriteManager::getAttackMobIndex(std::string name)
+{
+ std::map<std::string, int>::iterator i = mAttackMobsMap.find(name);
+ if (i == mAttackMobsMap.end())
+ return -1;
+
+ return (*i).second;
+}