/* * 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: * kappenh * Co-authors: * ... * */ #include "Highscore.h" #include "core/CoreIncludes.h" #include "core/config/ConfigValueIncludes.h" #include "core/singleton/ScopedSingletonIncludes.h" #include "infos/PlayerInfo.h" #include "util/Convert.h" namespace orxonox { ManageScopedSingleton(Highscore, ScopeID::ROOT, false); RegisterClassNoArgs(Highscore); Highscore::Highscore() { RegisterObject(Highscore); this->setConfigValues(); } /** * @brief set the config values in the orxonox.ini file */ void Highscore::setConfigValues() { SetConfigValue(highscores_, std::vector()).description("Highscores saved as vector"); } /** * @brief Returns highest score of given game, if exists. * Else returns -1. */ int Highscore::getHighestScoreOfGame(const std::string& game) { const std::string delimiter = "./."; //score save as "Playername./.game./.score" int best = -1; //check for the highest Score of given game for (std::string score : this->highscores_) { //filter the game string from given highscore score.erase(0, score.find(delimiter) + delimiter.length()); if (game.compare(score.substr(0,score.find(delimiter))) == 0) { score.erase(0, score.find(delimiter) + delimiter.length()); int possibleBest = multi_cast(score); if (possibleBest > best) best = possibleBest; } } return best; } /** * @brief stores a new highscore in the orxonox.ini file if the new score is better than the highest score so far. * @returns true if the given score marks a new high score */ bool Highscore::storeScore(const std::string& level, int points, PlayerInfo* player) { if (points > this->getHighestScoreOfGame(level)) { ModifyConfigValue(highscores_, add, player->getName() + "./." + level + "./." + multi_cast(points)); return true; } else return false; } }