Index: code/trunk/src/orxonox/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/CMakeLists.txt	(revision 5808)
+++ code/trunk/src/orxonox/CMakeLists.txt	(revision 5929)
@@ -25,18 +25,19 @@
 
 SET_SOURCE_FILES(ORXONOX_SRC_FILES
+  Level.cc
+  LevelManager.cc
   Main.cc
-
-  CameraManager.cc
-  LevelManager.cc
   PawnManager.cc
   PlayerManager.cc
-
-  Level.cc
   Radar.cc
+COMPILATION_BEGIN SceneCompilation.cc
+  CameraManager.cc
   Scene.cc
+COMPILATION_END
 )
 
 ADD_SUBDIRECTORY(collisionshapes)
 ADD_SUBDIRECTORY(controllers)
+ADD_SUBDIRECTORY(gamestates)
 ADD_SUBDIRECTORY(gametypes)
 ADD_SUBDIRECTORY(graphics)
Index: code/trunk/src/orxonox/CameraManager.cc
===================================================================
--- code/trunk/src/orxonox/CameraManager.cc	(revision 5808)
+++ code/trunk/src/orxonox/CameraManager.cc	(revision 5929)
@@ -26,4 +26,5 @@
  *
  */
+
 #include "CameraManager.h"
 
@@ -34,6 +35,8 @@
 #include "util/StringUtils.h"
 #include "core/GameMode.h"
+#include "core/GraphicsManager.h"
 #include "core/GUIManager.h"
 #include "core/ObjectList.h"
+#include "core/ScopedSingletonManager.h"
 #include "tools/Shader.h"
 #include "graphics/Camera.h"
@@ -43,20 +46,20 @@
 {
     CameraManager* CameraManager::singletonPtr_s = 0;
+    ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
 
-    CameraManager::CameraManager(Ogre::Viewport* viewport)
-        : viewport_(viewport)
+    CameraManager::CameraManager()
+        : viewport_(GraphicsManager::getInstance().getViewport())
     {
-        this->fallbackCamera_ = 0;
+        assert(GameMode::showsGraphics());
     }
 
     CameraManager::~CameraManager()
     {
-        if (this->fallbackCamera_)
-            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
+        GUIManager::getInstance().setCamera(0);
     }
 
     Camera* CameraManager::getActiveCamera() const
     {
-        if (this->cameraList_.size() > 0)
+        if (!this->cameraList_.empty())
             return this->cameraList_.front();
         else
@@ -66,23 +69,16 @@
     void CameraManager::requestFocus(Camera* camera)
     {
-        if (!GameMode::showsGraphics())
-            return;
-
         // notify old camera (if it exists)
-        if (this->cameraList_.size() > 0)
+        if (!this->cameraList_.empty())
             this->cameraList_.front()->removeFocus();
-        else if (this->fallbackCamera_)
-        {
-            this->fallbackCamera_->getSceneManager()->destroyCamera(this->fallbackCamera_);
-            this->fallbackCamera_ = 0;
-        }
 
         camera->setFocus();
 
         // make sure we don't add it twice
-        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end(); ++it)
+        for (std::list<Camera*>::iterator it = this->cameraList_.begin(); it != this->cameraList_.end();)
             if ((*it) == camera)
-                return;
-
+                this->cameraList_.erase(it++);
+            else
+                ++it;
         // add to list
         this->cameraList_.push_front(camera);
@@ -91,9 +87,6 @@
     void CameraManager::releaseFocus(Camera* camera)
     {
-        if (!GameMode::showsGraphics())
-            return;
-
         // notify the cam of releasing the focus
-        if (this->cameraList_.front() == camera)
+        if (!this->cameraList_.empty() && this->cameraList_.front() == camera)
         {
             camera->removeFocus();
@@ -101,18 +94,9 @@
 
             // set new focus if possible
-            if (this->cameraList_.size() > 0)
+            if (!this->cameraList_.empty())
                 this->cameraList_.front()->setFocus();
-            else
-            {
-                // there are no more cameras, create a fallback
-                if (!this->fallbackCamera_)
-                    this->fallbackCamera_ = camera->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
-                this->useCamera(this->fallbackCamera_);
-            }
         }
         else
-        {
             this->cameraList_.remove(camera);
-        }
     }
 
Index: code/trunk/src/orxonox/CameraManager.h
===================================================================
--- code/trunk/src/orxonox/CameraManager.h	(revision 5808)
+++ code/trunk/src/orxonox/CameraManager.h	(revision 5929)
@@ -42,12 +42,14 @@
 #include "util/OgreForwardRefs.h"
 #include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+#include "core/SmartPtr.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport CameraManager : public Singleton<CameraManager>
+    class _OrxonoxExport CameraManager : public Singleton<CameraManager>, public OrxonoxClass
     {
             friend class Singleton<CameraManager>;
         public:
-            CameraManager(Ogre::Viewport* viewport);
+            CameraManager();
             ~CameraManager();
 
@@ -66,5 +68,4 @@
             std::list<Camera*>    cameraList_;
             Ogre::Viewport*       viewport_;
-            Ogre::Camera*         fallbackCamera_;
 
             static CameraManager* singletonPtr_s;
Index: code/trunk/src/orxonox/Level.cc
===================================================================
--- code/trunk/src/orxonox/Level.cc	(revision 5808)
+++ code/trunk/src/orxonox/Level.cc	(revision 5929)
@@ -30,5 +30,4 @@
 
 #include "util/Math.h"
-#include "core/Core.h"
 #include "core/CoreIncludes.h"
 #include "core/Loader.h"
@@ -40,5 +39,4 @@
 #include "gametypes/Gametype.h"
 #include "overlays/OverlayGroup.h"
-#include "sound/SoundBase.h"
 #include "LevelManager.h"
 
@@ -53,4 +51,5 @@
         this->registerVariables();
         this->xmlfilename_ = this->getFilename();
+        this->xmlfile_ = 0;
     }
 
@@ -64,7 +63,4 @@
             if (this->xmlfile_)
                 Loader::unload(this->xmlfile_);
-
-            if(this->ambientsound_ != NULL)
-                delete this->ambientsound_;
         }
     }
@@ -76,6 +72,4 @@
         XMLPortParam(Level, "description", setDescription, getDescription, xmlelement, mode);
         XMLPortParam(Level, "gametype", setGametypeString, getGametypeString, xmlelement, mode).defaultValues("Gametype");
-
-        XMLPortParamLoadOnly(Level, "ambientsound", loadAmbientSound, xmlelement, mode);
 
         XMLPortObjectExtended(Level, BaseObject, "", addObject, getObject, xmlelement, mode, true, false);
@@ -116,10 +110,6 @@
             this->gametype_ = gametype;
 
-std::cout << "Load Gametype: " << this->gametype_ << std::endl;
-
         Gametype* rootgametype = orxonox_cast<Gametype*>(identifier->fabricate(this));
         this->setGametype(rootgametype);
-
-std::cout << "root gametype: " << rootgametype->getIdentifier()->getName() << std::endl;
 
         for (std::list<BaseObject*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)
@@ -149,19 +139,4 @@
     }
 
-    void Level::loadAmbientSound(const std::string& filename)
-    {
-        if(filename == "") return;
-        else
-        {
-            if(this->ambientsound_ == NULL)
-            {
-                this->ambientsound_ = new SoundBase();
-            }
-
-            this->ambientsound_->loadFile(filename);
-            this->ambientsound_->play(true);
-        }
-    }
-
     void Level::playerEntered(PlayerInfo* player)
     {
Index: code/trunk/src/orxonox/Level.h
===================================================================
--- code/trunk/src/orxonox/Level.h	(revision 5808)
+++ code/trunk/src/orxonox/Level.h	(revision 5929)
@@ -53,6 +53,4 @@
                 { return this->description_; }
 
-            void loadAmbientSound(const std::string& filename);
-
             void playerEntered(PlayerInfo* player);
             void playerLeft(PlayerInfo* player);
@@ -73,6 +71,4 @@
             XMLFile*               xmlfile_;
             std::list<BaseObject*> objects_;
-
-            SoundBase*             ambientsound_;
     };
 }
Index: code/trunk/src/orxonox/LevelManager.cc
===================================================================
--- code/trunk/src/orxonox/LevelManager.cc	(revision 5808)
+++ code/trunk/src/orxonox/LevelManager.cc	(revision 5929)
@@ -34,10 +34,9 @@
 #include "core/CommandLine.h"
 #include "core/ConfigValueIncludes.h"
-#include "core/Core.h"
 #include "core/CoreIncludes.h"
 #include "core/Loader.h"
+#include "core/ScopedSingletonManager.h"
 #include "PlayerManager.h"
 #include "Level.h"
-#include "infos/HumanPlayer.h"
 
 namespace orxonox
@@ -46,4 +45,5 @@
 
     LevelManager* LevelManager::singletonPtr_s = 0;
+    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
 
     LevelManager::LevelManager()
Index: code/trunk/src/orxonox/Main.cc
===================================================================
--- code/trunk/src/orxonox/Main.cc	(revision 5808)
+++ code/trunk/src/orxonox/Main.cc	(revision 5929)
@@ -31,11 +31,9 @@
 @file
 @brief
-    The main function of Orxonox.
+    The main function of Orxonox (but not the entry point of the program!)
 */
 
 #include "OrxonoxPrereqs.h"
-#include "SpecialConfig.h"
 
-#include "util/Exception.h"
 #include "core/CommandLine.h"
 #include "core/Game.h"
@@ -50,4 +48,5 @@
 SetCommandLineSwitch(dedicated).information("Start in dedicated server mode");
 SetCommandLineSwitch(standalone).information("Start in standalone mode");
+SetCommandLineSwitch(dedicatedClient).information("Start in dedicated client mode");
 
 DeclareToluaInterface(Orxonox);
@@ -57,5 +56,5 @@
     /**
     @brief
-        Main method. Game starts here (except for static initialisations).
+        Starting point of orxonox (however not the entry point of the program!)
     */
     int main(const std::string& strCmdLine)
@@ -67,11 +66,7 @@
         " graphics"
         "  mainMenu"
-        "  standalone"
+        "  standalone,server,client"
         "   level"
-        "  server"
-        "   level"
-        "  client"
-        "   level"
-        " dedicated"
+        " dedicated,dedicatedClient"
         "  level"
         " ioConsole"
@@ -89,4 +84,6 @@
         else if (CommandLine::getValue("dedicated").getBool())
             Game::getInstance().requestStates("dedicated, level");
+        else if (CommandLine::getValue("dedicatedClient").getBool())
+            Game::getInstance().requestStates("dedicatedClient, level");
         else if (CommandLine::getValue("console").getBool())
             Game::getInstance().requestStates("ioConsole");
Index: code/trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 5808)
+++ code/trunk/src/orxonox/OrxonoxPrereqs.h	(revision 5929)
@@ -28,6 +28,7 @@
 
 /**
-  @file
-  @brief Contains all the necessary forward declarations for all classes and structs.
+@file
+@brief
+    Shared library macros, enums, constants and forward declarations for the orxonox library
 */
 
@@ -36,5 +37,4 @@
 
 #include "OrxonoxConfig.h"
-
 #include "tools/ToolsPrereqs.h"
 
@@ -42,4 +42,5 @@
 // Shared library settings
 //-----------------------------------------------------------------------
+
 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD)
 #  ifdef ORXONOX_SHARED_BUILD
@@ -65,69 +66,73 @@
 {
     class CameraManager;
+    class Level;
     class LevelManager;
     class PawnManager;
     class PlayerManager;
-
-    class Level;
+    class Radar;
     class Scene;
-    class Tickable;
+
+    // collisionshapes
+    class CollisionShape;
+    class CompoundCollisionShape;
+    class WorldEntityCollisionShape;
+
+    // controllers
+    class AIController;
+    class ArtificialController;
+    class Controller;
+    class HumanController;
+    class ScriptController;
+    class WaypointController;
+    class WaypointPatrolController;
+
+    // gametypes
+    class Asteroids;
+    class Deathmatch;
+    class Gametype;
+    class TeamBaseMatch;
+    class TeamDeathmatch;
+    class UnderAttack;
+
+    // graphics
+    class Backlight;
+    class Billboard;
+    class BlinkingBillboard;
+    class Camera;
+    class FadingBillboard;
+    class GlobalShader;
+    class Light;
+    class Model;
+    class ParticleEmitter;
+    class ParticleSpawner;
+
+    // infos
+    class Bot;
+    class GametypeInfo;
+    class HumanPlayer;
+    class Info;
+    class PlayerInfo;
 
     // interfaces
     class GametypeMessageListener;
     class NotificationListener;
-    class PawnListener;
     class PlayerTrigger;
     class RadarListener;
     class RadarViewable;
     class Rewardable;
-    class Teamcolourable;
-
-    // worldentities
-    class WorldEntity;
-    class StaticEntity;
-    class MobileEntity;
-    class ControllableEntity;
-    class MovableEntity;
-
-    // graphics
-    class Model;
-    class Billboard;
-    class BlinkingBillboard;
-    class BigExplosion;
-    class ExplosionChunk;
-    class FadingBillboard;
-    class GlobalShader;
-    class Light;
-    class Backlight;
-    class ParticleEmitter;
-    class ParticleSpawner;
-    class Camera;
-
-    // mixed
-    class SpawnPoint;
-    class TeamSpawnPoint;
-
-    class CameraPosition;
-    class Sublevel;
-    class Radar;
-
-    class Test;
-
-    // pawns
-    class Spectator;
-    class Pawn;
-    class SpaceShip;
-    class TeamBaseMatchBase;
-    class Destroyer;
-
-    // gametypes
-    class Gametype;
-    class Deathmatch;
-    class TeamDeathmatch;
-    class Asteroids;
-    class TeamBaseMatch;
-    class UnderAttack;
-
-    // pickups
+    class TeamColourable;
+
+    // items
+    class Engine;
+    class Item;
+    class MultiStateEngine;
+
+    // overlays
+    class InGameConsole;
+    class Map;
+    class OrxonoxOverlay;
+    class OverlayGroup;
+
+    // pickup
     class BaseItem;
     class DroppedItem;
@@ -139,58 +144,42 @@
     class PickupSpawner;
     class UsableItem;
-
+    // pickup, items
+    class HealthImmediate;
+    class HealthUsable;
     class Jump;
-    class HealthUsable;
-    class PassiveItem;
-
-    // items
-    class Item;
-    class Engine;
-    class MultiStateEngine;
-    class RotatingEngine;
+
+    //sound
+    class AmbientSound;
+    class BaseSound;
+    class SoundManager;
+    class WorldSound;
 
     // weaponsystem
-    class WeaponSystem;
+    class DefaultWeaponmodeLink;
+    class Munition;
+    class Weapon;
+    class WeaponMode;
+    class WeaponPack;
     class WeaponSet;
     class WeaponSlot;
-    class WeaponPack;
-    class Weapon;
-    class WeaponMode;
-    class DefaultWeaponmodeLink;
-    class Munition;
-
-    // controller
-    class Controller;
-    class HumanController;
-    class ArtificialController;
-    class AIController;
-    class ScriptController;
-    class WaypointController;
-    class WaypointPatrolController;
-
-    // infos
-    class Info;
-    class PlayerInfo;
-    class HumanPlayer;
-    class Bot;
-    class GametypeInfo;
-
-    // collision
-    class CollisionShape;
-    class CompoundCollisionShape;
-    class WorldEntityCollisionShape;
-
-    // overlays
-    class OverlayGroup;
-    class OrxonoxOverlay;
-    class Notification;
-    class NotificationManager;
-    class InGameConsole;
-    class Map;
-
-    //sound
-    class SoundBase;
-    class SoundManager;
-    class SoundMainMenu;
+    class WeaponSystem;
+
+    // worldentities
+    class BigExplosion;
+    class CameraPosition;
+    class ControllableEntity;
+    class ExplosionChunk;
+    class MobileEntity;
+    class MovableEntity;
+    class SpawnPoint;
+    class StaticEntity;
+    class TeamSpawnPoint;
+    class WorldEntity;
+    // worldentities, pawns
+    class Destroyer;
+    class Pawn;
+    class SpaceShip;
+    class Spectator;
+    class TeamBaseMatchBase;
 }
 
Index: code/trunk/src/orxonox/PawnManager.cc
===================================================================
--- code/trunk/src/orxonox/PawnManager.cc	(revision 5808)
+++ code/trunk/src/orxonox/PawnManager.cc	(revision 5929)
@@ -57,5 +57,5 @@
         {
             if (!it->isAlive())
-                delete (*(it++));
+                (it++)->destroy();
             else
                 ++it;
@@ -63,5 +63,5 @@
 
         if (count == 0)
-            delete this;
+            this->destroy();
     }
 }
Index: code/trunk/src/orxonox/PlayerManager.cc
===================================================================
--- code/trunk/src/orxonox/PlayerManager.cc	(revision 5808)
+++ code/trunk/src/orxonox/PlayerManager.cc	(revision 5929)
@@ -31,4 +31,5 @@
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
+#include "core/ScopedSingletonManager.h"
 #include "Level.h"
 #include "infos/HumanPlayer.h"
@@ -38,4 +39,5 @@
 {
     PlayerManager* PlayerManager::singletonPtr_s = 0;
+    ManageScopedSingleton(PlayerManager, ScopeID::Root, false);
 
     PlayerManager::PlayerManager()
@@ -74,5 +76,6 @@
         if (GameMode::isMaster())
         {
-            COUT(3) << "client disconnected" << std::endl;
+            if (clientID != 0)
+                COUT(3) << "client disconnected" << std::endl;
 
             // remove from clients-map
@@ -85,5 +88,5 @@
             // delete PlayerInfo instance
             if (player)
-                delete player;
+                player->destroy();
         }
     }
Index: code/trunk/src/orxonox/PlayerManager.h
===================================================================
--- code/trunk/src/orxonox/PlayerManager.h	(revision 5808)
+++ code/trunk/src/orxonox/PlayerManager.h	(revision 5929)
@@ -50,8 +50,8 @@
                 { return this->clients_; }
 
-        private:
             void clientConnected(unsigned int clientID);
             void clientDisconnected(unsigned int clientID);
 
+        private:
             std::map<unsigned int, PlayerInfo*> clients_;
 
Index: code/trunk/src/orxonox/Radar.cc
===================================================================
--- code/trunk/src/orxonox/Radar.cc	(revision 5808)
+++ code/trunk/src/orxonox/Radar.cc	(revision 5929)
@@ -43,8 +43,4 @@
 namespace orxonox
 {
-    SetConsoleCommand(Radar, cycleNavigationFocus, true).accessLevel(AccessLevel::User);
-    SetConsoleCommand(Radar, releaseNavigationFocus, true).accessLevel(AccessLevel::User);
-
-    Radar* Radar::instance_s = 0;
 
     Radar::Radar()
@@ -52,7 +48,4 @@
         , objectTypeCounter_(0)
     {
-        assert(instance_s == 0);
-        instance_s = this;
-
         // TODO: make this mapping configurable. Maybe there's a possibility with self configured
         //       configValues..
@@ -79,10 +72,12 @@
     Radar::~Radar()
     {
-        instance_s = 0;
     }
 
     const RadarViewable* Radar::getFocus()
     {
-        return *(this->itFocus_);
+        if (this->itFocus_)
+            return *(this->itFocus_);
+        else
+            return 0;
     }
 
@@ -101,5 +96,5 @@
         SUPER(Radar, tick, dt);
 
-        if (this->focus_ != *(this->itFocus_))
+        if (this->itFocus_ && (this->focus_ != *(this->itFocus_)))
         {
             // focus object was deleted, release focus
@@ -191,26 +186,3 @@
         }
     }
-
-
-    /*static*/ Radar& Radar::getInstance()
-    {
-        assert(instance_s);
-        return *instance_s;
-    }
-
-    /*static*/ void Radar::cycleNavigationFocus()
-    {
-        // avoid using getInstance because of the assert().
-        // User might call this fuction even if HUDNavigation doesn't exist.
-        if (instance_s)
-            instance_s->cycleFocus();
-    }
-
-    /*static*/ void Radar::releaseNavigationFocus()
-    {
-        // avoid using getInstance because of the assert().
-        // User might call this fuction even if HUDNavigation doesn't exist.
-        if (instance_s)
-            instance_s->releaseFocus();
-    }
 }
Index: code/trunk/src/orxonox/Radar.h
===================================================================
--- code/trunk/src/orxonox/Radar.h	(revision 5808)
+++ code/trunk/src/orxonox/Radar.h	(revision 5929)
@@ -46,19 +46,9 @@
 namespace orxonox
 {
-    /**
-    @brief This class merely ensures that no one can inherit from Radar.
-    */
-    class _OrxonoxExport RadarBase
-    {
-    private:
-        friend class Radar;
-        RadarBase() { }
-    };
-
-    class _OrxonoxExport Radar : public Tickable, private virtual RadarBase
+    class _OrxonoxExport Radar : public Tickable
     {
     public:
         Radar();
-        ~Radar();
+        virtual ~Radar();
 
         virtual void tick(float dt);
@@ -69,16 +59,11 @@
         void listObjects() const;
 
-        static Radar& getInstance();
-        static Radar* getInstancePtr() { return instance_s; }
-
-        static void cycleNavigationFocus();
-        static void releaseNavigationFocus();
+        void releaseFocus();
+        void cycleFocus();
 
     private:
         Radar(Radar& instance);
 
-        void releaseFocus();
         void updateFocus();
-        void cycleFocus();
 
         ObjectListIterator<RadarViewable> itFocus_;
@@ -86,6 +71,4 @@
         std::map<std::string, RadarViewable::Shape> objectTypes_;
         int objectTypeCounter_;
-
-        static Radar* instance_s;
     };
 }
Index: code/trunk/src/orxonox/Scene.cc
===================================================================
--- code/trunk/src/orxonox/Scene.cc	(revision 5808)
+++ code/trunk/src/orxonox/Scene.cc	(revision 5929)
@@ -42,6 +42,8 @@
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
+#include "core/GUIManager.h"
 #include "core/XMLPort.h"
 #include "tools/BulletConversions.h"
+#include "Radar.h"
 #include "worldentities/WorldEntity.h"
 
@@ -54,5 +56,5 @@
         RegisterObject(Scene);
 
-        this->setScene(this);
+        this->setScene(SmartPtr<Scene>(this, false), OBJECTID_UNKNOWN);
         this->bShadows_ = true;
 
@@ -62,4 +64,6 @@
             this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
+
+            this->radar_ = new Radar();
         }
         else
@@ -68,4 +72,6 @@
             this->sceneManager_ = new Ogre::DefaultSceneManager("");
             this->rootSceneNode_ = this->sceneManager_->getRootSceneNode();
+
+            this->radar_ = 0;
         }
 
@@ -92,4 +98,7 @@
             else
                 delete this->sceneManager_;
+
+            if (this->radar_)
+                this->radar_->destroy();
 
             this->setPhysicalWorld(false);
@@ -275,5 +284,5 @@
     {
         this->objects_.push_back(object);
-        object->setScene(this);
+        object->setScene(this, this->getObjectID());
     }
 
Index: code/trunk/src/orxonox/Scene.h
===================================================================
--- code/trunk/src/orxonox/Scene.h	(revision 5808)
+++ code/trunk/src/orxonox/Scene.h	(revision 5929)
@@ -71,4 +71,9 @@
                 { return this->bShadows_; }
 
+            inline Radar* getRadar()
+                { return this->radar_; }
+            
+            inline virtual uint32_t getSceneID() const { return this->getObjectID(); }
+
             virtual void tick(float dt);
 
@@ -91,4 +96,5 @@
             std::list<BaseObject*>   objects_;
             bool                     bShadows_;
+            Radar*                   radar_;
 
 
Index: code/trunk/src/orxonox/Test.cc
===================================================================
--- code/trunk/src/orxonox/Test.cc	(revision 5808)
+++ code/trunk/src/orxonox/Test.cc	(revision 5929)
@@ -63,5 +63,5 @@
     setConfigValues();
     registerVariables();
-		setObjectMode(0x3);
+		setSyncMode(0x3);
 	}
 
Index: code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc
===================================================================
--- code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc	(revision 5808)
+++ code/trunk/src/orxonox/collisionshapes/CompoundCollisionShape.cc	(revision 5929)
@@ -56,5 +56,5 @@
                 // make sure that the child doesn't want to detach itself --> speedup because of the missing update
                 it->first->notifyDetached();
-                delete it->first;
+                it->first->destroy();
             }
 
Index: code/trunk/src/orxonox/collisionshapes/WorldEntityCollisionShape.cc
===================================================================
--- code/trunk/src/orxonox/collisionshapes/WorldEntityCollisionShape.cc	(revision 5808)
+++ code/trunk/src/orxonox/collisionshapes/WorldEntityCollisionShape.cc	(revision 5929)
@@ -43,5 +43,5 @@
         this->worldEntityOwner_ = creator;
         // suppress synchronisation
-        this->setObjectMode(0x0);
+        this->setSyncMode(0x0);
     }
 
Index: code/trunk/src/orxonox/controllers/AIController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/AIController.cc	(revision 5808)
+++ code/trunk/src/orxonox/controllers/AIController.cc	(revision 5929)
@@ -44,5 +44,5 @@
         RegisterObject(AIController);
 
-        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&AIController::action)));
+        this->actionTimer_.setTimer(ACTION_INTERVAL, true, createExecutor(createFunctor(&AIController::action, this)));
     }
 
Index: code/trunk/src/orxonox/controllers/AIController.h
===================================================================
--- code/trunk/src/orxonox/controllers/AIController.h	(revision 5808)
+++ code/trunk/src/orxonox/controllers/AIController.h	(revision 5929)
@@ -50,5 +50,5 @@
 
         private:
-            Timer<AIController> actionTimer_;
+            Timer actionTimer_;
     };
 }
Index: code/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 5808)
+++ code/trunk/src/orxonox/controllers/ArtificialController.cc	(revision 5929)
@@ -46,4 +46,6 @@
         this->bHasTargetPosition_ = false;
         this->targetPosition_ = Vector3::ZERO;
+        
+        this->target_.setCallback(createFunctor(&ArtificialController::targetDied, this));
     }
 
@@ -162,11 +164,14 @@
     }
 
-    void ArtificialController::destroyedPawn(Pawn* ship)
-    {
-        if (ship == this->target_)
-        {
-            this->forgetTarget();
-            this->searchRandomTargetPosition();
-        }
+    void ArtificialController::abandonTarget(Pawn* target)
+    {
+        if (target == this->target_)
+            this->targetDied();
+    }
+
+    void ArtificialController::targetDied()
+    {
+        this->forgetTarget();
+        this->searchRandomTargetPosition();
     }
 
Index: code/trunk/src/orxonox/controllers/ArtificialController.h
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.h	(revision 5808)
+++ code/trunk/src/orxonox/controllers/ArtificialController.h	(revision 5929)
@@ -33,18 +33,19 @@
 
 #include "util/Math.h"
-#include "interfaces/PawnListener.h"
 #include "Controller.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport ArtificialController : public Controller, public PawnListener
+    class _OrxonoxExport ArtificialController : public Controller
     {
         public:
             ArtificialController(BaseObject* creator);
             virtual ~ArtificialController();
-
-            virtual void destroyedPawn(Pawn* pawn);
+            
+            void abandonTarget(Pawn* target);
 
         protected:
+            void targetDied();
+
             void moveToPosition(const Vector3& target);
             void moveToTargetPosition();
@@ -65,5 +66,5 @@
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
-            Pawn* target_;
+            WeakPtr<Pawn> target_;
             bool bShooting_;
 
Index: code/trunk/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.cc	(revision 5808)
+++ code/trunk/src/orxonox/controllers/HumanController.cc	(revision 5929)
@@ -36,4 +36,8 @@
 #include "infos/PlayerInfo.h"
 #include "overlays/Map.h"
+#include "graphics/Camera.h"
+#include "sound/SoundManager.h"
+#include "Radar.h"
+#include "Scene.h"
 
 namespace orxonox
@@ -56,4 +60,6 @@
     SetConsoleCommand(HumanController, dropItems,     true);
     SetConsoleCommand(HumanController, useItem,       true);
+    SetConsoleCommand(HumanController, cycleNavigationFocus,   true);
+    SetConsoleCommand(HumanController, releaseNavigationFocus, true);
 
     CreateUnloadableFactory(HumanController);
@@ -71,4 +77,20 @@
     {
         HumanController::localController_s = 0;
+    }
+
+    void HumanController::tick(float dt)
+    {
+        if (GameMode::playsSound() && HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+        {
+            // Update sound listener
+            Camera* camera = HumanController::localController_s->controllableEntity_->getCamera();
+            if (camera)
+            {
+                SoundManager::getInstance().setListenerPosition(camera->getWorldPosition());
+                SoundManager::getInstance().setListenerOrientation(camera->getWorldOrientation());
+            }
+            else
+                COUT(3) << "HumanController, Warning: Using a ControllableEntity without Camera" << std::endl;
+        }
     }
 
@@ -200,3 +222,15 @@
             return NULL;
     }
+
+    void HumanController::cycleNavigationFocus()
+    {
+        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->cycleFocus();
+    }
+
+    void HumanController::releaseNavigationFocus()
+    {
+        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
+            HumanController::localController_s->controllableEntity_->getScene()->getRadar()->releaseFocus();
+    }
 }
Index: code/trunk/src/orxonox/controllers/HumanController.h
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.h	(revision 5808)
+++ code/trunk/src/orxonox/controllers/HumanController.h	(revision 5929)
@@ -31,13 +31,17 @@
 
 #include "OrxonoxPrereqs.h"
+
+#include "tools/interfaces/Tickable.h"
 #include "Controller.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport HumanController : public Controller
+    class _OrxonoxExport HumanController : public Controller, public Tickable
     {
         public:
             HumanController(BaseObject* creator);
             virtual ~HumanController();
+
+            virtual void tick(float dt);
 
             static void moveFrontBack(const Vector2& value);
@@ -58,4 +62,6 @@
             static void dropItems();
             static void useItem();
+            static void cycleNavigationFocus();
+            static void releaseNavigationFocus();
 
             static void suicide();
Index: code/trunk/src/orxonox/controllers/WaypointController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointController.cc	(revision 5808)
+++ code/trunk/src/orxonox/controllers/WaypointController.cc	(revision 5929)
@@ -50,5 +50,5 @@
         {
             for (size_t i = 0; i < this->waypoints_.size(); ++i)
-                delete this->waypoints_[i];
+                this->waypoints_[i]->destroy();
         }
     }
Index: code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointPatrolController.cc	(revision 5808)
+++ code/trunk/src/orxonox/controllers/WaypointPatrolController.cc	(revision 5929)
@@ -45,5 +45,5 @@
         this->alertnessradius_ = 500;
 
-        this->patrolTimer_.setTimer(rnd(), true, this, createExecutor(createFunctor(&WaypointPatrolController::searchEnemy)));
+        this->patrolTimer_.setTimer(rnd(), true, createExecutor(createFunctor(&WaypointPatrolController::searchEnemy, this)));
     }
 
Index: code/trunk/src/orxonox/controllers/WaypointPatrolController.h
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointPatrolController.h	(revision 5808)
+++ code/trunk/src/orxonox/controllers/WaypointPatrolController.h	(revision 5929)
@@ -61,5 +61,5 @@
             int team_;
             float alertnessradius_;
-            Timer<WaypointPatrolController> patrolTimer_;
+            Timer patrolTimer_;
     };
 }
Index: code/trunk/src/orxonox/gamestates/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/CMakeLists.txt	(revision 5929)
@@ -0,0 +1,12 @@
+ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+  GSClient.cc
+  GSDedicated.cc
+  GSDedicatedClient.cc
+  GSGraphics.cc
+  GSIOConsole.cc
+  GSLevel.cc
+  GSMainMenu.cc
+  GSRoot.cc
+  GSServer.cc
+  GSStandalone.cc
+)
Index: code/trunk/src/orxonox/gamestates/GSClient.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSClient.cc	(revision 5929)
@@ -0,0 +1,80 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "GSClient.h"
+
+#include "util/Clock.h"
+#include "util/Exception.h"
+#include "core/CommandLine.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "network/Client.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSClient, "client", false, true);
+
+    SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as string in the form #.#.#.#");
+
+    GSClient::GSClient(const GameStateInfo& info)
+        : GameState(info)
+        , client_(0)
+    {
+    }
+
+    GSClient::~GSClient()
+    {
+    }
+
+    void GSClient::activate()
+    {
+        GameMode::setIsClient(true);
+
+        this->client_ = new Client(CommandLine::getValue("ip").getString(), CommandLine::getValue("port"));
+
+        if(!client_->establishConnection())
+            ThrowException(InitialisationFailed, "Could not establish connection with server.");
+
+        client_->update(Game::getInstance().getGameClock());
+    }
+
+    void GSClient::deactivate()
+    {
+        client_->closeConnection();
+
+        // destroy client
+        delete this->client_;
+
+        GameMode::setIsClient(false);
+    }
+
+    void GSClient::update(const Clock& time)
+    {
+        client_->update(time);
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSClient.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSClient.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSClient.h	(revision 5929)
@@ -0,0 +1,54 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSClient_H__
+#define _GSClient_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/GameState.h"
+#include "network/NetworkPrereqs.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSClient : public GameState
+    {
+    public:
+        GSClient(const GameStateInfo& info);
+        ~GSClient();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+        Client* client_;
+    };
+}
+
+#endif /* _GSClient_H__ */
Index: code/trunk/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicated.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSDedicated.cc	(revision 5929)
@@ -0,0 +1,301 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "GSDedicated.h"
+
+#include <iomanip>
+#include <iostream>
+#include <boost/bind.hpp>
+
+#include "util/Clock.h"
+#include "util/Debug.h"
+#include "util/Sleep.h"
+#include "core/CommandLine.h"
+#include "core/CommandExecutor.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "network/Server.h"
+
+#ifdef ORXONOX_PLATFORM_UNIX
+#include <termios.h>
+#endif
+
+
+namespace orxonox
+{
+    const unsigned int MAX_COMMAND_LENGTH = 255;
+    
+    DeclareGameState(GSDedicated, "dedicated", false, false);
+    
+    termios* GSDedicated::originalTerminalSettings_;
+
+    GSDedicated::GSDedicated(const GameStateInfo& info)
+        : GameState(info)
+        , server_(0)
+        , closeThread_(false)
+        , cleanLine_(true)
+        , inputIterator_(0)
+        , cursorX_(0)
+        , cursorY_(0)
+    {
+    }
+
+    GSDedicated::~GSDedicated()
+    {
+    }
+
+    void GSDedicated::activate()
+    {
+        GameMode::setHasServer(true);
+        
+        this->inputThread_ = new boost::thread(boost::bind(&GSDedicated::inputThread, this));
+        
+#ifndef ORXONOX_PLATFORM_WINDOWS
+        this->originalTerminalSettings_ = new termios;
+        this->setTerminalMode();
+#endif
+
+        this->server_ = new Server(CommandLine::getValue("port"));
+        COUT(0) << "Loading scene in server mode" << std::endl;
+
+        server_->open();
+    }
+
+    void GSDedicated::deactivate()
+    {
+        this->server_->close();
+        delete this->server_;
+        
+        closeThread_ = true;
+#ifdef ORXONOX_PLATFORM_UNIX
+        std::cout << "\033[0G\033[K";
+        std::cout.flush();
+        resetTerminalMode();
+        delete this->originalTerminalSettings_;
+#else
+        COUT(0) << "Press enter to end the game..." << std::endl;
+#endif
+        inputThread_->join();
+        delete this->inputThread_;
+
+        GameMode::setHasServer(false);
+    }
+
+    void GSDedicated::update(const Clock& time)
+    {
+        server_->update(time);
+        processQueue();
+        printLine();
+    }
+    
+    void GSDedicated::inputThread()
+    {
+        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
+//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
+        unsigned char c;
+        unsigned int  escapeChar=0;
+        while(!closeThread_)
+        {
+#ifdef ORXONOX_PLATFORM_UNIX
+            size_t count = read(STDIN_FILENO, &c, 1);
+            if (count == 1)
+#else
+            c = getchar();
+#endif
+            {
+//                 boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' )
+                    continue;
+                if( escapeChar > 0 )
+                {
+                    if( c == '[' )
+                    {
+                        escapeChar = 2;
+                        continue;
+                    }
+                    else if ( escapeChar == 2 )
+                    {
+                        switch (c)
+                        {
+                            case 'A': //keyup
+                                
+                                break;
+                            case 'B': //keydown
+                                
+                                break;
+                            case 'C': //keyright
+                                if(cursorX_<inputIterator_)
+                                    ++cursorX_;
+                                break;
+                            case 'D': //keyleft
+                                if(cursorX_>0)
+                                    --cursorX_;
+                                break;
+                            default: //not supported...
+//                                 std::cout << endl << c << endl;
+                                break;
+                        }
+                        escapeChar = 0;
+                    }
+                }
+                else // not in escape sequence mode
+                {
+                    switch (c)
+                    {
+                        case '\n':
+                            this->cleanLine_ = true;
+                            {
+                                boost::recursive_mutex::scoped_lock(this->inputQueueMutex_);
+                                boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                                this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) );
+                            }
+                            memset( this->commandLine_, 0, inputIterator_ );
+                            inputIterator_ = 0;
+                            this->cursorX_ = 0;
+                            this->cursorY_ = 0;
+                            std::cout << endl;
+                            break;
+                        case 127: // backspace
+                        case '\b':
+                            deleteCharacter( this->cursorX_ );
+                            break;
+                        case '\t':
+                        {
+//                             boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                            std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl;
+                            strncpy(reinterpret_cast<char*>(this->commandLine_), CommandExecutor::complete( std::string(reinterpret_cast<char*>(this->commandLine_),inputIterator_) ).c_str(), MAX_COMMAND_LENGTH);
+                            this->inputIterator_ = strlen((const char*)this->commandLine_);
+                            this->cursorX_ = this->inputIterator_;
+                            break;
+                        }
+                        case '\033': // 1. escape character
+                            escapeChar = 1;
+                            break;
+                        default:
+                            insertCharacter( this->cursorX_, c );
+                            break;
+                    }
+                }
+            }
+        }
+
+        delete[] this->commandLine_;
+    }
+    
+    void GSDedicated::printLine()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        // set cursor to the begining of the line and erase the line
+        std::cout << "\033[0G\033[K";
+//         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+        // print status line
+        std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
+        //save cursor position
+        std::cout << "\033[s";
+        //print commandLine buffer
+        std::cout << std::string((const char*)this->commandLine_, inputIterator_);
+        //restore cursor position and move it cursorX_ to the right
+        std::cout << "\033[u";
+        if( this->cursorX_ > 0 )
+            std::cout << "\033[" << this->cursorX_ << "C";
+        std::cout.flush();
+#endif
+    }
+    
+    void GSDedicated::processQueue()
+    {
+        std::string tempstr;
+        {
+            boost::recursive_mutex::scoped_lock lock1(this->inputQueueMutex_);
+            while(true)
+            {
+                if ( !this->commandQueue_.empty() )
+                {
+                    tempstr = this->commandQueue_.front();
+                    this->commandQueue_.pop();
+                    lock1.unlock();
+                }
+                else
+                    break;
+                CommandExecutor::execute(tempstr, true);
+            }
+        }
+    }
+    
+    void GSDedicated::setTerminalMode()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        termios new_settings;
+     
+        tcgetattr(0,this->originalTerminalSettings_);
+        new_settings = *this->originalTerminalSettings_;
+        new_settings.c_lflag &= ~( ICANON | ECHO );
+//         new_settings.c_lflag |= ( ISIG | IEXTEN );
+        new_settings.c_cc[VTIME] = 1;
+        new_settings.c_cc[VMIN] = 0;
+        tcsetattr(0,TCSANOW,&new_settings);
+        COUT(0) << endl;
+//       atexit(&GSDedicated::resetTerminalMode);
+#endif
+    }
+    
+    void GSDedicated::resetTerminalMode()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        tcsetattr(0, TCSANOW, GSDedicated::originalTerminalSettings_);
+#endif
+    }
+    
+    void GSDedicated::insertCharacter( unsigned int position, char c )
+    {
+//         std::cout << endl << static_cast<unsigned int>(c) << endl;
+        // check that we do not exceed MAX_COMMAND_LENGTH
+        if( inputIterator_+1 < MAX_COMMAND_LENGTH )
+        {
+            // if cursor not at end of line then move the rest of the line
+            if( position != this->inputIterator_ )
+                    memmove( this->commandLine_+position+1, this->commandLine_+position, this->inputIterator_-position);
+//             boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+            this->commandLine_[position] = c;
+            ++this->cursorX_;
+            ++this->inputIterator_;
+        }
+    }
+    void GSDedicated::deleteCharacter( unsigned int position )
+    {
+//         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+        if ( this->inputIterator_>0 && position>0 )
+        {
+            if ( position != this->inputIterator_ )
+                memmove( this->commandLine_+position-1, this->commandLine_+position, this->inputIterator_-position);
+            --this->cursorX_;
+            --this->inputIterator_;
+        }
+    }
+    
+}
Index: code/trunk/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicated.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSDedicated.h	(revision 5929)
@@ -0,0 +1,85 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSDedicated_H__
+#define _GSDedicated_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <cstring>
+#include <queue>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+
+#include "core/GameState.h"
+#include "network/NetworkPrereqs.h"
+
+struct termios;
+
+namespace orxonox
+{
+
+    class _OrxonoxExport GSDedicated : public GameState
+    {
+    public:
+        GSDedicated(const GameStateInfo& info);
+        ~GSDedicated();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+        void inputThread();
+        void printLine();
+        void processQueue();
+        void setTerminalMode();
+        static void resetTerminalMode();
+
+        void insertCharacter( unsigned int position, char c );
+        void deleteCharacter( unsigned int position );
+
+        Server*                 server_;
+
+        boost::thread           *inputThread_;
+        boost::recursive_mutex  inputLineMutex_;
+        boost::recursive_mutex  inputQueueMutex_;
+        bool                    closeThread_;
+        bool                    cleanLine_;
+        unsigned char*          commandLine_;
+        unsigned int            inputIterator_;
+        std::queue<std::string> commandQueue_;
+        static termios*         originalTerminalSettings_;
+
+        unsigned int            cursorX_;
+        unsigned int            cursorY_;
+    };
+}
+
+#endif /* _GSDedicated_H__ */
Index: code/trunk/src/orxonox/gamestates/GSDedicatedClient.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicatedClient.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSDedicatedClient.cc	(revision 5929)
@@ -0,0 +1,306 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Oliver Scheuss
+ *
+ */
+
+#include "GSDedicatedClient.h"
+
+#include <iomanip>
+#include <iostream>
+#include <boost/bind.hpp>
+
+#include "util/Clock.h"
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "util/Sleep.h"
+#include "core/CommandLine.h"
+#include "core/CommandExecutor.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "network/Client.h"
+
+#ifdef ORXONOX_PLATFORM_UNIX
+#include <termios.h>
+#endif
+
+
+namespace orxonox
+{
+    const unsigned int MAX_COMMAND_LENGTH = 255;
+    
+    DeclareGameState(GSDedicatedClient, "dedicatedClient", false, false);
+    
+    termios* GSDedicatedClient::originalTerminalSettings_;
+
+    GSDedicatedClient::GSDedicatedClient(const GameStateInfo& info)
+        : GameState(info)
+        , client_(0)
+        , closeThread_(false)
+        , cleanLine_(true)
+        , inputIterator_(0)
+        , cursorX_(0)
+        , cursorY_(0)
+    {
+    }
+
+    GSDedicatedClient::~GSDedicatedClient()
+    {
+    }
+
+    void GSDedicatedClient::activate()
+    {
+        this->inputThread_ = new boost::thread(boost::bind(&GSDedicatedClient::inputThread, this));
+        
+#ifndef ORXONOX_PLATFORM_WINDOWS
+        this->originalTerminalSettings_ = new termios;
+        this->setTerminalMode();
+#endif
+
+        this->client_ = new Client(CommandLine::getValue("ip").getString(), CommandLine::getValue("port"));
+        COUT(0) << "Loading scene in client mode" << std::endl;
+
+        if( !client_->establishConnection() )
+            ThrowException(InitialisationFailed, "Could not establish connection with server.");
+            
+        client_->update(Game::getInstance().getGameClock());
+
+
+    }
+
+    void GSDedicatedClient::deactivate()
+    {
+        if( this->client_ )
+        {
+            this->client_->closeConnection();
+            delete this->client_;
+        }
+        
+        closeThread_ = true;
+#ifdef ORXONOX_PLATFORM_UNIX
+        std::cout << "\033[0G\033[K";
+        std::cout.flush();
+        resetTerminalMode();
+        delete this->originalTerminalSettings_;
+#else
+        COUT(0) << "Press enter to end the game..." << std::endl;
+#endif
+        inputThread_->join();
+        delete this->inputThread_;
+    }
+
+    void GSDedicatedClient::update(const Clock& time)
+    {
+        client_->update(time);
+        processQueue();
+        printLine();
+    }
+    
+    void GSDedicatedClient::inputThread()
+    {
+        this->commandLine_ = new unsigned char[MAX_COMMAND_LENGTH];
+//         memset( this->commandLine_, 0, MAX_COMMAND_LENGTH );
+        unsigned char c;
+        unsigned int  escapeChar=0;
+        while(!closeThread_)
+        {
+#ifdef ORXONOX_PLATFORM_UNIX
+            size_t count = read(STDIN_FILENO, &c, 1);
+            if (count == 1)
+#else
+            c = getchar();
+#endif
+            {
+//                 boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                if ( inputIterator_>=MAX_COMMAND_LENGTH-1 && c!='\n' )
+                    continue;
+                if( escapeChar > 0 )
+                {
+                    if( c == '[' )
+                    {
+                        escapeChar = 2;
+                        continue;
+                    }
+                    else if ( escapeChar == 2 )
+                    {
+                        switch (c)
+                        {
+                            case 'A': //keyup
+                                
+                                break;
+                            case 'B': //keydown
+                                
+                                break;
+                            case 'C': //keyright
+                                if(cursorX_<inputIterator_)
+                                    ++cursorX_;
+                                break;
+                            case 'D': //keyleft
+                                if(cursorX_>0)
+                                    --cursorX_;
+                                break;
+                            default: //not supported...
+//                                 std::cout << endl << c << endl;
+                                break;
+                        }
+                        escapeChar = 0;
+                    }
+                }
+                else // not in escape sequence mode
+                {
+                    switch (c)
+                    {
+                        case '\n':
+                            this->cleanLine_ = true;
+                            {
+                                boost::recursive_mutex::scoped_lock(this->inputQueueMutex_);
+                                boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                                this->commandQueue_.push( std::string((const char*)this->commandLine_,inputIterator_) );
+                            }
+                            memset( this->commandLine_, 0, inputIterator_ );
+                            inputIterator_ = 0;
+                            this->cursorX_ = 0;
+                            this->cursorY_ = 0;
+                            std::cout << endl;
+                            break;
+                        case 127: // backspace
+                        case '\b':
+                            deleteCharacter( this->cursorX_ );
+                            break;
+                        case '\t':
+                        {
+//                             boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+                            std::cout << endl << CommandExecutor::hint( std::string((const char*)this->commandLine_,inputIterator_) ) << endl;
+                            strncpy(reinterpret_cast<char*>(this->commandLine_), CommandExecutor::complete( std::string(reinterpret_cast<char*>(this->commandLine_),inputIterator_) ).c_str(), MAX_COMMAND_LENGTH);
+                            this->inputIterator_ = strlen((const char*)this->commandLine_);
+                            this->cursorX_ = this->inputIterator_;
+                            break;
+                        }
+                        case '\033': // 1. escape character
+                            escapeChar = 1;
+                            break;
+                        default:
+                            insertCharacter( this->cursorX_, c );
+                            break;
+                    }
+                }
+            }
+        }
+
+        delete[] this->commandLine_;
+    }
+    
+    void GSDedicatedClient::printLine()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        // set cursor to the begining of the line and erase the line
+        std::cout << "\033[0G\033[K";
+//         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+        // print status line
+        std::cout << std::fixed << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgFPS() << " fps, " << std::setprecision(2) << std::setw(5) << Game::getInstance().getAvgTickTime() << " ms avg ticktime # ";
+        //save cursor position
+        std::cout << "\033[s";
+        //print commandLine buffer
+        std::cout << std::string((const char*)this->commandLine_, inputIterator_);
+        //restore cursor position and move it cursorX_ to the right
+        std::cout << "\033[u";
+        if( this->cursorX_ > 0 )
+            std::cout << "\033[" << this->cursorX_ << "C";
+        std::cout.flush();
+#endif
+    }
+    
+    void GSDedicatedClient::processQueue()
+    {
+        std::string tempstr;
+        {
+            boost::recursive_mutex::scoped_lock lock1(this->inputQueueMutex_);
+            while(true)
+            {
+                if ( !this->commandQueue_.empty() )
+                {
+                    tempstr = this->commandQueue_.front();
+                    this->commandQueue_.pop();
+                    lock1.unlock();
+                }
+                else
+                    break;
+                CommandExecutor::execute(tempstr, true);
+            }
+        }
+    }
+    
+    void GSDedicatedClient::setTerminalMode()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        termios new_settings;
+     
+        tcgetattr(0,this->originalTerminalSettings_);
+        new_settings = *this->originalTerminalSettings_;
+        new_settings.c_lflag &= ~( ICANON | ECHO );
+//         new_settings.c_lflag |= ( ISIG | IEXTEN );
+        new_settings.c_cc[VTIME] = 1;
+        new_settings.c_cc[VMIN] = 0;
+        tcsetattr(0,TCSANOW,&new_settings);
+        COUT(0) << endl;
+//       atexit(&GSDedicatedClient::resetTerminalMode);
+#endif
+    }
+    
+    void GSDedicatedClient::resetTerminalMode()
+    {
+#ifdef ORXONOX_PLATFORM_UNIX
+        tcsetattr(0, TCSANOW, GSDedicatedClient::originalTerminalSettings_);
+#endif
+    }
+    
+    void GSDedicatedClient::insertCharacter( unsigned int position, char c )
+    {
+//         std::cout << endl << static_cast<unsigned int>(c) << endl;
+        // check that we do not exceed MAX_COMMAND_LENGTH
+        if( inputIterator_+1 < MAX_COMMAND_LENGTH )
+        {
+            // if cursor not at end of line then move the rest of the line
+            if( position != this->inputIterator_ )
+                    memmove( this->commandLine_+position+1, this->commandLine_+position, this->inputIterator_-position);
+//             boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+            this->commandLine_[position] = c;
+            ++this->cursorX_;
+            ++this->inputIterator_;
+        }
+    }
+    void GSDedicatedClient::deleteCharacter( unsigned int position )
+    {
+//         boost::recursive_mutex::scoped_lock(this->inputLineMutex_);
+        if ( this->inputIterator_>0 && position>0 )
+        {
+            if ( position != this->inputIterator_ )
+                memmove( this->commandLine_+position-1, this->commandLine_+position, this->inputIterator_-position);
+            --this->cursorX_;
+            --this->inputIterator_;
+        }
+    }
+    
+}
Index: code/trunk/src/orxonox/gamestates/GSDedicatedClient.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSDedicatedClient.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSDedicatedClient.h	(revision 5929)
@@ -0,0 +1,84 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Oliver Scheuss
+ *
+ */
+
+#ifndef _GSDedicatedClient_H__
+#define _GSDedicatedClient_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/GameState.h"
+#include "network/NetworkPrereqs.h"
+#include <queue>
+#include <cstring>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/recursive_mutex.hpp>
+
+struct termios;
+
+namespace orxonox
+{
+
+    class _OrxonoxExport GSDedicatedClient : public GameState
+    {
+    public:
+        GSDedicatedClient(const GameStateInfo& info);
+        ~GSDedicatedClient();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+        void inputThread();
+        void printLine();
+        void processQueue();
+        void setTerminalMode();
+        static void resetTerminalMode();
+
+        void insertCharacter( unsigned int position, char c );
+        void deleteCharacter( unsigned int position );
+
+        Client*                 client_;
+
+        boost::thread           *inputThread_;
+        boost::recursive_mutex  inputLineMutex_;
+        boost::recursive_mutex  inputQueueMutex_;
+        bool                    closeThread_;
+        bool                    cleanLine_;
+        unsigned char*          commandLine_;
+        unsigned int            inputIterator_;
+        std::queue<std::string> commandQueue_;
+        static termios*         originalTerminalSettings_;
+
+        unsigned int            cursorX_;
+        unsigned int            cursorY_;
+    };
+}
+
+#endif /* _GSDedicatedClient_H__ */
Index: code/trunk/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.cc	(revision 5929)
@@ -0,0 +1,101 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Benjamin Knecht
+ *
+ */
+
+/**
+@file
+@brief
+    Implementation of Graphics GameState class.
+ */
+
+#include "GSGraphics.h"
+
+#include "core/CommandExecutor.h"
+#include "core/ConsoleCommand.h"
+#include "core/Game.h"
+#include "core/GUIManager.h"
+// HACK:
+#include "overlays/Map.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSGraphics, "graphics", false, true);
+
+    GSGraphics::GSGraphics(const GameStateInfo& info)
+        : GameState(info)
+    {
+    }
+
+    GSGraphics::~GSGraphics()
+    {
+    }
+
+    /**
+    @brief
+        This function is called when we enter this game state.
+
+        There is only one thing to do here:
+        \li create console command to toggle GUI
+    */
+    void GSGraphics::activate()
+    {
+        // add console command to toggle GUI
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
+    }
+
+    /**
+    @brief
+        This function is called when the game state is left
+    */
+    void GSGraphics::deactivate()
+    {
+        // HACK: (destroys a resource smart pointer)
+        Map::hackDestroyMap();
+    }
+
+    /**
+    @brief
+        Toggles the visibility of the current GUI
+
+        This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
+        For more details on this function check out the Lua code.
+    */
+    void GSGraphics::toggleGUI()
+    {
+        GUIManager::getInstance().executeCode("toggleGUI()");
+    }
+
+    void GSGraphics::update(const Clock& time)
+    {
+        if (this->getActivity().topState)
+        {
+            // This state can not 'survive' on its own.
+            // Load a user interface therefore
+            Game::getInstance().requestState("mainMenu");
+        }
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSGraphics.h	(revision 5929)
@@ -0,0 +1,65 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Benjamin Knecht (documentation)
+ *
+ */
+
+/**
+@file
+@brief
+    Declaration of the Graphics GameState class.
+*/
+
+#ifndef _GSGraphics_H__
+#define _GSGraphics_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    /**
+    @brief
+        Game state used when displaying graphics of any kind. Another blubb resides here.
+
+        This game state is only left out if we start a dedicated server where no graphics are present.
+    */
+    class _OrxonoxExport GSGraphics : public GameState
+    {
+    public:
+        GSGraphics(const GameStateInfo& info);
+        ~GSGraphics();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+        void toggleGUI();
+
+    private:
+    };
+}
+
+#endif /* _GSGraphics_H__ */
Index: code/trunk/src/orxonox/gamestates/GSIOConsole.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSIOConsole.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSIOConsole.cc	(revision 5929)
@@ -0,0 +1,71 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "GSIOConsole.h"
+
+#include <iostream>
+#include "core/ConsoleCommand.h"
+#include "core/CommandExecutor.h"
+#include "core/Game.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSIOConsole, "ioConsole", false, false);
+
+    GSIOConsole::GSIOConsole(const GameStateInfo& info)
+        : GameState(info)
+    {
+    }
+
+    GSIOConsole::~GSIOConsole()
+    {
+    }
+
+    void GSIOConsole::activate()
+    {
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSIOConsole::loadMenu, this), "loadMenu"));
+    }
+
+    void GSIOConsole::deactivate()
+    {
+    }
+
+    void GSIOConsole::update(const Clock& time)
+    {
+        std::cout << ">";
+        std::string command;
+        std::getline(std::cin, command);
+        CommandExecutor::execute(command, true);
+    }
+
+    void GSIOConsole::loadMenu()
+    {
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("graphics, mainMenu");
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSIOConsole.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSIOConsole.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSIOConsole.h	(revision 5929)
@@ -0,0 +1,52 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSIOConsole_H__
+#define _GSIOConsole_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSIOConsole : public GameState
+    {
+    public:
+        GSIOConsole(const GameStateInfo& info);
+        ~GSIOConsole();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+        void loadMenu();
+    };
+}
+
+#endif /* _GSIOConsole_H__ */
Index: code/trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSLevel.cc	(revision 5929)
@@ -0,0 +1,182 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *      Benjamin Knecht
+ *
+ */
+
+#include "GSLevel.h"
+
+#include <OgreCompositorManager.h>
+
+#include "util/Clock.h"
+#include "core/input/InputManager.h"
+#include "core/input/InputState.h"
+#include "core/input/KeyBinderManager.h"
+#include "core/ConsoleCommand.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "core/GUIManager.h"
+#include "core/Loader.h"
+#include "core/XMLFile.h"
+
+#include "LevelManager.h"
+#include "PlayerManager.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSLevel, "level", false, false);
+
+    GSLevel::GSLevel(const GameStateInfo& info)
+        : GameState(info)
+        , gameInputState_(0)
+        , guiMouseOnlyInputState_(0)
+        , guiKeysOnlyInputState_(0)
+        , startFile_(0)
+    {
+    }
+
+    GSLevel::~GSLevel()
+    {
+    }
+
+    void GSLevel::activate()
+    {
+        if (GameMode::showsGraphics())
+        {
+            gameInputState_ = InputManager::getInstance().createInputState("game");
+            gameInputState_->setMouseMode(MouseMode::Exclusive);
+            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
+            KeyBinderManager::getInstance().setToDefault();
+
+            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
+            guiMouseOnlyInputState_->setMouseMode(MouseMode::Exclusive);
+            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
+
+            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
+            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
+
+            CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSLevel::showIngameGUI, this), "showIngameGUI"));
+        }
+
+        if (GameMode::isMaster())
+        {
+            this->loadLevel();
+        }
+
+        if (GameMode::showsGraphics())
+        {
+            // level is loaded: we can start capturing the input
+            InputManager::getInstance().enterState("game");
+            
+            // connect the HumanPlayer to the game
+            PlayerManager::getInstance().clientConnected(0);
+        }
+    }
+
+    void GSLevel::showIngameGUI(bool show)
+    {
+        if (show)
+        {
+            GUIManager::getInstance().showGUI("inGameTest");
+            GUIManager::getInstance().executeCode("showCursor()");
+            InputManager::getInstance().enterState("guiMouseOnly");
+        }
+        else
+        {
+            GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
+            GUIManager::getInstance().executeCode("hideCursor()");
+            InputManager::getInstance().leaveState("guiMouseOnly");
+        }
+    }
+
+    void GSLevel::deactivate()
+    {
+        if (GameMode::showsGraphics())
+        {
+            // disconnect the HumanPlayer
+            PlayerManager::getInstance().clientDisconnected(0);
+            
+            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
+            Ogre::CompositorManager::getSingleton().removeAll();
+
+            InputManager::getInstance().leaveState("game");
+        }
+
+        if (GameMode::isMaster())
+            this->unloadLevel();
+
+        if (GameMode::showsGraphics())
+        {
+            gameInputState_->setHandler(0);
+            guiMouseOnlyInputState_->setHandler(0);
+            guiKeysOnlyInputState_->setHandler(0);
+            InputManager::getInstance().destroyState("game");
+            InputManager::getInstance().destroyState("guiKeysOnly");
+            InputManager::getInstance().destroyState("guiMouseOnly");
+        }
+    }
+
+    void GSLevel::update(const Clock& time)
+    {
+        // Note: Temporarily moved to GSRoot.
+        //// Call the scene objects
+        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
+        //    it->tick(time.getDeltaTime() * this->timeFactor_);
+    }
+
+    void GSLevel::loadLevel()
+    {
+        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
+            this->staticObjects_.insert(*it);
+        
+        // call the loader
+        COUT(0) << "Loading level..." << std::endl;
+        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
+        Loader::open(startFile_);
+    }
+
+    void GSLevel::unloadLevel()
+    {
+        Loader::unload(startFile_);
+        delete startFile_;
+
+        COUT(3) << "Unloaded level. Remaining objects:" << std::endl;
+        unsigned int i = 0;
+        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
+        {
+            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
+            if (find == this->staticObjects_.end())
+            {
+                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << ")" << std::endl;
+            }
+        }
+        COUT(3) << i << " objects remaining.";
+        if (i == 0)
+            COUT(3) << " Well done!" << std::endl;
+        else
+            COUT(3) << " Try harder!" << std::endl;
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSLevel.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSLevel.h	(revision 5929)
@@ -0,0 +1,65 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Benjamin Knecht
+ *
+ */
+
+#ifndef _GSLevel_H__
+#define _GSLevel_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <set>
+#include "core/OrxonoxClass.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSLevel : public GameState
+    {
+    public:
+        GSLevel(const GameStateInfo& info);
+        ~GSLevel();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    protected:
+        void loadLevel();
+        void unloadLevel();
+        void showIngameGUI(bool show);
+
+        InputState*              gameInputState_;          //!< input state for normal ingame playing
+        InputState*              guiMouseOnlyInputState_;  //!< input state if we only need the mouse to use the GUI
+        InputState*              guiKeysOnlyInputState_;   //!< input state if we only need the keys to use the GUI
+
+        XMLFile* startFile_;
+        std::set<BaseObject*> staticObjects_;
+    };
+}
+
+#endif /* _GSLevel_H__ */
Index: code/trunk/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.cc	(revision 5929)
@@ -0,0 +1,164 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "GSMainMenu.h"
+
+#include <OgreSceneManager.h>
+
+#include "core/input/InputManager.h"
+#include "core/input/InputState.h"
+#include "core/input/KeyBinderManager.h"
+#include "core/Game.h"
+#include "core/ConsoleCommand.h"
+#include "core/GraphicsManager.h"
+#include "core/GUIManager.h"
+#include "Scene.h"
+#include "sound/AmbientSound.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSMainMenu, "mainMenu", false, true);
+
+    GSMainMenu::GSMainMenu(const GameStateInfo& info)
+        : GameState(info)
+        , inputState_(0)
+    {
+        inputState_ = InputManager::getInstance().createInputState("mainMenu");
+        inputState_->setMouseMode(MouseMode::Nonexclusive);
+        inputState_->setHandler(GUIManager::getInstancePtr());
+        inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
+        inputState_->setJoyStickHandler(&InputHandler::EMPTY);
+
+        // create an empty Scene
+        this->scene_ = new Scene(NULL);
+        this->scene_->setSyncMode( 0x0 );
+        // and a Camera
+        this->camera_ = this->scene_->getSceneManager()->createCamera("mainMenu/Camera");
+        if (GameMode::playsSound())
+        {
+            // Load sound
+            this->ambient_ = new AmbientSound(0);
+            this->ambient_->setSource("ambient/mainmenu.wav");
+        }
+    }
+
+    GSMainMenu::~GSMainMenu()
+    {
+        if (GameMode::playsSound())
+            delete this->ambient_;
+
+        InputManager::getInstance().destroyState("mainMenu");
+
+        this->scene_->getSceneManager()->destroyCamera(this->camera_);
+        this->scene_->destroy();
+    }
+
+    void GSMainMenu::activate()
+    {
+        // show main menu
+        GUIManager::getInstance().showGUI("MainMenu");
+        GUIManager::getInstance().setCamera(this->camera_);
+        GraphicsManager::getInstance().setCamera(this->camera_);
+
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone), "startGame"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startServer), "startServer"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startClient), "startClient"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startDedicated), "startDedicated"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startMainMenu), "startMainMenu"));
+        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startIOConsole), "startIOConsole"));
+
+        KeyBinderManager::getInstance().setToDefault();
+        InputManager::getInstance().enterState("mainMenu");
+
+        if (GameMode::playsSound())
+        {
+            this->ambient_->setLoop(true);
+            this->ambient_->play();
+        }
+    }
+
+    void GSMainMenu::deactivate()
+    {
+        if (GameMode::playsSound())
+        {
+            this->ambient_->stop();
+        }
+
+        InputManager::getInstance().leaveState("mainMenu");
+
+        GUIManager::getInstance().setCamera(0);
+        GraphicsManager::getInstance().setCamera(0);
+    }
+
+    void GSMainMenu::update(const Clock& time)
+    {
+    }
+
+    void GSMainMenu::startStandalone()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("standalone, level");
+    }
+
+    void GSMainMenu::startServer()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("server, level");
+    }
+
+    void GSMainMenu::startClient()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("client, level");
+    }
+
+    void GSMainMenu::startDedicated()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("dedicated, level");
+    }
+    void GSMainMenu::startMainMenu()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("mainmenu");
+    }
+    void GSMainMenu::startIOConsole()
+    {
+        // HACK - HACK
+        Game::getInstance().popState();
+        Game::getInstance().popState();
+        Game::getInstance().requestStates("ioConsole");
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSMainMenu.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSMainMenu.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSMainMenu.h	(revision 5929)
@@ -0,0 +1,66 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSMainMenu_H__
+#define _GSMainMenu_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "util/OgreForwardRefs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSMainMenu : public GameState
+    {
+    public:
+        GSMainMenu(const GameStateInfo& info);
+        ~GSMainMenu();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+        static void startStandalone();
+        static void startServer();
+        static void startClient();
+        static void startDedicated();
+        static void startMainMenu();
+        static void startIOConsole();
+
+    private:
+        InputState*       inputState_;
+        Scene*            scene_;
+        Ogre::Camera*     camera_;
+
+        // ambient sound for the main menu
+        AmbientSound*     ambient_;
+    };
+}
+
+#endif /* _GSMainMenu_H__ */
Index: code/trunk/src/orxonox/gamestates/GSRoot.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSRoot.cc	(revision 5929)
@@ -0,0 +1,157 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "GSRoot.h"
+
+#include "util/Clock.h"
+#include "core/ConsoleCommand.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "network/NetworkFunction.h"
+#include "tools/Timer.h"
+#include "tools/interfaces/TimeFactorListener.h"
+#include "tools/interfaces/Tickable.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSRoot, "root", false, false);
+    SetConsoleCommandShortcut(GSRoot, printObjects);
+
+    GSRoot::GSRoot(const GameStateInfo& info)
+        : GameState(info)
+        , timeFactor_(1.0f)
+        , bPaused_(false)
+        , timeFactorPauseBackup_(1.0f)
+    {
+    }
+
+    GSRoot::~GSRoot()
+    {
+        NetworkFunctionBase::destroyAllNetworkFunctions();
+    }
+    
+    void GSRoot::printObjects()
+    {
+        unsigned int nr=0;
+        for(ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it; ++it){
+            if( dynamic_cast<Synchronisable*>(*it) )
+                COUT(0) << "object: " << it->getIdentifier()->getName() << " id: " << dynamic_cast<Synchronisable*>(*it)->getObjectID() << std::endl;
+            else
+                COUT(0) << "object: " << it->getIdentifier()->getName() << std::endl;
+            nr++;
+        }
+        COUT(0) << "currently got " << nr << " objects" << std::endl;
+    
+    }
+
+    void GSRoot::activate()
+    {
+        // reset game speed to normal
+        this->timeFactor_ = 1.0f;
+
+        // time factor console command
+        ConsoleCommand* command = createConsoleCommand(createFunctor(&GSRoot::setTimeFactor, this), "setTimeFactor");
+        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);
+
+        // time factor console command
+        command = createConsoleCommand(createFunctor(&GSRoot::pause, this), "pause");
+        CommandExecutor::addConsoleCommandShortcut(command).accessLevel(AccessLevel::Offline);
+    }
+
+    void GSRoot::deactivate()
+    {
+    }
+
+    void GSRoot::update(const Clock& time)
+    {
+        if (this->getActivity().topState)
+        {
+            // This state can not 'survive' on its own.
+            // Load a user interface therefore
+            Game::getInstance().requestState("ioConsole");
+        }
+
+        for (ObjectList<Timer>::iterator it = ObjectList<Timer>::begin(); it; )
+            (it++)->tick(time);
+
+        /*** HACK *** HACK ***/
+        // Call the Tickable objects
+        float leveldt = time.getDeltaTime();
+        if (leveldt > 1.0f)
+        {
+            // just loaded
+            leveldt = 0.0f;
+        }
+        for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; )
+            (it++)->tick(leveldt * this->timeFactor_);
+        /*** HACK *** HACK ***/
+    }
+
+    /**
+    @brief
+        Changes the speed of Orxonox
+    @remark
+        This function is a hack when placed here!
+        Timefactor should be related to the scene (level or so), not the game
+    */
+    void GSRoot::setTimeFactor(float factor)
+    {
+        if (GameMode::isMaster())
+        {
+            if (!this->bPaused_)
+            {
+                TimeFactorListener::timefactor_s = factor;
+
+                for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it)
+                    it->changedTimeFactor(factor, this->timeFactor_);
+
+                this->timeFactor_ = factor;
+            }
+            else
+                this->timeFactorPauseBackup_ = factor;
+        }
+    }
+
+    void GSRoot::pause()
+    {
+        if (GameMode::isMaster())
+        {
+            if (!this->bPaused_)
+            {
+                this->timeFactorPauseBackup_ = this->timeFactor_;
+                this->setTimeFactor(0.0f);
+                this->bPaused_ = true;
+            }
+            else
+            {
+                this->bPaused_ = false;
+                this->setTimeFactor(this->timeFactorPauseBackup_);
+            }
+        }
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSRoot.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSRoot.h	(revision 5929)
@@ -0,0 +1,62 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSRoot_H__
+#define _GSRoot_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSRoot : public GameState
+    {
+    public:
+        GSRoot(const GameStateInfo& info);
+        ~GSRoot();
+
+        static void printObjects();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+        // this has to be public because proteced triggers a bug in msvc
+        // when taking the function address.
+        void setTimeFactor(float factor);
+        void pause();
+        float getTimeFactor() { return this->timeFactor_; }
+
+    private:
+        float                 timeFactor_;              //!< A factor that sets the gamespeed. 1 is normal.
+        bool                  bPaused_;
+        float                 timeFactorPauseBackup_;
+    };
+}
+
+#endif /* _GSRoot_H__ */
Index: code/trunk/src/orxonox/gamestates/GSServer.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSServer.cc	(revision 5929)
@@ -0,0 +1,75 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "GSServer.h"
+
+#include "util/Debug.h"
+#include "core/CommandLine.h"
+#include "core/Game.h"
+#include "core/GameMode.h"
+#include "network/Server.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSServer, "server", false, true);
+
+    SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)");
+
+    GSServer::GSServer(const GameStateInfo& info)
+        : GameState(info)
+        , server_(0)
+    {
+    }
+
+    GSServer::~GSServer()
+    {
+    }
+
+    void GSServer::activate()
+    {
+        GameMode::setHasServer(true);
+
+        this->server_ = new Server(CommandLine::getValue("port"));
+        COUT(0) << "Loading scene in server mode" << std::endl;
+
+        server_->open();
+    }
+
+    void GSServer::deactivate()
+    {
+        this->server_->close();
+        delete this->server_;
+
+        GameMode::setHasServer(false);
+    }
+
+    void GSServer::update(const Clock& time)
+    {
+        server_->update(time);
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSServer.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSServer.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSServer.h	(revision 5929)
@@ -0,0 +1,54 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSServer_H__
+#define _GSServer_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/GameState.h"
+#include "network/NetworkPrereqs.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSServer : public GameState
+    {
+    public:
+        GSServer(const GameStateInfo& info);
+        ~GSServer();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+        Server* server_;
+    };
+}
+
+#endif /* _GSServer_H__ */
Index: code/trunk/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- code/trunk/src/orxonox/gamestates/GSStandalone.cc	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSStandalone.cc	(revision 5929)
@@ -0,0 +1,61 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+#include "GSStandalone.h"
+
+#include "core/Game.h"
+#include "core/GameMode.h"
+
+namespace orxonox
+{
+    DeclareGameState(GSStandalone, "standalone", false, true);
+
+    GSStandalone::GSStandalone(const GameStateInfo& info)
+        : GameState(info)
+    {
+    }
+
+    GSStandalone::~GSStandalone()
+    {
+    }
+
+
+    void GSStandalone::activate()
+    {
+        GameMode::setIsStandalone(true);
+    }
+
+    void GSStandalone::deactivate()
+    {
+        GameMode::setIsStandalone(false);
+    }
+
+    void GSStandalone::update(const Clock& time)
+    {
+    }
+}
Index: code/trunk/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- code/trunk/src/orxonox/gamestates/GSStandalone.h	(revision 5929)
+++ code/trunk/src/orxonox/gamestates/GSStandalone.h	(revision 5929)
@@ -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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _GSStandalone_H__
+#define _GSStandalone_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+
+namespace orxonox
+{
+    class _OrxonoxExport GSStandalone : public GameState
+    {
+    public:
+        GSStandalone(const GameStateInfo& info);
+        ~GSStandalone();
+
+        void activate();
+        void deactivate();
+        void update(const Clock& time);
+
+    private:
+    };
+}
+
+#endif /* _GSStandalone_H__ */
Index: code/trunk/src/orxonox/gametypes/Asteroids.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Asteroids.cc	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/Asteroids.cc	(revision 5929)
@@ -54,5 +54,5 @@
         if (this->time_ < 0 && !this->hasEnded() && this->timerIsActive_)
         {
-            this->gtinfo_.sendAnnounceMessage("Time's up - you have lost the match!");
+            this->gtinfo_->sendAnnounceMessage("Time's up - you have lost the match!");
             this->end();
         }
@@ -63,5 +63,5 @@
         if (victim && victim->getPlayer())
         {
-            this->gtinfo_.sendAnnounceMessage("You're dead - you have lost the match!");
+            this->gtinfo_->sendAnnounceMessage("You're dead - you have lost the match!");
             this->end();
         }
Index: code/trunk/src/orxonox/gametypes/Gametype.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/Gametype.cc	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/Gametype.cc	(revision 5929)
@@ -33,4 +33,5 @@
 #include "core/ConfigValueIncludes.h"
 #include "core/GameMode.h"
+#include "core/ConsoleCommand.h"
 
 #include "infos/PlayerInfo.h"
@@ -47,9 +48,11 @@
     CreateUnloadableFactory(Gametype);
 
-    Gametype::Gametype(BaseObject* creator) : BaseObject(creator), gtinfo_(creator)
+    Gametype::Gametype(BaseObject* creator) : BaseObject(creator)
     {
         RegisterObject(Gametype);
-
-        this->setGametype(this);
+        
+        this->gtinfo_ = new GametypeInfo(creator);
+
+        this->setGametype(SmartPtr<Gametype>(this, false));
 
         this->defaultControllableEntity_ = Class(Spectator);
@@ -76,4 +79,23 @@
         else
             this->scoreboard_ = 0;
+        
+        /* HACK HACK HACK */
+        this->hackAddBots_ = createConsoleCommand( createFunctor(&Gametype::addBots, this), "hackAddBots");
+        this->hackKillBots_ = createConsoleCommand( createFunctor(&Gametype::killBots, this), "hackKillBots");
+        CommandExecutor::addConsoleCommandShortcut( this->hackAddBots_ );
+        CommandExecutor::addConsoleCommandShortcut( this->hackKillBots_ );
+        /* HACK HACK HACK */
+    }
+    
+    Gametype::~Gametype()
+    {
+        if (this->isInitialized())
+        {
+            this->gtinfo_->destroy();
+            if( this->hackAddBots_ )
+                delete this->hackAddBots_;
+            if( this->hackKillBots_ )
+                delete this->hackKillBots_;
+        }
     }
 
@@ -100,10 +122,10 @@
         }
 
-        if (this->gtinfo_.bStartCountdownRunning_ && !this->gtinfo_.bStarted_)
-            this->gtinfo_.startCountdown_ -= dt;
-
-        if (!this->gtinfo_.bStarted_)
+        if (this->gtinfo_->bStartCountdownRunning_ && !this->gtinfo_->bStarted_)
+            this->gtinfo_->startCountdown_ -= dt;
+
+        if (!this->gtinfo_->bStarted_)
             this->checkStart();
-        else if (!this->gtinfo_.bEnded_)
+        else if (!this->gtinfo_->bEnded_)
             this->spawnDeadPlayersIfRequested();
 
@@ -115,5 +137,5 @@
         this->addBots(this->numberOfBots_);
 
-        this->gtinfo_.bStarted_ = true;
+        this->gtinfo_->bStarted_ = true;
 
         this->spawnPlayersIfRequested();
@@ -122,5 +144,5 @@
     void Gametype::end()
     {
-        this->gtinfo_.bEnded_ = true;
+        this->gtinfo_->bEnded_ = true;
 
         for (std::map<PlayerInfo*, Player>::iterator it = this->players_.begin(); it != this->players_.end(); ++it)
@@ -130,5 +152,5 @@
                 ControllableEntity* oldentity = it->first->getControllableEntity();
 
-                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity->getCreator());
+                ControllableEntity* entity = this->defaultControllableEntity_.fabricate(oldentity);
                 if (oldentity->getCamera())
                 {
@@ -243,7 +265,7 @@
 
                         if (killer->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
-                            this->gtinfo_.sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
+                            this->gtinfo_->sendKillMessage("You killed " + victim->getPlayer()->getName(), killer->getPlayer()->getClientID());
                         if (victim->getPlayer()->getClientID() != CLIENTID_UNKNOWN)
-                            this->gtinfo_.sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
+                            this->gtinfo_->sendDeathMessage("You were killed by " + killer->getPlayer()->getName(), victim->getPlayer()->getClientID());
                     }
                 }
@@ -308,5 +330,5 @@
                 it->second.state_ = PlayerState::Dead;
 
-                if (!it->first->isReadyToSpawn() || !this->gtinfo_.bStarted_)
+                if (!it->first->isReadyToSpawn() || !this->gtinfo_->bStarted_)
                 {
                     this->spawnPlayerAsDefaultPawn(it->first);
@@ -319,12 +341,12 @@
     void Gametype::checkStart()
     {
-        if (!this->gtinfo_.bStarted_)
-        {
-            if (this->gtinfo_.bStartCountdownRunning_)
-            {
-                if (this->gtinfo_.startCountdown_ <= 0)
-                {
-                    this->gtinfo_.bStartCountdownRunning_ = false;
-                    this->gtinfo_.startCountdown_ = 0;
+        if (!this->gtinfo_->bStarted_)
+        {
+            if (this->gtinfo_->bStartCountdownRunning_)
+            {
+                if (this->gtinfo_->startCountdown_ <= 0)
+                {
+                    this->gtinfo_->bStartCountdownRunning_ = false;
+                    this->gtinfo_->startCountdown_ = 0;
                     this->start();
                 }
@@ -349,6 +371,6 @@
                     if (allplayersready && hashumanplayers)
                     {
-                        this->gtinfo_.startCountdown_ = this->initialStartCountdown_;
-                        this->gtinfo_.bStartCountdownRunning_ = true;
+                        this->gtinfo_->startCountdown_ = this->initialStartCountdown_;
+                        this->gtinfo_->bStartCountdownRunning_ = true;
                     }
                 }
@@ -419,7 +441,9 @@
             if (it->getGametype() == this)
             {
-                delete (*(it++));
+                (it++)->destroy();
                 ++i;
             }
+            else
+                ++it;
         }
     }
Index: code/trunk/src/orxonox/gametypes/Gametype.h
===================================================================
--- code/trunk/src/orxonox/gametypes/Gametype.h	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/Gametype.h	(revision 5929)
@@ -37,5 +37,5 @@
 
 #include "core/BaseObject.h"
-#include "core/Identifier.h"
+#include "core/SubclassIdentifier.h"
 #include "tools/interfaces/Tickable.h"
 #include "infos/GametypeInfo.h"
@@ -68,5 +68,5 @@
         public:
             Gametype(BaseObject* creator);
-            virtual ~Gametype() {}
+            virtual ~Gametype();
 
             void setConfigValues();
@@ -75,10 +75,10 @@
 
             inline const GametypeInfo* getGametypeInfo() const
-                { return &this->gtinfo_; }
+                { return this->gtinfo_; }
 
             inline bool hasStarted() const
-                { return this->gtinfo_.bStarted_; }
+                { return this->gtinfo_->bStarted_; }
             inline bool hasEnded() const
-                { return this->gtinfo_.bEnded_; }
+                { return this->gtinfo_->bEnded_; }
 
             virtual void start();
@@ -114,12 +114,12 @@
 
             inline bool isStartCountdownRunning() const
-                { return this->gtinfo_.bStartCountdownRunning_; }
+                { return this->gtinfo_->bStartCountdownRunning_; }
             inline float getStartCountdown() const
-                { return this->gtinfo_.startCountdown_; }
+                { return this->gtinfo_->startCountdown_; }
 
             inline void setHUDTemplate(const std::string& name)
-                { this->gtinfo_.hudtemplate_ = name; }
+                { this->gtinfo_->hudtemplate_ = name; }
             inline const std::string& getHUDTemplate() const
-                { return this->gtinfo_.hudtemplate_; }
+                { return this->gtinfo_->hudtemplate_; }
 
             void addBots(unsigned int amount);
@@ -163,5 +163,5 @@
             virtual void spawnDeadPlayersIfRequested();
 
-            GametypeInfo gtinfo_;
+            SmartPtr<GametypeInfo> gtinfo_;
 
             bool bAutoStart_;
@@ -184,4 +184,9 @@
             // Config Values
             std::string scoreboardTemplate_;
+            
+            /* HACK HACK HACK */
+            ConsoleCommand* hackAddBots_;
+            ConsoleCommand* hackKillBots_;
+            /* HACK HACK HACK */
     };
 }
Index: code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/TeamBaseMatch.cc	(revision 5929)
@@ -42,6 +42,6 @@
         RegisterObject(TeamBaseMatch);
 
-        this->scoreTimer_.setTimer(10, true, this, createExecutor(createFunctor(&TeamBaseMatch::winPoints)));
-        this->outputTimer_.setTimer(10, true, this, createExecutor(createFunctor(&TeamBaseMatch::showPoints)));
+        this->scoreTimer_.setTimer(10, true, createExecutor(createFunctor(&TeamBaseMatch::winPoints, this)));
+        this->outputTimer_.setTimer(10, true, createExecutor(createFunctor(&TeamBaseMatch::showPoints, this)));
 
         this->pointsTeam1_ = 0;
@@ -67,10 +67,10 @@
                 {
                     base->setState(BaseState::ControlTeam1);
-                    this->gtinfo_.sendAnnounceMessage("The red team captured a base");
+                    this->gtinfo_->sendAnnounceMessage("The red team captured a base");
                 }
                 if (teamnr == 1)
                 {
                     base->setState(BaseState::ControlTeam2);
-                    this->gtinfo_.sendAnnounceMessage("The blue team captured a base");
+                    this->gtinfo_->sendAnnounceMessage("The blue team captured a base");
                 }
             }
@@ -194,7 +194,7 @@
 
                 if (it->second == winningteam)
-                    this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
+                    this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
                 else
-                    this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+                    this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
             }
 
Index: code/trunk/src/orxonox/gametypes/TeamBaseMatch.h
===================================================================
--- code/trunk/src/orxonox/gametypes/TeamBaseMatch.h	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/TeamBaseMatch.h	(revision 5929)
@@ -65,6 +65,6 @@
 
             std::set<TeamBaseMatchBase*> bases_;
-            Timer<TeamBaseMatch> scoreTimer_;
-            Timer<TeamBaseMatch> outputTimer_;
+            Timer scoreTimer_;
+            Timer outputTimer_;
 
             //points for each team
Index: code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/TeamDeathmatch.cc	(revision 5929)
@@ -93,5 +93,5 @@
 
         if (valid_player)
-            this->players_.erase(player);
+            this->teamnumbers_.erase(player);
 
         return valid_player;
@@ -100,15 +100,15 @@
     bool TeamDeathmatch::allowPawnHit(Pawn* victim, Pawn* originator)
     {
-        return (!this->pawnsAreInTheSameTeam(victim, originator));
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
     }
 
     bool TeamDeathmatch::allowPawnDamage(Pawn* victim, Pawn* originator)
     {
-        return (!this->pawnsAreInTheSameTeam(victim, originator));
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
     }
 
     bool TeamDeathmatch::allowPawnDeath(Pawn* victim, Pawn* originator)
     {
-        return (!this->pawnsAreInTheSameTeam(victim, originator));
+        return (!this->pawnsAreInTheSameTeam(victim, originator) || !originator);
     }
 
Index: code/trunk/src/orxonox/gametypes/UnderAttack.cc
===================================================================
--- code/trunk/src/orxonox/gametypes/UnderAttack.cc	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/UnderAttack.cc	(revision 5929)
@@ -46,4 +46,5 @@
         this->teams_ = 2;
         this->destroyer_ = 0;
+        this->destroyer_.setCallback(createFunctor(&UnderAttack::killedDestroyer, this));
         this->gameEnded_ = false;
 
@@ -65,24 +66,21 @@
 
 
-    void UnderAttack::destroyedPawn(Pawn* pawn)
+    void UnderAttack::killedDestroyer()
     {
-        if (pawn == this->destroyer_)
+        this->end(); //end gametype
+        std::string message = "Ship destroyed! Team 0 has won!";
+        COUT(0) << message << std::endl;
+        Host::Broadcast(message);
+        this->gameEnded_ = true;
+
+        for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
         {
-            this->end(); //end gametype
-            std::string message = "Ship destroyed! Team 0 has won!";
-            COUT(0) << message << std::endl;
-            Host::Broadcast(message);
-            this->gameEnded_ = true;
+            if (it->first->getClientID() == CLIENTID_UNKNOWN)
+                continue;
 
-            for (std::map<PlayerInfo*, int>::iterator it = this->teamnumbers_.begin(); it != this->teamnumbers_.end(); ++it)
-            {
-                if (it->first->getClientID() == CLIENTID_UNKNOWN)
-                    continue;
-
-                if (it->second == 0)
-                    this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
-                else
-                    this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
-            }
+            if (it->second == 0)
+                this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
+            else
+                this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
         }
     }
@@ -164,7 +162,7 @@
 
                     if (it->second == 1)
-                        this->gtinfo_.sendAnnounceMessage("You have won the match!", it->first->getClientID());
+                        this->gtinfo_->sendAnnounceMessage("You have won the match!", it->first->getClientID());
                     else
-                        this->gtinfo_.sendAnnounceMessage("You have lost the match!", it->first->getClientID());
+                        this->gtinfo_->sendAnnounceMessage("You have lost the match!", it->first->getClientID());
                 }
             }
@@ -178,5 +176,5 @@
                 Host::Broadcast(message);
 */
-                this->gtinfo_.sendAnnounceMessage(message);
+                this->gtinfo_->sendAnnounceMessage(message);
 
                 if (timesequence_ >= 30 && timesequence_ <= 60)
Index: code/trunk/src/orxonox/gametypes/UnderAttack.h
===================================================================
--- code/trunk/src/orxonox/gametypes/UnderAttack.h	(revision 5808)
+++ code/trunk/src/orxonox/gametypes/UnderAttack.h	(revision 5929)
@@ -32,10 +32,9 @@
 #include "OrxonoxPrereqs.h"
 
-#include "interfaces/PawnListener.h"
 #include "TeamDeathmatch.h"
 
 namespace orxonox
 {
-    class _OrxonoxExport UnderAttack : public TeamDeathmatch, public PawnListener
+    class _OrxonoxExport UnderAttack : public TeamDeathmatch
     {
         public:
@@ -54,7 +53,7 @@
 
         protected:
-            virtual void destroyedPawn(Pawn* pawn);
+            virtual void killedDestroyer();
 
-            Destroyer* destroyer_;
+            WeakPtr<Destroyer> destroyer_;
             unsigned int teams_;
             float gameTime_;
Index: code/trunk/src/orxonox/graphics/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/graphics/CMakeLists.txt	(revision 5808)
+++ code/trunk/src/orxonox/graphics/CMakeLists.txt	(revision 5929)
@@ -1,12 +1,14 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
-  Backlight.cc
   Billboard.cc
   BlinkingBillboard.cc
-  Camera.cc
   FadingBillboard.cc
   GlobalShader.cc
-  Light.cc
   Model.cc
   ParticleEmitter.cc
   ParticleSpawner.cc
+COMPILATION_BEGIN GraphicsCompilation.cc
+  Backlight.cc
+  Camera.cc
+  Light.cc
+COMPILATION_END
 )
Index: code/trunk/src/orxonox/graphics/Camera.cc
===================================================================
--- code/trunk/src/orxonox/graphics/Camera.cc	(revision 5808)
+++ code/trunk/src/orxonox/graphics/Camera.cc	(revision 5929)
@@ -38,4 +38,6 @@
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
+#include "core/GameMode.h"
+#include "core/GUIManager.h"
 #include "Scene.h"
 #include "CameraManager.h"
@@ -49,4 +51,6 @@
         RegisterObject(Camera);
 
+        if (!GameMode::showsGraphics())
+            ThrowException(AbortLoading, "Can't create Camera, no graphics.");
         if (!this->getScene())
             ThrowException(AbortLoading, "Can't create Camera, no scene.");
@@ -65,5 +69,5 @@
         this->nearClipDistance_ = 1;
 
-        this->setObjectMode(0x0);
+        this->setSyncMode(0x0);
 
         this->setConfigValues();
@@ -75,4 +79,6 @@
         if (this->isInitialized())
         {
+            if (GUIManager::getInstance().getCamera() == this->camera_)
+                GUIManager::getInstance().setCamera(NULL);
             this->releaseFocus();
 
Index: code/trunk/src/orxonox/graphics/FadingBillboard.cc
===================================================================
--- code/trunk/src/orxonox/graphics/FadingBillboard.cc	(revision 5808)
+++ code/trunk/src/orxonox/graphics/FadingBillboard.cc	(revision 5929)
@@ -103,5 +103,5 @@
         {
             this->changedirection_ = 1;
-            this->turnonofftimer_.setTimer(this->turnontime_, false, this, createExecutor(createFunctor(&FadingBillboard::stopturnonoff)));
+            this->turnonofftimer_.setTimer(this->turnontime_, false, createExecutor(createFunctor(&FadingBillboard::stopturnonoff, this)));
 
             if (this->isVisible())
@@ -111,5 +111,5 @@
         {
             this->changedirection_ = -1;
-            this->turnonofftimer_.setTimer(this->turnofftime_, false, this, createExecutor(createFunctor(&FadingBillboard::stopturnonoff)));
+            this->turnonofftimer_.setTimer(this->turnofftime_, false, createExecutor(createFunctor(&FadingBillboard::stopturnonoff, this)));
         }
     }
@@ -126,5 +126,5 @@
             this->fadedColour_ = ColourValue::ZERO;
             this->getBillboardSet().setColour(this->fadedColour_);
-            this->turnonofftimer_.setTimer(this->postprocessingtime_, false, this, createExecutor(createFunctor(&FadingBillboard::poststopturnonoff)));
+            this->turnonofftimer_.setTimer(this->postprocessingtime_, false, createExecutor(createFunctor(&FadingBillboard::poststopturnonoff, this)));
         }
         this->changedirection_ = 0;
Index: code/trunk/src/orxonox/graphics/FadingBillboard.h
===================================================================
--- code/trunk/src/orxonox/graphics/FadingBillboard.h	(revision 5808)
+++ code/trunk/src/orxonox/graphics/FadingBillboard.h	(revision 5929)
@@ -74,5 +74,5 @@
             float turnofftime_;
             float postprocessingtime_;
-            Timer<FadingBillboard> turnonofftimer_;
+            Timer turnonofftimer_;
             char changedirection_;
             ColourValue fadedColour_;
Index: code/trunk/src/orxonox/graphics/ParticleEmitter.cc
===================================================================
--- code/trunk/src/orxonox/graphics/ParticleEmitter.cc	(revision 5808)
+++ code/trunk/src/orxonox/graphics/ParticleEmitter.cc	(revision 5929)
@@ -63,5 +63,5 @@
         {
             this->detachOgreObject(this->particles_->getParticleSystem());
-            delete this->particles_;
+            this->particles_->destroy();
         }
     }
@@ -101,5 +101,5 @@
         if (this->particles_)
         {
-            delete this->particles_;
+            this->particles_->destroy();
             this->particles_ = 0;
         }
Index: code/trunk/src/orxonox/graphics/ParticleSpawner.cc
===================================================================
--- code/trunk/src/orxonox/graphics/ParticleSpawner.cc	(revision 5808)
+++ code/trunk/src/orxonox/graphics/ParticleSpawner.cc	(revision 5929)
@@ -71,9 +71,9 @@
     }
 
-    void ParticleSpawner::processEvent(Event& event)
+    void ParticleSpawner::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
     {
-        SUPER(ParticleSpawner, processEvent, event);
+        SUPER(ParticleSpawner, XMLEventPort, xmlelement, mode);
 
-        ORXONOX_SET_EVENT(ParticleSpawner, "spawn", spawn, event);
+        XMLPortEventState(ParticleSpawner, BaseObject, "spawn", spawn, xmlelement, mode);
     }
 
@@ -88,13 +88,13 @@
     void ParticleSpawner::startParticleSpawner()
     {
-        if (!this->particles_)
-            return;
-
         this->setActive(false);
 
         if (this->bForceDestroy_ || this->bSuppressStart_)
+        {
+            this->timer_.stopTimer();
             return;
+        }
 
-        this->timer_.setTimer(this->startdelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner)));
+        this->timer_.setTimer(this->startdelay_, false, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner, this)));
     }
 
@@ -103,5 +103,5 @@
         this->setActive(true);
         if (this->lifetime_ != 0)
-            this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner)));
+            this->timer_.setTimer(this->lifetime_, false, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner, this)));
     }
 
@@ -116,9 +116,9 @@
 
             if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)
-                this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
+                this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner, this)));
         }
         else if (this->bLoop_)
         {
-            this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner)));
+            this->timer_.setTimer(this->destroydelay_, false, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner, this)));
         }
     }
@@ -126,5 +126,5 @@
     void ParticleSpawner::destroyParticleSpawner()
     {
-        delete this;
+        this->destroy();
     }
 }
Index: code/trunk/src/orxonox/graphics/ParticleSpawner.h
===================================================================
--- code/trunk/src/orxonox/graphics/ParticleSpawner.h	(revision 5808)
+++ code/trunk/src/orxonox/graphics/ParticleSpawner.h	(revision 5929)
@@ -44,8 +44,8 @@
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            virtual void processEvent(Event& event);
+            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
 
-            inline void destroy()
-                { this->bForceDestroy_ = true; this->stopParticleSpawner(); }
+            inline void stop(bool bDestroy)
+                { this->bForceDestroy_ = bDestroy; this->stopParticleSpawner(); }
             inline void spawn()
                 { this->bSuppressStart_ = false; this->startParticleSpawner(); }
@@ -89,5 +89,5 @@
             void destroyParticleSpawner();
 
-            Timer<ParticleSpawner> timer_;
+            Timer timer_;
 
             bool  bSuppressStart_;
Index: code/trunk/src/orxonox/infos/HumanPlayer.cc
===================================================================
--- code/trunk/src/orxonox/infos/HumanPlayer.cc	(revision 5808)
+++ code/trunk/src/orxonox/infos/HumanPlayer.cc	(revision 5929)
@@ -64,8 +64,8 @@
         {
             if (this->humanHud_)
-                delete this->humanHud_;
+                this->humanHud_->destroy();
 
             if (this->gametypeHud_)
-                delete this->gametypeHud_;
+                this->gametypeHud_->destroy();
         }
     }
@@ -116,5 +116,5 @@
 
             if (!GameMode::isMaster())
-                this->setObjectMode(ObjectDirection::Bidirectional);
+                this->setSyncMode(ObjectDirection::Bidirectional);
             else
                 this->setName(this->nick_);
@@ -162,6 +162,10 @@
 
         if (this->isInitialized() && this->isLocalPlayer())
-            if (this->getGametype()->getHUDTemplate() != "")
+        {
+            if (this->getGametype() && this->getGametype()->getHUDTemplate() != "")
                 this->setGametypeHUDTemplate(this->getGametype()->getHUDTemplate());
+            else
+                this->setGametypeHUDTemplate("");
+        }
     }
 
@@ -170,9 +174,9 @@
         if (this->humanHud_)
         {
-            delete this->humanHud_;
+            this->humanHud_->destroy();
             this->humanHud_ = 0;
         }
 
-        if (this->isLocalPlayer() && this->humanHudTemplate_ != "")
+        if (this->isLocalPlayer() && this->humanHudTemplate_ != "" && GameMode::showsGraphics())
         {
             this->humanHud_ = new OverlayGroup(this);
@@ -186,5 +190,5 @@
         if (this->gametypeHud_)
         {
-            delete this->gametypeHud_;
+            this->gametypeHud_->destroy();
             this->gametypeHud_ = 0;
         }
Index: code/trunk/src/orxonox/infos/PlayerInfo.cc
===================================================================
--- code/trunk/src/orxonox/infos/PlayerInfo.cc	(revision 5808)
+++ code/trunk/src/orxonox/infos/PlayerInfo.cc	(revision 5929)
@@ -35,4 +35,5 @@
 #include "gametypes/Gametype.h"
 #include "worldentities/ControllableEntity.h"
+#include "controllers/Controller.h"
 
 namespace orxonox
@@ -66,5 +67,5 @@
             if (this->controller_)
             {
-                delete this->controller_;
+                this->controller_->destroy();
                 this->controller_ = 0;
             }
@@ -131,5 +132,5 @@
         if (this->controller_)
         {
-            delete this->controller_;
+            this->controller_->destroy();
             this->controller_ = 0;
         }
Index: code/trunk/src/orxonox/infos/PlayerInfo.h
===================================================================
--- code/trunk/src/orxonox/infos/PlayerInfo.h	(revision 5808)
+++ code/trunk/src/orxonox/infos/PlayerInfo.h	(revision 5929)
@@ -33,6 +33,5 @@
 
 #include "Info.h"
-#include "core/Identifier.h"
-#include "controllers/Controller.h"
+#include "core/SubclassIdentifier.h"
 
 namespace orxonox
Index: code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc
===================================================================
--- code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc	(revision 5808)
+++ code/trunk/src/orxonox/interfaces/InterfaceCompilation.cc	(revision 5929)
@@ -34,5 +34,4 @@
 
 #include "GametypeMessageListener.h"
-#include "PawnListener.h"
 #include "PlayerTrigger.h"
 #include "RadarListener.h"
@@ -51,15 +50,4 @@
     {
         RegisterRootObject(GametypeMessageListener);
-    }
-
-    //----------------------------
-    // PawnListener
-    //----------------------------
-    /**
-        @brief Constructor for the PawnListener.
-    */
-    PawnListener::PawnListener()
-    {
-        RegisterRootObject(PawnListener);
     }
 
Index: code/trunk/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/trunk/src/orxonox/interfaces/NotificationListener.h	(revision 5808)
+++ code/trunk/src/orxonox/interfaces/NotificationListener.h	(revision 5929)
@@ -45,4 +45,6 @@
 namespace orxonox
 {
+    class Notification;
+
     class _OrxonoxExport NotificationListener : virtual public OrxonoxClass
     {
Index: code/trunk/src/orxonox/interfaces/PawnListener.h
===================================================================
--- code/trunk/src/orxonox/interfaces/PawnListener.h	(revision 5808)
+++ 	(revision )
@@ -1,47 +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:
- *      Fabian 'x3n' Landau
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _PawnListener_H__
-#define _PawnListener_H__
-
-#include "OrxonoxPrereqs.h"
-#include "core/OrxonoxClass.h"
-
-namespace orxonox
-{
-    class _OrxonoxExport PawnListener : virtual public OrxonoxClass
-    {
-        public:
-            PawnListener();
-            virtual ~PawnListener() {}
-
-            virtual void destroyedPawn(Pawn* pawn) = 0;
-    };
-}
-
-#endif /* _PawnListener_H__ */
Index: code/trunk/src/orxonox/interfaces/RadarViewable.cc
===================================================================
--- code/trunk/src/orxonox/interfaces/RadarViewable.cc	(revision 5808)
+++ code/trunk/src/orxonox/interfaces/RadarViewable.cc	(revision 5929)
@@ -38,4 +38,5 @@
 #include "worldentities/WorldEntity.h"
 #include "Radar.h"
+#include "Scene.h"
 #include "overlays/Map.h"
 
@@ -135,5 +136,5 @@
     void RadarViewable::setRadarObjectDescription(const std::string& str)
     {
-        Radar* radar = Radar::getInstancePtr();
+        Radar* radar = this->getWorldEntity()->getScene()->getRadar();
         if (radar)
             this->radarObjectShape_ = radar->addObjectDescription(str);
Index: code/trunk/src/orxonox/items/Engine.cc
===================================================================
--- code/trunk/src/orxonox/items/Engine.cc	(revision 5808)
+++ code/trunk/src/orxonox/items/Engine.cc	(revision 5929)
@@ -37,5 +37,4 @@
 #include "pickup/ModifierType.h"
 #include "tools/Shader.h"
-#include "sound/SoundBase.h"
 
 namespace orxonox
@@ -68,6 +67,4 @@
         this->setConfigValues();
         this->registerVariables();
-
-        this->sound_ = NULL;
     }
 
@@ -79,8 +76,5 @@
 
             if (this->boostBlur_)
-                delete this->boostBlur_;
-
-            if(this->sound_ != NULL)
-                delete this->sound_;
+                this->boostBlur_->destroy();
         }
     }
@@ -102,6 +96,4 @@
         XMLPortParam(Engine, "accelerationleftright", setAccelerationLeftRight, setAccelerationLeftRight, xmlelement, mode);
         XMLPortParam(Engine, "accelerationupdown",    setAccelerationUpDown,    setAccelerationUpDown,    xmlelement, mode);
-
-        XMLPortParamLoadOnly(Engine, "sound", loadSound, xmlelement, mode);
     }
 
@@ -237,10 +229,7 @@
             if (this->boostBlur_)
             {
-                delete this->boostBlur_;
+                this->boostBlur_->destroy();
                 this->boostBlur_ = 0;
             }
-
-            if(this->sound_ != NULL)
-                this->sound_->attachToEntity(ship);
         }
     }
@@ -253,18 +242,3 @@
             return Vector3::ZERO;
     }
-
-    void Engine::loadSound(const std::string filename)
-    {
-        if(filename == "") return;
-        else
-        {
-            if(this->sound_ == NULL)
-            {
-                this->sound_ = new SoundBase(this->ship_);
-            }
-
-            this->sound_->loadFile(filename);
-            this->sound_->play(true);
-        }
-    }
 }
Index: code/trunk/src/orxonox/items/Engine.h
===================================================================
--- code/trunk/src/orxonox/items/Engine.h	(revision 5808)
+++ code/trunk/src/orxonox/items/Engine.h	(revision 5929)
@@ -130,6 +130,4 @@
             Shader* boostBlur_;
             float blurStrength_;
-
-            SoundBase* sound_;
     };
 }
Index: code/trunk/src/orxonox/items/MultiStateEngine.cc
===================================================================
--- code/trunk/src/orxonox/items/MultiStateEngine.cc	(revision 5808)
+++ code/trunk/src/orxonox/items/MultiStateEngine.cc	(revision 5929)
@@ -60,11 +60,11 @@
             // We have no ship, so the effects are not attached and won't be destroyed automatically
             for (std::list<WorldEntity*>::const_iterator it = this->activeEffects_.begin(); it != this->activeEffects_.end(); ++it)
-                delete (*it);
+                (*it)->destroy();
             for (std::list<WorldEntity*>::const_iterator it = this->forwardEffects_.begin(); it != this->forwardEffects_.end(); ++it)
-                delete (*it);
+                (*it)->destroy();
             for (std::list<WorldEntity*>::const_iterator it = this->boostEffects_.begin(); it != this->boostEffects_.end(); ++it)
-                delete (*it);
+                (*it)->destroy();
             for (std::list<WorldEntity*>::const_iterator it = this->brakeEffects_.begin(); it != this->brakeEffects_.end(); ++it)
-                delete (*it);
+                (*it)->destroy();
         }
     }
@@ -91,5 +91,5 @@
             if (this->getShip()->hasLocalController())
             {
-                this->setObjectMode(ObjectDirection::Bidirectional);
+                this->setSyncMode(ObjectDirection::Bidirectional);
 
                 const Vector3& direction = this->getDirection();
Index: code/trunk/src/orxonox/overlays/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/overlays/CMakeLists.txt	(revision 5808)
+++ code/trunk/src/orxonox/overlays/CMakeLists.txt	(revision 5929)
@@ -3,5 +3,7 @@
   OverlayGroup.cc
 
+COMPILATION_BEGIN OverlayCompilation.cc
   InGameConsole.cc
   Map.cc
+COMPILATION_END
 )
Index: code/trunk/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/trunk/src/orxonox/overlays/InGameConsole.cc	(revision 5808)
+++ code/trunk/src/orxonox/overlays/InGameConsole.cc	(revision 5929)
@@ -41,11 +41,12 @@
 #include <OgreFont.h>
 
+#include "util/Clock.h"
+#include "util/Convert.h"
 #include "util/Math.h"
-#include "util/Convert.h"
 #include "util/UTFStringConversions.h"
-#include "core/Clock.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/ConsoleCommand.h"
+#include "core/ScopedSingletonManager.h"
 #include "core/input/InputManager.h"
 #include "core/input/InputState.h"
@@ -61,4 +62,5 @@
 
     InGameConsole* InGameConsole::singletonPtr_s = 0;
+    ManageScopedSingleton(InGameConsole, ScopeID::Graphics, false);
 
     /**
@@ -85,4 +87,5 @@
 
         this->setConfigValues();
+        this->initialise();
     }
 
Index: code/trunk/src/orxonox/overlays/InGameConsole.h
===================================================================
--- code/trunk/src/orxonox/overlays/InGameConsole.h	(revision 5808)
+++ code/trunk/src/orxonox/overlays/InGameConsole.h	(revision 5929)
@@ -50,5 +50,4 @@
 
         void initialise();
-        void destroy();
         void setConfigValues();
 
Index: code/trunk/src/orxonox/overlays/Map.cc
===================================================================
--- code/trunk/src/orxonox/overlays/Map.cc	(revision 5808)
+++ code/trunk/src/orxonox/overlays/Map.cc	(revision 5929)
@@ -290,5 +290,5 @@
        for(ObjectList<orxonox::RadarViewable>::iterator it = ObjectList<orxonox::RadarViewable>::begin();
             it!=ObjectList<orxonox::RadarViewable>::end();
-            it++)
+            ++it)
         {
             //COUT(0) << "Radar_Position: " << it->getRVWorldPosition() << std::endl;
@@ -392,5 +392,5 @@
         for(ObjectList<orxonox::Map>::iterator it = ObjectList<orxonox::Map>::begin();
             it!=ObjectList<orxonox::Map>::end();
-            it++)
+            ++it)
         {
         //Map * m = it->getMap();
Index: code/trunk/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- code/trunk/src/orxonox/overlays/OrxonoxOverlay.h	(revision 5808)
+++ code/trunk/src/orxonox/overlays/OrxonoxOverlay.h	(revision 5929)
@@ -213,6 +213,6 @@
   };
 
-  SUPER_FUNCTION(7, OrxonoxOverlay, changedOwner, false);
-  SUPER_FUNCTION(8, OrxonoxOverlay, changedOverlayGroup, false);
+  SUPER_FUNCTION(6, OrxonoxOverlay, changedOwner, false);
+  SUPER_FUNCTION(7, OrxonoxOverlay, changedOverlayGroup, false);
 }
 
Index: code/trunk/src/orxonox/overlays/OverlayGroup.cc
===================================================================
--- code/trunk/src/orxonox/overlays/OverlayGroup.cc	(revision 5808)
+++ code/trunk/src/orxonox/overlays/OverlayGroup.cc	(revision 5929)
@@ -61,5 +61,5 @@
     {
         for (std::set<OrxonoxOverlay*>::iterator it = hudElements_.begin(); it != hudElements_.end(); ++it)
-            delete (*it);
+            (*it)->destroy();
     }
 
Index: code/trunk/src/orxonox/pickup/DroppedItem.cc
===================================================================
--- code/trunk/src/orxonox/pickup/DroppedItem.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/DroppedItem.cc	(revision 5929)
@@ -56,5 +56,5 @@
         if (this->item_)
         {
-            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); it++)
+            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
             {
                 Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
@@ -69,5 +69,5 @@
         {
             COUT(3) << "DroppedItem '" << this->item_->getPickupIdentifier() << "' picked up." << std::endl;
-            delete this;
+            this->destroy();
         }
     }
@@ -76,6 +76,5 @@
         if (this->timeToLive_ > 0)
         {
-            ExecutorMember<DroppedItem>* exec = createExecutor(createFunctor(&DroppedItem::timerCallback));
-            this->timer_.setTimer(this->timeToLive_, false, this, exec, false);
+            this->timer_.setTimer(this->timeToLive_, false, createExecutor(createFunctor(&DroppedItem::timerCallback, this)), false);
         }
     }
@@ -85,8 +84,8 @@
         {
             COUT(3) << "Delete DroppedItem with '" << this->item_->getPickupIdentifier() << "'" << std::endl;
-            delete this->item_;
+            this->item_->destroy();
         }
 
-        delete this;
+        this->destroy();
     }
 
Index: code/trunk/src/orxonox/pickup/DroppedItem.h
===================================================================
--- code/trunk/src/orxonox/pickup/DroppedItem.h	(revision 5808)
+++ code/trunk/src/orxonox/pickup/DroppedItem.h	(revision 5929)
@@ -77,5 +77,5 @@
         BaseItem* item_;
 
-        Timer<DroppedItem> timer_;
+        Timer timer_;
     };
 }
Index: code/trunk/src/orxonox/pickup/ModifierPickup.cc
===================================================================
--- code/trunk/src/orxonox/pickup/ModifierPickup.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/ModifierPickup.cc	(revision 5929)
@@ -101,7 +101,7 @@
             if (this->duration_ > 0.0f)
             {
-                ExecutorMember<ModifierPickup>* executor = createExecutor(createFunctor(&ModifierPickup::timerCallback));
+                Executor* executor = createExecutor(createFunctor(&ModifierPickup::timerCallback, this));
                 executor->setDefaultValues(pawn);
-                this->timer_.setTimer(this->duration_, false, this, executor);
+                this->timer_.setTimer(this->duration_, false, executor);
             }
 
@@ -139,5 +139,5 @@
                 this->timer_.stopTimer();
 
-            delete this;
+            this->destroy();
 
             return true;
Index: code/trunk/src/orxonox/pickup/ModifierPickup.h
===================================================================
--- code/trunk/src/orxonox/pickup/ModifierPickup.h	(revision 5808)
+++ code/trunk/src/orxonox/pickup/ModifierPickup.h	(revision 5929)
@@ -129,4 +129,5 @@
 
         void timerCallback(Pawn* pawn);     //!< Method called when the timer runs out.
+        
     private:
         float getAdditiveModifier(ModifierType::Value type) const;               //!< Get the additive modifier for a given ModifierType.
@@ -138,6 +139,6 @@
         std::map<ModifierType::Value, float> multiplicativeModifiers_;           //!< Map of multiplicative modifiers, indexed by ModifierType.
 
-        float duration_;                                                        //!< Duration of this pickup's effect (0 for unlimited).
-        Timer<ModifierPickup> timer_;                                           //!< Timer used if the pickup's effect has a time limit.
+        float duration_;                                                         //!< Duration of this pickup's effect (0 for unlimited).
+        Timer timer_;                                                            //!< Timer used if the pickup's effect has a time limit.
     };
 }
Index: code/trunk/src/orxonox/pickup/PickupSpawner.cc
===================================================================
--- code/trunk/src/orxonox/pickup/PickupSpawner.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/PickupSpawner.cc	(revision 5929)
@@ -91,5 +91,5 @@
             asItem->addTemplate(this->itemTemplate_);
             PickupInventory::getImageForItem(asItem);
-            delete newObject;
+            newObject->destroy();
         }
 
@@ -127,5 +127,5 @@
         if (this->isActive())
         {
-            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); it++)
+            for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
             {
                 Vector3 distance = it->getWorldPosition() - this->getWorldPosition();
@@ -166,6 +166,5 @@
                     if (this->respawnTime_ > 0.0f)
                     {
-                        ExecutorMember<PickupSpawner>* executor = createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback));
-                        this->respawnTimer_.setTimer(this->respawnTime_, false, this, executor);
+                        this->respawnTimer_.setTimer(this->respawnTime_, false, createExecutor(createFunctor(&PickupSpawner::respawnTimerCallback, this)));
 
                         this->setActive(false);
@@ -174,5 +173,5 @@
                 }
                 else
-                    delete newObject;
+                    newObject->destroy();
             }
         }
Index: code/trunk/src/orxonox/pickup/PickupSpawner.h
===================================================================
--- code/trunk/src/orxonox/pickup/PickupSpawner.h	(revision 5808)
+++ code/trunk/src/orxonox/pickup/PickupSpawner.h	(revision 5929)
@@ -114,5 +114,5 @@
 
         float respawnTime_;                     //!< Time after which this gets re-actived.
-        Timer<PickupSpawner> respawnTimer_;     //!< Timer used for re-activating.
+        Timer respawnTimer_;                    //!< Timer used for re-activating.
     };
 }
Index: code/trunk/src/orxonox/pickup/items/HealthImmediate.cc
===================================================================
--- code/trunk/src/orxonox/pickup/items/HealthImmediate.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/items/HealthImmediate.cc	(revision 5929)
@@ -67,5 +67,5 @@
         {
             pawn->addHealth(this->recoveredHealth_);
-            delete this;
+            this->destroy();
         }
 
Index: code/trunk/src/orxonox/pickup/items/HealthUsable.cc
===================================================================
--- code/trunk/src/orxonox/pickup/items/HealthUsable.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/items/HealthUsable.cc	(revision 5929)
@@ -82,5 +82,5 @@
 
             this->removeFrom(pawn);
-            delete this;
+            this->destroy();
         }
     }
Index: code/trunk/src/orxonox/pickup/items/Jump.cc
===================================================================
--- code/trunk/src/orxonox/pickup/items/Jump.cc	(revision 5808)
+++ code/trunk/src/orxonox/pickup/items/Jump.cc	(revision 5929)
@@ -84,5 +84,5 @@
         {
             this->removeFrom(pawn);
-            delete this;
+            this->destroy();
         }
     }
Index: code/trunk/src/orxonox/sound/AmbientSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.cc	(revision 5929)
+++ code/trunk/src/orxonox/sound/AmbientSound.cc	(revision 5929)
@@ -0,0 +1,62 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "AmbientSound.h"
+
+#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+    CreateFactory(AmbientSound);
+
+    AmbientSound::AmbientSound(BaseObject* creator)
+        : BaseObject(creator)
+    {
+        RegisterObject(AmbientSound);
+    }
+
+    AmbientSound::~AmbientSound()
+    {
+    }
+
+    void AmbientSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(AmbientSound, XMLPort, xmlelement, mode);
+        XMLPortParamExtern(AmbientSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
+        XMLPortParamExtern(AmbientSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
+        XMLPortParamExtern(AmbientSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
+    }
+
+    void AmbientSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(AmbientSound, XMLEventPort, xmlelement, mode);
+        XMLPortEventState(AmbientSound, BaseObject, "play", play, xmlelement, mode);
+    }
+}
Index: code/trunk/src/orxonox/sound/AmbientSound.h
===================================================================
--- code/trunk/src/orxonox/sound/AmbientSound.h	(revision 5929)
+++ code/trunk/src/orxonox/sound/AmbientSound.h	(revision 5929)
@@ -0,0 +1,56 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _AmbientSound_H__
+#define _AmbientSound_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "core/BaseObject.h"
+#include "sound/BaseSound.h"
+
+namespace orxonox
+{
+    /**
+     * The AmbientSound class is the base class for all sound file loader classes.
+     * It server as main interface to the OpenAL library.
+     *
+     */
+    class _OrxonoxExport AmbientSound : public BaseSound, public BaseObject
+    {
+    public:
+        AmbientSound(BaseObject* creator);
+        virtual ~AmbientSound();
+
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+        virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
+    private:
+    };
+}
+
+#endif /* _AmbientSound_H__ */
Index: code/trunk/src/orxonox/sound/BaseSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/BaseSound.cc	(revision 5929)
+++ code/trunk/src/orxonox/sound/BaseSound.cc	(revision 5929)
@@ -0,0 +1,262 @@
+/*
+ *   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:
+ *      Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      Reto Grieder
+ *
+ */
+
+#include "BaseSound.h"
+
+#include <vector>
+#include <AL/alut.h>
+#include <vorbis/vorbisfile.h>
+
+#include "core/CoreIncludes.h"
+#include "core/GameMode.h"
+#include "core/Resource.h"
+
+namespace orxonox
+{
+    BaseSound::BaseSound()
+        : audioSource_(0)
+        , audioBuffer_(0)
+        , bPlayOnLoad_(false)
+        , bLoop_(false)
+    {
+        RegisterRootObject(BaseSound);
+    }
+
+    BaseSound::~BaseSound()
+    {
+        this->setSource("");
+    }
+
+    void BaseSound::play()
+    {
+        if (alIsSource(this->audioSource_))
+        {
+            if (this->bLoop_)
+                alSourcei(this->audioSource_, AL_LOOPING, AL_TRUE);
+            else
+                alSourcei(this->audioSource_, AL_LOOPING, AL_FALSE);
+            alSourcePlay(this->audioSource_);
+
+            if (alGetError() != AL_NO_ERROR)
+            {
+                 COUT(2) << "Sound: OpenAL: Error playin sound " << this->audioSource_ << std::endl;
+            }
+        }
+    }
+
+    void BaseSound::stop()
+    {
+        if (alIsSource(this->audioSource_))
+            alSourceStop(this->audioSource_);
+    }
+
+    void BaseSound::pause()
+    {
+        if (alIsSource(this->audioSource_))
+            alSourcePause(this->audioSource_);
+    }
+
+    bool BaseSound::isPlaying()
+    {
+        if (alIsSource(this->audioSource_))
+            return getSourceState() == AL_PLAYING;
+        return false;
+    }
+
+    bool BaseSound::isPaused()
+    {
+        if (alIsSource(this->audioSource_))
+            return getSourceState() == AL_PAUSED;
+        return true;
+    }
+
+    bool BaseSound::isStopped()
+    {
+        if (alIsSource(this->audioSource_))
+            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
+        return true;
+    }
+
+    void BaseSound::setPlayOnLoad(bool val)
+    {
+        this->bPlayOnLoad_ = true;
+        this->play();
+    }
+
+    void BaseSound::setSource(const std::string& source)
+    {
+        this->source_ = source;
+        if (!GameMode::playsSound())
+            return;
+
+        if (source.empty() && alIsSource(this->audioSource_))
+        {
+            // Unload sound
+            alSourcei(this->audioSource_, AL_BUFFER, 0);
+            alDeleteSources(1, &this->audioSource_);
+            alDeleteBuffers(1, &this->audioBuffer_);
+            return;
+        }
+
+        COUT(3) << "Sound: OpenAL ALUT: loading file " << source << std::endl;
+        // Get DataStream from the resources
+        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(source);
+        if (fileInfo == NULL)
+        {
+            COUT(2) << "Warning: Sound file '" << source << "' not found" << std::endl;
+            return;
+        }
+        dataStream_ = Resource::open(source);
+        // Read everything into a temporary buffer
+        char* buffer = new char[fileInfo->size];
+        dataStream_->read(buffer, fileInfo->size);
+        dataStream_->seek(0);
+
+        this->audioBuffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
+        delete[] buffer;
+
+        if (this->audioBuffer_ == AL_NONE)
+        {
+            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
+            if (source.find("ogg", 0) != std::string::npos)
+            {
+                COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
+                this->audioBuffer_ = loadOggFile();
+            }
+
+            if (this->audioBuffer_ == AL_NONE)
+            {
+                COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
+                return;
+            }
+        }
+
+        alGenSources(1, &this->audioSource_);
+        alSourcei(this->audioSource_, AL_BUFFER, this->audioBuffer_);
+        if (alGetError() != AL_NO_ERROR)
+        {
+            COUT(2) << "Sound: OpenAL: Error loading sample file: " << source << std::endl;
+            return;
+        }
+
+        alSource3f(this->audioSource_, AL_POSITION,  0, 0, 0);
+
+        if (this->bPlayOnLoad_)
+            this->play();
+    }
+
+    ALint BaseSound::getSourceState()
+    {
+        ALint state;
+        alGetSourcei(this->audioSource_, AL_SOURCE_STATE, &state);
+        return state;
+    }
+
+    size_t readVorbis(void* ptr, size_t size, size_t nmemb, void* datasource)
+    {
+        return static_cast<Ogre::DataStream*>(datasource)->read(ptr, size * nmemb);
+    }
+
+    int seekVorbis(void* datasource, ogg_int64_t offset, int whence)
+    {
+        Ogre::DataStream* stream = static_cast<Ogre::DataStream*>(datasource);
+        int offset_beg = offset;
+        if (whence == SEEK_CUR)
+            offset_beg = stream->tell() + offset;
+        else if (whence == SEEK_END)
+            offset_beg = stream->size() + offset;
+        else if (whence != SEEK_SET)
+            return -1;
+        stream->seek(offset_beg);
+        return 0;
+    }
+
+    long tellVorbis(void* datasource)
+    {
+        return static_cast<long>(static_cast<Ogre::DataStream*>(datasource)->tell());
+    }
+
+    ALuint BaseSound::loadOggFile()
+    {
+        char inbuffer[4096];
+        std::vector<char> outbuffer;
+        OggVorbis_File vf;
+        vorbis_info* vorbisInfo;
+        int eof = false;
+        int current_section;
+        ALuint buffer;
+        ALenum format;
+
+        // Open file with custom streaming
+        ov_callbacks vorbisCallbacks;
+        vorbisCallbacks.read_func  = &readVorbis;
+        vorbisCallbacks.seek_func  = &seekVorbis;
+        vorbisCallbacks.tell_func  = &tellVorbis;
+        vorbisCallbacks.close_func = NULL;
+
+        int ret = ov_open_callbacks(dataStream_.get(), &vf, NULL, 0, vorbisCallbacks);
+        if (ret < 0)
+        {
+            COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
+            ov_clear(&vf);
+            return AL_NONE;
+        }
+
+        while (!eof)
+        {
+            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
+            if (ret == 0)
+            {
+                eof = true;
+            }
+            else if (ret < 0)
+            {
+                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
+                ov_clear(&vf);
+                return AL_NONE;
+            }
+            else
+            {
+                outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer));
+            }
+        }
+
+        vorbisInfo = ov_info(&vf, -1);
+        if (vorbisInfo->channels == 1)
+            format = AL_FORMAT_MONO16;
+        else
+            format = AL_FORMAT_STEREO16;
+
+        alGenBuffers(1, &buffer);
+        alBufferData(buffer, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
+        ov_clear(&vf);
+
+        return buffer;
+    }
+
+} // namespace: orxonox
Index: code/trunk/src/orxonox/sound/BaseSound.h
===================================================================
--- code/trunk/src/orxonox/sound/BaseSound.h	(revision 5929)
+++ code/trunk/src/orxonox/sound/BaseSound.h	(revision 5929)
@@ -0,0 +1,83 @@
+/*
+ *   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:
+ *      Erwin 'vaiursch' Herrsche
+ *   Co-authors:
+ *      Reto Grieder
+ *
+ */
+#ifndef _BaseSound_H__
+#define _BaseSound_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <OgreSharedPtr.h>
+#include <OgreDataStream.h>
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+    /**
+     * The BaseSound class is the base class for all sound file loader classes.
+     * It server as main interface to the OpenAL library.
+     *
+     */
+    class _OrxonoxExport BaseSound : virtual public OrxonoxClass
+    {
+    public:
+        BaseSound();
+        virtual ~BaseSound();
+
+        void play();
+        void stop();
+        void pause();
+
+        bool isPlaying();
+        bool isPaused();
+        bool isStopped();
+
+        void setSource(const std::string& source);
+        const std::string& getSource() { return this->source_; }
+
+        bool getPlayOnLoad() { return this->bPlayOnLoad_; }
+        void setPlayOnLoad(bool val);
+
+        bool getLoop() { return this->bLoop_; }
+        void setLoop(bool val) { this->bLoop_ = val; }
+
+    protected:
+        ALuint loadOggFile();
+        ALint getSourceState();
+
+        ALuint audioSource_;
+        ALuint audioBuffer_;
+
+    private:
+        std::string source_;
+        bool bPlayOnLoad_;
+        bool bLoop_;
+        DataStreamPtr dataStream_;
+    };
+}
+
+#endif /* _BaseSound_H__ */
Index: code/trunk/src/orxonox/sound/CMakeLists.txt
===================================================================
--- code/trunk/src/orxonox/sound/CMakeLists.txt	(revision 5808)
+++ code/trunk/src/orxonox/sound/CMakeLists.txt	(revision 5929)
@@ -1,6 +1,7 @@
 ADD_SOURCE_FILES(ORXONOX_SRC_FILES
+    AmbientSound.cc
+    BaseSound.cc
     SoundManager.cc
-    SoundBase.cc
-    SoundMainMenu.cc
+    WorldSound.cc
 )
 
Index: code/trunk/src/orxonox/sound/SoundBase.cc
===================================================================
--- code/trunk/src/orxonox/sound/SoundBase.cc	(revision 5808)
+++ 	(revision )
@@ -1,240 +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:
- *       Erwin 'vaiursch' Herrsche
- *   Co-authors:
- *      ...
- *
- */
-
-#include "SoundBase.h"
-
-#include <string>
-#include <vector>
-#include <AL/alut.h>
-#include <vorbis/vorbisfile.h>
-
-#include "util/Math.h"
-#include "core/Core.h"
-#include "core/Resource.h"
-#include "worldentities/WorldEntity.h"
-#include "SoundManager.h"
-
-namespace orxonox
-{
-    SoundBase::SoundBase(WorldEntity* entity)
-    {
-        this->source_ = 0;
-        this->buffer_ = 0;
-        this->entity_ = entity;
-
-        SoundManager::getInstance().addSound(this);
-    }
-
-    SoundBase::~SoundBase()
-    {
-        alSourcei(this->source_, AL_BUFFER, 0);
-        alDeleteSources(1, &this->source_);
-        alDeleteBuffers(1, &this->buffer_);
-    }
-
-    void SoundBase::attachToEntity(WorldEntity* entity)
-    {
-        this->entity_ = entity;
-        this->update();
-    }
-
-    void SoundBase::update() {
-        if(this->entity_ != NULL && alIsSource(this->source_)) {
-            const Vector3& pos = this->entity_->getPosition();
-            alSource3f(this->source_, AL_POSITION, pos.x, pos.y, pos.z);
-            ALenum error = alGetError();
-            if(error == AL_INVALID_VALUE)
-                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
-
-            const Vector3& vel = this->entity_->getVelocity();
-            alSource3f(this->source_, AL_VELOCITY, vel.x, vel.y, vel.z);
-            error = alGetError();
-            if(error == AL_INVALID_VALUE)
-                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
-
-            const Quaternion& orient = this->entity_->getOrientation();
-            Vector3 at = orient.zAxis();
-            alSource3f(this->source_, AL_DIRECTION, at.x, at.y, at.z);
-            error = alGetError();
-            if(error == AL_INVALID_VALUE)
-                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
-        }
-    }
-
-    void SoundBase::play(bool loop) {
-        if(alIsSource(this->source_)) {
-            if(loop)
-                alSourcei(this->source_, AL_LOOPING, AL_TRUE);
-            else
-                alSourcei(this->source_, AL_LOOPING, AL_FALSE);
-            alSourcePlay(this->source_);
-
-            if(alGetError() != AL_NO_ERROR)
-            {
-                 COUT(2) << "Sound: OpenAL: Error playing sound " << this->source_ << std::endl;
-            }
-        }
-    }
-
-    void SoundBase::stop() {
-        if(alIsSource(this->source_)) {
-            alSourceStop(this->source_);
-        }
-    }
-
-    void SoundBase::pause() {
-        if(alIsSource(this->source_)) {
-            alSourcePause(this->source_);
-        }
-    }
-
-    bool SoundBase::isPlaying() {
-        if(alIsSource(this->source_)) {
-            return getSourceState() == AL_PLAYING;
-        }
-        return false;
-    }
-
-    bool SoundBase::isPaused() {
-        if(alIsSource(this->source_)) {
-            return getSourceState() == AL_PAUSED;
-        }
-        return true;
-    }
-
-    bool SoundBase::isStopped() {
-        if(alIsSource(this->source_)) {
-            return getSourceState() == AL_INITIAL || getSourceState() == AL_STOPPED;
-        }
-        return true;
-    }
-
-    bool SoundBase::loadFile(const std::string& filename) {
-        if(!SoundManager::getInstance().isSoundAvailable())
-        {
-            COUT(3) << "Sound: not available, skipping " << filename << std::endl;
-            return false;
-        }
-
-        COUT(3) << "Sound: OpenAL ALUT: loading file " << filename << std::endl;
-        // Get DataStream from the resources
-        shared_ptr<ResourceInfo> fileInfo = Resource::getInfo(filename);
-        if (fileInfo == NULL) {
-            COUT(2) << "Warning: Sound file '" << filename << "' not found" << std::endl;
-            return false;
-        }
-        DataStreamPtr stream = Resource::open(filename);
-        // Read everything into a temporary buffer
-        char* buffer = new char[fileInfo->size];
-        stream->read(buffer, fileInfo->size);
-
-        this->buffer_ = alutCreateBufferFromFileImage(buffer, fileInfo->size);
-        delete[] buffer;
-
-        if(this->buffer_ == AL_NONE) {
-            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
-            if(filename.find("ogg", 0) != std::string::npos)
-            {
-                COUT(2) << "Sound: Trying fallback ogg loader" << std::endl;
-                this->buffer_ = loadOggFile(filename);
-            }
-
-            if(this->buffer_ == AL_NONE)
-            {
-                COUT(2) << "Sound: fallback ogg loader failed: " << alutGetErrorString(alutGetError()) << std::endl;
-                return false;
-            }
-        }
-
-        alGenSources(1, &this->source_);
-        alSourcei(this->source_, AL_BUFFER, this->buffer_);
-        if(alGetError() != AL_NO_ERROR) {
-            COUT(2) << "Sound: OpenAL: Error loading sample file: " << filename << std::endl;
-            return false;
-        }
-        return true;
-    }
-
-    ALint SoundBase::getSourceState() {
-        ALint state;
-        alGetSourcei(this->source_, AL_SOURCE_STATE, &state);
-        return state;
-    }
-
-    ALuint SoundBase::loadOggFile(const std::string& filename)
-    {
-        char inbuffer[4096];
-        std::vector<char> outbuffer;
-        OggVorbis_File vf;
-        vorbis_info* vorbisInfo;
-        int eof = false;
-        int current_section;
-        ALuint buffer;
-        ALenum format;
-
-        FILE* f = fopen(filename.c_str(), "rb");
-
-        if(ov_open(f, &vf, NULL, 0) < 0)
-        {
-            COUT(2) << "Sound: libvorbisfile: File does not seem to be an Ogg Vorbis bitstream" << std::endl;
-            ov_clear(&vf);
-            return AL_NONE;
-        }
-
-        while(!eof)
-        {
-            long ret = ov_read(&vf, inbuffer, sizeof(inbuffer), 0, 2, 1, &current_section);
-            if (ret == 0)
-            {
-                eof = true;
-            }
-            else if (ret < 0)
-            {
-                COUT(2) << "Sound: libvorbisfile: error reading the file" << std::endl;
-                ov_clear(&vf);
-                return AL_NONE;
-            }
-            else
-            {
-                outbuffer.insert(outbuffer.end(), inbuffer, inbuffer + sizeof(inbuffer));
-            }
-        }
-
-        vorbisInfo = ov_info(&vf, -1);
-        if(vorbisInfo->channels == 1)
-            format = AL_FORMAT_MONO16;
-        else
-            format = AL_FORMAT_STEREO16;
-
-        alGenBuffers(1, &buffer);
-        alBufferData(buffer, format, &outbuffer[0], outbuffer.size(), vorbisInfo->rate);
-        ov_clear(&vf);
-
-        return buffer;
-    }
-} // namespace: orxonox
Index: code/trunk/src/orxonox/sound/SoundBase.h
===================================================================
--- code/trunk/src/orxonox/sound/SoundBase.h	(revision 5808)
+++ 	(revision )
@@ -1,69 +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:
- *       Erwin 'vaiursch' Herrsche
- *   Co-authors:
- *      ...
- *
- */
-#ifndef _SoundBase_H__
-#define _SoundBase_H__
-
-#include "OrxonoxPrereqs.h"
-#include <cstring> // define NULL
-
-namespace orxonox
-{
-    /**
-     * The SoundBase class is the base class for all sound file loader classes.
-     * It server as main interface to the OpenAL library.
-     *
-     */
-    class _OrxonoxExport SoundBase
-    {
-    public:
-        SoundBase(WorldEntity* entity = NULL);
-        ~SoundBase();
-
-        void attachToEntity(WorldEntity* entity);
-        void update();
-        void play(bool loop = false);
-        void stop();
-        void pause();
-
-        bool isPlaying();
-        bool isPaused();
-        bool isStopped();
-
-        bool loadFile(const std::string& filename);
-
-    private:
-        ALuint loadOggFile(const std::string& filename);
-        ALuint source_;
-        ALuint buffer_;
-        WorldEntity* entity_;
-
-        ALint getSourceState();
-    }; // class SoundBase
-} // namepsace orxonox
-
-#endif /* _SoundBase_H__ */
Index: code/trunk/src/orxonox/sound/SoundMainMenu.cc
===================================================================
--- code/trunk/src/orxonox/sound/SoundMainMenu.cc	(revision 5808)
+++ 	(revision )
@@ -1,47 +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:
- *       Erwin 'vaiursch' Herrsche
- *   Co-authors:
- *      ...
- *
- */
-
-#include "SoundMainMenu.h"
-
-#include "core/CoreIncludes.h"
-#include "core/ConfigValueIncludes.h"
-
-namespace orxonox
-{
-    SoundMainMenu::SoundMainMenu()
-    {
-        RegisterObject(SoundMainMenu);
-        setConfigValues();
-        loadFile(this->filename_);
-    }
-
-    void SoundMainMenu::setConfigValues()
-    {
-        SetConfigValue(filename_, "ambient/mainmenu.wav");
-    }
-}
Index: code/trunk/src/orxonox/sound/SoundMainMenu.h
===================================================================
--- code/trunk/src/orxonox/sound/SoundMainMenu.h	(revision 5808)
+++ 	(revision )
@@ -1,51 +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:
- *       Erwin 'vaiursch' Herrsche
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _SoundMainMenu_H__
-#define _SoundMainMenu_H__
-
-#include "OrxonoxPrereqs.h"
-
-#include <string>
-#include "core/OrxonoxClass.h"
-#include "SoundBase.h"
-
-namespace orxonox
-{
-    class _OrxonoxExport SoundMainMenu : public SoundBase, public virtual OrxonoxClass
-    {
-        public:
-            SoundMainMenu();
-            void setConfigValues();
-
-        private:
-            std::string filename_;
-    };
-}
-
-#endif /* _SoundMainMenu_H__ */
Index: code/trunk/src/orxonox/sound/SoundManager.cc
===================================================================
--- code/trunk/src/orxonox/sound/SoundManager.cc	(revision 5808)
+++ code/trunk/src/orxonox/sound/SoundManager.cc	(revision 5929)
@@ -31,63 +31,60 @@
 #include <AL/alut.h>
 
+#include "util/Exception.h"
 #include "util/Math.h"
-#include "CameraManager.h"
-#include "graphics/Camera.h"
-#include "SoundBase.h"
+#include "util/ScopeGuard.h"
+#include "core/GameMode.h"
+#include "core/ScopedSingletonManager.h"
 
 namespace orxonox
 {
     SoundManager* SoundManager::singletonPtr_s = NULL;
+    ManageScopedSingleton(SoundManager, ScopeID::Graphics, true);
 
-    /**
-     * Default constructor
-     */
     SoundManager::SoundManager()
     {
-        this->device_ = NULL;
-        this->soundavailable_ = true;
-        if(!alutInitWithoutContext(NULL,NULL))
+        if (!alutInitWithoutContext(NULL,NULL))
+            ThrowException(InitialisationFailed, "OpenAL ALUT error: " << alutGetErrorString(alutGetError()));
+        Loki::ScopeGuard alutExitGuard = Loki::MakeGuard(&alutExit);
+
+        COUT(3) << "OpenAL: Opening sound device..." << std::endl;
+        this->device_ = alcOpenDevice(NULL);
+        if (this->device_ == NULL)
         {
-            COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
-            this->soundavailable_ = false;
+            COUT(0) << "OpenaAL: Could not open sound device. Have you installed OpenAL?" << std::endl;
+#ifdef ORXONOX_PLATFORM_WINDOWS
+            COUT(0) << "Just getting the DLL with the dependencies is not enough for Windows (esp. Windows 7)!" << std::endl;
+#endif
+            ThrowException(InitialisationFailed, "OpenAL error: Could not open sound device.");
         }
+        Loki::ScopeGuard closeDeviceGuard = Loki::MakeGuard(&alcCloseDevice, this->device_);
+
+        COUT(3) << "OpenAL: Sound device opened" << std::endl;
+        this->context_ = alcCreateContext(this->device_, NULL);
+        if (this->context_ == NULL)
+            ThrowException(InitialisationFailed, "OpenAL error: Could not create sound context");
+        Loki::ScopeGuard desroyContextGuard = Loki::MakeGuard(&alcDestroyContext, this->context_);
+
+        if (alcMakeContextCurrent(this->context_) == AL_TRUE)
+            COUT(3) << "OpenAL: Context " << this->context_ << " loaded" << std::endl;
+
+        COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
+
+        const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
+        if (str == NULL)
+            COUT(2) << "OpenAL ALUT error: " << alutGetErrorString(alutGetError()) << std::endl;
         else
-        {
-            assert(this->device_ == NULL);
-            COUT(3) << "Sound: OpenAL: Open sound device..." << std::endl;
-            this->device_ = alcOpenDevice(NULL);
+            COUT(4) << "OpenAL ALUT supported MIME types: " << str << std::endl;
 
-            if(this->device_ == NULL)
-            {
-                COUT(2) << "Sound: OpenAL: Could not open sound device" << std::endl;
-                this->soundavailable_ = false;
-            }
-            else
-            {
-                COUT(3) << "Sound: OpenAL: Sound device opened" << std::endl;
-                this->context_ = alcCreateContext(this->device_, NULL);
-                if(this->context_ == NULL)
-                {
-                    COUT(2) << "Sound: OpenAL: Could not create sound context" << std::endl;
-                    this->soundavailable_ = false;
-                }
-                else
-                {
-                    if(alcMakeContextCurrent(this->context_) == AL_TRUE)
-                        COUT(3) << "Sound: OpenAL: Context " << this->context_ << " loaded" << std::endl;
-
-                    COUT(4) << "Sound: OpenAL ALUT version: " << alutGetMajorVersion() << "." << alutGetMinorVersion() << std::endl;
-                    const char* str = alutGetMIMETypes(ALUT_LOADER_BUFFER);
-                    if (str == NULL)
-                        COUT(2) << "Sound: OpenAL ALUT: " << alutGetErrorString(alutGetError()) << std::endl;
-                    else
-                        COUT(4) << "Sound: OpenAL ALUT supported MIME types: " << str << std::endl;
-                }
-            }
-        }
+        GameMode::setPlaysSound(true);
+        // Disarm guards
+        alutExitGuard.Dismiss();
+        closeDeviceGuard.Dismiss();
+        desroyContextGuard.Dismiss();
     }
 
     SoundManager::~SoundManager()
     {
+        GameMode::setPlaysSound(false);
         alcDestroyContext(this->context_);
         alcCloseDevice(this->device_);
@@ -95,74 +92,25 @@
     }
 
-    /**
-     * Add a SoundBase object to the list. Every SoundBase object should be in
-     * this list.
-     *
-     * @param sound Pointer to the SoundBase object to add
-     */
-    void SoundManager::addSound(SoundBase* sound)
+    void SoundManager::setListenerPosition(const Vector3& position)
     {
-        this->soundlist_.push_back(sound);
+        alListener3f(AL_POSITION, position.x, position.y, position.z);
+        ALenum error = alGetError();
+        if (error == AL_INVALID_VALUE)
+            COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
     }
 
-    /**
-     * Remove a SoundBase object from the list and destroy it.
-     */
-    void SoundManager::removeSound(SoundBase* sound)
+    void SoundManager::setListenerOrientation(const Quaternion& orientation)
     {
-        std::list<SoundBase*>::iterator pos = this->soundlist_.end();
-        for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
-        {
-            if((*i) == sound)
-                pos = i;
-        }
+        // update listener orientation
+        Vector3 up = orientation.xAxis(); // just a wild guess
+        Vector3 at = orientation.zAxis();
 
-        delete (*pos);
-        this->soundlist_.erase(pos);
-    }
+        ALfloat orient[6] = { at.x, at.y, at.z,
+                              up.x, up.y, up.z };
 
-    /**
-     * Tick function, updates listener and registred SoundBase objects
-     *
-     * @param dt @see Orxonox::Tickable
-     */
-    void SoundManager::tick(float dt)
-    {
-        if (!CameraManager::getInstancePtr())
-            return;
-
-        // update listener position
-        Camera* camera = CameraManager::getInstance().getActiveCamera();
-        if(camera == NULL) return;
-        Vector3 pos = camera->getPosition();
-        alListener3f(AL_POSITION, pos.x, pos.y, pos.z);
+        alListenerfv(AL_POSITION, orient);
         ALenum error = alGetError();
-        if(error == AL_INVALID_VALUE)
-            COUT(2) << "Sound: OpenAL: Invalid listener position" << std::endl;
-
-        // update listener orientation
-        const Quaternion& orient = camera->getOrientation();
-        Vector3 up = orient.xAxis(); // just a wild guess
-        Vector3 at = orient.zAxis();
-
-        ALfloat orientation[6] = { at.x, at.y, at.z,
-                                 up.x, up.y, up.z };
-
-        alListenerfv(AL_POSITION, orientation);
-        error = alGetError();
-        if(error == AL_INVALID_VALUE)
+        if (error == AL_INVALID_VALUE)
             COUT(2) << "Sound: OpenAL: Invalid listener orientation" << std::endl;
-
-        // update sounds
-        for(std::list<SoundBase*>::iterator i = this->soundlist_.begin(); i != this->soundlist_.end(); i++)
-            (*i)->update();
-    }
-
-    /**
-    * Check if sound is available
-    */
-    bool SoundManager::isSoundAvailable()
-    {
-        return this->soundavailable_;
     }
 }
Index: code/trunk/src/orxonox/sound/SoundManager.h
===================================================================
--- code/trunk/src/orxonox/sound/SoundManager.h	(revision 5808)
+++ code/trunk/src/orxonox/sound/SoundManager.h	(revision 5929)
@@ -39,9 +39,8 @@
     /**
      * The SoundManager class manages the OpenAL device, context and listener
-     * position. It has a list of all SoundBase objects and calls their update
-     * function every tick. It is a singleton.
+     * position. It is a singleton.
      *
      */
-    class _OrxonoxExport SoundManager : public Singleton<SoundManager>, public Tickable
+    class _OrxonoxExport SoundManager : public Singleton<SoundManager>
     {
         friend class Singleton<SoundManager>;
@@ -49,18 +48,15 @@
         SoundManager();
         ~SoundManager();
-        void addSound(SoundBase* sound);
-        void removeSound(SoundBase* sound);
-        void tick(float dt);
-        bool isSoundAvailable();
+
+        void setListenerPosition(const Vector3& position);
+        void setListenerOrientation(const Quaternion& orientation);
 
     private:
         ALCdevice* device_;
         ALCcontext* context_;
-        std::list<SoundBase*> soundlist_;
-        bool soundavailable_;
 
         static SoundManager* singletonPtr_s;
-    }; // class SoundManager
-} // namespace orxonox
+    };
+}
 
 #endif /* _SoundManager_H__ */
Index: code/trunk/src/orxonox/sound/WorldSound.cc
===================================================================
--- code/trunk/src/orxonox/sound/WorldSound.cc	(revision 5929)
+++ code/trunk/src/orxonox/sound/WorldSound.cc	(revision 5929)
@@ -0,0 +1,91 @@
+/*
+ *   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:
+ *      Erwin 'vaiursch' Herrsche
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "WorldSound.h"
+
+#include <AL/alut.h>
+#include "util/Math.h"
+#include "core/CoreIncludes.h"
+#include "core/EventIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+    CreateFactory(WorldSound);
+
+    WorldSound::WorldSound(BaseObject* creator)
+        : StaticEntity(creator)
+    {
+        RegisterObject(WorldSound);
+    }
+
+    WorldSound::~WorldSound()
+    {
+    }
+
+    void WorldSound::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WorldSound, XMLPort, xmlelement, mode);
+        XMLPortParamExtern(WorldSound, BaseSound, this, "source", setSource, getSource, xmlelement, mode);
+        XMLPortParamExtern(WorldSound, BaseSound, this, "loop", setLoop, getLoop, xmlelement, mode);
+        XMLPortParamExtern(WorldSound, BaseSound, this, "playOnLoad", setPlayOnLoad, getPlayOnLoad, xmlelement, mode);
+    }
+
+    void WorldSound::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(WorldSound, XMLEventPort, xmlelement, mode);
+        XMLPortEventState(WorldSound, BaseObject, "play", play, xmlelement, mode);
+    }
+
+    void WorldSound::tick(float dt)
+    {
+        if (alIsSource(this->audioSource_))
+        {
+            const Vector3& pos = this->getWorldPosition();
+            alSource3f(this->audioSource_, AL_POSITION, pos.x, pos.y, pos.z);
+            ALenum error = alGetError();
+            if (error == AL_INVALID_VALUE)
+                COUT(2) << "Sound: OpenAL: Invalid sound position" << std::endl;
+
+            const Vector3& vel = this->getVelocity();
+            alSource3f(this->audioSource_, AL_VELOCITY, vel.x, vel.y, vel.z);
+            error = alGetError();
+            if (error == AL_INVALID_VALUE)
+                COUT(2) << "Sound: OpenAL: Invalid sound velocity" << std::endl;
+
+            const Quaternion& orient = this->getWorldOrientation();
+            Vector3 at = orient.zAxis();
+            alSource3f(this->audioSource_, AL_DIRECTION, at.x, at.y, at.z);
+            error = alGetError();
+            if (error == AL_INVALID_VALUE)
+                COUT(2) << "Sound: OpenAL: Invalid sound direction" << std::endl;
+        }
+    }
+
+}
Index: code/trunk/src/orxonox/sound/WorldSound.h
===================================================================
--- code/trunk/src/orxonox/sound/WorldSound.h	(revision 5929)
+++ code/trunk/src/orxonox/sound/WorldSound.h	(revision 5929)
@@ -0,0 +1,58 @@
+/*
+ *   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:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+#ifndef _WorldSound_H__
+#define _WorldSound_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "tools/interfaces/Tickable.h"
+#include "sound/BaseSound.h"
+#include "worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+    /*
+    @brief
+        The WorldSound class is to be used for sounds with position and orientation.
+    */
+    class _OrxonoxExport WorldSound : public StaticEntity, public BaseSound, public Tickable
+    {
+    public:
+        WorldSound(BaseObject* creator);
+        virtual ~WorldSound();
+
+        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+        virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
+        virtual void tick(float dt);
+
+    private:
+    };
+}
+
+#endif /* _WorldSound_H__ */
Index: code/trunk/src/orxonox/weaponsystem/Munition.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/Munition.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/Munition.cc	(revision 5929)
@@ -461,8 +461,8 @@
         if (bUseReloadTime && (munition->reloadTime_ > 0 || munition->bStackMunition_))
         {
-            ExecutorMember<Magazine>* executor = createExecutor(createFunctor(&Magazine::loaded));
+            Executor* executor = createExecutor(createFunctor(&Magazine::loaded, this));
             executor->setDefaultValues(munition);
 
-            this->loadTimer_.setTimer(munition->reloadTime_, false, this, executor);
+            this->loadTimer_.setTimer(munition->reloadTime_, false, executor);
         }
         else
Index: code/trunk/src/orxonox/weaponsystem/Munition.h
===================================================================
--- code/trunk/src/orxonox/weaponsystem/Munition.h	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/Munition.h	(revision 5929)
@@ -47,5 +47,5 @@
 
                 unsigned int munition_;
-                Timer<Magazine> loadTimer_;
+                Timer loadTimer_;
                 bool bLoaded_;
 
Index: code/trunk/src/orxonox/weaponsystem/Weapon.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/Weapon.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/Weapon.cc	(revision 5929)
@@ -50,5 +50,5 @@
         this->reloadingWeaponmode_ = WeaponSystem::WEAPON_MODE_UNASSIGNED;
 
-        this->reloadTimer_.setTimer(0.0f, false, this, createExecutor(createFunctor(&Weapon::reloaded)));
+        this->reloadTimer_.setTimer(0.0f, false, createExecutor(createFunctor(&Weapon::reloaded, this)));
         this->reloadTimer_.stopTimer();
     }
@@ -62,5 +62,5 @@
 
             for (std::multimap<unsigned int, WeaponMode*>::iterator it = this->weaponmodes_.begin(); it != this->weaponmodes_.end(); ++it)
-                delete it->second;
+                it->second->destroy();
         }
     }
Index: code/trunk/src/orxonox/weaponsystem/Weapon.h
===================================================================
--- code/trunk/src/orxonox/weaponsystem/Weapon.h	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/Weapon.h	(revision 5929)
@@ -71,5 +71,5 @@
             std::multimap<unsigned int, WeaponMode*> weaponmodes_;
 
-            Timer<Weapon> reloadTimer_;
+            Timer reloadTimer_;
             bool bReloading_;
             unsigned int reloadingWeaponmode_;
Index: code/trunk/src/orxonox/weaponsystem/WeaponMode.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponMode.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/WeaponMode.cc	(revision 5929)
@@ -57,5 +57,5 @@
         this->bParallelReload_ = true;
 
-        this->reloadTimer_.setTimer(0.0f, false, this, createExecutor(createFunctor(&WeaponMode::reloaded)));
+        this->reloadTimer_.setTimer(0.0f, false, createExecutor(createFunctor(&WeaponMode::reloaded, this)));
         this->reloadTimer_.stopTimer();
 
Index: code/trunk/src/orxonox/weaponsystem/WeaponMode.h
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponMode.h	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/WeaponMode.h	(revision 5929)
@@ -36,5 +36,5 @@
 #include "util/Math.h"
 #include "core/BaseObject.h"
-#include "core/Identifier.h"
+#include "core/SubclassIdentifier.h"
 #include "tools/Timer.h"
 
@@ -150,5 +150,5 @@
             std::string munitionname_;
 
-            Timer<WeaponMode> reloadTimer_;
+            Timer reloadTimer_;
             bool bReloading_;
     };
Index: code/trunk/src/orxonox/weaponsystem/WeaponPack.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponPack.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/WeaponPack.cc	(revision 5929)
@@ -54,8 +54,8 @@
 
             while (!this->weapons_.empty())
-                delete (*this->weapons_.begin());
+                (*this->weapons_.begin())->destroy();
 
             for (std::set<DefaultWeaponmodeLink*>::iterator it = this->links_.begin(); it != this->links_.end(); )
-                delete (*(it++));
+                (*(it++))->destroy();
         }
     }
Index: code/trunk/src/orxonox/weaponsystem/WeaponSlot.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponSlot.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/WeaponSlot.cc	(revision 5929)
@@ -46,5 +46,5 @@
         this->weapon_ = 0;
 
-        this->setObjectMode(0x0);
+        this->setSyncMode(0x0);
     }
 
Index: code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc
===================================================================
--- code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc	(revision 5808)
+++ code/trunk/src/orxonox/weaponsystem/WeaponSystem.cc	(revision 5929)
@@ -62,14 +62,14 @@
 
             while (!this->weaponSets_.empty())
-                delete (this->weaponSets_.begin()->second);
+                this->weaponSets_.begin()->second->destroy();
 
             while (!this->weaponPacks_.empty())
-                delete (*this->weaponPacks_.begin());
+                (*this->weaponPacks_.begin())->destroy();
 
             while (!this->weaponSlots_.empty())
-                delete (*this->weaponSlots_.begin());
+                (*this->weaponSlots_.begin())->destroy();
 
             while (!this->munitions_.empty())
-                { delete (this->munitions_.begin()->second); this->munitions_.erase(this->munitions_.begin()); }
+                { this->munitions_.begin()->second->destroy(); this->munitions_.erase(this->munitions_.begin()); }
         }
     }
Index: code/trunk/src/orxonox/worldentities/BigExplosion.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/BigExplosion.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/BigExplosion.cc	(revision 5929)
@@ -90,5 +90,5 @@
             this->setVelocity(velocity);
 
-            this->destroyTimer_.setTimer(rnd(2, 4), false, this, createExecutor(createFunctor(&BigExplosion::stop)));
+            this->destroyTimer_.setTimer(rnd(2, 4), false, createExecutor(createFunctor(&BigExplosion::stop, this)));
         }
         this->registerVariables();
@@ -226,10 +226,10 @@
             {
                 this->debris1_->detachOgreObject(this->debrisFire1_->getParticleSystem());
-                delete this->debrisFire1_;
+                this->debrisFire1_->destroy();
             }
             if (this->debrisSmoke1_)
             {
                 this->debris1_->detachOgreObject(this->debrisSmoke1_->getParticleSystem());
-                delete this->debrisSmoke1_;
+                this->debrisSmoke1_->destroy();
             }
 
@@ -237,10 +237,10 @@
             {
                 this->debris2_->detachOgreObject(this->debrisFire2_->getParticleSystem());
-                delete this->debrisFire2_;
+                this->debrisFire2_->destroy();
             }
             if (this->debrisSmoke2_)
             {
                 this->debris2_->detachOgreObject(this->debrisSmoke2_->getParticleSystem());
-                delete this->debrisSmoke2_;
+                this->debrisSmoke2_->destroy();
             }
 
@@ -248,10 +248,10 @@
             {
                 this->debris3_->detachOgreObject(this->debrisFire3_->getParticleSystem());
-                delete this->debrisFire3_;
+                this->debrisFire3_->destroy();
             }
             if (this->debrisSmoke3_)
             {
                 this->debris3_->detachOgreObject(this->debrisSmoke3_->getParticleSystem());
-                delete this->debrisSmoke3_;
+                this->debrisSmoke3_->destroy();
             }
 
@@ -259,10 +259,10 @@
             {
                 this->debris4_->detachOgreObject(this->debrisFire4_->getParticleSystem());
-                delete this->debrisFire4_;
+                this->debrisFire4_->destroy();
             }
             if (this->debrisSmoke4_)
             {
                 this->debris4_->detachOgreObject(this->debrisSmoke4_->getParticleSystem());
-                delete this->debrisSmoke4_;
+                this->debrisSmoke4_->destroy();
             }
         }
@@ -329,11 +329,6 @@
         {
             this->bStop_ = true;
-            this->destroyTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&BigExplosion::destroy)));
-        }
-    }
-
-    void BigExplosion::destroy()
-    {
-        delete this;
+            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&BigExplosion::destroy, this)));
+        }
     }
 
Index: code/trunk/src/orxonox/worldentities/BigExplosion.h
===================================================================
--- code/trunk/src/orxonox/worldentities/BigExplosion.h	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/BigExplosion.h	(revision 5929)
@@ -57,5 +57,4 @@
             void checkStop();
             void stop();
-            void destroy();
             void init();
             void initZero();
@@ -98,6 +97,6 @@
             ParticleInterface*    explosionFire_;
 
-            LODParticle::Value      LOD_;
-            Timer<BigExplosion> destroyTimer_;
+            LODParticle::Value    LOD_;
+            Timer                 destroyTimer_;
     };
 }
Index: code/trunk/src/orxonox/worldentities/CameraPosition.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/CameraPosition.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/CameraPosition.cc	(revision 5929)
@@ -46,5 +46,5 @@
         this->bRenderCamera_ = false;
 
-        this->setObjectMode(0x0);
+        this->setSyncMode(0x0);
     }
 
Index: code/trunk/src/orxonox/worldentities/ControllableEntity.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/ControllableEntity.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/ControllableEntity.cc	(revision 5929)
@@ -96,14 +96,14 @@
 
             if (this->xmlcontroller_)
-                delete this->xmlcontroller_;
+                this->xmlcontroller_->destroy();
 
             if (this->hud_)
-                delete this->hud_;
+                this->hud_->destroy();
 
             if (this->camera_)
-                delete this->camera_;
-
-            for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
-                delete (*it);
+                this->camera_->destroy();
+
+            for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+                (*it)->destroy();
 
             if (this->getScene()->getSceneManager())
@@ -153,5 +153,5 @@
     {
         unsigned int i = 0;
-        for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+        for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
         {
             if (i == index)
@@ -172,5 +172,5 @@
             else if (this->cameraPositions_.size() > 0)
             {
-                for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+                for (std::list<SmartPtr<CameraPosition> >::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
                 {
                     if ((*it) == this->camera_->getParent())
@@ -238,5 +238,5 @@
             {
                 this->client_overwrite_ = this->server_overwrite_;
-                this->setObjectMode(ObjectDirection::Bidirectional);
+                this->setSyncMode(ObjectDirection::Bidirectional);
             }
         }
@@ -254,10 +254,10 @@
         this->bHasLocalController_ = false;
         this->bHasHumanController_ = false;
-        this->setObjectMode(ObjectDirection::ToClient);
+        this->setSyncMode(ObjectDirection::ToClient);
 
         this->changedPlayer();
 
         if (this->bDestroyWhenPlayerLeft_)
-            delete this;
+            this->destroy();
     }
 
@@ -275,5 +275,5 @@
     void ControllableEntity::startLocalHumanControl()
     {
-        if (!this->camera_)
+        if (!this->camera_ && GameMode::showsGraphics())
         {
             this->camera_ = new Camera(this);
@@ -287,5 +287,5 @@
         }
 
-        if (!this->hud_)
+        if (!this->hud_ && GameMode::showsGraphics())
         {
             if (this->hudtemplate_ != "")
@@ -303,5 +303,5 @@
         {
             this->camera_->detachFromParent();
-            delete this->camera_;
+            this->camera_->destroy();
             this->camera_ = 0;
         }
@@ -309,5 +309,5 @@
         if (this->hud_)
         {
-            delete this->hud_;
+            this->hud_->destroy();
             this->hud_ = 0;
         }
@@ -333,5 +333,5 @@
         if (parent)
         {
-            for (std::list<CameraPosition*>::iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
+            for (std::list<SmartPtr<CameraPosition> >::iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
                 if ((*it)->getIsAbsolute())
                     parent->attach((*it));
Index: code/trunk/src/orxonox/worldentities/ControllableEntity.h
===================================================================
--- code/trunk/src/orxonox/worldentities/ControllableEntity.h	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/ControllableEntity.h	(revision 5929)
@@ -104,5 +104,5 @@
             void addCameraPosition(CameraPosition* position);
             CameraPosition* getCameraPosition(unsigned int index) const;
-            inline const std::list<CameraPosition*>& getCameraPositions() const
+            inline const std::list<SmartPtr<CameraPosition> >& getCameraPositions() const
                 { return this->cameraPositions_; }
 
@@ -198,5 +198,5 @@
             float mouseLookSpeed_;
             Ogre::SceneNode* cameraPositionRootNode_;
-            std::list<CameraPosition*> cameraPositions_;
+            std::list<SmartPtr<CameraPosition> > cameraPositions_;
             std::string cameraPositionTemplate_;
             Controller* xmlcontroller_;
Index: code/trunk/src/orxonox/worldentities/ExplosionChunk.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/ExplosionChunk.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/ExplosionChunk.cc	(revision 5929)
@@ -79,5 +79,5 @@
             this->setVelocity(velocity);
 
-            this->destroyTimer_.setTimer(rnd(1, 2), false, this, createExecutor(createFunctor(&ExplosionChunk::stop)));
+            this->destroyTimer_.setTimer(rnd(1, 2), false, createExecutor(createFunctor(&ExplosionChunk::stop, this)));
         }
 
@@ -92,10 +92,10 @@
             {
                 this->detachOgreObject(this->fire_->getParticleSystem());
-                delete this->fire_;
+                this->fire_->destroy();
             }
             if (this->smoke_)
             {
                 this->detachOgreObject(this->smoke_->getParticleSystem());
-                delete this->smoke_;
+                this->smoke_->destroy();
             }
         }
@@ -132,11 +132,6 @@
         {
             this->bStop_ = true;
-            this->destroyTimer_.setTimer(1.0f, false, this, createExecutor(createFunctor(&ExplosionChunk::destroy)));
+            this->destroyTimer_.setTimer(1.0f, false, createExecutor(createFunctor(&ExplosionChunk::destroy, this)));
         }
-    }
-
-    void ExplosionChunk::destroy()
-    {
-        delete this;
     }
 
Index: code/trunk/src/orxonox/worldentities/ExplosionChunk.h
===================================================================
--- code/trunk/src/orxonox/worldentities/ExplosionChunk.h	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/ExplosionChunk.h	(revision 5929)
@@ -55,11 +55,10 @@
             void checkStop();
             void stop();
-            void destroy();
 
             bool                  bStop_;
             ParticleInterface*    fire_;
             ParticleInterface*    smoke_;
-            LODParticle::Value      LOD_;
-            Timer<ExplosionChunk> destroyTimer_;
+            LODParticle::Value    LOD_;
+            Timer                 destroyTimer_;
     };
 }
Index: code/trunk/src/orxonox/worldentities/MovableEntity.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/MovableEntity.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/MovableEntity.cc	(revision 5929)
@@ -61,5 +61,5 @@
         if (this->isInitialized())
             if (this->continuousResynchroTimer_)
-                delete this->continuousResynchroTimer_;
+                this->continuousResynchroTimer_->destroy();
     }
 
@@ -98,5 +98,5 @@
     void MovableEntity::clientConnected(unsigned int clientID)
     {
-        this->resynchronizeTimer_.setTimer(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize)));
+        this->resynchronizeTimer_.setTimer(rnd() * MAX_RESYNCHRONIZE_TIME, false, createExecutor(createFunctor(&MovableEntity::resynchronize, this)));
     }
 
@@ -110,6 +110,6 @@
         {
             // Resynchronise every few seconds because we only work with velocities (no positions)
-            continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1),
-                true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
+            continuousResynchroTimer_ = new Timer(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1),
+                true, createExecutor(createFunctor(&MovableEntity::resynchronize, this)), false);
         }
 
Index: code/trunk/src/orxonox/worldentities/MovableEntity.h
===================================================================
--- code/trunk/src/orxonox/worldentities/MovableEntity.h	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/MovableEntity.h	(revision 5929)
@@ -96,6 +96,6 @@
             Quaternion overwrite_orientation_;
 
-            Timer<MovableEntity> resynchronizeTimer_;
-            Timer<MovableEntity>* continuousResynchroTimer_;
+            Timer resynchronizeTimer_;
+            Timer* continuousResynchroTimer_;
 
             Pawn* owner_;
Index: code/trunk/src/orxonox/worldentities/SpawnPoint.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/SpawnPoint.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/SpawnPoint.cc	(revision 5929)
@@ -50,5 +50,5 @@
             COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl;
 
-        this->setObjectMode(0x0);
+        this->setSyncMode(0x0);
     }
 
Index: code/trunk/src/orxonox/worldentities/SpawnPoint.h
===================================================================
--- code/trunk/src/orxonox/worldentities/SpawnPoint.h	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/SpawnPoint.h	(revision 5929)
@@ -33,5 +33,5 @@
 
 #include <string>
-#include "core/Identifier.h"
+#include "core/SubclassIdentifier.h"
 #include "worldentities/StaticEntity.h"
 
Index: code/trunk/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/WorldEntity.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/WorldEntity.cc	(revision 5929)
@@ -119,5 +119,5 @@
             {
                 if ((*it)->getDeleteWithParent())
-                    delete (*(it++));
+                    (*(it++))->destroy();
                 else
                 {
@@ -132,5 +132,5 @@
                 delete this->physicalBody_;
             }
-            delete this->collisionShape_;
+            this->collisionShape_->destroy();
 
             this->node_->detachAllObjects();
@@ -175,5 +175,5 @@
     void WorldEntity::registerVariables()
     {
-        registerVariable(this->mainStateName_,  VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState));
+        registerVariable(this->mainStateName_,  VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainStateName));
 
         registerVariable(this->bActive_,        VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
Index: code/trunk/src/orxonox/worldentities/pawns/Destroyer.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Destroyer.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/pawns/Destroyer.cc	(revision 5929)
@@ -40,5 +40,5 @@
         RegisterObject(Destroyer);
 
-        UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype());
+        UnderAttack* gametype = orxonox_cast<UnderAttack*>(this->getGametype().get());
         if (gametype)
         {
Index: code/trunk/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/pawns/Pawn.cc	(revision 5929)
@@ -36,5 +36,4 @@
 #include "network/NetworkFunction.h"
 
-#include "interfaces/PawnListener.h"
 #include "PawnManager.h"
 #include "infos/PlayerInfo.h"
@@ -93,9 +92,6 @@
         if (this->isInitialized())
         {
-            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
-                it->destroyedPawn(this);
-
             if (this->weaponSystem_)
-                delete this->weaponSystem_;
+                this->weaponSystem_->destroy();
         }
     }
Index: code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/pawns/SpaceShip.cc	(revision 5929)
@@ -75,5 +75,5 @@
     {
         if (this->isInitialized() && this->engine_)
-            delete this->engine_;
+            this->engine_->destroy();
     }
 
@@ -207,5 +207,5 @@
                     else
                     {
-                        delete object;
+                        object->destroy();
                     }
                 }
Index: code/trunk/src/orxonox/worldentities/pawns/Spectator.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Spectator.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/pawns/Spectator.cc	(revision 5929)
@@ -145,5 +145,5 @@
         ControllableEntity::setPlayer(player);
 
-//        this->setObjectMode(ObjectDirection::ToClient);
+//        this->setSyncMode(ObjectDirection::ToClient);
     }
 
Index: code/trunk/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc	(revision 5808)
+++ code/trunk/src/orxonox/worldentities/pawns/TeamBaseMatchBase.cc	(revision 5929)
@@ -31,5 +31,5 @@
 
 #include "core/CoreIncludes.h"
-#include "interfaces/PawnListener.h"
+#include "controllers/ArtificialController.h"
 #include "interfaces/TeamColourable.h"
 #include "gametypes/TeamBaseMatch.h"
@@ -45,5 +45,5 @@
         this->state_ = BaseState::Uncontrolled;
 
-        TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype());
+        TeamBaseMatch* gametype = orxonox_cast<TeamBaseMatch*>(this->getGametype().get());
         if (gametype)
         {
@@ -58,5 +58,5 @@
         this->fireEvent();
 
-        TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype());
+        TeamDeathmatch* gametype = orxonox_cast<TeamDeathmatch*>(this->getGametype().get());
         if (!gametype)
             return;
@@ -92,6 +92,6 @@
 
         // Call this so bots stop shooting at the base after they converted it
-        for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
-            it->destroyedPawn(this);
+        for (ObjectList<ArtificialController>::iterator it = ObjectList<ArtificialController>::begin(); it != ObjectList<ArtificialController>::end(); ++it)
+            it->abandonTarget(this);
     }
 }
