]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
fixed some compile bugs
[irc/gameservirc.git] / gameserv / pouch.cpp
CommitLineData
1ee4a31b 1#include "extern.h"
09e1f7a2 2#include "pouch.h"
3#include "item.h"
23f22a79 4#include <list>
5#include <algorithm>
09e1f7a2 6
7pouch::pouch()
8{
1ee4a31b 9 count = 0;
09e1f7a2 10}
11
12pouch::~pouch()
13{
14 clear();
15}
16
ce97fd48 17pouch::pouch(const pouch &p)
18{
19 count = p.count;
20 items = p.items;
21}
22
23pouch::pouch(pouch *p)
24{
25 count = p->count;
26 items = p->items;
27}
28
09e1f7a2 29void pouch::clear()
30{
31 items.clear();
32}
33
34bool pouch::isEmpty()
35{
36 return items.empty();
37}
38
1ee4a31b 39void pouch::sort()
40{
41 items.sort();
42}
43
8a5cec4f 44itemContainer *pouch::Find(int id)
45{
46 list<itemContainer>::iterator item_iter;
47 item_iter = items.begin();
48
49 while (item_iter != items.end())
50 {
51 if ((*item_iter).getItem()->getID() == id)
52 {
53 return &(*item_iter);
54 }
55 ++item_iter;
56 }
57 return NULL;
58}
59
e696687e 60itemContainer *pouch::Find(char *n)
09e1f7a2 61{
e696687e 62 list<itemContainer>::iterator item_iter;
09e1f7a2 63 item_iter = items.begin();
64
65 while (item_iter != items.end())
66 {
e696687e 67 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 68 {
e696687e 69 return &(*item_iter);
09e1f7a2 70 }
8a5cec4f 71 ++item_iter;
09e1f7a2 72 }
73 return NULL;
74}
75
e696687e 76itemContainer *pouch::Find(string &n)
09e1f7a2 77{
e696687e 78 list<itemContainer>::iterator item_iter;
09e1f7a2 79 item_iter = items.begin();
80
81 while (item_iter != items.end())
82 {
e696687e 83 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 84 {
e696687e 85 return &(*item_iter);
09e1f7a2 86 }
8a5cec4f 87 ++item_iter;
09e1f7a2 88 }
89
90 return NULL;
91}
92
e0056fa6 93itemContainer *pouch::addItem(item *i)
1ee4a31b 94{
95 if (count >= 3000 || count >= maxitems)
96 {
97 return NULL;
98 }
2497f916 99 else
100 {
101 itemContainer it(i), *temp;
102 items.push_front(it);
103 ++count;
104 temp = &items.front();
105 sort();
106 return temp;
107 }
1ee4a31b 108}
53d5585b 109
7b51307d 110itemContainer *pouch::addItem(item *i, int amt)
111{
2497f916 112 if (count >= 3000 || (count + amt) >= maxitems)
7b51307d 113 {
114 return NULL;
115 }
2497f916 116 else
7b51307d 117 {
2497f916 118 itemContainer it(i), *temp;
119 for (int x=0; x < amt; x++)
120 {
121 items.push_front(it);
122 ++count;
123 }
124 temp = &items.front();
125 sort();
126 return temp;
7b51307d 127 }
7b51307d 128}
129
1ee4a31b 130itemContainer *pouch::addItemNoChecks(item *i)
09e1f7a2 131{
e696687e 132 itemContainer it(i);
133 items.push_front(it);
1ee4a31b 134 ++count;
e0056fa6 135 return &items.front();
09e1f7a2 136}
137
138void pouch::deleteItem(item *i)
139{
e696687e 140 list<itemContainer>::iterator item_iter;
8a5cec4f 141
09e1f7a2 142 item_iter = find(items.begin(), items.end(), i);
f9db99e0 143
09e1f7a2 144 if (item_iter != items.end())
f9db99e0 145 {
146 items.erase(item_iter);
147 count--;
148 }
09e1f7a2 149}
150
151const pouch &pouch::operator=(const pouch &right)
152{
153 if (&right != this)
154 {
155 items.clear();
156 items = right.items;
157 }
158 return *this;
159}