Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/LevelManager.cc @ 7559

Last change on this file since 7559 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

  • Property svn:eol-style set to native
File size: 4.5 KB
RevLine 
[2072]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
[3196]31#include <map>
[3280]32
[7284]33#include "util/ScopedSingletonManager.h"
[6021]34#include "core/CommandLineParser.h"
[3280]35#include "core/ConfigValueIncludes.h"
36#include "core/CoreIncludes.h"
[3370]37#include "core/Loader.h"
[6417]38#include "core/Resource.h"
[2171]39#include "PlayerManager.h"
[5738]40#include "Level.h"
[2072]41
42namespace orxonox
43{
[3280]44    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
45
[5929]46    ManageScopedSingleton(LevelManager, ScopeID::Root, false);
[2072]47
48    LevelManager::LevelManager()
49    {
[3280]50        RegisterRootObject(LevelManager);
51        this->setConfigValues();
52
53        // check override
[6021]54        if (!CommandLineParser::getArgument("level")->hasDefaultValue())
[3280]55        {
[6021]56            ModifyConfigValue(defaultLevelName_, tset, CommandLineParser::getValue("level").getString());
[3280]57        }
[2072]58    }
59
60    LevelManager::~LevelManager()
61    {
62    }
63
[3280]64    void LevelManager::setConfigValues()
65    {
66        SetConfigValue(defaultLevelName_, "presentation_dm.oxw")
[6417]67            .description("Sets the pre selection of the level in the main menu.");
[3280]68    }
69
[2072]70    void LevelManager::requestActivity(Level* level)
71    {
[7163]72        assert( std::find(this->levels_s.begin(), this->levels_s.end(), level)==this->levels_s.end() );
73        if( std::find(this->levels_s.begin(), this->levels_s.end(), level)!=this->levels_s.end() )
74            return; // level is already in list
[2072]75        this->levels_s.push_back(level);
76        if (this->levels_s.size() == 1)
77            this->activateNextLevel();
78    }
79
80    void LevelManager::releaseActivity(Level* level)
81    {
82        if (this->levels_s.size() > 0)
83        {
84            if (this->levels_s.front() == level)
85            {
86                level->setActive(false);
87                this->levels_s.pop_front();
88                this->activateNextLevel();
89            }
90            else
91            {
92                for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it)
93                    if ((*it) == level)
94                        this->levels_s.erase(it);
95            }
96        }
97    }
98
99    Level* LevelManager::getActiveLevel()
100    {
101        if (this->levels_s.size() > 0)
102            return this->levels_s.front();
103        else
104            return 0;
105    }
106
107    void LevelManager::activateNextLevel()
108    {
109        if (this->levels_s.size() > 0)
110        {
111            this->levels_s.front()->setActive(true);
[2171]112            for (std::map<unsigned int, PlayerInfo*>::const_iterator it = PlayerManager::getInstance().getClients().begin(); it != PlayerManager::getInstance().getClients().end(); ++it)
[2072]113                this->levels_s.front()->playerEntered(it->second);
114        }
115    }
[3280]116
117    void LevelManager::setDefaultLevel(const std::string& levelName)
118    {
119        ModifyConfigValue(defaultLevelName_, set, levelName);
120    }
121
[3370]122    const std::string& LevelManager::getDefaultLevel() const
[3280]123    {
124        return defaultLevelName_;
125    }
[3370]126
[6417]127    const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const
[3370]128    {
129        if (index >= availableLevels_.size())
[6417]130            return BLANKSTRING;
[3370]131        else
132            return availableLevels_[index];
133    }
134
135    void LevelManager::compileAvailableLevelList()
136    {
[6501]137        this->availableLevels_.clear();
138        Ogre::StringVectorPtr levels = Resource::findResourceNames("*.oxw");
139        for (Ogre::StringVector::const_iterator it = levels->begin(); it != levels->end(); ++it)
140        {
141            if (it->find("old/") != 0)
[3370]142            {
[5695]143                size_t pos = it->find(".oxw");
[6501]144                this->availableLevels_.push_back(it->substr(0, pos));
[3370]145            }
[6501]146        }
[3370]147    }
[2072]148}
Note: See TracBrowser for help on using the repository browser.