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