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 short Score::digits
[GC_NUMBER_DIGITS
];
42 short Score::previous_digits
[GC_NUMBER_DIGITS
];
43 int Score::fade_timer
;
44 GLfloat
Score::inverse_timer_start
;
45 int Score::n_digits_displayed
;
46 int Score::special_block_scores
[BF_NUMBER_SPECIAL
]
53 10, }; // special orange
55 int Score::player_rank
;
56 Rank
Score::record
[GC_SCORE_REC_LENGTH
];
58 void Score::initialize ( )
60 if (!(MetaState::mode
& CM_SOLO
)) return;
63 n_digits_displayed
= GC_MIN_NUMBER_DIGITS_DISPLAYED
;
64 for (int n
= GC_NUMBER_DIGITS
; n
--; ) {
65 digits
[n
] = previous_digits
[n
] = 0;
67 inverse_timer_start
= 1.0f
;
71 if (!readScoreRecord()) setupDefaultScoreRecord();
74 void Score::cleanUp ( )
76 if ((MetaState::mode
& CM_SOLO
) && player_rank
!= -1)
80 int Score::gameFinish ( )
82 for (int n
= GC_SCORE_REC_LENGTH
; n
--; )
83 if (score
> record
[n
].score
) {
87 for (int n
= 0; n
< player_rank
; n
++) {
88 strncpy(record
[n
].name
, record
[n
+ 1].name
, GC_PLAYER_NAME_LENGTH
);
89 record
[n
].score
= record
[n
+ 1].score
;
91 strncpy(record
[player_rank
].name
, MetaState::player_name
,
92 GC_PLAYER_NAME_LENGTH
);
93 record
[player_rank
].score
= score
;
100 bool Score::readScoreRecord ( )
103 TextureLoader::buildLocalDataFileName((MetaState::mode
& CM_X
)
104 ? GC_X_REC_FILE_NAME
: GC_REC_FILE_NAME
, file_name
);
105 ifstream
file(file_name
);
106 if (file
.fail()) return false;
109 for (int n
= GC_SCORE_REC_LENGTH
; n
--; ) {
110 file
.getline(record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
111 file
.getline(buffer
, 256);
112 record
[n
].score
= atoi(buffer
);
113 if (file
.fail()) return false;
118 void Score::writeScoreRecord ( )
121 TextureLoader::buildLocalDataFileName((MetaState::mode
& CM_X
)
122 ? GC_X_REC_FILE_NAME
: GC_REC_FILE_NAME
, file_name
);
123 ofstream
file(file_name
);
125 cerr
<< "Error writing to score record file '" << file_name
<< "'." << endl
;
129 for (int n
= GC_SCORE_REC_LENGTH
; n
--; )
130 file
<< record
[n
].name
<< '\n' << record
[n
].score
<< '\n';
133 void Score::setupDefaultScoreRecord ( )
135 ifstream
file(GC_DEFAULT_REC_FILE_NAME
);
137 cerr
<< "Error opening data file '" GC_DEFAULT_REC_FILE_NAME
"'."
143 for (n
= GC_SCORE_REC_LENGTH
; n
--; ) {
144 file
.getline(record
[n
].name
, GC_PLAYER_NAME_LENGTH
);
145 if (file
.fail()) break;
149 strncpy(record
[n
].name
, GC_SCORE_REC_DEFAULT_NAME
,
150 GC_PLAYER_NAME_LENGTH
);
151 for (n
= GC_SCORE_REC_LENGTH
; n
--; )
153 = ((n
+ 1) * GC_SCORE_DEFAULT_TOP_SCORE
) / GC_SCORE_REC_LENGTH
;