Fixes for datatype size on amd64.
[crack-attack.git] / src / Score.h
blob4f9de18d627a903f1c59ed84931ef3047ccf4afe
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
30 #include "Game.h"
31 #include "ComboTabulator.h"
32 #include "MetaState.h"
34 class Rank {
35 public:
36 char name[GC_PLAYER_NAME_LENGTH];
37 int score;
40 class ComboRank {
41 public:
42 char name[GC_PLAYER_NAME_LENGTH];
43 int multiplier;
44 int score;
47 /* static */ class Score {
48 public:
49 static void initialize ( );
50 static void cleanUp ( );
51 static int gameFinish ( );
53 static bool readScoreRecord ( );
54 static bool readMultRecord ( );
55 static void writeScoreRecord ( );
56 static void setupDefaultScoreRecord ( );
57 static void setupDefaultMultRecord ( );
59 static inline void timeStepMeta ( )
61 if (!(MetaState::mode & CM_SOLO)) return;
63 if (fade_timer == 0) return;
64 fade_timer--;
67 static inline void timeStepPlay ( )
69 if (!(MetaState::mode & CM_SOLO)) return;
71 if (fade_timer == 0) {
72 if (backlog > 0) {
73 backlog--;
74 score++;
75 incrementDigits();
76 fade_timer = GC_MAX_SCORE_INCREMENT_DELAY
77 - (GC_SCORE_DELAY_SLOPE * backlog);
78 if (fade_timer < GC_MIN_SCORE_INCREMENT_DELAY) {
79 fade_timer = GC_MIN_SCORE_INCREMENT_DELAY;
80 inverse_timer_start = 1.0f / (GLfloat) GC_MIN_SCORE_INCREMENT_DELAY;
81 } else
82 inverse_timer_start = 1.0f / (GLfloat) fade_timer;
84 } else
85 fade_timer--;
88 static inline void incrementDigits ( )
90 for (int i = GC_NUMBER_DIGITS; i--; )
91 previous_digits[i] = digits[i];
93 int i;
94 for (i = 0; i < GC_NUMBER_DIGITS; i++) {
95 digits[i]++;
96 if (digits[i] != 10) break;
97 digits[i] = 0;
99 if (++i > n_digits_displayed && i <= GC_NUMBER_DIGITS)
100 n_digits_displayed = i;
103 static inline void reportMultiplier ( ComboTabulator &combo )
105 // check for highest multiplier
106 if (combo.multiplier > top_combo_multiplier)
107 top_combo_multiplier = combo.multiplier;
109 if (!(MetaState::mode & CM_SOLO)) return;
111 // multiply this step's score
112 backlog += combo.base_score_this_step
113 * (combo.multiplier - combo.n_multipliers_this_step - 1);
115 // give another helping of the accumulated score
116 backlog += combo.base_accumulated_score
117 * combo.n_multipliers_this_step;
119 combo.n_multipliers_this_step = 0;
122 static inline int reportElimination ( ComboTabulator &combo )
124 if (!(MetaState::mode & CM_SOLO)) return 0;
126 int points = 0;
128 // gray elimination score
129 if (combo.special_magnitude > 0)
130 points
131 += GC_GRAY_SCORE * (combo.special_magnitude == GC_MIN_PATTERN_LENGTH
132 ? GC_MIN_PATTERN_SCORE
133 : combo.special_magnitude);
135 // colored elimination score
136 else
137 points += (combo.magnitude == GC_MIN_PATTERN_LENGTH
138 ? GC_MIN_PATTERN_SCORE
139 : combo.magnitude);
141 // special block bonuses
142 for (int n = BF_NUMBER_SPECIAL; n--; )
143 points += combo.special[n] * special_block_scores[n];
145 backlog += points;
147 return points;
150 static inline bool topRank ( )
152 return player_rank == GC_SCORE_REC_LENGTH - 1;
155 static int score;
156 static int backlog;
157 static short digits[GC_NUMBER_DIGITS];
158 static short previous_digits[GC_NUMBER_DIGITS];
159 static int fade_timer;
160 static GLfloat inverse_timer_start;
161 static int n_digits_displayed;
163 static int player_rank;
164 static Rank record[GC_SCORE_REC_LENGTH];
166 static int special_block_scores[BF_NUMBER_SPECIAL];
168 static int top_combo_multiplier;
169 static int top_combo_score;
170 static ComboRank combo_record[GC_SCORE_MULT_LENGTH];
173 #endif