From: Laszlo T. <ave...@us...> - 2004-04-13 19:43:58
|
Update of /cvsroot/gemrb/gemrb/gemrb/plugins/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13117 Modified Files: Inventory.cpp Inventory.h Log Message: Fixed a bug in inventory Index: Inventory.cpp =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Inventory.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Inventory.cpp 10 Apr 2004 17:46:24 -0000 1.7 --- Inventory.cpp 13 Apr 2004 19:29:48 -0000 1.8 *************** *** 24,49 **** #include "Inventory.h" Inventory::Inventory() { } Inventory::~Inventory() { ! for (size_t i = 0; i < slots.size(); i++) { ! if(slots[i]) { ! delete( slots[i] ); } } } void Inventory::SetSlotCount(unsigned int size) { ! if(slots.size()) { printf("Inventory size changed???\n"); //we don't allow reassignment, ! //if you want this, delete the previous slots here abort(); } ! slots.assign((size_t) size, NULL); } --- 24,62 ---- #include "Inventory.h" + static int Inited=-1; + Inventory::Inventory() { + InventoryType = INVENTORY_HEAP; } Inventory::~Inventory() { ! for (size_t i = 0; i < Slots.size(); i++) { ! if(Slots[i]) { ! delete( Slots[i] ); } } } + int Inventory::CalculateWeight() + { + //returns the weight of stored items + } + + void Inventory::SetInventoryType(int arg) + { + InventoryType = arg; + } + void Inventory::SetSlotCount(unsigned int size) { ! if(Slots.size()) { printf("Inventory size changed???\n"); //we don't allow reassignment, ! //if you want this, delete the previous Slots here abort(); } ! Slots.assign((size_t) size, NULL); } *************** *** 51,55 **** bool Inventory::HasItemInSlot(const char *resref, int slot) { ! CREItem *item = slots[slot]; if(!item) { return false; --- 64,68 ---- bool Inventory::HasItemInSlot(const char *resref, int slot) { ! CREItem *item = Slots[slot]; if(!item) { return false; *************** *** 61,80 **** } int Inventory::CountItems(const char *resref, bool stacks) { int count = 0; ! int slot = slots.size(); while(slot--) { ! CREItem *item = slots[slot]; if(!item) { continue; } ! if (strnicmp( item->ItemResRef, resref,8 ) == 0) { ! if (stacks && item->Flags&IE_ITEM_STACKED) { ! count+=item->Usages[0]; ! } ! else { ! count++; ! } } } --- 74,93 ---- } + /** counts the items in the inventory, if stacks == 1 then stacks are + accounted for their heap size */ int Inventory::CountItems(const char *resref, bool stacks) { int count = 0; ! int slot = Slots.size(); while(slot--) { ! CREItem *item = Slots[slot]; if(!item) { continue; } ! if (stacks && (item->Flags&IE_ITEM_STACKED) ) { ! count+=item->Usages[0]; ! } ! else { ! count++; } } *************** *** 87,93 **** bool Inventory::HasItem(const char *resref, ieDword flags) { ! int slot = slots.size(); while(slot--) { ! CREItem *item = slots[slot]; if(!item) { continue; --- 100,106 ---- bool Inventory::HasItem(const char *resref, ieDword flags) { ! int slot = Slots.size(); while(slot--) { ! CREItem *item = Slots[slot]; if(!item) { continue; *************** *** 110,116 **** void Inventory::DestroyItem(const char *resref, ieDword flags) { ! int slot = slots.size(); while(slot--) { ! CREItem *item = slots[slot]; if(!item) { continue; --- 123,129 ---- void Inventory::DestroyItem(const char *resref, ieDword flags) { ! int slot = Slots.size(); while(slot--) { ! CREItem *item = Slots[slot]; if(!item) { continue; *************** *** 128,132 **** //until that, we simply erase it delete item; ! slots[slot] = NULL; } } --- 141,145 ---- //until that, we simply erase it delete item; ! Slots[slot] = NULL; } } *************** *** 134,145 **** void Inventory::SetSlotItem(CREItem* item, unsigned int slot) { ! if (slot>=slots.size() ) { printf("Invalid slot!\n"); abort(); } ! if(slots[slot]) { ! delete slots[slot]; } ! slots[slot] = item; } --- 147,158 ---- void Inventory::SetSlotItem(CREItem* item, unsigned int slot) { ! if (slot>=Slots.size() ) { printf("Invalid slot!\n"); abort(); } ! if(Slots[slot]) { ! delete Slots[slot]; } ! Slots[slot] = item; } *************** *** 147,157 **** { // FIXME: join items if possible ! for (size_t i = 0; i < slots.size(); i++) { ! if (!slots[i]) { ! slots[i] = item; *res_item = NULL; return ( int ) i; } ! if (ItemsAreCompatible( slots[i], item )) { } } --- 160,182 ---- { // FIXME: join items if possible ! for (size_t i = 0; i < Slots.size(); i++) { ! if (!Slots[i]) { ! Slots[i] = item; *res_item = NULL; return ( int ) i; } ! ! if (ItemsAreCompatible( Slots[i], item )) { ! //calculate with the max movable stock ! int chunk=item->Usages[0]; ! if(!chunk) { ! continue; ! } ! Slots[i]->Usages[0]+=chunk; ! item->Usages[0]-=chunk; ! if(item->Usages[0]==0) { ! *res_item = NULL; ! return ( int ) i; ! } } } *************** *** 161,164 **** --- 186,212 ---- } + int Inventory::AddSlotItem(STOItem* item, unsigned int slot, CREItem **res_item, int count) + { + CREItem *temp; + CREItem *remains; + + for(int i=0;i<count;i++) { + //the first part of a STOItem is essentially a CREItem + temp = new CREItem; + memcpy(&temp, item, sizeof(CREItem) ); + if(!item->InfiniteSupply) { + if(!item->AmountInStock) { + break; + } + item->AmountInStock--; + } + AddSlotItem(temp, 0, &remains); + //FIXME: drop remains at feet of actor + if(remains) { + delete remains; + } + } + } + bool Inventory::ItemsAreCompatible(CREItem* target, CREItem* source) { *************** *** 167,174 **** } if (!strnicmp( target->ItemResRef, source->ItemResRef,8 )) { ! // FIXME: some magic code belongs here .... ! // this should check if the items are stacking or not ! return true; } return false; --- 215,226 ---- } + if(!(source->Flags&IE_ITEM_STACKED) ) { + return false; + } + if (!strnicmp( target->ItemResRef, source->ItemResRef,8 )) { ! if(target->Flags&IE_ITEM_STACKED) { ! return true; ! } } return false; *************** *** 178,185 **** CREItem* Inventory::GetSlotItem(int index) { ! if (index >= slots.size()) { return NULL; } ! return slots[index]; } --- 230,237 ---- CREItem* Inventory::GetSlotItem(int index) { ! if (index >= Slots.size()) { return NULL; } ! return Slots[index]; } *************** *** 188,195 **** int Inventory::FindCandidateSlot(CREItem* item, int first_slot) { ! if (first_slot >= slots.size()) return -1; ! for (size_t i = first_slot; i < slots.size(); i++) { } --- 240,247 ---- int Inventory::FindCandidateSlot(CREItem* item, int first_slot) { ! if (first_slot >= Slots.size()) return -1; ! for (size_t i = first_slot; i < Slots.size(); i++) { } *************** *** 204,229 **** { // FIXME: join items if possible ! for (size_t i = 0; i < slots.size(); i++) { ! if (!slots[i]) { ! slots[i] = item; return ( int ) i; } } ! slots.push_back( item ); ! return ( int ) slots.size() - 1; } int Inventory::DelSlotItem(unsigned int index, bool autoFree) { ! if (index >= slots.size()) { return -1; } ! if (!slots[index]) { return -1; } if (autoFree) { ! delete( slots[index] ); } ! slots[index] = NULL; return 0; } --- 256,281 ---- { // FIXME: join items if possible ! for (size_t i = 0; i < Slots.size(); i++) { ! if (!Slots[i]) { ! Slots[i] = item; return ( int ) i; } } ! Slots.push_back( item ); ! return ( int ) Slots.size() - 1; } int Inventory::DelSlotItem(unsigned int index, bool autoFree) { ! if (index >= Slots.size()) { return -1; } ! if (!Slots[index]) { return -1; } if (autoFree) { ! delete( Slots[index] ); } ! Slots[index] = NULL; return 0; } *************** *** 234,239 **** { printf( "INVENTORY:\n" ); ! for (size_t i = 0; i < slots.size(); i++) { ! CREItem* itm = slots[i]; if (!itm) { --- 286,291 ---- { printf( "INVENTORY:\n" ); ! for (size_t i = 0; i < Slots.size(); i++) { ! CREItem* itm = Slots[i]; if (!itm) { Index: Inventory.h =================================================================== RCS file: /cvsroot/gemrb/gemrb/gemrb/plugins/Core/Inventory.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Inventory.h 10 Apr 2004 17:46:24 -0000 1.6 --- Inventory.h 13 Apr 2004 19:29:53 -0000 1.7 *************** *** 29,32 **** --- 29,34 ---- #include "../../includes/ie_types.h" + #include "Store.h" + #ifdef WIN32 *************** *** 41,45 **** #endif ! const int INVENTORY_SIZE = 38; typedef enum ieCREItemFlagBits { --- 43,50 ---- #endif ! typedef enum ieInventoryType { ! INVENTORY_HEAP = 0, ! INVENTORY_CREATURE = 1, ! } ieInventoryType; typedef enum ieCREItemFlagBits { *************** *** 67,71 **** class GEM_EXPORT Inventory { private: ! std::vector<CREItem*> slots; public: --- 72,77 ---- class GEM_EXPORT Inventory { private: ! std::vector<CREItem*> Slots; ! int InventoryType; public: *************** *** 81,86 **** bool HasItem(const char *resref, ieDword flags); /** returns number of all slots in the inventory */ ! int GetSlotCount() { return slots.size(); }; /** sets inventory size, for the first time */ --- 87,95 ---- bool HasItem(const char *resref, ieDword flags); + int CalculateWeight(void); + void SetInventoryType(int arg); + /** returns number of all slots in the inventory */ ! int GetSlotCount() { return Slots.size(); }; /** sets inventory size, for the first time */ *************** *** 98,101 **** --- 107,112 ---- int AddSlotItem(CREItem* item, unsigned int slot, CREItem** res_item); + int AddSlotItem(STOItem* item, unsigned int slot, CREItem** res_item, int count); + /** flags: see ieCREItemFlagBits */ void DestroyItem(const char *resref, ieDword flags); |