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