Updated to include tests for Gentoo installation
[crack-attack.git] / src / Score.h
blob1979688e2d8cdc0ef328adb006f6dd06cb9935d1
1 /*
2 * Score.h
3 * Daniel Nelson - 8/24/0
5 * Copyright (C) 2000 Daniel Nelson
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * Daniel Nelson - aluminumangel.org
22 * 174 W. 18th Ave.
23 * Columbus, OH 43210
26 #ifndef SCORE_H
27 #define SCORE_H
29 using namespace std;
31 #include "Game.h"
32 #include "ComboTabulator.h"
33 #include "MetaState.h"
35 class Rank {
36 public:
37 char name[GC_PLAYER_NAME_LENGTH];
38 int score;
41 class ComboRank {
42 public:
43 char name[GC_PLAYER_NAME_LENGTH];
44 int multiplier;
45 int score;
48 /* static */ class Score {
49 public:
50 static void initialize ( );
51 static void cleanUp ( );
52 static int gameFinish ( );
54 static bool readScoreRecord ( );
55 static bool readMultRecord ( );
56 static void writeScoreRecord ( );
57 static void setupDefaultScoreRecord ( );
58 static void setupDefaultMultRecord ( );
60 static inline void timeStepMeta ( )
62 if (!(MetaState::mode & CM_SOLO)) return;
64 if (fade_timer == 0) return;
65 fade_timer--;
68 static inline void timeStepPlay ( )
70 if (!(MetaState::mode & CM_SOLO)) return;
72 if (fade_timer == 0) {
73 if (backlog > 0) {
74 backlog--;
75 score++;
76 incrementDigits();
77 fade_timer = GC_MAX_SCORE_INCREMENT_DELAY
78 - (GC_SCORE_DELAY_SLOPE * backlog);
79 if (fade_timer < GC_MIN_SCORE_INCREMENT_DELAY) {
80 fade_timer = GC_MIN_SCORE_INCREMENT_DELAY;
81 inverse_timer_start = 1.0f / (GLfloat) GC_MIN_SCORE_INCREMENT_DELAY;
82 } else
83 inverse_timer_start = 1.0f / (GLfloat) fade_timer;
85 } else
86 fade_timer--;
89 static inline void incrementDigits ( )
91 for (int i = GC_NUMBER_DIGITS; i--; )
92 previous_digits[i] = digits[i];
94 int i;
95 for (i = 0; i < GC_NUMBER_DIGITS; i++) {
96 digits[i]++;
97 if (digits[i] != 10) break;
98 digits[i] = 0;
100 if (++i > n_digits_displayed && i <= GC_NUMBER_DIGITS)
101 n_digits_displayed = i;
104 static inline void reportMultiplier ( ComboTabulator &combo )
106 // check for highest multiplier
107 if (combo.multiplier > top_combo_multiplier)
108 top_combo_multiplier = combo.multiplier;
110 if (!(MetaState::mode & CM_SOLO)) return;
112 // multiply this step's score
113 backlog += combo.base_score_this_step
114 * (combo.multiplier - combo.n_multipliers_this_step - 1);
116 // give another helping of the accumulated score
117 backlog += combo.base_accumulated_score
118 * combo.n_multipliers_this_step;
120 combo.n_multipliers_this_step = 0;
123 static inline int reportElimination ( ComboTabulator &combo )
125 if (!(MetaState::mode & CM_SOLO)) return 0;
127 int points = 0;
129 // gray elimination score
130 if (combo.special_magnitude > 0)
131 points
132 += GC_GRAY_SCORE * (combo.special_magnitude == GC_MIN_PATTERN_LENGTH
133 ? GC_MIN_PATTERN_SCORE
134 : combo.special_magnitude);
136 // colored elimination score
137 else
138 points += (combo.magnitude == GC_MIN_PATTERN_LENGTH
139 ? GC_MIN_PATTERN_SCORE
140 : combo.magnitude);
142 // special block bonuses
143 for (int n = BF_NUMBER_SPECIAL; n--; )
144 points += combo.special[n] * special_block_scores[n];
146 backlog += points;
148 return points;
151 static inline bool topRank ( )
153 return player_rank == GC_SCORE_REC_LENGTH - 1;
156 static int score;
157 static int backlog;
158 static short digits[GC_NUMBER_DIGITS];
159 static short previous_digits[GC_NUMBER_DIGITS];
160 static int fade_timer;
161 static GLfloat inverse_timer_start;
162 static int n_digits_displayed;
164 static int player_rank;
165 static Rank record[GC_SCORE_REC_LENGTH];
167 static int special_block_scores[BF_NUMBER_SPECIAL];
169 static int top_combo_multiplier;
170 static int top_combo_score;
171 static ComboRank combo_record[GC_SCORE_MULT_LENGTH];
174 #endif