]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
More updates to the item system
[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
e696687e 32itemContainer *pouch::Find(char *n)
09e1f7a2 33{
e696687e 34 list<itemContainer>::iterator item_iter;
09e1f7a2 35 item_iter = items.begin();
36
37 while (item_iter != items.end())
38 {
e696687e 39 if ((*item_iter).getItem()->getName() == n)
09e1f7a2 40 {
e696687e 41 return &(*item_iter);
09e1f7a2 42 }
43 item_iter++;
44 }
45 return NULL;
46}
47
e696687e 48itemContainer *pouch::Find(string &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 }
59 item_iter++;
60 }
61
62 return NULL;
63}
64
e0056fa6 65itemContainer *pouch::addItem(item *i)
1ee4a31b 66{
67 if (count >= 3000 || count >= maxitems)
68 {
69 return NULL;
70 }
71 itemContainer it(i);
72 items.push_front(it);
73 ++count;
74 sort();
75 return &items.front();
76}
77itemContainer *pouch::addItemNoChecks(item *i)
09e1f7a2 78{
e696687e 79 itemContainer it(i);
80 items.push_front(it);
1ee4a31b 81 ++count;
e0056fa6 82 return &items.front();
09e1f7a2 83}
84
85void pouch::deleteItem(item *i)
86{
e696687e 87 list<itemContainer>::iterator item_iter;
1ee4a31b 88 count--;
09e1f7a2 89
90 item_iter = find(items.begin(), items.end(), i);
91
92 if (item_iter != items.end())
93 items.erase(item_iter);
94}
95
96const pouch &pouch::operator=(const pouch &right)
97{
98 if (&right != this)
99 {
100 items.clear();
101 items = right.items;
102 }
103 return *this;
104}