diff options
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/beinginfo.cpp | 4 | ||||
-rw-r--r-- | src/resources/beinginfo.h | 6 | ||||
-rw-r--r-- | src/resources/itemdb.cpp | 22 | ||||
-rw-r--r-- | src/resources/iteminfo.cpp | 28 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 34 | ||||
-rw-r--r-- | src/resources/monsterdb.cpp | 5 | ||||
-rw-r--r-- | src/resources/spritedef.cpp | 117 | ||||
-rw-r--r-- | src/resources/spritedef.h | 41 |
8 files changed, 84 insertions, 173 deletions
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp index c9447283..e8824391 100644 --- a/src/resources/beinginfo.cpp +++ b/src/resources/beinginfo.cpp @@ -90,13 +90,13 @@ const std::string &BeingInfo::getSound(SoundEvent event) const const Attack *BeingInfo::getAttack(int type) const { - static Attack *empty = new Attack(ACTION_ATTACK, "", ""); + static Attack *empty = new Attack(SpriteAction::ATTACK, "", ""); Attacks::const_iterator i = mAttacks.find(type); return (i == mAttacks.end()) ? empty : (*i).second; } -void BeingInfo::addAttack(int id, SpriteAction action, +void BeingInfo::addAttack(int id, std::string action, const std::string &particleEffect, const std::string &missileParticle) { diff --git a/src/resources/beinginfo.h b/src/resources/beinginfo.h index 8485ac6c..52390976 100644 --- a/src/resources/beinginfo.h +++ b/src/resources/beinginfo.h @@ -32,11 +32,11 @@ #include <vector> struct Attack { - SpriteAction action; + std::string action; std::string particleEffect; std::string missileParticle; - Attack(SpriteAction action, std::string particleEffect, + Attack(std::string action, std::string particleEffect, std::string missileParticle) { this->action = action; @@ -95,7 +95,7 @@ class BeingInfo const std::string &getSound(SoundEvent event) const; - void addAttack(int id, SpriteAction action, + void addAttack(int id, std::string action, const std::string &particleEffect, const std::string &missileParticle); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index cbccc4cd..a8eed123 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -85,22 +85,6 @@ static ItemType itemTypeFromString(const std::string &name, int id = 0) else return ITEM_UNUSABLE; } -static WeaponType weaponTypeFromString(const 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; -} - static std::string normalized(const std::string &name) { std::string normalized = name; @@ -153,7 +137,7 @@ void ItemDB::load() std::string name = XML::getProperty(node, "name", ""); std::string image = XML::getProperty(node, "image", ""); std::string description = XML::getProperty(node, "description", ""); - int weaponType = weaponTypeFromString(XML::getProperty(node, "weapon-type", "")); + std::string attackAction = XML::getProperty(node, "attack-action", ""); int attackRange = XML::getProperty(node, "attack-range", 0); std::string missileParticle = XML::getProperty(node, "missile-particle", ""); @@ -167,7 +151,7 @@ void ItemDB::load() itemInfo->setType(itemTypeFromString(typeStr)); itemInfo->setView(view); itemInfo->setWeight(weight); - itemInfo->setWeaponType(weaponType); + itemInfo->setAttackAction(attackAction); itemInfo->setAttackRange(attackRange); itemInfo->setMissileParticle(missileParticle); @@ -231,7 +215,7 @@ void ItemDB::load() } } - if (weaponType > 0) + if (!attackAction.empty()) if (attackRange == 0) logger->log("ItemDB: Missing attack range from weapon %i!", id); diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index 9c275f96..1cd3c546 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -41,30 +41,12 @@ const std::string &ItemInfo::getSprite(Gender gender) const } } -void ItemInfo::setWeaponType(int type) +void ItemInfo::setAttackAction(std::string attackAction) { - // See server item.hpp file for type values. - switch (type) - { - case WPNTYPE_NONE: - mWeaponAttackType = ACTION_DEFAULT; - break; - case WPNTYPE_KNIFE: - case WPNTYPE_SWORD: - mWeaponAttackType = ACTION_ATTACK_STAB; - break; - case WPNTYPE_THROWN: - mWeaponAttackType = ACTION_ATTACK_THROW; - break; - case WPNTYPE_BOW: - mWeaponAttackType = ACTION_ATTACK_BOW; - break; - case WPNTYPE_POLEARM: - mWeaponAttackType = ACTION_ATTACK_SWING; - break; - default: - mWeaponAttackType = ACTION_ATTACK; - } + if (attackAction.empty()) + mAttackAction = SpriteAction::ATTACK; // (Equal to unarmed animation) + else + mAttackAction = attackAction; } void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 1f27ae66..ac747e33 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -90,24 +90,6 @@ enum ItemType }; /** - * Enumeration of available weapon's types. - */ -enum WeaponType -{ - WPNTYPE_NONE = 0, - WPNTYPE_KNIFE, - WPNTYPE_SWORD, - WPNTYPE_POLEARM, - WPNTYPE_STAFF, - WPNTYPE_WHIP, - WPNTYPE_BOW, - WPNTYPE_SHOOTING, - WPNTYPE_MACE, - WPNTYPE_AXE, - WPNTYPE_THROWN -}; - -/** * Defines a class for storing item infos. This includes information used when * the item is equipped. */ @@ -122,7 +104,7 @@ class ItemInfo mWeight(0), mView(0), mId(0), - mWeaponAttackType(ACTION_DEFAULT) + mAttackAction(SpriteAction::INVALID) { } @@ -180,15 +162,15 @@ class ItemInfo const std::string &getSprite(Gender gender) const; - void setWeaponType(int); + void setAttackAction(std::string attackAction); // Handlers for seting and getting the string used for particles when attacking void setMissileParticle(std::string s) { mMissileParticle = s; } std::string getMissileParticle() const { return mMissileParticle; } - SpriteAction getWeaponAttackType() const - { return mWeaponAttackType; } + std::string getAttackAction() const + { return mAttackAction; } int getAttackRange() const { return mAttackRange; } @@ -211,8 +193,12 @@ class ItemInfo int mView; /**< Item ID of how this item looks. */ int mId; /**< Item ID */ - // Equipment related members - SpriteAction mWeaponAttackType; /**< Attack type, in case of weapon. */ + // Equipment related members. + /** Attack type, in case of weapon. + * See SpriteAction in spritedef.h for more info. + * Attack action sub-types (bow, sword, ...) are defined in items.xml. + */ + std::string mAttackAction; int mAttackRange; /**< Attack range, will be zero if non weapon. */ // Particle to be shown when weapon attacks diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index ed062acf..6bc64a89 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -126,8 +126,9 @@ void MonsterDB::load() const int id = XML::getProperty(spriteNode, "id", 0); const std::string particleEffect = XML::getProperty( spriteNode, "particle-effect", ""); - SpriteAction spriteAction = SpriteDef::makeSpriteAction( - XML::getProperty(spriteNode, "action", "attack")); + const std::string spriteAction = XML::getProperty(spriteNode, + "action", + "attack"); const std::string missileParticle = XML::getProperty( spriteNode, "missile-particle", ""); currentInfo->addAttack(id, spriteAction, diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 32fb5757..97c9ab48 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -39,13 +39,13 @@ SpriteReference *SpriteReference::Empty = new SpriteReference( paths.getStringValue("spriteErrorFile"), 0); -Action *SpriteDef::getAction(SpriteAction action) const +Action *SpriteDef::getAction(std::string action) const { Actions::const_iterator i = mActions.find(action); if (i == mActions.end()) { - logger->log("Warning: no action \"%u\" defined!", action); + logger->log("Warning: no action \"%s\" defined!", action.c_str()); return NULL; } @@ -84,22 +84,29 @@ SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) return def; } +void SpriteDef::substituteAction(std::string complete, std::string with) +{ + if (mActions.find(complete) == mActions.end()) + { + Actions::iterator i = mActions.find(with); + if (i != mActions.end()) + { + mActions[complete] = i->second; + } + } +} + void SpriteDef::substituteActions() { - substituteAction(ACTION_STAND, ACTION_DEFAULT); - substituteAction(ACTION_WALK, ACTION_STAND); - substituteAction(ACTION_WALK, ACTION_RUN); - substituteAction(ACTION_ATTACK, ACTION_STAND); - substituteAction(ACTION_ATTACK_SWING, ACTION_ATTACK); - substituteAction(ACTION_ATTACK_STAB, ACTION_ATTACK_SWING); - substituteAction(ACTION_ATTACK_BOW, ACTION_ATTACK_STAB); - substituteAction(ACTION_ATTACK_THROW, ACTION_ATTACK_SWING); - substituteAction(ACTION_CAST_MAGIC, ACTION_ATTACK_SWING); - substituteAction(ACTION_USE_ITEM, ACTION_CAST_MAGIC); - substituteAction(ACTION_SIT, ACTION_STAND); - substituteAction(ACTION_SLEEP, ACTION_SIT); - substituteAction(ACTION_HURT, ACTION_STAND); - substituteAction(ACTION_DEAD, ACTION_HURT); + substituteAction(SpriteAction::STAND, SpriteAction::DEFAULT); + substituteAction(SpriteAction::MOVE, SpriteAction::STAND); + substituteAction(SpriteAction::ATTACK, SpriteAction::STAND); + substituteAction(SpriteAction::CAST_MAGIC, SpriteAction::ATTACK); + substituteAction(SpriteAction::USE_ITEM, SpriteAction::CAST_MAGIC); + substituteAction(SpriteAction::SIT, SpriteAction::STAND); + substituteAction(SpriteAction::SLEEP, SpriteAction::SIT); + substituteAction(SpriteAction::HURT, SpriteAction::STAND); + substituteAction(SpriteAction::DEAD, SpriteAction::HURT); } void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, @@ -171,20 +178,19 @@ void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) } ImageSet *imageSet = si->second; - SpriteAction actionType = makeSpriteAction(actionName); - if (actionType == ACTION_INVALID) + if (actionName == SpriteAction::INVALID) { logger->log("Warning: Unknown action \"%s\" defined in %s", actionName.c_str(), getIdPath().c_str()); return; } Action *action = new Action; - mActions[actionType] = action; + mActions[actionName] = action; // When first action set it as default direction - if (mActions.empty()) + if (mActions.size() == 1) { - mActions[ACTION_DEFAULT] = action; + mActions[SpriteAction::DEFAULT] = action; } // Load animations @@ -297,18 +303,6 @@ void SpriteDef::includeSprite(xmlNodePtr includeNode) loadSprite(rootNode, 0); } -void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) -{ - if (mActions.find(complete) == mActions.end()) - { - Actions::iterator i = mActions.find(with); - if (i != mActions.end()) - { - mActions[complete] = i->second; - } - } -} - SpriteDef::~SpriteDef() { // Actions are shared, so ensure they are deleted only once. @@ -332,63 +326,6 @@ SpriteDef::~SpriteDef() } } -SpriteAction SpriteDef::makeSpriteAction(const std::string &action) -{ - if (action.empty() || action == "default") - return ACTION_DEFAULT; - - if (action == "stand") - return ACTION_STAND; - else if (action == "walk") - return ACTION_WALK; - else if (action == "run") - return ACTION_RUN; - else if (action == "attack") - return ACTION_ATTACK; - else if (action == "attack_swing") - return ACTION_ATTACK_SWING; - else if (action == "attack_stab") - return ACTION_ATTACK_STAB; - else if (action == "attack_bow") - return ACTION_ATTACK_BOW; - else if (action == "attack_throw") - return ACTION_ATTACK_THROW; - else if (action == "special0") - return ACTION_SPECIAL_0; - else if (action == "special1") - return ACTION_SPECIAL_1; - else if (action == "special2") - return ACTION_SPECIAL_2; - else if (action == "special3") - return ACTION_SPECIAL_3; - else if (action == "special4") - return ACTION_SPECIAL_4; - else if (action == "special5") - return ACTION_SPECIAL_5; - else if (action == "special6") - return ACTION_SPECIAL_6; - else if (action == "special7") - return ACTION_SPECIAL_7; - else if (action == "special8") - return ACTION_SPECIAL_8; - else if (action == "special9") - return ACTION_SPECIAL_9; - else if (action == "cast_magic") - return ACTION_CAST_MAGIC; - else if (action == "use_item") - return ACTION_USE_ITEM; - else if (action == "sit") - return ACTION_SIT; - else if (action == "sleep") - return ACTION_SLEEP; - else if (action == "hurt") - return ACTION_HURT; - else if (action == "dead") - return ACTION_DEAD; - else - return ACTION_INVALID; -} - SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction) { if (direction.empty() || direction == "default") diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index bc9ae45f..16b8c0c8 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -54,7 +54,7 @@ struct SpriteDisplay }; typedef std::list<SpriteReference*>::const_iterator SpriteRefs; - +#if 0 enum SpriteAction { ACTION_DEFAULT = 0, @@ -84,7 +84,33 @@ enum SpriteAction ACTION_DEAD, ACTION_INVALID }; - +#endif +#if 1 // Aim to be reached +/* + * Remember those are the main action. + * Action subtypes, e.g.: "attack_bow" are to be passed by items.xml after + * an ACTION_ATTACK call. + * Which special to be use to to be passed with the USE_SPECIAL call. + * Running, walking, ... is a sub-type of moving. + * ... + * Please don't add hard-coded subtypes here! + */ +namespace SpriteAction +{ + static const std::string DEFAULT = "stand"; + static const std::string STAND = "stand"; + static const std::string SIT = "sit"; + static const std::string SLEEP = "sleep"; + static const std::string DEAD = "dead"; + static const std::string MOVE = "walk"; + static const std::string ATTACK = "attack"; + static const std::string HURT = "hurt"; + static const std::string USE_SPECIAL = "special"; + static const std::string CAST_MAGIC = "magic"; + static const std::string USE_ITEM = "item"; + static const std::string INVALID = ""; +}; +#endif enum SpriteDirection { DIRECTION_DEFAULT = 0, @@ -109,12 +135,7 @@ class SpriteDef : public Resource /** * Returns the specified action. */ - Action *getAction(SpriteAction action) const; - - /** - * Converts a string into a SpriteAction enum. - */ - static SpriteAction makeSpriteAction(const std::string &action); + Action *getAction(std::string action) const; /** * Converts a string into a SpriteDirection enum. @@ -170,12 +191,12 @@ class SpriteDef : public Resource * When there are no animations defined for the action "complete", its * animations become a copy of those of the action "with". */ - void substituteAction(SpriteAction complete, SpriteAction with); + void substituteAction(std::string complete, std::string with); typedef std::map<std::string, ImageSet*> ImageSets; typedef ImageSets::iterator ImageSetIterator; - typedef std::map<SpriteAction, Action*> Actions; + typedef std::map<std::string, Action*> Actions; ImageSets mImageSets; Actions mActions; |