From fc04fe6da8b490cceef6ee167775a65fe2e1b607 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 5 Feb 2015 08:00:28 -0500 Subject: XEEN: equipItem methods for armor and accessories --- engines/xeen/character.cpp | 135 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp index 00b7e4333f..b8dd53ddff 100644 --- a/engines/xeen/character.cpp +++ b/engines/xeen/character.cpp @@ -171,6 +171,9 @@ void InventoryItems::equipError(int itemIndex1, ItemCategory category1, int item /*------------------------------------------------------------------------*/ +/** + * Equip a given weapon + */ void WeaponItems::equipItem(int itemIndex) { XeenItem &item = operator[](itemIndex); @@ -208,10 +211,10 @@ void WeaponItems::equipItem(int itemIndex) { } } - for (uint idx = 0; idx < size(); ++idx) { + for (uint idx = 0; idx < _character->_armor.size(); ++idx) { XeenItem &i = _character->_armor[idx]; if (i._frame == 2) { - equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_WEAPON); + equipError(itemIndex, CATEGORY_WEAPON, idx, CATEGORY_ARMOR); return; } } @@ -223,14 +226,138 @@ void WeaponItems::equipItem(int itemIndex) { /*------------------------------------------------------------------------*/ +/** + * Equip a given piece of armor + */ void ArmorItems::equipItem(int itemIndex) { - error("TODO"); + XeenItem &item = operator[](itemIndex); + + if (item._id <= 7) { + if (passRestrictions(item._id, false)) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 9) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + item._frame = 3; + } + } else if (item._id == 8) { + if (passRestrictions(item._id, false)) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 2) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + for (uint idx = 0; idx < _character->_weapons.size(); ++idx) { + XeenItem &i = _character->_weapons[idx]; + if (i._frame == 13) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_WEAPON); + return; + } + } + + item._frame = 2; + } + } else if (item._id == 9) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 5) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + item._frame = 5; + } else if (item._id == 10) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 9) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + item._frame = 9; + } else if (item._id <= 12) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 10) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + item._frame = 10; + } else { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 6) { + equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_ARMOR); + return; + } + } + + item._frame = 6; + } } /*------------------------------------------------------------------------*/ +/** + * Equip a given accessory + */ void AccessoryItems::equipItem(int itemIndex) { - error("TODO"); + XeenItem &item = operator[](itemIndex); + + if (item._id == 1) { + int count = 0; + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 8) + ++count; + } + + if (count <= 1) + item._frame = 8; + else + equipError(-1, CATEGORY_ACCESSORY, itemIndex, CATEGORY_ACCESSORY); + } else if (item._id == 2) { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 12) { + equipError(itemIndex, CATEGORY_ACCESSORY, idx, CATEGORY_ACCESSORY); + return; + } + } + } else if (item._id <= 7) { + int count = 0; + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 7) + ++count; + } + + if (count <= 1) + item._frame = 7; + else + equipError(-2, CATEGORY_ACCESSORY, itemIndex, CATEGORY_ACCESSORY); + } else { + for (uint idx = 0; idx < size(); ++idx) { + XeenItem &i = operator[](idx); + if (i._frame == 11) { + equipError(itemIndex, CATEGORY_ACCESSORY, idx, CATEGORY_ACCESSORY); + return; + } + } + + item._frame = 11; + } } /*------------------------------------------------------------------------*/ -- cgit v1.2.3