X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/1ee4a31ba6be54ea7a46972bcfff6cd98979f2ea..f4f0d89de4c48f4b4fcd0a266c9d5796fc61ed42:/gameserv/pouch.cpp diff --git a/gameserv/pouch.cpp b/gameserv/pouch.cpp index 50e76a2..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() @@ -29,6 +42,22 @@ void pouch::sort() items.sort(); } +itemContainer *pouch::Find(int id) +{ + list::iterator item_iter; + item_iter = items.begin(); + + while (item_iter != items.end()) + { + if ((*item_iter).getItem()->getID() == id) + { + return &(*item_iter); + } + ++item_iter; + } + return NULL; +} + itemContainer *pouch::Find(char *n) { list::iterator item_iter; @@ -40,7 +69,7 @@ itemContainer *pouch::Find(char *n) { return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; } @@ -56,7 +85,7 @@ itemContainer *pouch::Find(string &n) { return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; @@ -68,12 +97,37 @@ itemContainer *pouch::addItem(item *i) { return NULL; } - itemContainer it(i); - items.push_front(it); - ++count; - sort(); - return &items.front(); + 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) + { + return NULL; + } + else + { + itemContainer it(i), *temp; + for (int x=0; x < amt; x++) + { + items.push_front(it); + ++count; + } + temp = &items.front(); + sort(); + return temp; + } } + itemContainer *pouch::addItemNoChecks(item *i) { itemContainer it(i); @@ -85,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); + 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)