Mercurial > hg > early-roguelike
comparison rogue3/options.c @ 2:e676d52b5d09
Prevent changing name or save file when using system savedir
| author | edwarj4 |
|---|---|
| date | Wed, 14 Oct 2009 11:21:33 +0000 |
| parents | 527e2150eaf0 |
| children | e52a8a7ad4c5 |
comparison
equal
deleted
inserted
replaced
| 1:b4856d4d4c4e | 2:e676d52b5d09 |
|---|---|
| 31 void (*o_putfunc)(); /* function to print value */ | 31 void (*o_putfunc)(); /* function to print value */ |
| 32 int (*o_getfunc)(); /* function to get value interactively */ | 32 int (*o_getfunc)(); /* function to get value interactively */ |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 typedef struct optstruct OPTION; | 35 typedef struct optstruct OPTION; |
| 36 | |
| 37 int allowchange(OPTION *opt); /* doesn't need to be externally visible */ | |
| 36 | 38 |
| 37 OPTION optlist[] = { | 39 OPTION optlist[] = { |
| 38 {"terse", "Terse output: ", | 40 {"terse", "Terse output: ", |
| 39 (int *) &terse, put_bool, get_bool }, | 41 (int *) &terse, put_bool, get_bool }, |
| 40 {"flush", "Flush typeahead during battle: ", | 42 {"flush", "Flush typeahead during battle: ", |
| 67 /* | 69 /* |
| 68 * Display current values of options | 70 * Display current values of options |
| 69 */ | 71 */ |
| 70 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) | 72 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
| 71 { | 73 { |
| 72 waddstr(hw, op->o_prompt); | 74 if (allowchange(op)) |
| 73 (*op->o_putfunc)(op->o_opt); | 75 { |
| 74 waddch(hw, '\n'); | 76 waddstr(hw, op->o_prompt); |
| 77 (*op->o_putfunc)(op->o_opt); | |
| 78 waddch(hw, '\n'); | |
| 79 } | |
| 75 } | 80 } |
| 76 /* | 81 /* |
| 77 * Set values | 82 * Set values |
| 78 */ | 83 */ |
| 79 wmove(hw, 0, 0); | 84 wmove(hw, 0, 0); |
| 80 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) | 85 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
| 81 { | 86 { |
| 87 if (!allowchange(op)) | |
| 88 continue; | |
| 82 waddstr(hw, op->o_prompt); | 89 waddstr(hw, op->o_prompt); |
| 83 if ((retval = (*op->o_getfunc)(op->o_opt, hw))) | 90 if ((retval = (*op->o_getfunc)(op->o_opt, hw))) |
| 91 { | |
| 84 if (retval == QUIT) | 92 if (retval == QUIT) |
| 85 break; | 93 break; |
| 86 else if (op > optlist) { /* MINUS */ | 94 #if 0 |
| 95 /* Support for MINUS has been removed because making it work with | |
| 96 * hidden unchangable options without underflowing optlist will | |
| 97 * require a complete rewrite. And it should also be rewritten | |
| 98 * so option() doesn't count on get_str() to put the cursor in the | |
| 99 * right place, because that makes it a pain to understand. | |
| 100 */ | |
| 101 else if (op > optlist) { /* retval == MINUS */ | |
| 87 wmove(hw, (int)(op - optlist) - 1, 0); | 102 wmove(hw, (int)(op - optlist) - 1, 0); |
| 88 op -= 2; | 103 op -= 2; |
| 89 } | 104 } |
| 90 else /* trying to back up beyond the top */ | 105 else /* trying to back up beyond the top */ |
| 91 { | 106 { |
| 92 beep(); | 107 beep(); |
| 93 wmove(hw, 0, 0); | 108 wmove(hw, 0, 0); |
| 94 op--; | 109 op--; |
| 95 } | 110 } |
| 111 #else | |
| 112 break; | |
| 113 #endif | |
| 114 } | |
| 96 } | 115 } |
| 97 /* | 116 /* |
| 98 * Switch back to original screen | 117 * Switch back to original screen |
| 99 */ | 118 */ |
| 100 mvwaddstr(hw, LINES-1, 0, "--Press space to continue--"); | 119 mvwaddstr(hw, LINES-1, 0, "--Press space to continue--"); |
| 283 len = (int)(sp - str); | 302 len = (int)(sp - str); |
| 284 /* | 303 /* |
| 285 * Look it up and deal with it | 304 * Look it up and deal with it |
| 286 */ | 305 */ |
| 287 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) | 306 for (op = optlist; op <= &optlist[NUM_OPTS-1]; op++) |
| 307 { | |
| 308 /* If using system savefiles, changing your name or the | |
| 309 save file is not allowed. */ | |
| 310 if (!allowchange(op)) | |
| 311 continue; | |
| 288 if (EQSTR(str, op->o_name, len)) | 312 if (EQSTR(str, op->o_name, len)) |
| 289 { | 313 { |
| 290 if (op->o_putfunc == put_bool) /* if option is a boolean */ | 314 if (op->o_putfunc == put_bool) /* if option is a boolean */ |
| 291 *(int *)op->o_opt = TRUE; | 315 *(int *)op->o_opt = TRUE; |
| 292 else /* string option */ | 316 else /* string option */ |
| 322 && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) | 346 && EQSTR(str, "no", 2) && EQSTR(str + 2, op->o_name, len - 2)) |
| 323 { | 347 { |
| 324 *(int *)op->o_opt = FALSE; | 348 *(int *)op->o_opt = FALSE; |
| 325 break; | 349 break; |
| 326 } | 350 } |
| 351 } | |
| 327 | 352 |
| 328 /* | 353 /* |
| 329 * skip to start of next option name | 354 * skip to start of next option name |
| 330 */ | 355 */ |
| 331 while (*sp && !isalpha(*sp)) | 356 while (*sp && !isalpha(*sp)) |
| 349 s1 += strlen(sp); | 374 s1 += strlen(sp); |
| 350 s2++; | 375 s2++; |
| 351 } | 376 } |
| 352 *s1 = '\0'; | 377 *s1 = '\0'; |
| 353 } | 378 } |
| 379 | |
| 380 /* Tells whether the user is allowed to change the option. */ | |
| 381 int allowchange(OPTION *opt) | |
| 382 { | |
| 383 if (!use_savedir) | |
| 384 return 1; | |
| 385 if (!strcmp(opt->o_name, "name")) | |
| 386 return 0; | |
| 387 if (!strcmp(opt->o_name, "file")) | |
| 388 return 0; | |
| 389 return 1; | |
| 390 } |
