[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 | |
---|
[6412] | 33 | #include "core/CommandLineParser.h" |
---|
[3280] | 34 | #include "core/ConfigValueIncludes.h" |
---|
| 35 | #include "core/CoreIncludes.h" |
---|
[3370] | 36 | #include "core/Loader.h" |
---|
[6412] | 37 | #include "core/Resource.h" |
---|
[5929] | 38 | #include "core/ScopedSingletonManager.h" |
---|
[2171] | 39 | #include "PlayerManager.h" |
---|
[5738] | 40 | #include "Level.h" |
---|
[2072] | 41 | |
---|
| 42 | namespace 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 |
---|
[6412] | 54 | if (!CommandLineParser::getArgument("level")->hasDefaultValue()) |
---|
[3280] | 55 | { |
---|
[6412] | 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") |
---|
[6412] | 67 | .description("Sets the pre selection of the level in the main menu."); |
---|
[3280] | 68 | } |
---|
| 69 | |
---|
[2072] | 70 | void LevelManager::requestActivity(Level* level) |
---|
| 71 | { |
---|
| 72 | this->levels_s.push_back(level); |
---|
| 73 | if (this->levels_s.size() == 1) |
---|
| 74 | this->activateNextLevel(); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | void LevelManager::releaseActivity(Level* level) |
---|
| 78 | { |
---|
| 79 | if (this->levels_s.size() > 0) |
---|
| 80 | { |
---|
| 81 | if (this->levels_s.front() == level) |
---|
| 82 | { |
---|
| 83 | level->setActive(false); |
---|
| 84 | this->levels_s.pop_front(); |
---|
| 85 | this->activateNextLevel(); |
---|
| 86 | } |
---|
| 87 | else |
---|
| 88 | { |
---|
| 89 | for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it) |
---|
| 90 | if ((*it) == level) |
---|
| 91 | this->levels_s.erase(it); |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | Level* LevelManager::getActiveLevel() |
---|
| 97 | { |
---|
| 98 | if (this->levels_s.size() > 0) |
---|
| 99 | return this->levels_s.front(); |
---|
| 100 | else |
---|
| 101 | return 0; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | void LevelManager::activateNextLevel() |
---|
| 105 | { |
---|
| 106 | if (this->levels_s.size() > 0) |
---|
| 107 | { |
---|
| 108 | this->levels_s.front()->setActive(true); |
---|
[2171] | 109 | for (std::map<unsigned int, PlayerInfo*>::const_iterator it = PlayerManager::getInstance().getClients().begin(); it != PlayerManager::getInstance().getClients().end(); ++it) |
---|
[2072] | 110 | this->levels_s.front()->playerEntered(it->second); |
---|
| 111 | } |
---|
| 112 | } |
---|
[3280] | 113 | |
---|
| 114 | void LevelManager::setDefaultLevel(const std::string& levelName) |
---|
| 115 | { |
---|
| 116 | ModifyConfigValue(defaultLevelName_, set, levelName); |
---|
| 117 | } |
---|
| 118 | |
---|
[3370] | 119 | const std::string& LevelManager::getDefaultLevel() const |
---|
[3280] | 120 | { |
---|
| 121 | return defaultLevelName_; |
---|
| 122 | } |
---|
[3370] | 123 | |
---|
[6412] | 124 | const std::string& LevelManager::getAvailableLevelListItem(unsigned int index) const |
---|
[3370] | 125 | { |
---|
| 126 | if (index >= availableLevels_.size()) |
---|
[6412] | 127 | return BLANKSTRING; |
---|
[3370] | 128 | else |
---|
| 129 | return availableLevels_[index]; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | void LevelManager::compileAvailableLevelList() |
---|
| 133 | { |
---|
[6412] | 134 | availableLevels_ = *Resource::findResourceNames("*.oxw"); |
---|
[5695] | 135 | for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();) |
---|
| 136 | if (it->find("old/") == 0) |
---|
| 137 | it = availableLevels_.erase(it); |
---|
| 138 | else |
---|
[3370] | 139 | { |
---|
[5695] | 140 | size_t pos = it->find(".oxw"); |
---|
| 141 | *it = it->substr(0, pos); |
---|
| 142 | ++it; |
---|
[3370] | 143 | } |
---|
| 144 | } |
---|
[2072] | 145 | } |
---|