Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

share item sanitation code between item loading and creation

Also use it for shops.
  • Loading branch information...
commit 9ca67d189ca6bb99067b69f06e4dd87854900147 1 parent 5986ffd
@fizzet fizzet authored
View
1  gemrb/core/GameScript/GSUtils.cpp
@@ -1276,6 +1276,7 @@ bool CreateItemCore(CREItem *item, const char *resref, int a, int b, int c)
}
item->Flags=0;
item->Expired=0;
+ core->SanitizeItem(item);
return true;
}
View
53 gemrb/core/Interface.cpp
@@ -4785,17 +4785,60 @@ CREItem *Interface::ReadItem(DataStream *str, CREItem *itm)
str->ReadWord( &itm->Usages[1] );
str->ReadWord( &itm->Usages[2] );
str->ReadDword( &itm->Flags );
+ if (ResolveRandomItem(itm)) {
+ SanitizeItem(itm);
+ return itm;
+ }
+ return NULL;
+}
+
+//Make sure the item attributes are valid
+//we don't update all flags here because some need to be set later (like
+//unmovable items in containers (e.g. the bg2 portal key) so that they
+//can actually be picked up)
+void Interface::SanitizeItem(CREItem *item) const
+{
//the stacked flag will be set by the engine if the item is indeed stacked
//this is to fix buggy saves so TakeItemNum works
//the equipped bit is also reset
- itm->Flags&=~(IE_INV_ITEM_STACKED|IE_INV_ITEM_EQUIPPED);
+ item->Flags &= ~(IE_INV_ITEM_STACKED|IE_INV_ITEM_EQUIPPED);
if (GF_NO_UNDROPPABLE) {
- itm->Flags&=~IE_INV_ITEM_UNDROPPABLE;
+ item->Flags &= ~IE_INV_ITEM_UNDROPPABLE;
}
- if (ResolveRandomItem(itm) ) {
- return itm;
+
+ Item *itm = gamedata->GetItem(item->ItemResRef, true);
+ if (itm) {
+ //This hack sets the charge counters for non-rechargeable items,
+ //if their charge is zero
+ for (int i = 0; i < CHARGE_COUNTERS; i++) {
+ if (item->Usages[i]) {
+ continue;
+ }
+ ITMExtHeader *h = itm->GetExtHeader(i);
+ if (h && !(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;
+ }
+ }
+ }
+
+ //auto identify basic items
+ if (!itm->LoreToID) {
+ 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);
}
- return NULL;
}
#define MAX_LOOP 10
View
1  gemrb/core/Interface.h
@@ -616,6 +616,7 @@ class GEM_EXPORT Interface
void SetDraggedPortrait(int dp, int cursor=-1);
CREItem *ReadItem(DataStream *str);
CREItem *ReadItem(DataStream *str, CREItem *itm);
+ void SanitizeItem(CREItem *item) const;
bool ResolveRandomItem(CREItem *itm);
ieStrRef GetRumour(const ieResRef resname);
Container *GetCurrentContainer();
View
44 gemrb/core/Inventory.cpp
@@ -158,52 +158,10 @@ CREItem *Inventory::GetItem(unsigned int slot)
return item;
}
-//Make sure the item attributes are valid
-//we don't update all flags here because some need to be set later (like
-//unmovable items in containers (e.g. the bg2 protal key) so that they
-//can actually be picked up)
-void Inventory::SanitizeItem(CREItem *item)
-{
- Item *itm = gamedata->GetItem(item->ItemResRef, true);
- if (itm) {
- //This hack sets the charge counters for non-rechargeable items,
- //if their charge is zero
- for (int i=0;i<3;i++) {
- if (item->Usages[i]) {
- continue;
- }
- ITMExtHeader *h = itm->GetExtHeader(i);
- if (h && !(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;
- }
- }
- }
-
- //auto identify basic items
- if (!itm->LoreToID) {
- 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 );
- }
-}
-
void Inventory::AddItem(CREItem *item)
{
if (!item) return; //invalid items get no slot
Slots.push_back(item);
- SanitizeItem(item);
}
void Inventory::CalculateWeight() const
@@ -619,8 +577,6 @@ void Inventory::SetSlotItem(CREItem* item, unsigned int slot)
delete Slots[slot];
}
- SanitizeItem(item);
-
Slots[slot] = item;
//update the action bar next time
View
1  gemrb/core/Inventory.h
@@ -363,7 +363,6 @@ class GEM_EXPORT Inventory {
inline Item *GetItemPointer(ieDword slot, CREItem *&Slot) const;
void UpdateWeaponAnimation();
void UpdateShieldAnimation(Item *it);
- void SanitizeItem(CREItem *item);
};
}
View
23 gemrb/plugins/STOImporter/STOImporter.cpp
@@ -174,19 +174,20 @@ void STOImporter::GetItem(STOItem *it, Store *s)
}
// make sure the inventory knows that it needs to update flags+weight
it->Weight = -1;
- Item *item = gamedata->GetItem( it->ItemResRef );
- if (item) {
- it->MaxStackAmount = item->MaxStackAmount;
- //another hack-fix
- if (item->LoreToID <= s->Lore && !s->IsBag()) {
- it->Flags |= IE_INV_ITEM_IDENTIFIED;
- }
- gamedata->FreeItem( item, it->ItemResRef, false );
- //make sure it has at least one charge for proper pricing purposes
- if (!it->Usages[0]) {
- it->Usages[0] = 1;
+ if (!(it->Flags & IE_INV_ITEM_IDENTIFIED) && !s->IsBag()) {
+ Item *item = gamedata->GetItem( it->ItemResRef );
+ if (item) {
+ //another hack-fix
+ if (item->LoreToID <= s->Lore) {
+ it->Flags |= IE_INV_ITEM_IDENTIFIED;
+ }
+ gamedata->FreeItem( item, it->ItemResRef, false );
}
}
+ //make sure it has at least one charge for proper pricing purposes
+ if (!it->Usages[0]) {
+ it->Usages[0] = 1;
+ }
str->ReadDword( (ieDword *) &it->InfiniteSupply );
ieDwordSigned tmp;
Please sign in to comment.
Something went wrong with that request. Please try again.