#303: Typo fixes from mathnerd314
[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
27 namespace lisp { class Writer; }
28 namespace lisp { class Lisp; }
29 class Surface;
30 class DrawingContext;
31
32 /** This class is a layer between level and worldmap to keep
33  *  track of stuff like scores, and minor, but funny things, like
34  *  number of jumps and stuff */
35 class Statistics
36 {
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   /// read statistics from lisp file
51   //void parse(const lisp::Lisp& lisp);
52   /// write statistics to lisp file
53   //void write(lisp::Writer& writer);
54
55   /**
56    * serialize statistics object as squirrel table "statistics"
57    */
58   void serialize_to_squirrel(HSQUIRRELVM vm);
59
60   /**
61    * unserialize statistics object from squirrel table "statistics"
62    */
63   void unserialize_from_squirrel(HSQUIRRELVM vm);
64
65   void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */
66   void draw_message_info(DrawingContext& context, std::string title); /**< draw stats at level start */
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(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 private:
77   bool valid; /**< stores whether these statistics can be trusted */
78
79   std::string coins_to_string(int coins, int total_coins) const;
80   std::string frags_to_string(int badguys, int total_badguys) const;
81   std::string time_to_string(float time) const;
82   std::string secrets_to_string(int secrets, int total_secrets) const;
83 };
84
85 #endif /*SUPERTUX_STATISTICS_H*/