Mercurial > hg > early-roguelike
comparison arogue7/options.c @ 129:9c4e50b5825c
arogue7: prevent changing protected options.
When using the savedir, whoami, file_name, and score_file cannot be
changed.
author | John "Elwin" Edwards |
---|---|
date | Mon, 11 May 2015 19:41:46 -0400 |
parents | b786053d2f37 |
children | aac28331e71d |
comparison
equal
deleted
inserted
replaced
128:c697782a9b37 | 129:9c4e50b5825c |
---|---|
46 get_str(), | 46 get_str(), |
47 put_abil(), | 47 put_abil(), |
48 get_abil(), | 48 get_abil(), |
49 get_quest(), | 49 get_quest(), |
50 put_quest(); | 50 put_quest(); |
51 | |
52 int get_str_prot(char *opt, WINDOW *win); | |
53 bool allowchange(OPTION *op); | |
51 | 54 |
52 OPTION optlist[] = { | 55 OPTION optlist[] = { |
53 {"terse", "Terse output: ", | 56 {"terse", "Terse output: ", |
54 (int *) &terse, put_bool, get_bool }, | 57 (int *) &terse, put_bool, get_bool }, |
55 {"flush", "Flush typeahead during battle: ", | 58 {"flush", "Flush typeahead during battle: ", |
63 {"pickup", "Pick things up automatically: ", | 66 {"pickup", "Pick things up automatically: ", |
64 (int *) &auto_pickup, put_bool, get_bool }, | 67 (int *) &auto_pickup, put_bool, get_bool }, |
65 {"overlay", "Overlay menu: ", | 68 {"overlay", "Overlay menu: ", |
66 (int *) &menu_overlay, put_bool, get_bool }, | 69 (int *) &menu_overlay, put_bool, get_bool }, |
67 {"name", "Name: ", | 70 {"name", "Name: ", |
68 (int *) whoami, put_str, get_str }, | 71 (int *) whoami, put_str, get_str_prot }, |
69 {"file", "Save file: ", | 72 {"file", "Save file: ", |
70 (int *) file_name, put_str, get_str }, | 73 (int *) file_name, put_str, get_str_prot }, |
71 {"score", "Score file: ", | 74 {"score", "Score file: ", |
72 (int *) score_file, put_str, get_str }, | 75 (int *) score_file, put_str, get_str_prot }, |
73 {"class", "Character class: ", | 76 {"class", "Character class: ", |
74 (int *)&char_type, put_abil, get_abil }, | 77 (int *)&char_type, put_abil, get_abil }, |
75 {"quest", "Quest item: ", | 78 {"quest", "Quest item: ", |
76 (int *) &quest_item, put_quest, get_quest } | 79 (int *) &quest_item, put_quest, get_quest } |
77 }; | 80 }; |
379 continue; | 382 continue; |
380 strucpy(start, str, sp - str); | 383 strucpy(start, str, sp - str); |
381 | 384 |
382 /* Put the value into the option field */ | 385 /* Put the value into the option field */ |
383 if (op->o_putfunc != put_abil) | 386 if (op->o_putfunc != put_abil) |
384 strcpy((char *)op->o_opt, (char *)value); | 387 { |
388 if (allowchange(op)) | |
389 strcpy((char *)op->o_opt, (char *)value); | |
390 } | |
385 | 391 |
386 else if (*op->o_opt == -1) { /* Only init ability once */ | 392 else if (*op->o_opt == -1) { /* Only init ability once */ |
387 register int len = strlen(value); | 393 register int len = strlen(value); |
388 register int i; | 394 register int i; |
389 | 395 |
461 char *str; | 467 char *str; |
462 WINDOW *win; | 468 WINDOW *win; |
463 { | 469 { |
464 waddstr(win, str); | 470 waddstr(win, str); |
465 } | 471 } |
472 | |
473 /* Like get_str, but disallows changes when use_savedir is set. */ | |
474 int | |
475 get_str_prot(char *opt, WINDOW *win) | |
476 { | |
477 int oy, ox; | |
478 | |
479 if (use_savedir) { | |
480 getyx(win, oy, ox); | |
481 waddstr(win, opt); | |
482 return get_ro(win, oy, ox); | |
483 } | |
484 else { | |
485 return get_str(opt, win); | |
486 } | |
487 } | |
488 | |
489 bool | |
490 allowchange(OPTION *op) | |
491 { | |
492 if (!use_savedir) | |
493 return TRUE; | |
494 if (!strcmp(op->o_name, "name")) | |
495 return FALSE; | |
496 if (!strcmp(op->o_name, "file")) | |
497 return FALSE; | |
498 if (!strcmp(op->o_name, "score")) | |
499 return FALSE; | |
500 return TRUE; | |
501 } |