diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-05-06 22:32:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-05-07 18:24:47 +0300 |
commit | 2a4649185cda0788444452168ddcf665af7f17b5 (patch) | |
tree | 5ef92bdda9421130873a08e7793fad40364b41e3 | |
parent | c371ce29dd114121fe0071e59460a9f197da70f5 (diff) | |
download | mv-2a4649185cda0788444452168ddcf665af7f17b5.tar.gz mv-2a4649185cda0788444452168ddcf665af7f17b5.tar.bz2 mv-2a4649185cda0788444452168ddcf665af7f17b5.tar.xz mv-2a4649185cda0788444452168ddcf665af7f17b5.zip |
Save atack filter between restarts.
-rw-r--r-- | src/actorspritemanager.cpp | 57 | ||||
-rw-r--r-- | src/actorspritemanager.h | 3 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 21 | ||||
-rw-r--r-- | src/utils/stringutils.h | 4 |
4 files changed, 83 insertions, 2 deletions
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<std::string> list = unpackList( + serverConfig.getValue("attackPriorityMobs", "")); + std::list<std::string>::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<std::string> 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<std::string> &list) +{ + std::list<std::string>::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<std::string> 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<std::string> getLang(); +std::string packList(std::list<std::string> &list); + +std::list<std::string> unpackList(const std::string str); + #endif // UTILS_STRINGUTILS_H |