]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/pouch.cpp
Consolidated monster data into a single .dat file
[irc/gameservirc.git] / gameserv / pouch.cpp
index 51306843c0792760e8b35b6ba0f4392fe6648a0f..01964bd4df12bc4f6e43cfd1de1f3c91e790c207 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,14 +14,22 @@ pouch::~pouch()
   clear();
 }
 
-void pouch::sort()
+pouch::pouch(const pouch &p)
 {
-  items.sort();
+  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()
@@ -27,6 +37,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 +69,7 @@ itemContainer *pouch::Find(char *n)
        {
          return &(*item_iter);
        }
-      item_iter++;
+      ++item_iter;
     }
   return NULL;
 }
@@ -54,27 +85,68 @@ 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;
+    }
+  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);
   items.push_front(it);
+  ++count;
   return &items.front();
 }
 
 void pouch::deleteItem(item *i)
 {
   list<itemContainer>::iterator item_iter;
-
-  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)