aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2018-03-22 19:17:54 -0400
committerPaul Gilbert2018-03-22 19:17:54 -0400
commit808090792749e4f6f819373f20225fa055a5f932 (patch)
tree0a021d658c92b764b0d52e892c4be05f0be0feec
parentd725d78ec5e58d84433634ce1d6171c722df46bc (diff)
downloadscummvm-rg350-808090792749e4f6f819373f20225fa055a5f932.tar.gz
scummvm-rg350-808090792749e4f6f819373f20225fa055a5f932.tar.bz2
scummvm-rg350-808090792749e4f6f819373f20225fa055a5f932.zip
XEEN: Fix bought items going into correct character's inventory
-rw-r--r--engines/xeen/character.cpp60
-rw-r--r--engines/xeen/character.h8
-rw-r--r--engines/xeen/item.cpp21
-rw-r--r--engines/xeen/item.h10
4 files changed, 97 insertions, 2 deletions
diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp
index 47d43d806f..9fde26edaa 100644
--- a/engines/xeen/character.cpp
+++ b/engines/xeen/character.cpp
@@ -37,13 +37,69 @@ void AttributePair::synchronize(Common::Serializer &s) {
/*------------------------------------------------------------------------*/
-Character::Character():
- _weapons(this), _armor(this), _accessories(this), _misc(this), _items(this) {
+Character::Character(): _weapons(this), _armor(this), _accessories(this), _misc(this), _items(this) {
clear();
_faceSprites = nullptr;
_rosterId = -1;
}
+Character::Character(const Character &src) : _weapons(this), _armor(this), _accessories(this), _misc(this), _items(this) {
+ clear();
+
+ _faceSprites = src._faceSprites;
+ _rosterId = src._rosterId;
+ _name = src._name;
+ _sex = src._sex;
+ _race = src._race;
+ _xeenSide = src._xeenSide;
+ _class = src._class;
+ _might = src._might;
+ _intellect = src._intellect;
+ _personality = src._personality;
+ _endurance = src._endurance;
+ _speed = src._speed;
+ _accuracy = src._accuracy;
+ _luck = src._luck;
+ _ACTemp = src._ACTemp;
+ _level = src._level;
+ _birthDay = src._birthDay;
+ _tempAge = src._tempAge;
+ Common::copy(&src._skills[0], &src._skills[18], &_skills[0]);
+ Common::copy(&src._awards[0], &src._awards[128], &_awards[0]);
+ Common::copy(&src._spells[0], &src._spells[SPELLS_PER_CLASS], &_spells[0]);
+ _lloydMap = src._lloydMap;
+ _lloydPosition = src._lloydPosition;
+ _hasSpells = src._hasSpells;
+ _currentSpell = src._currentSpell;
+ _quickOption = src._quickOption;
+ _weapons = src._weapons;
+ _armor = src._armor;
+ _accessories = src._accessories;
+ _misc = src._misc;
+ _lloydSide = src._lloydSide;
+ _fireResistence = src._fireResistence;
+ _coldResistence = src._coldResistence;
+ _electricityResistence = src._electricityResistence;
+ _poisonResistence = src._poisonResistence;
+ _energyResistence = src._energyResistence;
+ _magicResistence = src._magicResistence;
+ Common::copy(&src._conditions[0], &src._conditions[16], &_conditions[0]);
+ _townUnknown = src._townUnknown;
+ _savedMazeId = src._savedMazeId;
+ _currentHp = src._currentHp;
+ _currentSp = src._currentSp;
+ _birthYear = src._birthYear;
+ _experience = src._experience;
+ _currentAdventuringSpell = src._currentAdventuringSpell;
+ _currentCombatSpell = src._currentCombatSpell;
+
+ for (ItemCategory category = CATEGORY_WEAPON; category <= CATEGORY_MISC; category = (ItemCategory)((int)category + 1)) {
+ const InventoryItems &srcItems = src._items[category];
+ InventoryItems &destItems = _items[category];
+ destItems = srcItems;
+ }
+}
+
void Character::clear() {
_sex = MALE;
_race = HUMAN;
diff --git a/engines/xeen/character.h b/engines/xeen/character.h
index c169e6c769..5aa62d15ef 100644
--- a/engines/xeen/character.h
+++ b/engines/xeen/character.h
@@ -155,9 +155,17 @@ public:
SpriteResource *_faceSprites;
int _rosterId;
public:
+ /**
+ * Constructor
+ */
Character();
/**
+ * Constructor
+ */
+ Character(const Character &src);
+
+ /**
* Clears the data for a character
*/
void clear();
diff --git a/engines/xeen/item.cpp b/engines/xeen/item.cpp
index fe9e4ab052..fb8dd24aac 100644
--- a/engines/xeen/item.cpp
+++ b/engines/xeen/item.cpp
@@ -93,6 +93,14 @@ void InventoryItems::clear() {
operator[](idx).clear();
}
+InventoryItems &InventoryItems::operator=(const InventoryItems &src) {
+ Common::Array<XeenItem>::clear();
+ assert(src.size() == INV_ITEMS_TOTAL);
+ for (uint idx = 0; idx < INV_ITEMS_TOTAL; ++idx)
+ push_back(src[idx]);
+ return *this;
+}
+
bool InventoryItems::passRestrictions(int itemId, bool suppressError) const {
CharacterClass charClass = _character->_class;
@@ -642,6 +650,19 @@ InventoryItems &InventoryItemsGroup::operator[](ItemCategory category) {
}
}
+const InventoryItems &InventoryItemsGroup::operator[](ItemCategory category) const {
+ switch (category) {
+ case CATEGORY_WEAPON:
+ return _owner->_weapons;
+ case CATEGORY_ARMOR:
+ return _owner->_armor;
+ case CATEGORY_ACCESSORY:
+ return _owner->_accessories;
+ default:
+ return _owner->_misc;
+ }
+}
+
void InventoryItemsGroup::breakAllItems() {
for (int idx = 0; idx < INV_ITEMS_TOTAL; ++idx) {
if (_owner->_weapons[idx]._id != 34) {
diff --git a/engines/xeen/item.h b/engines/xeen/item.h
index c79de0c282..044d73e368 100644
--- a/engines/xeen/item.h
+++ b/engines/xeen/item.h
@@ -116,6 +116,11 @@ public:
void clear();
/**
+ * Handles copying items from one character to another
+ */
+ InventoryItems &operator=(const InventoryItems &src);
+
+ /**
* Return whether a given item passes class-based usage restrictions
* @param itemId Item Index
* @param suppressError If true, no dialog is shown if the item doesn't pass restrictions
@@ -269,6 +274,11 @@ public:
InventoryItems &operator[](ItemCategory category);
/**
+ * Returns the inventory items for a given category
+ */
+ const InventoryItems &operator[](ItemCategory category) const;
+
+ /**
* Breaks all the items in a given character's inventory
*/
void breakAllItems();