ManaPlus
complexitem.cpp
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2011-2019 The ManaPlus Developers
4  *
5  * This file is part of The ManaPlus Client.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
22 
23 #include "utils/dtor.h"
24 #include "utils/foreach.h"
25 
26 #include "debug.h"
27 
29  const ItemTypeT type,
30  const int quantity,
31  const uint8_t refine,
32  const ItemColor color,
33  const Identified identified,
34  const Damaged damaged,
35  const Favorite favorite,
36  const Equipm equipment,
37  const Equipped equipped) :
38  Item(id,
39  type,
40  quantity,
41  refine,
42  color,
43  identified,
44  damaged,
45  favorite,
46  equipment,
47  equipped),
48  mChildItems()
49 {
50 }
51 
53 {
55  mChildItems.clear();
56 }
57 
58 void ComplexItem::addChild(const Item *const item,
59  const int amount)
60 {
61  if (item == nullptr)
62  return;
63  increaseQuantity(amount);
64  Item *child = nullptr;
65  FOR_EACH (STD_VECTOR<Item*>::iterator, it, mChildItems)
66  {
67  Item *const item1 = *it;
68  if (item1->getId() == item->getId() &&
69  item1->getInvIndex() == item->getInvIndex() &&
70  item1->getTag() == item->getTag())
71  {
72  child = item1;
73  break;
74  }
75  }
76  if (child != nullptr)
77  {
78  child->increaseQuantity(amount);
79  }
80  else
81  {
82  child = new ComplexItem(item->getId(),
83  item->getType(),
84  amount,
85  item->getRefine(),
86  item->getColor(),
87  item->getIdentified(),
88  item->getDamaged(),
89  item->getFavorite(),
92  child->setTag(item->getTag());
93  child->setInvIndex(item->getInvIndex());
94  mChildItems.push_back(child);
95  }
96 }
Item
Definition: item.h:48
Item::getIdentified
Identified getIdentified() const
Definition: item.h:192
Equipm_false
const bool Equipm_false
Definition: equipm.h:29
Item::setTag
void setTag(const int tag)
Definition: item.h:227
Item::getColor
ItemColor getColor() const
Definition: item.h:180
ComplexItem::mChildItems
std::vector< Item * > mChildItems
Definition: complexitem.h:62
Item::setInvIndex
void setInvIndex(const int index)
Definition: item.h:158
ComplexItem::addChild
void addChild(const Item *const item, const int amount)
Definition: complexitem.cpp:58
Item::getId
int getId() const
Definition: item.h:80
ItemTypeT
ItemType ::T ItemTypeT
Definition: itemtype.h:42
ComplexItem::ComplexItem
ComplexItem(const int id, const ItemTypeT type, const int quantity, const uint8_t refine, const ItemColor color, const Identified identified, const Damaged damaged, const Favorite favorite, const Equipm equipment, const Equipped equipped)
Definition: complexitem.cpp:28
Item::increaseQuantity
void increaseQuantity(const int amount)
Definition: item.h:98
Item::getFavorite
Favorite getFavorite() const
Definition: item.h:204
bool
Item::getType
ItemTypeT getType() const
Definition: item.h:224
ComplexItem::~ComplexItem
virtual ~ComplexItem()
Definition: complexitem.cpp:52
Item::getRefine
uint8_t getRefine() const
Definition: item.h:140
Item::getTag
int getTag() const
Definition: item.h:230
ItemColor
uint16_t ItemColor
Definition: itemcolor.h:29
Item::getDamaged
Damaged getDamaged() const
Definition: item.h:198
Item::getInvIndex
int getInvIndex() const
Definition: item.h:164
complexitem.h
delete_all
void delete_all(Container &c)
Definition: dtor.h:55
foreach.h
dtor.h
Equipped_false
const bool Equipped_false
Definition: equipped.h:29
FOR_EACH
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
debug.h