X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fstatistics.hpp;h=a6c6c3766c9b0cf2b178cf2a354ceae1e092b7dd;hb=7a0031e8f250c852743709ab06ecafe1896eefbe;hp=08488e67352f6c6a7474efc35a650b21ae31b770;hpb=d5a14290ef3ba576ce0d6959155a4d45dffddf1f;p=supertux.git diff --git a/src/statistics.hpp b/src/statistics.hpp index 08488e673..a6c6c3766 100644 --- a/src/statistics.hpp +++ b/src/statistics.hpp @@ -2,7 +2,8 @@ // // SuperTux (Statistics module) // Copyright (C) 2004 Ricardo Cruz -// Copyright (C) 2006 Ondrej Hosek +// Copyright (C) 2006 Ondrej Hosek +// Copyright (C) 2006 Christoph Sommer // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -13,7 +14,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -21,67 +22,67 @@ #ifndef SUPERTUX_STATISTICS_H #define SUPERTUX_STATISTICS_H -#include "timer.hpp" -#include "lisp/lisp.hpp" -#include "lisp/writer.hpp" +#include +#include "video/color.hpp" +namespace lisp { class Writer; } +namespace lisp { class Lisp; } +class Surface; class DrawingContext; -#define SPLAYER 0 -#define STOTAL 1 - -enum { -// SCORE_STAT, - COINS_COLLECTED_STAT, - BADGUYS_KILLED_STAT, - TIME_NEEDED_STAT, - NUM_STATS -}; - /** 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 */ - class Statistics { + static Color header_color; + static Color text_color; public: - // don't forget to call reset() to init stat - Statistics(); + int coins; /**< coins collected */ + int total_coins; /**< coins in level */ + int badguys; /**< badguys actively killed */ + int total_badguys; /**< (vincible) badguys in level */ + float time; /**< seconds needed */ + int secrets; /**< secret areas found */ + int total_secrets; /**< secret areas in level */ + +public: + Statistics(); /**< Creates new statistics, call reset() before counting */ ~Statistics(); /// read statistics from lisp file - void parse(const lisp::Lisp& lisp); + //void parse(const lisp::Lisp& lisp); /// write statistics to lisp file - void write(lisp::Writer& writer); + //void write(lisp::Writer& writer); - /* Draw to the worldmap or a game message */ - // TODO: make this functions working - void draw_worldmap_info(DrawingContext& context); - void draw_message_info(DrawingContext& context, std::string title); + /** + * serialize statistics object as squirrel table "statistics" + */ + void serialize_to_squirrel(HSQUIRRELVM vm); - /* Add / Set / Get points to/from one of the stats this can keep track of */ - void add_points(int stat, int points); - void set_points(int stat, int points); - int get_points(int stat); + /** + * unserialize statistics object from squirrel table "statistics" + */ + void unserialize_from_squirrel(HSQUIRRELVM vm); - void set_total_points(int stat, int points); + void draw_worldmap_info(DrawingContext& context); /**< draw worldmap stat HUD */ + void draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop); /**< draw panel shown during level's end sequence */ - /* Reset statistics */ - void reset(); + void zero(); /**< Set stats to zero */ + void reset(); /**< Set stats (but not totals) to zero */ + void merge(const Statistics& stats); /**< Given another Statistics object finds the best of each one */ + void operator+=(const Statistics& o); /**< Add two Statistics objects */ - /* Give another Statistics object, find the best of each one */ - void merge(Statistics& stats); - - /* Add two statistic objects */ - void operator+=(const Statistics& o); + void declare_invalid(); /**< marks statistics as invalid for their entire lifetime (e.g. after cheating). Invalid statistics will not be merged or drawn. */ + + static std::string coins_to_string(int coins, int total_coins); + static std::string frags_to_string(int badguys, int total_badguys); + static std::string time_to_string(float time); + static std::string secrets_to_string(int secrets, int total_secrets); private: - int stats[NUM_STATS][2]; + bool valid; /**< stores whether these statistics can be trusted */ - Timer timer; - int display_stat; }; -extern Statistics global_stats; - #endif /*SUPERTUX_STATISTICS_H*/