summaryrefslogtreecommitdiff
path: root/src/game-server/monstermanager.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2011-03-15 20:27:33 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2011-03-16 08:36:52 +0100
commitb6e7feedc82c3c549af0d3cd53be1a981945f42d (patch)
tree5890776fa8f1c70e7d94ac1e1fed6c554f269371 /src/game-server/monstermanager.cpp
parent24f2b307f089558276d1d526f1288d229af11678 (diff)
downloadmanaserv-b6e7feedc82c3c549af0d3cd53be1a981945f42d.tar.gz
manaserv-b6e7feedc82c3c549af0d3cd53be1a981945f42d.tar.bz2
manaserv-b6e7feedc82c3c549af0d3cd53be1a981945f42d.tar.xz
manaserv-b6e7feedc82c3c549af0d3cd53be1a981945f42d.zip
Allowed monster names in @spawn command
I rewrote the @spawn command to allow two new things: 1. The monster ID can be replaced with the name of the monster. 2. The amount of monsters can be omitted. In that case a single monster is spawned. Reviewed by: Jaxad and Thorbjorn
Diffstat (limited to 'src/game-server/monstermanager.cpp')
-rw-r--r--src/game-server/monstermanager.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/game-server/monstermanager.cpp b/src/game-server/monstermanager.cpp
index ac5b07ff..0810164f 100644
--- a/src/game-server/monstermanager.cpp
+++ b/src/game-server/monstermanager.cpp
@@ -25,6 +25,7 @@
#include "game-server/itemmanager.h"
#include "game-server/monster.h"
#include "utils/logger.h"
+#include "utils/string.h"
#include "utils/xml.h"
#define MAX_MUTATION 99
@@ -106,6 +107,7 @@ void MonsterManager::reload()
{
monster = i->second;
}
+ monster->setName(name);
MonsterDrops drops;
bool attributesSet = false;
@@ -344,6 +346,25 @@ void MonsterManager::deinitialize()
mMonsterClasses.clear();
}
+MonsterClass *MonsterManager::getMonsterByName(std::string name) const
+{
+ // this function is not very fast but neither does it need to be
+ // because it is only used by the @spawn command. It would be
+ // possible to speed it up by caching the lowercase_name/MonsterClass
+ // mapping in a std::map during MonsterManager::reload, should the
+ // need arise.
+ name = utils::toLower(name);
+ for (MonsterClasses::const_iterator i = mMonsterClasses.begin(),
+ i_end = mMonsterClasses.end(); i != i_end; ++i)
+ {
+ if(utils::toLower(i->second->getName()) == name)
+ {
+ return i->second;
+ }
+ }
+ return 0;
+}
+
MonsterClass *MonsterManager::getMonster(int id)
{
MonsterClasses::const_iterator i = mMonsterClasses.find(id);