From: Laszlo T. <ave...@us...> - 2012-04-15 11:45:35
|
gemrb: Infinity Engine emulator The branch master has been updated via e142fe5aad4cfcdb8a5d1751ace8548274b55695 (commit) Summary of changes: gemrb/core/GameScript/GSUtils.cpp | 60 +++++++++++++++++++++++++++++++++++- gemrb/core/Store.cpp | 16 ++++++++- gemrb/core/Store.h | 3 +- 3 files changed, 74 insertions(+), 5 deletions(-) from 5b551c771147cc6b23be2d28c04dd3db67173059 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- http://gemrb.git.sourceforge.net/git/gitweb.cgi?p=gemrb/gemrb;a=commitdiff;h=e142fe5aad4cfcdb8a5d1751ace8548274b55695 commit e142fe5aad4cfcdb8a5d1751ace8548274b55695 Author: Avenger <ave...@so...> Date: Sun Apr 15 13:44:55 2012 +0200 remove items from containers too diff --git a/gemrb/core/GameScript/GSUtils.cpp b/gemrb/core/GameScript/GSUtils.cpp index bb1e8ab..6e7e871 100644 --- a/gemrb/core/GameScript/GSUtils.cpp +++ b/gemrb/core/GameScript/GSUtils.cpp @@ -274,6 +274,26 @@ bool StoreHasItemCore(const ieResRef storename, const ieResRef itemname) return ret; } +bool StoreGetItemCore(CREItem &item, const ieResRef storename, const ieResRef itemname) +{ + Store* store = gamedata->GetStore(storename); + if (!store) { + Log(ERROR, "GameScript", "Store cannot be opened!"); + return false; + } + + //RemoveItem doesn't use trigger, and hopefully this will always run on bags (with no triggers) + unsigned int idx = store->FindItem(itemname, false); + if (idx == (unsigned int) -1) return false; + + STOItem *si = store->GetItem(idx, false); + memcpy( &item, si, sizeof( CREItem ) ); + store->RemoveItem(idx); + //store changed, save it + gamedata->SaveStore(store); + return true; +} + //don't pass this point by reference, it is subject to change void ClickCore(Scriptable *Sender, Point point, int type, int speed) { @@ -354,6 +374,30 @@ bool HasItemCore(Inventory *inventory, const ieResRef itemname, ieDword flags) return false; } +//finds and takes an item from a container in the given inventory +bool GetItemContainer(CREItem &itemslot2, Inventory *inventory, const ieResRef itemname) +{ + int i=inventory->GetSlotCount(); + while (i--) { + //maybe we could speed this up if we mark bag items with a flags bit + CREItem *itemslot = inventory->GetSlotItem(i); + if (!itemslot) + continue; + Item *item = gamedata->GetItem(itemslot->ItemResRef); + if (!item) + continue; + bool ret = core->CanUseItemType(SLOT_BAG,item,NULL); + gamedata->FreeItem(item, itemslot->ItemResRef); + if (!ret) + continue; + //the store is the same as the item's name + if (StoreGetItemCore(itemslot2, itemslot->ItemResRef, itemname)) { + return true; + } + } + return false; +} + void DisplayStringCore(Scriptable* const Sender, int Strref, int flags) { StringBlock sb; @@ -529,6 +573,17 @@ int MoveItemCore(Scriptable *Sender, Scriptable *target, const char *resref, int } CREItem *item; myinv->RemoveItem(resref, flags, &item, count); + + //there was no item in the inventory itself, try with containers in the inventory + if (!item) { + item = new CREItem(); + + if (!GetItemContainer(*item, myinv, resref)) { + delete item; + item = NULL; + } + } + if (!item) { // nothing was removed return MIC_NOITEM; @@ -548,9 +603,10 @@ int MoveItemCore(Scriptable *Sender, Scriptable *target, const char *resref, int myinv = NULL; break; } + if (lostitem&&!gotitem) displaymsg->DisplayConstantString(STR_LOSTITEM, DMC_BG2XPGREEN); + if (!myinv) { delete item; - if (lostitem) displaymsg->DisplayConstantString(STR_LOSTITEM, DMC_BG2XPGREEN); return MIC_GOTITEM; // actually it was lost, not gained } if ( myinv->AddSlotItem(item, SLOT_ONLYINVENTORY) !=ASI_SUCCESS) { @@ -559,7 +615,7 @@ int MoveItemCore(Scriptable *Sender, Scriptable *target, const char *resref, int if (gotitem) displaymsg->DisplayConstantString(STR_INVFULL_ITEMDROP, DMC_BG2XPGREEN); return MIC_FULL; } - if (gotitem) displaymsg->DisplayConstantString(STR_GOTITEM, DMC_BG2XPGREEN); + if (gotitem&&!lostitem) displaymsg->DisplayConstantString(STR_GOTITEM, DMC_BG2XPGREEN); return MIC_GOTITEM; } diff --git a/gemrb/core/Store.cpp b/gemrb/core/Store.cpp index b257df4..c62e7e5 100644 --- a/gemrb/core/Store.cpp +++ b/gemrb/core/Store.cpp @@ -152,9 +152,9 @@ STODrink *Store::GetDrink(unsigned int idx) const } //We need this weirdness for PST item lookup -STOItem *Store::GetItem(unsigned int idx) +STOItem *Store::GetItem(unsigned int idx, bool usetrigger) { - if (!HasTriggers) { + if (!HasTriggers || !usetrigger) { if (idx>=items.size()) { return NULL; } @@ -300,6 +300,18 @@ void Store::RemoveItem( unsigned int idx ) ItemsCount--; } +void Store::RemoveItem( STOItem *itm ) +{ + size_t i = items.size(); + while(i--) { + if (items[i]==itm) { + items.erase(items.begin()+i); + ItemsCount--; + break; + } + } +} + ieDword Store::GetOwnerID() const { return StoreOwnerID; diff --git a/gemrb/core/Store.h b/gemrb/core/Store.h index c71cd71..4c08eaf 100644 --- a/gemrb/core/Store.h +++ b/gemrb/core/Store.h @@ -158,7 +158,7 @@ public: //queries int AcceptableItemType(ieDword type, ieDword invflags, bool pc) const; STOCure *GetCure(unsigned int idx) const; STODrink *GetDrink(unsigned int idx) const; - STOItem *GetItem(unsigned int idx); + STOItem *GetItem(unsigned int idx, bool usetrigger); /** Evaluates item availability triggers */ int GetRealStockSize(); /** Recharges item */ @@ -166,6 +166,7 @@ public: //queries /** Adds a new item to the store (selling) */ void AddItem(CREItem* item); void RemoveItem(unsigned int idx); + void RemoveItem( STOItem *itm); /** Returns index of item */ unsigned int FindItem(const ieResRef item, bool usetrigger) const; const char *GetOwner() const; ----------------------------------------------------------------------- This is an automated email from the git hooks/post-receive script. -- gemrb: Infinity Engine emulator |