summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-06-19 23:04:05 +0300
committerAndrei Karas <akaras@inbox.ru>2016-06-20 01:48:03 +0300
commit9dfde677430ab0dc1c11807b2b0d9f76bab353bb (patch)
tree92907f9c9467cf798c2b6fa392df9eefaebf4898
parent8462b9ae346a41a37b2790c3ea5f14f0e783ab71 (diff)
downloadmanaplus-9dfde677430ab0dc1c11807b2b0d9f76bab353bb.tar.gz
manaplus-9dfde677430ab0dc1c11807b2b0d9f76bab353bb.tar.bz2
manaplus-9dfde677430ab0dc1c11807b2b0d9f76bab353bb.tar.xz
manaplus-9dfde677430ab0dc1c11807b2b0d9f76bab353bb.zip
Add support for stored cards with sprites in Being.
-rw-r--r--src/being/being.cpp45
-rw-r--r--src/being/being.h9
-rw-r--r--src/itemcolormanager.cpp5
-rw-r--r--src/itemcolormanager.h5
-rw-r--r--src/resources/item/cardslist.h22
5 files changed, 66 insertions, 20 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index db8eec991..66b01acb3 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -170,6 +170,7 @@ Being::Being(const BeingId id,
mDest(),
mSpriteColors(),
mSpriteIDs(),
+ mSpriteCardsIds(),
mSpriteColorsIds(),
mSpriteParticles(),
mGuilds(),
@@ -2485,16 +2486,19 @@ void Being::updateSprite(const unsigned int slot,
if (slot >= CAST_U32(mSpriteIDs.size()))
mSpriteIDs.resize(slot + 1, 0);
+ if (slot >= CAST_U32(mSpriteCardsIds.size()))
+ mSpriteCardsIds.resize(slot + 1, zeroCards);
+
if (slot && mSpriteIDs[slot] == id)
return;
- setSprite(slot, id, color, colorId, nullptr);
+ setSprite(slot, id, color, colorId, mSpriteCardsIds[slot]);
}
void Being::setSprite(const unsigned int slot,
const int id,
std::string color,
ItemColor colorId,
- const int *const cards) restrict2
+ CardsList cards) restrict2
{
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
@@ -2505,6 +2509,9 @@ void Being::setSprite(const unsigned int slot,
if (slot >= CAST_U32(mSpriteIDs.size()))
mSpriteIDs.resize(slot + 1, 0);
+ if (slot >= CAST_U32(mSpriteCardsIds.size()))
+ mSpriteCardsIds.resize(slot + 1, zeroCards);
+
if (slot >= CAST_U32(mSpriteColors.size()))
mSpriteColors.resize(slot + 1, "");
@@ -2551,7 +2558,7 @@ void Being::setSprite(const unsigned int slot,
addPet(pet);
}
- if (cards != nullptr)
+ if (!cards.isEmpty())
colorId = ItemColorManager::getColorFromCards(cards);
if (!filename.empty())
@@ -2590,6 +2597,7 @@ void Being::setSprite(const unsigned int slot,
mSpriteIDs[slot] = id;
mSpriteColors[slot] = color;
mSpriteColorsIds[slot] = colorId;
+ mSpriteCardsIds[slot] = CardsList(cards);
recalcSpritesOrder();
if (beingEquipmentWindow)
beingEquipmentWindow->updateBeing(this);
@@ -2606,7 +2614,7 @@ void Being::setWeaponId(const int id) restrict2
void Being::setTempSprite(const unsigned int slot,
const int id,
std::string color,
- const int *const cards) restrict2
+ CardsList cards) restrict2
{
if (!charServerHandler || slot >= charServerHandler->maxSprite())
return;
@@ -2617,6 +2625,9 @@ void Being::setTempSprite(const unsigned int slot,
if (slot >= CAST_U32(mSpriteIDs.size()))
mSpriteIDs.resize(slot + 1, 0);
+ if (slot >= CAST_U32(mSpriteCardsIds.size()))
+ mSpriteCardsIds.resize(slot + 1, zeroCards);
+
if (slot >= CAST_U32(mSpriteColors.size()))
mSpriteColors.resize(slot + 1, "");
@@ -2643,7 +2654,7 @@ void Being::setTempSprite(const unsigned int slot,
AnimatedSprite *restrict equipmentSprite = nullptr;
ItemColor colorId = ItemColor_one;
- if (cards != nullptr)
+ if (!cards.isEmpty())
colorId = ItemColorManager::getColorFromCards(cards);
if (!filename.empty())
@@ -2687,7 +2698,7 @@ void Being::setSpriteID(const unsigned int slot,
id,
mSpriteColors[slot],
ItemColor_one,
- nullptr);
+ mSpriteCardsIds[slot]);
}
void Being::setSpriteColor(const unsigned int slot,
@@ -2697,7 +2708,7 @@ void Being::setSpriteColor(const unsigned int slot,
mSpriteIDs[slot],
color,
ItemColor_one,
- nullptr);
+ mSpriteCardsIds[slot]);
}
void Being::setHairStyle(const unsigned int slot,
@@ -2708,7 +2719,7 @@ void Being::setHairStyle(const unsigned int slot,
id,
ItemDB::get(id).getDyeColorsString(mHairColor),
ItemColor_one,
- nullptr);
+ mSpriteCardsIds[slot]);
// dumpSprites();
}
@@ -2723,7 +2734,7 @@ void Being::setHairColor(const unsigned int slot,
mSpriteIDs[slot],
ItemDB::get(id).getDyeColorsString(color),
ItemColor_one,
- nullptr);
+ mSpriteCardsIds[slot]);
}
}
@@ -2912,7 +2923,7 @@ void Being::setGender(const GenderT gender) restrict2
mSpriteIDs[i],
mSpriteColors[i],
ItemColor_one,
- nullptr);
+ mSpriteCardsIds[i]);
}
}
@@ -3484,7 +3495,7 @@ void Being::recalcSpritesOrder() restrict2
setTempSprite(remSprite,
repIt->second,
mSpriteColors[remSprite],
- nullptr);
+ mSpriteCardsIds[remSprite]);
}
else
{
@@ -3492,7 +3503,7 @@ void Being::recalcSpritesOrder() restrict2
repIt->second,
ItemDB::get(repIt->second)
.getDyeColorsString(mHairColor),
- nullptr);
+ mSpriteCardsIds[remSprite]);
}
updatedSprite[remSprite] = true;
}
@@ -3515,7 +3526,7 @@ void Being::recalcSpritesOrder() restrict2
setTempSprite(slot2,
repIt->second,
mSpriteColors[slot2],
- nullptr);
+ mSpriteCardsIds[slot2]);
}
else
{
@@ -3524,7 +3535,7 @@ void Being::recalcSpritesOrder() restrict2
ItemDB::get(repIt->second)
.getDyeColorsString(
mHairColor),
- nullptr);
+ mSpriteCardsIds[slot2]);
}
updatedSprite[slot2] = true;
}
@@ -3669,7 +3680,7 @@ void Being::recalcSpritesOrder() restrict2
setTempSprite(slot,
id,
mSpriteColors[slot],
- nullptr);
+ mSpriteCardsIds[slot]);
}
}
}
@@ -3684,7 +3695,7 @@ void Being::recalcSpritesOrder() restrict2
setTempSprite(static_cast<unsigned int>(slot),
id,
mSpriteColors[slot],
- nullptr);
+ mSpriteCardsIds[slot]);
}
}
}
@@ -3758,7 +3769,7 @@ void Being::undressItemById(const int id) restrict2
0,
std::string(),
ItemColor_one,
- nullptr);
+ zeroCards);
break;
}
}
diff --git a/src/being/being.h b/src/being/being.h
index e5cc44fa0..bcb9d3106 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -23,6 +23,8 @@
#ifndef BEING_BEING_H
#define BEING_BEING_H
+#include "position.h"
+
#include "enums/being/badgeindex.h"
#include "enums/being/reachable.h"
@@ -32,7 +34,7 @@
#include "resources/beinginfo.h"
-#include "position.h"
+#include "resources/item/cardslist.h"
#include "being/actorsprite.h"
@@ -321,14 +323,14 @@ class Being notfinal : public ActorSprite,
const int id,
std::string color,
ItemColor colorId,
- const int *const cards) restrict2;
+ CardsList cards) restrict2;
void setWeaponId(const int id) restrict2;
void setTempSprite(const unsigned int slot,
const int id,
std::string color,
- const int *const cards) restrict2;
+ CardsList cards) restrict2;
void updateSprite(const unsigned int slot,
const int id,
@@ -1094,6 +1096,7 @@ class Being notfinal : public ActorSprite,
StringVect mSpriteColors;
std::vector<int> mSpriteIDs;
+ std::vector<CardsList> mSpriteCardsIds;
std::vector<ItemColor> mSpriteColorsIds;
SpriteParticleInfo mSpriteParticles;
diff --git a/src/itemcolormanager.cpp b/src/itemcolormanager.cpp
index 0cf48015b..dc8d65afb 100644
--- a/src/itemcolormanager.cpp
+++ b/src/itemcolormanager.cpp
@@ -50,3 +50,8 @@ ItemColor ItemColorManager::getColorFromCards(const int *const cards)
}
return ItemColor_one;
}
+
+ItemColor ItemColorManager::getColorFromCards(const CardsList &cards)
+{
+ return getColorFromCards(&cards.cards[0]);
+}
diff --git a/src/itemcolormanager.h b/src/itemcolormanager.h
index 8b778d149..61addf721 100644
--- a/src/itemcolormanager.h
+++ b/src/itemcolormanager.h
@@ -23,6 +23,8 @@
#include "enums/simpletypes/itemcolor.h"
+#include "resources/item/cardslist.h"
+
#include "localconsts.h"
class ItemColorManager final
@@ -32,6 +34,9 @@ class ItemColorManager final
static ItemColor getColorFromCards(const int *const cards)
A_WARN_UNUSED;
+
+ static ItemColor getColorFromCards(const CardsList &cards)
+ A_WARN_UNUSED;
};
#endif // ITEMCOLORMANAGER_H
diff --git a/src/resources/item/cardslist.h b/src/resources/item/cardslist.h
index f8a7fee3a..8da565091 100644
--- a/src/resources/item/cardslist.h
+++ b/src/resources/item/cardslist.h
@@ -40,6 +40,28 @@ struct CardsList final
cards[3] = card3;
}
+ CardsList(const int *const cards0)
+ {
+ if (cards0)
+ {
+ for (int f = 0; f < maxCards; f ++)
+ cards[f] = cards0[f];
+ }
+ else
+ {
+ for (int f = 0; f < maxCards; f ++)
+ cards[f] = 0;
+ }
+ }
+
+ bool isEmpty() const A_WARN_UNUSED
+ {
+ return cards[0] == 0 &&
+ cards[1] == 0 &&
+ cards[2] == 0 &&
+ cards[3] == 0;
+ }
+
int cards[maxCards];
};