GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/item/complexitem.cpp Lines: 0 31 0.0 %
Date: 2017-11-29 Branches: 0 14 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  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
21
#include "resources/item/complexitem.h"
22
23
#include "utils/dtor.h"
24
#include "utils/foreach.h"
25
26
#include "debug.h"
27
28
ComplexItem::ComplexItem(const int id,
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
52
ComplexItem::~ComplexItem()
53
{
54
    delete_all(mChildItems);
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(),
90
            Equipm_false,
91
            Equipped_false);
92
        child->setTag(item->getTag());
93
        child->setInvIndex(item->getInvIndex());
94
        mChildItems.push_back(child);
95
    }
96
}