SuperTuxKart
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AchievementsStatus Class Reference

This class keeps tracks of all achievements of one player. More...

#include <achievements_status.hpp>

Classes

struct  AchievementVariable
 
struct  TrackStats
 

Public Types

enum  AchievementData {
  WON_RACES = 0 , WON_NORMAL_RACES = 1 , WON_TT_RACES = 2 , WON_FTL_RACES = 3 ,
  CONS_WON_RACES = 4 , CONS_WON_RACES_MAX = 5 , CONS_WON_RACES_HARD = 6 , CONS_WON_RACES_HARD_MAX = 7 ,
  EASY_STARTED = 8 , EASY_FINISHED = 9 , MEDIUM_STARTED = 10 , MEDIUM_FINISHED = 11 ,
  HARD_STARTED = 12 , HARD_FINISHED = 13 , BEST_STARTED = 14 , BEST_FINISHED = 15 ,
  NORMAL_STARTED = 16 , NORMAL_FINISHED = 17 , TT_STARTED = 18 , TT_FINISHED = 19 ,
  FTL_STARTED = 20 , FTL_FINISHED = 21 , THREE_STRIKES_STARTED = 22 , THREE_STRIKES_FINISHED = 23 ,
  SOCCER_STARTED = 24 , SOCCER_FINISHED = 25 , EGG_HUNT_STARTED = 26 , EGG_HUNT_FINISHED = 27 ,
  WITH_GHOST_STARTED = 28 , WITH_GHOST_FINISHED = 29 , CTF_STARTED = 30 , CTF_FINISHED = 31 ,
  FFA_STARTED = 32 , FFA_FINISHED = 33 , POWERUP_USED = 34 , POWERUP_USED_1RACE = 35 ,
  POWERUP_USED_1RACE_MAX = 36 , BOWLING_HIT = 37 , BOWLING_HIT_1RACE = 38 , BOWLING_HIT_1RACE_MAX = 39 ,
  SWATTER_HIT = 40 , SWATTER_HIT_1RACE = 41 , SWATTER_HIT_1RACE_MAX = 42 , ALL_HITS = 43 ,
  ALL_HITS_1RACE = 44 , ALL_HITS_1RACE_MAX = 45 , BANANA = 46 , BANANA_1RACE = 47 ,
  BANANA_1RACE_MAX = 48 , SKIDDING = 49 , SKIDDING_1RACE = 50 , SKIDDING_1RACE_MAX = 51 ,
  SKIDDING_1LAP = 52 , SKIDDING_1LAP_MAX = 53 , ACHIEVE_DATA_NUM = 54
}
 
enum  TrackData {
  TR_STARTED = 0 , TR_FINISHED = 1 , TR_WON = 2 , TR_FINISHED_REVERSE = 3 ,
  TR_FINISHED_ALONE = 4 , TR_LESS_LAPS = 5 , TR_MORE_LAPS = 6 , TR_MIN_TWICE_LAPS = 7 ,
  TR_EGG_HUNT_STARTED = 8 , TR_EGG_HUNT_FINISHED = 9 , TR_DATA_NUM = 10
}
 

Public Member Functions

 AchievementsStatus ()
 Constructor for an Achievement.
 
 ~AchievementsStatus ()
 Removes all achievements.
 
AchievementgetAchievement (uint32_t id)
 
void load (const XMLNode *input)
 Loads the saved state of all achievements from an XML file.
 
void save (UTFWriter &out)
 Saves the achievement status to a file.
 
void add (Achievement *achievement)
 
void sync (const std::vector< uint32_t > &achieved_ids)
 Synchronises the achievements between local and online usage.
 
void increaseDataVar (unsigned int achieve_data_id, int increase)
 
void resetDataVar (unsigned int achieve_data_id)
 
void onRaceEnd (bool aborted=false)
 
void onLapEnd ()
 
void trackEvent (std::string track_ident, AchievementsStatus::TrackData event)
 Use the event type to increment the correct track event counter.
 
void resetKartHits (int num_karts)
 
void addKartHit (int kart_id)
 
void updateAllAchievementsProgress ()
 
int getNumTracksAboveValue (int value, std::string goal_string)
 
int getNumAchieveTracks ()
 
std::map< uint32_t, Achievement * > & getAllAchievements ()
 
bool isOnline () const
 
bool isValid () const
 

Private Types

enum  UpdateType { UP_ACHIEVEMENT_DATA = 0 , UP_TRACK_DATA = 1 , UP_KART_HITS = 2 }
 

Private Member Functions

void setEnumToString ()
 This function loads a table associating an enum identifier with the matching command in achievements.xml.
 
void updateAchievementsProgress (UpdateType type, unsigned int enum_id)
 

Private Attributes

std::map< uint32_t, Achievement * > m_achievements
 
const int DATA_VERSION = 4
 
AchievementVariable m_variables [ACHIEVE_DATA_NUM]
 
std::string m_ach_enum_to_xml [ACHIEVE_DATA_NUM]
 
std::vector< TrackStatsm_track_stats
 
std::string m_tr_enum_to_xml [2 *TR_DATA_NUM]
 
std::vector< int > m_kart_hits
 
bool m_online
 
bool m_valid
 

Detailed Description

This class keeps tracks of all achievements of one player.

One instance of this class is stored in each PlayerProfile. It stores a map of achievements ids to instances of Achievement. Each achievement in turn stores either fulfilled achievements, or the current state of an achievement (e.g. an achievement to race every track in STK needs to keep information about which tracks have already been used.)

Member Function Documentation

◆ load()

void AchievementsStatus::load ( const XMLNode input)

Loads the saved state of all achievements from an XML file.

Parameters
inputThe XML node to load the data from.

◆ save()

void AchievementsStatus::save ( UTFWriter out)

Saves the achievement status to a file.

Achievements are stored as part of the player data file players.xml.

Parameters
outFile to write to.

◆ setEnumToString()

void AchievementsStatus::setEnumToString ( )
private

This function loads a table associating an enum identifier with the matching command in achievements.xml.

counters with anassociated max version are prefixed to allow the achievement progress update to do the correct action.

◆ sync()

void AchievementsStatus::sync ( const std::vector< uint32_t > &  achieved_ids)

Synchronises the achievements between local and online usage.

It takes the list of online achievements, and marks them all to be achieved locally. Then it issues 'achieved' requests to the server for all local achievements that are not set online.

◆ trackEvent()

void AchievementsStatus::trackEvent ( std::string  track_ident,
AchievementsStatus::TrackData  event 
)

Use the event type to increment the correct track event counter.

Parameters
track_ident- the internal name of the track
event- the type of counter to increment

The documentation for this class was generated from the following files: