From 85c2dd5f6864540d66e0abfe74ec791bbde41c30 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 5 Feb 2015 20:05:24 -0500 Subject: XEEN: Split up assembleItemName and renamed to getFullDescription --- engines/xeen/character.cpp | 174 ++++++++++++++++++++++++----------------- engines/xeen/character.h | 18 ++++- engines/xeen/dialogs_items.cpp | 19 +++-- engines/xeen/resources.cpp | 4 + engines/xeen/resources.h | 4 + 5 files changed, 138 insertions(+), 81 deletions(-) (limited to 'engines') diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp index b8dd53ddff..ff85c97855 100644 --- a/engines/xeen/character.cpp +++ b/engines/xeen/character.cpp @@ -122,9 +122,19 @@ Common::String InventoryItems::getName(int itemIndex) { /** * Discard an item from the inventory */ -void InventoryItems::discardItem(int itemIndex) { - operator[](itemIndex).clear(); - sort(); +bool InventoryItems::discardItem(int itemIndex) { + XeenItem &item = operator[](itemIndex); + XeenEngine *vm = Party::_vm; + + if (item._bonusFlags & ITEMFLAG_CURSED) { + ErrorScroll::show(vm, CANNOT_DISCARD_CURSED_ITEM); + return false; + } else { + Common::String itemDesc = getFullDescription(itemIndex, 4); + + error("TODO: discardItem - %s", itemDesc.c_str()); + } + error("TODO"); } /** @@ -149,8 +159,21 @@ void InventoryItems::sort() { } } +/** + * Un-equips the given item + */ void InventoryItems::removeItem(int itemIndex) { - error("TODO"); + XeenItem &item = operator[](itemIndex); + XeenEngine *vm = Party::_vm; + + if (item._bonusFlags & ITEMFLAG_CURSED) + ErrorScroll::show(vm, CANNOT_REMOVE_CURSED_ITEM); + else + item._frame = 0; +} + +XeenEngine *InventoryItems::vm() { + return Party::_vm; } void InventoryItems::equipError(int itemIndex1, ItemCategory category1, int itemIndex2, @@ -224,6 +247,25 @@ void WeaponItems::equipItem(int itemIndex) { } } +/** + * Assembles a full lines description for a specified item for use in + * the Items dialog + */ +Common::String WeaponItems::getFullDescription(int itemIndex, int displayNum) { + XeenItem &i = operator[](itemIndex); + Spells &spells = *vm()->_spells; + + return Common::String::format("\f%02u%s%s%s\f%02u%s%s%s", displayNum, + !i._bonusFlags ? spells._maeNames[i._material] : "", + (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", + (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", + WEAPON_NAMES[i._id], + !i._bonusFlags ? "" : BONUS_NAMES[i._bonusFlags & ITEMFLAG_BONUS_MASK], + (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || + !i._bonusFlags ? "\b " : "" + ); +} + /*------------------------------------------------------------------------*/ /** @@ -307,6 +349,24 @@ void ArmorItems::equipItem(int itemIndex) { } } +/** + * Assembles a full lines description for a specified item for use in + * the Items dialog + */ +Common::String ArmorItems::getFullDescription(int itemIndex, int displayNum) { + XeenItem &i = operator[](itemIndex); + Spells &spells = *vm()->_spells; + + return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, + !i._bonusFlags ? "" : spells._maeNames[i._material], + (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", + (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", + ARMOR_NAMES[i._id], + (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || + !i._bonusFlags ? "\b " : "" + ); +} + /*------------------------------------------------------------------------*/ /** @@ -359,6 +419,46 @@ void AccessoryItems::equipItem(int itemIndex) { item._frame = 11; } } + +/** + * Assembles a full lines description for a specified item for use in + * the Items dialog + */ +Common::String AccessoryItems::getFullDescription(int itemIndex, int displayNum) { + Spells &spells = *vm()->_spells; + XeenItem &i = operator[](itemIndex); + + return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, + !i._bonusFlags ? "" : spells._maeNames[i._material], + (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", + (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", + ARMOR_NAMES[i._id], + (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || + !i._bonusFlags ? "\b " : "" + ); +} + +/*------------------------------------------------------------------------*/ + +/** + * Assembles a full lines description for a specified item for use in + * the Items dialog + */ +Common::String MiscItems::getFullDescription(int itemIndex, int displayNum) { + XeenItem &i = operator[](itemIndex); + Spells &spells = *vm()->_spells; + + return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, + !i._bonusFlags ? "" : spells._maeNames[i._material], + (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", + (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", + ARMOR_NAMES[i._id], + (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || + !i._id ? "\b " : "" + ); +} + + /*------------------------------------------------------------------------*/ InventoryItemsGroup::InventoryItemsGroup(InventoryItems &weapons, InventoryItems &armor, @@ -1203,70 +1303,4 @@ int Character::getNumAwards() const { return total; } -/** - * Assembles a full lines description for a specified item for use in - * the Items dialog - */ -Common::String Character::assembleItemName(int itemIndex, int displayNum, - ItemCategory category) { - Spells &spells = *Party::_vm->_spells; - - switch (category) { - case CATEGORY_WEAPON: { - // Weapons - XeenItem &i = _weapons[itemIndex]; - return Common::String::format("\f%02u%s%s%s\f%02u%s%s%s", displayNum, - !i._bonusFlags ? spells._maeNames[i._material] : "", - (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", - (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", - WEAPON_NAMES[i._id], - !i._bonusFlags ? "" : BONUS_NAMES[i._bonusFlags & ITEMFLAG_BONUS_MASK], - (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || - !i._bonusFlags ? "\b " : "" - ); - } - - case CATEGORY_ARMOR: { - // Armor - XeenItem &i = _armor[itemIndex]; - return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, - !i._bonusFlags ? "" : spells._maeNames[i._material], - (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", - (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", - ARMOR_NAMES[i._id], - (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || - !i._bonusFlags ? "\b " : "" - ); - } - - case CATEGORY_ACCESSORY: { - // Accessories - XeenItem &i = _accessories[itemIndex]; - return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, - !i._bonusFlags ? "" : spells._maeNames[i._material], - (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", - (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", - ARMOR_NAMES[i._id], - (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || - !i._bonusFlags ? "\b " : "" - ); - } - - case CATEGORY_MISC: { - // Misc - XeenItem &i = _misc[itemIndex]; - return Common::String::format("\f%02u%s%s%s\f%02u%s%s", displayNum, - !i._bonusFlags ? "" : spells._maeNames[i._material], - (i._bonusFlags & ITEMFLAG_BROKEN) ? ITEM_BROKEN : "", - (i._bonusFlags & ITEMFLAG_CURSED) ? ITEM_CURSED : "", - ARMOR_NAMES[i._id], - (i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED)) || - !i._id ? "\b " : "" - ); - } - default: - return ""; - } -} - } // End of namespace Xeen diff --git a/engines/xeen/character.h b/engines/xeen/character.h index c4eae0e706..6514caeaa1 100644 --- a/engines/xeen/character.h +++ b/engines/xeen/character.h @@ -100,6 +100,7 @@ protected: ItemCategory _category; const char *const *_names; + XeenEngine *vm(); void equipError(int itemIndex1, ItemCategory category1, int itemIndex2, ItemCategory category2); public: @@ -109,7 +110,9 @@ public: Common::String getName(int itemIndex); - void discardItem(int itemIndex); + virtual Common::String getFullDescription(int itemIndex, int displayNum) = 0; + + bool discardItem(int itemIndex); virtual void equipItem(int itemIndex) {} @@ -121,24 +124,35 @@ public: class WeaponItems: public InventoryItems { public: WeaponItems(Character *character) : InventoryItems(character, CATEGORY_WEAPON) {} + virtual void equipItem(int itemIndex); + + virtual Common::String getFullDescription(int itemIndex, int displayNum); }; class ArmorItems : public InventoryItems { public: ArmorItems(Character *character) : InventoryItems(character, CATEGORY_ARMOR) {} + virtual void equipItem(int itemIndex); + + virtual Common::String getFullDescription(int itemIndex, int displayNum); }; class AccessoryItems : public InventoryItems { public: AccessoryItems(Character *character) : InventoryItems(character, CATEGORY_ACCESSORY) {} + virtual void equipItem(int itemIndex); + + virtual Common::String getFullDescription(int itemIndex, int displayNum); }; class MiscItems : public InventoryItems { public: MiscItems(Character *character) : InventoryItems(character, CATEGORY_MISC) {} + + virtual Common::String getFullDescription(int itemIndex, int displayNum); }; class InventoryItemsGroup { @@ -257,8 +271,6 @@ public: int getNumSkills() const; int getNumAwards() const; - - Common::String assembleItemName(int itemIndex, int displayNum, ItemCategory category); }; } // End of namespace Xeen diff --git a/engines/xeen/dialogs_items.cpp b/engines/xeen/dialogs_items.cpp index c28085c15e..beaf5652d7 100644 --- a/engines/xeen/dialogs_items.cpp +++ b/engines/xeen/dialogs_items.cpp @@ -141,11 +141,11 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) { || mode == ITEMMODE_6 || mode == ITEMMODE_4) { lines.push_back(Common::String::format(ITEMS_DIALOG_LINE1, arr[idx], idx + 1, - c->assembleItemName(idx, arr[idx], category))); + c->_items[category].getFullDescription(idx, arr[idx]))); } else { lines.push_back(Common::String::format(ITEMS_DIALOG_LINE2, arr[idx], idx + 1, - c->assembleItemName(idx, arr[idx], category), + c->_items[category].getFullDescription(idx, arr[idx]), calcItemCost(c, idx, mode, mode == ITEMMODE_TO_GOLD ? 1 : startingChar->_skills[MERCHANT], category) @@ -186,7 +186,7 @@ Character *ItemsDialog::execute(Character *c, ItemsMode mode) { lines.push_back(Common::String::format(ITEMS_DIALOG_LINE2, arr[idx], idx + 1, - c->assembleItemName(idx, arr[idx], category), + c->_items[category].getFullDescription(idx, arr[idx]), calcItemCost(c, idx, tempMode, skill, category) )); } @@ -631,8 +631,8 @@ bool ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, It ErrorScroll::show(_vm, USE_ITEM_IN_COMBAT); } else if (i._id && (i._bonusFlags & ITEMFLAG_BONUS_MASK) && !(i._bonusFlags & (ITEMFLAG_BROKEN | ITEMFLAG_CURSED))) { - int bonus = (i._bonusFlags & ITEMFLAG_BONUS_MASK) - 1; - i._bonusFlags = bonus; + int charges = (i._bonusFlags & ITEMFLAG_BONUS_MASK) - 1; + i._bonusFlags = charges; _oldCharacter = &c; screen._windows[30].close(); @@ -640,16 +640,19 @@ bool ItemsDialog::doItemOptions(Character &c, int actionIndex, int itemIndex, It screen._windows[24].close(); spells.doSpell(i._id); - if (!bonus) { - c._items[category].discardItem(itemIndex); + if (!charges) { + // Ran out of charges, so make item disappear + c._items[category][itemIndex].clear(); + c._items[category].sort(); } } else { ErrorScroll::show(_vm, Common::String::format(NO_SPECIAL_ABILITIES, - c.assembleItemName(itemIndex, 15, category).c_str() + c._items[category].getFullDescription(itemIndex, 15).c_str() )); } } } + break; case 3: // TODO: Remaining switches default: diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp index c643152f5b..b38868f7a4 100644 --- a/engines/xeen/resources.cpp +++ b/engines/xeen/resources.cpp @@ -1130,4 +1130,8 @@ const char *const REMOVE_X_TO_EQUIP_Y = "\x3""c\v007You must remove %sto equip % const char *const RING = "ring"; const char *const MEDAL = "medal"; +const char *const CANNOT_REMOVE_CURSED_ITEM = "\x3""You cannot remove a cursed item!"; + +const char *const CANNOT_DISCARD_CURSED_ITEM = "\3x""cYou cannot discard a cursed item!"; + } // End of namespace Xeen diff --git a/engines/xeen/resources.h b/engines/xeen/resources.h index c6d2bdeb6d..e1f276b91c 100644 --- a/engines/xeen/resources.h +++ b/engines/xeen/resources.h @@ -403,6 +403,10 @@ extern const char *const REMOVE_X_TO_EQUIP_Y; extern const char *const RING; extern const char *const MEDAL; +extern const char *const CANNOT_REMOVE_CURSED_ITEM; + +extern const char *const CANNOT_DISCARD_CURSED_ITEM; + } // End of namespace Xeen #endif /* XEEN_RESOURCES_H */ -- cgit v1.2.3