Ooops, forgot to upload the actual Statistics implementation.
[supertux.git] / src / statistics.cpp
1 //  SuperTux
2 //  Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details
3 //
4 //  This program is free software; you can redistribute it and/or
5 //  modify it under the terms of the GNU General Public License
6 //  as published by the Free Software Foundation; either version 2
7 //  of the License, or (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 // 
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program; if not, write to the Free Software
16 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 //  02111-1307, USA.
18
19 #include "utils/lispreader.h"
20 #include "utils/lispwriter.h"
21 #include "statistics.h"
22
23 Statistics global_stats;
24
25 Statistics::Statistics()
26 {
27   reset();
28 }
29
30 Statistics::~Statistics()
31 {
32 }
33
34 void
35 Statistics::parse(LispReader& reader)
36 {
37   reader.read_int("score", stats[SCORE_STAT]);
38 }
39
40 void
41 Statistics::write(LispWriter& writer)
42 {
43   writer.write_int("score", stats[SCORE_STAT]);
44 }
45
46 void
47 Statistics::add_points(int stat, int points)
48 {
49   stats[stat] += points;
50 }
51
52 int
53 Statistics::get_points(int stat)
54 {
55   return stats[stat];
56 }
57
58 void
59 Statistics::reset()
60 {
61   for(int i = 0; i < MAX_STATS; i++)
62     stats[i] = 0;
63 }
64
65 void
66 Statistics::merge(Statistics& stats_)
67 {
68   stats[SCORE_STAT] = std::max(stats[SCORE_STAT], stats_.stats[SCORE_STAT]);
69 }
70
71 void
72 Statistics::operator+=(const Statistics& stats_)
73 {
74   stats[SCORE_STAT] += stats_.stats[SCORE_STAT];
75 }