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 "video/color.hpp"
23 #include "video/surface_ptr.hpp"
24 
25 class DrawingContext;
26 class Level;
27 class SquirrelVM;
28 
32 class Statistics final
33 {
34 private:
35  static Color header_color;
36  static Color text_color;
37 
38 public:
39  static std::string coins_to_string(int coins, int total_coins);
40  static std::string frags_to_string(int badguys, int total_badguys);
41  static std::string time_to_string(float time);
42  static std::string secrets_to_string(int secrets, int total_secrets);
43 
44 public:
45  enum Status { INVALID, ACCUMULATING, FINAL };
46 
47 public:
48  Statistics();
51  void serialize_to_squirrel(SquirrelVM& vm) const;
52 
55 
56  void draw_worldmap_info(DrawingContext& context, float target_time);
57  void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, const SurfacePtr& backdrop);
59  void init(const Level& level);
60  void finish(float time);
61  void invalidate();
62 
63  Status get_status() const { return m_status; }
64 
65 public:
66  void update(const Statistics& stats);
67  bool completed(const Statistics& stats, const float target_time) const; /* Check if stats match total stats */
68 
69  float get_time() const { return m_time; }
70 
71 private:
72  void calculate_max_caption_length();
73 
74 private:
75  enum Status m_status;
76 
77 public:
82  int m_coins;
83  int m_badguys;
84  int m_secrets;
86 private:
87  float m_time;
89 private:
90  int m_max_width;
93  std::string CAPTION_MAX_COINS;
94  std::string CAPTION_MAX_FRAGGING;
95  std::string CAPTION_MAX_SECRETS;
96  std::string CAPTION_BEST_TIME;
97  std::string CAPTION_TARGET_TIME;
98 
99  float WMAP_INFO_LEFT_X;
100  float WMAP_INFO_RIGHT_X;
101  float WMAP_INFO_TOP_Y1;
102  float WMAP_INFO_TOP_Y2;
103 
104 private:
105  Statistics(const Statistics&) = delete;
106  Statistics& operator=(const Statistics&) = delete;
107 };
108 
109 #endif
110 
111 /* EOF */
void unserialize_from_squirrel(SquirrelVM &vm)
unserialize statistics object from squirrel table "statistics"
Definition: statistics.cpp:102
void serialize_to_squirrel(SquirrelVM &vm) const
serialize statistics object as squirrel table "statistics"
Definition: statistics.cpp:86
int m_secrets
secret areas found
Definition: statistics.hpp:84
This class is a layer between level and worldmap to keep track of stuff like scores, and minor, but funny things, like number of jumps and stuff.
Definition: statistics.hpp:32
int m_total_coins
coins in level
Definition: statistics.hpp:78
int m_badguys
badguys actively killed
Definition: statistics.hpp:83
void draw_worldmap_info(DrawingContext &context, float target_time)
draw worldmap stat HUD
Definition: statistics.cpp:125
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:29
void update(const Statistics &stats)
Given another Statistics object finds the best of each one.
Definition: statistics.cpp:281
Statistics()
Creates new statistics, call reset() before counting.
Definition: statistics.cpp:37
Basic wrapper around HSQUIRRELVM with some utility functions, not to be confused with SquirrelVirtual...
Definition: squirrel_vm.hpp:29
Definition: color.hpp:25
int m_total_secrets
secret areas in level
Definition: statistics.hpp:80
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
int m_total_badguys
(vincible) badguys in level
Definition: statistics.hpp:79
void draw_endseq_panel(DrawingContext &context, Statistics *best_stats, const SurfacePtr &backdrop)
draw panel shown during level&#39;s end sequence
Definition: statistics.cpp:187
int m_coins
coins collected
Definition: statistics.hpp:82