Adding another round of custom snow tiles, thanks to dexnim
[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 Lisp; }
28 class DrawingContext;
29
30 /** This class is a layer between level and worldmap to keep
31  *  track of stuff like scores, and minor, but funny things, like
32  *  number of jumps and stuff */
33 class Statistics
34 {
35   static Color header_color;
36   static Color text_color;
37 public:
38   int coins; /**< coins collected */
39   int total_coins; /**< coins in level */
40   int badguys; /**< badguys actively killed */
41   int total_badguys; /**< (vincible) badguys in level */
42   float time; /**< seconds needed */
43   int secrets; /**< secret areas found */
44   int total_secrets; /**< secret areas in level */
45
46 public:
47   Statistics(); /**< Creates new statistics, call reset() before counting */
48   ~Statistics();
49
50   /**
51    * serialize statistics object as squirrel table "statistics"
52    */
53   void serialize_to_squirrel(HSQUIRRELVM vm);
54
55   /**
56    * unserialize statistics object from squirrel table "statistics"
57    */
58   void unserialize_from_squirrel(HSQUIRRELVM vm);
59
60   void draw_worldmap_info(DrawingContext& context, float target_time); /**< draw worldmap stat HUD */
61   void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop); /**< draw panel shown during level's end sequence */
62
63   void zero(); /**< Set stats to zero */
64   void reset(); /**< Set stats (but not totals) to zero */
65   void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */
66   void operator+=(const Statistics& o); /**< Add two Statistics objects */
67   bool completed(const Statistics& stats, const float target_time); /* Check if stats match total stats */
68
69   void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */
70
71   static std::string coins_to_string(int coins, int total_coins);
72   static std::string frags_to_string(int badguys, int total_badguys);
73   static std::string time_to_string(float time);
74   static std::string secrets_to_string(int secrets, int total_secrets);
75
76 private:
77   bool valid; /**< stores whether these statistics can be trusted */
78
79 };
80
81 #endif /*SUPERTUX_STATISTICS_H*/
82
83 /* EOF */