31 vector<achievement_data> achievements::_achievements;
33 achievements::achievements()
38 achievements::~achievements()
45 if (achievement == 0 || achievement == 255)
48 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
50 if (i->id() == achievement)
63 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
65 if (i->id() == achievement)
67 bool unlocked = i->update(bit);
87 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
99 if (index < _achievements.size())
101 return _achievements[index].is_unlocked();
108 if (index < _achievements.size())
110 return _achievements[index].id();
118 bool update_only = _achievements.size() > 0;
124 for (
u_int32 i = 0; i < j; i++)
132 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
136 i->_current = current;
144 _achievements[i]._current << file;
155 j = _achievements.size ();
158 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
161 i->_expected >> file;
172 if (_achievements.size() == 0)
174 if (!gamedata::load_achievements(0))
180 filepath +=
"/achievement.data";
183 if (!in.
open (filepath))
193 uLong checksum = adler32(0L, Z_NULL, 0);
196 for (
u_int32 i = 0; i < j; i++)
201 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
205 i->_persistent = global;
212 memcpy(buffer, &global, 4);
213 checksum = adler32(checksum, buffer, 5);
217 previous_checksum << in;
219 if (previous_checksum != checksum)
221 cout <<
"Checksum error: " << previous_checksum <<
" != " << checksum << endl;
223 _achievements.clear();
225 _achievements[0]._persistent = _achievements[0]._expected;
237 filepath +=
"/achievement.data";
240 if (!file.
open (filepath))
242 cerr <<
"Failed writing " << filepath << endl;
250 uLong checksum = adler32(0L, Z_NULL, 0);
252 for (vector<achievement_data>::iterator i = _achievements.begin(); i != _achievements.end(); i++)
255 i->_persistent >> file;
259 memcpy(buffer, &i->_persistent, 4);
260 checksum = adler32(checksum, buffer, 5);
278 _id(id), _expected(expected)
284 achievement_data::~achievement_data() { }
291 _current |= (1 << bit);
294 if (_current == _expected)
296 _persistent = _current;
void callback_func1(int arg)
Calls the python function with an integer.
Class to write data from a Gzip compressed file.
void close()
Close the file that was opened.
Class to read data from a Gzip compressed file.
static void make_persistent()
Write permanent unlock status of available achievements.
static bool is_unlocked(const u_int32 &index)
Checks whether the achievement at the given index is unlocked.
static void put_state(ogzstream &file)
Save achievement data to stream.
static bool get_state(igzstream &file)
Load achievement data from stream.
static bool create(const u_int8 &achievement, const u_int32 &bitmask)
Create a new achievement with the given id and the bitmask that will eventually unlock it...
#define u_int32
32 bits long unsigned integer
#define u_int8
8 bits long unsigned integer
static int num_achievements()
Return the total number of available achievements.
achievement_data(const u_int8 &id, const u_int32 &expected)
Create a new achievement with the given id and the bitmask that will eventually unlock it...
static void init()
Initialize achievements by loading all available achievements and their permanent unlocked status...
static void py_signal_connect(PyObject *pyfunc, PyObject *args=NULL)
Allow to connect a python callback to get notified when a new achievement was unlocked.
Manages in-game achievements.
bool open(const string &fname)
Opens a file for write access.
bool open(const string &fname)
Opens a file for read access.
static u_int8 achievement_id(const u_int32 &index)
Get the achievement id at the given index.
Declares the gamedata and data classes.
static void update(const u_int8 &achievement, const u_int8 &bit)
Set the nth bit of the given achievement to 1.
bool is_unlocked() const
Check whether the achievement is permanently unlocked.
bool update(const u_int8 &bit)
Set the nth bit of the given achievement to 1.
Data for a single achievement.
static int num_unlocked()
Returns how many achievements have been permanently unlocked.
Stores the C++ <-> Python callback binding.
static string user_data_dir()
Returns the absolute path to the user data directory (usually ~/.adonthell).