]> jfr.im git - irc/gameservirc.git/blob - gameserv/pouch.cpp
added items to the tavern.dat, added the filename option to the config file
[irc/gameservirc.git] / gameserv / pouch.cpp
1 #include "pouch.h"
2 #include "item.h"
3 #include <list>
4 #include <algorithm>
5
6 pouch::pouch()
7 {
8 }
9
10 pouch::~pouch()
11 {
12 clear();
13 }
14
15 void pouch::sort()
16 {
17 items.sort();
18 }
19
20 void pouch::clear()
21 {
22 items.clear();
23 }
24
25 bool pouch::isEmpty()
26 {
27 return items.empty();
28 }
29
30 itemContainer *pouch::Find(char *n)
31 {
32 list<itemContainer>::iterator item_iter;
33 item_iter = items.begin();
34
35 while (item_iter != items.end())
36 {
37 if ((*item_iter).getItem()->getName() == n)
38 {
39 return &(*item_iter);
40 }
41 item_iter++;
42 }
43 return NULL;
44 }
45
46 itemContainer *pouch::Find(string &n)
47 {
48 list<itemContainer>::iterator item_iter;
49 item_iter = items.begin();
50
51 while (item_iter != items.end())
52 {
53 if ((*item_iter).getItem()->getName() == n)
54 {
55 return &(*item_iter);
56 }
57 item_iter++;
58 }
59
60 return NULL;
61 }
62
63 itemContainer *pouch::addItem(item *i)
64 {
65 itemContainer it(i);
66 items.push_front(it);
67 return &items.front();
68 }
69
70 void pouch::deleteItem(item *i)
71 {
72 list<itemContainer>::iterator item_iter;
73
74 item_iter = find(items.begin(), items.end(), i);
75
76 if (item_iter != items.end())
77 items.erase(item_iter);
78 }
79
80 const pouch &pouch::operator=(const pouch &right)
81 {
82 if (&right != this)
83 {
84 items.clear();
85 items = right.items;
86 }
87 return *this;
88 }