//o--------------------------------------------------------------------------o //| Function - SI32 CWeight::calcCharWeight( CChar *mChar ) //| Date - 2/23/2003 //| Developers - Zane //| Organization - UOX3 DevTeam //o--------------------------------------------------------------------------o //| Description - Calculate the total weight of a character based upon all items he owns, //| This function should never need to be called but is available for //| bruteforce weight updating //o--------------------------------------------------------------------------o SI32 CWeight::calcCharWeight( CChar *mChar ) { SI32 totalWeight = 0; SI32 contWeight = 0; for( CItem *i = mChar->FirstItem(); !mChar->FinishedItems(); i = mChar->NextItem() ) { if( !ValidateObject( i ) ) continue; if( IsWeightedContainer( i ) ) { if( i->GetLayer() == IL_PACKITEM ) { CTile& tile = Map->SeekTile( i->GetID() ); contWeight = static_cast<SI32>( tile.Weight() * 100); // Add the weight of the container contWeight += calcWeight( i ); // Find and add the weight of the items in the container i->SetWeight( contWeight, false ); // Also update the weight property of the container totalWeight += contWeight; } else totalWeight += i->GetWeight(); // Normal item, just add its weight } if( totalWeight >= MAX_WEIGHT ) return MAX_WEIGHT; } return totalWeight; }
void CContainer::OnRemoveOb( CGObListRec* pObRec ) // Override this = called when removed from list. { ADDTOCALLSTACK("CContainer::OnRemoveOb"); // remove this object from the container list. // Overload the RemoveAt for general lists to come here. CItem * pItem = STATIC_CAST <CItem*>(pObRec); ASSERT(pItem); CGObList::OnRemoveOb( pItem ); ASSERT( pItem->GetParent() == NULL ); pItem->SetContainerFlags(UID_O_DISCONNECT); // It is no place for the moment. OnWeightChange( -pItem->GetWeight()); }
void CCPropsItemChar::SetPropertyNum(int iPropIndex, PropertyValNum_t iVal, CObjBase* pLinkedObj, RESDISPLAY_VERSION iLimitToExpansion, bool fDeleteZero) { ADDTOCALLSTACK("CCPropsItemChar::SetPropertyNum"); ASSERT(!IsPropertyStr(iPropIndex)); ASSERT((iLimitToExpansion >= RDS_PRET2A) && (iLimitToExpansion < RDS_QTY)); if ((fDeleteZero && (iVal == 0)) || (_iPropertyExpansion[iPropIndex] > iLimitToExpansion)) { if (0 == _mPropsNum.erase(iPropIndex)) return; // I didn't have this property, so avoid further processing. } else _mPropsNum[iPropIndex] = iVal; if (!pLinkedObj) return; // Do stuff to the pLinkedObj switch (iPropIndex) { case PROPITCH_WEIGHTREDUCTION: { CItem *pItemLink = static_cast<CItem*>(pLinkedObj); int oldweight = pItemLink->GetWeight(); CContainer * pCont = dynamic_cast <CContainer*> (pItemLink->GetParent()); if (pCont) { ASSERT(pItemLink->IsItemEquipped() || pItemLink->IsItemInContainer()); pCont->OnWeightChange(pItemLink->GetWeight() - oldweight); pLinkedObj->UpdatePropertyFlag(); } break; } //default: // pLinkedObj->UpdatePropertyFlag(); // break; } }
int GetWeight( ItemAttr item ) { int type, num; getItemIndex( item.item_no, type, num ); CItem *t = ItemUnit( type, num ); if( !t ) return 0; int weight = t->GetWeight(); if( t->GetRbutton() == DIVIDE_ITEM ) { int dur = t->GetItemDuration(); if( dur > 0 ) weight *= item.attr[IATTR_MUCH] / dur; else weight *= item.attr[IATTR_MUCH]; } return weight; }