players.c
changeset 2613 b008d366ed8a
parent 2572 f3ab5cadbdc5
child 2616 e47170379049
--- a/players.c	Mon Nov 07 13:02:33 2005 +0000
+++ b/players.c	Mon Nov 07 13:30:43 2005 +0000
@@ -897,7 +897,7 @@
 	return 0;
 }
 
-static const StringID _endgame_performance_titles[16] = {
+static const StringID _endgame_perf_titles[16] = {
 	STR_0213_BUSINESSMAN,
 	STR_0213_BUSINESSMAN,
 	STR_0213_BUSINESSMAN,
@@ -918,7 +918,10 @@
 
 StringID EndGameGetPerformanceTitleFromValue(uint value)
 {
-	return _endgame_performance_titles[minu(value, 1000) >> 6];
+	value = minu(value, 1000) >> 6;
+	if (value >= lengthof(_endgame_perf_titles)) value = lengthof(_endgame_perf_titles);
+
+	return _endgame_perf_titles[value];
 }
 
 /* Return true if any cheat has been used, false otherwise */
@@ -1029,7 +1032,7 @@
 /* Save HighScore table to file */
 void SaveToHighScore(void)
 {
-	FILE *fp = fopen(_highscore_file, "w");
+	FILE *fp = fopen(_highscore_file, "wb");
 
 	if (fp != NULL) {
 		uint i;
@@ -1043,7 +1046,7 @@
 				fwrite(&length, sizeof(length), 1, fp); // write away string length
 				fwrite(hs->company, length, 1, fp);
 				fwrite(&hs->score, sizeof(hs->score), 1, fp);
-				fwrite(&hs->title, sizeof(hs->title), 1, fp);
+				fwrite("", 2, 1, fp); /* XXX - placeholder for hs->title, not saved anymore; compatibility */
 			}
 		}
 		fclose(fp);
@@ -1053,7 +1056,7 @@
 /* Initialize the highscore table to 0 and if any file exists, load in values */
 void LoadFromHighScore(void)
 {
-	FILE *fp = fopen(_highscore_file, "r");
+	FILE *fp = fopen(_highscore_file, "rb");
 
 	memset(_highscore_table, 0, sizeof(_highscore_table));
 
@@ -1068,7 +1071,8 @@
 
 				fread(hs->company, 1, length, fp);
 				fread(&hs->score, sizeof(hs->score), 1, fp);
-				fread(&hs->title, sizeof(hs->title), 1, fp);
+				fseek(fp, 2, SEEK_CUR); /* XXX - placeholder for hs->title, not saved anymore; compatibility */
+				hs->title = EndGameGetPerformanceTitleFromValue(hs->score);
 			}
 		}
 		fclose(fp);