Advanced Rogue family: fix the "score" option.
Changing the score file (when permitted) now works again, closing the old score file and opening the new one.
This commit is contained in:
parent
ea4244de91
commit
e3620a3781
14 changed files with 105 additions and 14 deletions
|
|
@ -16,7 +16,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
@ -43,8 +42,6 @@ static char *funfruit[] = {
|
||||||
};
|
};
|
||||||
#define NFRUIT (sizeof(funfruit) / sizeof (char *))
|
#define NFRUIT (sizeof(funfruit) / sizeof (char *))
|
||||||
|
|
||||||
int scorefd = -1;
|
|
||||||
FILE *logfile = NULL;
|
|
||||||
void open_records(void);
|
void open_records(void);
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
|
|
@ -255,7 +252,7 @@ void
|
||||||
open_records(void)
|
open_records(void)
|
||||||
{
|
{
|
||||||
if (scorefd == -1)
|
if (scorefd == -1)
|
||||||
scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
|
md_reopen_score();
|
||||||
#ifdef LOGFILE
|
#ifdef LOGFILE
|
||||||
if (logfile == NULL)
|
if (logfile == NULL)
|
||||||
logfile = fopen(LOGFILE, "a");
|
logfile = fopen(LOGFILE, "a");
|
||||||
|
|
|
||||||
|
|
@ -695,6 +695,17 @@ md_flushinp()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int scorefd;
|
||||||
|
extern char score_file[];
|
||||||
|
|
||||||
|
void
|
||||||
|
md_reopen_score(void)
|
||||||
|
{
|
||||||
|
if (scorefd > 0)
|
||||||
|
close(scorefd);
|
||||||
|
scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cursor/Keypad Support
|
Cursor/Keypad Support
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ int put_bool(),
|
||||||
put_str(),
|
put_str(),
|
||||||
get_str(),
|
get_str(),
|
||||||
get_restr(),
|
get_restr(),
|
||||||
|
get_score(),
|
||||||
put_abil(),
|
put_abil(),
|
||||||
get_abil(),
|
get_abil(),
|
||||||
get_quest(),
|
get_quest(),
|
||||||
|
|
@ -65,7 +66,7 @@ OPTION optlist[] = {
|
||||||
{"file", "Save file: ",
|
{"file", "Save file: ",
|
||||||
(int *) file_name, put_str, get_restr },
|
(int *) file_name, put_str, get_restr },
|
||||||
{"score", "Score file: ",
|
{"score", "Score file: ",
|
||||||
(int *) score_file, put_str, get_restr },
|
(int *) score_file, put_str, get_score },
|
||||||
{"class", "Character class: ",
|
{"class", "Character class: ",
|
||||||
(int *)&char_type, put_abil, get_abil },
|
(int *)&char_type, put_abil, get_abil },
|
||||||
{"quest", "Quest item: ",
|
{"quest", "Quest item: ",
|
||||||
|
|
@ -87,6 +88,26 @@ int get_restr(char *optstr, WINDOW *win)
|
||||||
return get_str(optstr, win);
|
return get_str(optstr, win);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* For the score file, which must be opened. */
|
||||||
|
int get_score(char *optstr, WINDOW *win)
|
||||||
|
{
|
||||||
|
char old_score_file[LINELEN];
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (use_savedir)
|
||||||
|
return get_restr(optstr, win);
|
||||||
|
|
||||||
|
strcpy(old_score_file, optstr);
|
||||||
|
status = get_str(optstr, win);
|
||||||
|
if (status != NORM)
|
||||||
|
return status;
|
||||||
|
if (strcmp(old_score_file, optstr))
|
||||||
|
{
|
||||||
|
md_reopen_score();
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The ability field is read-only
|
* The ability field is read-only
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ int pray_time = 0;
|
||||||
int spell_power = 0;
|
int spell_power = 0;
|
||||||
int turns = 0; /* Number of turns player has taken */
|
int turns = 0; /* Number of turns player has taken */
|
||||||
int quest_item = 0; /* Item player is looking for */
|
int quest_item = 0; /* Item player is looking for */
|
||||||
|
int scorefd = -1; /* File descriptor for the scorefile */
|
||||||
char nfloors = -1; /* Number of floors in this dungeon */
|
char nfloors = -1; /* Number of floors in this dungeon */
|
||||||
char curpurch[LINELEN*2]; /* name of item ready to buy */
|
char curpurch[LINELEN*2]; /* name of item ready to buy */
|
||||||
char PLAYER = VPLAYER; /* what the player looks like */
|
char PLAYER = VPLAYER; /* what the player looks like */
|
||||||
|
|
@ -123,6 +124,7 @@ char *spacemsg = "--Press space to continue--";
|
||||||
char *morestr = "-- More --";
|
char *morestr = "-- More --";
|
||||||
char *retstr = "[Press return to continue]";
|
char *retstr = "[Press return to continue]";
|
||||||
|
|
||||||
|
FILE *logfile = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* NOTE: the ordering of the points in this array is critical. They MUST
|
* NOTE: the ordering of the points in this array is critical. They MUST
|
||||||
|
|
|
||||||
|
|
@ -1050,6 +1050,7 @@ extern int pray_time; /* Number of prayer points/exp level */
|
||||||
extern int spell_power; /* Spell power left at this level */
|
extern int spell_power; /* Spell power left at this level */
|
||||||
extern int turns; /* Number of turns player has taken */
|
extern int turns; /* Number of turns player has taken */
|
||||||
extern int quest_item; /* Item hero is looking for */
|
extern int quest_item; /* Item hero is looking for */
|
||||||
|
extern int scorefd; /* File descriptor for the scorefile */
|
||||||
extern int cur_relic[]; /* Current relics */
|
extern int cur_relic[]; /* Current relics */
|
||||||
extern char take; /* Thing the rogue is taking */
|
extern char take; /* Thing the rogue is taking */
|
||||||
extern char prbuf[]; /* Buffer for sprintfs */
|
extern char prbuf[]; /* Buffer for sprintfs */
|
||||||
|
|
@ -1121,3 +1122,4 @@ extern char *stones[NSTONES];
|
||||||
extern char *metal[NMETAL];
|
extern char *metal[NMETAL];
|
||||||
extern char *wood[NWOOD];
|
extern char *wood[NWOOD];
|
||||||
extern coord ch_ret;
|
extern coord ch_ret;
|
||||||
|
extern FILE *logfile;
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#ifdef BSD
|
#ifdef BSD
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#else
|
#else
|
||||||
|
|
@ -33,8 +31,6 @@ extern struct uwdata wdata, oldwin;
|
||||||
extern char oldtext[WTXTNUM][WTXTLEN];
|
extern char oldtext[WTXTNUM][WTXTLEN];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int scorefd = -1;
|
|
||||||
FILE *logfile = NULL;
|
|
||||||
void open_records(void);
|
void open_records(void);
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
|
|
@ -553,7 +549,7 @@ void
|
||||||
open_records(void)
|
open_records(void)
|
||||||
{
|
{
|
||||||
if (scorefd == -1)
|
if (scorefd == -1)
|
||||||
scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
|
md_reopen_score();
|
||||||
#ifdef LOGFILE
|
#ifdef LOGFILE
|
||||||
if (logfile == NULL)
|
if (logfile == NULL)
|
||||||
logfile = fopen(LOGFILE, "a");
|
logfile = fopen(LOGFILE, "a");
|
||||||
|
|
|
||||||
|
|
@ -677,6 +677,17 @@ md_flushinp()
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int scorefd;
|
||||||
|
extern char score_file[];
|
||||||
|
|
||||||
|
void
|
||||||
|
md_reopen_score(void)
|
||||||
|
{
|
||||||
|
if (scorefd > 0)
|
||||||
|
close(scorefd);
|
||||||
|
scorefd = open(score_file, O_RDWR | O_CREAT, 0666);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Cursor/Keypad Support
|
Cursor/Keypad Support
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ int put_bool(),
|
||||||
put_quest();
|
put_quest();
|
||||||
|
|
||||||
int get_str_prot(char *opt, WINDOW *win);
|
int get_str_prot(char *opt, WINDOW *win);
|
||||||
|
int get_score(char *opt, WINDOW *win);
|
||||||
bool allowchange(OPTION *op);
|
bool allowchange(OPTION *op);
|
||||||
|
|
||||||
OPTION optlist[] = {
|
OPTION optlist[] = {
|
||||||
|
|
@ -72,7 +73,7 @@ OPTION optlist[] = {
|
||||||
{"file", "Save file: ",
|
{"file", "Save file: ",
|
||||||
(int *) file_name, put_str, get_str_prot },
|
(int *) file_name, put_str, get_str_prot },
|
||||||
{"score", "Score file: ",
|
{"score", "Score file: ",
|
||||||
(int *) score_file, put_str, get_str_prot },
|
(int *) score_file, put_str, get_score },
|
||||||
{"class", "Character class: ",
|
{"class", "Character class: ",
|
||||||
(int *)&char_type, put_abil, get_abil },
|
(int *)&char_type, put_abil, get_abil },
|
||||||
{"quest", "Quest item: ",
|
{"quest", "Quest item: ",
|
||||||
|
|
@ -486,6 +487,25 @@ get_str_prot(char *opt, WINDOW *win)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* When getting the scorefile, the new file must be opened. */
|
||||||
|
int
|
||||||
|
get_score(char *optstr, WINDOW *win)
|
||||||
|
{
|
||||||
|
char old_score_file[LINELEN];
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (use_savedir)
|
||||||
|
return get_str_prot(optstr, win);
|
||||||
|
|
||||||
|
strcpy(old_score_file, optstr);
|
||||||
|
status = get_str(optstr, win);
|
||||||
|
if (status == NORM && strcmp(old_score_file, optstr))
|
||||||
|
{
|
||||||
|
md_reopen_score();
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
allowchange(OPTION *op)
|
allowchange(OPTION *op)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ int pray_time = 0;
|
||||||
int spell_power = 0;
|
int spell_power = 0;
|
||||||
int turns = 0; /* Number of turns player has taken */
|
int turns = 0; /* Number of turns player has taken */
|
||||||
int quest_item = 0; /* Item player is looking for */
|
int quest_item = 0; /* Item player is looking for */
|
||||||
|
int scorefd = -1; /* File descriptor for score file */
|
||||||
int cols = 0; /* number of columns in terminal */
|
int cols = 0; /* number of columns in terminal */
|
||||||
int lines = 0; /* number of lines on the terminal */
|
int lines = 0; /* number of lines on the terminal */
|
||||||
char nfloors = -1; /* Number of floors in this dungeon */
|
char nfloors = -1; /* Number of floors in this dungeon */
|
||||||
|
|
@ -133,6 +134,7 @@ bool askme = FALSE;
|
||||||
bool in_shell = FALSE;
|
bool in_shell = FALSE;
|
||||||
bool daytime = TRUE;
|
bool daytime = TRUE;
|
||||||
bool use_savedir = FALSE;
|
bool use_savedir = FALSE;
|
||||||
|
FILE *logfile = NULL;
|
||||||
LEVTYPE levtype; /* type of level i'm on */
|
LEVTYPE levtype; /* type of level i'm on */
|
||||||
|
|
||||||
char *nothing = "Nothing seems to happen.";
|
char *nothing = "Nothing seems to happen.";
|
||||||
|
|
|
||||||
|
|
@ -1227,6 +1227,7 @@ extern int pray_time; /* Number of prayer points/exp level */
|
||||||
extern int spell_power; /* Spell power left at this level */
|
extern int spell_power; /* Spell power left at this level */
|
||||||
extern int turns; /* Number of turns player has taken */
|
extern int turns; /* Number of turns player has taken */
|
||||||
extern int quest_item; /* Item hero is looking for */
|
extern int quest_item; /* Item hero is looking for */
|
||||||
|
extern int scorefd; /* File descriptor for score file */
|
||||||
extern int cur_relic[]; /* Current relics */
|
extern int cur_relic[]; /* Current relics */
|
||||||
extern char take; /* Thing the rogue is taking */
|
extern char take; /* Thing the rogue is taking */
|
||||||
extern char prbuf[]; /* Buffer for sprintfs */
|
extern char prbuf[]; /* Buffer for sprintfs */
|
||||||
|
|
@ -1286,6 +1287,7 @@ extern char *nothing; /* "nothing happens" msg */
|
||||||
extern char *spacemsg;
|
extern char *spacemsg;
|
||||||
extern char *morestr;
|
extern char *morestr;
|
||||||
extern char *retstr;
|
extern char *retstr;
|
||||||
|
extern FILE *logfile;
|
||||||
extern LEVTYPE levtype;
|
extern LEVTYPE levtype;
|
||||||
extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
|
extern void (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
|
||||||
extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */
|
extern void (*res_abil[NUMABILITIES])(); /* Functions to change abilities */
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,6 @@
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "rogue.h"
|
#include "rogue.h"
|
||||||
|
|
||||||
FILE *scorefi = NULL;
|
|
||||||
FILE *logfile = NULL;
|
|
||||||
void open_records(void);
|
void open_records(void);
|
||||||
|
|
||||||
main(argc, argv, envp)
|
main(argc, argv, envp)
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ int put_bool(),
|
||||||
get_default();
|
get_default();
|
||||||
|
|
||||||
int get_str_prot(char *opt, WINDOW *win);
|
int get_str_prot(char *opt, WINDOW *win);
|
||||||
|
int get_score(char *opt, WINDOW *win);
|
||||||
bool allowchange(OPTION *op);
|
bool allowchange(OPTION *op);
|
||||||
|
|
||||||
OPTION optlist[] = {
|
OPTION optlist[] = {
|
||||||
|
|
@ -74,7 +75,7 @@ OPTION optlist[] = {
|
||||||
{"file", "Save file: ",
|
{"file", "Save file: ",
|
||||||
(int *) file_name, put_str, get_str_prot },
|
(int *) file_name, put_str, get_str_prot },
|
||||||
{"score", "Score file: ",
|
{"score", "Score file: ",
|
||||||
(int *) score_file, put_str, get_str_prot },
|
(int *) score_file, put_str, get_score },
|
||||||
{"class", "Character type: ",
|
{"class", "Character type: ",
|
||||||
(int *) &char_type, put_abil, get_abil },
|
(int *) &char_type, put_abil, get_abil },
|
||||||
{"quest", "Quest item: ",
|
{"quest", "Quest item: ",
|
||||||
|
|
@ -521,6 +522,29 @@ get_str_prot(char *opt, WINDOW *win)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* When getting the scorefile, the new file must be opened. */
|
||||||
|
int
|
||||||
|
get_score(char *optstr, WINDOW *win)
|
||||||
|
{
|
||||||
|
char old_score_file[LINELEN];
|
||||||
|
int status;
|
||||||
|
|
||||||
|
if (use_savedir)
|
||||||
|
return get_str_prot(optstr, win);
|
||||||
|
|
||||||
|
strcpy(old_score_file, optstr);
|
||||||
|
status = get_str(optstr, win);
|
||||||
|
if (status == NORM && strcmp(old_score_file, optstr))
|
||||||
|
{
|
||||||
|
if (scorefi != NULL)
|
||||||
|
fclose(scorefi);
|
||||||
|
scorefi = fopen(score_file, "rb+");
|
||||||
|
if (scorefi == NULL)
|
||||||
|
scorefi = fopen(score_file, "wb+");
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
allowchange(OPTION *op)
|
allowchange(OPTION *op)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,9 @@ bool in_shell = FALSE;
|
||||||
bool daytime = TRUE;
|
bool daytime = TRUE;
|
||||||
bool funfont = FALSE;
|
bool funfont = FALSE;
|
||||||
|
|
||||||
|
FILE *scorefi = NULL;
|
||||||
|
FILE *logfile = NULL;
|
||||||
|
|
||||||
LEVTYPE levtype; /* what type of level am i'm on? */
|
LEVTYPE levtype; /* what type of level am i'm on? */
|
||||||
|
|
||||||
char *nothing = "Nothing seems to happen. ";
|
char *nothing = "Nothing seems to happen. ";
|
||||||
|
|
|
||||||
|
|
@ -1398,6 +1398,8 @@ extern char *nothing; /* "Nothing seems to happen." */
|
||||||
extern char *spacemsg;
|
extern char *spacemsg;
|
||||||
extern char *morestr;
|
extern char *morestr;
|
||||||
extern char *retstr;
|
extern char *retstr;
|
||||||
|
extern FILE *scorefi;
|
||||||
|
extern FILE *logfile;
|
||||||
extern LEVTYPE levtype;
|
extern LEVTYPE levtype;
|
||||||
extern int (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
|
extern int (*add_abil[NUMABILITIES])(); /* Functions to change abilities */
|
||||||
extern int (*res_abil[NUMABILITIES])(); /* Functions to change abilities */
|
extern int (*res_abil[NUMABILITIES])(); /* Functions to change abilities */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue