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 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 
20 #ifndef HEADER_SUPERTUX_SUPERTUX_STATISTICS_HPP
21 #define HEADER_SUPERTUX_SUPERTUX_STATISTICS_HPP
22 
23 #include "video/color.hpp"
24 #include "video/surface_ptr.hpp"
25 
26 class DrawingContext;
27 class Level;
28 
29 namespace ssq {
30 class Table;
31 } // namespace ssq
32 
36 class Statistics final
37 {
38 private:
39  static Color header_color;
40  static Color text_color;
41  static Color perfect_color;
42 
43 public:
44  static std::string coins_to_string(int coins, int total_coins);
45  static std::string frags_to_string(int badguys, int total_badguys);
46  static std::string time_to_string(float time);
47  static std::string secrets_to_string(int secrets, int total_secrets);
48 
49 public:
50  enum Status { INVALID, ACCUMULATING, FINAL };
51 
52 public:
53  Statistics();
56  void serialize_to_squirrel(ssq::Table& table) const;
57 
59  void unserialize_from_squirrel(const ssq::Table& table);
60 
61  void draw_worldmap_info(DrawingContext& context, float target_time);
62  void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, const SurfacePtr& backdrop, float target_time);
63  void draw_ingame_stats(DrawingContext& context, bool on_pause_menu);
66  void update_timers(float dt_sec);
67 
68  void init(const Level& level);
69  void finish(float time);
70  void invalidate();
71 
72  void update(const Statistics& stats);
73  bool completed(const Statistics& stats, const float target_time) const; /* Check if stats match total stats */
74 
75  int get_coins() const { return m_coins; }
76  int get_badguys() const { return m_badguys; }
77  int get_secrets() const { return m_secrets; }
78  float get_time() const { return m_time; }
79  Status get_status() const { return m_status; }
80 
81  void increment_coins() { m_coins++; check_coins(); }
82  void increment_badguys() { m_badguys++; check_badguys(); }
83  void increment_secrets() { m_secrets++; check_secrets(); }
84 
85 private:
86  void calculate_max_caption_length();
87 
88  void check_coins();
89  void check_badguys();
90  void check_secrets();
91 
92 private:
93  enum Status m_status;
94 
95 public:
100 private:
101  int m_coins;
102  int m_badguys;
103  int m_secrets;
105  float m_time;
107  bool m_cleared_coins,
108  m_cleared_badguys,
109  m_cleared_secrets;
110 
111  float m_coins_time,
112  m_badguys_time,
113  m_secrets_time;
114 
115 private:
116  int m_max_width;
119  std::string CAPTION_MAX_COINS;
120  std::string CAPTION_MAX_FRAGGING;
121  std::string CAPTION_MAX_SECRETS;
122  std::string CAPTION_BEST_TIME;
123  std::string CAPTION_TARGET_TIME;
124 
125  float WMAP_INFO_LEFT_X;
126  float WMAP_INFO_RIGHT_X;
127  float WMAP_INFO_TOP_Y1;
128  float WMAP_INFO_TOP_Y2;
129 
130  SurfacePtr coin_icon;
131  SurfacePtr badguy_icon;
132  SurfacePtr secret_icon;
133 
134 private:
135  Statistics(const Statistics&) = delete;
136  Statistics& operator=(const Statistics&) = delete;
137 };
138 
139 #endif
140 
141 /* EOF */
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:36
int m_total_coins
coins in level
Definition: statistics.hpp:96
Definition: path_object.hpp:28
Represents a collection of Sectors running in a single GameSession.
Definition: level.hpp:30
Definition: color.hpp:26
int m_total_secrets
secret areas in level
Definition: statistics.hpp:98
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:97