comparison rogue4/main.c @ 13:63b9fd7d70ce

rogue4: add -n option and system savedir
author edwarj4
date Sat, 31 Oct 2009 01:51:52 +0000
parents 9535a08ddc39
children ea7372f5d314
comparison
equal deleted inserted replaced
12:9535a08ddc39 13:63b9fd7d70ce
69 argv++; 69 argv++;
70 argc--; 70 argc--;
71 } 71 }
72 #endif 72 #endif
73 73
74 #ifdef SAVEDIR
75 if (argc >= 3 && !strcmp(argv[1], "-n"))
76 {
77 strncpy(whoami, argv[2], MAXSTR - 1);
78 whoami[MAXSTR - 1] = '\0'; /* insurance */
79 use_savedir = TRUE;
80 /* look for savefile at SAVEDIR/UIDplayername.r4sav */
81 if (snprintf(file_name, MAXSTR, "%s%d%.10s.r4sav", SAVEDIR, md_getuid(),
82 whoami) >= MAXSTR)
83 {
84 /* Name is too long- this shouldn't happen */
85 strcpy(file_name, "rogue4.save");
86 use_savedir = FALSE;
87 }
88 }
89 #endif
90
74 /* 91 /*
75 * get home and options from environment 92 * get home and options from environment
76 */ 93 */
77 strncpy(home, md_gethomedir(), PATH_MAX); 94 strncpy(home, md_gethomedir(), PATH_MAX);
78 strcpy(file_name, home); 95 if (!use_savedir)
79 strcat(file_name, "rogue52.sav"); 96 {
97 strcpy(file_name, home);
98 strcat(file_name, "/rogue4.save");
99 }
80 100
81 if ((env = getenv("ROGUEOPTS")) != NULL) 101 if ((env = getenv("ROGUEOPTS")) != NULL)
82 parse_opts(env); 102 parse_opts(env);
83 if (env == NULL || whoami[0] == '\0') 103 if (!use_savedir && (env == NULL || whoami[0] == '\0'))
84 strucpy(whoami, md_getusername(md_getuid()), strlen(md_getusername(md_getuid()))); 104 strucpy(whoami, md_getusername(md_getuid()), strlen(md_getusername(md_getuid())));
85 if (env == NULL || fruit[0] == '\0') 105 if (env == NULL || fruit[0] == '\0')
86 strcpy(fruit, "slime-mold"); 106 strcpy(fruit, "slime-mold");
87 107
88 /* 108 /*
94 noscore = TRUE; 114 noscore = TRUE;
95 score(0, -1); 115 score(0, -1);
96 exit(0); 116 exit(0);
97 } 117 }
98 init_check(); /* check for legal startup */ 118 init_check(); /* check for legal startup */
99 if (argc == 2) 119
120 if (use_savedir)
121 {
122 /* Try to restore from file_name which we just set up. */
123 if (!restore(file_name, envp))
124 exit(1);
125 /* If restore() returns true, the system savefile doesn't exist.
126 So we'll start a new game. */
127 }
128 else if (argc == 2)
129 {
100 if (!restore(argv[1], envp)) /* Note: restore will never return */ 130 if (!restore(argv[1], envp)) /* Note: restore will never return */
101 { 131 {
102 endwin(); 132 endwin();
103 exit(1); 133 exit(1);
104 } 134 }
135 }
136
137 if (!use_savedir)
138 md_normaluser();
139
105 lowtime = (int) time(NULL); 140 lowtime = (int) time(NULL);
106 141
107 #ifdef WIZARD 142 #ifdef WIZARD
108 noscore = wizard; 143 noscore = wizard;
109 #endif 144 #endif