Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation3/src/orxonox/LevelManager.cc @ 6927

Last change on this file since 6927 was 6927, checked in by scheusso, 14 years ago

fix in levelmanager: if a template was assigned to the Level the gametype was set twice to the level which resulted in the level being twice in the list of active levels in the levelmanager and only once removed (when the level was destroyed)

  • Property svn:eol-style set to native
File size: 4.4 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "LevelManager.h"
30
31#include <map>
32
33#include "core/CommandLineParser.h"
34#include "core/ConfigValueIncludes.h"
35#include "core/CoreIncludes.h"
36#include "core/Loader.h"
37#include "core/Resource.h"
38#include "core/ScopedSingletonManager.h"
39#include "PlayerManager.h"
40#include "Level.h"
41
42namespace orxonox
43{
44    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
45
46    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
47
48    LevelManager::LevelManager()
49    {
50        RegisterRootObject(LevelManager);
51        this->setConfigValues();
52
53        // check override
54        if (!CommandLineParser::getArgument("level")->hasDefaultValue())
55        {
56            ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").getString());
57        }
58    }
59
60    LevelManager::~LevelManager()
61    {
62    }
63
64    void LevelManager::setConfigValues()
65    {
66        SetConfigValue(defaultLevelName_, "presentation_dm.oxw")
67            .description("Sets the pre selection of the level in the main menu.");
68    }
69
70    void LevelManager::requestActivity(Level* level)
71    {
72        if( std::find(this->levels_s.begin(), this->levels_s.end(), level)!=this->levels_s.end() )
73            return; // level is already in list
74        this->levels_s.push_back(level);
75        if (this->levels_s.size() == 1)
76            this->activateNextLevel();
77    }
78
79    void LevelManager::releaseActivity(Level* level)
80    {
81        if (this->levels_s.size() > 0)
82        {
83            if (this->levels_s.front() == level)
84            {
85                level->setActive(false);
86                this->levels_s.pop_front();
87                this->activateNextLevel();
88            }
89            else
90            {
91                for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it)
92                    if ((*it) == level)
93                        this->levels_s.erase(it);
94            }
95        }
96    }
97
98    Level* LevelManager::getActiveLevel()
99    {
100        if (this->levels_s.size() > 0)
101            return this->levels_s.front();
102        else
103            return 0;
104    }
105
106    void LevelManager::activateNextLevel()
107    {
108        if (this->levels_s.size() > 0)
109        {
110            this->levels_s.front()->setActive(true);
111            for (std::map<unsigned int, PlayerInfo*>::const_iterator it = PlayerManager::getInstance().getClients().begin(); it != PlayerManager::getInstance().getClients().end(); ++it)
112                this->levels_s.front()->playerEntered(it->second);
113        }
114    }
115
116    void LevelManager::setDefaultLevel(const std::string& levelName)
117    {
118        ModifyConfigValue(defaultLevelName_, set, levelName);
119    }
120
121    const std::string& LevelManager::getDefaultLevel() const
122    {
123        return defaultLevelName_;
124    }
125
126    const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const
127    {
128        if (index >= availableLevels_.size())
129            return BLANKSTRING;
130        else
131            return availableLevels_[index];
132    }
133
134    void LevelManager::compileAvailableLevelList()
135    {
136        this->availableLevels_.clear();
137        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
138        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
139        {
140            if (it->find("old/") != 0)
141            {
142                size_t pos = it->find(".oxw");
143                this->availableLevels_.push_back(it->substr(0, pos));
144            }
145        }
146    }
147}
Note: See TracBrowser for help on using the repository browser.