X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/53d5585b4b7338902f1f4618b6a95ca63342d31c..f71a53ab6e251712c26a11c0b373d41014f775d5:/gameserv/pouch.cpp diff --git a/gameserv/pouch.cpp b/gameserv/pouch.cpp index 078ff42..01964bd 100644 --- a/gameserv/pouch.cpp +++ b/gameserv/pouch.cpp @@ -14,9 +14,22 @@ pouch::~pouch() clear(); } +pouch::pouch(const pouch &p) +{ + count = p.count; + items = p.items; +} + +pouch::pouch(pouch *p) +{ + count = p->count; + items = p->items; +} + void pouch::clear() { items.clear(); + count = 0; } bool pouch::isEmpty() @@ -84,30 +97,35 @@ itemContainer *pouch::addItem(item *i) { return NULL; } - itemContainer it(i), *temp; - items.push_front(it); - ++count; - temp = &items.front(); - sort(); - return temp; + else + { + itemContainer it(i), *temp; + items.push_front(it); + ++count; + temp = &items.front(); + sort(); + return temp; + } } itemContainer *pouch::addItem(item *i, int amt) { - if (count >= 3000 || count + amt >= maxitems) + if (count >= 3000 || (count + amt) >= maxitems) { return NULL; } - - itemContainer it(i), *temp; - for (int x=0; x < amt; x++) + else { - items.push_front(it); - ++count; + itemContainer it(i), *temp; + for (int x=0; x < amt; x++) + { + items.push_front(it); + ++count; + } + temp = &items.front(); + sort(); + return temp; } - temp = &items.front(); - sort(); - return temp; } itemContainer *pouch::addItemNoChecks(item *i) @@ -121,12 +139,14 @@ itemContainer *pouch::addItemNoChecks(item *i) void pouch::deleteItem(item *i) { list::iterator item_iter; - count--; item_iter = find(items.begin(), items.end(), i); - + if (item_iter != items.end()) - items.erase(item_iter); + { + items.erase(item_iter); + count--; + } } const pouch &pouch::operator=(const pouch &right)