diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | src/game-server/inventory.cpp | 2 | ||||
-rw-r--r-- | src/game-server/item.hpp | 63 | ||||
-rw-r--r-- | src/game-server/itemmanager.cpp | 86 |
4 files changed, 114 insertions, 44 deletions
@@ -1,3 +1,10 @@ +2008-01-10 Philipp Sehmisch <tmw@crushnet.org> + + * src/game-server/inventory.cpp, src/game-server/item.hpp, + src/game-server/itemmanager.cpp: Item types and weapon types + are now identified by name instead of numbers in the items.xml. + Cleaned out some nonsensical weapon types. + 2008-01-07 Philipp Sehmisch <tmw@crushnet.org> * src/defines.h, src/game-server/being.cpp, diff --git a/src/game-server/inventory.cpp b/src/game-server/inventory.cpp index 31f3b17b..84244e3e 100644 --- a/src/game-server/inventory.cpp +++ b/src/game-server/inventory.cpp @@ -722,7 +722,7 @@ void Inventory::equip(int slot) return; } - case ITEM_EQUIPMENT_PROJECTILE: + case ITEM_EQUIPMENT_AMMO: msg.writeByte(EQUIP_PROJECTILE_SLOT); msg.writeShort(itemId); mPoss->equipment[EQUIP_PROJECTILE_SLOT] = itemId; diff --git a/src/game-server/item.hpp b/src/game-server/item.hpp index 84695429..dcf1b731 100644 --- a/src/game-server/item.hpp +++ b/src/game-server/item.hpp @@ -33,45 +33,42 @@ class Being; /** * Enumeration of available Item types. */ -enum +enum ItemType { ITEM_UNUSABLE = 0, - ITEM_USABLE, // 1 - ITEM_EQUIPMENT_ONE_HAND_WEAPON, // 2 - ITEM_EQUIPMENT_TWO_HANDS_WEAPON, // 3 - ITEM_EQUIPMENT_TORSO, // 4 - ITEM_EQUIPMENT_ARMS, // 5 - ITEM_EQUIPMENT_HEAD, // 6 - ITEM_EQUIPMENT_LEGS, // 7 - ITEM_EQUIPMENT_SHIELD, // 8 - ITEM_EQUIPMENT_RING, // 9 - ITEM_EQUIPMENT_NECKLACE, // 10 - ITEM_EQUIPMENT_FEET, // 11 - ITEM_EQUIPMENT_PROJECTILE // 12 + ITEM_USABLE, // 1 + ITEM_EQUIPMENT_ONE_HAND_WEAPON, // 2 + ITEM_EQUIPMENT_TWO_HANDS_WEAPON,// 3 + ITEM_EQUIPMENT_TORSO,// 4 + ITEM_EQUIPMENT_ARMS,// 5 + ITEM_EQUIPMENT_HEAD,// 6 + ITEM_EQUIPMENT_LEGS,// 7 + ITEM_EQUIPMENT_SHIELD,// 8 + ITEM_EQUIPMENT_RING,// 9 + ITEM_EQUIPMENT_NECKLACE,// 10 + ITEM_EQUIPMENT_FEET,// 11 + ITEM_EQUIPMENT_AMMO// 12 }; /** * Enumeration of available weapon's types. */ -enum +enum WeaponType { WPNTYPE_NONE = 0, - WPNTYPE_KNIFE, // 1 - WPNTYPE_SWORD, // 2 - WPNTYPE_SPEAR, // 3 - WPNTYPE_JAVELIN, // 4 - WPNTYPE_ROD, // 5 - WPNTYPE_STAFF, // 6 - WPNTYPE_WHIP, // 7 - WPNTYPE_PROJECTILE, // 8 - WPNTYPE_BOOMERANG, // 9 - WPNTYPE_BOW, // 10 - WPNTYPE_SICKLE, // 11 - WPNTYPE_CROSSBOW, // 12 - WPNTYPE_STICK, // 13 - WPNTYPE_HAMMER, // 14 - WPNTYPE_AXE, // 15 - WPNTYPE_HAND_PROJECTILE // 16 + WPNTYPE_KNIFE,// 1 + WPNTYPE_SWORD,// 2 + WPNTYPE_POLEARM,// 3 + WPNTYPE_JAVELIN,// 4 + WPNTYPE_STAFF,// 5 + WPNTYPE_WHIP,// 6 + WPNTYPE_BOOMERANG,// 7 + WPNTYPE_BOW,// 8 + WPNTYPE_SICKLE,// 9 + WPNTYPE_CROSSBOW,// 10 + WPNTYPE_MACE,// 11 + WPNTYPE_AXE,// 12 + WPNTYPE_THROWN// 13 }; /** @@ -172,7 +169,7 @@ class ItemModifiers class ItemClass { public: - ItemClass(int id, int type) + ItemClass(int id, ItemType type) : mDatabaseID(id), mType(type) {} @@ -185,7 +182,7 @@ class ItemClass /** * Gets item type. */ - int getType() const + ItemType getType() const { return mType; } /** @@ -259,7 +256,7 @@ class ItemClass // Item reference information unsigned short mDatabaseID; unsigned short mSpriteID; /**< The sprite that should be shown to the character */ - unsigned char mType; /**< Type: usable, equipment. */ + ItemType mType; /**< Type: usable, equipment etc. */ unsigned short mWeight; /**< Weight of the item. */ unsigned short mCost; /**< Unit cost the item. */ unsigned short mMaxPerSlot; /**< Max item amount per slot in inventory. */ diff --git a/src/game-server/itemmanager.cpp b/src/game-server/itemmanager.cpp index 57486177..8113a109 100644 --- a/src/game-server/itemmanager.cpp +++ b/src/game-server/itemmanager.cpp @@ -35,6 +35,65 @@ typedef std::map< int, ItemClass * > ItemClasses; static ItemClasses itemClasses; /**< Item reference */ static std::string itemReferenceFile; + +ItemType itemTypeFromString (std::string name, int id = 0) +{ + 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=="") + { + LOG_WARN("No item type defined for item "<<id<<" in items.xml"); + return ITEM_UNUSABLE; + } + else + { + LOG_WARN("Unknown item type \""<<name<<"\" for item "<<id<<" in items.xml"); + if (name.find("weapon") != std::string::npos) + LOG_WARN("do you mean \"equip-1hand\" or \"equip-2hand\"?"); + if (name.find("armor") != std::string::npos) + LOG_WARN("do you mean \"equip-...\" instead of \"armor-...\"?"); + return ITEM_UNUSABLE; + } +} + +WeaponType weaponTypeFromString (std::string name, int id = 0) +{ + if (name=="knife") return WPNTYPE_KNIFE; + else if (name=="sword") return WPNTYPE_SWORD; + else if (name=="polearm") return WPNTYPE_POLEARM; + else if (name=="javelin") return WPNTYPE_JAVELIN; + else if (name=="staff") return WPNTYPE_STAFF; + else if (name=="whip") return WPNTYPE_WHIP; + else if (name=="boomerang") return WPNTYPE_BOOMERANG; + else if (name=="bow") return WPNTYPE_BOW; + else if (name=="sickle") return WPNTYPE_SICKLE; + else if (name=="crossbow") return WPNTYPE_CROSSBOW; + else if (name=="mace") return WPNTYPE_MACE; + else if (name=="axe") return WPNTYPE_AXE; + else if (name=="thrown") return WPNTYPE_THROWN; + else if (name=="") + { + LOG_WARN("ItemManager: No weapon type defined for weapon with item id "<<id); + return WPNTYPE_NONE; + } + else + { + LOG_WARN("ItemManager: Unknown weapon type \""<<name<<"\" for item "<<id); + return WPNTYPE_NONE; + } +} + void ItemManager::initialize(std::string const &file) { itemReferenceFile = file; @@ -81,8 +140,6 @@ void ItemManager::reload() } int id = XML::getProperty(node, "id", 0); - int itemType = XML::getProperty(node, "type", 0); - if (id == 0) { LOG_WARN("Item Manager: An (ignored) item has no ID in " @@ -90,6 +147,9 @@ void ItemManager::reload() continue; } + std::string sItemType = XML::getProperty(node, "type", ""); + ItemType itemType = itemTypeFromString(sItemType, id); + ItemClass *item; ItemClasses::iterator i = itemClasses.find(id); if (i == itemClasses.end()) @@ -104,16 +164,22 @@ void ItemManager::reload() int weight = XML::getProperty(node, "weight", 0); int value = XML::getProperty(node, "value", 0); - int maxPerSlot = XML::getProperty(node, "max_per_slot", 0); + int maxPerSlot = XML::getProperty(node, "max-per-slot", 0); int sprite = XML::getProperty(node, "sprite_id", 0); std::string scriptName = XML::getProperty(node, "script_name", std::string()); - //TODO: add child nodes for these modifiers (additive and factor) ItemModifiers modifiers; - modifiers.setValue(MOD_WEAPON_TYPE, XML::getProperty(node, "weapon_type", 0)); - modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0)); - modifiers.setValue(MOD_ELEMENT_TYPE, XML::getProperty(node, "element", 0)); + if (itemType == ITEM_EQUIPMENT_ONE_HAND_WEAPON || + itemType == ITEM_EQUIPMENT_TWO_HANDS_WEAPON) + { + std::string sWeaponType = XML::getProperty(node, "weapon-type", ""); + WeaponType weaponType = weaponTypeFromString(sWeaponType, id); + modifiers.setValue(MOD_WEAPON_TYPE, weaponType); + modifiers.setValue(MOD_WEAPON_RANGE, XML::getProperty(node, "range", 0)); + modifiers.setValue(MOD_ELEMENT_TYPE, XML::getProperty(node, "element", 0)); + } modifiers.setValue(MOD_LIFETIME, XML::getProperty(node, "lifetime", 0) * 10); + //TODO: add child nodes for these modifiers (additive and factor) modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_MIN, XML::getProperty(node, "attack-min", 0)); modifiers.setAttributeValue(BASE_ATTR_PHY_ATK_DELTA, XML::getProperty(node, "attack-delta", 0)); modifiers.setAttributeValue(BASE_ATTR_HP, XML::getProperty(node, "hp", 0)); @@ -127,15 +193,15 @@ void ItemManager::reload() if (maxPerSlot == 0) { - LOG_WARN("Item Manager: Missing max_per_slot property for " + LOG_WARN("Item Manager: Missing max-per-slot property for " "item " << id << " in " << itemReferenceFile << '.'); maxPerSlot = 1; } - if (itemType > ITEM_USABLE && itemType < ITEM_EQUIPMENT_PROJECTILE && + if (itemType > ITEM_USABLE && itemType < ITEM_EQUIPMENT_AMMO && maxPerSlot != 1) { - LOG_WARN("Item Manager: Setting max_per_slot property to 1 for " + LOG_WARN("Item Manager: Setting max-per-slot property to 1 for " "equipment " << id << " in " << itemReferenceFile << '.'); maxPerSlot = 1; } |