SuperTuxKart
Loading...
Searching...
No Matches
achievement_info.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_INFO_HPP
21#define HEADER_ACHIEVEMENT_INFO_HPP
22
23#include "utils/types.hpp"
24
25#include <irrString.h>
26#include <string>
27#include <vector>
28
29// ============================================================================
30
31class Achievement;
32class XMLNode;
33
41{
42public:
43 // The operations supported for a goal
44 enum operationType {
45 OP_NONE = 0,
46 OP_ADD = 1,
47 OP_SUBSTRACT = 2,
48 };
49
50 // We store goals in a recursive tree.
51 // This structure matching the algorithms
52 // we use to manipulate it simplify code.
53 struct goalTree {
54 std::string type;
55 int value;
56 operationType operation;
57 std::vector<goalTree> children;
58 };
59
60private:
62 uint32_t m_id;
63
65 std::string m_name;
66
68 std::string m_description;
69
72
73 void parseGoals(const XMLNode * input, goalTree &parent);
74 int recursiveGoalCount(goalTree &parent);
75 int recursiveProgressCount(goalTree &parent);
76 int getRecursiveDepth(goalTree &parent);
77protected:
78 friend class Achievement;
79 friend class AchievementProgressDialog;
82
83public:
84 AchievementInfo(const XMLNode * input);
85 virtual ~AchievementInfo() {};
86
87 virtual irr::core::stringw goalString();
88 virtual irr::core::stringw progressString();
89
90 int getProgressTarget() { return recursiveProgressCount(m_goal_tree); }
91 int getGoalCount() { return recursiveGoalCount(m_goal_tree); }
92 int getDepth() { return getRecursiveDepth(m_goal_tree); }
93 uint32_t getID() const { return m_id; }
94 irr::core::stringw getDescription() const;
95 irr::core::stringw getName() const;
96 std::string getRawName() const { return m_name; }
97 std::string getRawDescription() const { return m_description; }
98 bool isSecret() const { return m_is_secret; }
99
100 // This function should not be called if copy already has children
101 void copyGoalTree(goalTree &copy, goalTree &model, bool set_values_to_zero);
102}; // class AchievementInfo
103
104
105#endif
106
107/*EOF*/
This class stores an achievement definition from the xml file, including title, description,...
Definition: achievement_info.hpp:41
virtual irr::core::stringw goalString()
Returns a string with the number of goals to fullfil to get this achievements.
Definition: achievement_info.cpp:187
std::string m_description
The description of this achievement.
Definition: achievement_info.hpp:68
void parseGoals(const XMLNode *input, goalTree &parent)
Parses recursively the list of goals, to construct the tree of goals.
Definition: achievement_info.cpp:67
virtual irr::core::stringw progressString()
Returns a string with the target of the goal if the achievement has only one goal (a sum counts as on...
Definition: achievement_info.cpp:215
int getRecursiveDepth(goalTree &parent)
Returns the goal tree's depth.
Definition: achievement_info.cpp:159
std::string m_name
The title of this achievement.
Definition: achievement_info.hpp:65
goalTree m_goal_tree
The tree storing all goals.
Definition: achievement_info.hpp:81
bool m_is_secret
A secret achievement has its progress not shown.
Definition: achievement_info.hpp:71
void copyGoalTree(goalTree &copy, goalTree &model, bool set_values_to_zero)
Copy a goal tree to an EMPTY goal tree by recursion.
Definition: achievement_info.cpp:141
uint32_t m_id
The id of this Achievement.
Definition: achievement_info.hpp:62
Dialog that shows an achievement description and progress.
Definition: achievement_progress_dialog.hpp:42
Definition: achievement.hpp:42
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.