New grow and skid sounds from remaxim
[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 "video/color.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   static Color header_color;
39   static Color text_color;
40 public:
41   int coins; /**< coins collected */
42   int total_coins; /**< coins in level */
43   int badguys; /**< badguys actively killed */
44   int total_badguys; /**< (vincible) badguys in level */
45   float time; /**< seconds needed */
46   int secrets; /**< secret areas found */
47   int total_secrets; /**< secret areas in level */
48
49 public:
50   Statistics(); /**< Creates new statistics, call reset() before counting */
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   /**
59    * serialize statistics object as squirrel table "statistics"
60    */
61   void serialize_to_squirrel(HSQUIRRELVM vm);
62
63   /**
64    * unserialize statistics object from squirrel table "statistics"
65    */
66   void unserialize_from_squirrel(HSQUIRRELVM vm);
67
68   void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
69   void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */
70
71   void zero(); /**< Set stats to zero */
72   void reset(); /**< Set stats (but not totals) to zero */
73   void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */
74   void operator+=(const Statistics& o); /**< Add two Statistics objects */
75
76   void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */
77   
78   static std::string coins_to_string(int coins, int total_coins);
79   static std::string frags_to_string(int badguys, int total_badguys);
80   static std::string time_to_string(float time);
81   static std::string secrets_to_string(int secrets, int total_secrets);
82
83 private:
84   bool valid; /**< stores whether these statistics can be trusted */
85
86 };
87
88 #endif /*SUPERTUX_STATISTICS_H*/