2 // SuperTux - A Jump'n Run
3 // Copyright (C) 2004 Ricardo Cruz <rick2@aeiou.pt>
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 #include "utils/lispreader.h"
21 #include "utils/lispwriter.h"
22 #include "statistics.h"
23 #include "video/drawing_context.h"
24 #include "resources.h"
26 Statistics global_stats;
29 stat_name_to_string(int stat_enum)
35 case BADGUYS_SQUISHED_STAT:
36 return "badguys-squished";
39 case TIME_NEEDED_STAT:
46 Statistics::Statistics()
51 Statistics::~Statistics()
56 Statistics::parse(LispReader& reader)
58 for(int i = 0; i < NUM_STATS; i++)
59 reader.read_int(stat_name_to_string(i).c_str(), stats[i]);
63 Statistics::write(LispWriter& writer)
65 for(int i = 0; i < NUM_STATS; i++)
66 writer.write_int(stat_name_to_string(i), stats[i]);
70 Statistics::draw_worldmap_info(DrawingContext& context)
74 //TODO: this is just a simple message, will be imporved
75 sprintf(str, "Level Max Score: %d", stats[SCORE_STAT]);
76 context.draw_text(white_small_text, str, Vector(580, 580), LAYER_GUI);
80 Statistics::draw_message_info(DrawingContext& context)
86 Statistics::add_points(int stat, int points)
88 stats[stat] += points;
92 Statistics::get_points(int stat)
98 Statistics::set_points(int stat, int points)
100 stats[stat] = points;
106 for(int i = 0; i < NUM_STATS; i++)
111 Statistics::merge(Statistics& stats_)
113 stats[SCORE_STAT] = std::max(stats[SCORE_STAT], stats_.stats[SCORE_STAT]);
114 stats[JUMPS_STAT] = std::min(stats[JUMPS_STAT], stats_.stats[JUMPS_STAT]);
115 stats[BADGUYS_SQUISHED_STAT] =
116 std::max(stats[BADGUYS_SQUISHED_STAT], stats_.stats[BADGUYS_SQUISHED_STAT]);
117 stats[SHOTS_STAT] = std::min(stats[SHOTS_STAT], stats_.stats[SHOTS_STAT]);
118 stats[TIME_NEEDED_STAT] =
119 std::min(stats[TIME_NEEDED_STAT], stats_.stats[TIME_NEEDED_STAT]);
123 Statistics::operator+=(const Statistics& stats_)
125 for(int i = 0; i < NUM_STATS; i++)
126 stats[i] += stats_.stats[i];