diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/xml.cpp | 72 | ||||
-rw-r--r-- | src/utils/xml.hpp | 23 |
2 files changed, 95 insertions, 0 deletions
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp index 41742d7e..f71e5bfd 100644 --- a/src/utils/xml.cpp +++ b/src/utils/xml.cpp @@ -39,6 +39,20 @@ int getProperty(xmlNodePtr node, char const *name, int def) return def; } +double +getFloatProperty(xmlNodePtr node, const char* name, double def) +{ + double &ret = def; + + xmlChar *prop = xmlGetProp(node, BAD_CAST name); + if (prop) { + ret = atof((char*)prop); + xmlFree(prop); + } + + return ret; +} + std::string getProperty(xmlNodePtr node, char const *name, std::string const &def) { if (xmlChar *prop = xmlGetProp(node, BAD_CAST name)) @@ -50,4 +64,62 @@ std::string getProperty(xmlNodePtr node, char const *name, std::string const &de return def; } +unsigned int elementFromString(std::string name) +{ + if (name=="neutral") return ELEMENT_NEUTRAL; + else if (name=="fire") return ELEMENT_FIRE; + else if (name=="water") return ELEMENT_WATER; + else if (name=="earth") return ELEMENT_EARTH; + else if (name=="air") return ELEMENT_AIR; + else if (name=="lightning") return ELEMENT_LIGHTNING; + else if (name=="metal") return ELEMENT_METAL; + else if (name=="wood") return ELEMENT_WOOD; + else if (name=="ice") return ELEMENT_ICE; + { + return ELEMENT_ILLEGAL; + } +} + +ItemType itemTypeFromString (std::string name) +{ + if (name=="generic") return ITEM_UNUSABLE; + else if (name=="usable") return ITEM_USABLE; + else if (name=="equip-1hand") return ITEM_EQUIPMENT_ONE_HAND_WEAPON; + else if (name=="equip-2hand") return ITEM_EQUIPMENT_TWO_HANDS_WEAPON; + else if (name=="equip-torso") return ITEM_EQUIPMENT_TORSO; + else if (name=="equip-arms") return ITEM_EQUIPMENT_ARMS; + else if (name=="equip-head") return ITEM_EQUIPMENT_HEAD; + else if (name=="equip-legs") return ITEM_EQUIPMENT_LEGS; + else if (name=="equip-shield") return ITEM_EQUIPMENT_SHIELD; + else if (name=="equip-ring") return ITEM_EQUIPMENT_RING; + else if (name=="equip-necklace") return ITEM_EQUIPMENT_NECKLACE; + else if (name=="equip-feet") return ITEM_EQUIPMENT_FEET; + else if (name=="equip-ammo") return ITEM_EQUIPMENT_AMMO; + else if (name=="hairsprite") return ITEM_HAIRSPRITE; + else if (name=="racesprite") return ITEM_RACESPRITE; + else + { + return ITEM_UNKNOWN; + } +} + +WeaponType weaponTypeFromString (std::string name) +{ + if (name=="knife") return WPNTYPE_KNIFE; + else if (name=="sword") return WPNTYPE_SWORD; + else if (name=="polearm") return WPNTYPE_POLEARM; + else if (name=="staff") return WPNTYPE_STAFF; + else if (name=="whip") return WPNTYPE_WHIP; + else if (name=="bow") return WPNTYPE_BOW; + else if (name=="shooting") return WPNTYPE_SHOOTING; + else if (name=="mace") return WPNTYPE_MACE; + else if (name=="axe") return WPNTYPE_AXE; + else if (name=="thrown") return WPNTYPE_THROWN; + else + { + return WPNTYPE_NONE; + } +} + + } // namespace XML diff --git a/src/utils/xml.hpp b/src/utils/xml.hpp index ace8d64d..d2ab62e7 100644 --- a/src/utils/xml.hpp +++ b/src/utils/xml.hpp @@ -27,6 +27,9 @@ #include <string> #include <libxml/tree.h> +#include "defines.h" +#include "../game-server/item.hpp" + namespace XML { /** @@ -38,6 +41,26 @@ namespace XML * Gets a string property from an xmlNodePtr. */ std::string getProperty(xmlNodePtr node, char const *name, std::string const &def); + + /** + * Gets an floating point property from an xmlNodePtr. + */ + double + getFloatProperty(xmlNodePtr node, const char *name, double def); + + + /** + * Converts a string into an element number + */ + unsigned int elementFromString(std::string name); + /** + * Converts a string into an ItemType number + */ + ItemType itemTypeFromString (std::string name); + /** + * Converts a string into a weaponType number + */ + WeaponType weaponTypeFromString (std::string name); } #define for_each_xml_child_node(var, parent) \ |