summaryrefslogtreecommitdiff
path: root/src/files.c
diff options
context:
space:
mode:
authorBardur Arantsson <bardur@scientician.net>2012-06-29 20:49:49 +0200
committerBardur Arantsson <bardur@scientician.net>2012-06-29 20:49:49 +0200
commitf7e87bc98111f97ca489e1f13999058a7df8171e (patch)
tree7775a192c756e9ae921087e26eb83d9b2db2c343 /src/files.c
parentc6cd8211eb4655520a607d7d1a854927de7a1803 (diff)
Split high score reading/writing into separate compilation unit
Diffstat (limited to 'src/files.c')
-rw-r--r--src/files.c157
1 files changed, 2 insertions, 155 deletions
diff --git a/src/files.c b/src/files.c
index ea1922a5..f8125148 100644
--- a/src/files.c
+++ b/src/files.c
@@ -12,6 +12,8 @@
#include "angband.h"
+#include "hiscore.h"
+
/*
* Extract the first few "tokens" from a buffer
@@ -4694,161 +4696,6 @@ static void show_info(void)
/*
- * Semi-Portable High Score List Entry (128 bytes) -- BEN
- *
- * All fields listed below are null terminated ascii strings.
- *
- * In addition, the "number" fields are right justified, and
- * space padded, to the full available length (minus the "null").
- *
- * Note that "string comparisons" are thus valid on "pts".
- */
-
-typedef struct high_score high_score;
-
-struct high_score
-{
- char what[8]; /* Version info (string) */
-
- char pts[10]; /* Total Score (number) */
-
- char gold[10]; /* Total Gold (number) */
-
- char turns[10]; /* Turns Taken (number) */
-
- char day[10]; /* Time stamp (string) */
-
- char who[16]; /* Player Name (string) */
-
- char unused_1[8]; /* Kept for compatibility only */
-
- char sex[2]; /* Player Sex (string) */
- char p_r[3]; /* Player Race (number) */
- char p_s[3]; /* Player Subrace (number) */
- char p_c[3]; /* Player Class (number) */
- char p_cs[3]; /* Player Class spec (number) */
-
- char cur_lev[4]; /* Current Player Level (number) */
- char cur_dun[4]; /* Current Dungeon Level (number) */
- char max_lev[4]; /* Max Player Level (number) */
- char max_dun[4]; /* Max Dungeon Level (number) */
-
- char arena_number[4]; /* Arena level attained -KMW- */
- char inside_arena[4]; /* Did the player die in the arena? */
- char inside_quest[4]; /* Did the player die in a quest? */
- char exit_bldg[4]; /* Can the player exit arena? Goal obtained? -KMW- */
-
- char how[32]; /* Method of death (string) */
-};
-
-
-
-/*
- * Seek score 'i' in the highscore file
- */
-static int highscore_seek(int highscore_fd, int i)
-{
- /* Seek for the requested record */
- return (fd_seek(highscore_fd, (huge)(i) * sizeof(high_score)));
-}
-
-
-/*
- * Read one score from the highscore file
- */
-static errr highscore_read(int highscore_fd, high_score *score)
-{
- /* Read the record, note failure */
- return (fd_read(highscore_fd, (char*)(score), sizeof(high_score)));
-}
-
-
-/*
- * Write one score to the highscore file
- */
-static int highscore_write(int highscore_fd, high_score *score)
-{
- /* Write the record, note failure */
- return (fd_write(highscore_fd, (char*)(score), sizeof(high_score)));
-}
-
-
-
-
-/*
- * Just determine where a new score *would* be placed
- * Return the location (0 is best) or -1 on failure
- */
-static int highscore_where(int highscore_fd, high_score *score)
-{
- int i;
-
- high_score the_score;
-
- /* Paranoia -- it may not have opened */
- if (highscore_fd < 0) return ( -1);
-
- /* Go to the start of the highscore file */
- if (highscore_seek(highscore_fd, 0)) return ( -1);
-
- /* Read until we get to a higher score */
- for (i = 0; i < MAX_HISCORES; i++)
- {
- if (highscore_read(highscore_fd, &the_score)) return (i);
- if (strcmp(the_score.pts, score->pts) < 0) return (i);
- }
-
- /* The "last" entry is always usable */
- return (MAX_HISCORES - 1);
-}
-
-
-/*
- * Actually place an entry into the high score file
- * Return the location (0 is best) or -1 on "failure"
- */
-static int highscore_add(int highscore_fd, high_score *score)
-{
- int i, slot;
- bool_ done = FALSE;
-
- high_score the_score, tmpscore;
-
-
- /* Paranoia -- it may not have opened */
- if (highscore_fd < 0) return ( -1);
-
- /* Determine where the score should go */
- slot = highscore_where(highscore_fd, score);
-
- /* Hack -- Not on the list */
- if (slot < 0) return ( -1);
-
- /* Hack -- prepare to dump the new score */
- the_score = (*score);
-
- /* Slide all the scores down one */
- for (i = slot; !done && (i < MAX_HISCORES); i++)
- {
- /* Read the old guy, note errors */
- if (highscore_seek(highscore_fd, i)) return ( -1);
- if (highscore_read(highscore_fd, &tmpscore)) done = TRUE;
-
- /* Back up and dump the score we were holding */
- if (highscore_seek(highscore_fd, i)) return ( -1);
- if (highscore_write(highscore_fd, &the_score)) return ( -1);
-
- /* Hack -- Save the old score, for the next pass */
- the_score = tmpscore;
- }
-
- /* Return location used */
- return (slot);
-}
-
-
-
-/*
* Display the scores in a given range.
* Assumes the high score list is already open.
* Only five entries per line, too much info.