Skip to content

Commit

Permalink
Skip stacked items when sanitizing charges
Browse files Browse the repository at this point in the history
Fixes some stacked items resetting to stack size 1 on load.
  • Loading branch information
fizzet committed Jan 20, 2014
1 parent fbc49c3 commit 979e67e
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions gemrb/core/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4844,25 +4844,32 @@ void Interface::SanitizeItem(CREItem *item) const

Item *itm = gamedata->GetItem(item->ItemResRef, true);
if (itm) {
//set charge counters for non-rechargeable items if their charge is zero
//set charge counters for items not using charges to one
for (int i = 0; i < CHARGE_COUNTERS; i++) {
ITMExtHeader *h = itm->GetExtHeader(i);
if (h) {
if (item->Usages[i] == 0) {
if (!(h->RechargeFlags&IE_ITEM_RECHARGE)) {
//HACK: the original (bg2) allows for 0 charged gems
if (h->Charges) {
item->Usages[i] = h->Charges;
} else {
item->Usages[i] = 1;

item->MaxStackAmount = itm->MaxStackAmount;
//if item is stacked mark it as so
if (itm->MaxStackAmount) {
item->Flags |= IE_INV_ITEM_STACKED;
} else {
//set charge counters for non-rechargeable items if their charge is zero
//set charge counters for items not using charges to one
for (int i = 0; i < CHARGE_COUNTERS; i++) {
ITMExtHeader *h = itm->GetExtHeader(i);
if (h) {
if (item->Usages[i] == 0) {
if (!(h->RechargeFlags&IE_ITEM_RECHARGE)) {
//HACK: the original (bg2) allows for 0 charged gems
if (h->Charges) {
item->Usages[i] = h->Charges;
} else {
item->Usages[i] = 1;
}
}
} else if (h->Charges == 0) {
item->Usages[i] = 1;
}
} else if (h->Charges == 0) {
item->Usages[i] = 1;
} else {
item->Usages[i] = 0;
}
} else {
item->Usages[i] = 0;
}
}

Expand Down Expand Up @@ -4893,13 +4900,6 @@ void Interface::SanitizeItem(CREItem *item) const
item->Flags |= IE_INV_ITEM_IDENTIFIED;
}

//if item is stacked mark it as so
if (itm->MaxStackAmount) {
item->Flags |= IE_INV_ITEM_STACKED;
}

item->MaxStackAmount = itm->MaxStackAmount;

gamedata->FreeItem(itm, item->ItemResRef, false);
}
}
Expand Down

0 comments on commit 979e67e

Please sign in to comment.