SuperTuxKart
Loading...
Searching...
No Matches
achievement.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2013-2015 Glenn De Jonghe
4// (C) 2014-2015 Joerg Henrichs
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License
8// as published by the Free Software Foundation; either version 3
9// of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20#ifndef HEADER_ACHIEVEMENT_HPP
21#define HEADER_ACHIEVEMENT_HPP
22
23#include "achievements/achievement_info.hpp"
24#include "utils/types.hpp"
25
26#include <irrString.h>
27#include <map>
28#include <string>
29
30class UTFWriter;
31class XMLNode;
32
33// ============================================================================
39class AchievementInfo;
40
42{
43private:
46
47 /* When quitting the game, the achievement info is deleted before
48 * the achievement's status is saved. We need to store the id here
49 * to prevent saving junk data.
50 * FIXME: an achievement info should not be removed until all references
51 * to it have been too.*/
52 int m_id;
53
54 void onCompletion();
55 bool recursiveSetGoalValue(AchievementInfo::goalTree &tree, const std::string &goal_string, int value,
56 bool and_or, bool sum_andatonce);
58protected:
59 friend class AchievementProgressDialog;
60
61
67
70
71 int computeFullfiledGoals(AchievementInfo::goalTree &progress, AchievementInfo::goalTree &reference);
72 int computeGoalProgress(AchievementInfo::goalTree &progress, AchievementInfo::goalTree &reference, bool same_tree=false);
73public:
74
76 virtual ~Achievement();
77 virtual void loadProgress(const XMLNode *node);
78 virtual void saveProgress(UTFWriter &out);
79
80 virtual irr::core::stringw getProgressAsString();
81 virtual irr::core::stringw getGoalProgressAsString();
82
83 uint32_t getID() const { return m_id; }
84 AchievementInfo * getInfo() { return m_achievement_info; }
86 int getProgress();
87
88 void setAchieved() { m_achieved = true; };
89 bool isAchieved() const { return m_achieved; }
90
91 void setGoalValue(std::string &goal_string, int value);
92}; // class Achievement
93#endif
This class stores an achievement definition from the xml file, including title, description,...
Definition: achievement_info.hpp:41
Dialog that shows an achievement description and progress.
Definition: achievement_progress_dialog.hpp:42
Definition: achievement.hpp:42
AchievementInfo::goalTree m_progress_goal_tree
The tree of goals.
Definition: achievement.hpp:66
void onCompletion()
Manages what needs to happen once the achievement is completed, like displaying the completion messag...
Definition: achievement.cpp:378
int computeGoalProgress(AchievementInfo::goalTree &progress, AchievementInfo::goalTree &reference, bool same_tree=false)
Should ONLY be called if the achievement has one goal (a sum counts as one goal).
Definition: achievement.cpp:168
void setGoalValue(std::string &goal_string, int value)
Set any leaf of the progress goal tree whose type matches the goal_string to the value passed as para...
Definition: achievement.cpp:253
int getProgress()
Returns how many goals of an achievement have been achieved.
Definition: achievement.cpp:155
virtual irr::core::stringw getGoalProgressAsString()
Returns how many goals of an achievement have been achieved, in the form n/m.
Definition: achievement.cpp:76
bool m_achieved
True if this achievement has been achieved.
Definition: achievement.hpp:45
virtual irr::core::stringw getProgressAsString()
Returns how much of an achievement has been achieved in the form n/m.
Definition: achievement.cpp:141
virtual void saveProgress(UTFWriter &out)
Saves the achievement status to a file.
Definition: achievement.cpp:64
int getFullfiledGoals()
Returns how many goals of an achievement have been achieved.
Definition: achievement.cpp:86
virtual void loadProgress(const XMLNode *node)
Loads the value from an XML node.
Definition: achievement.cpp:55
bool recursiveCompletionCheck(AchievementInfo::goalTree &progress, AchievementInfo::goalTree &reference)
Checks if this achievement has been achieved.
Definition: achievement.cpp:336
AchievementInfo * m_achievement_info
A pointer to the corresponding AchievementInfo instance.
Definition: achievement.hpp:69
utility class used to write wide (UTF-16 or UTF-32, depending of size of wchar_t) XML files
Definition: utf_writer.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
Definition: achievement_info.hpp:53
Declares the general types that are used by the network.