From: Keith F. <ven...@us...> - 2007-02-26 05:57:42
|
Update of /cvsroot/planeshift/planeshift/src/server/bulkobjects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29776/src/server/bulkobjects Modified Files: dictionary.cpp pscharinventory.cpp pscharinventory.h psitem.cpp psitem.h Log Message: - Took out a lot more unnecessary code, mostly related to items containing items. All item hierarchy is now implied by parent item instance id (GetContainerID() ) but stored in the same flat inventory[] array. - Also started work on re-enabling weight and space tracking, so please test this if you are one of the people testing my stuff, for which I thank you. :-) Index: dictionary.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/dictionary.cpp,v retrieving revision 1.140 retrieving revision 1.141 diff -C2 -d -r1.140 -r1.141 *** dictionary.cpp 17 Feb 2007 22:11:54 -0000 1.140 --- dictionary.cpp 26 Feb 2007 05:56:58 -0000 1.141 *************** *** 474,478 **** csArray<int> availableResponseList; ! // Check if not all responses is blocked(Not availabe in quests, Prequests not fullfitted,...) if (trig && !trig->HaveAvailableResponses(client,npc,this,&availableResponseList)) { --- 474,478 ---- csArray<int> availableResponseList; ! // Check if not all responses is blocked(Not available in quests, Prequests not fullfitted,...) if (trig && !trig->HaveAvailableResponses(client,npc,this,&availableResponseList)) { *************** *** 1011,1017 **** // This is a available response that is connected to a available quest haveAvail = true; ! if (availableResponseList) availableResponseList->Push(resp->id); } ! } else { Debug2(LOG_QUESTS,client->GetClientNum(),"Pushing non quest response: %d\n",resp->id); --- 1011,1019 ---- // This is a available response that is connected to a available quest haveAvail = true; ! if (availableResponseList) ! availableResponseList->Push(resp->id); } ! } ! else { Debug2(LOG_QUESTS,client->GetClientNum(),"Pushing non quest response: %d\n",resp->id); Index: pscharinventory.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/pscharinventory.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pscharinventory.cpp 25 Feb 2007 19:19:32 -0000 1.5 --- pscharinventory.cpp 26 Feb 2007 05:56:58 -0000 1.6 *************** *** 288,292 **** loaded = true; // Begin dimension checking ! ReassessInventoryDimensions(); return true; --- 288,292 ---- loaded = true; // Begin dimension checking ! /////// ReassessInventoryDimensions(); return true; *************** *** 467,472 **** return -1; } ! /********************************* ! if ( !HasWeight(item->GetSumWeight()) ) { lastError.Format("The %s is too heavy for you to carry", item->GetName() ); --- 467,471 ---- return -1; } ! if ( !HasEnoughUnusedWeight(item->GetWeight()) ) { lastError.Format("The %s is too heavy for you to carry", item->GetName() ); *************** *** 474,483 **** } ! if ( !HasSpace(item->GetSumSize()) ) { lastError.Format("The %s is too big for you to carry", item->GetName() ); return -1; } ! *********************************/ return 0; // 0 here means successful because the calling function returns -1 for no slot avail } --- 473,482 ---- } ! if ( !HasEnoughUnusedSpace(item->GetTotalStackSize()) ) { lastError.Format("The %s is too big for you to carry", item->GetName() ); return -1; } ! return 0; // 0 here means successful because the calling function returns -1 for no slot avail } *************** *** 608,612 **** { int size = 0; ////////////GetTotalSizeOfItemsInContainer(inventory[i].item); ! if (size + item->GetSize() < inventory[i].item->GetContainerMaxSize() ) // adequate space in container { INVENTORY_SLOT_NUMBER containerSlot = (INVENTORY_SLOT_NUMBER)FindFirstOpenSlot(inventory[i].item); --- 607,611 ---- { int size = 0; ////////////GetTotalSizeOfItemsInContainer(inventory[i].item); ! if (size + item->GetItemSize() < inventory[i].item->GetContainerMaxSize() ) // adequate space in container { INVENTORY_SLOT_NUMBER containerSlot = (INVENTORY_SLOT_NUMBER)FindFirstOpenSlot(inventory[i].item); *************** *** 686,737 **** } - /***************************************** - psItem *psCharacterInventory::RemoveEquippedItem(int slot) - { - if (slot<0 || slot>=PSCHARACTER_SLOT_BULK_END) - return NULL; - - psItem* currentitem=equipment[slot].itemIndexEquipped; - if (currentitem==NULL) - return NULL; - if (currentitem->IsInUse()) - return NULL; - - equipment[slot].itemIndexEquipped=SIZET_NOT_FOUND; - - owner->CalculateEquipmentModifiers(); - - inventoryCacheServer.EquipmentSlotModified(slot); // update cache - - return currentitem; - } - ***********************************************/ - - - /** - bool psCharacterInventory::PutInEquipped(int slot, int itemIndex, bool test) - { - if (slot<0 || slot>=PSCHARACTER_SLOT_COUNT) - return false; - - if (equipment[slot].item == NULL || item == NULL) - return false; - - if ( equipment[slot].item->GetIsContainer() ) - { - if ( !equipment[slot].item->AddItemToContainer(item, test) ) - return false; - else if (test) - return true; - - AddDimensionsToInventory(item); - equipment[slot].item->Save(true); - return true; - } - - return false; - } - ****/ psItem *psCharacterInventory::GetItem(psItem *container,INVENTORY_SLOT_NUMBER slot) --- 685,689 ---- *************** *** 898,912 **** } - /*****************not used***************************** - bool psCharacterInventory::IsEquippedItemSingleAttack(int slot) - { - // Slot out of range - if (slot<0 || slot>=PSCHARACTER_SLOT_COUNT) - return false; - - return (equipment[slot].EquipmentFlags & PSCHARACTER_EQUIPMENTFLAG_SINGLEATTACK) ? true : false; - } - *******************************************************************/ - psItem *psCharacterInventory::GetEffectiveWeaponInSlot(INVENTORY_SLOT_NUMBER slot) --- 850,853 ---- *************** *** 951,1027 **** } - /***************************not needed KWF - int psCharacterInventory::FindItemInTopLevelEquipment(psItem *item) - { - for (int i=0;i<PSCHARACTER_SLOT_COUNT;i++) - { - if (equipment[i].item==item) - return i; - } - return -1; - } ! int psCharacterInventory::FindItemInTopLevelBulk(psItem *item) { ! for (int i=0;i<PSCHARACTER_BULK_COUNT;i++) ! { ! if (bulk[i]==item) ! return i; ! } ! return -1; ! } ! int psCharacterInventory::FindItemInTopLevelBulkWithStats(psItemStats *stats) ! { ! for (int i=0;i<PSCHARACTER_BULK_COUNT;i++) ! { ! if (bulk[i] && bulk[i]->GetCurrentStats() == stats) ! return i; ! } ! return -1; ! } ! int psCharacterInventory::FindItemInTopLevelEquipmentWithStats(psItemStats *stats) { ! for (int i=0;i<PSCHARACTER_SLOT_COUNT;i++) ! { ! if (equipment[i].item && equipment[i].item->GetCurrentStats() == stats) ! return i; ! } ! return -1; ! } ! *******************************************************/ ! bool psCharacterInventory::HasSpace( float requiredSpace ) { ! //TODO if ( !doRestrictions ) ! return true; ! #if !ENABLE_MAX_CAPACITY ! return true; ! #endif ! // return (totalSize + requiredSpace <= maxSize ); } ! bool psCharacterInventory::HasWeight( float requiredWeight ) { ! // if ( !doRestrictions ) return true; ! // return (totalWeight + requiredWeight <= maxWeight ); } ! size_t psCharacterInventory::CanFit(psItem* item) { ! return 20; ! /******TODO if ( !doRestrictions ) return 65535; // Fit any amount ! if ( !HasWeight(0) || !HasSpace(0) ) return 0; // Can't fit any --- 892,962 ---- } ! bool psCharacterInventory::HasEnoughUnusedSpace( float requiredSpace ) { ! if (!doRestrictions ) ! return true; ! #if !ENABLE_MAX_CAPACITY ! return true; ! #endif + return (GetCurrentTotalSpace() + requiredSpace <= GetCurrentMaxSpace() ); + } ! int psCharacterInventory::GetCurrentTotalSpace() { ! int total=0; ! for (size_t i=0; i<inventory.GetSize(); i++) ! total += inventory[i].item->GetItemSize(); // * stackCount here? KWF + printf("Current total size available is %d.\n", total); + return total; + } ! int psCharacterInventory::GetCurrentMaxSpace() { ! // Your max available space is your personal space + the sum of the space of your containers ! int total=0; ! total = maxSize; // Calculated by mathscript ! for (size_t i=0; i<inventory.GetSize(); i++) ! { ! if (inventory[i].item->GetIsContainer()) ! total += inventory[i].item->GetContainerMaxSize(); // * stackCount here? KWF ! } ! printf("Current total size available is %d.\n", total); ! return total; } ! bool psCharacterInventory::HasEnoughUnusedWeight( float requiredWeight ) { ! if ( !doRestrictions ) return true; ! return (GetCurrentTotalWeight() + requiredWeight <= MaxWeight() ); } ! int psCharacterInventory::GetCurrentTotalWeight() { ! int total=0; ! for (size_t i=0; i<inventory.GetSize(); i++) ! total += inventory[i].item->GetWeight(); ! ! printf("Current total weight is %d.\n", total); ! return total; ! } ! ! ! size_t psCharacterInventory::HowManyCanFit(psItem* item) ! { ! printf("Checking how many items can fit (%s)\n", item->GetName() ); ! if ( !doRestrictions ) return 65535; // Fit any amount ! if ( !HasEnoughUnusedWeight(0) || !HasEnoughUnusedSpace(0) ) return 0; // Can't fit any *************** *** 1031,1113 **** float individualWeight = item->GetBaseStats()->GetWeight(); if ( individualWeight > 0.01 ) ! w = (size_t)((maxWeight-totalWeight)/individualWeight); #if ENABLE_MAX_CAPACITY unsigned short individualSize = item->GetBaseStats()->GetSize(); if ( individualSize > 0 ) ! s = (size_t)((maxSize-totalSize)/individualSize); #endif return (w<s)?w:s; // Capacity depends on the lesser - *****/ } - void psCharacterInventory::ReassessInventoryDimensions() - { - /*************************** - if (!loaded) // Make sure we're ready to calculate - return; - - int i; - - totalCount = 0; - totalWeight = 0.0f; - totalSize = 0.0f; - - for (i=0; i<PSCHARACTER_SLOT_COUNT; i++) - { - if (equipment[i].item != NULL) - AddDimensionsToInventory(equipment[i].item); - } - - for (i=0; i<PSCHARACTER_BULK_COUNT; i++) - { - if (bulk[i] != NULL) - AddDimensionsToInventory(bulk[i]); - } - *****************/ - } - - void psCharacterInventory::AddDimensionsToInventory(psItem *item) - { - /*************************** - if (loaded) // Make sure we're ready to calculate - { - totalCount += item->GetStackCount(); // TODO: count children - totalWeight += item->RecalculateFullWeight(); // Total weight of stack including children - if (item->GetParentItem() == NULL) // Sizes may be nested; don't add children to the total - totalSize += item->GetSumSize(); // Total size of all in this stack - } - *********************/ - } - - void psCharacterInventory::SubtractDimensionsFromInventory(psItem *item) - { - /********************* - if (loaded) // Make sure we're ready to calculate - { - totalCount -= item->GetStackCount(); // TODO: count children - totalWeight -= item->RecalculateFullWeight(); // Total weight of stack including children - if (item->GetParentItem() == NULL) // Sizes may be nested; don't add children to the total - totalSize -= item->GetSumSize(); // Total size of all in this stack - } - *********************/ - } - - int psCharacterInventory::HasEmptyBulkSlots() - { - /********************* - int count = 0; - - for (int i=0; i<PSCHARACTER_BULK_COUNT; i++) - { - if (bulk[i] == NULL) - ++count; - } - - return count; - *********************/ - return 1; - } void psCharacterInventory::SetDoRestrictions(bool v) --- 966,980 ---- float individualWeight = item->GetBaseStats()->GetWeight(); if ( individualWeight > 0.01 ) ! w = (size_t)((maxWeight-GetCurrentTotalWeight() )/individualWeight); #if ENABLE_MAX_CAPACITY unsigned short individualSize = item->GetBaseStats()->GetSize(); if ( individualSize > 0 ) ! s = (size_t)((maxSize-GetCurrentMaxSpace() )/individualSize); #endif return (w<s)?w:s; // Capacity depends on the lesser } void psCharacterInventory::SetDoRestrictions(bool v) Index: pscharinventory.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/pscharinventory.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** pscharinventory.h 21 Feb 2007 07:35:01 -0000 1.1 --- pscharinventory.h 26 Feb 2007 05:56:58 -0000 1.2 *************** *** 150,166 **** * @return true if the player has enough capacity for the requiredSpace. */ ! bool HasSpace( float desiredSpace ); ! /** Check to see if the player has the ability to carry and additional weight. * @param requiedWeight The amount of weight that we want to check. * @return true if the player has can carry the additional weight. */ ! bool HasWeight( float requiredWeight ); /// @return the max number of the given item that can fit ! size_t CanFit(psItem* item); /// @return the number of empty bulk slots ! int HasEmptyBulkSlots(); /// @return The max allowable weight for this inventory. --- 150,169 ---- * @return true if the player has enough capacity for the requiredSpace. */ ! bool HasEnoughUnusedSpace( float desiredSpace ); ! int GetCurrentTotalSpace(); ! int GetCurrentMaxSpace(); ! /** Check to see if the player has the ability to carry and additional weight. * @param requiedWeight The amount of weight that we want to check. * @return true if the player has can carry the additional weight. */ ! bool HasEnoughUnusedWeight( float requiredWeight ); ! int GetCurrentTotalWeight(); /// @return the max number of the given item that can fit ! size_t HowManyCanFit(psItem* item); /// @return the number of empty bulk slots ! //// int HasEmptyBulkSlots(); /// @return The max allowable weight for this inventory. *************** *** 168,172 **** /// @return The max capacity ( ie space ) this inventory can handle. ! float MaxCapacity() { return maxSize; } /// Do we have sufficient space/weight capacity for the specified item --- 171,175 ---- /// @return The max capacity ( ie space ) this inventory can handle. ! /////float MaxCapacity() { return maxSize; } /// Do we have sufficient space/weight capacity for the specified item *************** *** 307,311 **** /// Recalculate total weight, bulk, and count of inventory items. (use when dealing with containers) ! void ReassessInventoryDimensions(); /// Changes this inventories handling of weight/capacity restrictions --- 310,314 ---- /// Recalculate total weight, bulk, and count of inventory items. (use when dealing with containers) ! //////// void ReassessInventoryDimensions(); /// Changes this inventories handling of weight/capacity restrictions *************** *** 393,399 **** /// Add the weight, bulk, and count of this item to the totals. ! void AddDimensionsToInventory(psItem *item); /// Subtract the weight, bulk, and count of this item from the totals. ! void SubtractDimensionsFromInventory(psItem *item); /// Allocate either a psItem or a psGlyph --- 396,402 ---- /// Add the weight, bulk, and count of this item to the totals. ! ////////void AddDimensionsToInventory(psItem *item); /// Subtract the weight, bulk, and count of this item from the totals. ! //////void SubtractDimensionsFromInventory(psItem *item); /// Allocate either a psItem or a psGlyph Index: psitem.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/psitem.cpp,v retrieving revision 1.242 retrieving revision 1.243 diff -C2 -d -r1.242 -r1.243 *** psitem.cpp 24 Feb 2007 05:38:52 -0000 1.242 --- psitem.cpp 26 Feb 2007 05:56:58 -0000 1.243 *************** *** 173,178 **** equippedSlot = SIZET_NOT_FOUND; ! for (i=0;i<PSITEM_MAX_CONTAINER_SLOTS;i++) ! container_data.contained_item_ptr[i]=NULL; decay_resistance = 0; --- 173,178 ---- equippedSlot = SIZET_NOT_FOUND; ! //////// for (i=0;i<PSITEM_MAX_CONTAINER_SLOTS;i++) ! //////// container_data.contained_item_ptr[i]=NULL; decay_resistance = 0; *************** *** 227,230 **** --- 227,231 ---- } + /***************************************************************** // Destroy contained items first if (current_stats != NULL) // if our item wasn't properly initialised and this attribute wasn't set, don't continue so we won't crash *************** *** 243,247 **** } } ! // If this is a uniq item delete the item state if (base_stats!=NULL && flags & PSITEM_FLAG_UNIQUE_ITEM ) --- 244,249 ---- } } ! *************************************************************************/ ! // If this is a uniq item delete the item state if (base_stats!=NULL && flags & PSITEM_FLAG_UNIQUE_ITEM ) *************** *** 520,524 **** return; ! /*************** // Do not save items that are in limbo (in an exchange) if (owning_character && owning_character->GetActor() && owning_character->GetActor()->GetClient() && --- 522,526 ---- return; ! /*************** // Do not save items that are in limbo (in an exchange) if (owning_character && owning_character->GetActor() && owning_character->GetActor()->GetClient() && *************** *** 535,538 **** --- 537,541 ---- ***************/ + /*************************************************************** if (children) { *************** *** 546,549 **** --- 549,553 ---- } } + ***************************************************************/ psStringArray fields; *************** *** 872,877 **** void psItem::SetStackCount(unsigned short v) { - // This adjusts the weight of parents as well - // AdjustSumWeight(current_stats->GetWeight() * (v-stack_count)); stack_count=v; } --- 876,879 ---- *************** *** 1002,1007 **** void psItem::SetOwningCharacter(psCharacter *owner) { - int i; - // No need to go through resetting all the owner pointers if they are already set if (owning_character==owner) --- 1004,1007 ---- *************** *** 1013,1372 **** else owningCharacterID = 0; - - if (current_stats->GetIsContainer()) - { - for (i=0;i<PSITEM_MAX_CONTAINER_SLOTS;i++) - { - if (container_data.contained_item_ptr[i]!=NULL) - container_data.contained_item_ptr[i]->SetOwningCharacter(owner); - } - } - } - - - bool psItem::GetIsContainerEmpty() - { - if (!GetIsContainer()) - return true; - - for (int i=0;i<PSITEM_MAX_CONTAINER_SLOTS;i++) - { - if (container_data.contained_item_ptr[i]!=NULL) - return false; - } - return true; - } - - unsigned short psItem::GetContainedSize() - { - if (!GetIsContainer()) - return 0; - - unsigned int size = 0; - for (int i=0; i<PSITEM_MAX_CONTAINER_SLOTS; i++) - if (container_data.contained_item_ptr[i]!=NULL) - size += (unsigned int)container_data.contained_item_ptr[i]->GetSumSize(); - - return size; - } - - - psItem *psItem::GetItemInSlot(unsigned int slot) - { - if (!(current_stats->GetIsContainer()) || slot>=PSITEM_MAX_CONTAINER_SLOTS) - return NULL; - return container_data.contained_item_ptr[slot]; - } - - - /*************** - bool psItem::TakeOutOfContainer() - { - unsigned int parent_idx; - if (!container_parent) - return false; // This object is not contained in any other object - - for (parent_idx=0;parent_idx<PSITEM_MAX_CONTAINER_SLOTS;parent_idx++) - { - if (container_parent->container_data.contained_item_ptr[parent_idx]==this) - { - // TODO: Adjust sum properties if need be - weight, etc - container_parent->container_data.contained_item_ptr[parent_idx]=NULL; - container_parent->AdjustSumWeight(-sum_weight); - - container_parent=NULL; - owning_character=NULL; - loc_in_parent=PSITEM_MAX_CONTAINER_SLOTS; - - // Cannot save this item because it is in a limbo state. The caller - // must call save when the item is in a good state. - //Save(); - // Save the parent in it's new state. - return true; - } - } - - - // This should not happen. - Error3("Item ID %u has parent with ID %u, but parent does not contain child.",GetUID(),container_parent->GetUID()); - CS_ASSERT("Item parent does not know about item child in psItem::TakeOutOfContainer()"); - - container_parent=NULL; - owning_character=NULL; - loc_in_parent=PSITEM_MAX_CONTAINER_SLOTS; - - return true; // The parent claims it does not contain this object? - - } - - - bool psItem::AddItemToContainer(psItem *addme, bool test, psCharacter* useOwner) - { - unsigned int location_idx; - // Fail if this is not a container - if (!(GetIsContainer())) - { - Error3( "%s(%u) is not a container", GetName(), GetUID() ); - return false; - } - - //we can't put item into itself - if (addme==this || IsIndirectParent(addme)) - { - Error3( "Cannot add %s(%u) in itself", GetName(), GetUID() ); - return false; - } - - // Check size - if (GetContainerMaxSize() < addme->GetSize() || addme->GetSize()==65535) - { - csString error; - error.Format( "Item %s(%u) will not fit inside container %s(%u)\nMax Size = %d Item Size = %d\n", - addme->GetName(), addme->GetUID(), GetName(), GetUID(), GetContainerMaxSize(), addme->GetSize() ); - Error1( error ); - return false; - } - - - - // Remove item if it's in something else - if(!test) - addme->TakeOutOfContainer(); - - for (location_idx=0;location_idx<PSITEM_MAX_CONTAINER_SLOTS;location_idx++) - { - if (container_data.contained_item_ptr[location_idx]==NULL) - { - if(test) - return true; - addme->container_parent=this; - addme->loc_in_parent=location_idx; - container_data.contained_item_ptr[location_idx]=addme; - if ( useOwner ) - addme->SetOwningCharacter(useOwner); - else - addme->SetOwningCharacter(owning_character); - - AdjustSumWeight(addme->GetSumWeight()); - - return true; - } - } - - Error3("Item %s(%u) could not be added at all", addme->GetName(), addme->GetUID() ); - // Doesn't fit there either - return false; - } - - bool psItem::AddItemToContainer(psItem *addme, unsigned int slot, bool test) - { - // Fail if this is not a container or slot is out of range - if (!(GetIsContainer()) || slot>=PSITEM_MAX_CONTAINER_SLOTS) - { - Error3( "%s(%u) is not a container", GetName(), GetUID() ); - return false; - } - - //we can't put item into itself - if (addme==this || IsIndirectParent(addme)) - { - Error3( "%s(%u) is not a container", GetName(), GetUID() ); - return false; - } - - // Check size - if (GetContainerMaxSize() < addme->GetSize() || addme->GetSize()==65535) - { - csString error; - error.Format( "Item %s(%u) will not fit inside container %s(%u)\nMax Size = %d Item Size = %d\n", - addme->GetName(), addme->GetUID(), GetName(), GetUID(), GetContainerMaxSize(), addme->GetSize() ); - Error1( error ); - - return false; - } - - // Fail if the slot is not free and not stackable - if (container_data.contained_item_ptr[slot]!=NULL) - { - csString error; - error.Format("%s(%u) already has an item %s(%u) in slot %d.", GetName(), GetUID(), - container_data.contained_item_ptr[slot]->GetName(), container_data.contained_item_ptr[slot]->GetUID(), slot ); - return false; - } - if(test) - return true; - - // Remove item if it's in something else - addme->TakeOutOfContainer(); - - addme->container_parent=this; - addme->loc_in_parent=slot; - container_data.contained_item_ptr[slot]=addme; - - addme->SetOwningCharacter(owning_character); - AdjustSumWeight(addme->GetSumWeight()); - - return true; - } - - bool psItem::SwapItemsInContainer(unsigned int fromSlot, unsigned int toSlot) - { - // Fail if this is not a container - if (!GetIsContainer()) - return false; - - // Fail if fromSlot is out of range - if (fromSlot>=PSITEM_MAX_CONTAINER_SLOTS) - return false; - - // Fail if toSlot is out of range - if (toSlot>=PSITEM_MAX_CONTAINER_SLOTS) - return false; - - // swap 'em - psItem* toItem = container_data.contained_item_ptr[toSlot]; - psItem* fromItem = container_data.contained_item_ptr[fromSlot]; - container_data.contained_item_ptr[toSlot] = fromItem; - container_data.contained_item_ptr[fromSlot] = toItem; - - // only set items that exist - if (toItem) - toItem->SetLocInParent(fromSlot); - if (fromItem) - fromItem->SetLocInParent(toSlot); - return true; } - psItem *psItem::RemoveItemsInContainer(Client* client, unsigned int fromSlot, int count) - { - // Fail if fromSlot is out of range - if (fromSlot >= PSITEM_MAX_CONTAINER_SLOTS) - return NULL; - - psItem* fromItem = container_data.contained_item_ptr[fromSlot]; - if (fromItem==NULL) - return NULL; - - // Fail if move was more then current count - if (count < 0 || count > fromItem->GetStackCount() ) - return NULL; - - // Check to see if this client has the admin level to move this particular item - bool securityOverride = CacheManager::GetSingleton().GetCommandManager()->Validate(client->GetSecurityLevel(), - "move unpickupables/spawns"); - - // check if the item is pickable - if ((fromItem->flags & PSITEM_FLAG_NOPICKUP) && !securityOverride) - return NULL; - - if (fromItem->flags & PSITEM_FLAG_NOPICKUP) - { - psserver->SendSystemOK(client->GetClientNum(),"You picked up a non-pickable item."); - } - - // Do full move - if ( count == fromItem->GetStackCount() ) - { - container_data.contained_item_ptr[fromSlot]=NULL; - fromItem->container_parent = NULL; - return fromItem; - } - // Do partial move - else - { - psItem* newItem = fromItem->SplitStack((unsigned short)count); - if (!newItem) - return NULL; - - newItem->container_parent = NULL; - return newItem; - } - return NULL; - } - - int psItem::PutItemsInContainer(unsigned int toSlot,psItem *&item, psCharacter* owner, bool test) - { - // Fail if toSlot is out of range or item NULL - if (toSlot>=PSITEM_MAX_CONTAINER_SLOTS) - return PS_CONT_ERR_OUT_RANGE; - if (item==NULL) - return PS_CONT_ERR_NO_ITEM; - - //we can't put item into itself - if (item==this || IsIndirectParent(item)) - return PS_CONT_ERR_SELF; - - if ( GetContainerMaxSize() < item->GetCurrentStats()->GetSize() ) - return PS_CONT_ERR_TO_BIG; - - - psItem* toItem = container_data.contained_item_ptr[toSlot]; - - // If the slot is already occupied, we will try to stack items - if (toItem!=NULL) - { - // Fail if toItem has other real owner - if ((toItem->GetOwningCharacter() != owner) && - (toItem->GetOwningCharacter() != 0)) - return PS_CONT_ERR_NOT_OWNER; - - // Check if can't stack - if (!item->CheckStackableWith(*toItem)) - return PS_CONT_ERR_NO_STACK; - - // Combine the stacks. - int remainder = toItem->CombineStack(item, test); - - // Handle a remainder during the stacking attempt - if (remainder != 0) - return remainder; - } - - // otherwise put the item - else - { - if(test) - return PS_CONT_OK; - container_data.contained_item_ptr[toSlot] = item; - item->SetLocInParent( toSlot); - //item->SetOwningCharacter( GetOwningCharacter() ); - if (owner) - item->SetOwningCharacter( owner); - item->SetParent( this ); - } - - return PS_CONT_OK; - } - - ***************************************/ - - /*********************** - float psItem::AdjustSumWeight(float delta) - { - sum_weight += delta; - - // if (container_parent != NULL) - // container_parent->AdjustSumWeight(delta); - // else if (owning_character != NULL && GetIsContainer()) // Top level container in character's inventory - // owning_character->Inventory().ReassessInventoryDimensions(); // Update inventory - - // return sum_weight; - } - - float psItem::RecalculateFullWeight() - { - sum_weight=GetWeight(); - - if (current_stats->GetIsContainer()) - { - for (int i=0;i<PSITEM_MAX_CONTAINER_SLOTS;i++) - { - if (container_data.contained_item_ptr[i]!=NULL) - sum_weight+=container_data.contained_item_ptr[i]->RecalculateFullWeight(); - } - } - return sum_weight; - } - *************************************/ void psItem::SetUniqueStats(psItemStats *statptr) --- 1013,1018 ---- *************** *** 1894,1898 **** } ! unsigned short psItem::GetSize() { return current_stats->GetSize(); --- 1540,1544 ---- } ! unsigned short psItem::GetItemSize() { return current_stats->GetSize(); *************** *** 2432,2435 **** --- 2078,2082 ---- bool psItem::Destroy() { + /********************************************************** // csString itemid; if (this->GetIsContainer()) *************** *** 2442,2445 **** --- 2089,2093 ---- } } + ***********************************************************/ if (this->GetIsUnique()) Index: psitem.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/server/bulkobjects/psitem.h,v retrieving revision 1.135 retrieving revision 1.136 diff -C2 -d -r1.135 -r1.136 *** psitem.h 21 Feb 2007 07:27:28 -0000 1.135 --- psitem.h 26 Feb 2007 05:56:58 -0000 1.136 *************** *** 269,273 **** /// If set, this is a pointer to the item that is currently being trade skill transformed. psWorkGameEvent* transformationEvent; ! /// Container specific data struct --- 269,273 ---- /// If set, this is a pointer to the item that is currently being trade skill transformed. psWorkGameEvent* transformationEvent; ! /************************************************************************* /// Container specific data struct *************** *** 276,280 **** psItem *contained_item_ptr[PSITEM_MAX_CONTAINER_SLOTS]; } container_data; ! /// Location in the game world. Only valid if this item is not being carried by a player (directly or indirectly) struct --- 276,280 ---- psItem *contained_item_ptr[PSITEM_MAX_CONTAINER_SLOTS]; } container_data; ! ***************************************************/ /// Location in the game world. Only valid if this item is not being carried by a player (directly or indirectly) struct *************** *** 588,595 **** /// Returns true if this is not a container or if it's a container that's empty. ! bool GetIsContainerEmpty(); /// Returns the total size of the items within a container. ! unsigned short GetContainedSize(); /// Returns the item that contains this item, or NULL if it's not contained by another item. --- 588,595 ---- /// Returns true if this is not a container or if it's a container that's empty. ! /// bool GetIsContainerEmpty(); /// Returns the total size of the items within a container. ! ///// unsigned short GetContainedSize(); /// Returns the item that contains this item, or NULL if it's not contained by another item. *************** *** 745,751 **** float GetWeight(); ! unsigned short GetSize(); /// Gets the total size of the items in the stack. ! float GetSumSize() { return (float)GetSize()*stack_count; } unsigned short GetContainerMaxSize(); --- 745,751 ---- float GetWeight(); ! unsigned short GetItemSize(); /// Gets the total size of the items in the stack. ! float GetTotalStackSize() { return (float)GetItemSize()*stack_count; } unsigned short GetContainerMaxSize(); |