e11c39d0d4a7a87b5bc4407a6840909ed192e0cd
[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 #include "video/surface_ptr.hpp"
26
27 namespace lisp { class Writer; }
28 namespace lisp { class Lisp; }
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   /**
52    * serialize statistics object as squirrel table "statistics"
53    */
54   void serialize_to_squirrel(HSQUIRRELVM vm);
55
56   /**
57    * unserialize statistics object from squirrel table "statistics"
58    */
59   void unserialize_from_squirrel(HSQUIRRELVM vm);
60
61   void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
62   void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop); /**< draw panel shown during level's end sequence */
63
64   void zero(); /**< Set stats to zero */
65   void reset(); /**< Set stats (but not totals) to zero */
66   void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */
67   void operator+=(const Statistics& o); /**< Add two Statistics objects */
68   bool completed(const Statistics& stats, const float target_time); /* Check if stats match total stats */
69
70   void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */
71   
72   static std::string coins_to_string(int coins, int total_coins);
73   static std::string frags_to_string(int badguys, int total_badguys);
74   static std::string time_to_string(float time);
75   static std::string secrets_to_string(int secrets, int total_secrets);
76
77 private:
78   bool valid; /**< stores whether these statistics can be trusted */
79
80 };
81
82 #endif /*SUPERTUX_STATISTICS_H*/
83
84 /* EOF */