218c02751b19b904404e455b89f76e174ae0b90e
[supertux.git] / src / statistics.h
1 //
2 //  SuperTux -  A Jump'n Run
3 //  Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
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 2
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
18 //  02111-1307, USA.
19
20 #ifndef SUPERTUX_STATISTICS_H
21 #define SUPERTUX_STATISTICS_H
22
23 #include "timer.h"
24 #include "lisp/lisp.h"
25 #include "lisp/writer.h"
26
27 using namespace SuperTux;
28
29 class DrawingContext;
30
31 #define SPLAYER 0
32 #define STOTAL  1
33
34 enum {
35   SCORE_STAT,
36   COINS_COLLECTED_STAT,
37   BADGUYS_KILLED_STAT,
38   TIME_NEEDED_STAT,
39   NUM_STATS
40 };
41
42 /** This class is a layer between level and worldmap to keep
43  *  track of stuff like scores, and minor, but funny things, like
44  *  number of jumps and stuff */
45
46 class Statistics
47 {
48 public:
49   // don't forget to call reset() to init stat
50   Statistics();
51   ~Statistics();
52
53   /// read statistics from lisp file
54   void parse(const lisp::Lisp& lisp);
55   /// write statistics to lisp file
56   void write(lisp::Writer& writer);
57
58   /* Draw to the worldmap or a game message */
59   // TODO: make this functions working
60   void draw_worldmap_info(DrawingContext& context);
61   void draw_message_info(DrawingContext& context, std::string title);
62
63   /* Add / Set / Get points to/from one of the stats this can keep track of */
64   void add_points(int stat, int points);
65   void set_points(int stat, int points);
66   int get_points(int stat);
67
68   void set_total_points(int stat, int points);
69
70   /* Reset statistics */
71   void reset();
72
73   /* Give another Statistics object, find the best of each one */
74   void merge(Statistics& stats);
75
76   /* Add two statistic objects */
77   void operator+=(const Statistics& o);
78
79 private:
80   int stats[NUM_STATS][2];
81
82   Timer2 timer;
83   int display_stat;
84 };
85
86 extern Statistics global_stats;
87
88 #endif /*SUPERTUX_STATISTICS_H*/