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