summaryrefslogtreecommitdiffstats
path: root/highscore.h
blob: ba10d40fe32883d1f9e10d02c0cd9a30c1f30ab4 (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
51
52
53
54
55
56
57
/*
 * highscore.h
 */

#ifndef HIGHSCORE_H
#define HIGHSCORE_H 1

#include <inttypes.h>
#include <stdio.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 */
  uint8_t upload;		/* Need upload */
};

struct best_level {
  struct best_level_score {
    uint64_t gameid;
    int64_t score;
    uint8_t upload;
  } score[MAX_PER_LEVEL];
  struct best_level_time {
    uint64_t gameid;
    int32_t time_ms;
    uint8_t upload;
  } 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, uint8_t upload);
int highscore_add_level_score(uint64_t gameid, int lvl, int64_t score,
			      uint8_t upload);
int highscore_add_level_time(uint64_t gameid, int lvl, int32_t time_ms,
			     uint8_t upload);
void highscore_init(void);
void highscore_parse(FILE *f, uint8_t upload);
int highscore_write(FILE *f, uint8_t leave);
int have_upload_scores(void);

#endif