Commit ae898aa1a5175b2b08f7248e4cd89bf61bc8e4be
- Diff rendering mode:
- inline
- side by side
src/animatedsprite.cpp
(3 / 3)
|   | |||
| 51 | 51 | mSprite->incRef(); | |
| 52 | 52 | ||
| 53 | 53 | // Play the stand animation by default | |
| 54 | play(ACTION_STAND); | ||
| 54 | play(SpriteAction::STAND); | ||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | AnimatedSprite *AnimatedSprite::load(const std::string &filename, int variant) | |
| … | … | ||
| 81 | 81 | return ret; | |
| 82 | 82 | } | |
| 83 | 83 | ||
| 84 | bool AnimatedSprite::play(SpriteAction spriteAction) | ||
| 84 | bool AnimatedSprite::play(std::string spriteAction) | ||
| 85 | 85 | { | |
| 86 | 86 | Action *action = mSprite->getAction(spriteAction); | |
| 87 | 87 | if (!action) | |
| … | … | ||
| 122 | 122 | if (!updateCurrentAnimation(dt)) | |
| 123 | 123 | { | |
| 124 | 124 | // Animation finished, reset to default | |
| 125 | play(ACTION_STAND); | ||
| 125 | play(SpriteAction::STAND); | ||
| 126 | 126 | } | |
| 127 | 127 | ||
| 128 | 128 | // Make sure something actually changed |
src/animatedsprite.h
(1 / 1)
|   | |||
| 56 | 56 | ||
| 57 | 57 | bool reset(); | |
| 58 | 58 | ||
| 59 | bool play(SpriteAction action); | ||
| 59 | bool play(std::string action); | ||
| 60 | 60 | ||
| 61 | 61 | bool update(int time); | |
| 62 | 62 |
src/being.cpp
(22 / 18)
|   | |||
| 249 | 249 | mPath = path; | |
| 250 | 250 | ||
| 251 | 251 | if ((Net::getNetworkType() == ServerInfo::TMWATHENA) && | |
| 252 | mAction != WALK && mAction != DEAD) | ||
| 252 | mAction != MOVE && mAction != DEAD) | ||
| 253 | 253 | { | |
| 254 | 254 | nextTile(); | |
| 255 | 255 | mActionTime = tick_time; | |
| … | … | ||
| 550 | 550 | ||
| 551 | 551 | void Being::setAction(Action action, int attackType) | |
| 552 | 552 | { | |
| 553 | SpriteAction currentAction = ACTION_INVALID; | ||
| 553 | std::string currentAction = SpriteAction::INVALID; | ||
| 554 | 554 | ||
| 555 | 555 | switch (action) | |
| 556 | 556 | { | |
| 557 | case WALK: | ||
| 558 | currentAction = ACTION_WALK; | ||
| 557 | case MOVE: | ||
| 558 | currentAction = SpriteAction::MOVE; | ||
| 559 | // Note: When adding a run action, | ||
| 560 | // Differentiate walk and run with action name, | ||
| 561 | // while using only the ACTION_MOVE. | ||
| 559 | 562 | break; | |
| 560 | 563 | case SIT: | |
| 561 | currentAction = ACTION_SIT; | ||
| 564 | currentAction = SpriteAction::SIT; | ||
| 562 | 565 | break; | |
| 563 | 566 | case ATTACK: | |
| 564 | 567 | if (mEquippedWeapon) | |
| 565 | 568 | { | |
| 566 | currentAction = mEquippedWeapon->getWeaponAttackType(); | ||
| 569 | currentAction = mEquippedWeapon->getAttackAction(); | ||
| 567 | 570 | reset(); | |
| 568 | 571 | } | |
| 569 | 572 | else | |
| … | … | ||
| 601 | 601 | ||
| 602 | 602 | break; | |
| 603 | 603 | case HURT: | |
| 604 | //currentAction = ACTION_HURT; // Buggy: makes the player stop | ||
| 604 | //currentAction = SpriteAction::HURT;// Buggy: makes the player stop | ||
| 605 | 605 | // attacking and unable to attack | |
| 606 | // again until he moves | ||
| 606 | // again until he moves. | ||
| 607 | // TODO: fix this! | ||
| 607 | 608 | break; | |
| 608 | 609 | case DEAD: | |
| 609 | currentAction = ACTION_DEAD; | ||
| 610 | currentAction = SpriteAction::DEAD; | ||
| 610 | 611 | sound.playSfx(mInfo->getSound(SOUND_EVENT_DIE)); | |
| 611 | 612 | break; | |
| 612 | 613 | case STAND: | |
| 613 | currentAction = ACTION_STAND; | ||
| 614 | currentAction = SpriteAction::STAND; | ||
| 614 | 615 | break; | |
| 615 | 616 | } | |
| 616 | 617 | ||
| 617 | if (currentAction != ACTION_INVALID) | ||
| 618 | if (currentAction != SpriteAction::INVALID) | ||
| 618 | 619 | { | |
| 619 | 620 | play(currentAction); | |
| 620 | 621 | mAction = action; | |
| 621 | 622 | } | |
| 622 | 623 | ||
| 623 | if (currentAction != ACTION_WALK) | ||
| 624 | if (currentAction != SpriteAction::MOVE) | ||
| 624 | 625 | mActionTime = tick_time; | |
| 625 | 626 | } | |
| 626 | 627 | ||
| … | … | ||
| 683 | 683 | ||
| 684 | 684 | mX = pos.x; | |
| 685 | 685 | mY = pos.y; | |
| 686 | setAction(WALK); | ||
| 686 | setAction(MOVE); | ||
| 687 | 687 | mActionTime += (int)(mWalkSpeed.x / 10); | |
| 688 | 688 | } | |
| 689 | 689 | ||
| … | … | ||
| 747 | 747 | else | |
| 748 | 748 | setPosition(mPos + diff); | |
| 749 | 749 | ||
| 750 | if (mAction != WALK) | ||
| 751 | setAction(WALK); | ||
| 750 | if (mAction != MOVE) | ||
| 751 | setAction(MOVE); | ||
| 752 | 752 | ||
| 753 | 753 | // Update the player sprite direction. | |
| 754 | 754 | // N.B.: We only change this if the distance is more than one pixel. | |
| … | … | ||
| 777 | 777 | // remove it and go to the next one. | |
| 778 | 778 | mPath.pop_front(); | |
| 779 | 779 | } | |
| 780 | else if (mAction == WALK) | ||
| 780 | else if (mAction == MOVE) | ||
| 781 | 781 | { | |
| 782 | 782 | setAction(STAND); | |
| 783 | 783 | } | |
| … | … | ||
| 794 | 794 | case HURT: | |
| 795 | 795 | break; | |
| 796 | 796 | ||
| 797 | case WALK: | ||
| 797 | case MOVE: | ||
| 798 | 798 | if ((int) ((get_elapsed_time(mActionTime) * frameCount) | |
| 799 | 799 | / getWalkSpeed().x) >= frameCount) | |
| 800 | 800 | nextTile(); | |
| … | … | ||
| 945 | 945 | int Being::getOffset(char pos, char neg) const | |
| 946 | 946 | { | |
| 947 | 947 | // Check whether we're walking in the requested direction | |
| 948 | if (mAction != WALK || !(mDirection & (pos | neg))) | ||
| 948 | if (mAction != MOVE || !(mDirection & (pos | neg))) | ||
| 949 | 949 | return 0; | |
| 950 | 950 | ||
| 951 | 951 | int offset = 0; |
src/being.h
(1 / 1)
|   | |||
| 73 | 73 | enum Action | |
| 74 | 74 | { | |
| 75 | 75 | STAND, | |
| 76 | WALK, | ||
| 76 | MOVE, | ||
| 77 | 77 | ATTACK, | |
| 78 | 78 | SIT, | |
| 79 | 79 | DEAD, |
src/compoundsprite.cpp
(1 / 1)
|   | |||
| 67 | 67 | return ret; | |
| 68 | 68 | } | |
| 69 | 69 | ||
| 70 | bool CompoundSprite::play(SpriteAction action) | ||
| 70 | bool CompoundSprite::play(std::string action) | ||
| 71 | 71 | { | |
| 72 | 72 | bool ret = false; | |
| 73 | 73 |
src/compoundsprite.h
(1 / 1)
|   | |||
| 36 | 36 | ||
| 37 | 37 | virtual bool reset(); | |
| 38 | 38 | ||
| 39 | virtual bool play(SpriteAction action); | ||
| 39 | virtual bool play(std::string action); | ||
| 40 | 40 | ||
| 41 | 41 | virtual bool update(int time); | |
| 42 | 42 |
src/gui/skilldialog.h
(2 / 2)
|   | |||
| 19 | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 20 | 20 | */ | |
| 21 | 21 | ||
| 22 | #ifndef SKILL_H | ||
| 23 | #define SKILL_H | ||
| 22 | #ifndef SKILLDIALOG_H | ||
| 23 | #define SKILLDIALOG_H | ||
| 24 | 24 | ||
| 25 | 25 | #include "guichanfwd.h" | |
| 26 | 26 |
src/imagesprite.h
(1 / 1)
|   | |||
| 37 | 37 | bool reset() | |
| 38 | 38 | { return false; } | |
| 39 | 39 | ||
| 40 | bool play(SpriteAction action) | ||
| 40 | bool play(std::string action) | ||
| 41 | 41 | { return false; } | |
| 42 | 42 | ||
| 43 | 43 | bool update(int time) |
src/localplayer.cpp
(4 / 4)
|   | |||
| 776 | 776 | mWalkingDir = dir; | |
| 777 | 777 | ||
| 778 | 778 | // If we're not already walking, start walking. | |
| 779 | if (mAction != WALK && dir) | ||
| 779 | if (mAction != MOVE && dir) | ||
| 780 | 780 | { | |
| 781 | 781 | startWalking(dir); | |
| 782 | 782 | } | |
| 783 | else if (mAction == WALK && (Net::getNetworkType() == ServerInfo::MANASERV)) | ||
| 783 | else if (mAction == MOVE && (Net::getNetworkType() == ServerInfo::MANASERV)) | ||
| 784 | 784 | { | |
| 785 | 785 | nextTile(dir); | |
| 786 | 786 | } | |
| … | … | ||
| 793 | 793 | if (!mMap || !dir) | |
| 794 | 794 | return; | |
| 795 | 795 | ||
| 796 | if (mAction == WALK && !mPath.empty()) | ||
| 796 | if (mAction == MOVE && !mPath.empty()) | ||
| 797 | 797 | { | |
| 798 | 798 | // Just finish the current action, otherwise we get out of sync | |
| 799 | 799 | if (Net::getNetworkType() == ServerInfo::MANASERV) | |
| … | … | ||
| 848 | 848 | ||
| 849 | 849 | void LocalPlayer::stopWalking(bool sendToServer) | |
| 850 | 850 | { | |
| 851 | if (mAction == WALK && mWalkingDir) | ||
| 851 | if (mAction == MOVE && mWalkingDir) | ||
| 852 | 852 | { | |
| 853 | 853 | mWalkingDir = 0; | |
| 854 | 854 | mLocalWalkTime = 0; |
|   | |||
| 641 | 641 | x = msg.readInt16(); | |
| 642 | 642 | y = msg.readInt16(); | |
| 643 | 643 | dstBeing->setTileCoords(x, y); | |
| 644 | if (dstBeing->getCurrentAction() == Being::WALK) | ||
| 644 | if (dstBeing->getCurrentAction() == Being::MOVE) | ||
| 645 | 645 | dstBeing->setAction(Being::STAND); | |
| 646 | 646 | } | |
| 647 | 647 | } |
src/resources/beinginfo.cpp
(2 / 2)
|   | |||
| 90 | 90 | ||
| 91 | 91 | const Attack *BeingInfo::getAttack(int type) const | |
| 92 | 92 | { | |
| 93 | static Attack *empty = new Attack(ACTION_ATTACK, "", ""); | ||
| 93 | static Attack *empty = new Attack(SpriteAction::ATTACK, "", ""); | ||
| 94 | 94 | ||
| 95 | 95 | Attacks::const_iterator i = mAttacks.find(type); | |
| 96 | 96 | return (i == mAttacks.end()) ? empty : (*i).second; | |
| 97 | 97 | } | |
| 98 | 98 | ||
| 99 | void BeingInfo::addAttack(int id, SpriteAction action, | ||
| 99 | void BeingInfo::addAttack(int id, std::string action, | ||
| 100 | 100 | const std::string &particleEffect, | |
| 101 | 101 | const std::string &missileParticle) | |
| 102 | 102 | { |
src/resources/beinginfo.h
(3 / 3)
|   | |||
| 32 | 32 | #include <vector> | |
| 33 | 33 | ||
| 34 | 34 | struct Attack { | |
| 35 | SpriteAction action; | ||
| 35 | std::string action; | ||
| 36 | 36 | std::string particleEffect; | |
| 37 | 37 | std::string missileParticle; | |
| 38 | 38 | ||
| 39 | Attack(SpriteAction action, std::string particleEffect, | ||
| 39 | Attack(std::string action, std::string particleEffect, | ||
| 40 | 40 | std::string missileParticle) | |
| 41 | 41 | { | |
| 42 | 42 | this->action = action; | |
| … | … | ||
| 95 | 95 | ||
| 96 | 96 | const std::string &getSound(SoundEvent event) const; | |
| 97 | 97 | ||
| 98 | void addAttack(int id, SpriteAction action, | ||
| 98 | void addAttack(int id, std::string action, | ||
| 99 | 99 | const std::string &particleEffect, | |
| 100 | 100 | const std::string &missileParticle); | |
| 101 | 101 |
src/resources/itemdb.cpp
(3 / 19)
|   | |||
| 85 | 85 | else return ITEM_UNUSABLE; | |
| 86 | 86 | } | |
| 87 | 87 | ||
| 88 | static WeaponType weaponTypeFromString(const std::string &name) | ||
| 89 | { | ||
| 90 | if (name=="knife") return WPNTYPE_KNIFE; | ||
| 91 | else if (name=="sword") return WPNTYPE_SWORD; | ||
| 92 | else if (name=="polearm") return WPNTYPE_POLEARM; | ||
| 93 | else if (name=="staff") return WPNTYPE_STAFF; | ||
| 94 | else if (name=="whip") return WPNTYPE_WHIP; | ||
| 95 | else if (name=="bow") return WPNTYPE_BOW; | ||
| 96 | else if (name=="shooting") return WPNTYPE_SHOOTING; | ||
| 97 | else if (name=="mace") return WPNTYPE_MACE; | ||
| 98 | else if (name=="axe") return WPNTYPE_AXE; | ||
| 99 | else if (name=="thrown") return WPNTYPE_THROWN; | ||
| 100 | |||
| 101 | else return WPNTYPE_NONE; | ||
| 102 | } | ||
| 103 | |||
| 104 | 88 | static std::string normalized(const std::string &name) | |
| 105 | 89 | { | |
| 106 | 90 | std::string normalized = name; | |
| … | … | ||
| 137 | 137 | std::string name = XML::getProperty(node, "name", ""); | |
| 138 | 138 | std::string image = XML::getProperty(node, "image", ""); | |
| 139 | 139 | std::string description = XML::getProperty(node, "description", ""); | |
| 140 | int weaponType = weaponTypeFromString(XML::getProperty(node, "weapon-type", "")); | ||
| 140 | std::string attackAction = XML::getProperty(node, "attack-action", ""); | ||
| 141 | 141 | int attackRange = XML::getProperty(node, "attack-range", 0); | |
| 142 | 142 | std::string missileParticle = XML::getProperty(node, "missile-particle", ""); | |
| 143 | 143 | ||
| … | … | ||
| 151 | 151 | itemInfo->setType(itemTypeFromString(typeStr)); | |
| 152 | 152 | itemInfo->setView(view); | |
| 153 | 153 | itemInfo->setWeight(weight); | |
| 154 | itemInfo->setWeaponType(weaponType); | ||
| 154 | itemInfo->setAttackAction(attackAction); | ||
| 155 | 155 | itemInfo->setAttackRange(attackRange); | |
| 156 | 156 | itemInfo->setMissileParticle(missileParticle); | |
| 157 | 157 | ||
| … | … | ||
| 215 | 215 | } | |
| 216 | 216 | } | |
| 217 | 217 | ||
| 218 | if (weaponType > 0) | ||
| 218 | if (!attackAction.empty()) | ||
| 219 | 219 | if (attackRange == 0) | |
| 220 | 220 | logger->log("ItemDB: Missing attack range from weapon %i!", id); | |
| 221 | 221 |
src/resources/iteminfo.cpp
(5 / 23)
|   | |||
| 41 | 41 | } | |
| 42 | 42 | } | |
| 43 | 43 | ||
| 44 | void ItemInfo::setWeaponType(int type) | ||
| 44 | void ItemInfo::setAttackAction(std::string attackAction) | ||
| 45 | 45 | { | |
| 46 | // See server item.hpp file for type values. | ||
| 47 | switch (type) | ||
| 48 | { | ||
| 49 | case WPNTYPE_NONE: | ||
| 50 | mWeaponAttackType = ACTION_DEFAULT; | ||
| 51 | break; | ||
| 52 | case WPNTYPE_KNIFE: | ||
| 53 | case WPNTYPE_SWORD: | ||
| 54 | mWeaponAttackType = ACTION_ATTACK_STAB; | ||
| 55 | break; | ||
| 56 | case WPNTYPE_THROWN: | ||
| 57 | mWeaponAttackType = ACTION_ATTACK_THROW; | ||
| 58 | break; | ||
| 59 | case WPNTYPE_BOW: | ||
| 60 | mWeaponAttackType = ACTION_ATTACK_BOW; | ||
| 61 | break; | ||
| 62 | case WPNTYPE_POLEARM: | ||
| 63 | mWeaponAttackType = ACTION_ATTACK_SWING; | ||
| 64 | break; | ||
| 65 | default: | ||
| 66 | mWeaponAttackType = ACTION_ATTACK; | ||
| 67 | } | ||
| 46 | if (attackAction.empty()) | ||
| 47 | mAttackAction = SpriteAction::ATTACK; // (Equal to unarmed animation) | ||
| 48 | else | ||
| 49 | mAttackAction = attackAction; | ||
| 68 | 50 | } | |
| 69 | 51 | ||
| 70 | 52 | void ItemInfo::addSound(EquipmentSoundEvent event, const std::string &filename) |
src/resources/iteminfo.h
(10 / 24)
|   | |||
| 90 | 90 | }; | |
| 91 | 91 | ||
| 92 | 92 | /** | |
| 93 | * Enumeration of available weapon's types. | ||
| 94 | */ | ||
| 95 | enum WeaponType | ||
| 96 | { | ||
| 97 | WPNTYPE_NONE = 0, | ||
| 98 | WPNTYPE_KNIFE, | ||
| 99 | WPNTYPE_SWORD, | ||
| 100 | WPNTYPE_POLEARM, | ||
| 101 | WPNTYPE_STAFF, | ||
| 102 | WPNTYPE_WHIP, | ||
| 103 | WPNTYPE_BOW, | ||
| 104 | WPNTYPE_SHOOTING, | ||
| 105 | WPNTYPE_MACE, | ||
| 106 | WPNTYPE_AXE, | ||
| 107 | WPNTYPE_THROWN | ||
| 108 | }; | ||
| 109 | |||
| 110 | /** | ||
| 111 | 93 | * Defines a class for storing item infos. This includes information used when | |
| 112 | 94 | * the item is equipped. | |
| 113 | 95 | */ | |
| … | … | ||
| 104 | 104 | mWeight(0), | |
| 105 | 105 | mView(0), | |
| 106 | 106 | mId(0), | |
| 107 | mWeaponAttackType(ACTION_DEFAULT) | ||
| 107 | mAttackAction(SpriteAction::INVALID) | ||
| 108 | 108 | { | |
| 109 | 109 | } | |
| 110 | 110 | ||
| … | … | ||
| 162 | 162 | ||
| 163 | 163 | const std::string &getSprite(Gender gender) const; | |
| 164 | 164 | ||
| 165 | void setWeaponType(int); | ||
| 165 | void setAttackAction(std::string attackAction); | ||
| 166 | 166 | ||
| 167 | 167 | // Handlers for seting and getting the string used for particles when attacking | |
| 168 | 168 | void setMissileParticle(std::string s) { mMissileParticle = s; } | |
| 169 | 169 | ||
| 170 | 170 | std::string getMissileParticle() const { return mMissileParticle; } | |
| 171 | 171 | ||
| 172 | SpriteAction getWeaponAttackType() const | ||
| 173 | { return mWeaponAttackType; } | ||
| 172 | std::string getAttackAction() const | ||
| 173 | { return mAttackAction; } | ||
| 174 | 174 | ||
| 175 | 175 | int getAttackRange() const | |
| 176 | 176 | { return mAttackRange; } | |
| … | … | ||
| 193 | 193 | int mView; /**< Item ID of how this item looks. */ | |
| 194 | 194 | int mId; /**< Item ID */ | |
| 195 | 195 | ||
| 196 | // Equipment related members | ||
| 197 | SpriteAction mWeaponAttackType; /**< Attack type, in case of weapon. */ | ||
| 196 | // Equipment related members. | ||
| 197 | /** Attack type, in case of weapon. | ||
| 198 | * See SpriteAction in spritedef.h for more info. | ||
| 199 | * Attack action sub-types (bow, sword, ...) are defined in items.xml. | ||
| 200 | */ | ||
| 201 | std::string mAttackAction; | ||
| 198 | 202 | int mAttackRange; /**< Attack range, will be zero if non weapon. */ | |
| 199 | 203 | ||
| 200 | 204 | // Particle to be shown when weapon attacks |
src/resources/monsterdb.cpp
(3 / 2)
|   | |||
| 126 | 126 | const int id = XML::getProperty(spriteNode, "id", 0); | |
| 127 | 127 | const std::string particleEffect = XML::getProperty( | |
| 128 | 128 | spriteNode, "particle-effect", ""); | |
| 129 | SpriteAction spriteAction = SpriteDef::makeSpriteAction( | ||
| 130 | XML::getProperty(spriteNode, "action", "attack")); | ||
| 129 | const std::string spriteAction = XML::getProperty(spriteNode, | ||
| 130 | "action", | ||
| 131 | "attack"); | ||
| 131 | 132 | const std::string missileParticle = XML::getProperty( | |
| 132 | 133 | spriteNode, "missile-particle", ""); | |
| 133 | 134 | currentInfo->addAttack(id, spriteAction, |
src/resources/spritedef.cpp
(27 / 90)
|   | |||
| 39 | 39 | SpriteReference *SpriteReference::Empty = new SpriteReference( | |
| 40 | 40 | paths.getStringValue("spriteErrorFile"), 0); | |
| 41 | 41 | ||
| 42 | Action *SpriteDef::getAction(SpriteAction action) const | ||
| 42 | Action *SpriteDef::getAction(std::string action) const | ||
| 43 | 43 | { | |
| 44 | 44 | Actions::const_iterator i = mActions.find(action); | |
| 45 | 45 | ||
| 46 | 46 | if (i == mActions.end()) | |
| 47 | 47 | { | |
| 48 | logger->log("Warning: no action \"%u\" defined!", action); | ||
| 48 | logger->log("Warning: no action \"%s\" defined!", action.c_str()); | ||
| 49 | 49 | return NULL; | |
| 50 | 50 | } | |
| 51 | 51 | ||
| … | … | ||
| 84 | 84 | return def; | |
| 85 | 85 | } | |
| 86 | 86 | ||
| 87 | void SpriteDef::substituteAction(std::string complete, std::string with) | ||
| 88 | { | ||
| 89 | if (mActions.find(complete) == mActions.end()) | ||
| 90 | { | ||
| 91 | Actions::iterator i = mActions.find(with); | ||
| 92 | if (i != mActions.end()) | ||
| 93 | { | ||
| 94 | mActions[complete] = i->second; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 87 | 99 | void SpriteDef::substituteActions() | |
| 88 | 100 | { | |
| 89 | substituteAction(ACTION_STAND, ACTION_DEFAULT); | ||
| 90 | substituteAction(ACTION_WALK, ACTION_STAND); | ||
| 91 | substituteAction(ACTION_WALK, ACTION_RUN); | ||
| 92 | substituteAction(ACTION_ATTACK, ACTION_STAND); | ||
| 93 | substituteAction(ACTION_ATTACK_SWING, ACTION_ATTACK); | ||
| 94 | substituteAction(ACTION_ATTACK_STAB, ACTION_ATTACK_SWING); | ||
| 95 | substituteAction(ACTION_ATTACK_BOW, ACTION_ATTACK_STAB); | ||
| 96 | substituteAction(ACTION_ATTACK_THROW, ACTION_ATTACK_SWING); | ||
| 97 | substituteAction(ACTION_CAST_MAGIC, ACTION_ATTACK_SWING); | ||
| 98 | substituteAction(ACTION_USE_ITEM, ACTION_CAST_MAGIC); | ||
| 99 | substituteAction(ACTION_SIT, ACTION_STAND); | ||
| 100 | substituteAction(ACTION_SLEEP, ACTION_SIT); | ||
| 101 | substituteAction(ACTION_HURT, ACTION_STAND); | ||
| 102 | substituteAction(ACTION_DEAD, ACTION_HURT); | ||
| 101 | substituteAction(SpriteAction::STAND, SpriteAction::DEFAULT); | ||
| 102 | substituteAction(SpriteAction::MOVE, SpriteAction::STAND); | ||
| 103 | substituteAction(SpriteAction::ATTACK, SpriteAction::STAND); | ||
| 104 | substituteAction(SpriteAction::CAST_MAGIC, SpriteAction::ATTACK); | ||
| 105 | substituteAction(SpriteAction::USE_ITEM, SpriteAction::CAST_MAGIC); | ||
| 106 | substituteAction(SpriteAction::SIT, SpriteAction::STAND); | ||
| 107 | substituteAction(SpriteAction::SLEEP, SpriteAction::SIT); | ||
| 108 | substituteAction(SpriteAction::HURT, SpriteAction::STAND); | ||
| 109 | substituteAction(SpriteAction::DEAD, SpriteAction::HURT); | ||
| 103 | 110 | } | |
| 104 | 111 | ||
| 105 | 112 | void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, | |
| … | … | ||
| 178 | 178 | } | |
| 179 | 179 | ImageSet *imageSet = si->second; | |
| 180 | 180 | ||
| 181 | SpriteAction actionType = makeSpriteAction(actionName); | ||
| 182 | if (actionType == ACTION_INVALID) | ||
| 181 | if (actionName == SpriteAction::INVALID) | ||
| 183 | 182 | { | |
| 184 | 183 | logger->log("Warning: Unknown action \"%s\" defined in %s", | |
| 185 | 184 | actionName.c_str(), getIdPath().c_str()); | |
| 186 | 185 | return; | |
| 187 | 186 | } | |
| 188 | 187 | Action *action = new Action; | |
| 189 | mActions[actionType] = action; | ||
| 188 | mActions[actionName] = action; | ||
| 190 | 189 | ||
| 191 | 190 | // When first action set it as default direction | |
| 192 | if (mActions.empty()) | ||
| 191 | if (mActions.size() == 1) | ||
| 193 | 192 | { | |
| 194 | mActions[ACTION_DEFAULT] = action; | ||
| 193 | mActions[SpriteAction::DEFAULT] = action; | ||
| 195 | 194 | } | |
| 196 | 195 | ||
| 197 | 196 | // Load animations | |
| … | … | ||
| 303 | 303 | loadSprite(rootNode, 0); | |
| 304 | 304 | } | |
| 305 | 305 | ||
| 306 | void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) | ||
| 307 | { | ||
| 308 | if (mActions.find(complete) == mActions.end()) | ||
| 309 | { | ||
| 310 | Actions::iterator i = mActions.find(with); | ||
| 311 | if (i != mActions.end()) | ||
| 312 | { | ||
| 313 | mActions[complete] = i->second; | ||
| 314 | } | ||
| 315 | } | ||
| 316 | } | ||
| 317 | |||
| 318 | 306 | SpriteDef::~SpriteDef() | |
| 319 | 307 | { | |
| 320 | 308 | // Actions are shared, so ensure they are deleted only once. | |
| … | … | ||
| 324 | 324 | { | |
| 325 | 325 | i->second->decRef(); | |
| 326 | 326 | } | |
| 327 | } | ||
| 328 | |||
| 329 | SpriteAction SpriteDef::makeSpriteAction(const std::string &action) | ||
| 330 | { | ||
| 331 | if (action.empty() || action == "default") | ||
| 332 | return ACTION_DEFAULT; | ||
| 333 | |||
| 334 | if (action == "stand") | ||
| 335 | return ACTION_STAND; | ||
| 336 | else if (action == "walk") | ||
| 337 | return ACTION_WALK; | ||
| 338 | else if (action == "run") | ||
| 339 | return ACTION_RUN; | ||
| 340 | else if (action == "attack") | ||
| 341 | return ACTION_ATTACK; | ||
| 342 | else if (action == "attack_swing") | ||
| 343 | return ACTION_ATTACK_SWING; | ||
| 344 | else if (action == "attack_stab") | ||
| 345 | return ACTION_ATTACK_STAB; | ||
| 346 | else if (action == "attack_bow") | ||
| 347 | return ACTION_ATTACK_BOW; | ||
| 348 | else if (action == "attack_throw") | ||
| 349 | return ACTION_ATTACK_THROW; | ||
| 350 | else if (action == "special0") | ||
| 351 | return ACTION_SPECIAL_0; | ||
| 352 | else if (action == "special1") | ||
| 353 | return ACTION_SPECIAL_1; | ||
| 354 | else if (action == "special2") | ||
| 355 | return ACTION_SPECIAL_2; | ||
| 356 | else if (action == "special3") | ||
| 357 | return ACTION_SPECIAL_3; | ||
| 358 | else if (action == "special4") | ||
| 359 | return ACTION_SPECIAL_4; | ||
| 360 | else if (action == "special5") | ||
| 361 | return ACTION_SPECIAL_5; | ||
| 362 | else if (action == "special6") | ||
| 363 | return ACTION_SPECIAL_6; | ||
| 364 | else if (action == "special7") | ||
| 365 | return ACTION_SPECIAL_7; | ||
| 366 | else if (action == "special8") | ||
| 367 | return ACTION_SPECIAL_8; | ||
| 368 | else if (action == "special9") | ||
| 369 | return ACTION_SPECIAL_9; | ||
| 370 | else if (action == "cast_magic") | ||
| 371 | return ACTION_CAST_MAGIC; | ||
| 372 | else if (action == "use_item") | ||
| 373 | return ACTION_USE_ITEM; | ||
| 374 | else if (action == "sit") | ||
| 375 | return ACTION_SIT; | ||
| 376 | else if (action == "sleep") | ||
| 377 | return ACTION_SLEEP; | ||
| 378 | else if (action == "hurt") | ||
| 379 | return ACTION_HURT; | ||
| 380 | else if (action == "dead") | ||
| 381 | return ACTION_DEAD; | ||
| 382 | else | ||
| 383 | return ACTION_INVALID; | ||
| 384 | 327 | } | |
| 385 | 328 | ||
| 386 | 329 | SpriteDirection SpriteDef::makeSpriteDirection(const std::string &direction) |
src/resources/spritedef.h
(31 / 10)
|   | |||
| 54 | 54 | }; | |
| 55 | 55 | ||
| 56 | 56 | typedef std::list<SpriteReference*>::const_iterator SpriteRefs; | |
| 57 | |||
| 57 | #if 0 | ||
| 58 | 58 | enum SpriteAction | |
| 59 | 59 | { | |
| 60 | 60 | ACTION_DEFAULT = 0, | |
| … | … | ||
| 84 | 84 | ACTION_DEAD, | |
| 85 | 85 | ACTION_INVALID | |
| 86 | 86 | }; | |
| 87 | |||
| 87 | #endif | ||
| 88 | #if 1 // Aim to be reached | ||
| 89 | /* | ||
| 90 | * Remember those are the main action. | ||
| 91 | * Action subtypes, e.g.: "attack_bow" are to be passed by items.xml after | ||
| 92 | * an ACTION_ATTACK call. | ||
| 93 | * Which special to be use to to be passed with the USE_SPECIAL call. | ||
| 94 | * Running, walking, ... is a sub-type of moving. | ||
| 95 | * ... | ||
| 96 | * Please don't add hard-coded subtypes here! | ||
| 97 | */ | ||
| 98 | namespace SpriteAction | ||
| 99 | { | ||
| 100 | static const std::string DEFAULT = "stand"; | ||
| 101 | static const std::string STAND = "stand"; | ||
| 102 | static const std::string SIT = "sit"; | ||
| 103 | static const std::string SLEEP = "sleep"; | ||
| 104 | static const std::string DEAD = "dead"; | ||
| 105 | static const std::string MOVE = "walk"; | ||
| 106 | static const std::string ATTACK = "attack"; | ||
| 107 | static const std::string HURT = "hurt"; | ||
| 108 | static const std::string USE_SPECIAL = "special"; | ||
| 109 | static const std::string CAST_MAGIC = "magic"; | ||
| 110 | static const std::string USE_ITEM = "item"; | ||
| 111 | static const std::string INVALID = ""; | ||
| 112 | }; | ||
| 113 | #endif | ||
| 88 | 114 | enum SpriteDirection | |
| 89 | 115 | { | |
| 90 | 116 | DIRECTION_DEFAULT = 0, | |
| … | … | ||
| 135 | 135 | /** | |
| 136 | 136 | * Returns the specified action. | |
| 137 | 137 | */ | |
| 138 | Action *getAction(SpriteAction action) const; | ||
| 138 | Action *getAction(std::string action) const; | ||
| 139 | 139 | ||
| 140 | 140 | /** | |
| 141 | * Converts a string into a SpriteAction enum. | ||
| 142 | */ | ||
| 143 | static SpriteAction makeSpriteAction(const std::string &action); | ||
| 144 | |||
| 145 | /** | ||
| 146 | 141 | * Converts a string into a SpriteDirection enum. | |
| 147 | 142 | */ | |
| 148 | 143 | static SpriteDirection | |
| … | … | ||
| 191 | 191 | * When there are no animations defined for the action "complete", its | |
| 192 | 192 | * animations become a copy of those of the action "with". | |
| 193 | 193 | */ | |
| 194 | void substituteAction(SpriteAction complete, SpriteAction with); | ||
| 194 | void substituteAction(std::string complete, std::string with); | ||
| 195 | 195 | ||
| 196 | 196 | typedef std::map<std::string, ImageSet*> ImageSets; | |
| 197 | 197 | typedef ImageSets::iterator ImageSetIterator; | |
| 198 | 198 | ||
| 199 | typedef std::map<SpriteAction, Action*> Actions; | ||
| 199 | typedef std::map<std::string, Action*> Actions; | ||
| 200 | 200 | ||
| 201 | 201 | ImageSets mImageSets; | |
| 202 | 202 | Actions mActions; |
src/sprite.h
(1 / 1)
|   | |||
| 43 | 43 | * | |
| 44 | 44 | * @returns true if the sprite changed, false otherwise | |
| 45 | 45 | */ | |
| 46 | virtual bool play(SpriteAction action) = 0; | ||
| 46 | virtual bool play(std::string action) = 0; | ||
| 47 | 47 | ||
| 48 | 48 | /** | |
| 49 | 49 | * Inform the animation of the passed time so that it can output the |
src/statuseffect.cpp
(4 / 4)
|   | |||
| 73 | 73 | paths.getStringValue("sprites") + mIcon); | |
| 74 | 74 | if (false && sprite) | |
| 75 | 75 | { | |
| 76 | sprite->play(ACTION_DEFAULT); | ||
| 76 | sprite->play(SpriteAction::DEFAULT); | ||
| 77 | 77 | sprite->reset(); | |
| 78 | 78 | } | |
| 79 | 79 | return sprite; | |
| 80 | 80 | } | |
| 81 | 81 | } | |
| 82 | 82 | ||
| 83 | SpriteAction StatusEffect::getAction() | ||
| 83 | std::string StatusEffect::getAction() | ||
| 84 | 84 | { | |
| 85 | 85 | if (mAction.empty()) | |
| 86 | return ACTION_INVALID; | ||
| 86 | return SpriteAction::INVALID; | ||
| 87 | 87 | else | |
| 88 | return SpriteDef::makeSpriteAction(mAction); | ||
| 88 | return mAction; | ||
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | 91 |
src/statuseffect.h
(2 / 2)
|   | |||
| 56 | 56 | AnimatedSprite *getIcon(); | |
| 57 | 57 | ||
| 58 | 58 | /** | |
| 59 | * Retrieves an action to perform, or ACTION_INVALID | ||
| 59 | * Retrieves an action to perform, or SpriteAction::INVALID | ||
| 60 | 60 | */ | |
| 61 | SpriteAction getAction(); | ||
| 61 | std::string getAction(); | ||
| 62 | 62 | ||
| 63 | 63 | /** | |
| 64 | 64 | * Determines whether the particle effect should be restarted when the |

