]>
Commit | Line | Data |
---|---|---|
1ee4a31b | 1 | #include "extern.h" |
09e1f7a2 | 2 | #include "pouch.h" |
3 | #include "item.h" | |
23f22a79 | 4 | #include <list> |
5 | #include <algorithm> | |
09e1f7a2 | 6 | |
7 | pouch::pouch() | |
8 | { | |
1ee4a31b | 9 | count = 0; |
09e1f7a2 | 10 | } |
11 | ||
12 | pouch::~pouch() | |
13 | { | |
14 | clear(); | |
15 | } | |
16 | ||
09e1f7a2 | 17 | void pouch::clear() |
18 | { | |
19 | items.clear(); | |
20 | } | |
21 | ||
22 | bool pouch::isEmpty() | |
23 | { | |
24 | return items.empty(); | |
25 | } | |
26 | ||
1ee4a31b | 27 | void pouch::sort() |
28 | { | |
29 | items.sort(); | |
30 | } | |
31 | ||
8a5cec4f | 32 | itemContainer *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 | 48 | itemContainer *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 | 64 | itemContainer *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 | 81 | itemContainer *pouch::addItem(item *i) |
1ee4a31b | 82 | { |
83 | if (count >= 3000 || count >= maxitems) | |
84 | { | |
85 | return NULL; | |
86 | } | |
53d5585b | 87 | itemContainer it(i), *temp; |
1ee4a31b | 88 | items.push_front(it); |
89 | ++count; | |
53d5585b | 90 | temp = &items.front(); |
1ee4a31b | 91 | sort(); |
53d5585b | 92 | return temp; |
1ee4a31b | 93 | } |
53d5585b | 94 | |
7b51307d | 95 | itemContainer *pouch::addItem(item *i, int amt) |
96 | { | |
97 | if (count >= 3000 || count + amt >= maxitems) | |
98 | { | |
99 | return NULL; | |
100 | } | |
101 | ||
53d5585b | 102 | itemContainer it(i), *temp; |
7b51307d | 103 | for (int x=0; x < amt; x++) |
104 | { | |
7b51307d | 105 | items.push_front(it); |
106 | ++count; | |
107 | } | |
53d5585b | 108 | temp = &items.front(); |
7b51307d | 109 | sort(); |
53d5585b | 110 | return temp; |
7b51307d | 111 | } |
112 | ||
1ee4a31b | 113 | itemContainer *pouch::addItemNoChecks(item *i) |
09e1f7a2 | 114 | { |
e696687e | 115 | itemContainer it(i); |
116 | items.push_front(it); | |
1ee4a31b | 117 | ++count; |
e0056fa6 | 118 | return &items.front(); |
09e1f7a2 | 119 | } |
120 | ||
121 | void pouch::deleteItem(item *i) | |
122 | { | |
e696687e | 123 | list<itemContainer>::iterator item_iter; |
1ee4a31b | 124 | count--; |
8a5cec4f | 125 | |
09e1f7a2 | 126 | item_iter = find(items.begin(), items.end(), i); |
127 | ||
128 | if (item_iter != items.end()) | |
129 | items.erase(item_iter); | |
130 | } | |
131 | ||
132 | const pouch &pouch::operator=(const pouch &right) | |
133 | { | |
134 | if (&right != this) | |
135 | { | |
136 | items.clear(); | |
137 | items = right.items; | |
138 | } | |
139 | return *this; | |
140 | } |