aboutsummaryrefslogtreecommitdiffstats
path: root/highscore.h
blob: bb531ee3eb567857e081527636bf09ad20034166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * highscore.h
 */

#ifndef HIGHSCORE_H
#define HIGHSCORE_H 1

#include <inttypes.h>

#define PLAYER_LEN	11	/* Max length of player alias */
#define MAX_BEST        100	/* Number of best_total to keep track of */
#define MAX_LEVEL	75	/* Max levels to keep track of */
#define MAX_PER_LEVEL	3	/* Max "bests" per level */

struct best_total {
  uint64_t gameid;		/* GameID */
  int64_t score;		/* Final score */
  int32_t endlvl;		/* Ending level (-1) */
  unsigned char player[PLAYER_LEN+1]; /* Player alias */
};

struct best_level {
  struct best_level_score {
    uint64_t gameid;
    int64_t score;
  } score[MAX_PER_LEVEL];
  struct best_level_time {
    uint64_t gameid;
    int32_t time_ms;
  } time_ms[MAX_PER_LEVEL];
};

struct bests {
  struct best_total total[MAX_BEST];
  struct best_level level[MAX_LEVEL];
};

extern struct bests bests;

#define NO_TIME	0x7fffffff	/* Max int32_t value */

int highscore_add_total(uint64_t gameid, int64_t score, int endlvl, unsigned char **pptr);
int highscore_add_level_score(uint64_t gameid, int lvl, int64_t score);
int highscore_add_level_time(uint64_t gameid, int lvl, int32_t time_ms);
void highscore_init(void);
void highscore_parse(FILE *f);
int highscore_write(FILE *f);


#endif