Mercurial > hg > early-roguelike
comparison urogue/options.c @ 261:ac42afd962e4
UltraRogue: restrict changing name and save file.
When the -n option is in use, player name and save file location cannot
be changed. The score file is also restricted.
author | John "Elwin" Edwards |
---|---|
date | Sun, 12 Feb 2017 20:16:57 -0500 |
parents | c495a4f288c6 |
children | 2b452dbf0138 |
comparison
equal
deleted
inserted
replaced
260:b80e1bf4eaec | 261:ac42afd962e4 |
---|---|
21 #include "rogue.h" | 21 #include "rogue.h" |
22 | 22 |
23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) | 23 #define NUM_OPTS (sizeof optlist / sizeof (OPTION)) |
24 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) | 24 #define EQSTR(a, b, c) (strncmp(a, b, c) == 0) |
25 | 25 |
26 int get_restr(opt_arg *opt, WINDOW *win); | |
27 | |
26 /* description of an option and what to do with it */ | 28 /* description of an option and what to do with it */ |
27 static OPTION optlist[] = | 29 static OPTION optlist[] = |
28 { | 30 { |
29 {"jump","Show position only at end of run (jump): ", &jump,put_bool,get_bool}, | 31 {"jump","Show position only at end of run (jump): ", &jump,put_bool,get_bool}, |
30 {"inven","Style of inventories (inven): ", &inv_type, put_inv, get_inv}, | 32 {"inven","Style of inventories (inven): ", &inv_type, put_inv, get_inv}, |
31 {"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool}, | 33 {"askme","Ask me about unidentified things (askme): ",&askme,put_bool,get_bool}, |
32 {"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool}, | 34 {"doorstop","Stop running when adjacent (doorstop): ",&doorstop,put_bool,get_bool}, |
33 {"name", "Name (name): ", &whoami, put_str, get_str}, | 35 {"name", "Name (name): ", &whoami, put_str, get_restr}, |
34 {"fruit", "Fruit (fruit): ", &fruit, put_str, get_str}, | 36 {"fruit", "Fruit (fruit): ", &fruit, put_str, get_str}, |
35 {"file", "Save file (file): ", &file_name, put_str, get_str}, | 37 {"file", "Save file (file): ", &file_name, put_str, get_restr}, |
36 {"score", "Score file (score): ", &score_file, put_str, get_str}, | 38 {"score", "Score file (score): ", &score_file, put_str, get_restr}, |
37 {"class", "Character class (class): ",&char_type, put_abil, get_abil} | 39 {"class", "Character class (class): ",&char_type, put_abil, get_abil} |
38 }; | 40 }; |
39 | 41 |
40 /* | 42 /* |
41 option() | 43 option() |
309 len = sp - str; | 311 len = sp - str; |
310 | 312 |
311 /* Look it up and deal with it */ | 313 /* Look it up and deal with it */ |
312 | 314 |
313 for (op = optlist; op < &optlist[NUM_OPTS]; op++) | 315 for (op = optlist; op < &optlist[NUM_OPTS]; op++) |
316 { | |
314 if (EQSTR(str, op->o_name, len)) | 317 if (EQSTR(str, op->o_name, len)) |
315 { | 318 { |
316 if (op->o_putfunc == put_bool) | 319 if (op->o_putfunc == put_bool) |
317 *op->o_opt.iarg = TRUE; | 320 *op->o_opt.iarg = TRUE; |
318 else /* string option */ | 321 else /* string option */ |
331 | 334 |
332 for (sp = str + 1; *sp && *sp != ','; sp++) | 335 for (sp = str + 1; *sp && *sp != ','; sp++) |
333 continue; | 336 continue; |
334 | 337 |
335 strncpy(start, str, sp - str); | 338 strncpy(start, str, sp - str); |
339 | |
340 /* Some options can't be changed. */ | |
341 if (use_savedir && | |
342 (op->o_opt.str == whoami || | |
343 op->o_opt.str == file_name || | |
344 op->o_opt.str == score_file)) | |
345 break; | |
336 | 346 |
337 /* Put the value into the option field */ | 347 /* Put the value into the option field */ |
338 | 348 |
339 if (op->o_putfunc != put_abil && | 349 if (op->o_putfunc != put_abil && |
340 op->o_putfunc != put_inv) | 350 op->o_putfunc != put_inv) |
392 EQSTR(str + 2, op->o_name, len - 2)) | 402 EQSTR(str + 2, op->o_name, len - 2)) |
393 { | 403 { |
394 *op->o_opt.iarg = FALSE; | 404 *op->o_opt.iarg = FALSE; |
395 break; | 405 break; |
396 } | 406 } |
407 } | |
397 | 408 |
398 /* skip to start of next option name */ | 409 /* skip to start of next option name */ |
399 | 410 |
400 while (*sp && !isalpha(*sp)) | 411 while (*sp && !isalpha(*sp)) |
401 sp++; | 412 sp++; |
515 break; | 526 break; |
516 } | 527 } |
517 | 528 |
518 return(NORM); | 529 return(NORM); |
519 } | 530 } |
531 | |
532 /* | |
533 * get_restr() | |
534 * | |
535 * Gets strings that cannot be changed when use_savedir is set. | |
536 * get_abil() can't be repurposed to do this without ugliness. | |
537 * | |
538 */ | |
539 int | |
540 get_restr(opt_arg *opt, WINDOW *win) | |
541 { | |
542 int oy, ox, ny, nx; | |
543 int keep_up; | |
544 | |
545 keep_up = TRUE; | |
546 getyx(win, oy, ox); | |
547 put_str(opt, win); | |
548 | |
549 if (!use_savedir) | |
550 return get_str(opt, win); | |
551 | |
552 getyx(win, ny, nx); | |
553 while(keep_up) | |
554 { | |
555 wmove(win, oy, ox); | |
556 wrefresh(win); | |
557 | |
558 switch(readcharw(win)) | |
559 { | |
560 case '\n': | |
561 case '\r': | |
562 keep_up = FALSE; | |
563 break; | |
564 | |
565 case '\033': | |
566 case '\007': | |
567 return(QUIT); | |
568 | |
569 case '-': | |
570 return(MINUS); | |
571 | |
572 default: | |
573 mvwaddstr(win, ny, nx + 5, "(no change allowed)"); | |
574 } | |
575 } | |
576 | |
577 wmove(win, ny, nx + 5); | |
578 wclrtoeol(win); | |
579 wmove(win, ny, nx); | |
580 waddch(win, '\n'); | |
581 | |
582 return(NORM); | |
583 } |