Index: code/branches/console/src/core/ArgumentCompleter.h
===================================================================
--- code/branches/console/src/core/ArgumentCompleter.h	(revision 1430)
+++ code/branches/console/src/core/ArgumentCompleter.h	(revision 1430)
@@ -0,0 +1,81 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _ArgumentCompleter_H__
+#define _ArgumentCompleter_H__
+
+#include <list>
+#include <string>
+
+#include "CorePrereqs.h"
+
+namespace orxonox
+{
+    class _CoreExport ArgumentCompleter
+    {
+        public:
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (void)) : paramCount_(0), function_0_(function) {}
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1)) : paramCount_(1), function_1_(function) {}
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2)) : paramCount_(2), function_2_(function) {}
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3)) : paramCount_(3), function_3_(function) {}
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4)) : paramCount_(4), function_4_(function) {}
+            ArgumentCompleter(std::list<std::pair<std::string, std::string> > (*function) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)) : paramCount_(5), function_5_(function) {}
+
+            std::list<std::pair<std::string, std::string> > operator()(const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "")
+            {
+                switch (this->paramCount_)
+                {
+                    case 0:
+                        return (*this->function_0_)();
+                    case 1:
+                        return (*this->function_1_)(param1);
+                    case 2:
+                        return (*this->function_2_)(param1, param2);
+                    case 3:
+                        return (*this->function_3_)(param1, param2, param3);
+                    case 4:
+                        return (*this->function_4_)(param1, param2, param3, param4);
+                    case 5:
+                        return (*this->function_5_)(param1, param2, param3, param4, param5);
+                    default:
+                        return (*this->function_0_)();
+                }
+            }
+
+        private:
+            unsigned char paramCount_;
+            std::list<std::pair<std::string, std::string> > (*function_0_) (void);
+            std::list<std::pair<std::string, std::string> > (*function_1_) (const std::string& param1);
+            std::list<std::pair<std::string, std::string> > (*function_2_) (const std::string& param1, const std::string& param2);
+            std::list<std::pair<std::string, std::string> > (*function_3_) (const std::string& param1, const std::string& param2, const std::string& param3);
+            std::list<std::pair<std::string, std::string> > (*function_4_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4);
+            std::list<std::pair<std::string, std::string> > (*function_5_) (const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5);
+    };
+}
+
+#endif /* _ArgumentCompleter_H__ */
Index: code/branches/console/src/core/ArgumentCompletionFunctions.cc
===================================================================
--- code/branches/console/src/core/ArgumentCompletionFunctions.cc	(revision 1429)
+++ code/branches/console/src/core/ArgumentCompletionFunctions.cc	(revision 1430)
@@ -35,8 +35,7 @@
     namespace autocompletion
     {
-        std::list<std::pair<std::string, std::string> > fallback()
+        ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(fallback)()
         {
-            static std::list<std::pair<std::string, std::string> > list(1, std::pair<std::string, std::string>("muh", "MUH"));
-            return list;
+            return std::list<std::pair<std::string, std::string> >();
         }
     }
Index: code/branches/console/src/core/ArgumentCompletionFunctions.h
===================================================================
--- code/branches/console/src/core/ArgumentCompletionFunctions.h	(revision 1429)
+++ code/branches/console/src/core/ArgumentCompletionFunctions.h	(revision 1430)
@@ -33,9 +33,26 @@
 #include <string>
 
+#include "ArgumentCompleter.h"
+#include "CorePrereqs.h"
+
+
+#define ARGUMENT_COMPLETION_FUNCTION_DECLARATION(functionname) \
+    ArgumentCompleter* functionname(); \
+    _CoreExport std::list<std::pair<std::string, std::string> > acf_##functionname
+
+#define ARGUMENT_COMPLETION_FUNCTION_IMPLEMENTATION(functionname) \
+    ArgumentCompleter* functionname() \
+    { \
+        static ArgumentCompleter completer = ArgumentCompleter(&acf_##functionname); \
+        return &completer; \
+    } \
+    \
+    std::list<std::pair<std::string, std::string> > acf_##functionname
+
 namespace orxonox
 {
     namespace autocompletion
     {
-        std::list<std::pair<std::string, std::string> > fallback();
+        ARGUMENT_COMPLETION_FUNCTION_DECLARATION(fallback)();
     }
 }
Index: code/branches/console/src/core/CommandEvaluation.cc
===================================================================
--- code/branches/console/src/core/CommandEvaluation.cc	(revision 1429)
+++ code/branches/console/src/core/CommandEvaluation.cc	(revision 1430)
@@ -110,10 +110,10 @@
                     {
                         if (this->function_->getParamCount() == 0)
-                            return /*CommandExecutor::complete*/(this->command_ = this->function_->getName());
+                            return (this->command_ = this->function_->getName());
                         else
-                            return /*CommandExecutor::complete*/(this->command_ = this->function_->getName() + " ");
+                            return (this->command_ = this->function_->getName() + " ");
                     }
                     else if (this->functionclass_)
-                        return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " ");
+                        return (this->command_ = this->functionclass_->getName() + " ");
                     break;
                 case CS_Function:
@@ -121,7 +121,7 @@
                     {
                         if (this->function_->getParamCount() == 0)
-                            return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName());
+                            return (this->command_ = this->functionclass_->getName() + " " + this->function_->getName());
                         else
-                            return /*CommandExecutor::complete*/(this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");
+                            return (this->command_ = this->functionclass_->getName() + " " + this->function_->getName() + " ");
                     }
                     break;
@@ -129,4 +129,7 @@
                 case CS_Params:
                 {
+                    if (this->argument_ == "" && this->possibleArgument_ == "")
+                        break;
+
                     unsigned int maxIndex = this->commandTokens_.size();
                     if (this->command_[this->command_.size() - 1] != ' ')
@@ -142,5 +145,5 @@
                     }
 
-                    return /*CommandExecutor::complete*/(this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace);
+                    return (this->command_ = this->commandTokens_.subSet(0, maxIndex).join() + " " + this->argument_ + whitespace);
                     break;
                 }
Index: code/branches/console/src/core/CommandExecutor.cc
===================================================================
--- code/branches/console/src/core/CommandExecutor.cc	(revision 1429)
+++ code/branches/console/src/core/CommandExecutor.cc	(revision 1430)
@@ -355,8 +355,9 @@
                 else
                 {
-                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 1;
+                    unsigned int argumentNumber = CommandExecutor::argumentsGiven() - 2;
                     if (CommandExecutor::getEvaluation().functionclass_)
                         argumentNumber -= 1;
 
+std::cout << "arglist: " << CommandExecutor::getLastArgument() << ", " << CommandExecutor::getEvaluation().function_->getName() << ", " << argumentNumber << std::endl;
                     CommandExecutor::createListOfPossibleArguments(CommandExecutor::getLastArgument(), CommandExecutor::getEvaluation().function_, argumentNumber);
                     CommandExecutor::getEvaluation().state_ = CS_Params;
@@ -488,7 +489,9 @@
     void CommandExecutor::createListOfPossibleArguments(const std::string& fragment, ConsoleCommand* command, unsigned int param)
     {
+        CommandExecutor::createArgumentCompletionList(command, param);
+
         CommandExecutor::getEvaluation().listOfPossibleArguments_.clear();
         std::string lowercase = getLowercase(fragment);
-        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
+        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
             if ((*it).first.find(lowercase) == 0 || fragment == "")
                 CommandExecutor::getEvaluation().listOfPossibleArguments_.push_back(std::pair<const std::string*, const std::string*>(&(*it).first, &(*it).second));
@@ -527,6 +530,8 @@
     std::string CommandExecutor::getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param)
     {
+        CommandExecutor::createArgumentCompletionList(command, param);
+
         std::string lowercase = getLowercase(name);
-        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(param); it != command->getArgumentCompletionListEnd(param); ++it)
+        for (std::list<std::pair<std::string, std::string> >::const_iterator it = command->getArgumentCompletionListBegin(); it != command->getArgumentCompletionListEnd(); ++it)
             if ((*it).first == lowercase)
                 return (*it).second;
@@ -535,4 +540,22 @@
     }
 
+    void CommandExecutor::createArgumentCompletionList(ConsoleCommand* command, unsigned int param)
+    {
+        std::string params[5];
+
+        unsigned int index = 0;
+        unsigned int lowestIndex = 1 + (CommandExecutor::getEvaluation().functionclass_ != 0);
+
+        for (unsigned int i = CommandExecutor::argumentsGiven() - 2; i >= lowestIndex; --i)
+        {
+            params[index] = CommandExecutor::getArgument(i);
+            ++index;
+            if (index >= 5)
+                break;
+        }
+
+        command->createArgumentCompletionList(param, params[0], params[1], params[2], params[3], params[4]);
+    }
+
     std::string CommandExecutor::getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list)
     {
Index: code/branches/console/src/core/CommandExecutor.h
===================================================================
--- code/branches/console/src/core/CommandExecutor.h	(revision 1429)
+++ code/branches/console/src/core/CommandExecutor.h	(revision 1430)
@@ -93,4 +93,5 @@
             static std::string getPossibleArgument(const std::string& name, ConsoleCommand* command, unsigned int param);
 
+            static void createArgumentCompletionList(ConsoleCommand* command, unsigned int param);
             static std::string getCommonBegin(const std::list<std::pair<const std::string*, const std::string*> >& list);
             static bool compareStringsInList(const std::pair<const std::string*, const std::string*>& first, const std::pair<const std::string*, const std::string*>& second);
Index: code/branches/console/src/core/ConsoleCommand.cc
===================================================================
--- code/branches/console/src/core/ConsoleCommand.cc	(revision 1429)
+++ code/branches/console/src/core/ConsoleCommand.cc	(revision 1430)
@@ -34,15 +34,15 @@
     {
         this->accessLevel_ = AccessLevel::None;
-        this->autocompletionFunction_[0] = &autocompletion::fallback;
-        this->autocompletionFunction_[1] = &autocompletion::fallback;
-        this->autocompletionFunction_[2] = &autocompletion::fallback;
-        this->autocompletionFunction_[3] = &autocompletion::fallback;
-        this->autocompletionFunction_[4] = &autocompletion::fallback;
+        this->argumentCompleter_[0] = 0;
+        this->argumentCompleter_[1] = 0;
+        this->argumentCompleter_[2] = 0;
+        this->argumentCompleter_[3] = 0;
+        this->argumentCompleter_[4] = 0;
     }
 
-    ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void))
+    ConsoleCommand& ConsoleCommand::setArgumentCompletionList(unsigned int param, ArgumentCompleter* completer)
     {
         if (param < 5)
-            this->autocompletionFunction_[param] = function;
+            this->argumentCompleter_[param] = completer;
         else
         {
@@ -52,32 +52,10 @@
     }
 
-    const std::list<std::pair<std::string, std::string> >& ConsoleCommand::getArgumentCompletionList(unsigned int param)
+    void ConsoleCommand::createArgumentCompletionList(unsigned int param, const std::string& param1, const std::string& param2, const std::string& param3, const std::string& param4, const std::string& param5)
     {
-        if (param < 5)
-            this->argumentList_ = (*this->autocompletionFunction_[param])();
+        if (param < 5 && this->argumentCompleter_[param])
+            this->argumentList_ = (*this->argumentCompleter_[param])(param1, param2, param3, param4, param5);
         else
-            this->argumentList_ = autocompletion::fallback();
-
-        return this->argumentList_;
-    }
-
-    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListBegin(unsigned int param)
-    {
-        if (param < 5)
-            this->argumentList_ = (*this->autocompletionFunction_[param])();
-        else
-            this->argumentList_ = autocompletion::fallback();
-
-        return this->argumentList_.begin();
-    }
-
-    std::list<std::pair<std::string, std::string> >::const_iterator ConsoleCommand::getArgumentCompletionListEnd(unsigned int param)
-    {
-        if (param < 5)
-            this->argumentList_ = (*this->autocompletionFunction_[param])();
-        else
-            this->argumentList_ = autocompletion::fallback();
-
-        return this->argumentList_.end();
+            this->argumentList_.clear();
     }
 }
Index: code/branches/console/src/core/ConsoleCommand.h
===================================================================
--- code/branches/console/src/core/ConsoleCommand.h	(revision 1429)
+++ code/branches/console/src/core/ConsoleCommand.h	(revision 1430)
@@ -43,5 +43,5 @@
 
 #define SetConsoleCommandGeneric(fakevariable, classname, command, bCreateShortcut) \
-    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand((ConsoleCommand*)command, bCreateShortcut)
+    ConsoleCommand& fakevariable = ClassManager<classname>::getIdentifier()->addConsoleCommand(command, bCreateShortcut)
 
 
@@ -53,5 +53,5 @@
 
 #define SetConsoleCommandShortcutGeneric(fakevariable, command) \
-    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut((ConsoleCommand*)command)
+    ConsoleCommand& fakevariable = CommandExecutor::addConsoleCommandShortcut(command)
 
 
@@ -100,13 +100,16 @@
                 { return this->accessLevel_; }
 
-            ConsoleCommand& setArgumentCompletionList(unsigned int param, std::list<std::pair<std::string, std::string> > (*function) (void));
-
-            const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList(unsigned int param);
-            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin(unsigned int param);
-            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd(unsigned int param);
+            ConsoleCommand& setArgumentCompletionList(unsigned int param, ArgumentCompleter* completer);
+            void createArgumentCompletionList(unsigned int param, const std::string& param1 = "", const std::string& param2 = "", const std::string& param3 = "", const std::string& param4 = "", const std::string& param5 = "");
+            const std::list<std::pair<std::string, std::string> >& getArgumentCompletionList() const
+                { return this->argumentList_; }
+            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListBegin() const
+                { return this->argumentList_.begin(); }
+            std::list<std::pair<std::string, std::string> >::const_iterator getArgumentCompletionListEnd() const
+                { return this->argumentList_.end(); }
 
         private:
             AccessLevel::Level accessLevel_;
-            std::list<std::pair<std::string, std::string> > (*autocompletionFunction_[5]) (void);
+            ArgumentCompleter* argumentCompleter_[5];
             std::list<std::pair<std::string, std::string> > argumentList_;
     };
Index: code/branches/console/src/core/CorePrereqs.h
===================================================================
--- code/branches/console/src/core/CorePrereqs.h	(revision 1429)
+++ code/branches/console/src/core/CorePrereqs.h	(revision 1430)
@@ -77,4 +77,5 @@
   typedef std::string LanguageEntryLabel;
 
+  class ArgumentCompleter;
   class BaseFactory;
   class BaseMetaObjectListElement;
