Index: code/branches/objecthierarchy/src/core/CMakeLists.txt
===================================================================
--- code/branches/objecthierarchy/src/core/CMakeLists.txt	(revision 1958)
+++ code/branches/objecthierarchy/src/core/CMakeLists.txt	(revision 1959)
@@ -6,8 +6,8 @@
   GameState.cc
   Language.cc
+  Luabind.cc
   ObjectListBase.cc
   OrxonoxClass.cc
   RootGameState.cc
-  Script.cc
 
   # command
@@ -62,5 +62,5 @@
     tolua_orxonox
     tolua/tolua.pkg
-    Script.h
+    LuaBind.h
     CommandExecutor.h
   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
Index: code/branches/objecthierarchy/src/core/Loader.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Loader.cc	(revision 1958)
+++ code/branches/objecthierarchy/src/core/Loader.cc	(revision 1959)
@@ -34,5 +34,5 @@
 #include "ObjectList.h"
 #include "CoreIncludes.h"
-#include "Script.h"
+#include "LuaBind.h"
 #include "Namespace.h"
 #include "util/Debug.h"
@@ -119,9 +119,5 @@
 
         // let Lua work this out:
-        //Script* lua;
-        /*Script::loadFile(level->getFile(), true);
-        Script::init(Script::getLuaState());
-        Script::run();*/
-        Script* lua = Script::getInstance();
+        LuaBind* lua = LuaBind::getInstance();
         lua->clearLuaOutput();
         lua->loadFile(level->getFile(), true);
Index: code/branches/objecthierarchy/src/core/LuaBind.cc
===================================================================
--- code/branches/objecthierarchy/src/core/LuaBind.cc	(revision 1959)
+++ code/branches/objecthierarchy/src/core/LuaBind.cc	(revision 1959)
@@ -0,0 +1,291 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "LuaBind.h"
+
+#include <fstream>
+#include <map>
+
+#include "lua/lua.hpp"
+#include "tolua/tolua++.h"
+#include "tolua/tolua_bind.h"
+#include "util/String.h"
+#include "CoreIncludes.h"
+
+namespace orxonox
+{
+  LuaBind* LuaBind::singletonRef = NULL;
+
+  LuaBind::LuaBind()
+  {
+    luaState_ = lua_open();
+    luaSource_ = "";
+#if LUA_VERSION_NUM == 501
+    luaL_openlibs(luaState_);
+#else
+    luaopen_base(luaState_);
+    luaopen_string(luaState_);
+    luaopen_table(luaState_);
+    luaopen_math(luaState_);
+    luaopen_io(luaState_);
+    luaopen_debug(luaState_);
+#endif
+    tolua_Core_open(luaState_);
+    output_ = "";
+    isRunning_ = false;
+  }
+
+  void LuaBind::luaPrint(std::string str)
+  {
+    output_ += str;
+//    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
+    COUT(5) << str;
+  }
+
+  /**
+      @brief Loads the specified file line by line
+      @param filename The filename of the file
+      @param luaTags if true, the loaded file gets stripped off luaTags
+  */
+  void LuaBind::loadFile(std::string filename, bool luaTags)
+  {
+    output_ = "";
+    std::ifstream file;
+    file.open(filename.c_str(), std::fstream::in);
+
+    if (!file.is_open())
+    {
+      // some error msg
+    }
+
+    char line[1024];
+    std::string levelString = "";
+
+    while (file.good() && !file.eof())
+    {
+      file.getline(line, 1024);
+      levelString += line;
+      levelString += "\n";
+    }
+
+    file.close();
+    //std::string output;
+
+    if (luaTags) luaSource_ = replaceLuaTags(levelString);
+    COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl;
+  }
+
+  void LuaBind::loadString(std::string code)
+  {
+    luaSource_ = code;
+    output_ = "";
+  }
+
+#if LUA_VERSION_NUM != 501
+  const char * LuaBind::lua_Chunkreader(lua_State *L, void *data, size_t *size)
+  {
+    LoadS* ls = ((LoadS*)data);
+    if (ls->size == 0) return NULL;
+    *size = ls->size;
+    ls->size = 0;
+    return ls->s;
+  }
+#endif
+  void LuaBind::run()
+  {
+    if (!isRunning_)
+    {
+      isRunning_ = true;
+      int error = 0;
+      std::string init = "local scr = orxonox.LuaBind:getInstance()\nlocal debug = print\nprint = function(s)\nscr:luaPrint(s)\nend\ninclude = function(f)\nfile = io.open(f)\ncontent = file:read(\"*a\")\nfile:close()\nsource = scr:replaceLuaTags(content)\ndebug(source)\nassert(loadstring(source))()\nend\n";
+      init += luaSource_;
+  #if LUA_VERSION_NUM == 501
+      error = luaL_loadstring(luaState_, init.c_str());
+  #else
+      LoadS ls;
+      ls.s = init.c_str();
+      ls.size = init.size();
+      error = lua_load(luaState_, &orxonox::LuaBind::lua_Chunkreader, &ls, init.c_str());
+  #endif
+      if (error == 0)
+      {
+        error = lua_pcall(luaState_, 0, 0, 0);
+      }
+      if (error != 0)
+      {
+        COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
+      }
+      isRunning_ = false;
+    }
+    else
+    {
+      COUT(2) << "Warning: Lua's run is called while running!" << std::endl;
+    }
+  }
+
+  std::string LuaBind::replaceLuaTags(const std::string& text)
+  {
+    // chreate map with all Lua tags
+    std::map<size_t, bool> luaTags;
+    {
+      size_t pos = 0;
+      while ((pos = text.find("<?lua", pos)) != std::string::npos)
+        luaTags[pos++] = true;
+    }
+    {
+      size_t pos = 0;
+      while ((pos = text.find("?>", pos)) != std::string::npos)
+        luaTags[pos++] = false;
+    }
+
+    // erase all tags from the map that are between two quotes
+    {
+      std::map<size_t, bool>::iterator it = luaTags.begin();
+      std::map<size_t, bool>::iterator it2 = it;
+      bool bBetweenQuotes = false;
+      size_t pos = 0;
+      while ((pos = getNextQuote(text, pos)) != std::string::npos)
+      {
+        while ((it != luaTags.end()) && (it->first < pos))
+        {
+          if (bBetweenQuotes) {
+            it2++;
+            if(it->second && !(it2->second) && it2->first < pos)
+              it = ++it2;
+            else
+              luaTags.erase(it++);
+          }
+          else
+            ++it;
+        }
+        bBetweenQuotes = !bBetweenQuotes;
+        pos++;
+      }
+    }
+
+    // check whether on every opening <?lua tag a closing ?> tag follows
+    {
+      bool expectedValue = true;
+      for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
+      {
+        if (it->second == expectedValue)
+          expectedValue = !expectedValue;
+        else
+        {
+          expectedValue = false;
+          break;
+        }
+      }
+      if (!expectedValue) {
+        COUT(2) << "Warning: Error in level file" << std::endl;
+        // todo: errorhandling
+        return "";
+      }
+    }
+
+    // cut the original string into pieces and put them together with print() instead of lua tags
+    std::string output;
+    {
+      std::map<size_t, bool>::iterator it = luaTags.begin();
+      bool bInPrintFunction = true;
+      size_t start = 0;
+      size_tend = 0;
+
+      do
+      {
+        if (it != luaTags.end())
+          end = (*(it++)).first;
+        else
+          end = std::string::npos;
+
+        unsigned int equalSignCounter = 0;
+
+        if (bInPrintFunction)
+        {
+          // count ['='[ and ]'='] and replace tags with print([[ and ]])
+          std::string temp = text.substr(start, end - start);
+          {
+            size_t pos = 0;
+            while ((pos = temp.find('[', pos)) != std::string::npos)
+            {
+              unsigned int tempCounter = 1;
+              size_t tempPos = pos++;
+              while(temp[++tempPos] == '=') {
+                tempCounter++;
+              }
+              if(temp[tempPos] != '[') {
+                tempCounter = 0;
+              }
+              else if(tempCounter == 0) {
+                tempCounter = 1;
+              }
+              if (tempCounter > equalSignCounter)
+                equalSignCounter = tempCounter;
+            }
+          }
+          {
+            size_t pos = 0;
+            while ((pos = temp.find(']', pos)) != std::string::npos)
+            {
+              unsigned int tempCounter = 1;
+              size_t tempPos = pos++;
+              while(temp[++tempPos] == '=') {
+                tempCounter++;
+              }
+              if(temp[tempPos] != ']') {
+                tempCounter = 0;
+              }
+              else if(tempCounter == 0) {
+                tempCounter = 1;
+              }
+              if (tempCounter > equalSignCounter)
+                equalSignCounter = tempCounter;
+            }
+          }
+          std::string equalSigns = "";
+          for(unsigned int i = 0; i < equalSignCounter; i++) {
+            equalSigns += "=";
+          }
+          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
+          start = end + 5;
+        }
+        else
+        {
+          output += text.substr(start, end - start);
+          start = end + 2;
+        }
+
+        bInPrintFunction = !bInPrintFunction;
+      }
+      while (end != std::string::npos);
+    }
+
+    return output;
+  }
+
+}
Index: code/branches/objecthierarchy/src/core/LuaBind.h
===================================================================
--- code/branches/objecthierarchy/src/core/LuaBind.h	(revision 1959)
+++ code/branches/objecthierarchy/src/core/LuaBind.h	(revision 1959)
@@ -0,0 +1,92 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+ @file
+ @brief Representation of an interface to lua
+ @author Benjamin Knecht <beni_at_orxonox.net>
+ */
+
+#ifndef _LuaBind_H__
+#define _LuaBind_H__
+
+#include "CorePrereqs.h"
+
+extern "C" {
+#include <lua/lua.h>
+}
+
+#include <list>
+#include <string>
+
+namespace orxonox // tolua_export
+{ // tolua_export
+  class _CoreExport LuaBind
+  {
+  /*
+  class LuaBind { // tolua_export
+  */
+    struct LoadS {
+      const char *s;
+      size_t size;
+    };
+
+    public:
+      inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
+      inline ~LuaBind() { LuaBind::singletonRef = NULL; };
+
+    void loadFile(std::string filename, bool luaTags);
+    void loadString(std::string code);
+    //void init(lua_State *state_);
+    //void xmlToLua();
+    void run();
+    void luaPrint(std::string str); // tolua_export
+
+#if LUA_VERSION_NUM != 501
+    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
+#endif
+
+    inline lua_State* getLuaState() { return luaState_; };
+    inline std::string getLuaOutput() { return output_; };
+    //inline std::string* getFileString() { return &fileString_; };
+    inline void clearLuaOutput() { output_ = ""; }
+
+    std::string replaceLuaTags(const std::string& text); // tolua_export
+
+    private:
+      LuaBind();
+      static LuaBind* singletonRef;
+
+      std::string luaSource_;
+      std::string output_;
+      lua_State* luaState_;
+      bool isRunning_;
+
+  }; // tolua_export
+} // tolua_export
+#endif /* _LuaBind_H__ */
Index: code/branches/objecthierarchy/src/core/Script.cc
===================================================================
--- code/branches/objecthierarchy/src/core/Script.cc	(revision 1958)
+++ 	(revision )
@@ -1,274 +1,0 @@
-/*
- *   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:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-#include "Script.h"
-
-#include <fstream>
-#include <map>
-
-#include "CoreIncludes.h"
-
-#include "util/String.h"
-
-#include "lua/lua.hpp"
-
-#include "tolua/tolua++.h"
-#include "tolua/tolua_bind.h"
-
-namespace orxonox
-{
-  Script* Script::singletonRef = NULL;
-
-  Script::Script()
-  {
-    luaState_ = lua_open();
-    luaSource_ = "";
-#if LUA_VERSION_NUM == 501
-    luaL_openlibs(luaState_);
-#else
-    luaopen_base(luaState_);
-    luaopen_string(luaState_);
-    luaopen_table(luaState_);
-    luaopen_math(luaState_);
-    luaopen_io(luaState_);
-    luaopen_debug(luaState_);
-#endif
-    tolua_Core_open(luaState_);
-    output_ = "";
-  }
-
-  void Script::luaPrint(std::string str)
-  {
-    output_ += str;
-//    COUT(4) << "Lua_output!:" << std::endl << str << std::endl << "***" << std::endl;
-    COUT(5) << str;
-  }
-
-  /**
-      @brief Loads the specified file line by line
-      @param filename The filename of the file
-      @param luaTags if true, the loaded file gets stripped off luaTags
-  */
-  void Script::loadFile(std::string filename, bool luaTags)
-  {
-    std::ifstream file;
-    file.open(filename.c_str(), std::fstream::in);
-
-    if (!file.is_open())
-    {
-      // some error msg
-    }
-
-    char line[1024];
-    std::string levelString = "";
-
-    while (file.good() && !file.eof())
-    {
-      file.getline(line, 1024);
-      levelString += line;
-      levelString += "\n";
-    }
-
-    file.close();
-    //std::string output;
-
-    if (luaTags) luaSource_ = replaceLuaTags(levelString);
-    COUT(5) << "ParsedSourceCode: " << luaSource_ << std::endl;
-  }
-
-#if LUA_VERSION_NUM != 501
-  const char * Script::lua_Chunkreader(lua_State *L, void *data, size_t *size)
-  {
-    LoadS* ls = ((LoadS*)data);
-    if (ls->size == 0) return NULL;
-    *size = ls->size;
-    ls->size = 0;
-    return ls->s;
-  }
-#endif
-  void Script::run()
-  {
-    int error = 0;
-    std::string init = "local scr = orxonox.Script:getInstance()\nprint = function(s)\nscr:luaPrint(s)\nend\n";
-    init += luaSource_;
-#if LUA_VERSION_NUM == 501
-    error = luaL_loadstring(luaState_, init.c_str());
-#else
-    LoadS ls;
-    ls.s = init.c_str();
-    ls.size = init.size();
-    error = lua_load(luaState_, &orxonox::Script::lua_Chunkreader, &ls, init.c_str());
-#endif
-    if (error == 0)
-      error = lua_pcall(luaState_, 0, 0, 0);
-    if (error != 0)
-    {
-      COUT(2) << "Error in Lua-script: " << lua_tostring(luaState_, -1) << std::endl;
-    }
-  }
-
-  std::string Script::replaceLuaTags(const std::string& text)
-  {
-    // chreate map with all Lua tags
-    std::map<size_t, bool> luaTags;
-    {
-      size_t pos = 0;
-      while ((pos = text.find("<?lua", pos)) != std::string::npos)
-        luaTags[pos++] = true;
-    }
-    {
-      size_t pos = 0;
-      while ((pos = text.find("?>", pos)) != std::string::npos)
-        luaTags[pos++] = false;
-    }
-
-    // erase all tags from the map that are between two quotes
-    {
-      std::map<size_t, bool>::iterator it = luaTags.begin();
-      std::map<size_t, bool>::iterator it2 = it;
-      bool bBetweenQuotes = false;
-      size_t pos = 0;
-      while ((pos = getNextQuote(text, pos)) != std::string::npos)
-      {
-        while ((it != luaTags.end()) && (it->first < pos))
-        {
-          if (bBetweenQuotes) {
-            it2++;
-            if(it->second && !(it2->second) && it2->first < pos)
-              it = ++it2;
-            else
-              luaTags.erase(it++);
-          }
-          else
-            ++it;
-        }
-        bBetweenQuotes = !bBetweenQuotes;
-        pos++;
-      }
-    }
-
-    // check whether on every opening <?lua tag a closing ?> tag follows
-    {
-      bool expectedValue = true;
-      for (std::map<size_t, bool>::iterator it = luaTags.begin(); it != luaTags.end(); ++it)
-      {
-        if (it->second == expectedValue)
-          expectedValue = !expectedValue;
-        else
-        {
-          expectedValue = false;
-          break;
-        }
-      }
-      if (!expectedValue) {
-        // todo: errorhandling
-        return "";
-      }
-    }
-
-    // cut the original string into pieces and put them together with print() instead of lua tags
-    std::string output;
-    {
-      std::map<size_t, bool>::iterator it = luaTags.begin();
-      bool bInPrintFunction = true;
-      size_t start = 0;
-      size_t end = 0;
-
-      do
-      {
-        if (it != luaTags.end())
-          end = (*(it++)).first;
-        else
-          end = std::string::npos;
-
-        unsigned int equalSignCounter = 0;
-
-        if (bInPrintFunction)
-        {
-          // count ['='[ and ]'='] and replace tags with print([[ and ]])
-          std::string temp = text.substr(start, end - start);
-          {
-            size_t pos = 0;
-            while ((pos = temp.find('[', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              size_t tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != '[') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          {
-            size_t pos = 0;
-            while ((pos = temp.find(']', pos)) != std::string::npos)
-            {
-              unsigned int tempCounter = 1;
-              size_t tempPos = pos++;
-              while(temp[++tempPos] == '=') {
-                tempCounter++;
-              }
-              if(temp[tempPos] != ']') {
-                tempCounter = 0;
-              }
-              else if(tempCounter == 0) {
-                tempCounter = 1;
-              }
-              if (tempCounter > equalSignCounter)
-                equalSignCounter = tempCounter;
-            }
-          }
-          std::string equalSigns = "";
-          for(unsigned int i = 0; i < equalSignCounter; i++) {
-            equalSigns += "=";
-          }
-          output += "print([" + equalSigns + "[" + temp + "]" + equalSigns +"])";
-          start = end + 5;
-        }
-        else
-        {
-          output += text.substr(start, end - start);
-          start = end + 2;
-        }
-
-        bInPrintFunction = !bInPrintFunction;
-      }
-      while (end != std::string::npos);
-    }
-
-    return output;
-  }
-
-}
Index: code/branches/objecthierarchy/src/core/Script.h
===================================================================
--- code/branches/objecthierarchy/src/core/Script.h	(revision 1958)
+++ 	(revision )
@@ -1,90 +1,0 @@
-/*
- *   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:
- *      Benjamin Knecht
- *   Co-authors:
- *      ...
- *
- */
-
-/**
- @file
- @brief Representation of an interface to lua
- @author Benjamin Knecht <beni_at_orxonox.net>
- */
-
-#ifndef _Script_H__
-#define _Script_H__
-
-#include "CorePrereqs.h"
-
-extern "C" {
-#include "lua/lua.h"
-}
-
-#include <list>
-#include <string>
-
-namespace orxonox // tolua_export
-{ // tolua_export
-  class _CoreExport Script
-  /*
-  class Script { // tolua_export
-  */
-  {
-    struct LoadS {
-      const char *s;
-      size_t size;
-    };
-
-    public:
-      inline static Script* getInstance() { if (!Script::singletonRef) Script::singletonRef = new Script(); return Script::singletonRef; } // tolua_export
-      inline ~Script() { Script::singletonRef = NULL; };
-
-    void loadFile(std::string filename, bool luaTags);
-    //void init(lua_State *state_);
-    //void xmlToLua();
-    void run();
-    void luaPrint(std::string str); // tolua_export
-
-#if LUA_VERSION_NUM != 501
-    static const char * lua_Chunkreader(lua_State *L, void *data, size_t *size);
-#endif
-
-    inline lua_State* getLuaState() { return luaState_; };
-    inline std::string getLuaOutput() { return output_; };
-    //inline std::string* getFileString() { return &fileString_; };
-    inline void clearLuaOutput() { output_ = ""; }
-
-    std::string replaceLuaTags(const std::string& text);
-
-    private:
-      Script();
-      static Script* singletonRef;
-
-      std::string luaSource_;
-      std::string output_;
-      lua_State* luaState_;
-
-  }; // tolua_export
-} // tolua_export
-#endif /* _Script_H__ */
Index: code/branches/objecthierarchy/src/core/tolua/tolua.pkg
===================================================================
--- code/branches/objecthierarchy/src/core/tolua/tolua.pkg	(revision 1958)
+++ code/branches/objecthierarchy/src/core/tolua/tolua.pkg	(revision 1959)
@@ -1,2 +1,2 @@
-$cfile "../../src/core/Script.h"
+$cfile "../../src/core/LuaBind.h"
 $cfile "../../src/core/CommandExecutor.h"
Index: code/branches/objecthierarchy/src/orxonox/CMakeLists.txt
===================================================================
--- code/branches/objecthierarchy/src/orxonox/CMakeLists.txt	(revision 1958)
+++ code/branches/objecthierarchy/src/orxonox/CMakeLists.txt	(revision 1959)
@@ -54,4 +54,7 @@
   objects/Tickable.cc
   objects/Test.cc
+  objects/Script.cc
+  objects/Trigger.cc
+  objects/DistanceTrigger.cc
 
   objects/infos/Info.cc
@@ -74,5 +77,6 @@
   WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib
 )
-	
+
+
 ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} )
 
Index: code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.cc
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.cc	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.cc	(revision 1959)
@@ -0,0 +1,125 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "DistanceTrigger.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox {
+
+  CreateFactory(DistanceTrigger);
+
+  DistanceTrigger::DistanceTrigger()
+  {
+    RegisterObject(DistanceTrigger);
+
+    targetMask_.exclude(Class(BaseObject));
+  }
+
+  DistanceTrigger::~DistanceTrigger()
+  {
+  }
+
+  void DistanceTrigger::addTarget(Ogre::Node* targetNode)
+  {
+    this->targetSet_.insert(targetNode);
+  }
+
+  void DistanceTrigger::removeTarget(Ogre::Node* targetNode)
+  {
+    int returnval = this->targetSet_.erase(targetNode);
+    if (returnval == 0)
+    {
+      COUT(2) << "Warning: Node " << targetNode << " did not exist in targetSet of trigger " << this << " !" << std::endl;
+      COUT(4) << "Content of targetSet of trigger " << this << " :" << std::endl;
+      std::set<Ogre::Node*>::iterator it;
+      for(it = this->targetSet_.begin(); it != this->targetSet_.end(); it++)
+      {
+        COUT(4) << *it << std::endl;
+      }
+      COUT(4) << "End of targetSet of trigger " << this << std::endl;
+    }
+  }
+
+  void DistanceTrigger::addTargets(std::string targets)
+  {
+    Identifier* targetId = ID(targets);
+    targetMask_.include(targetId);
+    // trigger shouldn't react on itself or other triggers
+    targetMask_.exclude(Class(Trigger), true);
+
+  }
+
+  void DistanceTrigger::removeTargets(std::string targets)
+  {
+    Identifier* targetId = ID(targets);
+    targetMask_.exclude(targetId);
+  }
+
+  bool DistanceTrigger::checkDistance()
+  {
+    // Iterate through all WorldEntities
+    for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; it++)
+    {
+      // check if WorldEntity is a target
+      if(targetMask_.isIncluded(it->getIdentifier()))
+      {
+        Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition();
+        if (distanceVec.length() < this->distance_)
+        {
+          return true;
+        }
+      }
+    }
+    return false;
+
+  }
+
+  void DistanceTrigger::setDistance(float dist)
+  {
+    this->distance_ = dist;
+  }
+
+  void DistanceTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+  {
+    Trigger::XMLPort(xmlelement, mode);
+
+    XMLPortParamLoadOnly(DistanceTrigger, "distance", setDistance, xmlelement, mode);
+    XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode);
+  }
+
+  bool DistanceTrigger::isTriggered(TriggerMode mode)
+  {
+    if(Trigger::isTriggered(mode))
+      return checkDistance();
+    else
+      return false;
+  }
+}
Index: code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.h
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.h	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/DistanceTrigger.h	(revision 1959)
@@ -0,0 +1,67 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _DistanceTrigger_H__
+#define _DistanceTrigger_H__
+
+#include "Trigger.h"
+
+#include <set>
+
+#include <OgreNode.h>
+
+#include "core/ClassTreeMask.h"
+#include "core/BaseObject.h"
+
+namespace orxonox {
+
+  class _OrxonoxExport DistanceTrigger : public Trigger
+  {
+    public:
+      DistanceTrigger();
+      ~DistanceTrigger();
+      void addTarget(Ogre::Node* targetNode);
+      void removeTarget(Ogre::Node* targetNode);
+      void addTargets(std::string targets);
+      void removeTargets(std::string targets);
+      void setDistance(float dist);
+      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+      bool checkDistance();
+
+    protected:
+      bool isTriggered(TriggerMode mode);
+
+    private:
+      ClassTreeMask targetMask_;
+      std::set<Ogre::Node*> targetSet_;
+      float distance_;
+  };
+
+}
+
+#endif /* _Trigger_H__ */
Index: code/branches/objecthierarchy/src/orxonox/objects/Script.cc
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/Script.cc	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/Script.cc	(revision 1959)
@@ -0,0 +1,70 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "Script.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/LuaBind.h"
+#include "core/Debug.h"
+
+namespace orxonox
+{
+  CreateFactory(Script);
+
+  Script::Script()
+  {
+    RegisterObject(Script);
+
+    code_ = "";
+  }
+
+  Script::~Script()
+  {
+  }
+
+  /**
+  @brief XML loading and saving.
+  @param xmlelement The XML-element
+  @param loading Loading (true) or saving (false)
+   */
+  void Script::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+  {
+    BaseObject::XMLPort(xmlelement, mode);
+
+    code_ = xmlelement.GetText(false);
+  }
+
+  void Script::execute()
+  {
+    LuaBind* lua = LuaBind::getInstance();
+    lua->loadString(this->code_);
+    lua->run();
+  }
+}
Index: code/branches/objecthierarchy/src/orxonox/objects/Script.h
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/Script.h	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/Script.h	(revision 1959)
@@ -0,0 +1,51 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Script_H__
+#define _Script_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/BaseObject.h"
+
+namespace orxonox
+{
+  class _OrxonoxExport Script : public BaseObject
+  {
+    public:
+      Script();
+      ~Script();
+      void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+      void execute();
+
+    private:
+      std::string code_;
+  };
+}
+
+#endif /* _Script_H__ */
Index: code/branches/objecthierarchy/src/orxonox/objects/Trigger.cc
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/Trigger.cc	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/Trigger.cc	(revision 1959)
@@ -0,0 +1,290 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "Trigger.h"
+
+#include <OgreBillboard.h>
+#include "core/Debug.h"
+#include "core/CoreIncludes.h"
+#include "core/ConsoleCommand.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+
+  ConsoleCommand(Trigger, setVisibility, AccessLevel::Debug, false).setDefaultValues(0);
+
+  CreateFactory(Trigger);
+
+  Trigger::Trigger()
+  {
+    RegisterObject(Trigger);
+
+    mode_ = TM_EventTriggerAND;
+    bActive_ = false;
+    bInvertMode_ = false;
+    delay_ = 0.0;
+    bTriggered_ = false;
+    bUpdating_ = false;
+    remainingActivations_ = -1;
+    bStayOn_ = false;
+    latestState_ = 0x0;
+
+    debugBillboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 0.0, 0.0), 1);
+    this->getNode()->attachObject(debugBillboard_.getBillboardSet());
+  }
+
+  Trigger::~Trigger()
+  {
+  }
+
+  void Trigger::init()
+  {
+    this->setVisibility(true);
+    timeSinceLastEvent_ = delay_;
+  }
+
+  void Trigger::setVisibility(bool bVisible)
+  {
+    if(bVisible)
+      this->setScale(2,2,2);
+    else
+      this->setScale(0,0,0);
+  }
+
+  const Trigger* Trigger::getTrigger(unsigned int index) const
+  {
+    if (children_.size() <= index)
+      return NULL;
+
+    std::set<Trigger*>::iterator it;
+    it = children_.begin();
+
+    for ( unsigned int i = 0; i != index; i++ )
+    {
+      it++;
+    }
+    return *it;
+  }
+
+  void Trigger::tick(float dt)
+  {
+
+    bool newTriggered;
+    newTriggered = this->isTriggered();
+
+    // check if new triggering event is really new
+    if((this->latestState_ & 0x1) != newTriggered)
+    {
+      // create new state
+      if(newTriggered)
+      {
+        latestState_ |= 1; // set trigger bit
+        this->switchState();
+      }
+      else
+      {
+        latestState_ &= 0xFE; // set trigger bit
+        if (this->bStayOn_)
+          this->storeState();
+        else
+          this->switchState();
+      }
+    }
+
+    if(remainingTime_ > 0.0)
+    {
+      remainingTime_ -= dt;
+      // only increase when acctually waiting for a state in the queue
+      if(timeSinceLastEvent_ >= 0.0)
+        timeSinceLastEvent_ += dt;
+    }
+
+    while(remainingTime_ <= 0.0 && stateChanges_.size() > 0)
+    {
+      // time ran out, change state to new one
+      char newState = stateChanges_.front().second;
+      bTriggered_ = (newState & 0x1);
+      bActive_ = newState & 2;
+      this->stateChanges_.pop();
+      if(stateChanges_.size() != 0)
+        remainingTime_ = stateChanges_.front().first;
+      else
+        timeSinceLastEvent_ = delay_;
+    }
+
+
+
+    if (bTriggered_ && bActive_)
+      this->setBillboardColour(ColourValue(0.5, 1.0, 0.0));
+    else if (!bTriggered_ && bActive_)
+      this->setBillboardColour(ColourValue(0.0, 1.0, 0.0));
+    else if (bTriggered_ && !bActive_)
+      this->setBillboardColour(ColourValue(1.0, 0.5, 0.0));
+    else
+      this->setBillboardColour(ColourValue(1.0, 0.0, 0.0));
+    bUpdating_ = false;
+  }
+
+  void Trigger::setBillboardColour(ColourValue colour)
+  {
+    this->debugBillboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
+  }
+
+  void Trigger::storeState()
+  {
+    // put state change into queue
+    this->stateChanges_.push(std::pair<float,char>(timeSinceLastEvent_, latestState_));
+    // reset time since last event
+    timeSinceLastEvent_ = 0.0;
+
+    if(this->stateChanges_.size() == 1)
+      remainingTime_ = stateChanges_.front().first;
+  }
+
+  bool Trigger::isTriggered(TriggerMode mode)
+  {
+    if(bUpdating_)
+      return bTriggered_;
+
+    if( children_.size() != 0 )
+    {
+      bUpdating_ = true;
+      bool returnval = false;
+      switch(mode)
+      {
+        case TM_EventTriggerAND:
+          returnval = checkAnd();
+          break;
+        case TM_EventTriggerOR:
+          returnval = checkOr();
+          break;
+        case TM_EventTriggerXOR:
+          returnval = checkXor();
+          break;
+        default:
+          returnval = false;
+          break;
+      }
+      if(bInvertMode_)
+        return !returnval;
+      else
+        return returnval;
+    }
+    return true;
+  }
+
+  void Trigger::setDelay(float delay)
+  {
+    this->delay_ = delay;
+  }
+
+  void Trigger::setMode(std::string modeName)
+  {
+    if (modeName == "and")
+      setMode(TM_EventTriggerAND);
+    else if (modeName == "or")
+      setMode(TM_EventTriggerOR);
+    else if (modeName == "xor")
+      setMode(TM_EventTriggerXOR);
+  }
+
+  void Trigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+  {
+    WorldEntity::XMLPort(xmlelement, mode);
+
+    XMLPortParamLoadOnly(Trigger, "delay", setDelay, xmlelement, mode);
+    XMLPortParamLoadOnly(Trigger, "stayOn", setStayOn, xmlelement, mode);
+    XMLPortParamLoadOnly(Trigger, "activations", setActivations, xmlelement, mode);
+    XMLPortParamLoadOnly(Trigger, "invert", setInvert, xmlelement, mode);
+    //XMLPortParamLoadOnlyTemplate(Trigger, "mode", setMode, xmlelement, mode, std::string);
+
+    XMLPortObject(Trigger, Trigger, "", addTrigger, getTrigger, xmlelement, mode, false, true);
+
+    this->init();
+  }
+
+  void Trigger::addTrigger(Trigger* trig)
+  {
+    if (this != trig)
+      this->children_.insert(trig);
+  }
+
+  bool Trigger::switchState()
+  {
+    if ( remainingActivations_ <= -1 || this->latestState_ & 2 || remainingActivations_ > 0)
+    {
+      this->latestState_ ^= 2; // toggle state bit
+      // increase activation count
+      if (this->latestState_ & 2) remainingActivations_--;
+      this->storeState();
+
+      return true;
+    }
+    return false;
+  }
+
+
+  bool Trigger::checkAnd()
+  {
+    std::set<Trigger*>::iterator it;
+    for(it = this->children_.begin(); it != this->children_.end(); it++)
+    {
+      if(!((*it)->isActive()))
+        return false;
+    }
+    return true;
+  }
+
+  bool Trigger::checkOr()
+  {
+    std::set<Trigger*>::iterator it;
+    for(it = this->children_.begin(); it != this->children_.end(); it++)
+    {
+      if((*it)->isActive())
+        return true;
+    }
+    return false;
+  }
+
+  bool Trigger::checkXor()
+  {
+    std::set<Trigger*>::iterator it;
+    bool test = false;
+    for(it = this->children_.begin(); it != this->children_.end(); it++)
+    {
+      if(test && (*it)->isActive())
+        return false;
+      if((*it)->isActive())
+        test = true;
+    }
+    return test;
+  }
+
+}
Index: code/branches/objecthierarchy/src/orxonox/objects/Trigger.h
===================================================================
--- code/branches/objecthierarchy/src/orxonox/objects/Trigger.h	(revision 1959)
+++ code/branches/objecthierarchy/src/orxonox/objects/Trigger.h	(revision 1959)
@@ -0,0 +1,102 @@
+/*
+ *   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:
+ *      Benjamin Knecht
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _Trigger_H__
+#define _Trigger_H__
+
+#include <set>
+#include <queue>
+
+#include "OrxonoxPrereqs.h"
+
+#include "WorldEntity.h"
+
+#include "../tools/BillboardSet.h"
+
+namespace orxonox {
+
+  enum TriggerMode
+  {
+    TM_EventTriggerAND,
+    TM_EventTriggerOR,
+    TM_EventTriggerXOR,
+  };
+
+  class _OrxonoxExport Trigger : public WorldEntity
+  {
+    public:
+      Trigger();
+      ~Trigger();
+
+      inline bool isActive() { return bActive_; }
+      void addTrigger(Trigger* trig);
+      void setInvert(int invert) { bInvertMode_ = invert; }
+      const Trigger* getTrigger(unsigned int index) const;
+      void setVisibility(bool bVisible);
+      void setDelay(float delay);
+      bool switchState();
+      virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+      inline TriggerMode getMode() { return mode_; }
+      inline void setMode(TriggerMode mode) { this->mode_ = mode; }
+      void setMode(std::string modeName);
+      inline void setStayOn(int stayOn) { if (stayOn == 1) this->bStayOn_ = true; else this->bStayOn_ = false; }
+      inline void setActivations(int activations) { this->remainingActivations_ = activations; }
+      void tick(float dt);
+
+    private:
+      void init();
+      bool checkAnd();
+      bool checkOr();
+      bool checkXor();
+      void setBillboardColour(ColourValue colour);
+      void storeState();
+
+    protected:
+      inline bool isTriggered() { return this->isTriggered(this->mode_); }
+      virtual bool isTriggered(TriggerMode mode);
+
+    private:
+      std::set<Trigger*> children_;
+      std::queue<std::pair<float,char> > stateChanges_;
+      float remainingTime_;
+      float timeSinceLastEvent_;
+      TriggerMode mode_;
+      bool bActive_;
+      bool bInvertMode_;
+      bool bTriggered_;
+      bool bUpdating_;
+      BillboardSet debugBillboard_;
+      float delay_;
+      int remainingActivations_;
+      bool bStayOn_;
+      char latestState_;
+  };
+
+}
+
+#endif /* _Trigger_H__ */
