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