Index: /code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua
===================================================================
--- /code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua	(revision 9156)
+++ /code/branches/shipSelection/data/gui/scripts/ShipSelectionMenu.lua	(revision 9157)
@@ -6,5 +6,5 @@
 P.shipList = {}
 function P.onLoad()
-   --orxonox.execute("orxout internal_warning Ships= " .. selectedlevel:hasShip("abcdef"))
+   --orxonox.execute("orxout user_warning Ships= " .. selectedlevel:hasShip("abcdef"))
    local dircmd = "ls ../levels/templates/ -l | awk '{print $9}' | grep \"spaceship\" | sed -e 's/\\.[a-zA-Z]*$//'" -- go to spaceships folder and generate a list of installed shipmodels.
    os.execute(dircmd .. " > ../levels/templates/.shipmodels") --saves output in a textfile
@@ -16,23 +16,11 @@
 
    P.shipList = {}
+   for line in io.lines("../levels/templates/.shipmodels") do  
+	if selectedlevel:hasShip(string.lower(line)) then
+		P.shipList[#P.shipList+1] = string.lower(line)
+	end
+   end 
+   P.createFilterTab("Show All")
 
-  --for line in io.lines("../levels/templates/.shipmodels") do  orxonox.execute("orxout user_warning " .. line) end
-  for line in io.lines("../levels/templates/.shipmodels") do  
-	P.shipList[#P.shipList+1] = string.lower(line)
-  end 
-   --[[for f in io.lines("../levels/templates/.shipmodels") do
-        if selectedlevel:hasShip(f) then
-            P.shipList[#P.shipList+1] = f
-            table.insert(P.shipList, f)
-        end
-    end--]]
-    P.shipList[1]="spaceshipAssff"
-    P.shipList[2]="spaceshipGhost"
-    P.shipList[3]="spaceshipPirate"
-    P.createFilterTab("Show All")
-    --[[list = winMgr:createWindow("MenuWidgets/Listbox", "listbox")
-    item = CEGUI.createListboxTextItem("Text")
-    CEGUI.toListbox(list):addItem(item)
-    list:enable()--]]
 end
 
@@ -45,41 +33,4 @@
 
 function P.createFilterTab(name)
-
- --[[-- create unique tab window name
-    orxonox.execute("orxout user_warning test")
-    local tabName = "orxonox/SchipSelectionLevelTab"
-    -- create new tab window with desired name
-    local listbox = CEGUI.toListbox(winMgr:createWindow("MenuWidgets/Listbox", tabName))
-    listbox:setText(name)
-    listbox:setProperty("UnifiedMaxSize", "{{1,0},{1,0}}")
-    listbox:setProperty("UnifiedAreaRect", "{{0.05,0},{0.1,0},{0.5,0},{0.675,0}}")
-    -- fill listbox with items
-    listbox:resetList()
-    orxonox.GUIManager:setItemTooltipsEnabledHelper(listbox, true)
-    local preselect = "spaceshipAssff"
-    local tabIndexes = {}
-    for k,v in pairs(P.shipList) do
-    --for i = 1 ,#P.shipList,1 do
-        -- only add level if it has desired tag
-         --if v:hasShip(Ship) then
-            local item = CEGUI.createListboxTextItem("asbsergse")
-            item:setSelectionBrushImage(menuImageSet, "MultiListSelectionBrush")
-            listbox:addItem(item)
-            table.insert(tabIndexes, k)
-            if v:getXMLFilename() == preselect then
-                listbox:setItemSelectState(item, true)
-            end
-            --orxonox.GUIManager:setTooltipTextHelper(item, v:getDescription())
-       -- end
-    end
-    table.insert(P.activeTabIndexes, tabIndexes)
-    -- listen to selection changes
-    orxonox.GUIManager:subscribeEventHelper(listbox, "ItemSelectionChanged", P.name..".SingleplayerSelectionChanged")
-    local tabControl = winMgr:getWindow("orxonox/SingleplayerTabControl")
-    orxonox.GUIManager:subscribeEventHelper(tabControl, "TabSelectionChanged", P.name..".SingleplayerSelectionChanged")
-    if listbox:getItemCount() > 0 then
-        tabControl:addChildWindow(tabName)
-    end--]]
-    -- create unique tab window name
 
     local tabName = "orxonox/ShipSelectionLevelTab"
@@ -117,5 +68,5 @@
 end
 
-function P.ShipSelectionGetSelectedLevel()
+function P.ShipSelectionGetSelectedModel()
     -- choose the active listbox
     local tabControl = CEGUI.toTabControl(winMgr:getWindow("orxonox/ShipSelectionTabControl"))
@@ -126,5 +77,5 @@
         local tabIndexes = P.activeTabIndexes[tabControl:getSelectedTabIndex()+1]
         local index = tabIndexes[listbox:getItemIndex(choice)+1]
-        --return P.levelList[index]
+        return P.shipList[index]
     else
         return nil
@@ -136,17 +87,17 @@
     local levelDescription = winMgr:getWindow("orxonox/ShipSelectionLevelDescription")
     local configButton = winMgr:getWindow("orxonox/ShipSelectionConfigButton")
-    local level = P.ShipSelectionGetSelectedLevel()
+    local level = P.ShipSelectionGetSelectedModel()
     if level ~= nil then
-        local levelXMLFilename = level:getXMLFilename()
-        local imageName = level:getScreenshot()
+        --local levelXMLFilename = selectedlevel:getXMLFilename()
+        --local imageName = selectedlevel:getScreenshot()
         -- set the screenshot and the description for the selected level
-        levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
-        levelDescription:setText(level:getDescription())
+        --levelImage:setProperty("Image", "set:"..levelXMLFilename..imageName.." image:full_image")
+        --levelDescription:setText(level:getDescription())
         -- only enable config button for "gametype" levels
-        if level:hasTag("gametype") then
-            configButton:setProperty("Disabled", "False")
-        else
-            configButton:setProperty("Disabled", "True")
-        end
+        --if level:hasTag("gametype") then
+         --   configButton:setProperty("Disabled", "False")
+        --else
+        --    configButton:setProperty("Disabled", "True")
+        --end
     else
         -- also take care of "no level selected"
@@ -160,5 +111,5 @@
 
     if selectedlevel ~= nil then
-	selectedlevel:selectShip(P.ShipSelectionGetSelectedLevel())
+	selectedlevel:selectShip(P.ShipSelectionGetSelectedModel())
         orxonox.execute("startGame " .. "_temp.oxw")
         hideAllMenuSheets()
@@ -170,5 +121,5 @@
 function P.ShipSelectionConfigButton_clicked(e)
 --[[
-    local level = P.ShipSelectionGetSelectedLevel()
+    local level = P.ShipSelectionGetSelectedModel()
     if level ~= nil then
         local configMenu = showMenuSheet("ShipSelectionConfigMenu")
Index: /code/branches/shipSelection/data/levels/tutorial.oxw
===================================================================
--- /code/branches/shipSelection/data/levels/tutorial.oxw	(revision 9156)
+++ /code/branches/shipSelection/data/levels/tutorial.oxw	(revision 9157)
@@ -4,5 +4,5 @@
  tags = "tutorial, shipselection"
  screenshot = "codingtutorial.png"
- startingships = "spaceshipAssff, spaceshipGhost, spaceshipSpacecruiser"
+ startingships = "spaceshipassff, spaceshipghost, spaceshipspacecruiser"
 />
 
Index: /code/branches/shipSelection/src/orxonox/LevelInfo.cc
===================================================================
--- /code/branches/shipSelection/src/orxonox/LevelInfo.cc	(revision 9156)
+++ /code/branches/shipSelection/src/orxonox/LevelInfo.cc	(revision 9157)
@@ -163,7 +163,8 @@
     bool LevelInfoItem::addShip(const std::string& ship, bool update)
     {
-        bool success = this->tags_.insert(ship).second;
+        bool success = this->ships_.insert(ship).second;
         if(update && success)
-            this->tagsUpdated();
+            this->shipsUpdated();
+            
         return success;
     }
Index: /code/branches/shipSelection/src/orxonox/ShipManager.cc
===================================================================
--- /code/branches/shipSelection/src/orxonox/ShipManager.cc	(revision 9157)
+++ /code/branches/shipSelection/src/orxonox/ShipManager.cc	(revision 9157)
@@ -0,0 +1,202 @@
+/*
+ *   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:
+ *      Damian 'Mozork' Frick
+ *
+ */
+
+/**
+    @file LevelManager.cc
+    @brief Implementation of the LevelManager singleton.
+*/
+
+#include "LevelManager.h"
+
+#include <map>
+
+#include "util/ScopedSingletonManager.h"
+#include "core/ClassTreeMask.h"
+#include "core/CommandLineParser.h"
+#include "core/ConfigValueIncludes.h"
+#include "core/CoreIncludes.h"
+#include "core/Loader.h"
+#include "core/Resource.h"
+#include "core/XMLFile.h"
+#include "Level.h"
+#include "PlayerManager.h"
+
+namespace orxonox
+{
+    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
+
+    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
+
+    /**
+    @brief
+        Constructor.
+    */
+    ShipManager::ShipManager()
+    {
+        RegisterRootObject(LevelManager);
+        this->compileAvailableLevelList();
+        this->nextIndex_ = 0;
+        this->nextLevel_ = this->availableLevels_.begin();
+    }
+
+    ShipManager::~ShipManager()
+    {
+        // Delete all the Ship objects because the LevelManager created them
+        std::set<SpaceShip*, LevelInfoCompare>::iterator it = availableLevels_.begin();
+        for (; it != availableLevels_.end(); ++it)
+            delete *it;
+    }
+
+   
+    /**
+    @brief
+        Get the number of available Ships.
+    @return
+        Returns the number of available Ships.
+    */
+    unsigned int LevelManager::getNumberOfLevels(){ return this->availableLevels_.size(); }
+
+    /**
+    @brief
+        Get the SpaceShip at the given index in the list of available Ships.
+        The SpaceShips are sorted in alphabetical order accoridng to the name of the Ship.
+        This method is most efficiently called with consecutive indices (or at least ascending indices).
+    @param index
+        The index of the item that should be returned.
+    @return
+        Returns a pointer to the SpaceShip at the given index.
+    */
+    SpaceShip* ShipManager::getAvailableShipListItem(unsigned int index)
+    {
+        if(index >= this->availableShips_.size())
+            return NULL;
+
+        // If this index directly follows the last we can optimize a lot.
+        if(index == this->nextIndex_)
+        {
+            this->nextIndex_++;
+            std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextShip_;
+            this->nextLevel_++;
+            return *it;
+        }
+        else
+        {
+            // If this index is bigger than the last, we can optimize a little.
+            if(index < this->nextIndex_)
+            {
+                this->nextIndex_ = 0;
+                this->nextShip_ = this->availableShips_.begin();
+            }
+
+            while(this->nextIndex_ != index)
+            {
+                this->nextIndex_++;
+                this->nextShip_++;
+            }
+            this->nextIndex_++;
+            std::set<SpaceShip*, SpaceShipCompare>::iterator it = this->nextLevel_;
+            this->nextLevel_++;
+            return *it;
+        }
+    }
+
+    /**
+    @brief
+        Compile the list of available Levels.
+        Iterates over all *.oxw files, loads the LevelInfo objects in them and from that it creates the LevelInfoItems which are inserted in a list.
+    */
+    void ShipManager::compileAvailableShipList()
+    {
+		/*
+		// We only want to load as little as possible
+		ClassTreeMask mask;
+		    mask.exclude(Class(BaseObject));
+		    mask.include(Class(SpaceShip));
+		SpaceShip* info = NULL;
+		XMLFile file = XMLFile(ship);
+		Loader::load(&file, mask, false, true);
+		for(ObjectList<SpaceShip>::iterator item = ObjectList<SpaceShip>::begin(); item != ObjectList<SpaceShip>::end(); ++item)
+		        if(item->getXMLFilename() == *it)
+		            info = item->copy();
+		Loader::unload(&file);
+		*/
+    
+        // Get all files matching the level criteria
+        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
+
+        // We only want to load as little as possible
+        ClassTreeMask mask;
+        mask.exclude(Class(BaseObject));
+        mask.include(Class(LevelInfo));
+
+        // Iterate over all the found *.oxw files
+        orxout(internal_info) << "Loading LevelInfos..." << endl;
+        std::set<std::string> names;
+        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
+        {
+            // TODO: Replace with tag?
+            if (it->find("old/") != 0 )
+            {
+                LevelInfoItem* info = NULL;
+
+                // Load the LevelInfo object from the level file.
+                XMLFile file = XMLFile(*it);
+                Loader::load(&file, mask, false, true);
+
+                // Find the LevelInfo object we've just loaded (if there was one)
+                for(ObjectList<LevelInfo>::iterator item = ObjectList<LevelInfo>::begin(); item != ObjectList<LevelInfo>::end(); ++item)
+                    if(item->getXMLFilename() == *it)
+                        info = item->copy();
+
+                // We don't need the loaded stuff anymore
+                Loader::unload(&file);
+
+                if(info == NULL)
+                {
+                    // Create a default LevelInfoItem object that merely contains the name
+                    std::string filenameWOExtension = it->substr(0, it->find(".oxw"));
+                    info = new LevelInfoItem(filenameWOExtension, *it);
+                }
+
+                // Warn about levels with the same name.
+                if(!names.insert(info->getName()).second)
+                    orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with name '" << info->getName() << "' found!" << endl;
+
+                // Warn about multiple items so that it gets fixed quickly
+                if(availableLevels_.find(info) != availableLevels_.end())
+                {
+                    orxout(internal_warning) << "Multiple levels (" << info->getXMLFilename() << ") with same name '" << info->getName() << "' and filename found! Exluding..." << endl;
+                    // Delete LevelInfoItem to avoid a dangling pointer
+                    delete info;
+                }
+                else
+                    this->availableLevels_.insert(info);
+            }
+        }
+    }
+}
Index: /code/branches/shipSelection/src/orxonox/ShipManager.h
===================================================================
--- /code/branches/shipSelection/src/orxonox/ShipManager.h	(revision 9157)
+++ /code/branches/shipSelection/src/orxonox/ShipManager.h	(revision 9157)
@@ -0,0 +1,93 @@
+/*
+ *   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:
+ *      Matthias Hutter
+ */
+
+/**
+    @file ShipManager.h
+    @brief Definition of the ShipManager singleton.
+    @ingroup Orxonox
+*/
+
+#ifndef _ShipManager_H__
+#define _ShipManager_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <cassert>
+#include <list>
+#include <map>
+#include <string>
+#include "worldentities/pawns/SpaceShip.h"
+
+#include "util/Singleton.h"
+#include "core/OrxonoxClass.h"
+
+// tolua_begin
+namespace orxonox
+{
+
+    /**
+    @author
+       Matthias Hutter
+
+    @ingroup Orxonox
+    */
+    class _OrxonoxExport ShipManager
+    // tolua_end
+        : public Singleton<ShipManager>, public OrxonoxClass
+    { // tolua_export
+            friend class Singleton<LevelManager>;
+        public:
+            ShipManager();
+            virtual ~ShipManager();
+
+            void setConfigValues(); //!< Set the config values for this object.
+            // tolua_begin
+            /**
+            @brief Get the instance of the LevelManager.
+            @return Returns the instance of the LevelManager.
+            */
+            static ShipManager& getInstance()
+                { return Singleton<ShipManager>::getInstance(); }
+            // tolua_end
+
+        private:
+            ShipManager(const ShipManager&);
+
+
+            void compileAvailableLevelList(void); //!< Compile the list of available Levels.
+            void updateAvailableLevelList(void); //!< Update the list of available Levels.
+
+            std::list<Level*> levels_; //!< A list of all the Levels whose activity has been requested, in the order in which they will become active.
+            std::set<LevelInfoItem*, LevelInfoCompare> availableLevels_; //!< The set of available Levels sorted alphabetically according to the name of the Level.
+
+            // Helpers to allow fast access to the availableLevels list.
+            unsigned int nextIndex_; //! The next expected index to be accessed.
+            std::set<LevelInfoItem*, LevelInfoCompare>::iterator nextLevel_; //! The next expected Level to be accessed.
+
+            static LevelManager* singletonPtr_s;
+    }; // tolua_export
+} // tolua_export
+
+#endif /* _LevelManager_H__ */
