From 9d1fbb5a538b3c5a1ba7d5ab55f39033ddb880f1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 14 Aug 2009 12:21:07 -0600 Subject: Add functions to more easily work with equipment Move hair changes back over to them; related server change was reverted. Also move NPCs back over to extending Player. NPCs will have equipment in the future too, but for now, disable that part while we finish the system. --- src/player.cpp | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'src/player.cpp') diff --git a/src/player.cpp b/src/player.cpp index 55888654..288c565d 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -38,16 +38,27 @@ #include "utils/stringutils.h" -Player::Player(int id, int job, Map *map): +Player::Player(int id, int job, Map *map, bool isNPC): Being(id, job, map), 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); + if (!isNPC) + { + for (int i = 0; i < VECTOREND_SPRITE; i++) + { + mSprites.push_back(NULL); + mSpriteIDs.push_back(0); + mSpriteColors.push_back(""); + } + + /* Human base sprite. When implementing different races remove this + * line and set the base sprite when setting the race of the player + * character. + */ + setSprite(BASE_SPRITE, -100); + } mShowName = config.getValue("visiblenames", 1); config.addListener("visiblenames", this); @@ -125,14 +136,8 @@ void Player::setGender(Gender 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(BASE_SPRITE, -100); - // Reload all subsprites - for (unsigned int i = 1; i < mSprites.size(); i++) + for (unsigned int i = 0; i < mSprites.size(); i++) { if (mSpriteIDs.at(i) != 0) setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i)); @@ -147,7 +152,7 @@ void Player::setGM(bool gm) updateColors(); } -void Player::setSprite(int slot, int id, const std::string &color) +void Player::setSprite(unsigned int slot, int id, const std::string &color) { assert(slot >= BASE_SPRITE && slot < VECTOREND_SPRITE); @@ -193,6 +198,16 @@ void Player::setSprite(int slot, int id, const std::string &color) mSpriteColors[slot] = color; } +void Player::setSpriteID(unsigned int slot, int id) +{ + setSprite(slot, id, mSpriteColors[slot]); +} + +void Player::setSpriteColor(unsigned int slot, const std::string &color) +{ + setSprite(slot, mSpriteIDs[slot], color); +} + #ifdef TMWSERV_SUPPORT Guild* Player::addGuild(short guildId, short rights) { -- cgit v1.2.3-70-g09d2