]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
added a parameter to the tavern buy command that allows you to specify how many items...
[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
09e1f7a2 17void pouch::clear()
18{
19 items.clear();
20}
21
22bool pouch::isEmpty()
23{
24 return items.empty();
25}
26
1ee4a31b 27void pouch::sort()
28{
29 items.sort();
30}
31
8a5cec4f 32itemContainer *pouch::Find(int id)
33{
34 list<itemContainer>::iterator item_iter;
35 item_iter = items.begin();
36
37 while (item_iter != items.end())
38 {
39 if ((*item_iter).getItem()->getID() == id)
40 {
41 return &(*item_iter);
42 }
43 ++item_iter;
44 }
45 return NULL;
46}
47
e696687e 48itemContainer *pouch::Find(char *n)
09e1f7a2 49{
e696687e 50 list<itemContainer>::iterator item_iter;
09e1f7a2 51 item_iter = items.begin();
52
53 while (item_iter != items.end())
54 {
e696687e 55 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 56 {
e696687e 57 return &(*item_iter);
09e1f7a2 58 }
8a5cec4f 59 ++item_iter;
09e1f7a2 60 }
61 return NULL;
62}
63
e696687e 64itemContainer *pouch::Find(string &n)
09e1f7a2 65{
e696687e 66 list<itemContainer>::iterator item_iter;
09e1f7a2 67 item_iter = items.begin();
68
69 while (item_iter != items.end())
70 {
e696687e 71 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 72 {
e696687e 73 return &(*item_iter);
09e1f7a2 74 }
8a5cec4f 75 ++item_iter;
09e1f7a2 76 }
77
78 return NULL;
79}
80
e0056fa6 81itemContainer *pouch::addItem(item *i)
1ee4a31b 82{
83 if (count >= 3000 || count >= maxitems)
84 {
85 return NULL;
86 }
87 itemContainer it(i);
88 items.push_front(it);
89 ++count;
90 sort();
91 return &items.front();
92}
7b51307d 93itemContainer *pouch::addItem(item *i, int amt)
94{
95 if (count >= 3000 || count + amt >= maxitems)
96 {
97 return NULL;
98 }
99
100 for (int x=0; x < amt; x++)
101 {
102 itemContainer it(i);
103 items.push_front(it);
104 ++count;
105 }
106 sort();
107 return &items.front();
108}
109
1ee4a31b 110itemContainer *pouch::addItemNoChecks(item *i)
09e1f7a2 111{
e696687e 112 itemContainer it(i);
113 items.push_front(it);
1ee4a31b 114 ++count;
e0056fa6 115 return &items.front();
09e1f7a2 116}
117
118void pouch::deleteItem(item *i)
119{
e696687e 120 list<itemContainer>::iterator item_iter;
1ee4a31b 121 count--;
8a5cec4f 122
09e1f7a2 123 item_iter = find(items.begin(), items.end(), i);
124
125 if (item_iter != items.end())
126 items.erase(item_iter);
127}
128
129const pouch &pouch::operator=(const pouch &right)
130{
131 if (&right != this)
132 {
133 items.clear();
134 items = right.items;
135 }
136 return *this;
137}