Statistics are now saved to disk
[supertux.git] / src / statistics.hpp
1 //  $Id$
2 //
3 //  SuperTux (Statistics module)
4 //  Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
5 //  Copyright (C) 2006 Ondrej Hosek <ondra.hosek@gmail.com>
6 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 #ifndef SUPERTUX_STATISTICS_H
23 #define SUPERTUX_STATISTICS_H
24
25 #include <squirrel.h>
26 #include "timer.hpp"
27
28 namespace lisp { class Writer; }
29 namespace lisp { class Lisp; }
30 class Surface;
31 class DrawingContext;
32
33 /** This class is a layer between level and worldmap to keep
34  *  track of stuff like scores, and minor, but funny things, like
35  *  number of jumps and stuff */
36 class Statistics
37 {
38 public:
39   int coins; /**< coins collected */
40   int total_coins; /**< coins in level */
41   int badguys; /**< badguys actively killed */
42   int total_badguys; /**< (vincible) badguys in level */
43   float time; /**< seconds needed */
44   int secrets; /**< secret areas found */
45   int total_secrets; /**< secret areas in level */
46
47 public:
48   Statistics(); /**< Creates new statistics, call reset() before counting */
49   ~Statistics();
50
51   /// read statistics from lisp file
52   //void parse(const lisp::Lisp& lisp);
53   /// write statistics to lisp file
54   //void write(lisp::Writer& writer);
55
56   /**
57    * serialize statistics object as squirrel table "statistics"
58    */
59   void serialize_to_squirrel(HSQUIRRELVM vm);
60
61   /**
62    * unserialize statistics object from squirrel table "statistics"
63    */
64   void unserialize_from_squirrel(HSQUIRRELVM vm);
65
66   void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
67   void draw_message_info(DrawingContext& context, std::string title); /**< draw stats at level start */
68   void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */
69
70   void zero(); /**< Set stats to zero */
71   void reset(); /**< Set stats (but not totals) to zero */
72   void merge(Statistics& stats); /**< Given another Statistics object finds the best of each one */
73   void operator+=(const Statistics& o); /**< Add two Statistics objects */
74
75   void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */
76
77 private:
78   bool valid; /**< stores whether this statistics can be trusted */
79   Timer timer; /**< for draw_worldmap_info: time until switching to next stat */
80   int display_stat; /**< for draw_worldmap_info: which stat is currently displayed */
81 };
82
83 #endif /*SUPERTUX_STATISTICS_H*/