aboutsummaryrefslogtreecommitdiff
path: root/engines/xeen/scripts.cpp
diff options
context:
space:
mode:
authorPaul Gilbert2018-03-30 23:03:15 -0400
committerPaul Gilbert2018-03-30 23:03:15 -0400
commit494fd3bb52e054969eb94ed72dc2d12a6e412fd1 (patch)
tree58781d5b9b2ae8232ba0329f2fb3fec626f32406 /engines/xeen/scripts.cpp
parentc33fce7ac7445dc9d5a9cf767673ab3abb52bdf6 (diff)
downloadscummvm-rg350-494fd3bb52e054969eb94ed72dc2d12a6e412fd1.tar.gz
scummvm-rg350-494fd3bb52e054969eb94ed72dc2d12a6e412fd1.tar.bz2
scummvm-rg350-494fd3bb52e054969eb94ed72dc2d12a6e412fd1.zip
XEEN: Fixes for giving items via scripts
Diffstat (limited to 'engines/xeen/scripts.cpp')
-rw-r--r--engines/xeen/scripts.cpp88
1 files changed, 35 insertions, 53 deletions
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();
}
}