diff options
author | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-10 02:22:59 +0000 |
---|---|---|
committer | Philipp Sehmisch <tmw@crushnet.org> | 2007-12-10 02:22:59 +0000 |
commit | e961be5bfd29ad3f44f948828981cb3ab07f25a7 (patch) | |
tree | 5464d14635191407eb24c7ad76b1b218b33016d2 | |
parent | 43b986ceffdb436d8850a876bd485c9a3eea8cdd (diff) | |
download | mana-e961be5bfd29ad3f44f948828981cb3ab07f25a7.tar.gz mana-e961be5bfd29ad3f44f948828981cb3ab07f25a7.tar.bz2 mana-e961be5bfd29ad3f44f948828981cb3ab07f25a7.tar.xz mana-e961be5bfd29ad3f44f948828981cb3ab07f25a7.zip |
Simplified player subsprite handling by treating equipment, hairstyle and base sprites alike. Implementing female hairstyles is now a purely content-sided task.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/being.cpp | 11 | ||||
-rw-r--r-- | src/being.h | 5 | ||||
-rw-r--r-- | src/net/beinghandler.cpp | 24 | ||||
-rw-r--r-- | src/net/charserverhandler.cpp | 8 | ||||
-rw-r--r-- | src/net/equipmenthandler.cpp | 4 | ||||
-rw-r--r-- | src/player.cpp | 49 | ||||
-rw-r--r-- | src/player.h | 9 |
8 files changed, 58 insertions, 60 deletions
@@ -1,3 +1,11 @@ +2007-12-10 Philipp Sehmisch <tmw@crushnet.org> + + * src/being.cpp, src/being.h, src/net/beinghandler.cpp, + src/net/charserverhandler.cpp, src/net/equipmenthandler.cpp, + src/player.cpp, src/player.h, data/items.xml: Simplified player + subsprite handling by treating equipment, hairstyle and base + sprites alike. This also enables gender-specific hairstyles. + 2007-12-09 Philipp Sehmisch <tmw@crushnet.org> * data/graphics/sprites/head-funkywinter.png, diff --git a/src/being.cpp b/src/being.cpp index a9dfa93c..a562389f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -57,12 +57,13 @@ Being::Being(int id, int job, Map *map): mDirection(DOWN), mMap(NULL), mEquippedWeapon(NULL), - mHairStyle(0), mHairColor(0), + mHairStyle(1), mHairColor(0), mGender(2), mSpeechTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), - mEquipmentSpriteIDs(VECTOREND_SPRITE, 0) + mSpriteIDs(VECTOREND_SPRITE, 0), + mSpriteColors(VECTOREND_SPRITE, "") { setMap(map); @@ -134,9 +135,11 @@ Being::setHairStyle(int style, int color) } void -Being::setVisibleEquipment(int slot, int id) +Being::setSprite(int slot, int id, std::string color) { - mEquipmentSpriteIDs[slot] = id; + assert (slot >= BASE_SPRITE && slot < VECTOREND_SPRITE); + mSpriteIDs[slot] = id; + mSpriteColors[slot] = color; } void diff --git a/src/being.h b/src/being.h index 2770dd6b..bdcabbdf 100644 --- a/src/being.h +++ b/src/being.h @@ -204,7 +204,7 @@ class Being : public Sprite * Sets visible equipments for this being. */ virtual void - setVisibleEquipment(int slot, int id); + setSprite(int slot, int id, std::string color = ""); /** * Sets the gender of this being. @@ -386,7 +386,8 @@ class Being : public Sprite Sint32 mPx, mPy; /**< Pixel coordinates */ std::vector<AnimatedSprite*> mSprites; - std::vector<int> mEquipmentSpriteIDs; + std::vector<int> mSpriteIDs; + std::vector<std::string> mSpriteColors; std::list<Particle *> mChildParticleEffects; private: diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index e54a66ed..6100e76f 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -108,9 +108,9 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; hairStyle = msg->readInt16(); - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::WEAPON_SPRITE, msg->readInt16()); - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::BOTTOMCLOTHES_SPRITE, msg->readInt16()); if (msg->getId() == SMSG_BEING_MOVE) @@ -121,8 +121,8 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt16(); // shield headTop = msg->readInt16(); headMid = msg->readInt16(); - dstBeing->setVisibleEquipment(Being::HAT_SPRITE, headTop); - dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, headMid); + dstBeing->setSprite(Being::HAT_SPRITE, headTop); + dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); hairColor = msg->readInt16(); msg->readInt16(); // unknown msg->readInt16(); // head dir @@ -263,18 +263,18 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setHairStyle(id, -1); break; case 2: - dstBeing->setVisibleEquipment(Being::WEAPON_SPRITE, id); + dstBeing->setSprite(Being::WEAPON_SPRITE, id); break; case 3: // Change lower headgear for eAthena, pants for us - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::BOTTOMCLOTHES_SPRITE, id); break; case 4: // Change upper headgear for eAthena, hat for us - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::HAT_SPRITE, id); break; case 5: // Change middle headgear for eathena, armor for us - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::TOPCLOTHES_SPRITE, id); break; case 6: @@ -316,7 +316,7 @@ void BeingHandler::handleMessage(MessageIn *msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; hairStyle = msg->readInt16(); - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::WEAPON_SPRITE, msg->readInt16()); msg->readInt16(); // item id 2 headBottom = msg->readInt16(); @@ -337,10 +337,10 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt8(); // karma dstBeing->setGender(1 - msg->readInt8()); // gender dstBeing->setHairStyle(hairStyle, hairColor); - dstBeing->setVisibleEquipment( + dstBeing->setSprite( Being::BOTTOMCLOTHES_SPRITE, headBottom); - dstBeing->setVisibleEquipment(Being::HAT_SPRITE, headTop); - dstBeing->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, headMid); + dstBeing->setSprite(Being::HAT_SPRITE, headTop); + dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); if (msg->getId() == SMSG_PLAYER_MOVE) { diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 063be212..5c275b94 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -204,13 +204,13 @@ LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot) msg.readInt16(); // class int hairStyle = msg.readInt16(); Uint16 weapon = msg.readInt16(); - tempPlayer->setVisibleEquipment(Being::WEAPON_SPRITE, weapon); + tempPlayer->setSprite(Being::WEAPON_SPRITE, weapon); tempPlayer->mLevel = msg.readInt16(); msg.readInt16(); // skill point - tempPlayer->setVisibleEquipment(Being::BOTTOMCLOTHES_SPRITE, msg.readInt16()); // head bottom + tempPlayer->setSprite(Being::BOTTOMCLOTHES_SPRITE, msg.readInt16()); // head bottom msg.readInt16(); // shield - tempPlayer->setVisibleEquipment(Being::HAT_SPRITE, msg.readInt16()); // head option top - tempPlayer->setVisibleEquipment(Being::TOPCLOTHES_SPRITE, msg.readInt16()); // head option mid + tempPlayer->setSprite(Being::HAT_SPRITE, msg.readInt16()); // head option top + tempPlayer->setSprite(Being::TOPCLOTHES_SPRITE, msg.readInt16()); // head option mid int hairColor = msg.readInt16(); tempPlayer->setHairStyle(hairStyle, hairColor); msg.readInt16(); // unknown diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index 60be5c74..84da9365 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -141,7 +141,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) if (!being) break; - being->setVisibleEquipment(Being::WEAPON_SPRITE, itemId); + being->setSprite(Being::WEAPON_SPRITE, itemId); break; case SMSG_PLAYER_UNEQUIP: @@ -184,7 +184,7 @@ void EquipmentHandler::handleMessage(MessageIn *msg) case 536: case 1200: case 1201: - player_node->setVisibleEquipment(Being::WEAPON_SPRITE, 0); + player_node->setSprite(Being::WEAPON_SPRITE, 0); // TODO: Why this break? Shouldn't a weapon be // unequipped in inventory too? break; diff --git a/src/player.cpp b/src/player.cpp index d1999c89..a1a86587 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -94,39 +94,26 @@ void Player::setGender(int gender) gender = 0; } + if (gender != mGender) { - // Reload base sprite - AnimatedSprite *newBaseSprite; - if (gender == 0) - { - newBaseSprite = AnimatedSprite::load( - "graphics/sprites/player_male_base.xml"); - } - else - { - newBaseSprite = AnimatedSprite::load( - "graphics/sprites/player_female_base.xml"); - } + Being::setGender(gender); - delete mSprites[BASE_SPRITE]; - mSprites[BASE_SPRITE] = newBaseSprite; + setSprite(Being::BASE_SPRITE, -100); /* Human base sprite. When implementing + * different races remove this line + * and set the base sprite when setting + * the race of the player character. + */ - // Reload equipment + // Reload all subsprites for (int i = 1; i < VECTOREND_SPRITE; i++) { - if (i != HAIR_SPRITE && mEquipmentSpriteIDs.at(i) != 0) + if (mSpriteIDs.at(i) != 0) { - AnimatedSprite *newEqSprite = AnimatedSprite::load( - "graphics/sprites/" + ItemDB::get( - mEquipmentSpriteIDs.at(i)).getSprite(gender)); - delete mSprites[i]; - mSprites[i] = newEqSprite; + setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i)); } } } - - Being::setGender(gender); } void Player::setHairStyle(int style, int color) @@ -151,20 +138,12 @@ void Player::setHairStyle(int style, int color) "#460850,611967,e7b4ae", // dark purple }; - AnimatedSprite *newHairSprite = AnimatedSprite::load - (strprintf("graphics/sprites/hairstyle%d%s.xml|%s", - style, - "", //(mGender == 0) ? "-male" : "-female", - colors[color])); - if (newHairSprite) - newHairSprite->setDirection(getSpriteDirection()); - delete mSprites[HAIR_SPRITE]; - mSprites[HAIR_SPRITE] = newHairSprite; + setSprite(HAIR_SPRITE, style * -1, colors[color]); setAction(mAction); } -void Player::setVisibleEquipment(int slot, int id) +void Player::setSprite(int slot, int id, std::string color) { // id = 0 means unequip if (id == 0) @@ -175,7 +154,7 @@ void Player::setVisibleEquipment(int slot, int id) else { AnimatedSprite *equipmentSprite = AnimatedSprite::load( - "graphics/sprites/" + ItemDB::get(id).getSprite(mGender)); + "graphics/sprites/" + ItemDB::get(id).getSprite(mGender) + "|" + color); if (equipmentSprite) equipmentSprite->setDirection(getSpriteDirection()); @@ -191,5 +170,5 @@ void Player::setVisibleEquipment(int slot, int id) setAction(mAction); } - Being::setVisibleEquipment(slot, id); + Being::setSprite(slot, id, color); } diff --git a/src/player.h b/src/player.h index 1526d2bc..e9a30da0 100644 --- a/src/player.h +++ b/src/player.h @@ -53,6 +53,13 @@ class Player : public Being /** * Sets the hair style and color for this player. + * + * Only for convenience in 0.0 client. When porting + * this to the trunk remove this function and + * call setSprite directly instead. The server should + * provide the hair ID and coloring in the same way + * it does for other equipment pieces. + * */ void setHairStyle(int style, int color); @@ -60,7 +67,7 @@ class Player : public Being * Sets visible equipments for this player. */ virtual void - setVisibleEquipment(int slot, int id); + setSprite(int slot, int id, std::string color = ""); }; #endif |