SuperTuxKart
Loading...
Searching...
No Matches
challenge_status.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2008-2015 Joerg Henrichs
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_CHALLENGE_STATUS_HPP
20#define HEADER_CHALLENGE_STATUS_HPP
21
28#include <string>
29#include <vector>
30#include <fstream>
31#include <irrString.h>
32
33#include "race/race_manager.hpp"
34#include "utils/no_copy.hpp"
35
36class ChallengeData;
37class UTFWriter;
38class XMLNode;
39
52class ChallengeStatus : public NoCopy
53{
54private:
55 // Stores the active and solved status for each difficulty with a bitmask
56 int m_active;
57 int m_solved;
58
59 // If the challenge's SuperTux time requirement has been beaten
60 // in a (s)lower difficulty.
61 bool m_max_req_in_lower_diff;
62
65
66public:
68 {
69 m_data = data;
70 m_active = 0;
71 m_solved = 0;
72 m_max_req_in_lower_diff = false;
73 }
74 virtual ~ChallengeStatus() {};
75 void load(const XMLNode* config);
76 void save(UTFWriter& writer);
77 void setSolved(RaceManager::Difficulty d);
78
79 // ------------------------------------------------------------------------
83 {
84 return ((m_solved >> (int) d)&0x01) == 1;
85 } // isSolved
86 // ------------------------------------------------------------------------
89 bool isSolvedAtAnyDifficulty() const { return m_solved != 0; }
93 {
94 return (m_solved & 0x08) ? RaceManager::DIFFICULTY_BEST :
95 (m_solved & 0x04) ? RaceManager::DIFFICULTY_HARD :
96 (m_solved & 0x02) ? RaceManager::DIFFICULTY_MEDIUM :
97 (m_solved & 0x01) ? RaceManager::DIFFICULTY_EASY :
98 RaceManager::DIFFICULTY_NONE;
99 } // highestSolved
100 // ------------------------------------------------------------------------
104 {
105 return ((m_active >> (int) d)&0x01) == 1;
106 } // isActive
107 // ------------------------------------------------------------------------
111 {
112 m_active |= (0x01 << (int) d);
113 } // setActive
114 // ------------------------------------------------------------------------
116 bool isUnlockList();
117
118 // ------------------------------------------------------------------------
120 bool isGrandPrix();
121 // ------------------------------------------------------------------------
125 {
126 if (!isGrandPrix() && !isUnlockList())
127 m_max_req_in_lower_diff = true;
128 } // setMaxReqInLowerDiff
129 // ------------------------------------------------------------------------
133 {
134 return m_max_req_in_lower_diff;
135 } // areMaxReqMetInLowerDiff
136 // ------------------------------------------------------------------------
139 const ChallengeData* getData() const { return m_data; }
140}; // ChallengeStatus
141#endif
the description of one challenge
Definition: challenge_data.hpp:35
The state of a challenge for one player.
Definition: challenge_status.hpp:53
bool isSolved(RaceManager::Difficulty d) const
Returns if this challenge was solved at the specified difficulty.
Definition: challenge_status.hpp:82
bool areMaxReqMetInLowerDiff() const
Returns if the hardest difficulty requirements have been met in a lower difficulty.
Definition: challenge_status.hpp:132
void setActive(RaceManager::Difficulty d)
Sets this challenge to be active.
Definition: challenge_status.hpp:110
const ChallengeData * m_data
Pointer to the original challenge data.
Definition: challenge_status.hpp:64
RaceManager::Difficulty highestSolved() const
Returns the highest difficulty at which this challenge was solved.
Definition: challenge_status.hpp:92
bool isUnlockList()
Returns if this challenge is only an unlock list.
Definition: challenge_status.cpp:81
void setMaxReqInLowerDiff()
Used when a challenge's requirement in the hardest difficulty are matched in a lower difficulty.
Definition: challenge_status.hpp:124
bool isActive(RaceManager::Difficulty d) const
True if this challenge is active at the given difficulty.
Definition: challenge_status.hpp:103
void load(const XMLNode *config)
Loads the state for a challenge object (esp.
Definition: challenge_status.cpp:36
bool isGrandPrix()
Returns if this challenge is a grand prix.
Definition: challenge_status.cpp:87
bool isSolvedAtAnyDifficulty() const
Returns true if this challenge was solved at any difficult.
Definition: challenge_status.hpp:89
const ChallengeData * getData() const
Returns a pointer to the actual Challenge data.
Definition: challenge_status.hpp:139
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Difficulty
Game difficulty.
Definition: race_manager.hpp:230
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