Mercurial > hg > early-roguelike
comparison xrogue/main.c @ 136:1fbdefa82533
xrogue: initial support for the -n option.
The scorefile location is also configurable now.
author | John "Elwin" Edwards |
---|---|
date | Wed, 22 Apr 2015 16:03:00 -0400 |
parents | ce0cf824c192 |
children | 0d151573bdb0 |
comparison
equal
deleted
inserted
replaced
135:ce0cf824c192 | 136:1fbdefa82533 |
---|---|
24 | 24 |
25 #include "mach_dep.h" | 25 #include "mach_dep.h" |
26 #include "network.h" | 26 #include "network.h" |
27 #include "rogue.h" | 27 #include "rogue.h" |
28 | 28 |
29 #define SCOREFILE "xrogue.scr" | |
30 #define SAVEDIR "." | |
31 | |
29 main(argc, argv, envp) | 32 main(argc, argv, envp) |
30 char **argv; | 33 char **argv; |
31 char **envp; | 34 char **envp; |
32 { | 35 { |
33 register char *env; | 36 register char *env; |
44 /* Get default save file */ | 47 /* Get default save file */ |
45 strcpy(file_name, home); | 48 strcpy(file_name, home); |
46 strcat(file_name, "xrogue.sav"); | 49 strcat(file_name, "xrogue.sav"); |
47 | 50 |
48 /* Get default score file */ | 51 /* Get default score file */ |
52 #ifdef SCOREFILE | |
53 strncpy(score_file, SCOREFILE, LINELEN); | |
54 score_file[LINELEN-1] = '\0'; | |
55 #else | |
49 strcpy(score_file, md_getroguedir()); | 56 strcpy(score_file, md_getroguedir()); |
50 | 57 |
51 if (*score_file) | 58 if (*score_file) |
52 strcat(score_file,"/"); | 59 strcat(score_file,"/"); |
53 | 60 |
54 strcat(score_file, "xrogue.scr"); | 61 strcat(score_file, "xrogue.scr"); |
62 #endif | |
63 | |
64 #ifdef SAVEDIR | |
65 /* Check for common save location */ | |
66 if (argc >= 3 && strcmp(argv[1], "-n") == 0) | |
67 { | |
68 strncpy(whoami, argv[2], 79); | |
69 whoami[79] = '\0'; | |
70 use_savedir = TRUE; | |
71 if (LINELEN <= snprintf(file_name, LINELEN, "%s/%d-%s.xrsav", SAVEDIR, | |
72 md_getuid(), whoami)) | |
73 { | |
74 strcpy(file_name, "xrogue.sav"); | |
75 use_savedir = FALSE; | |
76 } | |
77 } | |
78 #endif | |
55 | 79 |
56 if ((env = getenv("ROGUEOPTS")) != NULL) | 80 if ((env = getenv("ROGUEOPTS")) != NULL) |
57 parse_opts(env); | 81 parse_opts(env); |
58 | 82 |
59 if (whoami[0] == '\0') | 83 if (whoami[0] == '\0') |
119 printf("Sorry, %s, but the system is too loaded now.\n", whoami); | 143 printf("Sorry, %s, but the system is too loaded now.\n", whoami); |
120 printf("Try again later.\n"); | 144 printf("Try again later.\n"); |
121 exit_game(0); | 145 exit_game(0); |
122 } | 146 } |
123 | 147 |
148 if (use_savedir) | |
149 { | |
150 /* restore() will return TRUE if a new game should be started. */ | |
151 if (!restore(file_name, envp)) | |
152 exit_game(0); | |
153 } | |
124 if (argc == 2) | 154 if (argc == 2) |
125 if (!restore(argv[1], envp)) /* Note: restore will never return */ | 155 if (!restore(argv[1], envp)) /* Note: restore will never return */ |
126 exit_game(0); | 156 exit_game(0); |
127 | 157 |
128 if (wizard && getenv("SEED") != NULL) { | 158 if (wizard && getenv("SEED") != NULL) { |