Index: /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc
===================================================================
--- /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	(revision 7184)
+++ /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.cc	(revision 7185)
@@ -80,7 +80,8 @@
     _ConsoleCommand::_ConsoleCommandManipulator test(_ModifyConsoleCommand("BaseObject", "setName").setFunction(&BaseObject::setActive));
 
-    _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
-    {
-        this->state_ = state;
+    _ConsoleCommand::_ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized) : Executor(functor, name), functionHeader_(functor->getHeaderIdentifier())
+    {
+        this->bActive_ = true;
+        this->bInitialized_ = bInitialized;
         _ConsoleCommand::registerCommand(group, name, this);
     }
@@ -110,85 +111,48 @@
     }
 
-    void _ConsoleCommand::setActive(bool bActive)
-    {
-        if (bActive)
-        {
-            if (this->state_ == State::Inactive)
-                this->state_ = State::Active;
-            else if (this->state_ == State::UninitializedInactive)
-                this->state_ = State::UninitializedActive;
-        }
-        else
-        {
-            if (this->state_ == State::Active)
-                this->state_ = State::Inactive;
-            else if (this->state_ == State::UninitializedActive)
-                this->state_ = State::UninitializedInactive;
-        }
-    }
-
-    void _ConsoleCommand::setInitialized(bool bInitialized)
-    {
-        if (bInitialized)
-        {
-            if (this->state_ == State::UninitializedActive)
-                this->state_ = State::Active;
-            else if (this->state_ == State::UninitializedInactive)
-                this->state_ = State::Inactive;
-        }
-        else
-        {
-            if (this->state_ == State::Active)
-                this->state_ = State::UninitializedActive;
-            else if (this->state_ == State::Inactive)
-                this->state_ = State::UninitializedInactive;
-        }
-    }
-
-    void _ConsoleCommand::setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode)
+    bool _ConsoleCommand::setFunctor(Functor* functor, bool bForce)
     {
         if (!functor)
         {
-            this->setInitialized(false);
-            return;
-        }
-
-        if (!this->functionHeaderMatches(functor))
+            this->bInitialized_ = false;
+            return true;
+        }
+
+        if (!bForce && !this->functionHeaderMatches(functor))
         {
             COUT(1) << "Error: Couldn't assign new function to console command with name \"" << this->getName() << "\", headers don't match." << std::endl;
-            return;
-        }
-
-        switch (mode)
-        {
-            default:
-            case _ConsoleCommand::ObjectPointer::Null:
-            {
-                this->functor_ = functor;
-            }
-            break;
-
-            case _ConsoleCommand::ObjectPointer::RawCopy:
-            {
-                void* object = (this->functor_) ? this->functor_->getRawObjectPointer() : 0;
-
-                this->functor_ = functor;
-
-                if (!this->functor_->getBaseObject())
-                    this->functor_->setRawObjectPointer(object);
-            }
-            break;
-
-            case _ConsoleCommand::ObjectPointer::CastViaBaseObject:
-            {
-                BaseObject* object = (this->functor_) ? this->functor_->getBaseObject() : 0;
-
-                this->functor_ = functor;
-
-                if (!this->functor_->getBaseObject())
-                    this->functor_->setBaseObject(object);
-            }
-            break;
-        }
+            return false;
+        }
+
+        this->functor_ = functor;
+        this->bInitialized_ = true;
+        return true;
+    }
+
+    void _ConsoleCommand::pushFunctor(Functor* functor, bool bForce)
+    {
+        Functor* oldfunctor = this->getFunctor();
+
+        if (this->setFunctor(functor, bForce));
+            this->functorStack_.push(oldfunctor);
+    }
+
+    void _ConsoleCommand::popFunctor()
+    {
+        Functor* newfunctor = 0;
+        if (!this->functorStack_.empty())
+        {
+            newfunctor = this->functorStack_.top();
+            this->functorStack_.pop();
+        }
+        this->setFunctor(newfunctor);
+    }
+
+    Functor* _ConsoleCommand::getFunctor() const
+    {
+        if (this->bInitialized_)
+            return this->functor_;
+        else
+            return 0;
     }
 
@@ -198,7 +162,7 @@
         {
             assert(false);
-            return false;
-        }
-        return (functor->getHeaderIdentifier() == this->functor_->getHeaderIdentifier());
+            return true;
+        }
+        return (functor->getHeaderIdentifier() == this->functionHeader_);
     }
 
@@ -207,10 +171,36 @@
         if (this->functor_)
             this->functor_->setRawObjectPointer(object);
-    }
-
-    void _ConsoleCommand::setObject(BaseObject* object)
+        else if (object)
+            COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
+    }
+
+    void _ConsoleCommand::pushObject(void* object)
     {
         if (this->functor_)
-            this->functor_->setBaseObject(object);
+        {
+            this->objectStack_.push(this->getObject());
+            this->setObject(object);
+        }
+        else
+            COUT(0) << "Error: Can't set object in console command \"" << this->getName() << "\", no functor set." << std::endl;
+    }
+
+    void _ConsoleCommand::popObject()
+    {
+        void* newobject = 0;
+        if (!this->objectStack_.empty())
+        {
+            newobject = this->objectStack_.top();
+            this->objectStack_.pop();
+        }
+        this->setObject(newobject);
+    }
+
+    void* _ConsoleCommand::getObject() const
+    {
+        if (this->functor_)
+            return this->functor_->getRawObjectPointer();
+        else
+            return 0;
     }
 
Index: /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h
===================================================================
--- /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	(revision 7184)
+++ /code/branches/consolecommands3/src/libraries/core/ConsoleCommand.h	(revision 7185)
@@ -32,4 +32,5 @@
 #include "CorePrereqs.h"
 
+#include <stack>
 #include <boost/preprocessor/cat.hpp>
 #include <boost/preprocessor/facilities/expand.hpp>
@@ -179,5 +180,5 @@
 
 #define _DeclareConsoleCommandGeneric(group, name, functionpointer) \
-    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), orxonox::_ConsoleCommand::State::UninitializedActive))
+    orxonox::_ConsoleCommand& BOOST_PP_CAT(__consolecommand_, __LINE__) = (*orxonox::_createConsoleCommand(group, name, orxonox::createFunctor(functionpointer), false))
 
 
@@ -193,25 +194,4 @@
 
         public:
-            struct State
-            {
-                enum Enum
-                {
-                    UninitializedActive,
-                    UninitializedInactive,
-                    Active,
-                    Inactive
-                };
-            };
-
-            struct ObjectPointer
-            {
-                enum Enum
-                {
-                    Null,
-                    RawCopy,
-                    CastViaBaseObject
-                };
-            };
-
             struct _ConsoleCommandManipulator
             {
@@ -220,28 +200,20 @@
 
                     template <class F>
-                    inline _ConsoleCommandManipulator& setFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
-                        { if (this->command_) { this->command_->setFunctor(createFunctor(function), mode); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(F function, bool bForce = false)
+                        { if (this->command_) { this->command_->setFunctor(createFunctor(function), bForce); } return *this; }
                     template <class F, class O>
-                    inline _ConsoleCommandManipulator& setFunction(F function, O* object)
-                        { if (this->command_) { this->command_->setFunctor(createFunctor(function, object)); } return *this; }
-                    inline _ConsoleCommandManipulator& setFunction(Functor* functor)
-                        { if (this->command_) { this->command_->setFunctor(functor); } return *this; }
-                    inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommand* command)
-                        { if (this->command_) { this->command_->setFunctor(command->functor_); } return *this; }
-                    inline _ConsoleCommandManipulator& setFunction(const _ConsoleCommandManipulator& manipulator)
-                        { if (this->command_) { this->command_->setFunctor(manipulator.command_->functor_); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(F function, O* object, bool bForce = false)
+                        { if (this->command_) { this->command_->setFunctor(createFunctor(function, object), bForce); } return *this; }
+                    inline _ConsoleCommandManipulator& setFunction(Functor* functor, bool bForce = false)
+                        { if (this->command_) { this->command_->setFunctor(functor, bForce); } return *this; }
 
                     template <class F>
-                    inline _ConsoleCommandManipulator& pushFunction(F function, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null)
-                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function), mode); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(F function, bool bForce = false)
+                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function), bForce); } return *this; }
                     template <class F, class O>
-                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object)
-                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object)); } return *this; }
-                    inline _ConsoleCommandManipulator& pushFunction(Functor* functor)
-                        { if (this->command_) { this->command_->pushFunctor(functor); } return *this; }
-                    inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommand* command)
-                        { if (this->command_) { this->command_->pushFunctor(command->functor_); } return *this; }
-                    inline _ConsoleCommandManipulator& pushFunction(const _ConsoleCommandManipulator& manipulator)
-                        { if (this->command_) { this->command_->pushFunctor(manipulator.command_->functor_); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(F function, O* object, bool bForce = false)
+                        { if (this->command_) { this->command_->pushFunctor(createFunctor(function, object), bForce); } return *this; }
+                    inline _ConsoleCommandManipulator& pushFunction(Functor* functor, bool bForce = false)
+                        { if (this->command_) { this->command_->pushFunctor(functor, bForce); } return *this; }
 
                     inline _ConsoleCommandManipulator& popFunction()
@@ -250,6 +222,11 @@
                     inline _ConsoleCommandManipulator& setObject(void* object)
                         { if (this->command_) { this->command_->setObject(object); } return *this; }
-                    inline _ConsoleCommandManipulator& setObject(BaseObject* object)
-                        { if (this->command_) { this->command_->setObject(object); } return *this; }
+                    inline _ConsoleCommandManipulator& pushObject(void* object)
+                        { if (this->command_) { this->command_->pushObject(object); } return *this; }
+                    inline _ConsoleCommandManipulator& popObject()
+                        { if (this->command_) { this->command_->popObject(); } return *this; }
+
+                    inline void* getObject() const
+                        { if (this->command_) { return this->command_->getObject(); } else { return 0; } }
 
                     inline _ConsoleCommandManipulator& setActive(bool bActive)
@@ -261,5 +238,5 @@
 
         public:
-            _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, State::Enum state = State::Active);
+            _ConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true);
 
             _ConsoleCommand& addShortcut();
@@ -268,9 +245,11 @@
             _ConsoleCommand& addGroup(const std::string& group, const std::string&  name);
 
-            void setActive(bool bActive);
-            inline State::Enum getState() const
-                { return this->state_; }
+            inline void setActive(bool bActive)
+                { this->bActive_ = bActive; }
             inline bool isActive() const
-                { return (this->state_ == State::Active); }
+                { return (this->bActive_ && this->bInitialized_); }
+
+            inline _ConsoleCommandManipulator getManipulator() const
+                { return this; }
 
             static inline const std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommands()
@@ -281,33 +260,35 @@
             static const _ConsoleCommand* getCommand(const std::string& group, const std::string& name, bool bPrintError = false);
 
-            inline _ConsoleCommandManipulator getManipulator() const
-                { return this; }
-
         private:
             static std::map<std::string, std::map<std::string, _ConsoleCommand*> >& getCommandMap();
             static void registerCommand(const std::string& group, const std::string& name, _ConsoleCommand* command);
 
-            void setInitialized(bool bInitialized);
-
-            void setFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
-            void pushFunctor(Functor* functor, _ConsoleCommand::ObjectPointer::Enum mode = _ConsoleCommand::ObjectPointer::Null);
+            bool setFunctor(Functor* functor, bool bForce = false);
+            void pushFunctor(Functor* functor, bool bForce = false);
             void popFunctor();
+            Functor* getFunctor() const;
+
             bool functionHeaderMatches(Functor* functor) const;
 
             void setObject(void* object);
-            void setObject(BaseObject* object);
-
-            State::Enum state_;
+            void pushObject(void* object);
+            void popObject();
+            void* getObject() const;
+
+            bool bActive_;
+            bool bInitialized_;
             const std::type_info& functionHeader_;
+            std::stack<Functor*> functorStack_;
+            std::stack<void*> objectStack_;
     };
 
-    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
-    {
-        return new _ConsoleCommand("", name, functor, state);
-    }
-
-    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, _ConsoleCommand::State::Enum state = _ConsoleCommand::State::Active)
-    {
-        return new _ConsoleCommand(group, name, functor, state);
+    inline _ConsoleCommand* _createConsoleCommand(const std::string& name, Functor* functor, bool bInitialized = true)
+    {
+        return new _ConsoleCommand("", name, functor, bInitialized);
+    }
+
+    inline _ConsoleCommand* _createConsoleCommand(const std::string& group, const std::string& name, Functor* functor, bool bInitialized = true)
+    {
+        return new _ConsoleCommand(group, name, functor, bInitialized);
     }
 }
Index: /code/branches/consolecommands3/src/libraries/core/Functor.h
===================================================================
--- /code/branches/consolecommands3/src/libraries/core/Functor.h	(revision 7184)
+++ /code/branches/consolecommands3/src/libraries/core/Functor.h	(revision 7185)
@@ -38,5 +38,4 @@
 #include "util/Debug.h"
 #include "util/MultiType.h"
-#include "BaseObject.h"
 
 namespace orxonox
@@ -116,8 +115,4 @@
             virtual void evaluateParam(unsigned int index, MultiType& param) const = 0;
 
-            virtual void setBaseObject(BaseObject* object) {}
-            virtual void setBaseObject(const BaseObject* object) {}
-            virtual BaseObject* getBaseObject() const { return 0; }
-
             virtual void setRawObjectPointer(void* object) {}
             virtual void* getRawObjectPointer() const { return 0; }
@@ -183,24 +178,4 @@
             }
 
-            void setBaseObject(BaseObject* object)
-            {
-                this->object_ = dynamic_cast<T*>(object);
-                this->constObject_ = 0;
-            }
-
-            void setBaseObject(const BaseObject* object)
-            {
-                this->object_ = 0;
-                this->constObject_ = dynamic_cast<const T*>(object);
-            }
-
-            BaseObject* getBaseObject() const
-            {
-                if (this->object_)
-                    return upcast<BaseObject*>(this->object_);
-                else
-                    return const_cast<BaseObject*>(upcast<const BaseObject*>(this->constObject_));
-            }
-
             void setRawObjectPointer(void* object)
             {
@@ -237,5 +212,5 @@
 
 
-    template <int r, class R, class P1, class P2, class P3, class P4, class P5>
+    template <class R, class P1, class P2, class P3, class P4, class P5>
     struct FunctorHeaderIdentifier {};
 
@@ -354,10 +329,10 @@
 
 #define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES(returnvalue, numparams) FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES##numparams(returnvalue)
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES0(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), void, void, void, void, void>
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES1(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, void, void, void, void>
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES2(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, void, void, void>
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES3(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, void, void>
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES4(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, void>
-#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES5(returnvalue) <returnvalue, FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, P5>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES0(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), void, void, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES1(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, void, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES2(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, void, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES3(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, void, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES4(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, void>
+#define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES5(returnvalue) <FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue), P1, P2, P3, P4, P5>
 
 #define FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE(returnvalue) FUNCTOR_HEADER_IDENTIFIER_TEMPLATE_CLASSES_RETURNVALUE##returnvalue
