Index: code/trunk/src/core/BaseObject.h
===================================================================
--- code/trunk/src/core/BaseObject.h	(revision 1841)
+++ code/trunk/src/core/BaseObject.h	(revision 2087)
@@ -37,4 +37,6 @@
 #define _BaseObject_H__
 
+#include <map>
+
 #include "CorePrereqs.h"
 
@@ -42,14 +44,16 @@
 #include "OrxonoxClass.h"
 #include "XMLIncludes.h"
+#include "Event.h"
 
 namespace orxonox
 {
+    class Scene;
+    class Gametype;
+
     //! The BaseObject is the parent of all classes representing an instance in the game.
     class _CoreExport BaseObject : virtual public OrxonoxClass
     {
-        friend class WorldEntity;
-
         public:
-            BaseObject();
+            BaseObject(BaseObject* creator);
             virtual ~BaseObject();
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
@@ -59,7 +63,9 @@
 
             /** @brief Sets the name of the object. @param name The name */
-            inline void setName(const std::string& name) { this->name_ = name; this->changedName(); }
-            /** @brief Returns the name of the object. @return The name */
+            inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); }
+            /** @brief Returns the name of the object. */
             inline const std::string& getName() const { return this->name_; }
+            /** @brief Returns the old name of the object. */
+            inline const std::string& getOldName() const { return this->oldName_; }
             /** @brief This function gets called if the name of the object changes. */
             virtual void changedName() {}
@@ -79,12 +85,48 @@
             virtual void changedVisibility() {}
 
-            /** @brief Sets a pointer to the level that loaded this object. @param level The pointer to the level */
-            inline void setLevel(const Level* level) { this->level_ = level; }
-            /** @brief Returns a pointer to the level that loaded this object. @return The level */
-            inline const Level* getLevel() const { return this->level_; }
-            const std::string& getLevelfile() const;
+            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
+            inline void setFile(const XMLFile* file) { this->file_ = file; }
+            /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */
+            inline const XMLFile* getFile() const { return this->file_; }
+            const std::string& getFilename() const;
+
+            void addTemplate(const std::string& name);
+            void addTemplate(Template* temp);
+            /** @brief Returns the set of all aplied templates. */
+            inline const std::set<Template*>& getTemplates() const
+                { return this->templates_; }
 
             virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
             inline Namespace* getNamespace() const { return this->namespace_; }
+
+            inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
+            inline BaseObject* getCreator() const { return this->creator_; }
+
+            inline void setScene(Scene* scene) { this->scene_ = scene; }
+            inline Scene* getScene() const { return this->scene_; }
+
+            inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
+            inline Gametype* getGametype() const { return this->gametype_; }
+            inline Gametype* getOldGametype() const { return this->oldGametype_; }
+            virtual inline void changedGametype() {}
+
+            void fireEvent();
+            void fireEvent(bool activate);
+            void fireEvent(bool activate, BaseObject* originator);
+            void fireEvent(Event& event);
+
+            virtual void processEvent(Event& event);
+
+            inline void registerEventListener(BaseObject* object, const std::string& sectionname)
+                { this->eventListeners_[object] = sectionname; }
+            inline void unregisterEventListener(BaseObject* object)
+                { this->eventListeners_.erase(object); }
+
+            void addEvent(BaseObject* event, const std::string& sectionname);
+            void removeEvent(BaseObject* event);
+            BaseObject* getEvent(unsigned int index) const;
+
+            void addEventContainer(const std::string& sectionname, EventContainer* container);
+            EventContainer* getEventContainer(const std::string& sectionname) const;
 
             /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
@@ -93,12 +135,26 @@
             inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }
 
-        private:
+        protected:
             std::string name_;                          //!< The name of the object
-            bool bInitialized_;                         //!< True if the object was initialized (passed the object registration)
+            std::string oldName_;                       //!< The old name of the object
             bool bActive_;                              //!< True = the object is active
             bool bVisible_;                             //!< True = the object is visible
-            const Level* level_;                        //!< The level that loaded this object
-            std::string loaderIndentation_;             //!< Indentation of the debug output in the Loader
-            Namespace* namespace_;
+
+        private:
+            void setXMLName(const std::string& name);
+            Template* getTemplate(unsigned int index) const;
+
+            bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
+            const XMLFile*        file_;                 //!< The XMLFile that loaded this object
+            std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
+            Namespace*            namespace_;
+            BaseObject*           creator_;
+            Scene*                scene_;
+            Gametype*             gametype_;
+            Gametype*             oldGametype_;
+            std::set<Template*>   templates_;
+            std::map<BaseObject*, std::string> eventListeners_;
+            std::list<BaseObject*> events_;
+            std::map<std::string, EventContainer*> eventContainers_;
     };
 
@@ -106,4 +162,5 @@
     SUPER_FUNCTION(2, BaseObject, changedActivity, false);
     SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
+    SUPER_FUNCTION(4, BaseObject, processEvent, false);
 }
 
