summaryrefslogtreecommitdiff
path: root/src/game-server/item.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2008-02-21 17:59:40 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2008-02-21 17:59:40 +0000
commit12c9a7508dfa863087035f6dc2f73866789927f1 (patch)
tree749b96a4738fcc199c8a7c23bf890f01aefb2e06 /src/game-server/item.cpp
parentd1649dfdf5628fb49d1c2c50085cd318a87a515f (diff)
downloadmanaserv-12c9a7508dfa863087035f6dc2f73866789927f1.tar.gz
manaserv-12c9a7508dfa863087035f6dc2f73866789927f1.tar.bz2
manaserv-12c9a7508dfa863087035f6dc2f73866789927f1.tar.xz
manaserv-12c9a7508dfa863087035f6dc2f73866789927f1.zip
Moved the functions which translate strings into enumerations from the XML library into the item and monstermanager modules and reimplemented them using std::maps.
Diffstat (limited to 'src/game-server/item.cpp')
-rw-r--r--src/game-server/item.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp
index 23df3b0e..f14374b6 100644
--- a/src/game-server/item.cpp
+++ b/src/game-server/item.cpp
@@ -21,10 +21,65 @@
* $Id$
*/
+
+#include <string>
+#include <map>
+
#include "game-server/item.hpp"
#include "game-server/being.hpp"
+WeaponType weaponTypeFromString (const std::string &name)
+{
+ static std::map<const std::string, WeaponType> table;
+
+ if (table.empty())
+ {
+ table["knife"] = WPNTYPE_KNIFE;
+ table["sword"] = WPNTYPE_SWORD;
+ table["polearm"] = WPNTYPE_POLEARM;
+ table["staff"] = WPNTYPE_STAFF;
+ table["whip"] = WPNTYPE_WHIP;
+ table["bow"] = WPNTYPE_BOW;
+ table["shooting"] = WPNTYPE_SHOOTING;
+ table["mace"] = WPNTYPE_MACE;
+ table["axe"] = WPNTYPE_AXE;
+ table["thrown"] = WPNTYPE_THROWN;
+ }
+
+ std::map<const std::string, WeaponType>::iterator val = table.find(name);
+
+ return val == table.end() ? WPNTYPE_NONE : (*val).second;
+}
+
+ItemType itemTypeFromString (const std::string &name)
+{
+ static std::map<const std::string, ItemType> table;
+
+ if (table.empty())
+ {
+ table["generic"] = ITEM_UNUSABLE;
+ table["usable"] = ITEM_USABLE;
+ table["equip-1hand"] = ITEM_EQUIPMENT_ONE_HAND_WEAPON;
+ table["equip-2hand"] = ITEM_EQUIPMENT_TWO_HANDS_WEAPON;
+ table["equip-torso"] = ITEM_EQUIPMENT_TORSO;
+ table["equip-arms"] = ITEM_EQUIPMENT_ARMS;
+ table["equip-head"] = ITEM_EQUIPMENT_HEAD;
+ table["equip-legs"] = ITEM_EQUIPMENT_LEGS;
+ table["equip-shield"] = ITEM_EQUIPMENT_SHIELD;
+ table["equip-ring"] = ITEM_EQUIPMENT_RING;
+ table["equip-necklace"] = ITEM_EQUIPMENT_NECKLACE;
+ table["equip-feet"] = ITEM_EQUIPMENT_FEET;
+ table["equip-ammo"] = ITEM_EQUIPMENT_AMMO;
+ table["hairsprite"] = ITEM_HAIRSPRITE;
+ table["racesprite"] = ITEM_RACESPRITE;
+ }
+
+ std::map<const std::string, ItemType>::iterator val = table.find(name);
+
+ return val == table.end() ? ITEM_UNKNOWN : (*val).second;
+}
+
int ItemModifiers::getValue(int type) const
{
for (std::vector< ItemModifier >::const_iterator i = mModifiers.begin(),