XEEN: Implemented weapon variation of equipItem

This commit is contained in:
Paul Gilbert 2015-02-04 22:24:45 -05:00
parent 7ea32f3333
commit a983d9abce
7 changed files with 161 additions and 31 deletions

View File

@ -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,14 +149,89 @@ void InventoryItems::sort() {
}
}
void InventoryItems::equipItem(int itemIndex) {
error("TODO");
}
void InventoryItems::removeItem(int itemIndex) {
error("TODO");
}
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,
@ -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;

View File

@ -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;

View File

@ -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

View File

@ -24,19 +24,26 @@
#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);

View File

@ -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

View File

@ -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 */

View File

@ -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;
}
}