aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen
diff options
context:
space:
mode:
authorPaul Gilbert2015-02-04 22:24:45 -0500
committerPaul Gilbert2015-02-04 22:24:45 -0500
commita983d9abcea603a3857c1c250f398e6b2fae29a0 (patch)
tree502c9a413664b0af49b3f5acf878c3b0dceed83a /engines/xeen
parent7ea32f3333cb2123675f6dbdfae3ed232347d1a5 (diff)
downloadscummvm-rg350-a983d9abcea603a3857c1c250f398e6b2fae29a0.tar.gz
scummvm-rg350-a983d9abcea603a3857c1c250f398e6b2fae29a0.tar.bz2
scummvm-rg350-a983d9abcea603a3857c1c250f398e6b2fae29a0.zip
XEEN: Implemented weapon variation of equipItem
Diffstat (limited to 'engines/xeen')
-rw-r--r--engines/xeen/character.cpp96
-rw-r--r--engines/xeen/character.h40
-rw-r--r--engines/xeen/dialogs_error.cpp25
-rw-r--r--engines/xeen/dialogs_error.h13
-rw-r--r--engines/xeen/resources.cpp5
-rw-r--r--engines/xeen/resources.h5
-rw-r--r--engines/xeen/spells.cpp4
7 files changed, 159 insertions, 29 deletions
diff --git a/engines/xeen/character.cpp b/engines/xeen/character.cpp
index 02c578a313..00b7e4333f 100644
--- a/engines/xeen/character.cpp
+++ b/engines/xeen/character.cpp
@@ -21,6 +21,7 @@
*/
#include "xeen/character.h"
+#include "xeen/dialogs_error.h"
#include "xeen/resources.h"
#include "xeen/xeen.h"
@@ -110,12 +111,25 @@ bool InventoryItems::passRestrictions(int itemId, bool showError) const {
return false;
}
+/**
+ * Return the bare name of a given inventory item
+ */
+Common::String InventoryItems::getName(int itemIndex) {
+ int id = operator[](itemIndex)._id;
+ return _names[id];
+}
+/**
+ * Discard an item from the inventory
+ */
void InventoryItems::discardItem(int itemIndex) {
operator[](itemIndex).clear();
sort();
}
+/**
+ * Sorts the items list, removing any empty item slots to the end of the array
+ */
void InventoryItems::sort() {
for (uint idx = 0; idx < size(); ++idx) {
if (operator[](idx)._id == 0) {
@@ -135,16 +149,91 @@ void InventoryItems::sort() {
}
}
-void InventoryItems::equipItem(int itemIndex) {
+void InventoryItems::removeItem(int itemIndex) {
error("TODO");
}
-void InventoryItems::removeItem(int itemIndex) {
+void InventoryItems::equipError(int itemIndex1, ItemCategory category1, int itemIndex2,
+ ItemCategory category2) {
+ XeenEngine *vm = Party::_vm;
+
+ if (itemIndex1 >= 0) {
+ Common::String itemName1 = _character->_items[category1].getName(itemIndex1);
+ Common::String itemName2 = _character->_items[category2].getName(itemIndex2);
+
+ ErrorDialog::show(vm, Common::String::format(REMOVE_X_TO_EQUIP_Y,
+ itemName1.c_str(), itemName2.c_str()));
+ } else {
+ ErrorDialog::show(vm, Common::String::format(EQUIPPED_ALL_YOU_CAN,
+ (itemIndex1 == -1) ? RING : MEDAL));
+ }
+}
+
+/*------------------------------------------------------------------------*/
+
+void WeaponItems::equipItem(int itemIndex) {
+ XeenItem &item = operator[](itemIndex);
+
+ if (item._id <= 17) {
+ if (passRestrictions(item._id, false)) {
+ for (uint idx = 0; idx < size(); ++idx) {
+ XeenItem &i = operator[](idx);
+ if (i._frame == 13 || i._frame == 1) {
+ equipError(itemIndex, CATEGORY_WEAPON, idx, CATEGORY_WEAPON);
+ return;
+ }
+ }
+
+ item._frame = 1;
+ }
+ } else if (item._id >= 30 && item._id <= 33) {
+ if (passRestrictions(item._id, false)) {
+ for (uint idx = 0; idx < size(); ++idx) {
+ XeenItem &i = operator[](idx);
+ if (i._frame == 4) {
+ equipError(itemIndex, CATEGORY_WEAPON, idx, CATEGORY_WEAPON);
+ return;
+ }
+ }
+
+ item._frame = 4;
+ }
+ } else {
+ if (passRestrictions(item._id, false)) {
+ for (uint idx = 0; idx < size(); ++idx) {
+ XeenItem &i = operator[](idx);
+ if (i._frame == 13 || i._frame == 1) {
+ equipError(itemIndex, CATEGORY_WEAPON, idx, CATEGORY_WEAPON);
+ return;
+ }
+ }
+
+ for (uint idx = 0; idx < size(); ++idx) {
+ XeenItem &i = _character->_armor[idx];
+ if (i._frame == 2) {
+ equipError(itemIndex, CATEGORY_ARMOR, idx, CATEGORY_WEAPON);
+ return;
+ }
+ }
+
+ item._frame = 13;
+ }
+ }
+}
+
+/*------------------------------------------------------------------------*/
+
+void ArmorItems::equipItem(int itemIndex) {
error("TODO");
}
/*------------------------------------------------------------------------*/
+void AccessoryItems::equipItem(int itemIndex) {
+ error("TODO");
+}
+/*------------------------------------------------------------------------*/
+
InventoryItemsGroup::InventoryItemsGroup(InventoryItems &weapons, InventoryItems &armor,
InventoryItems &accessories, InventoryItems &misc) {
_itemSets[0] = &weapons;
@@ -174,8 +263,7 @@ AttributePair::AttributePair() {
/*------------------------------------------------------------------------*/
Character::Character():
- _weapons(this, CATEGORY_WEAPON), _armor(this, CATEGORY_ARMOR),
- _accessories(this, CATEGORY_ACCESSORY), _misc(this, CATEGORY_MISC),
+ _weapons(this), _armor(this), _accessories(this), _misc(this),
_items(_weapons, _armor, _accessories, _misc) {
_sex = MALE;
_race = HUMAN;
diff --git a/engines/xeen/character.h b/engines/xeen/character.h
index b3c9965e9d..c4eae0e706 100644
--- a/engines/xeen/character.h
+++ b/engines/xeen/character.h
@@ -95,24 +95,52 @@ public:
};
class InventoryItems : public Common::Array<XeenItem> {
-private:
+protected:
Character *_character;
ItemCategory _category;
const char *const *_names;
+
+ void equipError(int itemIndex1, ItemCategory category1, int itemIndex2,
+ ItemCategory category2);
public:
InventoryItems(Character *character, ItemCategory category);
bool passRestrictions(int itemId, bool showError) const;
+ Common::String getName(int itemIndex);
+
void discardItem(int itemIndex);
- void equipItem(int itemIndex);
+ virtual void equipItem(int itemIndex) {}
void removeItem(int itemIndex);
void sort();
};
+class WeaponItems: public InventoryItems {
+public:
+ WeaponItems(Character *character) : InventoryItems(character, CATEGORY_WEAPON) {}
+ virtual void equipItem(int itemIndex);
+};
+
+class ArmorItems : public InventoryItems {
+public:
+ ArmorItems(Character *character) : InventoryItems(character, CATEGORY_ARMOR) {}
+ virtual void equipItem(int itemIndex);
+};
+
+class AccessoryItems : public InventoryItems {
+public:
+ AccessoryItems(Character *character) : InventoryItems(character, CATEGORY_ACCESSORY) {}
+ virtual void equipItem(int itemIndex);
+};
+
+class MiscItems : public InventoryItems {
+public:
+ MiscItems(Character *character) : InventoryItems(character, CATEGORY_MISC) {}
+};
+
class InventoryItemsGroup {
private:
InventoryItems *_itemSets[4];
@@ -162,10 +190,10 @@ public:
int _currentSpell;
int _quickOption;
InventoryItemsGroup _items;
- InventoryItems _weapons;
- InventoryItems _armor;
- InventoryItems _accessories;
- InventoryItems _misc;
+ WeaponItems _weapons;
+ ArmorItems _armor;
+ AccessoryItems _accessories;
+ MiscItems _misc;
int _lloydSide;
AttributePair _fireResistence;
AttributePair _coldResistence;
diff --git a/engines/xeen/dialogs_error.cpp b/engines/xeen/dialogs_error.cpp
index a58e0e9e78..598af1ede7 100644
--- a/engines/xeen/dialogs_error.cpp
+++ b/engines/xeen/dialogs_error.cpp
@@ -27,29 +27,19 @@
namespace Xeen {
-void ErrorScroll::show(XeenEngine *vm, const Common::String &msg, ErrorWaitType waitType) {
- ErrorScroll *dlg = new ErrorScroll(vm);
+void ErrorDialog::show(XeenEngine *vm, const Common::String &msg, ErrorWaitType waitType) {
+ ErrorDialog *dlg = new ErrorDialog(vm);
dlg->execute(msg, waitType);
delete dlg;
}
-void ErrorScroll::execute(const Common::String &msg, ErrorWaitType waitType) {
+void ErrorDialog::execute(const Common::String &msg, ErrorWaitType waitType) {
Screen &screen = *_vm->_screen;
EventsManager &events = *_vm->_events;
Window &w = screen._windows[6];
- Common::String s;
- if (waitType == WT_UNFORMATTED) {
- // This type isn't technically a waiting type, but it saved on adding
- // yet another parameter
- waitType = WT_FREEZE_WAIT;
- s = msg;
- } else {
- s = Common::String::format("\x03c\v010\t000%s", msg.c_str());
- }
-
w.open();
- w.writeString(s);
+ w.writeString(msg);
w.update();
switch (waitType) {
@@ -83,4 +73,11 @@ void ErrorScroll::execute(const Common::String &msg, ErrorWaitType waitType) {
}
}
+/*------------------------------------------------------------------------*/
+
+void ErrorScroll::show(XeenEngine *vm, const Common::String &msg, ErrorWaitType waitType) {
+ Common::String s = Common::String::format("\x03c\v010\t000%s", msg.c_str());
+ ErrorDialog::show(vm, s, waitType);
+}
+
} // End of namespace Xeen
diff --git a/engines/xeen/dialogs_error.h b/engines/xeen/dialogs_error.h
index 1a86afce87..644b7e3b0e 100644
--- a/engines/xeen/dialogs_error.h
+++ b/engines/xeen/dialogs_error.h
@@ -24,20 +24,27 @@
#define XEEN_DIALOGS_ERROR_H
#include "xeen/dialogs.h"
+#include "xeen/character.h"
namespace Xeen {
enum ErrorWaitType { WT_FREEZE_WAIT = 0, WT_NONFREEZED_WAIT = 1,
- WT_2 = 2, WT_3 = 3, WT_UNFORMATTED = 9 };
+ WT_2 = 2, WT_3 = 3 };
-class ErrorScroll: public ButtonContainer {
+class ErrorDialog : public ButtonContainer {
private:
XeenEngine *_vm;
- ErrorScroll(XeenEngine *vm) : ButtonContainer(), _vm(vm) {}
+ ErrorDialog(XeenEngine *vm) : ButtonContainer(), _vm(vm) {}
void execute(const Common::String &msg, ErrorWaitType waitType);
public:
+ static void show(XeenEngine *vm, const Common::String &msg,
+ ErrorWaitType waitType = WT_FREEZE_WAIT);
+};
+
+class ErrorScroll {
+public:
static void show(XeenEngine *vm, const Common::String &msg,
ErrorWaitType waitType = WT_FREEZE_WAIT);
};
diff --git a/engines/xeen/resources.cpp b/engines/xeen/resources.cpp
index 1f1c979f7a..c643152f5b 100644
--- a/engines/xeen/resources.cpp
+++ b/engines/xeen/resources.cpp
@@ -1125,4 +1125,9 @@ const char *const NO_SPECIAL_ABILITIES = "\v005\x3""c%s\fdhas no special abiliti
const char *const CANT_CAST_WHILE_ENGAGED = "\x03c\v007Can't cast %s while engaged!";
+const char *const EQUIPPED_ALL_YOU_CAN = "\x3""c\v007You have equipped all the %ss you can!";
+const char *const REMOVE_X_TO_EQUIP_Y = "\x3""c\v007You must remove %sto equip %s\x8!";
+const char *const RING = "ring";
+const char *const MEDAL = "medal";
+
} // End of namespace Xeen
diff --git a/engines/xeen/resources.h b/engines/xeen/resources.h
index 88e01cdb51..c6d2bdeb6d 100644
--- a/engines/xeen/resources.h
+++ b/engines/xeen/resources.h
@@ -398,6 +398,11 @@ extern const char *const NO_SPECIAL_ABILITIES;
extern const char *const CANT_CAST_WHILE_ENGAGED;
+extern const char *const EQUIPPED_ALL_YOU_CAN;
+extern const char *const REMOVE_X_TO_EQUIP_Y;
+extern const char *const RING;
+extern const char *const MEDAL;
+
} // End of namespace Xeen
#endif /* XEEN_RESOURCES_H */
diff --git a/engines/xeen/spells.cpp b/engines/xeen/spells.cpp
index 3492510db9..5f1df6aef0 100644
--- a/engines/xeen/spells.cpp
+++ b/engines/xeen/spells.cpp
@@ -100,8 +100,8 @@ void Spells::doSpell(int spellId) {
if (_vm->_mode == MODE_InCombat) {
if (spellId == 15 || spellId == 20 || spellId == 27 || spellId == 41
|| spellId == 47 || spellId == 54 || spellId == 57) {
- ErrorScroll::show(_vm, Common::String::format(CANT_CAST_WHILE_ENGAGED,
- _spellNames[spellId].c_str()), WT_UNFORMATTED);
+ ErrorDialog::show(_vm, Common::String::format(CANT_CAST_WHILE_ENGAGED,
+ _spellNames[spellId].c_str()));
return;
}
}