X-Git-Url: https://jfr.im/git/irc/gameservirc.git/blobdiff_plain/09e1f7a231f3675e66baa7a306e7d8a170a812dd..d7c069e247c2b2d3073eab722aa0c3afc2a75214:/gameserv/pouch.cpp diff --git a/gameserv/pouch.cpp b/gameserv/pouch.cpp index 20bf3af..078ff42 100644 --- a/gameserv/pouch.cpp +++ b/gameserv/pouch.cpp @@ -1,8 +1,12 @@ +#include "extern.h" #include "pouch.h" #include "item.h" +#include +#include pouch::pouch() { + count = 0; } pouch::~pouch() @@ -10,11 +14,6 @@ pouch::~pouch() clear(); } -void pouch::sort() -{ - items.sort(); -} - void pouch::clear() { items.clear(); @@ -25,48 +24,105 @@ bool pouch::isEmpty() return items.empty(); } -item *pouch::Find(char *n) +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; + list::iterator item_iter; item_iter = items.begin(); while (item_iter != items.end()) { - if ((*item_iter)->getName() == n) + if ((*item_iter).getItem()->getName() == n) { - return (*item_iter); + return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; } -item *pouch::Find(string &n) +itemContainer *pouch::Find(string &n) { - list::iterator item_iter; + list::iterator item_iter; item_iter = items.begin(); while (item_iter != items.end()) { - if ((*item_iter)->getName() == n) + if ((*item_iter).getItem()->getName() == n) { - return (*item_iter); + return &(*item_iter); } - item_iter++; + ++item_iter; } return NULL; } -void pouch::addItem(item *i) +itemContainer *pouch::addItem(item *i) { - items.push_front(i); + if (count >= 3000 || count >= maxitems) + { + return NULL; + } + itemContainer it(i), *temp; + items.push_front(it); + ++count; + temp = &items.front(); + sort(); + return temp; } -void pouch::deleteItem(item *i) +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) { - list::iterator item_iter; + itemContainer it(i); + items.push_front(it); + ++count; + return &items.front(); +} +void pouch::deleteItem(item *i) +{ + list::iterator item_iter; + count--; + item_iter = find(items.begin(), items.end(), i); if (item_iter != items.end())