aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/xeen/item.cpp40
-rw-r--r--engines/xeen/item.h8
-rw-r--r--engines/xeen/party.cpp3
-rw-r--r--engines/xeen/scripts.cpp88
4 files changed, 69 insertions, 70 deletions
diff --git a/engines/xeen/item.cpp b/engines/xeen/item.cpp
index 871f60b82b..cb18bd4b02 100644
--- a/engines/xeen/item.cpp
+++ b/engines/xeen/item.cpp
@@ -66,22 +66,30 @@ AttributeCategory XeenItem::getAttributeCategory() const {
}
const char *XeenItem::getItemName(ItemCategory category, uint id) {
- if (id < 82)
- return Res.ITEM_NAMES[category][id];
-
- const char **questItems = (g_vm->getGameID() == GType_Swords) ? Res.QUEST_ITEM_NAMES_SWORDS : Res.QUEST_ITEM_NAMES;
- switch (category) {
- case CATEGORY_WEAPON:
- return questItems[id - 82];
-
- case CATEGORY_ARMOR:
- return questItems[id - 82 + 35];
-
- case CATEGORY_ACCESSORY:
- return questItems[id - 82 + 35 + 14];
-
- default:
- return questItems[id - 82 + 35 + 14 + 11];
+ if (id < 82) {
+ switch (category) {
+ case CATEGORY_WEAPON:
+ return Res.WEAPON_NAMES[id];
+ case CATEGORY_ARMOR:
+ return Res.ARMOR_NAMES[id - 35];
+ case CATEGORY_ACCESSORY:
+ return Res.ACCESSORY_NAMES[id - 49];
+ default:
+ return Res.MISC_NAMES[id];
+ }
+ } else {
+ const char **questItems = (g_vm->getGameID() == GType_Swords) ? Res.QUEST_ITEM_NAMES_SWORDS : Res.QUEST_ITEM_NAMES;
+
+ switch (category) {
+ case CATEGORY_WEAPON:
+ return questItems[id - 82];
+ case CATEGORY_ARMOR:
+ return questItems[id - 82 + 35];
+ case CATEGORY_ACCESSORY:
+ return questItems[id - 82 + 35 + 14];
+ default:
+ return questItems[id - 82 + 35 + 14 + 11];
+ }
}
}
diff --git a/engines/xeen/item.h b/engines/xeen/item.h
index 0fcfa92f44..105df0e661 100644
--- a/engines/xeen/item.h
+++ b/engines/xeen/item.h
@@ -64,9 +64,17 @@ public:
*/
static const char *getItemName(ItemCategory category, uint id);
public:
+ /**
+ * Constructor
+ */
XeenItem();
/**
+ * Constructor
+ */
+ XeenItem(uint id, int material, int bonusFlags) : _id(id), _material(material), _bonusFlags(bonusFlags) {}
+
+ /**
* Clear the data for the item
*/
void clear();
diff --git a/engines/xeen/party.cpp b/engines/xeen/party.cpp
index 42b45a8079..d6ef37791e 100644
--- a/engines/xeen/party.cpp
+++ b/engines/xeen/party.cpp
@@ -827,7 +827,8 @@ void Party::giveTreasureToCharacter(Character &c, ItemCategory category, int ite
w.update();
events.ipause(5);
- const char *itemName = XeenItem::getItemName(category, treasureItem._id);
+ const char *itemName = XeenItem::getItemName(category, (category == CATEGORY_MISC) ?
+ treasureItem._material : treasureItem._id);
w.writeString(Common::String::format(Res.X_FOUND_Y, c._name.c_str(), itemName));
w.update();
c._items[category].sort();
diff --git a/engines/xeen/scripts.cpp b/engines/xeen/scripts.cpp
index d135a4ae11..970004765c 100644
--- a/engines/xeen/scripts.cpp
+++ b/engines/xeen/scripts.cpp
@@ -1225,64 +1225,46 @@ bool Scripts::cmdSelectRandomChar(ParamsIterator &params) {
bool Scripts::cmdGiveEnchanted(ParamsIterator &params) {
Party &party = *_vm->_party;
-
+ XeenItem *item;
+ int invIndex;
int id = params.readByte();
- int material = params.readByte();
- int flags = params.readByte();
-
- if (id >= 35) {
- if (id < 49) {
- for (int idx = 0; idx < MAX_TREASURE_ITEMS; ++idx) {
- XeenItem &item = party._treasure._armor[idx];
- if (!item.empty()) {
- item._id = id - 35;
- item._material = material;
- item._bonusFlags = flags;
- party._treasure._hasItems = true;
- break;
- }
- }
- return true;
- } else if (id < 60) {
- for (int idx = 0; idx < MAX_TREASURE_ITEMS; ++idx) {
- XeenItem &item = party._treasure._accessories[idx];
- if (!item.empty()) {
- item._id = id - 49;
- item._material = material;
- item._bonusFlags = flags;
- party._treasure._hasItems = true;
- break;
- }
- }
+ // Get category of item to add
+ ItemCategory cat = CATEGORY_WEAPON;
+ if (id < 35) {
+ } else if (id < 49) {
+ cat = CATEGORY_ARMOR;
+ id -= 35;
+ } else if (id < 60) {
+ cat = CATEGORY_ACCESSORY;
+ id -= 49;
+ } else if (id < 82) {
+ cat = CATEGORY_MISC;
+ id -= 60;
+ } else {
+ party._questItems[id - 82]++;
+ }
- return true;
- } else if (id < 82) {
- for (int idx = 0; idx < MAX_TREASURE_ITEMS; ++idx) {
- XeenItem &item = party._treasure._misc[idx];
- if (!item.empty()) {
- item._id = id;
- item._material = material;
- item._bonusFlags = flags;
- party._treasure._hasItems = true;
- break;
- }
- }
+ // Check for an empty slot
+ for (invIndex = 0, item = party._treasure[cat]; invIndex < MAX_TREASURE_ITEMS && !item->empty(); ++invIndex, ++item)
+ ;
- return true;
- } else {
- party._questItems[id - 82]++;
- }
- }
+ if (invIndex == MAX_TREASURE_ITEMS) {
+ // Treasure category entirely full. Should never happen
+ warning("Treasure category was completely filled up");
+ } else {
+ party._treasure._hasItems = true;
- for (int idx = 0; idx < MAX_TREASURE_ITEMS; ++idx) {
- XeenItem &item = party._treasure._weapons[idx];
- if (!item.empty()) {
- item._id = id;
- item._material = material;
- item._bonusFlags = flags;
- party._treasure._hasItems = true;
- break;
+ if (cat == CATEGORY_MISC) {
+ // Handling of misc items. Note that for them, id actually specifies the material field
+ item->_material = id;
+ item->_id = params.readByte();
+ item->_bonusFlags = (item->_material == 10 || item->_material == 11) ? 1 : _vm->getRandomNumber(3, 10);
+ } else {
+ // Weapons, armor, and accessories
+ item->_id = id;
+ item->_material = params.readByte();
+ item->_bonusFlags = params.readByte();
}
}