From 2a4649185cda0788444452168ddcf665af7f17b5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 6 May 2011 22:32:21 +0300 Subject: Save atack filter between restarts. --- src/actorspritemanager.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++- src/actorspritemanager.h | 3 +++ src/utils/stringutils.cpp | 21 ++++++++++++++++- src/utils/stringutils.h | 4 ++++ 4 files changed, 83 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index d193c4ab1..e7c28fd1e 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -180,7 +180,7 @@ ActorSpriteManager::ActorSpriteManager() : config.addListener("cyclePlayers", this); config.addListener("cycleMonsters", this); - addAttackMob(""); + loadAttackList(); } ActorSpriteManager::~ActorSpriteManager() @@ -189,6 +189,7 @@ ActorSpriteManager::~ActorSpriteManager() config.removeListener("targetOnlyReachable", this); config.removeListener("cyclePlayers", this); config.removeListener("cycleMonsters", this); + storeAttackList(); clear(); } @@ -1312,3 +1313,57 @@ int ActorSpriteManager::getAttackMobIndex(std::string name) return (*i).second; } + +void ActorSpriteManager::loadAttackList() +{ + bool empty = false; + std::list list = unpackList( + serverConfig.getValue("attackPriorityMobs", "")); + std::list::iterator i = list.begin(); + while (i != list.end()) + { + if (*i == "") + empty = true; + mPriorityAttackMobs.push_back(*i); + mPriorityAttackMobsSet.insert(*i); + ++ i; + } + + list = unpackList(serverConfig.getValue("attackMobs", "")); + i = list.begin(); + while (i != list.end()) + { + if (*i == "") + empty = true; + mAttackMobs.push_back(*i); + mAttackMobsSet.insert(*i); + ++ i; + } + + list = unpackList(serverConfig.getValue("ignoreAttackMobs", "")); + i = list.begin(); + while (i != list.end()) + { + if (*i == "") + empty = true; + mIgnoreAttackMobs.push_back(*i); + mIgnoreAttackMobsSet.insert(*i); + ++ i; + } + + if (!empty) + { + mAttackMobs.push_back(""); + mAttackMobsSet.insert(""); + } + + rebuildAttackMobs(); + rebuildPriorityAttackMobs(); +} + +void ActorSpriteManager::storeAttackList() +{ + serverConfig.setValue("attackPriorityMobs", packList(mPriorityAttackMobs)); + serverConfig.setValue("attackMobs", packList(mAttackMobs)); + serverConfig.setValue("ignoreAttackMobs", packList(mIgnoreAttackMobs)); +} diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index d25bee2c1..dc1cc9869 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -305,6 +305,9 @@ class ActorSpriteManager: public ConfigListener Being::Type type, int x, int y, Being *excluded = 0) const; + void loadAttackList(); + void storeAttackList(); + ActorSprites mActors; ActorSprites mDeleteActors; Map *mMap; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index ea2d18276..d9eca557d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -456,4 +456,23 @@ std::vector getLang() if (dot != (signed)std::string::npos) langs.push_back(lang.substr(0, dot)); return langs; -} \ No newline at end of file +} + +std::string packList(std::list &list) +{ + std::list::iterator i = list.begin(); + std::string str = ""; + while (i != list.end()) + { + str = str + (*i) + "|"; + ++ i; + } + if (str.size() > 1) + str = str.substr(0, str.size() - 1); + return str; +} + +std::list unpackList(const std::string str) +{ + return splitToStringList(str, '|'); +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index f0dbf0bd9..9d22f8ba8 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -180,4 +180,8 @@ std::string combineDye2(std::string file, std::string dye); std::vector getLang(); +std::string packList(std::list &list); + +std::list unpackList(const std::string str); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-60-g2f50