[2771] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Container.cpp
blob53ad397b52697ce97d480a991fdc3cbcb3b16abf
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "ObjectMgr.h"
21 #include "Database/DatabaseEnv.h"
22 #include "Container.h"
24 Container::Container( )
26 m_objectType |= TYPE_CONTAINER;
27 m_objectTypeId = TYPEID_CONTAINER;
29 m_valuesCount = CONTAINER_END;
32 void Container::Create( uint32 guidlow, uint32 itemid, Player *owner )
34 Object::_Create( guidlow, HIGHGUID_CONTAINER );
36 ItemPrototype const *m_itemProto = objmgr.GetItemPrototype( itemid );
37 ASSERT(m_itemProto);
39 uint32 ContainerSlots =m_itemProto->ContainerSlots;
41 SetUInt32Value( OBJECT_FIELD_ENTRY, itemid );
42 SetFloatValue( OBJECT_FIELD_SCALE_X, 1.0f );
43 SetUInt64Value( ITEM_FIELD_OWNER, owner->GetGUID() );
44 SetUInt64Value( ITEM_FIELD_CONTAINED, owner->GetGUID() );
45 SetUInt32Value( ITEM_FIELD_STACK_COUNT, 1 );
46 SetUInt32Value( CONTAINER_FIELD_NUM_SLOTS,ContainerSlots);
48 m_Slot = new Item*[ContainerSlots];
49 memset(m_Slot, 0, sizeof(Item*)*ContainerSlots);
51 m_owner = owner;
54 uint8 Container::FindFreeSlot()
56 uint32 TotalSlots = GetUInt32Value( CONTAINER_FIELD_NUM_SLOTS );
57 for (uint8 i=0; i < TotalSlots; i++)
59 if(!m_Slot[i])
61 return i;
63 else
67 return (uint8)-1;
70 void Container::AddItem(uint8 slot, Item *item)
72 ASSERT(m_Slot[slot] == NULL);
74 m_Slot[slot] = item;
75 SetUInt64Value( (uint16)(CONTAINER_FIELD_SLOT_1 + (slot*2)), item->GetGUID() );
78 ItemPrototype const * Container:: GetProto()
80 return objmgr.GetItemPrototype(GetUInt32Value( OBJECT_FIELD_ENTRY ));