blob: e1a74dc1b0e9d306c0914ad1d0349e7614b4d4ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/*
core/inventory.cc
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
#include "core/inventory.h"
#include "sys/sys.h"
namespace core
{
/* ---- class Inventory -------------------------------------------- */
Inventory::Inventory()
{
}
Inventory::~Inventory()
{
clear();
}
void Inventory::add(Item *item)
{
for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) {
// check if the item was already added
if ((*it) == item)
return;
}
inventory_items.push_back(item);
}
void Inventory::remove(Item *item)
{
for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) {
if ((*it) == item) {
inventory_items.erase(it);
delete item;
return;
}
}
}
Item *Inventory::find(const Info *info)
{
// sarch the inventory for a specified item type
for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) {
Item *item = (*it);
if (item->info() == info) {
return item;
}
}
// not found
return 0;
}
void Inventory::clear()
{
for (Items::iterator it = inventory_items.begin(); it != inventory_items.end(); it++) {
Item *item = (*it);
delete item;
}
inventory_items.clear();
}
} // namespace core
|