]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/pouch.cpp
fixed some bugs
[irc/gameservirc.git] / gameserv / pouch.cpp
index 51306843c0792760e8b35b6ba0f4392fe6648a0f..078ff42bce0be65fa41fa780b2d6863b89e9d2d5 100644 (file)
@@ -1,3 +1,4 @@
+#include "extern.h"
 #include "pouch.h"
 #include "item.h"
 #include <list>
@@ -5,6 +6,7 @@
 
 pouch::pouch()
 {
+  count = 0;
 }
 
 pouch::~pouch()
@@ -12,11 +14,6 @@ pouch::~pouch()
   clear();
 }
 
-void pouch::sort()
-{
-  items.sort();
-}
-
 void pouch::clear()
 {
   items.clear();
@@ -27,6 +24,27 @@ bool pouch::isEmpty()
   return items.empty();
 }
 
+void pouch::sort()
+{
+  items.sort();
+}
+
+itemContainer *pouch::Find(int id)
+{
+  list<itemContainer>::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<itemContainer>::iterator item_iter;
@@ -38,7 +56,7 @@ itemContainer *pouch::Find(char *n)
        {
          return &(*item_iter);
        }
-      item_iter++;
+      ++item_iter;
     }
   return NULL;
 }
@@ -54,23 +72,57 @@ itemContainer *pouch::Find(string &n)
         {
           return &(*item_iter);
         }
-      item_iter++;
+      ++item_iter;
     }
 
   return NULL;
 }
 
 itemContainer *pouch::addItem(item *i)
+{
+  if (count >= 3000 || count >= maxitems)
+    {
+      return NULL;
+    }
+  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;
+       }
+
+  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);
   items.push_front(it);
+  ++count;
   return &items.front();
 }
 
 void pouch::deleteItem(item *i)
 {
   list<itemContainer>::iterator item_iter;
-
+  count--;
+  
   item_iter = find(items.begin(), items.end(), i);
   
   if (item_iter != items.end())