Index: trunk/src/util/loading/factory.cc
===================================================================
--- trunk/src/util/loading/factory.cc	(revision 5750)
+++ trunk/src/util/loading/factory.cc	(revision 5982)
@@ -13,13 +13,13 @@
    co-programmer: Benjamin Grauer
 */
-
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_LOADING
 
 #include "factory.h"
 
-#include "shell_command.h"
-#include "game_loader.h"
+//#include "shell_command.h"
+
 using namespace std;
 
-SHELL_COMMAND(create, Factory, fabricate);
+//SHELL_COMMAND(create, Factory, fabricate);
 
 
@@ -39,18 +39,21 @@
   this->setName(factoryName);
 
-  this->next = NULL;
   this->classID = classID;
+  this->className = factoryName;
 
-  Factory::registerFactory(this);
+  if( Factory::factoryList == NULL)
+    Factory::factoryList = new std::list<Factory*>;
+
+  Factory::factoryList->push_back(this);
 }
 
 /** a reference to the First Factory */
-Factory* Factory::first = NULL;
+std::list<Factory*>* Factory::factoryList = NULL;
 
 /**
  *  destructor
-
-   clear the Q
-*/
+ *
+ * clear the Q
+ */
 Factory::~Factory ()
 {
@@ -58,52 +61,96 @@
   //  Factory* tmpDel = this->next;
   //  this->next = NULL;
-  if (this->next)
-    delete this->next;
 }
 
+void Factory::deleteFactories()
+{
+  if (Factory::factoryList != NULL)
+  {
+    while(!Factory::factoryList->empty())
+    {
+      delete Factory::factoryList->front();
+      Factory::factoryList->pop_front();
+    }
+    delete Factory::factoryList;
+    Factory::factoryList = NULL;
+  }
+}
+
+
 /**
- *  add a Factory to the Factory Queue
- * @param factory a Factory to be registered
-*/
-void Factory::registerFactory( Factory* factory)
+ * Compares the Factories Name against a given ClassName
+ * @param className the Name of the Class to Query
+ * @returns true on match, false otherwise.
+ */
+bool Factory::operator==(const char* className) const
 {
-  assert( factory != NULL);
+  return(className != NULL && !strcmp(className, this->className));
+}
 
-  PRINTF(5)("Registered factory for '%s'\n", factory->getName());
 
-  if( Factory::first == NULL)
+BaseObject* Factory::fabricate(const TiXmlElement* root)
+{
+  if (root == NULL || Factory::factoryList == NULL)
+    return NULL;
+
+  std::list<Factory*>::const_iterator factory;
+  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
+    if (*(*factory) == root->Value())
+      break;
+
+  if (factory != Factory::factoryList->end())
   {
-    Factory::first = factory;
+    PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName());
+    return (*factory)->fabricateObject(root);
   }
   else
   {
-    Factory* tmpFac = Factory::first;
-    while( tmpFac->next != NULL)
-    {
-      tmpFac = tmpFac->next;
-    }
-    tmpFac->setNext(factory);
+    PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", root->Value());
+    return NULL;
   }
 }
 
-void Factory::fabricate(const char* className, const char* entityName)
+BaseObject* Factory::fabricate(const char* className)
 {
-  if (className == NULL)
-    return;
-  Factory* fac = Factory::first;
+  if (className == NULL || Factory::factoryList == NULL)
+    return NULL;
 
-  while (fac != NULL)
+  std::list<Factory*>::const_iterator factory;
+  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
+    if (*(*factory) == className)
+      break;
+
+  if (factory != Factory::factoryList->end())
   {
-    if (!strcmp(className, fac->getName()))
-    {
-      PRINTF(3)("Create a new Object of type %s\n", fac->getName());
-      BaseObject* object = fac->fabricateDirect();
-      if (object != NULL)
-      {
-        object->setName(entityName);
-      }
-      break;
-    }
-    fac = fac->next;
+    PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName());
+    return (*factory)->fabricateObject(NULL);
+  }
+  else
+  {
+    PRINTF(2)("Could not Fabricate an Object of Class '%s'\n", className);
+    return NULL;
   }
 }
+
+
+BaseObject* Factory::fabricate(ClassID classID)
+{
+  if (Factory::factoryList == NULL)
+    return NULL;
+
+  std::list<Factory*>::const_iterator factory;
+  for (factory = Factory::factoryList->begin(); factory != Factory::factoryList->end(); factory++)
+    if (*(*factory) == classID)
+      break;
+
+  if (factory != Factory::factoryList->end())
+  {
+    PRINTF(4)("Create a new Object of type %s\n", (*factory)->getName());
+    return (*factory)->fabricateObject(NULL);
+  }
+  else
+  {
+    PRINTF(2)("Could not Fabricate an Object of ClassID '%h'\n", classID);
+    return NULL;
+  }
+}
