3 * Daniel Nelson - 12/3/1
5 * Copyright (C) 2000 Daniel Nelson
6 * Copyright (C) 2004 Andrew Sayman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Daniel Nelson - aluminumangel.org
26 * Handles the score for solo games.
34 #include "TextureLoader.h"
36 #include "MetaState.h"
41 int Score::top_combo_multiplier
;
42 int Score::top_combo_score
;
43 ComboRank
Score::combo_record
[GC_SCORE_MULT_LENGTH
];
44 short Score::digits
[GC_NUMBER_DIGITS
];
45 short Score::previous_digits
[GC_NUMBER_DIGITS
];
46 int Score::fade_timer
;
47 GLfloat
Score::inverse_timer_start
;
48 int Score::n_digits_displayed
;
49 int Score::special_block_scores
[BF_NUMBER_SPECIAL
]
56 10, }; // special orange
58 int Score::player_rank
;
59 Rank
Score::record
[GC_SCORE_REC_LENGTH
];
61 void Score::initialize ( )
63 if (!(MetaState::mode
& CM_SOLO
)) return;
65 score
= backlog
= top_combo_multiplier
= top_combo_score
= 0;
66 n_digits_displayed
= GC_MIN_NUMBER_DIGITS_DISPLAYED
;
67 for (int n
= GC_NUMBER_DIGITS
; n
--; ) {
68 digits
[n
] = previous_digits
[n
] = 0;
70 inverse_timer_start
= 1.0f
;
74 if (!readScoreRecord()) setupDefaultScoreRecord();
75 if (!readMultRecord()) setupDefaultMultRecord();
78 void Score::cleanUp ( )
80 if ((MetaState::mode
& CM_SOLO
) && player_rank
!= -1)
84 int Score::gameFinish ( )
86 // first do non-victory deciding scores
87 for (int n
= GC_SCORE_MULT_LENGTH
; n
--; )
88 if (top_combo_multiplier
> combo_record
[n
].multiplier
) {
92 for (int n
= 0; n
< player_rank
; n
++) {
93 strncpy(combo_record
[n
].name
, combo_record
[n
+ 1].name
, GC_PLAYER_NAME_LENGTH
);
94 combo_record
[n
].multiplier
= combo_record
[n
+ 1].multiplier
;
96 strncpy(combo_record
[player_rank
].name
, MetaState::player_name
,
97 GC_PLAYER_NAME_LENGTH
);
98 combo_record
[player_rank
].multiplier
= top_combo_multiplier
;
102 // now decide the winner
103 for (int n
= GC_SCORE_REC_LENGTH
; n
--; )
104 if (score
> record
[n
].score
) {
108 for (int n
= 0; n
< player_rank
; n
++) {
109 strncpy(record
[n
].name
, record
[n
+ 1].name
, GC_PLAYER_NAME_LENGTH
);
110 record
[n
].score
= record
[n
+ 1].score
;
112 strncpy(record
[player_rank
].name
, MetaState::player_name
,
113 GC_PLAYER_NAME_LENGTH
);
114 record
[player_rank
].score
= score
;
121 bool Score::readMultRecord ( )
125 TextureLoader::buildLocalDataFileName(GC_MULT_FILE_NAME
, file_name
);
126 ifstream
new_file(file_name
);
127 if (new_file
.fail()) return false;
129 for (int n
= GC_SCORE_MULT_LENGTH
; n
--; ) {
130 new_file
.getline(combo_record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
131 new_file
.getline(buffer
, 256);
132 combo_record
[n
].multiplier
= atoi(buffer
);
133 if (new_file
.fail()) return false;
138 bool Score::readScoreRecord ( )
141 TextureLoader::buildLocalDataFileName((MetaState::mode
& CM_X
)
142 ? GC_X_REC_FILE_NAME
: GC_REC_FILE_NAME
, file_name
);
143 ifstream
file(file_name
);
144 if (file
.fail()) return false;
147 for (int n
= GC_SCORE_REC_LENGTH
; n
--; ) {
148 file
.getline(record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
149 file
.getline(buffer
, 256);
150 record
[n
].score
= atoi(buffer
);
151 if (file
.fail()) return false;
156 void Score::writeScoreRecord ( )
159 TextureLoader::buildLocalDataFileName((MetaState::mode
& CM_X
)
160 ? GC_X_REC_FILE_NAME
: GC_REC_FILE_NAME
, file_name
);
161 ofstream
file(file_name
);
163 cerr
<< "Error writing to score record file '" << file_name
<< "'." << endl
;
167 for (int n
= GC_SCORE_REC_LENGTH
; n
--; )
168 file
<< record
[n
].name
<< '\n' << record
[n
].score
<< '\n';
172 TextureLoader::buildLocalDataFileName(GC_MULT_FILE_NAME
, file_name
);
173 ofstream
mult(file_name
);
175 cerr
<< "Error writing to score record file '" << file_name
<< "'." << endl
;
178 for (int n
= GC_SCORE_MULT_LENGTH
; n
--; )
179 mult
<< combo_record
[n
].name
<< '\n' << combo_record
[n
].multiplier
<< '\n';
184 void Score::setupDefaultMultRecord ( )
186 ifstream
new_file(GC_DEFAULT_MULT_FILE_NAME
);
187 if (new_file
.fail()) {
188 cerr
<< "Error opening data file '" << GC_DEFAULT_MULT_FILE_NAME
<< "'." << endl
;
193 for (int n
= GC_SCORE_MULT_LENGTH
; n
--; ) {
194 new_file
.getline(combo_record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
195 new_file
.getline(buffer
, 256);
196 combo_record
[n
].multiplier
= atoi(buffer
);
197 if (new_file
.fail()) break;
202 void Score::setupDefaultScoreRecord ( )
204 ifstream
file(GC_DEFAULT_REC_FILE_NAME
);
206 cerr
<< "Error opening data file '" << GC_DEFAULT_REC_FILE_NAME
<< "'." << endl
;
211 for (n
= GC_SCORE_REC_LENGTH
; n
--; ) {
212 file
.getline(record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
213 if (file
.fail()) break;
217 strncpy(record
[n
].name
, GC_SCORE_REC_DEFAULT_NAME
,
218 GC_PLAYER_NAME_LENGTH
);
219 for (n
= GC_SCORE_REC_LENGTH
; n
--; )
221 = ((n
+ 1) * GC_SCORE_DEFAULT_TOP_SCORE
) / GC_SCORE_REC_LENGTH
;