Adonthell  0.4
achievements Class Reference

Class that keeps track of all available achievements, their permanent unlocked state and state in the current game. More...

#include <achievements.h>

Static Public Member Functions

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. More...
 
static void update (const u_int8 &achievement, const u_int8 &bit)
 Set the nth bit of the given achievement to 1. More...
 
static int num_achievements ()
 Return the total number of available achievements. More...
 
static int num_unlocked ()
 Returns how many achievements have been permanently unlocked. More...
 
static bool is_unlocked (const u_int32 &index)
 Checks whether the achievement at the given index is unlocked. More...
 
static u_int8 achievement_id (const u_int32 &index)
 Get the achievement id at the given index. More...
 
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. More...
 
static bool get_state (igzstream &file)
 Load achievement data from stream. More...
 
static void put_state (ogzstream &file)
 Save achievement data to stream. More...
 
static void init ()
 Initialize achievements by loading all available achievements and their permanent unlocked status. More...
 
static void make_persistent ()
 Write permanent unlock status of available achievements. More...
 

Detailed Description

Class that keeps track of all available achievements, their permanent unlocked state and state in the current game.

Definition at line 95 of file achievements.h.

Member Function Documentation

bool achievements::create ( const u_int8 achievement,
const u_int32 bitmask 
)
static

Create a new achievement with the given id and the bitmask that will eventually unlock it.

If an achievement with the given id already exists, it will be updated.

Note that ids 0 and 255 are reserved.

Parameters
achievementthe unique achievement id
bitmaskthe value that will unlock the achievement
Returns
true on success, false otherwise

Definition at line 43 of file achievements.cc.

void achievements::update ( const u_int8 achievement,
const u_int8 bit 
)
static

Set the nth bit of the given achievement to 1.

If the current value of the achievement afterwards matches the bitmask given when creating the achievement, the achievement will be unlocked permanently (only once).

Parameters
achievementthe unique achievement id
bitthe index of the bit to set to 1.

Definition at line 61 of file achievements.cc.

static int achievements::num_achievements ( )
inlinestatic

Return the total number of available achievements.

Returns
the number of achievements.

Definition at line 127 of file achievements.h.

int achievements::num_unlocked ( )
static

Returns how many achievements have been permanently unlocked.

Returns
the number of unlocked achievements.

Definition at line 84 of file achievements.cc.

bool achievements::is_unlocked ( const u_int32 index)
static

Checks whether the achievement at the given index is unlocked.

Parameters
indexa number between 0 and num_achievements
Returns
true if the achievement has been unlocked, false if not.

Definition at line 97 of file achievements.cc.

u_int8 achievements::achievement_id ( const u_int32 index)
static

Get the achievement id at the given index.

Parameters
indexa number between 0 and num_achievements
Returns
the id of the achievement stored at the given index.

Definition at line 106 of file achievements.cc.

void achievements::py_signal_connect ( PyObject *  pyfunc,
PyObject *  args = NULL 
)
static

Allow to connect a python callback to get notified when a new achievement was unlocked.

Callback will receive the achievement id along with any additional arguments given when connecting the callback

Parameters
pyfuncthe callback to register
argsthe optional arguments to use when executing the callback

Definition at line 267 of file achievements.cc.

bool achievements::get_state ( igzstream file)
static

Load achievement data from stream.

Parameters
filethe stream to read data from.
Returns
true on success, false otherwise.

Definition at line 115 of file achievements.cc.

void achievements::put_state ( ogzstream file)
static

Save achievement data to stream.

Parameters
filethe stream to write data to.

Definition at line 151 of file achievements.cc.

void achievements::init ( )
static

Initialize achievements by loading all available achievements and their permanent unlocked status.

Definition at line 166 of file achievements.cc.

void achievements::make_persistent ( )
static

Write permanent unlock status of available achievements.

Definition at line 231 of file achievements.cc.


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