1 // 2 // SuperTuxKart - a fun racing game with go-kart 3 // Copyright (C) 2010-2015 SuperTuxKart-Team 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 3 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19 #ifndef GAME_SLOT_HPP 20 #define GAME_SLOT_HPP 21 22 #include "challenges/challenge_data.hpp" 23 #include "race/race_manager.hpp" 24 25 #include <irrString.h> 26 using namespace irr; 27 28 #include <string> 29 #include <map> 30 #include <vector> 31 32 class ChallengeData; 33 class ChallengeStatus; 34 class UTFWriter; 35 class XMLNode; 36 37 const int CHALLENGE_POINTS[] = { 6, 7, 8, 10 }; 38 const int GP_FACTOR = 3; 39 40 /** This class contains the progression through challenges for the story mode. 41 * It maintains a list of all challenges in a mapping of challenge id to 42 * an instance of ChallengeStatus. Each ChallengeStatus stores at which level 43 * a challenge was solved. 44 * This object also keeps track of the overall points a player has. 45 * \ingroup challenges 46 */ 47 48 class StoryModeStatus 49 { 50 private: 51 /** Contains whether each feature of the challenge is locked or unlocked */ 52 std::map<std::string, bool> m_locked_features; 53 54 /** Recently unlocked features (they are waiting here 55 * until they are shown to the user) */ 56 std::vector<const ChallengeData*> m_unlocked_features; 57 58 std::map<std::string, ChallengeStatus*> m_challenges_state; 59 60 /** A pointer to the current challenge, or NULL 61 * if no challenge is active. */ 62 const ChallengeStatus *m_current_challenge; 63 64 int m_points; 65 int m_points_before; // used for unlocks 66 int m_next_unlock_points; 67 68 /** Set to false after the initial stuff (intro, select kart, etc.) */ 69 bool m_first_time; 70 71 int m_easy_challenges; 72 int m_medium_challenges; 73 int m_hard_challenges; 74 int m_best_challenges; 75 76 /* Set to true after fort magma */ 77 bool m_story_mode_finished; 78 79 /* Set to true after fort magma if there was a valid speedrun active 80 * This is used to know if m_speedrun_milliseconds contain valid data */ 81 bool m_valid_speedrun_finished; 82 83 // It overflows at over 500 hours 84 int m_story_mode_milliseconds; 85 int m_speedrun_milliseconds; 86 87 public: 88 89 StoryModeStatus(const XMLNode *node=NULL); 90 ~StoryModeStatus(); 91 92 void computeActive (bool first_call=false); 93 bool isLocked (const std::string& feature); 94 void unlockFeatureByList(); 95 void lockFeature (ChallengeStatus *challenge); 96 void unlockFeature (ChallengeStatus* c, RaceManager::Difficulty d, 97 bool do_save=true); 98 void raceFinished (); 99 void grandPrixFinished (); 100 void save (UTFWriter &out, bool current_player=false); 101 void addStatus(ChallengeStatus *cs); 102 void setCurrentChallenge(const std::string &challenge_id); 103 104 // ---------------------------------------------------------------------------------------- 105 /** Returns the list of recently unlocked features (e.g. call at the end 106 * of a race to know if any features were unlocked) */ 107 const std::vector<const ChallengeData*> getRecentlyCompletedChallenges()108 getRecentlyCompletedChallenges() {return m_unlocked_features;} 109 // ---------------------------------------------------------------------------------------- 110 /** Clear the list of recently unlocked challenges */ clearUnlocked()111 void clearUnlocked () {m_unlocked_features.clear(); } 112 // ---------------------------------------------------------------------------------------- 113 /** Returns the number of completed challenges. */ getNumCompletedChallenges() const114 int getNumCompletedChallenges () const { return (m_easy_challenges + m_medium_challenges + 115 m_hard_challenges + m_best_challenges); } 116 // ---------------------------------------------------------------------------------------- 117 /** Returns the number of challenges with the superTux time beaten in a lower difficulty. */ 118 int getNumReqMetInLowerDiff () const; 119 // ---------------------------------------------------------------------------------------- 120 /** Returns the number of points accumulated. */ getPoints() const121 int getPoints () const { return m_points; } 122 // ---------------------------------------------------------------------------------------- 123 /** Returns the number of points before the previous point increase */ getPointsBefore() const124 int getPointsBefore () const { return m_points_before; } 125 // ---------------------------------------------------------------------------------------- 126 /** Returns the number of points needed by the next unlockable. 0 if none. */ getNextUnlockPoints() const127 int getNextUnlockPoints () const { return m_next_unlock_points; } 128 // ---------------------------------------------------------------------------------------- 129 /** Returns the number of fulfilled challenges at easy level. */ getNumEasyTrophies() const130 int getNumEasyTrophies () const { return m_easy_challenges; } 131 // ---------------------------------------------------------------------------------------- 132 /* Returns the number of fulfilled challenges at medium level. */ getNumMediumTrophies() const133 int getNumMediumTrophies() const { return m_medium_challenges; } 134 // ---------------------------------------------------------------------------------------- 135 /** Returns the number of fulfilled challenges at hard level. */ getNumHardTrophies() const136 int getNumHardTrophies () const { return m_hard_challenges; } 137 // ---------------------------------------------------------------------------------------- 138 /** Returns the number of fulfilled challenges at best level. */ getNumBestTrophies() const139 int getNumBestTrophies () const { return m_best_challenges; } 140 // ---------------------------------------------------------------------------------------- 141 /** Sets if this is the first time the intro is shown. */ setFirstTime(bool ft)142 void setFirstTime(bool ft) { m_first_time = ft; } 143 // ---------------------------------------------------------------------------------------- 144 /** Returns if this is the first time the intro is shown. */ isFirstTime() const145 bool isFirstTime() const { return m_first_time; } 146 // ---------------------------------------------------------------------------------------- 147 /** Sets if the player has beaten Nolock */ setFinished()148 void setFinished() { m_story_mode_finished = true; } 149 // ---------------------------------------------------------------------------------------- 150 /** Returns if the player has beaten Nolock */ isFinished() const151 bool isFinished() const { return m_story_mode_finished; } 152 // ---------------------------------------------------------------------------------------- 153 /** Sets if the player has finished a valid speedrun */ setSpeedrunFinished()154 void setSpeedrunFinished() { m_valid_speedrun_finished = true; } 155 // ---------------------------------------------------------------------------------------- 156 /** Returns if the player has finished a valid speedrun */ isSpeedrunFinished() const157 bool isSpeedrunFinished() const { return m_valid_speedrun_finished; } 158 // ---------------------------------------------------------------------------------------- 159 /** Sets the story mode timer */ setStoryModeTimer(int milliseconds)160 void setStoryModeTimer(int milliseconds) { m_story_mode_milliseconds = milliseconds; } 161 // ---------------------------------------------------------------------------------------- 162 /** Gets the story mode timer 163 * This is designed to be used on loading and once story mode is completed ; 164 * it will return out-of-date values when the timer is running. */ getStoryModeTimer()165 int getStoryModeTimer() { return m_story_mode_milliseconds; } 166 // ---------------------------------------------------------------------------------------- 167 /** Sets the story mode timer */ setSpeedrunTimer(int milliseconds)168 void setSpeedrunTimer(int milliseconds) { m_speedrun_milliseconds = milliseconds; } 169 // ---------------------------------------------------------------------------------------- 170 /** Gets the speedrun timer 171 * This is designed to be used on loading and once story mode is completed ; 172 * it will return out-of-date values when the timer is running. */ getSpeedrunTimer()173 int getSpeedrunTimer() { return m_speedrun_milliseconds; } 174 // ---------------------------------------------------------------------------------------- getCurrentChallengeStatus() const175 const ChallengeStatus *getCurrentChallengeStatus() const { return m_current_challenge; } 176 // ---------------------------------------------------------------------------------------- 177 /** Returns a challenge given the challenge id. 178 */ getChallengeStatus(const std::string & id) const179 const ChallengeStatus* getChallengeStatus(const std::string& id) const 180 { 181 std::map<std::string, ChallengeStatus*>::const_iterator it = 182 m_challenges_state.find(id); 183 assert(it!=m_challenges_state.end()); 184 return it->second; 185 } // getChallengeStatus 186 }; // StoryModeStatus 187 188 #endif 189