summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-08-15 13:58:32 +0300
committerAndrei Karas <akaras@inbox.ru>2015-08-16 01:52:14 +0300
commit41cc92f73e39cec5dfea6b1164176610cccc7df4 (patch)
tree22fd3d388084d2c61fe80f0441c3c30ab8ffd33c /src/being
parent7aa637abc8b0bca35aacdb9492e65f557ed32038 (diff)
downloadplus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.gz
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.bz2
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.tar.xz
plus-41cc92f73e39cec5dfea6b1164176610cccc7df4.zip
Add strong typed int for item color.
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp79
-rw-r--r--src/being/being.h17
-rw-r--r--src/being/localplayer.cpp8
-rw-r--r--src/being/localplayer.h2
4 files changed, 67 insertions, 39 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 4ba600294..ca5d7fd1a 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -227,7 +227,7 @@ Being::Being(const BeingId id,
mTeamId(0U),
mLook(0U),
mBadgesCount(0U),
- mHairColor(0),
+ mHairColor(ItemColor_zero),
mErased(false),
mEnemy(false),
mGotComment(false),
@@ -354,7 +354,7 @@ void Being::setSubtype(const BeingTypeId subtype,
setupSpriteDisplay(mInfo->getDisplay(),
ForceDisplay_true,
0,
- mInfo->getColor(mLook));
+ mInfo->getColor(fromInt(mLook, ItemColor)));
mYDiff = mInfo->getSortOffsetY();
}
}
@@ -368,7 +368,7 @@ void Being::setSubtype(const BeingTypeId subtype,
setupSpriteDisplay(mInfo->getDisplay(),
ForceDisplay_true,
0,
- mInfo->getColor(mLook));
+ mInfo->getColor(fromInt(mLook, ItemColor)));
mYDiff = mInfo->getSortOffsetY();
}
}
@@ -381,7 +381,7 @@ void Being::setSubtype(const BeingTypeId subtype,
setupSpriteDisplay(mInfo->getDisplay(),
ForceDisplay_true,
0,
- mInfo->getColor(mLook));
+ mInfo->getColor(fromInt(mLook, ItemColor)));
mYDiff = mInfo->getSortOffsetY();
}
}
@@ -394,7 +394,7 @@ void Being::setSubtype(const BeingTypeId subtype,
setupSpriteDisplay(mInfo->getDisplay(),
ForceDisplay_true,
0,
- mInfo->getColor(mLook));
+ mInfo->getColor(fromInt(mLook, ItemColor)));
mYDiff = mInfo->getSortOffsetY();
}
}
@@ -456,7 +456,7 @@ void Being::setSubtype(const BeingTypeId subtype,
if (charServerHandler)
{
setSprite(charServerHandler->baseSprite(),
- id, info.getColor(mLook));
+ id, info.getColor(fromInt(mLook, ItemColor)));
}
}
}
@@ -2296,9 +2296,12 @@ void Being::updateColors()
}
}
-void Being::updateSprite(const unsigned int slot, const int id,
- std::string color, const unsigned char colorId,
- const bool isWeapon, const bool isTempSprite)
+void Being::updateSprite(const unsigned int slot,
+ const int id,
+ std::string color,
+ const ItemColor colorId,
+ const bool isWeapon,
+ const bool isTempSprite)
{
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
@@ -2311,9 +2314,12 @@ void Being::updateSprite(const unsigned int slot, const int id,
setSprite(slot, id, color, colorId, isWeapon, isTempSprite);
}
-void Being::setSprite(const unsigned int slot, const int id,
- std::string color, const unsigned char colorId,
- const bool isWeapon, const bool isTempSprite)
+void Being::setSprite(const unsigned int slot,
+ const int id,
+ std::string color,
+ const ItemColor colorId,
+ const bool isWeapon,
+ const bool isTempSprite)
{
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
@@ -2328,7 +2334,7 @@ void Being::setSprite(const unsigned int slot, const int id,
mSpriteColors.resize(slot + 1, "");
if (slot >= static_cast<unsigned int>(mSpriteColorsIds.size()))
- mSpriteColorsIds.resize(slot + 1, 1);
+ mSpriteColorsIds.resize(slot + 1, ItemColor_one);
// disabled for now, because it may broke replace/reorder sprites logic
// if (slot && mSpriteIDs[slot] == id)
@@ -2421,7 +2427,7 @@ void Being::setHairStyle(const unsigned int slot, const int id)
// dumpSprites();
}
-void Being::setHairColor(const unsigned int slot, const unsigned char color)
+void Being::setHairColor(const unsigned int slot, const ItemColor color)
{
mHairColor = color;
setSprite(slot, mSpriteIDs[slot], ItemDB::get(
@@ -2434,15 +2440,15 @@ void Being::dumpSprites() const
const std::vector<int>::const_iterator it1_end = mSpriteIDs.end();
StringVectCIter it2 = mSpriteColors.begin();
const StringVectCIter it2_end = mSpriteColors.end();
- std::vector<unsigned char>::const_iterator it3 = mSpriteColorsIds.begin();
- const std::vector<unsigned char>::const_iterator
+ std::vector<ItemColor>::const_iterator it3 = mSpriteColorsIds.begin();
+ const std::vector<ItemColor>::const_iterator
it3_end = mSpriteColorsIds.end();
logger->log("sprites");
for (; it1 != it1_end && it2 != it2_end && it3 != it3_end;
++ it1, ++ it2, ++ it3)
{
- logger->log("%d,%s,%d", *it1, (*it2).c_str(), *it3);
+ logger->log("%d,%s,%d", *it1, (*it2).c_str(), toInt(*it3, int));
}
}
@@ -2994,14 +3000,18 @@ void Being::recalcSpritesOrder()
{
setSprite(remSprite, repIt->second,
mSpriteColors[remSprite],
- 1, false, true);
+ ItemColor_one,
+ false,
+ true);
}
else
{
setSprite(remSprite, repIt->second,
ItemDB::get(repIt->second)
.getDyeColorsString(mHairColor),
- 1, false, true);
+ ItemColor_one,
+ false,
+ true);
}
updatedSprite[remSprite] = true;
}
@@ -3023,7 +3033,9 @@ void Being::recalcSpritesOrder()
{
setSprite(slot2, repIt->second,
mSpriteColors[slot2],
- 1, false, true);
+ ItemColor_one,
+ false,
+ true);
}
else
{
@@ -3031,7 +3043,9 @@ void Being::recalcSpritesOrder()
ItemDB::get(repIt->second)
.getDyeColorsString(
mHairColor),
- 1, false, true);
+ ItemColor_one,
+ false,
+ true);
}
updatedSprite[slot2] = true;
}
@@ -3174,7 +3188,12 @@ void Being::recalcSpritesOrder()
continue;
updatedSprite[slot] = true;
- setSprite(slot, id, mSpriteColors[slot], 1, false, true);
+ setSprite(slot,
+ id,
+ mSpriteColors[slot],
+ ItemColor_one,
+ false,
+ true);
}
}
}
@@ -3183,8 +3202,16 @@ void Being::recalcSpritesOrder()
if (mSpriteHide[slot] == 0)
{
const int id = mSpriteIDs[slot];
- if (updatedSprite[slot] == false && mSpriteDraw[slot] != id)
- setSprite(slot, id, mSpriteColors[slot], 1, false, true);
+ if (updatedSprite[slot] == false &&
+ mSpriteDraw[slot] != id)
+ {
+ setSprite(slot,
+ id,
+ mSpriteColors[slot],
+ ItemColor_one,
+ false,
+ true);
+ }
}
}
}
@@ -3467,10 +3494,10 @@ int Being::getSpriteID(const int slot) const
return mSpriteIDs[slot];
}
-unsigned char Being::getSpriteColor(const int slot) const
+ItemColor Being::getSpriteColor(const int slot) const
{
if (slot < 0 || static_cast<size_t>(slot) >= mSpriteColorsIds.size())
- return 1;
+ return ItemColor_one;
return mSpriteColorsIds[slot];
}
diff --git a/src/being/being.h b/src/being/being.h
index 8926e5548..7bb7def7d 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -27,6 +27,7 @@
#include "enums/gui/usercolorid.h"
+#include "enums/simpletypes/itemcolor.h"
#include "enums/simpletypes/move.h"
#include "resources/beinginfo.h"
@@ -306,13 +307,13 @@ class Being notfinal : public ActorSprite,
*/
void setSprite(const unsigned int slot, const int id,
std::string color = "",
- const unsigned char colorId = 1,
+ const ItemColor colorId = ItemColor_one,
const bool isWeapon = false,
const bool isTempSprite = false);
void updateSprite(const unsigned int slot, const int id,
std::string color = "",
- const unsigned char colorId = 1,
+ const ItemColor colorId = ItemColor_one,
const bool isWeapon = false,
const bool isTempSprite = false);
@@ -784,17 +785,17 @@ class Being notfinal : public ActorSprite,
int getSpriteID(const int slot) const A_WARN_UNUSED;
- unsigned char getSpriteColor(const int slot) const A_WARN_UNUSED;
+ ItemColor getSpriteColor(const int slot) const A_WARN_UNUSED;
void setHairStyle(const unsigned int slot, const int id);
void setHairColor(const unsigned int slot,
- const unsigned char color);
+ const ItemColor color);
- void setHairColor(const unsigned char color)
+ void setHairColor(const ItemColor color)
{ mHairColor = color; }
- unsigned char getHairColor() const A_WARN_UNUSED
+ ItemColor getHairColor() const A_WARN_UNUSED
{ return mHairColor; }
void recalcSpritesOrder();
@@ -1007,7 +1008,7 @@ class Being notfinal : public ActorSprite,
StringVect mSpriteColors;
std::vector<int> mSpriteIDs;
- std::vector<unsigned char> mSpriteColorsIds;
+ std::vector<ItemColor> mSpriteColorsIds;
SpriteParticleInfo mSpriteParticles;
// Character guild information
@@ -1139,7 +1140,7 @@ class Being notfinal : public ActorSprite,
uint16_t mTeamId;
uint16_t mLook;
uint16_t mBadgesCount;
- unsigned char mHairColor;
+ ItemColor mHairColor;
bool mErased;
bool mEnemy;
bool mGotComment;
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index acc6e2c0e..6722d5a4b 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -813,7 +813,7 @@ void LocalPlayer::untarget()
void LocalPlayer::pickedUp(const ItemInfo &itemInfo,
const int amount,
- const unsigned char color,
+ const ItemColor color,
const BeingId floorItemId,
const PickupT fail)
{
@@ -1317,7 +1317,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
const WeaponsInfos &swords = WeaponsDB::getSwords();
FOR_EACH (WeaponsInfosIter, it, swords)
{
- item = inv->findItem(*it, 0);
+ item = inv->findItem(*it, ItemColor_zero);
if (item)
break;
}
@@ -1337,7 +1337,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
const WeaponsInfos &shields = WeaponsDB::getShields();
FOR_EACH (WeaponsInfosIter, it, shields)
{
- item = inv->findItem(*it, 0);
+ item = inv->findItem(*it, ItemColor_zero);
if (item)
break;
}
@@ -1352,7 +1352,7 @@ void LocalPlayer::changeEquipmentBeforeAttack(const Being *const target) const
const WeaponsInfos &bows = WeaponsDB::getBows();
FOR_EACH (WeaponsInfosIter, it, bows)
{
- item = inv->findItem(*it, 0);
+ item = inv->findItem(*it, ItemColor_zero);
if (item)
break;
}
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 475101528..c258a14f1 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -176,7 +176,7 @@ class LocalPlayer final : public Being,
*/
void pickedUp(const ItemInfo &itemInfo,
const int amount,
- const unsigned char color,
+ const ItemColor color,
const BeingId floorItemId,
const PickupT fail);