]> jfr.im git - irc/gameservirc.git/blame - gameserv/pouch.cpp
readded the config.php
[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 }
2497f916 87 else
88 {
89 itemContainer it(i), *temp;
90 items.push_front(it);
91 ++count;
92 temp = &items.front();
93 sort();
94 return temp;
95 }
1ee4a31b 96}
53d5585b 97
7b51307d 98itemContainer *pouch::addItem(item *i, int amt)
99{
2497f916 100 if (count >= 3000 || (count + amt) >= maxitems)
7b51307d 101 {
102 return NULL;
103 }
2497f916 104 else
7b51307d 105 {
2497f916 106 itemContainer it(i), *temp;
107 for (int x=0; x < amt; x++)
108 {
109 items.push_front(it);
110 ++count;
111 }
112 temp = &items.front();
113 sort();
114 return temp;
7b51307d 115 }
7b51307d 116}
117
1ee4a31b 118itemContainer *pouch::addItemNoChecks(item *i)
09e1f7a2 119{
e696687e 120 itemContainer it(i);
121 items.push_front(it);
1ee4a31b 122 ++count;
e0056fa6 123 return &items.front();
09e1f7a2 124}
125
126void pouch::deleteItem(item *i)
127{
e696687e 128 list<itemContainer>::iterator item_iter;
1ee4a31b 129 count--;
8a5cec4f 130
09e1f7a2 131 item_iter = find(items.begin(), items.end(), i);
132
133 if (item_iter != items.end())
134 items.erase(item_iter);
135}
136
137const pouch &pouch::operator=(const pouch &right)
138{
139 if (&right != this)
140 {
141 items.clear();
142 items = right.items;
143 }
144 return *this;
145}