comparison arogue5/main.c @ 64:a98834ce7e04

arogue5: add the savedir feature.
author elwin
date Fri, 10 Aug 2012 05:16:08 +0000
parents 0ed67132cf10
children c56f672244f4
comparison
equal deleted inserted replaced
63:0ed67132cf10 64:a98834ce7e04
55 * get home and options from environment 55 * get home and options from environment
56 */ 56 */
57 57
58 strncpy(home,md_gethomedir(),LINELEN); 58 strncpy(home,md_gethomedir(),LINELEN);
59 59
60 #ifdef SAVEDIR
61 if (argc >= 3 && !strcmp(argv[1], "-n")) {
62 use_savedir = TRUE;
63 strncpy(whoami, argv[2], LINELEN);
64 whoami[LINELEN - 1] = '\0';
65 if (snprintf(file_name, LINELEN, "%s%d-%.10s.ar5sav", SAVEDIR,
66 md_getuid(), whoami) >= LINELEN)
67 {
68 /* The name is too long */
69 use_savedir = FALSE;
70 }
71 }
72 #endif
60 /* Get default save file */ 73 /* Get default save file */
61 strcpy(file_name, home); 74 if (!use_savedir) {
62 strcat(file_name, "arogue58.sav"); 75 strcpy(file_name, home);
63 76 strcat(file_name, "arogue58.sav");
77 }
78
79 #ifdef SCOREFILE
80 strncpy(score_file, SCOREFILE, LINELEN);
81 score_file[LINELEN - 1] = '\0';
82 #else
64 /* Get default score file */ 83 /* Get default score file */
65 strcpy(score_file, roguedir); 84 strcpy(score_file, roguedir);
66 85
67 if (*score_file) 86 if (*score_file)
68 strcat(score_file,"/"); 87 strcat(score_file,"/");
69 88
70 strcat(score_file, "arogue58.scr"); 89 strcat(score_file, "arogue58.scr");
90 #endif
71 91
72 if ((env = getenv("ROGUEOPTS")) != NULL) 92 if ((env = getenv("ROGUEOPTS")) != NULL)
73 parse_opts(env); 93 parse_opts(env);
74 94
75 if (whoami[0] == '\0') 95 if (whoami[0] == '\0')
137 printf("Try again later. Meanwhile, why not enjoy a%s %s?\n", 157 printf("Try again later. Meanwhile, why not enjoy a%s %s?\n",
138 vowelstr(fruit), fruit); 158 vowelstr(fruit), fruit);
139 exit(1); 159 exit(1);
140 } 160 }
141 #endif 161 #endif
142 if (argc == 2) 162 if (use_savedir)
163 {
164 /* Try to restore from file_name first. */
165 if (!restore(file_name, envp))
166 exit(1);
167 /* If restore() returns true, there is no such saved game.
168 So start a new one. */
169 }
170 else if (argc == 2)
143 if (!restore(argv[1], envp)) /* Note: restore will never return */ 171 if (!restore(argv[1], envp)) /* Note: restore will never return */
144 exit(1); 172 exit(1);
145 lowtime = (int) time(&now); 173 lowtime = (int) time(&now);
146 dnum = (wizard && getenv("SEED") != NULL ? 174 dnum = (wizard && getenv("SEED") != NULL ?
147 atoi(getenv("SEED")) : 175 atoi(getenv("SEED")) :