Back to index

supertuxkart  0.5+dfsg1
challenge.hpp
Go to the documentation of this file.
00001 //  $Id: challenge.hpp 1259 2007-09-24 12:28:19Z hiker $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2008 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_CHALLENGE_H
00021 #define HEADER_CHALLENGE_H
00022 
00023 #include <string>
00024 #include <vector>
00025 
00026 #include "lisp/lisp.hpp"
00027 #include "lisp/parser.hpp"
00028 #include "lisp/writer.hpp"
00029 
00030 enum REWARD_TYPE
00031    {UNLOCK_TRACK,
00032     UNLOCK_GP,
00033     UNLOCK_MODE,
00034     UNLOCK_DIFFICULTY};
00035 
00036 struct UnlockableFeature
00037 {
00038     std::string name; // itnernal name
00039     std::string user_name; // not all types of feature have one
00040     REWARD_TYPE type;
00041 };
00042 
00043 // A base class for all challenges
00044 class Challenge
00045 {
00046     enum {CH_INACTIVE,                 // challenge not yet possible
00047           CH_ACTIVE,                   // challenge possible, but not yet solved
00048           CH_SOLVED}         m_state;  // challenge was solved
00049     std::string              m_Id;                    // short, internal name for this challenge
00050     std::string              m_Name;                  // name used in menu for this challenge
00051     std::string              m_challenge_description; // Message the user gets when the feature is not yet unlocked
00052     std::vector<UnlockableFeature> m_feature;         // Features to unlock
00053     std::vector<std::string> m_prerequisites;         // what needs to be done before accessing this challenge
00054 public:
00055              Challenge(std::string id, std::string name);
00056     virtual ~Challenge() {};
00057     const std::string& getId() const             {return m_Id;                  }
00058     const std::string& getName() const           {return m_Name;                }
00059     
00060     void addUnlockTrackReward(std::string track_name);
00061     void addUnlockModeReward(std::string internal_mode_name, std::string user_mode_name);
00062     void addUnlockGPReward(std::string gp_name);
00063     void addUnlockDifficultyReward(std::string internal_name, std::string user_name);
00064     
00065     const std::string getUnlockedMessage() const;
00066     const std::vector<UnlockableFeature>&
00067           getFeatures() const                    {return m_feature;               }
00068     void  setChallengeDescription(const std::string& d) 
00069                                                  {m_challenge_description=d;      }
00070     const std::string& 
00071           getChallengeDescription() const        {return m_challenge_description; }
00072     void  addDependency(const std::string id)    {m_prerequisites.push_back(id);  }
00073     bool  isSolved() const                       {return m_state==CH_SOLVED;      }
00074     bool  isActive() const                       {return m_state==CH_ACTIVE;      }
00075     void  setSolved()                            {m_state = CH_SOLVED;            }
00076     void  setActive()                            {m_state = CH_ACTIVE;            }
00077     const std::vector<std::string>& 
00078           getPrerequisites() const               {return m_prerequisites;         }
00079     void  load(const lisp::Lisp* config);
00080     void  save(lisp::Writer* writer);
00081 
00082     // These functions are meant for customisation, e.g. load/save
00083     // additional state information specific to the challenge
00084     virtual void loadState(const lisp::Lisp* config) {};
00085     virtual void saveState(lisp::Writer* writer)     {};
00086 
00087     // These functions are called when a race/gp is finished. It allows
00088     // the challenge to unlock features (when returning true), otherwise
00089     // the feature remains locked.
00090     virtual bool raceFinished()                      {return false;}   // end of a race
00091     virtual bool grandPrixFinished()                 {return false;}   // end of a GP
00092     virtual void setRace() const = 0;                                  // set race to use
00093 };
00094 #endif