2007-05-27 12:01:53 -04:00
|
|
|
//
|
|
|
|
// SuperTuxKart - a fun racing game with go-kart
|
2013-11-15 06:43:21 -05:00
|
|
|
// Copyright (C) 2010-2013 SuperTuxKart-Team
|
2007-05-27 12:01:53 -04:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
2008-06-12 20:53:52 -04:00
|
|
|
// as published by the Free Software Foundation; either version 3
|
2007-05-27 12:01:53 -04:00
|
|
|
// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
2014-02-17 07:16:53 -05:00
|
|
|
#ifndef HEADER_PLAYER_PROFILE_HPP
|
|
|
|
#define HEADER_PLAYER_PROFILE_HPP
|
2014-02-09 07:22:45 -05:00
|
|
|
|
2014-02-17 07:16:53 -05:00
|
|
|
#include "challenges/story_mode_status.hpp"
|
2010-09-08 07:39:19 -04:00
|
|
|
#include "utils/no_copy.hpp"
|
2014-01-06 07:23:16 -05:00
|
|
|
#include "utils/types.hpp"
|
2014-02-05 22:43:47 -05:00
|
|
|
|
2011-05-22 15:29:52 -04:00
|
|
|
#include <irrString.h>
|
2010-12-27 20:29:36 -05:00
|
|
|
using namespace irr;
|
2009-07-04 13:24:09 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class UTFWriter;
|
2014-02-20 06:04:03 -05:00
|
|
|
class AchievementsStatus;
|
2014-02-05 22:43:47 -05:00
|
|
|
|
2014-02-23 16:21:15 -05:00
|
|
|
/** Class for managing player profiles (name, usage frequency,
|
|
|
|
* etc.). All PlayerProfiles are managed by the PlayerManager.
|
|
|
|
* A PlayerProfile keeps track of the story mode progress using an instance
|
|
|
|
* of StoryModeStatus, and achievements with AchievementsStatus. All data
|
|
|
|
* is saved in the players.xml file.
|
|
|
|
* \ingroup config
|
|
|
|
*/
|
2010-09-08 07:39:19 -04:00
|
|
|
class PlayerProfile : public NoCopy
|
2007-05-27 12:01:53 -04:00
|
|
|
{
|
2014-02-09 07:22:45 -05:00
|
|
|
private:
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
/** The name of the player (wide string, so it can be in native
|
|
|
|
* language). */
|
|
|
|
core::stringw m_name;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
/** True if this account is a guest account. */
|
|
|
|
bool m_is_guest_account;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2010-09-25 14:34:04 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
unsigned int m_magic_number;
|
|
|
|
#endif
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Counts how often this player was used (always -1 for guests). */
|
|
|
|
int m_use_frequency;
|
2010-03-26 21:35:11 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
/** A unique number for this player, used to link it to challenges etc. */
|
|
|
|
unsigned int m_unique_id;
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-09 07:22:45 -05:00
|
|
|
/** True if this is the default (last used) player. */
|
|
|
|
bool m_is_default;
|
|
|
|
|
|
|
|
/** The complete challenge state. */
|
2014-02-17 07:16:53 -05:00
|
|
|
StoryModeStatus *m_story_mode_status;
|
2014-02-09 07:22:45 -05:00
|
|
|
|
2014-02-20 06:04:03 -05:00
|
|
|
AchievementsStatus *m_achievements_status;
|
|
|
|
|
2011-02-04 20:56:18 -05:00
|
|
|
public:
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
PlayerProfile(const core::stringw& name, bool is_guest = false);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2012-04-25 18:29:03 -04:00
|
|
|
PlayerProfile(const XMLNode* node);
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
void save(UTFWriter &out);
|
|
|
|
void incrementUseFrequency();
|
2014-02-06 07:08:55 -05:00
|
|
|
bool operator<(const PlayerProfile &other);
|
|
|
|
bool operator>(const PlayerProfile &other);
|
|
|
|
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2010-09-25 14:34:04 -04:00
|
|
|
~PlayerProfile()
|
|
|
|
{
|
2010-12-27 20:29:36 -05:00
|
|
|
#ifdef DEBUG
|
2010-09-25 14:34:04 -04:00
|
|
|
m_magic_number = 0xDEADBEEF;
|
2010-12-27 20:29:36 -05:00
|
|
|
#endif
|
2014-02-10 16:12:10 -05:00
|
|
|
} // ~PlayerProfile
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Sets the name of this player. */
|
2010-12-27 20:29:36 -05:00
|
|
|
void setName(const core::stringw& name)
|
2013-05-30 15:47:39 -04:00
|
|
|
{
|
2010-12-27 20:29:36 -05:00
|
|
|
#ifdef DEBUG
|
2012-06-21 12:33:30 -04:00
|
|
|
assert(m_magic_number == 0xABCD1234);
|
2010-12-27 20:29:36 -05:00
|
|
|
#endif
|
2012-06-21 12:33:30 -04:00
|
|
|
m_name = name;
|
2014-02-10 16:12:10 -05:00
|
|
|
} // setName
|
2009-07-11 12:50:57 -04:00
|
|
|
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Returns the name of this player. */
|
2010-12-27 20:29:36 -05:00
|
|
|
core::stringw getName() const
|
2013-05-30 15:47:39 -04:00
|
|
|
{
|
2010-12-27 20:29:36 -05:00
|
|
|
#ifdef DEBUG
|
|
|
|
assert(m_magic_number == 0xABCD1234);
|
|
|
|
#endif
|
2012-06-21 12:33:30 -04:00
|
|
|
return m_name.c_str();
|
2014-02-10 16:12:10 -05:00
|
|
|
} // getName
|
2009-07-11 12:50:57 -04:00
|
|
|
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Returns true if this player is a guest account. */
|
2010-12-27 20:29:36 -05:00
|
|
|
bool isGuestAccount() const
|
2013-05-30 15:47:39 -04:00
|
|
|
{
|
2010-12-27 20:29:36 -05:00
|
|
|
#ifdef DEBUG
|
2013-05-30 15:47:39 -04:00
|
|
|
assert(m_magic_number == 0xABCD1234);
|
2010-12-27 20:29:36 -05:00
|
|
|
#endif
|
2012-06-21 12:33:30 -04:00
|
|
|
return m_is_guest_account;
|
2014-02-10 16:12:10 -05:00
|
|
|
} // isGuestAccount
|
2013-05-30 15:47:39 -04:00
|
|
|
|
2014-02-05 22:43:47 -05:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns the unique id of this player. */
|
|
|
|
unsigned int getUniqueID() const { return m_unique_id; }
|
2014-02-10 16:12:10 -05:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
/** Returns true if this is the default (last used) player. */
|
|
|
|
bool isDefault() const { return m_is_default; }
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Sets if this player is the default player or not. */
|
|
|
|
void setDefault(bool is_default) { m_is_default = is_default; }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Returnes if the feature (kart, track) is locked. */
|
2014-02-09 07:22:45 -05:00
|
|
|
bool isLocked(const std::string &feature) const
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->isLocked(feature);
|
2014-02-09 07:22:45 -05:00
|
|
|
} // isLocked
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Returns all active challenges. */
|
2014-02-17 07:16:53 -05:00
|
|
|
void computeActive() { m_story_mode_status->computeActive(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Returns the list of recently completed challenges. */
|
2014-02-09 07:22:45 -05:00
|
|
|
std::vector<const ChallengeData*> getRecentlyCompletedChallenges()
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getRecentlyCompletedChallenges();
|
2014-02-09 07:22:45 -05:00
|
|
|
} // getRecently Completed Challenges
|
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Sets the currently active challenge. */
|
2014-02-09 07:22:45 -05:00
|
|
|
void setCurrentChallenge(const std::string &name)
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
m_story_mode_status->setCurrentChallenge(name);
|
2014-02-09 07:22:45 -05:00
|
|
|
} // setCurrentChallenge
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
/** Notification of a finished race, which can trigger fulfilling
|
|
|
|
* challenges. */
|
2014-02-17 07:16:53 -05:00
|
|
|
void raceFinished() { m_story_mode_status->raceFinished(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-10 16:12:10 -05:00
|
|
|
/** Callback when a GP is finished (to test if a challenge was
|
|
|
|
* fulfilled). */
|
2014-02-17 07:16:53 -05:00
|
|
|
void grandPrixFinished() { m_story_mode_status->grandPrixFinished(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-17 07:16:53 -05:00
|
|
|
unsigned int getPoints() const { return m_story_mode_status->getPoints(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-17 07:16:53 -05:00
|
|
|
void setFirstTime(bool b) { m_story_mode_status->setFirstTime(b); }
|
2014-02-09 16:41:54 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-17 07:16:53 -05:00
|
|
|
bool isFirstTime() const { return m_story_mode_status->isFirstTime(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-17 07:16:53 -05:00
|
|
|
void clearUnlocked() { m_story_mode_status->clearUnlocked(); }
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-09 16:41:54 -05:00
|
|
|
/** Returns the current challenge for this player. */
|
2014-02-17 06:20:23 -05:00
|
|
|
const ChallengeStatus* getCurrentChallengeStatus() const
|
2014-02-09 16:41:54 -05:00
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getCurrentChallengeStatus();
|
2014-02-17 06:20:23 -05:00
|
|
|
} // getCurrentChallengeStatus
|
2014-02-09 16:41:54 -05:00
|
|
|
// ------------------------------------------------------------------------
|
2014-02-17 06:20:23 -05:00
|
|
|
const ChallengeStatus* getChallengeStatus(const std::string &id)
|
2014-02-09 07:22:45 -05:00
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getChallengeStatus(id);
|
2014-02-17 06:20:23 -05:00
|
|
|
} // getChallengeStatus
|
2014-02-09 07:22:45 -05:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
unsigned int getNumEasyTrophies() const
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getNumEasyTrophies();
|
2014-02-09 07:22:45 -05:00
|
|
|
} // getNumEasyTrophies
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
unsigned int getNumMediumTrophies() const
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getNumMediumTrophies();
|
2014-02-09 07:22:45 -05:00
|
|
|
} // getNumEasyTrophies
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
unsigned int getNumHardTrophies() const
|
|
|
|
{
|
2014-02-17 07:16:53 -05:00
|
|
|
return m_story_mode_status->getNumHardTrophies();
|
2014-02-09 07:22:45 -05:00
|
|
|
} // getNumHardTropies
|
2014-02-20 06:04:03 -05:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
AchievementsStatus* getAchievementsStatus()
|
|
|
|
{
|
|
|
|
return m_achievements_status;
|
|
|
|
} // getAchievementsStatus
|
2014-02-05 22:43:47 -05:00
|
|
|
|
|
|
|
}; // class PlayerProfile
|
2009-07-11 12:50:57 -04:00
|
|
|
|
2007-05-27 12:01:53 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*EOF*/
|