Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / supertux / statistics.hpp
1 //  SuperTux (Statistics module)
2 //  Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
3 //  Copyright (C) 2006 Ondrej Hosek <ondra.hosek@gmail.com>
4 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 //
6 //  This program is free software: you can redistribute it and/or modify
7 //  it under the terms of the GNU General Public License as published by
8 //  the Free Software Foundation, either version 3 of the License, or
9 //  (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 #ifndef HEADER_SUPERTUX_SUPERTUX_STATISTICS_HPP
20 #define HEADER_SUPERTUX_SUPERTUX_STATISTICS_HPP
21
22 #include <squirrel.h>
23
24 #include "video/color.hpp"
25
26 namespace lisp { class Writer; }
27 namespace lisp { class Lisp; }
28 class Surface;
29 class DrawingContext;
30
31 /** This class is a layer between level and worldmap to keep
32  *  track of stuff like scores, and minor, but funny things, like
33  *  number of jumps and stuff */
34 class Statistics
35 {
36   static Color header_color;
37   static Color text_color;
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 Reader& 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_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */
68
69   void zero(); /**< Set stats to zero */
70   void reset(); /**< Set stats (but not totals) to zero */
71   void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */
72   void operator+=(const Statistics& o); /**< Add two Statistics objects */
73
74   void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */
75   
76   static std::string coins_to_string(int coins, int total_coins);
77   static std::string frags_to_string(int badguys, int total_badguys);
78   static std::string time_to_string(float time);
79   static std::string secrets_to_string(int secrets, int total_secrets);
80
81 private:
82   bool valid; /**< stores whether these statistics can be trusted */
83
84 };
85
86 #endif /*SUPERTUX_STATISTICS_H*/
87
88 /* EOF */