diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 147 | ||||
-rw-r--r-- | src/being.h | 104 | ||||
-rw-r--r-- | src/flooritem.cpp | 4 | ||||
-rw-r--r-- | src/flooritem.h | 6 | ||||
-rw-r--r-- | src/gui/charcreatedialog.cpp | 46 | ||||
-rw-r--r-- | src/gui/charcreatedialog.h | 8 | ||||
-rw-r--r-- | src/gui/charselectdialog.h | 3 | ||||
-rw-r--r-- | src/gui/playerbox.cpp | 6 | ||||
-rw-r--r-- | src/localplayer.cpp | 27 | ||||
-rw-r--r-- | src/localplayer.h | 10 | ||||
-rw-r--r-- | src/map.cpp | 8 | ||||
-rw-r--r-- | src/map.h | 12 | ||||
-rw-r--r-- | src/monster.cpp | 62 | ||||
-rw-r--r-- | src/monster.h | 15 | ||||
-rw-r--r-- | src/net/ea/beinghandler.cpp | 91 | ||||
-rw-r--r-- | src/net/ea/charserverhandler.cpp | 25 | ||||
-rw-r--r-- | src/net/ea/partyhandler.cpp | 2 | ||||
-rw-r--r-- | src/net/logindata.h | 2 | ||||
-rw-r--r-- | src/net/tmwserv/beinghandler.cpp | 11 | ||||
-rw-r--r-- | src/net/tmwserv/charserverhandler.cpp | 4 | ||||
-rw-r--r-- | src/npc.cpp | 36 | ||||
-rw-r--r-- | src/npc.h | 9 | ||||
-rw-r--r-- | src/player.cpp | 127 | ||||
-rw-r--r-- | src/player.h | 71 | ||||
-rw-r--r-- | src/playerrelations.cpp | 2 | ||||
-rw-r--r-- | src/resources/iteminfo.h | 2 |
26 files changed, 365 insertions, 475 deletions
diff --git a/src/being.cpp b/src/being.cpp index 23b87e6c..37ae2200 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -77,18 +77,11 @@ Being::Being(int id, int job, Map *map): mSpriteDirection(DIRECTION_DOWN), mMap(NULL), mParticleEffects(config.getValue("particleeffects", 1)), + mDispName(0), + mShowName(false), mEquippedWeapon(NULL), -#ifdef TMWSERV_SUPPORT - mHairStyle(0), -#else - mHairStyle(1), -#endif - mHairColor(0), - mGender(GENDER_UNSPECIFIED), + mText(0), mStunMode(0), - mSprites(VECTOREND_SPRITE, NULL), - mSpriteIDs(VECTOREND_SPRITE, 0), - mSpriteColors(VECTOREND_SPRITE, ""), mStatusParticleEffects(&mStunParticleEffects, false), mChildParticleEffects(&mStatusParticleEffects, false), mMustResetParticles(false), @@ -105,8 +98,8 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble; - mNameColor = &guiPalette->getColor(Palette::CHAT); - mText = 0; + mNameColor = &guiPalette->getColor(Palette::NPC); + mTextColor = &guiPalette->getColor(Palette::CHAT); } Being::~Being() @@ -120,6 +113,7 @@ Being::~Being() setMap(NULL); delete mSpeechBubble; + delete mDispName; delete mText; } @@ -218,19 +212,6 @@ void Being::setPath(const Path &path) #endif } -void Being::setHairStyle(int style, int color) -{ - mHairStyle = style < 0 ? mHairStyle : style % mNumberOfHairstyles; - mHairColor = color < 0 ? mHairColor : color % ColorDB::size(); -} - -void Being::setSprite(int slot, int id, const std::string &color) -{ - assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE); - mSpriteIDs[slot] = id; - mSpriteColors[slot] = color; -} - void Being::setSpeech(const std::string &text, int time) { mSpeech = text; @@ -368,17 +349,42 @@ void Being::handleAttack(Being *victim, int damage, AttackType type) #endif } +void Being::setName(const std::string &name) +{ + mName = name; + + if (getShowName()) + showName(); +} + +void Being::setShowName(bool doShowName) +{ + bool oldShow = mShowName; + mShowName = doShowName; + + if (doShowName != oldShow) + { + if (doShowName) + showName(); + else + { + delete mDispName; + mDispName = 0; + } + } +} + void Being::setMap(Map *map) { // Remove sprite from potential previous map if (mMap) - mMap->removeSprite(mSpriteIterator); + mMap->removeSprite(mMapSprite); mMap = map; // Add sprite to potential new map if (mMap) - mSpriteIterator = mMap->addSprite(this); + mMapSprite = mMap->addSprite(this); // Clear particle effect list because child particles became invalid mChildParticleEffects.clear(); @@ -408,11 +414,9 @@ void Being::setAction(Action action, int attackType) else currentAction = ACTION_ATTACK; - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - mSprites[i]->reset(); - } + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->reset(); break; case HURT: //currentAction = ACTION_HURT; // Buggy: makes the player stop @@ -429,11 +433,9 @@ void Being::setAction(Action action, int attackType) if (currentAction != ACTION_INVALID) { - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - mSprites[i]->play(currentAction); - } + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->play(currentAction); mAction = action; } } @@ -461,11 +463,9 @@ void Being::setDirection(Uint8 direction) dir = DIRECTION_LEFT; mSpriteDirection = dir; - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - mSprites[i]->setDirection(dir); - } + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->setDirection(dir); } #ifdef EATHENA_SUPPORT @@ -573,11 +573,9 @@ void Being::logic() if (mUsedTargetCursor) mUsedTargetCursor->update(tick_time * 10); - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - mSprites[i]->update(tick_time * 10); - } + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->update(tick_time * 10); // Restart status/particle effects, if needed if (mMustResetParticles) { @@ -605,13 +603,9 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const if (mUsedTargetCursor) mUsedTargetCursor->draw(graphics, px, py); - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - { - mSprites[i]->draw(graphics, px, py); - } - } + for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->draw(graphics, px, py); } void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) @@ -650,7 +644,7 @@ void Being::drawSpeech(int offsetX, int offsetY) mText = NULL; } - mSpeechBubble->setCaption(showName ? mName : "", mNameColor); + mSpeechBubble->setCaption(showName ? mName : "", mTextColor); mSpeechBubble->setText(mSpeech, showName); mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2), @@ -680,11 +674,6 @@ void Being::drawSpeech(int offsetX, int offsetY) } } -Being::Type Being::getType() const -{ - return UNKNOWN; -} - void Being::setStatusEffectBlock(int offset, Uint16 newEffects) { for (int i = 0; i < STATUS_EFFECTS; i++) { @@ -765,7 +754,13 @@ int Being::getOffset(char pos, char neg) const int Being::getWidth() const { - if (AnimatedSprite *base = mSprites[BASE_SPRITE]) + AnimatedSprite *base = NULL; + + for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) + if ((base = (*it))) + break; + + if (base) return std::max(base->getWidth(), DEFAULT_WIDTH); else return DEFAULT_WIDTH; @@ -773,7 +768,13 @@ int Being::getWidth() const int Being::getHeight() const { - if (AnimatedSprite *base = mSprites[BASE_SPRITE]) + AnimatedSprite *base = NULL; + + for (SpriteConstIterator it = mSprites.begin(); it != mSprites.end(); it++) + if ((base = (*it))) + break; + + if (base) return std::max(base->getHeight(), DEFAULT_HEIGHT); else return DEFAULT_HEIGHT; @@ -875,9 +876,27 @@ void Being::internalTriggerEffect(int effectId, bool sfx, bool gfx) } } -int Being::getHairStyleCount() +void Being::updateCoords() { - return mNumberOfHairstyles; + if (mDispName) + { + mDispName->adviseXY(getPixelX(), getPixelY()); + } +} + +void Being::flashName(int time) +{ + if (mDispName) + mDispName->flash(time); +} + +void Being::showName() +{ + delete mDispName; + mDispName = 0; + + mDispName = new FlashText(mName, getPixelX(), getPixelY(), + gcn::Graphics::CENTER, mNameColor); } void Being::load() diff --git a/src/being.h b/src/being.h index 6e90b39d..ad7f3459 100644 --- a/src/being.h +++ b/src/being.h @@ -46,11 +46,11 @@ #define SPEECH_MAX_TIME 1000 class AnimatedSprite; +class FlashText; +class Graphics; class Image; class ItemInfo; class Item; -class Map; -class Graphics; class Particle; class Position; class SimpleAnimation; @@ -59,16 +59,6 @@ class Text; class StatusEffect; -typedef std::list<Sprite*> Sprites; -typedef Sprites::iterator SpriteIterator; - -enum Gender -{ - GENDER_MALE = 0, - GENDER_FEMALE = 1, - GENDER_UNSPECIFIED = 2 -}; - class Being : public Sprite, public ConfigListener { public: @@ -95,29 +85,6 @@ class Being : public Sprite, public ConfigListener HURT }; - enum Sprite - { - BASE_SPRITE = 0, - SHOE_SPRITE, - BOTTOMCLOTHES_SPRITE, - TOPCLOTHES_SPRITE, -#ifdef EATHENA_SUPPORT - MISC1_SPRITE, - MISC2_SPRITE, -#endif - HAIR_SPRITE, - HAT_SPRITE, -#ifdef EATHENA_SUPPORT - CAPE_SPRITE, - GLOVES_SPRITE, -#endif - WEAPON_SPRITE, -#ifdef EATHENA_SUPPORT - SHIELD_SPRITE, -#endif - VECTOREND_SPRITE - }; - enum TargetCursorSize { TC_SMALL = 0, @@ -246,42 +213,17 @@ class Being : public Sprite, public ConfigListener * * @param name The name that should appear. */ - virtual void setName(const std::string &name) - { mName = name; } + virtual void setName(const std::string &name); - /** - * Gets the hair color for this being. - */ - int getHairColor() const { return mHairColor; } + const bool getShowName() const { return mShowName; } - /** - * Gets the hair style for this being. - */ - int getHairStyle() const { return mHairStyle; } + virtual void setShowName(bool doShowName); /** * Get the number of hairstyles implemented */ static int getNumOfHairstyles() { return mNumberOfHairstyles; } - /** - * Sets the hair style and color for this being. - */ - virtual void setHairStyle(int style, int color); - - /** - * Sets visible equipments for this being. - */ - virtual void setSprite(int slot, int id, - const std::string &color = ""); - - /** - * Sets the gender of this being. - */ - virtual void setGender(Gender gender) { mGender = gender; } - - Gender getGender() const { return mGender; } - #ifdef EATHENA_SUPPORT /** * Makes this being take the next step of his path. @@ -307,7 +249,7 @@ class Being : public Sprite, public ConfigListener /** * Returns the type of the being. */ - virtual Type getType() const; + virtual Type getType() const { return UNKNOWN; } /** * Sets the walk speed (in pixels per second). @@ -496,14 +438,14 @@ class Being : public Sprite, public ConfigListener internalTriggerEffect(effectId, false, true); } - static int getHairStyleCount(); - virtual AnimatedSprite *getSprite(int index) const { return mSprites[index]; } static void load(); - void optionChanged(const std::string &value) {} + virtual void optionChanged(const std::string &value) {} + + void flashName(int time); protected: /** @@ -512,9 +454,9 @@ class Being : public Sprite, public ConfigListener void setPath(const Path &path); /** - * Let the sub-classes react to a replacement. + * Updates name's location. */ - virtual void updateCoords() {} + virtual void updateCoords(); /** * Gets the way the object blocks pathfinding for other objects @@ -551,14 +493,23 @@ class Being : public Sprite, public ConfigListener */ virtual void handleStatusEffect(StatusEffect *effect, int effectId); + virtual void showName(); + int mId; /**< Unique sprite id */ Uint8 mDirection; /**< Facing direction */ Uint8 mSpriteDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ std::string mName; /**< Name of character */ - SpriteIterator mSpriteIterator; + MapSprite mMapSprite; bool mParticleEffects; /**< Whether to display particles or not */ + /** + * Holds a text object when the being displays it's name, 0 otherwise + */ + FlashText *mDispName; + const gcn::Color *mNameColor; + bool mShowName; + /** Engine-related infos about weapon. */ const ItemInfo *mEquippedWeapon; @@ -567,17 +518,14 @@ class Being : public Sprite, public ConfigListener Path mPath; std::string mSpeech; Text *mText; - int mHairStyle; - int mHairColor; - Gender mGender; + const gcn::Color *mTextColor; Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set<int> mStatusEffects; /**< set of active status effects */ - const gcn::Color *mNameColor; - - std::vector<AnimatedSprite*> mSprites; - std::vector<int> mSpriteIDs; - std::vector<std::string> mSpriteColors; + typedef std::vector<AnimatedSprite*> Sprites; + typedef Sprites::iterator SpriteIterator; + typedef Sprites::const_iterator SpriteConstIterator; + Sprites mSprites; ParticleList mStunParticleEffects; ParticleVector mStatusParticleEffects; ParticleList mChildParticleEffects; diff --git a/src/flooritem.cpp b/src/flooritem.cpp index b08258c1..9376dd73 100644 --- a/src/flooritem.cpp +++ b/src/flooritem.cpp @@ -41,13 +41,13 @@ FloorItem::FloorItem(int id, mItem = new Item(itemId); // Add ourselves to the map - mSpriteIterator = mMap->addSprite(this); + mMapSprite = mMap->addSprite(this); } FloorItem::~FloorItem() { // Remove ourselves from the map - mMap->removeSprite(mSpriteIterator); + mMap->removeSprite(mMapSprite); delete mItem; } diff --git a/src/flooritem.h b/src/flooritem.h index 99074943..61e88a70 100644 --- a/src/flooritem.h +++ b/src/flooritem.h @@ -24,14 +24,12 @@ #include <list> +#include "map.h" #include "sprite.h" class Graphics; class Image; class Item; -class Map; - -typedef std::list<Sprite*> Sprites; /** * An item lying on the floor. @@ -100,7 +98,7 @@ class FloorItem : public Sprite int mId; int mX, mY; Item *mItem; - Sprites::iterator mSpriteIterator; + MapSprite mMapSprite; Map *mMap; }; diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index e09eee55..7c2b0ed9 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -59,8 +59,9 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot): int numberOfHairColors = ColorDB::size(); - mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(), - rand() % numberOfHairColors); + mHairStyle = rand() % mPlayer->getNumOfHairstyles(); + mHairColor = rand() % numberOfHairColors; + updateHair(); mNameField = new TextField(""); mNameLabel = new Label(_("Name:")); @@ -153,7 +154,6 @@ CharCreateDialog::~CharCreateDialog() void CharCreateDialog::action(const gcn::ActionEvent &event) { - int numberOfColors = ColorDB::size(); if (event.getId() == "create") { if (getName().length() >= 4) @@ -168,8 +168,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) } Net::getCharHandler()->newCharacter(getName(), mSlot, - mFemale->isSelected(), mPlayer->getHairStyle(), - mPlayer->getHairColor(), atts); + mFemale->isSelected(), mHairStyle, + mHairColor, atts); } else { @@ -181,19 +181,25 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "cancel") scheduleDelete(); else if (event.getId() == "nextcolor") - mPlayer->setHairStyle(mPlayer->getHairStyle(), - (mPlayer->getHairColor() + 1) % numberOfColors); + { + mHairColor++; + updateHair(); + } else if (event.getId() == "prevcolor") - mPlayer->setHairStyle(mPlayer->getHairStyle(), - (mPlayer->getHairColor() + numberOfColors - 1) % - numberOfColors); + { + mHairColor--; + updateHair(); + } else if (event.getId() == "nextstyle") - mPlayer->setHairStyle(mPlayer->getHairStyle() + 1, - mPlayer->getHairColor()); + { + mHairStyle++; + updateHair(); + } else if (event.getId() == "prevstyle") - mPlayer->setHairStyle(mPlayer->getHairStyle() + - mPlayer->getNumOfHairstyles() - 1, - mPlayer->getHairColor()); + { + mHairStyle--; + updateHair(); + } else if (event.getId() == "statslider") { updateSliders(); } @@ -334,3 +340,13 @@ void CharCreateDialog::setFixedGender(bool fixed, Gender gender) mFemale->setEnabled(false); } } + +void CharCreateDialog::updateHair() +{ + mHairStyle %= Being::getNumOfHairstyles(); + + mHairColor %= ColorDB::size(); + + mPlayer->setSprite(Player::HAIR_SPRITE, + mHairStyle * -1, ColorDB::get(mHairColor)); +} diff --git a/src/gui/charcreatedialog.h b/src/gui/charcreatedialog.h index 5dbc6050..a30aadd3 100644 --- a/src/gui/charcreatedialog.h +++ b/src/gui/charcreatedialog.h @@ -22,7 +22,7 @@ #ifndef CHAR_CREATE_H #define CHAR_CREATE_H -#include "being.h" +#include "player.h" #include "guichanfwd.h" #include "lockedarray.h" @@ -34,7 +34,6 @@ #include <vector> class LocalPlayer; -class Player; class PlayerBox; /** @@ -82,6 +81,8 @@ class CharCreateDialog : public Window, public gcn::ActionListener */ void attemptCharCreate(); + void updateHair(); + gcn::TextField *mNameField; gcn::Label *mNameLabel; gcn::Button *mNextHairColorButton; @@ -108,6 +109,9 @@ class CharCreateDialog : public Window, public gcn::ActionListener Player *mPlayer; PlayerBox *mPlayerBox; + int mHairStyle; + int mHairColor; + int mSlot; }; diff --git a/src/gui/charselectdialog.h b/src/gui/charselectdialog.h index 06ce4b55..4427017e 100644 --- a/src/gui/charselectdialog.h +++ b/src/gui/charselectdialog.h @@ -24,7 +24,7 @@ #include "gui/widgets/window.h" -#include "being.h" +#include "player.h" #include "guichanfwd.h" #include "lockedarray.h" @@ -32,7 +32,6 @@ class LocalPlayer; class LoginData; -class Player; class PlayerBox; /** diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index d00194bd..9a1f4805 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -82,11 +82,11 @@ void PlayerBox::draw(gcn::Graphics *graphics) { // Draw character const int bs = getFrameSize(); -#ifdef TMWSERV_SUPPORT +//#ifdef TMWSERV_SUPPORT const int x = getWidth() / 2 + bs; const int y = getHeight() - bs - 8; mPlayer->draw(static_cast<Graphics*>(graphics), x, y); -#else +/*#else const int x = getWidth() / 2 - 16 + bs; const int y = getHeight() / 2 + bs; for (int i = 0; i < Being::VECTOREND_SPRITE; i++) @@ -96,7 +96,7 @@ void PlayerBox::draw(gcn::Graphics *graphics) mPlayer->getSprite(i)->draw(static_cast<Graphics*>(graphics), x, y); } } -#endif +#endif*/ } if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 57dc8981..8fbfe70a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -118,7 +118,12 @@ LocalPlayer::LocalPlayer(int id, int job, Map *map): mUpdateName = true; + mTextColor = &guiPalette->getColor(Palette::PLAYER); + mNameColor = &guiPalette->getColor(Palette::SELF); + initTargetCursor(); + + config.addListener("showownname", this); } LocalPlayer::~LocalPlayer() @@ -241,20 +246,6 @@ void LocalPlayer::setGMLevel(int level) setGM(true); } -void LocalPlayer::setName(const std::string &name) -{ - if (mName) - { - delete mName; - mName = 0; - } - - if (config.getValue("showownname", false) && mMapInitialized) - Player::setName(name); - else - Being::setName(name); -} - void LocalPlayer::nextStep() { // TODO: Fix picking up when reaching target (this method is obsolete) @@ -1087,3 +1078,11 @@ void LocalPlayer::addMessageToQueue(const std::string &message, { mMessages.push_back(MessagePair(message, color)); } + +void LocalPlayer::optionChanged(const std::string &value) +{ + if (value == "showownname") + { + setShowName(config.getValue("showownname", 1)); + } +} diff --git a/src/localplayer.h b/src/localplayer.h index fa0b8984..ff26e701 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -109,8 +109,6 @@ class LocalPlayer : public Player */ ~LocalPlayer(); - virtual void setName(const std::string &name); - virtual void logic(); virtual void setAction(Action action, int attackType = 0); @@ -361,9 +359,17 @@ class LocalPlayer : public Player void addMessageToQueue(const std::string &message, Palette::ColorType color = Palette::EXP_INFO); + /** + * Called when a option (set with config.addListener()) is changed + */ + void optionChanged(const std::string &value); + protected: virtual void handleStatusEffect(StatusEffect *effect, int effectId); + // Colors don't change for local player + virtual void updateColors() {} + void walk(unsigned char dir); bool mInStorage; /**< Whether storage is currently accessible */ diff --git a/src/map.cpp b/src/map.cpp index dbecda3d..5f6433c2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -123,7 +123,7 @@ Image* MapLayer::getTile(int x, int y) const void MapLayer::draw(Graphics *graphics, int startX, int startY, int endX, int endY, int scrollX, int scrollY, - const Sprites &sprites) const + const MapSprites &sprites) const { startX -= mX; startY -= mY; @@ -135,7 +135,7 @@ void MapLayer::draw(Graphics *graphics, int startX, int startY, if (endX > mWidth) endX = mWidth; if (endY > mHeight) endY = mHeight; - Sprites::const_iterator si = sprites.begin(); + MapSprites::const_iterator si = sprites.begin(); for (int y = startY; y < endY; y++) { @@ -467,13 +467,13 @@ MetaTile *Map::getMetaTile(int x, int y) const return &mMetaTiles[x + y * mWidth]; } -SpriteIterator Map::addSprite(Sprite *sprite) +MapSprite Map::addSprite(Sprite *sprite) { mSprites.push_front(sprite); return mSprites.begin(); } -void Map::removeSprite(SpriteIterator iterator) +void Map::removeSprite(MapSprite iterator) { mSprites.erase(iterator); } @@ -39,8 +39,8 @@ class Sprite; class Tileset; typedef std::vector<Tileset*> Tilesets; -typedef std::list<Sprite*> Sprites; -typedef Sprites::iterator SpriteIterator; +typedef std::list<Sprite*> MapSprites; +typedef MapSprites::iterator MapSprite; typedef std::vector<MapLayer*> Layers; /** @@ -128,7 +128,7 @@ class MapLayer int startX, int startY, int endX, int endY, int scrollX, int scrollY, - const Sprites &sprites) const; + const MapSprites &sprites) const; private: int mX, mY; @@ -266,12 +266,12 @@ class Map : public Properties /** * Adds a sprite to the map. */ - SpriteIterator addSprite(Sprite *sprite); + MapSprite addSprite(Sprite *sprite); /** * Removes a sprite from the map. */ - void removeSprite(SpriteIterator iterator); + void removeSprite(MapSprite iterator); /** * Adds a particle effect @@ -317,7 +317,7 @@ class Map : public Properties MetaTile *mMetaTiles; Layers mLayers; Tilesets mTilesets; - Sprites mSprites; + MapSprites mSprites; // Pathfinding members int mOnClosedList, mOnOpenList; diff --git a/src/monster.cpp b/src/monster.cpp index 3bdf1a62..cc2285fe 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -33,29 +33,24 @@ #include "resources/monsterinfo.h" Monster::Monster(int id, int job, Map *map): - Being(id, job, map), - mText(0) + Being(id, job, map) { const MonsterInfo& info = getInfo(); // Setup Monster sprites - int c = BASE_SPRITE; const std::list<std::string> &sprites = info.getSprites(); for (std::list<std::string>::const_iterator i = sprites.begin(); i != sprites.end(); i++) { - if (c == VECTOREND_SPRITE) break; - std::string file = "graphics/sprites/" + *i; - mSprites[c] = AnimatedSprite::load(file); - c++; + mSprites.push_back(AnimatedSprite::load(file)); } // Ensure that something is shown - if (c == BASE_SPRITE) + if (mSprites.size() == 0) { - mSprites[c] = AnimatedSprite::load("graphics/sprites/error.xml"); + mSprites.push_back(AnimatedSprite::load("graphics/sprites/error.xml")); } if (mParticleEffects) @@ -69,15 +64,11 @@ Monster::Monster(int id, int job, Map *map): } mNameColor = &guiPalette->getColor(Palette::MONSTER); + mTextColor = &guiPalette->getColor(Palette::MONSTER); Being::setName(getInfo().getName()); } -Monster::~Monster() -{ - delete mText; -} - #ifdef EATHENA_SUPPORT void Monster::logic() { @@ -93,11 +84,6 @@ void Monster::logic() } #endif -Being::Type Monster::getType() const -{ - return MONSTER; -} - void Monster::setAction(Action action, int attackType) { SpriteAction currentAction = ACTION_INVALID; @@ -115,7 +101,8 @@ void Monster::setAction(Action action, int attackType) break; case ATTACK: currentAction = getInfo().getAttackAction(attackType); - mSprites[BASE_SPRITE]->reset(); + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + (*it)->reset(); //attack particle effect particleEffect = getInfo().getAttackParticleEffect(attackType); @@ -147,11 +134,9 @@ void Monster::setAction(Action action, int attackType) if (currentAction != ACTION_INVALID) { - for (int i = 0; i < VECTOREND_SPRITE; i++) - { - if (mSprites[i]) - mSprites[i]->play(currentAction); - } + for (SpriteIterator it = mSprites.begin(); it != mSprites.end(); it++) + if (*it) + (*it)->play(currentAction); mAction = action; } } @@ -183,29 +168,18 @@ const MonsterInfo &Monster::getInfo() const return MonsterDB::get(mJob); } -void Monster::setShowName(bool show) +void Monster::updateCoords() { - delete mText; - - if (show) - { - mText = new Text(getInfo().getName(), - getPixelX(), - getPixelY() - getHeight(), - gcn::Graphics::CENTER, - &guiPalette->getColor(Palette::MONSTER)); - } - else + if (mDispName) { - mText = 0; + mDispName->adviseXY(getPixelX(), + getPixelY() - getHeight() - mDispName->getHeight()); } } -void Monster::updateCoords() +void Monster::showName() { - if (mText) - { - mText->adviseXY(getPixelX(), - getPixelY() - getHeight() - mText->getHeight()); - } + Being::showName(); + + updateCoords(); } diff --git a/src/monster.h b/src/monster.h index 29b04eab..1cfb8e93 100644 --- a/src/monster.h +++ b/src/monster.h @@ -32,15 +32,13 @@ class Monster : public Being public: Monster(int id, int job, Map *map); - ~Monster(); - #ifdef EATHENA_SUPPORT virtual void logic(); #endif virtual void setAction(Action action, int attackType = 0); - virtual Type getType() const; + virtual Type getType() const { return MONSTER; } virtual TargetCursorSize getTargetCursorSize() const; @@ -70,11 +68,6 @@ class Monster : public Being const MonsterInfo& getInfo() const; /** - * Determine whether the mob should show it's name - */ - void setShowName(bool show); - - /** * Gets the way the monster is blocked by other objects */ virtual unsigned char getWalkMask() const @@ -96,11 +89,7 @@ class Monster : public Being */ void updateCoords(); - private: - /** - * holds a text object when the mod displays it's name, 0 otherwise - */ - Text *mText; + void showName(); }; #endif diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 1d780a60..96c5986b 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -37,6 +37,8 @@ #include "gui/partywindow.h" +#include "resources/colordb.h" + #include <iostream> namespace EAthena { @@ -98,7 +100,7 @@ Being *createBeing(int id, short job) void BeingHandler::handleMessage(MessageIn &msg) { int id; - short job, speed; + short job, speed, gender; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves; Uint16 weapon, shield; @@ -109,6 +111,7 @@ void BeingHandler::handleMessage(MessageIn &msg) int type; Uint16 status; Being *srcBeing, *dstBeing; + Player *player; int hairStyle, hairColor, flag; switch (msg.getId()) @@ -137,6 +140,8 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing = createBeing(id, job); } + player = dynamic_cast<Player*>(dstBeing); + // Fix monster jobs if (dstBeing->getType() == Being::MONSTER) { @@ -158,7 +163,7 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; hairStyle = msg.readInt16(); - dstBeing->setSprite(Being::WEAPON_SPRITE, msg.readInt16()); + weapon = msg.readInt16(); headBottom = msg.readInt16(); if (msg.getId() == SMSG_BEING_MOVE) @@ -166,7 +171,7 @@ void BeingHandler::handleMessage(MessageIn &msg) msg.readInt32(); // server tick } - dstBeing->setSprite(Being::SHIELD_SPRITE, msg.readInt16()); + shield = msg.readInt16(); headTop = msg.readInt16(); headMid = msg.readInt16(); hairColor = msg.readInt16(); @@ -178,16 +183,22 @@ void BeingHandler::handleMessage(MessageIn &msg) msg.readInt16(); // manner dstBeing->setStatusEffectBlock(32, msg.readInt16()); // opt3 msg.readInt8(); // karma - dstBeing->setGender( - (msg.readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); + gender = msg.readInt8(); - // Set these after the gender, as the sprites may be gender-specific - dstBeing->setSprite(Being::BOTTOMCLOTHES_SPRITE, headBottom); - dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); - dstBeing->setSprite(Being::HAT_SPRITE, headTop); - dstBeing->setSprite(Being::SHOE_SPRITE, shoes); - dstBeing->setSprite(Being::GLOVES_SPRITE, gloves); - dstBeing->setHairStyle(hairStyle, hairColor); + if (player) + { + player->setGender((gender == 0) + ? GENDER_FEMALE : GENDER_MALE); + // Set these after the gender, as the sprites may be gender-specific + player->setSprite(Player::HAIR_SPRITE, hairStyle * -1, ColorDB::get(hairColor)); + player->setSprite(Player::BOTTOMCLOTHES_SPRITE, headBottom); + player->setSprite(Player::TOPCLOTHES_SPRITE, headMid); + player->setSprite(Player::HAT_SPRITE, headTop); + player->setSprite(Player::SHOE_SPRITE, shoes); + player->setSprite(Player::GLOVES_SPRITE, gloves); + player->setSprite(Player::WEAPON_SPRITE, weapon); + player->setSprite(Player::SHIELD_SPRITE, shield); + } if (msg.getId() == SMSG_BEING_MOVE) { @@ -371,6 +382,8 @@ void BeingHandler::handleMessage(MessageIn &msg) break; } + player = dynamic_cast<Player*>(dstBeing); + int type = msg.readInt8(); int id = 0; int id2 = 0; @@ -384,41 +397,42 @@ void BeingHandler::handleMessage(MessageIn &msg) switch (type) { case 1: // eAthena LOOK_HAIR - dstBeing->setHairStyle(id, -1); + player->setSprite(Player::HAIR_SPRITE, id * -1, + ColorDB::get(id2)); break; case 2: // Weapon ID in id, Shield ID in id2 - dstBeing->setSprite(Being::WEAPON_SPRITE, id); - dstBeing->setSprite(Being::SHIELD_SPRITE, id2); + player->setSprite(Player::WEAPON_SPRITE, id); + player->setSprite(Player::SHIELD_SPRITE, id2); break; case 3: // Change lower headgear for eAthena, pants for us - dstBeing->setSprite(Being::BOTTOMCLOTHES_SPRITE, id); + player->setSprite(Player::BOTTOMCLOTHES_SPRITE, id); break; case 4: // Change upper headgear for eAthena, hat for us - dstBeing->setSprite(Being::HAT_SPRITE, id); + player->setSprite(Player::HAT_SPRITE, id); break; case 5: // Change middle headgear for eathena, armor for us - dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, id); + player->setSprite(Player::TOPCLOTHES_SPRITE, id); break; case 6: // eAthena LOOK_HAIR_COLOR - dstBeing->setHairStyle(-1, id); + // ignored (duplicate of LOOK_HAIR) break; case 8: // eAthena LOOK_SHIELD - dstBeing->setSprite(Being::SHIELD_SPRITE, id); + player->setSprite(Player::SHIELD_SPRITE, id); break; case 9: // eAthena LOOK_SHOES - dstBeing->setSprite(Being::SHOE_SPRITE, id); + player->setSprite(Player::SHOE_SPRITE, id); break; case 10: // LOOK_GLOVES - dstBeing->setSprite(Being::GLOVES_SPRITE, id); + player->setSprite(Player::GLOVES_SPRITE, id); break; case 11: // LOOK_CAPE - dstBeing->setSprite(Being::CAPE_SPRITE, id); + player->setSprite(Player::CAPE_SPRITE, id); break; case 12: - dstBeing->setSprite(Being::MISC1_SPRITE, id); + player->setSprite(Player::MISC1_SPRITE, id); break; case 13: - dstBeing->setSprite(Being::MISC2_SPRITE, id); + player->setSprite(Player::MISC2_SPRITE, id); break; default: logger->log("SMSG_BEING_CHANGE_LOOKS: unsupported type: " @@ -466,15 +480,16 @@ void BeingHandler::handleMessage(MessageIn &msg) dstBeing = createBeing(id, job); } + player = dynamic_cast<Player*>(dstBeing); + { PartyMember *member = partyWindow->findMember(id); if (member && member->online) { - dynamic_cast<Player*>(dstBeing)->setInParty(true); + player->setInParty(true); } } - dstBeing->setWalkSpeed(speed); dstBeing->mJob = job; hairStyle = msg.readInt16(); @@ -497,19 +512,19 @@ void BeingHandler::handleMessage(MessageIn &msg) msg.readInt16(); // manner dstBeing->setStatusEffectBlock(32, msg.readInt16()); // opt3 msg.readInt8(); // karma - dstBeing->setGender( - (msg.readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); + player->setGender((msg.readInt8() == 0) + ? GENDER_FEMALE : GENDER_MALE); // Set these after the gender, as the sprites may be gender-specific - dstBeing->setSprite(Being::WEAPON_SPRITE, weapon); - dstBeing->setSprite(Being::SHIELD_SPRITE, shield); - dstBeing->setSprite(Being::BOTTOMCLOTHES_SPRITE, headBottom); - dstBeing->setSprite(Being::TOPCLOTHES_SPRITE, headMid); - dstBeing->setSprite(Being::HAT_SPRITE, headTop); - //dstBeing->setSprite(Being::CAPE_SPRITE, cape); - //dstBeing->setSprite(Being::MISC1_SPRITE, misc1); - //dstBeing->setSprite(Being::MISC2_SPRITE, misc2); - dstBeing->setHairStyle(hairStyle, hairColor); + player->setSprite(Player::WEAPON_SPRITE, weapon); + player->setSprite(Player::SHIELD_SPRITE, shield); + player->setSprite(Player::BOTTOMCLOTHES_SPRITE, headBottom); + player->setSprite(Player::TOPCLOTHES_SPRITE, headMid); + player->setSprite(Player::HAT_SPRITE, headTop); + //player->setSprite(Player::CAPE_SPRITE, cape); + //player->setSprite(Player::MISC1_SPRITE, misc1); + //player->setSprite(Player::MISC2_SPRITE, misc2); + player->setSprite(Player::HAIR_SPRITE, hairStyle * -1, ColorDB::get(hairColor)); if (msg.getId() == SMSG_PLAYER_MOVE) { diff --git a/src/net/ea/charserverhandler.cpp b/src/net/ea/charserverhandler.cpp index 6fae1864..47d454a8 100644 --- a/src/net/ea/charserverhandler.cpp +++ b/src/net/ea/charserverhandler.cpp @@ -35,6 +35,8 @@ #include "gui/charcreatedialog.h" #include "gui/okdialog.h" +#include "resources/colordb.h" + #include "utils/gettext.h" #include "utils/stringutils.h" @@ -176,10 +178,10 @@ LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) int temp = msg.readInt32(); tempPlayer->setAttributeBase(JOB, temp); tempPlayer->setAttributeEffective(JOB, temp); - tempPlayer->setSprite(Being::SHOE_SPRITE, msg.readInt16()); - tempPlayer->setSprite(Being::GLOVES_SPRITE, msg.readInt16()); - tempPlayer->setSprite(Being::CAPE_SPRITE, msg.readInt16()); - tempPlayer->setSprite(Being::MISC1_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::SHOE_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::GLOVES_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::CAPE_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::MISC1_SPRITE, msg.readInt16()); msg.readInt32(); // option msg.readInt32(); // karma msg.readInt32(); // manner @@ -192,16 +194,15 @@ LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) msg.readInt16(); // class int hairStyle = msg.readInt16(); Uint16 weapon = msg.readInt16(); - tempPlayer->setSprite(Being::WEAPON_SPRITE, weapon); + tempPlayer->setSprite(Player::WEAPON_SPRITE, weapon); tempPlayer->setLevel(msg.readInt16()); msg.readInt16(); // skill point - tempPlayer->setSprite(Being::BOTTOMCLOTHES_SPRITE, msg.readInt16()); // head bottom - tempPlayer->setSprite(Being::SHIELD_SPRITE, msg.readInt16()); - 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); - tempPlayer->setSprite(Being::MISC2_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::BOTTOMCLOTHES_SPRITE, msg.readInt16()); // head bottom + tempPlayer->setSprite(Player::SHIELD_SPRITE, msg.readInt16()); + tempPlayer->setSprite(Player::HAT_SPRITE, msg.readInt16()); // head option top + tempPlayer->setSprite(Player::TOPCLOTHES_SPRITE, msg.readInt16()); // head option mid + tempPlayer->setSprite(Player::HAIR_SPRITE, hairStyle * -1, ColorDB::get(msg.readInt16())); + tempPlayer->setSprite(Player::MISC2_SPRITE, msg.readInt16()); tempPlayer->setName(msg.readString(24)); for (int i = 0; i < 6; i++) { tempPlayer->setAttributeBase(i + STR, msg.readInt8()); diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp index a4a84b07..f514c3b6 100644 --- a/src/net/ea/partyhandler.cpp +++ b/src/net/ea/partyhandler.cpp @@ -139,7 +139,6 @@ void PartyHandler::handleMessage(MessageIn &msg) break; } std::string nick; - int gender = 0; std::string partyName = ""; if (being->getType() != Being::PLAYER) { @@ -148,7 +147,6 @@ void PartyHandler::handleMessage(MessageIn &msg) else { nick = being->getName(); - gender = being->getGender(); partyName = msg.readString(24); } partyWindow->showPartyInvite(nick, partyName); diff --git a/src/net/logindata.h b/src/net/logindata.h index 4cf989cb..db7aafff 100644 --- a/src/net/logindata.h +++ b/src/net/logindata.h @@ -24,7 +24,7 @@ #include <string> -#include "being.h" +#include "player.h" struct LoginData { diff --git a/src/net/tmwserv/beinghandler.cpp b/src/net/tmwserv/beinghandler.cpp index acd6b62c..d5092782 100644 --- a/src/net/tmwserv/beinghandler.cpp +++ b/src/net/tmwserv/beinghandler.cpp @@ -37,6 +37,8 @@ #include "gui/okdialog.h" +#include "resources/colordb.h" + #include "utils/gettext.h" #include "net/tmwserv/gameserver/player.h" @@ -95,8 +97,8 @@ static void handleLooks(Player *being, MessageIn &msg) // Order of sent slots. Has to be in sync with the server code. static int const nb_slots = 4; static int const slots[nb_slots] = - { Being::WEAPON_SPRITE, Being::HAT_SPRITE, Being::TOPCLOTHES_SPRITE, - Being::BOTTOMCLOTHES_SPRITE }; + { Player::WEAPON_SPRITE, Player::HAT_SPRITE, Player::TOPCLOTHES_SPRITE, + Player::BOTTOMCLOTHES_SPRITE }; int mask = msg.readInt8(); @@ -144,7 +146,7 @@ void BeingHandler::handleBeingEnterMessage(MessageIn &msg) } Player *p = static_cast< Player * >(being); int hs = msg.readInt8(), hc = msg.readInt8(); - p->setHairStyle(hs, hc); + p->setSprite(Player::HAIR_SPRITE, hs * -1, ColorDB::get(hc)); p->setGender(msg.readInt8() == GENDER_MALE ? GENDER_MALE : GENDER_FEMALE); handleLooks(p, msg); @@ -304,8 +306,7 @@ void BeingHandler::handleBeingLooksChangeMessage(MessageIn &msg) { int style = msg.readInt16(); int color = msg.readInt16(); - player->setHairStyle(style, color); - player->setGender((Gender)msg.readInt16()); + player->setSprite(Player::HAIR_SPRITE, style * -1, ColorDB::get(color)); } } diff --git a/src/net/tmwserv/charserverhandler.cpp b/src/net/tmwserv/charserverhandler.cpp index 0146babb..93181a93 100644 --- a/src/net/tmwserv/charserverhandler.cpp +++ b/src/net/tmwserv/charserverhandler.cpp @@ -38,6 +38,8 @@ #include "gui/charcreatedialog.h" #include "gui/okdialog.h" +#include "resources/colordb.h" + #include "utils/gettext.h" extern Net::Connection *gameServerConnection; @@ -229,7 +231,7 @@ LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot) tempPlayer->setName(msg.readString()); tempPlayer->setGender(msg.readInt8() == GENDER_MALE ? GENDER_MALE : GENDER_FEMALE); int hs = msg.readInt8(), hc = msg.readInt8(); - tempPlayer->setHairStyle(hs, hc); + tempPlayer->setSprite(Player::HAIR_SPRITE, hs * -1, ColorDB::get(hc)); tempPlayer->setLevel(msg.readInt16()); tempPlayer->setCharacterPoints(msg.readInt16()); tempPlayer->setCorrectionPoints(msg.readInt16()); diff --git a/src/npc.cpp b/src/npc.cpp index f7172d4b..dbae24e4 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -41,18 +41,13 @@ NPC::NPC(int id, int job, Map *map): NPCInfo info = NPCDB::get(job); // Setup NPC sprites - int c = BASE_SPRITE; for (std::list<NPCsprite*>::const_iterator i = info.sprites.begin(); i != info.sprites.end(); i++) { - if (c == VECTOREND_SPRITE) - break; - std::string file = "graphics/sprites/" + (*i)->sprite; int variant = (*i)->variant; - mSprites[c] = AnimatedSprite::load(file, variant); - c++; + mSprites.push_back(AnimatedSprite::load(file, variant)); } if (mParticleEffects) @@ -66,32 +61,15 @@ NPC::NPC(int id, int job, Map *map): this->controlParticle(p); } } - mName = 0; - - mNameColor = &guiPalette->getColor(Palette::NPC); -} -NPC::~NPC() -{ - delete mName; + setShowName(true); } void NPC::setName(const std::string &name) { const std::string displayName = name.substr(0, name.find('#', 0)); - delete mName; - mName = new Text(displayName, - getPixelX(), - getPixelY(), - gcn::Graphics::CENTER, - &guiPalette->getColor(Palette::NPC)); - Being::setName(displayName + " (NPC)"); -} - -Being::Type NPC::getType() const -{ - return Being::NPC; + Being::setName(displayName); } void NPC::talk() @@ -103,11 +81,3 @@ void NPC::talk() Net::getNpcHandler()->talk(mId); } - -void NPC::updateCoords() -{ - if (mName) - { - mName->adviseXY(getPixelX(), getPixelY()); - } -} @@ -32,11 +32,9 @@ class NPC : public Being public: NPC(int id, int job, Map *map); - ~NPC(); - void setName(const std::string &name); - virtual Type getType() const; + virtual Type getType() const { return Being::NPC; } void talk(); @@ -58,11 +56,6 @@ class NPC : public Being */ virtual Map::BlockType getBlockType() const { return Map::BLOCKTYPE_CHARACTER; } //blocks like a player character - - void updateCoords(); - - private: - Text *mName; }; extern int current_npc; diff --git a/src/player.cpp b/src/player.cpp index fd7cd0d6..55888654 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -40,53 +40,23 @@ Player::Player(int id, int job, Map *map): Being(id, job, map), - mName(0), + mGender(GENDER_UNSPECIFIED), + mSpriteIDs(VECTOREND_SPRITE, 0), + mSpriteColors(VECTOREND_SPRITE, ""), mIsGM(false), mInParty(false) { + for (int i = 0; i < VECTOREND_SPRITE; i++) + mSprites.push_back(NULL); mShowName = config.getValue("visiblenames", 1); config.addListener("visiblenames", this); + + updateColors(); } Player::~Player() { config.removeListener("visiblenames", this); - delete mName; -} - -void Player::setName(const std::string &name) -{ - if (!mName && mShowName) - { - mNameColor = &guiPalette->getColor(Palette::PLAYER); - - const gcn::Color *color; - if (this == player_node) - { - color = &guiPalette->getColor(Palette::SELF); - } - else if (mIsGM) - { - mNameColor = &guiPalette->getColor(Palette::GM); - color = &guiPalette->getColor(Palette::GM_NAME); - } - else if (mInParty) - { - color = &guiPalette->getColor(Palette::PARTY); - } - else - { - color = &guiPalette->getColor(Palette::PC); - } - - mName = new FlashText(name, - getPixelX(), - getPixelY(), - gcn::Graphics::CENTER, - color); - } - - Being::setName(name); } #ifdef EATHENA_SUPPORT @@ -149,31 +119,20 @@ void Player::logic() } #endif -Being::Type Player::getType() const -{ - return PLAYER; -} - -void Player::flash(int time) -{ - if (mName) - mName->flash(time); -} - void Player::setGender(Gender gender) { if (gender != mGender) { - Being::setGender(gender); + mGender = gender; /* Human base sprite. When implementing different races remove this * line and set the base sprite when setting the race of the player * character. */ - setSprite(Being::BASE_SPRITE, -100); + setSprite(BASE_SPRITE, -100); // Reload all subsprites - for (int i = 1; i < VECTOREND_SPRITE; i++) + for (unsigned int i = 1; i < mSprites.size(); i++) { if (mSpriteIDs.at(i) != 0) setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i)); @@ -185,28 +144,12 @@ void Player::setGM(bool gm) { mIsGM = gm; - if (gm && mName) - mName->setColor(&guiPalette->getColor(Palette::GM)); -} - -void Player::setHairStyle(int style, int color) -{ - style = style < 0 ? mHairStyle : style % mNumberOfHairstyles; - color = color < 0 ? mHairColor : color % ColorDB::size(); - if (style == mHairStyle && color == mHairColor) return; - - Being::setHairStyle(style, color); - - setSprite(HAIR_SPRITE, style * -1, ColorDB::get(color)); - - setAction(mAction); + updateColors(); } void Player::setSprite(int slot, int id, const std::string &color) { - // TODO: Find a better way - if (getType() == NPC) - return; + assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE); // id = 0 means unequip if (id == 0) @@ -237,6 +180,7 @@ void Player::setSprite(int slot, int id, const std::string &color) equipmentSprite->setDirection(getSpriteDirection()); delete mSprites[slot]; + mSprites[slot] = equipmentSprite; if (slot == WEAPON_SPRITE) @@ -245,13 +189,8 @@ void Player::setSprite(int slot, int id, const std::string &color) setAction(mAction); } - Being::setSprite(slot, id, color); -} - -void Player::updateCoords() -{ - if (mName) - mName->adviseXY(getPixelX(), getPixelY()); + mSpriteIDs[slot] = id; + mSpriteColors[slot] = color; } #ifdef TMWSERV_SUPPORT @@ -305,26 +244,32 @@ void Player::setInParty(bool inParty) { mInParty = inParty; - if (this != player_node && mName) + updateColors(); +} + +void Player::optionChanged(const std::string &value) +{ + if (value == "visiblenames") { - Palette::ColorType colorType = mInParty ? Palette::PARTY : Palette::PC; - mName->setColor(&guiPalette->getColor(colorType)); + setShowName(config.getValue("visiblenames", 1)); } } -void Player::optionChanged(const std::string &value) +void Player::updateColors() { - if (value == "visiblenames" && getType() == Being::PLAYER && player_node != this) + mTextColor = &guiPalette->getColor(Palette::PLAYER); + + if (mIsGM) { - mShowName = config.getValue("visiblenames", 1); - if (!mShowName && mName) - { - delete mName; - mName = NULL; - } - else if (mShowName && !mName && !(getName().empty())) - { - setName(getName()); - } + mTextColor = &guiPalette->getColor(Palette::GM); + mNameColor = &guiPalette->getColor(Palette::GM_NAME); + } + else if (mInParty) + { + mNameColor = &guiPalette->getColor(Palette::PARTY); + } + else + { + mNameColor = &guiPalette->getColor(Palette::PC); } } diff --git a/src/player.h b/src/player.h index 9a5c6c94..36f0266e 100644 --- a/src/player.h +++ b/src/player.h @@ -24,13 +24,19 @@ #include "being.h" -class FlashText; class Graphics; class Map; #ifdef TMWSERV_SUPPORT class Guild; #endif +enum Gender +{ + GENDER_MALE = 0, + GENDER_FEMALE = 1, + GENDER_UNSPECIFIED = 2 +}; + /** * A player being. Players have their name drawn beneath them. This class also * implements player-specific loading of base sprite, hair sprite and equipment @@ -39,6 +45,29 @@ class Guild; class Player : public Being { public: + enum Sprite + { + BASE_SPRITE = 0, + SHOE_SPRITE, + BOTTOMCLOTHES_SPRITE, + TOPCLOTHES_SPRITE, +#ifdef EATHENA_SUPPORT + MISC1_SPRITE, + MISC2_SPRITE, +#endif + HAIR_SPRITE, + HAT_SPRITE, +#ifdef EATHENA_SUPPORT + CAPE_SPRITE, + GLOVES_SPRITE, +#endif + WEAPON_SPRITE, +#ifdef EATHENA_SUPPORT + SHIELD_SPRITE, +#endif + VECTOREND_SPRITE + }; + /** * Constructor. */ @@ -46,19 +75,19 @@ class Player : public Being ~Player(); - /** - * Set up mName to be the character's name - */ - virtual void setName(const std::string &name); - #ifdef EATHENA_SUPPORT virtual void logic(); #endif - virtual Type getType() const; + virtual Type getType() const { return PLAYER; } + /** + * Sets the gender of this being. + */ virtual void setGender(Gender gender); + Gender getGender() const { return mGender; } + /** * Whether or not this player is a GM. */ @@ -70,27 +99,10 @@ class Player : public Being virtual void setGM(bool gm); /** - * 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); - - /** * Sets visible equipments for this player. */ virtual void setSprite(int slot, int id, const std::string &color = ""); - /** - * Flash the player's name - */ - void flash(int time); - #ifdef TMWSERV_SUPPORT /** * Adds a guild to the player. @@ -137,7 +149,7 @@ class Player : public Being /** * Called when a option (set with config.addListener()) is changed */ - void optionChanged(const std::string &value); + virtual void optionChanged(const std::string &value); protected: /** @@ -146,16 +158,17 @@ class Player : public Being virtual Map::BlockType getBlockType() const { return Map::BLOCKTYPE_CHARACTER; } - virtual void updateCoords(); + virtual void updateColors(); + + Gender mGender; + std::vector<int> mSpriteIDs; + std::vector<std::string> mSpriteColors; #ifdef TMWSERV_SUPPORT // Character guild information std::map<int, Guild*> mGuilds; #endif - bool mShowName; - FlashText *mName; - bool mIsGM; private: diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index 7bc1b14d..2825d114 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -329,7 +329,7 @@ public: virtual void ignore(Player *player, unsigned int flags) { - player->flash(200); + player->flashName(200); } }; diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 0c87b585..6c033490 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -24,7 +24,7 @@ #include "resources/spritedef.h" -#include "being.h" +#include "player.h" #include <map> #include <string> |