X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/1ee4a31ba6be54ea7a46972bcfff6cd98979f2ea..d7c069e247c2b2d3073eab722aa0c3afc2a75214:/gameserv/pouch.cpp diff --git a/gameserv/pouch.cpp b/gameserv/pouch.cpp index 50e76a2..078ff42 100644 --- a/gameserv/pouch.cpp +++ b/gameserv/pouch.cpp @@ -29,6 +29,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 +56,7 @@ itemContainer *pouch::Find(char *n) { return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; } @@ -56,7 +72,7 @@ itemContainer *pouch::Find(string &n) { return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; @@ -68,12 +84,32 @@ itemContainer *pouch::addItem(item *i) { return NULL; } - itemContainer it(i); + itemContainer it(i), *temp; items.push_front(it); ++count; + temp = &items.front(); sort(); - return &items.front(); + return temp; } + +itemContainer *pouch::addItem(item *i, int amt) +{ + if (count >= 3000 || count + amt >= maxitems) + { + return NULL; + } + + 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); @@ -86,7 +122,7 @@ void pouch::deleteItem(item *i) { list::iterator item_iter; count--; - + item_iter = find(items.begin(), items.end(), i); if (item_iter != items.end())