]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
Fixed the Player class so that the data is all private and encapsulated. Updated...
[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}
93itemContainer *pouch::addItemNoChecks(item *i)
09e1f7a2 94{
e696687e 95 itemContainer it(i);
96 items.push_front(it);
1ee4a31b 97 ++count;
e0056fa6 98 return &items.front();
09e1f7a2 99}
100
101void pouch::deleteItem(item *i)
102{
e696687e 103 list<itemContainer>::iterator item_iter;
1ee4a31b 104 count--;
8a5cec4f 105
09e1f7a2 106 item_iter = find(items.begin(), items.end(), i);
107
108 if (item_iter != items.end())
109 items.erase(item_iter);
110}
111
112const pouch &pouch::operator=(const pouch &right)
113{
114 if (&right != this)
115 {
116 items.clear();
117 items = right.items;
118 }
119 return *this;
120}