Changeset 177 for trunk/src/game/Bag.cpp

Show
Ignore:
Timestamp:
11/19/08 13:43:30 (17 years ago)
Author:
yumileroy
Message:

[svn] * Avoid access to bag item prototype for getting bag size, use related item
update field instead as more fast source. source mangos.
* Further reduce of DB access in guild handlers.
* Multi-locale DBC extracting - source Foks

*** Devs not responsible if all your player items drop to the ground and get eaten by ants or rabbits.. or some kind of wierd ant-rabbits..

Original author: KingPin?
Date: 2008-11-06 08:20:26-06:00

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/game/Bag.cpp

    r102 r177  
    4040Bag::~Bag() 
    4141{ 
    42     for(int i = 0; i<MAX_BAG_SIZE; i++) 
    43     { 
    44         if(m_bagslot[i])    delete m_bagslot[i]; 
    45     } 
     42    for(int i = 0; i < MAX_BAG_SIZE; ++i) 
     43        if (m_bagslot[i]) 
     44             delete m_bagslot[i]; 
    4645} 
    4746 
     
    5049    Item::AddToWorld(); 
    5150 
    52     for(int i = 0; i<MAX_BAG_SIZE; i++) 
    53     { 
     51    for(uint32 i = 0;  i < GetBagSize(); ++i) 
    5452        if(m_bagslot[i]) 
    5553            m_bagslot[i]->AddToWorld(); 
    56     } 
    5754} 
    5855 
    5956void Bag::RemoveFromWorld() 
    6057{ 
    61     for(int i = 0; i<MAX_BAG_SIZE; i++) 
    62     { 
     58    for(uint32 i = 0; i < GetBagSize(); ++i) 
    6359        if(m_bagslot[i]) 
    6460            m_bagslot[i]->RemoveFromWorld(); 
    65     } 
    6661 
    6762    Item::RemoveFromWorld(); 
     
    112107 
    113108    // cleanup bag content related item value fields (its will be filled correctly from `character_inventory`) 
    114     for (uint32 i = 0; i < GetProto()->ContainerSlots; i++) 
     109    for (int i = 0; i < MAX_BAG_SIZE; ++i) 
    115110    { 
    116111        SetUInt64Value(CONTAINER_FIELD_SLOT_1 + (i*2), 0); 
     
    128123{ 
    129124    for (int i = 0; i < MAX_BAG_SIZE; i++) 
    130     { 
    131         if (m_bagslot[i]) 
    132         { 
     125        if (m_bagslot[i]) 
    133126            m_bagslot[i]->DeleteFromDB(); 
    134         } 
    135     } 
    136127 
    137128    Item::DeleteFromDB(); 
     
    140131uint32 Bag::GetFreeSlots() const 
    141132{ 
    142     uint32 ContainerSlots=GetProto()->ContainerSlots; 
    143133    uint32 slots = 0; 
    144     for (uint8 i=0; i <ContainerSlots; i++) 
     134    for (uint32 i=0; i < GetBagSize(); i++) 
    145135        if (!m_bagslot[i]) 
    146136            ++slots; 
     
    179169    Item::BuildCreateUpdateBlockForPlayer( data, target ); 
    180170 
    181     for (int i = 0; i < MAX_BAG_SIZE; i++) 
    182     { 
     171    for (uint32 i = 0; i < GetBagSize(); ++i) 
    183172        if(m_bagslot[i]) 
    184173            m_bagslot[i]->BuildCreateUpdateBlockForPlayer( data, target ); 
    185     } 
    186174} 
    187175 
     
    189177bool Bag::IsEmpty() const 
    190178{ 
    191     uint32 ContainerSlots=GetProto()->ContainerSlots; 
    192     for(uint32 i=0; i < ContainerSlots; i++) 
    193         if (m_bagslot[i]) return false; 
     179    for(uint32 i = 0; i < GetBagSize(); ++i) 
     180        if (m_bagslot[i]) 
     181            return false; 
    194182 
    195183    return true; 
     
    198186uint32 Bag::GetItemCount( uint32 item, Item* eItem ) const 
    199187{ 
    200     uint32 ContainerSlots=GetProto()->ContainerSlots; 
    201  
    202188    Item *pItem; 
    203189    uint32 count = 0; 
    204     for(uint32 i=0; i < ContainerSlots; i++) 
     190    for(uint32 i=0; i < GetBagSize(); ++i) 
    205191    { 
    206192        pItem = m_bagslot[i]; 
     
    211197    if(eItem && eItem->GetProto()->GemProperties) 
    212198    { 
    213         for(uint32 i=0; i < ContainerSlots; i++) 
     199        for(uint32 i=0; i < GetBagSize(); ++i) 
    214200        { 
    215201            pItem = m_bagslot[i]; 
     
    224210uint8 Bag::GetSlotByItemGUID(uint64 guid) const 
    225211{ 
    226     uint32 ContainerSlots=GetProto()->ContainerSlots; 
    227  
    228     for(uint32 i=0;i<ContainerSlots;i++) 
    229     { 
     212    for(uint32 i = 0; i < GetBagSize(); ++i) 
    230213        if(m_bagslot[i] != 0) 
    231214            if(m_bagslot[i]->GetGUID() == guid) 
    232215                return i; 
    233     } 
    234216    return NULL_SLOT; 
    235217} 
    236218 
    237 // Adds an item to a bag slot 
    238 // - slot can be NULL_SLOT, in that case function searchs for a free slot 
    239 // - Return values: 0 - item not added 
    240 //                  1 - item added to a free slot (and perhaps to a stack) 
    241 //                  2 - item added to a stack (item should be deleted) 
    242219Item* Bag::GetItemByPos( uint8 slot ) const 
    243220{ 
    244     ItemPrototype const *pBagProto = GetProto(); 
    245     if( pBagProto ) 
    246     { 
    247         if( slot < pBagProto->ContainerSlots ) 
    248             return m_bagslot[slot]; 
    249     } 
     221    if( slot < GetBagSize() ) 
     222        return m_bagslot[slot]; 
     223         
    250224    return NULL; 
    251225}