Пример #1
0
static int query_gender_name(int what, char *buf)
{
  if (what >= ROLE_GENDERS)
    return -1;

  strcpy(buf, genders[what].adj);
  
  return ok_gend(flags.initrole, flags.initrace, what,
      flags.initalign) ? 1 : 0;
}
Пример #2
0
/* Do a window-port specific player type selection. If player_selection()
   offers a Quit option, it is its responsibility to clean up and terminate
   the process. You need to fill in pl_character[0].
*/
void
dummy_player_selection()
{
#if 0
    int n, i, sel;
    const char** choices;
    int* pickmap;

    /* prevent an unnecessary prompt */
    rigid_role_checks();

    if (!flags.randomall && flags.initrole < 0) {

	/* select a role */
	for (n = 0; roles[n].name.m; n++) continue;
	choices = (const char **)alloc(sizeof(char *) * (n+1));
	pickmap = (int*)alloc(sizeof(int) * (n+1));
	for (;;) {
	    for (n = 0, i = 0; roles[i].name.m; i++) {
		if (ok_role(i, flags.initrace,
			    flags.initgend, flags.initalign)) {
		    if (flags.initgend >= 0 && flags.female && roles[i].name.f)
			choices[n] = roles[i].name.f;
		    else
			choices[n] = roles[i].name.m;
		    pickmap[n++] = i;
		}
	    }
	    if (n > 0) break;
	    else if (flags.initalign >= 0) flags.initalign = -1;    /* reset */
	    else if (flags.initgend >= 0) flags.initgend = -1;
	    else if (flags.initrace >= 0) flags.initrace = -1;
	    else panic("no available ROLE+race+gender+alignment combinations");
	}
	choices[n] = (const char *) 0;
	if (n > 1)
	    sel = ghack_player_sel_dialog(choices,
		_("Player selection"), _("Choose one of the following roles:"));
	else sel = 0;
	if (sel >= 0) sel = pickmap[sel];
	else if (sel == ROLE_NONE) {		/* Quit */
	    clearlocks();
	    dummy_exit_nhwindows(0);
	}
	free(choices);
	free(pickmap);
    } else if (flags.initrole < 0) sel = ROLE_RANDOM;
    else sel = flags.initrole;
  
    if (sel == ROLE_RANDOM) {	/* Random role */
	sel = pick_role(flags.initrace, flags.initgend,
			  flags.initalign, PICK_RANDOM);
	if (sel < 0) sel = randrole();
    }

    flags.initrole = sel;

    /* Select a race, if necessary */
    /* force compatibility with role, try for compatibility with
     * pre-selected gender/alignment */
    if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
	if (flags.initrace == ROLE_RANDOM || flags.randomall) {
	    flags.initrace = pick_race(flags.initrole, flags.initgend,
				       flags.initalign, PICK_RANDOM);
	    if (flags.initrace < 0) flags.initrace = randrace(flags.initrole);
	} else {
	    /* Count the number of valid races */
	    n = 0;	/* number valid */
	    for (i = 0; races[i].noun; i++) {
		if (ok_race(flags.initrole, i, flags.initgend, flags.initalign))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; races[i].noun; i++) {
		    if (validrace(flags.initrole, i)) n++;
		}
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; races[i].noun; i++) {
		if (ok_race(flags.initrole, i, flags.initgend,
			    flags.initalign)) {
		    choices[n] = races[i].noun;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = ghack_player_sel_dialog(choices, _("Race selection"),
			_("Choose one of the following races:"));
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		dummy_exit_nhwindows(0);
	    }
	    flags.initrace = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initrace == ROLE_RANDOM) {	/* Random role */
	    sel = pick_race(flags.initrole, flags.initgend,
			    flags.initalign, PICK_RANDOM);
	    if (sel < 0) sel = randrace(flags.initrole);
	    flags.initrace = sel;
	}
    }

    /* Select a gender, if necessary */
    /* force compatibility with role/race, try for compatibility with
     * pre-selected alignment */
    if (flags.initgend < 0 ||
	!validgend(flags.initrole, flags.initrace, flags.initgend)) {
	if (flags.initgend == ROLE_RANDOM || flags.randomall) {
	    flags.initgend = pick_gend(flags.initrole, flags.initrace,
				       flags.initalign, PICK_RANDOM);
	    if (flags.initgend < 0)
		flags.initgend = randgend(flags.initrole, flags.initrace);
	} else {
	    /* Count the number of valid genders */
	    n = 0;	/* number valid */
	    for (i = 0; i < ROLE_GENDERS; i++) {
		if (ok_gend(flags.initrole, flags.initrace, i, flags.initalign))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; i < ROLE_GENDERS; i++) {
		    if (validgend(flags.initrole, flags.initrace, i)) n++;
		}
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; i < ROLE_GENDERS; i++) {
		if (ok_gend(flags.initrole, flags.initrace, i,
				flags.initalign)) {
		    choices[n] = genders[i].adj;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = ghack_player_sel_dialog(choices, _("Gender selection"),
			_("Choose one of the following genders:"));
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		dummy_exit_nhwindows(0);
	    }
	    flags.initgend = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initgend == ROLE_RANDOM) {	/* Random gender */
	    sel = pick_gend(flags.initrole, flags.initrace,
			    flags.initalign, PICK_RANDOM);
	    if (sel < 0) sel = randgend(flags.initrole, flags.initrace);
	    flags.initgend = sel;
	}
    }

    /* Select an alignment, if necessary */
    /* force compatibility with role/race/gender */
    if (flags.initalign < 0 ||
	!validalign(flags.initrole, flags.initrace, flags.initalign)) {
	if (flags.initalign == ROLE_RANDOM || flags.randomall) {
	    flags.initalign = pick_align(flags.initrole, flags.initrace,
					 flags.initgend, PICK_RANDOM);
	    if (flags.initalign < 0)
		flags.initalign = randalign(flags.initrole, flags.initrace);
	} else {
	    /* Count the number of valid alignments */
	    n = 0;	/* number valid */
	    for (i = 0; i < ROLE_ALIGNS; i++) {
		if (ok_align(flags.initrole, flags.initrace, flags.initgend, i))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; i < ROLE_ALIGNS; i++)
		    if (validalign(flags.initrole, flags.initrace, i)) n++;
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; i < ROLE_ALIGNS; i++) {
		if (ok_align(flags.initrole,
			     flags.initrace, flags.initgend, i)) {
		    choices[n] = aligns[i].adj;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = ghack_player_sel_dialog(choices, _("Alignment selection"),
			_("Choose one of the following alignments:"));
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		dummy_exit_nhwindows(0);
	    }
	    flags.initalign = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initalign == ROLE_RANDOM) {
	    sel = pick_align(flags.initrole, flags.initrace,
			     flags.initgend, PICK_RANDOM);
	    if (sel < 0) sel = randalign(flags.initrole, flags.initrace);
	    flags.initalign = sel;
	}
    }
#endif
}
Пример #3
0
void curses_choose_character()
{
    int n, i, sel, count_off, pick4u;
    int count = 0;
    int cur_character = 0;
    const char** choices;
    int* pickmap;
    char *prompt;
    char pbuf[QBUFSZ];
    char choice[QBUFSZ];
    char tmpchoice[QBUFSZ];
#ifdef TUTORIAL_MODE
	winid win;
	anything any;
	menu_item *selected = 0;
#endif

	prompt = build_plselection_prompt(pbuf, QBUFSZ, flags.initrole,
	 flags.initrace, flags.initgend, flags.initalign);

    /* This part is irritating: we have to strip the choices off of
    the string and put them in a separate string in order to use
    curses_character_input_dialog for this prompt. */

    while (cur_character != '[')
    {
        cur_character = prompt[count];
        count++;
    }
    
    count_off = count;
    
    while (cur_character != ']')
    {
        tmpchoice[count - count_off] = prompt[count];
        count++;
        cur_character = prompt[count];
    }
    
    tmpchoice[count - count_off] = '\0';
    lcase(tmpchoice);
    
    while (!isspace(prompt[count_off]))
    {
        count_off--;
    }
    
    prompt[count_off] = '\0';
    sprintf(choice, "%s%c", tmpchoice, '\033');
    if(strchr(tmpchoice, 't'))  /* Tutorial mode */
    {
        mvaddstr(0, 1, "New? Press t to enter a tutorial.");
    }
    
    /* Add capital letters as choices that aren't displayed */
    
    for (count = 0; tmpchoice[count]; count++)
    {
        tmpchoice[count] = toupper(tmpchoice[count]);
    }
    
    sprintf(choice, "%s%s", choice, tmpchoice);

    /* prevent an unnecessary prompt */
    rigid_role_checks(); 
    
	if (!flags.randomall &&
	    (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE ||
	     flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE))
	{
        pick4u = tolower(curses_character_input_dialog(prompt, choice,
         'y'));
    }
    else
    {
        pick4u = 'y';
    }
    
    if (pick4u == 'q')  /* Quit or cancelled */
    {
	    clearlocks();
	    curses_bail(0);
    }
    
    if (pick4u == 'y')
    {
        flags.randomall = TRUE;
    }
#ifdef TUTORIAL_MODE
    else if (pick4u == 't') /* Tutorial mode in UnNetHack */
    {
	    clear();
        mvaddstr(0, 1, "Choose a character");
        refresh();
	    win = curses_get_wid(NHW_MENU);
        curses_create_nhmenu(win);
	    any.a_int = 1;
	    curses_add_menu(win, NO_GLYPH, &any, 'v', 0, ATR_NONE,
		     "lawful female dwarf Valkyrie (uses melee and thrown weapons)",
		     MENU_UNSELECTED);
	    any.a_int = 2;
	    curses_add_menu(win, NO_GLYPH, &any, 'w', 0, ATR_NONE,
		     "chaotic male elf Wizard (relies mostly on spells)",
		     MENU_UNSELECTED);
	    any.a_int = 3;
	    curses_add_menu(win, NO_GLYPH, &any, 'R', 0, ATR_NONE,
		     "neutral female human Ranger (good with ranged combat)",
		     MENU_UNSELECTED);
	    any.a_int = 4;
	    curses_add_menu(win, NO_GLYPH, &any, 'q', 0, ATR_NONE,
		     "quit", MENU_UNSELECTED);
	    curses_end_menu(win, "What character do you want to try?");
	    n = curses_select_menu(win, PICK_ONE, &selected);
	    destroy_nhwindow(win);
	    if (n != 1 || selected[0].item.a_int == 4)
	    {
    	    clearlocks();
    	    curses_bail(0);
	    }
	    switch (selected[0].item.a_int) {
	    case 1:
		flags.initrole = str2role("Valkyrie");
		flags.initrace = str2race("dwarf");
		flags.initgend = str2gend("female");
		flags.initalign = str2align("lawful");
		break;
	    case 2:
		flags.initrole = str2role("Wizard");
		flags.initrace = str2race("elf");
		flags.initgend = str2gend("male");
		flags.initalign = str2align("chaotic");
		break;
	    case 3:
		flags.initrole = str2role("Ranger");
		flags.initrace = str2race("human");
		flags.initgend = str2gend("female");
		flags.initalign = str2align("neutral");
		break;
	    default: panic("Impossible menu selection"); break;
	    }
	    free((genericptr_t) selected);
	    selected = 0;
	    flags.tutorial = 1;
	}
#endif
    
    clear();
    refresh();

    if (!flags.randomall && flags.initrole < 0) {
	/* select a role */
	for (n = 0; roles[n].name.m; n++) continue;
	choices = (const char **)alloc(sizeof(char *) * (n+1));
	pickmap = (int*)alloc(sizeof(int) * (n+1));
	for (;;) {
	    for (n = 0, i = 0; roles[i].name.m; i++) {
		if (ok_role(i, flags.initrace,
			    flags.initgend, flags.initalign)) {
		    if (flags.initgend >= 0 && flags.female && roles[i].name.f)
			choices[n] = roles[i].name.f;
		    else
			choices[n] = roles[i].name.m;
		    pickmap[n++] = i;
		}
	    }
	    if (n > 0) break;
	    else if (flags.initalign >= 0) flags.initalign = -1;    /* reset */
	    else if (flags.initgend >= 0) flags.initgend = -1;
	    else if (flags.initrace >= 0) flags.initrace = -1;
	    else panic("no available ROLE+race+gender+alignment combinations");
	}
	choices[n] = (const char *) 0;
	if (n > 1)
        sel = curses_character_dialog(choices, "Choose one of the following roles:");
	else sel = 0;
	if (sel >= 0) sel = pickmap[sel];
	else if (sel == ROLE_NONE) {		/* Quit */
	    clearlocks();
	    curses_bail(0);
	}
	free(choices);
	free(pickmap);
    } else if (flags.initrole < 0) sel = ROLE_RANDOM;
    else sel = flags.initrole;
  
    if (sel == ROLE_RANDOM) {	/* Random role */
	sel = pick_role(flags.initrace, flags.initgend,
			  flags.initalign, PICK_RANDOM);
	if (sel < 0) sel = randrole();
    }

    flags.initrole = sel;

    /* Select a race, if necessary */
    /* force compatibility with role, try for compatibility with
     * pre-selected gender/alignment */
    if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
	if (flags.initrace == ROLE_RANDOM || flags.randomall) {
	    flags.initrace = pick_race(flags.initrole, flags.initgend,
				       flags.initalign, PICK_RANDOM);
	    if (flags.initrace < 0) flags.initrace = randrace(flags.initrole);
	} else {
	    /* Count the number of valid races */
	    n = 0;	/* number valid */
	    for (i = 0; races[i].noun; i++) {
		if (ok_race(flags.initrole, i, flags.initgend, flags.initalign))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; races[i].noun; i++) {
		    if (validrace(flags.initrole, i)) n++;
		}
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; races[i].noun; i++) {
		if (ok_race(flags.initrole, i, flags.initgend,
			    flags.initalign)) {
		    choices[n] = races[i].noun;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = curses_character_dialog(choices, "Choose one of the following races:");
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		curses_bail(0);
	    }
	    flags.initrace = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initrace == ROLE_RANDOM) {	/* Random role */
	    sel = pick_race(flags.initrole, flags.initgend,
			    flags.initalign, PICK_RANDOM);
	    if (sel < 0) sel = randrace(flags.initrole);
	    flags.initrace = sel;
	}
    }

    /* Select a gender, if necessary */
    /* force compatibility with role/race, try for compatibility with
     * pre-selected alignment */
    if (flags.initgend < 0 ||
	!validgend(flags.initrole, flags.initrace, flags.initgend)) {
	if (flags.initgend == ROLE_RANDOM || flags.randomall) {
	    flags.initgend = pick_gend(flags.initrole, flags.initrace,
				       flags.initalign, PICK_RANDOM);
	    if (flags.initgend < 0)
		flags.initgend = randgend(flags.initrole, flags.initrace);
	} else {
	    /* Count the number of valid genders */
	    n = 0;	/* number valid */
	    for (i = 0; i < ROLE_GENDERS; i++) {
		if (ok_gend(flags.initrole, flags.initrace, i, flags.initalign))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; i < ROLE_GENDERS; i++) {
		    if (validgend(flags.initrole, flags.initrace, i)) n++;
		}
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; i < ROLE_GENDERS; i++) {
		if (ok_gend(flags.initrole, flags.initrace, i,
				flags.initalign)) {
		    choices[n] = genders[i].adj;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = curses_character_dialog(choices, "Choose one of the following genders:");
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		curses_bail(0);
	    }
	    flags.initgend = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initgend == ROLE_RANDOM) {	/* Random gender */
	    sel = pick_gend(flags.initrole, flags.initrace,
			    flags.initalign, PICK_RANDOM);
	    if (sel < 0) sel = randgend(flags.initrole, flags.initrace);
	    flags.initgend = sel;
	}
    }

    /* Select an alignment, if necessary */
    /* force compatibility with role/race/gender */
    if (flags.initalign < 0 ||
	!validalign(flags.initrole, flags.initrace, flags.initalign)) {
	if (flags.initalign == ROLE_RANDOM || flags.randomall) {
	    flags.initalign = pick_align(flags.initrole, flags.initrace,
					 flags.initgend, PICK_RANDOM);
	    if (flags.initalign < 0)
		flags.initalign = randalign(flags.initrole, flags.initrace);
	} else {
	    /* Count the number of valid alignments */
	    n = 0;	/* number valid */
	    for (i = 0; i < ROLE_ALIGNS; i++) {
		if (ok_align(flags.initrole, flags.initrace, flags.initgend, i))
		    n++;
	    }
	    if (n == 0) {
		for (i = 0; i < ROLE_ALIGNS; i++)
		    if (validalign(flags.initrole, flags.initrace, i)) n++;
	    }

	    choices = (const char **)alloc(sizeof(char *) * (n+1));
	    pickmap = (int*)alloc(sizeof(int) * (n + 1));
	    for (n = 0, i = 0; i < ROLE_ALIGNS; i++) {
		if (ok_align(flags.initrole,
			     flags.initrace, flags.initgend, i)) {
		    choices[n] = aligns[i].adj;
		    pickmap[n++] = i;
		}
	    }
	    choices[n] = (const char *) 0;
	    /* Permit the user to pick, if there is more than one */
	    if (n > 1)
		sel = curses_character_dialog(choices, "Choose one of the following alignments:");
	    else sel = 0;
	    if (sel >= 0) sel = pickmap[sel];
	    else if (sel == ROLE_NONE) { /* Quit */
		clearlocks();
		curses_bail(0);
	    }
	    flags.initalign = sel;
	    free(choices);
	    free(pickmap);
	}
	if (flags.initalign == ROLE_RANDOM) {
	    sel = pick_align(flags.initrole, flags.initrace,
			     flags.initgend, PICK_RANDOM);
	    if (sel < 0) sel = randalign(flags.initrole, flags.initrace);
	    flags.initalign = sel;
	}
    }
}
Пример #4
0
void nds_player_selection()
{
  int i, k, n;
  char pick4u = 'n', thisch, lastch = 0;
  char pbuf[PROMPT_LAYER_WIDTH], plbuf[PROMPT_LAYER_WIDTH];
  winid win;
  anything any;
  menu_item *selected = 0;

  /* prevent an unnecessary prompt */
  rigid_role_checks();

  /* Should we randomly pick for the player? */
  if (!flags.randomall &&
      (flags.initrole == ROLE_NONE || flags.initrace == ROLE_NONE ||
       flags.initgend == ROLE_NONE || flags.initalign == ROLE_NONE)) {

    char *prompt = build_plselection_prompt(pbuf, PROMPT_LAYER_WIDTH, flags.initrole,
                                            flags.initrace, flags.initgend, flags.initalign);
    int res = _nds_display_yes_no_prompt(prompt);

    if (res < 0) {
give_up:
      return;
    }

    if (res) {
      pick4u = 'y';
    }
  }

  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                          flags.initrole, flags.initrace, flags.initgend, flags.initalign);

  /* Select a role, if necessary */
  /* we'll try to be compatible with pre-selected race/gender/alignment,
   * but may not succeed */

  if (flags.initrole < 0) {
    char rolenamebuf[PROMPT_LAYER_WIDTH];

    /* Process the choice */
    if (pick4u == 'y' || flags.initrole == ROLE_RANDOM || flags.randomall) {
      /* Pick a random role */
      flags.initrole = pick_role(flags.initrace, flags.initgend,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initrole < 0) {
        iprintf("Incompatible role!");

        flags.initrole = randrole();
      }
    } else {
      /* Prompt for a role */

      win = create_nhwindow(NHW_MENU);
      start_menu(win);

      any.a_void = 0;         /* zero out all bits */

      for (i = 0; roles[i].name.m; i++) {
        if (ok_role(i, flags.initrace, flags.initgend,
                    flags.initalign)) {

          any.a_int = i+1;	/* must be non-zero */
          thisch = lowc(roles[i].name.m[0]);

          if (thisch == lastch) thisch = highc(thisch);

          if (flags.initgend != ROLE_NONE && flags.initgend != ROLE_RANDOM) {
            if (flags.initgend == 1  && roles[i].name.f)
              Strcpy(rolenamebuf, roles[i].name.f);
            else
              Strcpy(rolenamebuf, roles[i].name.m);
          } else {
            if (roles[i].name.f) {
              Strcpy(rolenamebuf, roles[i].name.m);
              Strcat(rolenamebuf, "/");
              Strcat(rolenamebuf, roles[i].name.f);
            } else 
              Strcpy(rolenamebuf, roles[i].name.m);
          }	

          add_menu(win, NO_GLYPH, &any, thisch,
                   0, ATR_NONE, an(rolenamebuf), MENU_UNSELECTED);

          lastch = thisch;
        }
      }

      any.a_int = pick_role(flags.initrace, flags.initgend,
                            flags.initalign, PICK_RANDOM)+1;

      if (any.a_int == 0)	/* must be non-zero */
        any.a_int = randrole()+1;

      add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
               "Random", MENU_UNSELECTED);

      any.a_int = i+1;	/* must be non-zero */

      add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
               "Quit", MENU_UNSELECTED);

      Sprintf(pbuf, "Pick a role for your %s", plbuf);

      end_menu(win, pbuf);

      n = select_menu(win, PICK_ONE, &selected);

      destroy_nhwindow(win);

      /* Process the choice */
      if (n != 1 || selected[0].item.a_int == any.a_int)
        goto give_up;		/* Selected quit */

      flags.initrole = selected[0].item.a_int - 1;
      free((genericptr_t) selected),	selected = 0;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select a race, if necessary */
  /* force compatibility with role, try for compatibility with
   * pre-selected gender/alignment */

  if (flags.initrace < 0 || !validrace(flags.initrole, flags.initrace)) {
    /* pre-selected race not valid */

    if (pick4u == 'y' || flags.initrace == ROLE_RANDOM || flags.randomall) {
      flags.initrace = pick_race(flags.initrole, flags.initgend,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initrace < 0) {
        iprintf("Incompatible race!");
        flags.initrace = randrace(flags.initrole);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid races */
      n = 0;	/* number valid */
      k = 0;	/* valid race */

      for (i = 0; races[i].noun; i++) {
        if (ok_race(flags.initrole, i, flags.initgend,
                    flags.initalign)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; races[i].noun; i++) {
          if (validrace(flags.initrole, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);

        start_menu(win);
        any.a_void = 0;         /* zero out all bits */

        for (i = 0; races[i].noun; i++)
          if (ok_race(flags.initrole, i, flags.initgend,
                      flags.initalign)) {
            any.a_int = i+1;	/* must be non-zero */
            add_menu(win, NO_GLYPH, &any, races[i].noun[0],
                     0, ATR_NONE, races[i].noun, MENU_UNSELECTED);
          }

        any.a_int = pick_race(flags.initrole, flags.initgend,
                              flags.initalign, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randrace(flags.initrole)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the race of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initrace = k;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select a gender, if necessary */
  /* force compatibility with role/race, try for compatibility with
   * pre-selected alignment */
  if (flags.initgend < 0 || !validgend(flags.initrole, flags.initrace,
                                       flags.initgend)) {
    /* pre-selected gender not valid */
    if (pick4u == 'y' || flags.initgend == ROLE_RANDOM || flags.randomall) {
      flags.initgend = pick_gend(flags.initrole, flags.initrace,
                                 flags.initalign, PICK_RANDOM);
      if (flags.initgend < 0) {
        iprintf("Incompatible gender!");
        flags.initgend = randgend(flags.initrole, flags.initrace);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid genders */
      n = 0;	/* number valid */
      k = 0;	/* valid gender */

      for (i = 0; i < ROLE_GENDERS; i++) {
        if (ok_gend(flags.initrole, flags.initrace, i,
                    flags.initalign)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; i < ROLE_GENDERS; i++) {
          if (validgend(flags.initrole, flags.initrace, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);
        start_menu(win);

        any.a_void = 0;         /* zero out all bits */

        for (i = 0; i < ROLE_GENDERS; i++)
          if (ok_gend(flags.initrole, flags.initrace, i,
                      flags.initalign)) {
            any.a_int = i+1;
            add_menu(win, NO_GLYPH, &any, genders[i].adj[0],
                     0, ATR_NONE, genders[i].adj, MENU_UNSELECTED);
          }

        any.a_int = pick_gend(flags.initrole, flags.initrace,
                              flags.initalign, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randgend(flags.initrole, flags.initrace)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the gender of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initgend = k;
    }

    (void)  root_plselection_prompt(plbuf, PROMPT_LAYER_WIDTH - 1,
                                    flags.initrole, flags.initrace, flags.initgend, flags.initalign);
  }

  /* Select an alignment, if necessary */
  /* force compatibility with role/race/gender */
  if (flags.initalign < 0 || !validalign(flags.initrole, flags.initrace,
                                         flags.initalign)) {
    /* pre-selected alignment not valid */
    if (pick4u == 'y' || flags.initalign == ROLE_RANDOM || flags.randomall) {
      flags.initalign = pick_align(flags.initrole, flags.initrace,
                                   flags.initgend, PICK_RANDOM);
      if (flags.initalign < 0) {
        iprintf("Incompatible alignment!");
        flags.initalign = randalign(flags.initrole, flags.initrace);
      }
    } else {	/* pick4u == 'n' */
      /* Count the number of valid alignments */
      n = 0;	/* number valid */
      k = 0;	/* valid alignment */

      for (i = 0; i < ROLE_ALIGNS; i++) {
        if (ok_align(flags.initrole, flags.initrace, flags.initgend,
                     i)) {
          n++;
          k = i;
        }
      }

      if (n == 0) {
        for (i = 0; i < ROLE_ALIGNS; i++) {
          if (validalign(flags.initrole, flags.initrace, i)) {
            n++;
            k = i;
          }
        }
      }

      /* Permit the user to pick, if there is more than one */
      if (n > 1) {
        win = create_nhwindow(NHW_MENU);
        start_menu(win);

        any.a_void = 0;         /* zero out all bits */

        for (i = 0; i < ROLE_ALIGNS; i++)
          if (ok_align(flags.initrole, flags.initrace,
                       flags.initgend, i)) {
            any.a_int = i+1;
            add_menu(win, NO_GLYPH, &any, aligns[i].adj[0],
                     0, ATR_NONE, aligns[i].adj, MENU_UNSELECTED);
          }

        any.a_int = pick_align(flags.initrole, flags.initrace,
                               flags.initgend, PICK_RANDOM)+1;

        if (any.a_int == 0)	/* must be non-zero */
          any.a_int = randalign(flags.initrole, flags.initrace)+1;

        add_menu(win, NO_GLYPH, &any , '*', 0, ATR_NONE,
                 "Random", MENU_UNSELECTED);

        any.a_int = i+1;	/* must be non-zero */

        add_menu(win, NO_GLYPH, &any , 'q', 0, ATR_NONE,
                 "Quit", MENU_UNSELECTED);

        Sprintf(pbuf, "Pick the alignment of your %s", plbuf);
        end_menu(win, pbuf);

        n = select_menu(win, PICK_ONE, &selected);
        destroy_nhwindow(win);

        if (n != 1 || selected[0].item.a_int == any.a_int)
          goto give_up;		/* Selected quit */

        k = selected[0].item.a_int - 1;
        free((genericptr_t) selected),	selected = 0;
      }

      flags.initalign = k;
    }
  }
}
Пример #5
0
struct nh_roles_info *nh_get_roles(void)
{
	int i, rolenum, racenum, gendnum, alignnum, arrsize;
	struct nh_roles_info *info = xmalloc(sizeof(struct nh_roles_info));
	const char **names, **names2;
	nh_bool *tmpmatrix;
	
	/* number of choices */
	for (i = 0; roles[i].name.m; i++);
	info->num_roles = i;
	
	for (i = 0; races[i].noun; i++);
	info->num_races = i;
	
	info->num_genders = ROLE_GENDERS;
	info->num_aligns = ROLE_ALIGNS;
	
	/* names of choices */
	names = xmalloc(info->num_roles * sizeof(char*));
	names2 = xmalloc(info->num_roles * sizeof(char*));
	for (i = 0; i < info->num_roles; i++) {
	    names[i]  = roles[i].name.m;
	    names2[i] = roles[i].name.f;
	}
	info->rolenames_m = names;
	info->rolenames_f = names2;

	names = xmalloc(info->num_races * sizeof(char*));
	for (i = 0; i < info->num_races; i++)
	    names[i] = races[i].noun;
	info->racenames = names;
	
	names = xmalloc(info->num_genders * sizeof(char*));
	for (i = 0; i < info->num_genders; i++)
	    names[i] = genders[i].adj;
	info->gendnames = names;
	
	names = xmalloc(info->num_aligns * sizeof(char*));
	for (i = 0; i < info->num_aligns; i++)
	    names[i] = aligns[i].adj;
	info->alignnames = names;
	
	/* default choices */
	info->def_role = flags.init_role;
	info->def_race = flags.init_race;
	info->def_gend = flags.init_gend;
	info->def_align = flags.init_align;
	
	/* valid combinations of choices */
	arrsize = info->num_roles * info->num_races * info->num_genders * info->num_aligns;
	tmpmatrix = xmalloc(arrsize * sizeof(nh_bool));
	memset(tmpmatrix, FALSE, arrsize * sizeof(nh_bool));
	for (rolenum = 0; rolenum < info->num_roles; rolenum++) {
	    for (racenum = 0; racenum < info->num_races; racenum++) {
		if (!ok_race(rolenum, racenum, ROLE_NONE, ROLE_NONE))
		    continue;
		for (gendnum = 0; gendnum < info->num_genders; gendnum++) {
		    if (!ok_gend(rolenum, racenum, gendnum, ROLE_NONE))
			continue;
		    for (alignnum = 0; alignnum < info->num_aligns; alignnum++) {
			tmpmatrix[nh_cm_idx((*info), rolenum, racenum, gendnum, alignnum)] =
			    ok_align(rolenum, racenum, gendnum, alignnum);
		    }
		}
	    }
	}
	info->matrix = tmpmatrix;
	
	return info;
}
/* prompt the player to choose a gender */
static int vultures_player_selection_gender (void)
{
	winid window;
	anything identifier;
	menu_item *menu_list;
	int chosen, item = 0, items;
	char rolename[BUFSZ];
	char selection[BUFSZ];
	char thisch, lastch;

	menu_list = 0;
	window = vultures_create_nhwindow(NHW_MENU);
	vultures_start_menu(window);
	chosen = 0;
	items = 0;
	lastch = 0;

	/* add all possible genders to the menu */
	while (chosen < ROLE_GENDERS)
	{
		identifier.a_int = chosen + 1;
		if (ok_gend(flags.initrole, flags.initrole, chosen, flags.initalign))
		{
			thisch = lowc(genders[chosen].adj[0]);
			if (thisch == lastch)
				thisch = highc(thisch);
			lastch = thisch;
			vultures_add_menu(window, NO_GLYPH, &identifier, thisch, 0, 0,
								genders[chosen].adj, chosen==flags.initgend);
			items++;
			item = chosen;
		}
		chosen++;
	}

	if (items==1)
	{
		flags.initgend = item;
		free(menu_list);
		vultures_destroy_nhwindow(window);
		return 1;
	}

	identifier.a_int=-1;
	vultures_add_menu(window, NO_GLYPH, &identifier, '*', 0, 0, "Random", (flags.initgend<0));

	vultures_player_selection_rolename((char *)&rolename);
	sprintf(selection,"Pick the gender of your %s", strlen(rolename) ? rolename : "character");
	vultures_end_menu(window, selection);

	if (vultures_select_menu (window, PICK_ONE, &menu_list) == 1)
	{
		chosen=menu_list->item.a_int;
		if (chosen == -1)
			chosen = pick_gend(flags.initrole, flags.initrace, flags.initalign, PICK_RANDOM);
		else
			chosen--;

		flags.initgend = chosen;
		free(menu_list);
		vultures_destroy_nhwindow(window);
		return 1;
	}
	else
		vultures_bail(NULL);

	flags.initgend = -1;
	vultures_destroy_nhwindow(window);
	return 0;
}
Пример #7
0
/* adjust role/race/alignment/gender list - filter out
   invalid combinations
   changed_sel points to the list where selection occurred
   (-1 if unknown)
*/
void
plselAdjustLists(HWND hWnd, int changed_sel)
{
    HWND control_role, control_race, control_gender, control_align;
    int initrole, initrace, initgend, initalign;
    int i;
    int ind;
    int valid_opt;
    TCHAR wbuf[255];

    /* get control handles */
    control_role = GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST);
    control_race = GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST);
    control_gender = GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST);
    control_align = GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST);

    /* get current selections */
    ind = SendMessage(control_role, CB_GETCURSEL, 0, 0);
    initrole = (ind == LB_ERR)
                   ? flags.initrole
                   : SendMessage(control_role, CB_GETITEMDATA, ind, 0);

    ind = SendMessage(control_race, CB_GETCURSEL, 0, 0);
    initrace = (ind == LB_ERR)
                   ? flags.initrace
                   : SendMessage(control_race, CB_GETITEMDATA, ind, 0);

    ind = SendMessage(control_gender, CB_GETCURSEL, 0, 0);
    initgend = (ind == LB_ERR)
                   ? flags.initgend
                   : SendMessage(control_gender, CB_GETITEMDATA, ind, 0);

    ind = SendMessage(control_align, CB_GETCURSEL, 0, 0);
    initalign = (ind == LB_ERR)
                    ? flags.initalign
                    : SendMessage(control_align, CB_GETITEMDATA, ind, 0);

    /* intialize roles list */
    if (changed_sel == -1) {
        valid_opt = 0;

        /* reset content and populate the list */
        SendMessage(control_role, CB_RESETCONTENT, 0, 0);
        for (i = 0; roles[i].name.m; i++) {
            if (ok_role(i, initrace, initgend, initalign)) {
                if (initgend >= 0 && flags.female && roles[i].name.f)
                    ind = SendMessage(
                        control_role, CB_ADDSTRING, (WPARAM) 0,
                        (LPARAM) NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)));
                else
                    ind = SendMessage(
                        control_role, CB_ADDSTRING, (WPARAM) 0,
                        (LPARAM) NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)));

                SendMessage(control_role, CB_SETITEMDATA, (WPARAM) ind,
                            (LPARAM) i);
                if (i == initrole) {
                    SendMessage(control_role, CB_SETCURSEL, (WPARAM) ind,
                                (LPARAM) 0);
                    valid_opt = 1;
                }
            }
        }

        /* set selection to the previously selected role
           if it is still valid */
        if (!valid_opt) {
            initrole = ROLE_NONE;
            initrace = ROLE_NONE;
            initgend = ROLE_NONE;
            initalign = ROLE_NONE;
            SendMessage(control_role, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
        }

        /* trigger change of the races list */
        changed_sel = IDC_PLSEL_ROLE_LIST;
    }

    /* intialize races list */
    if (changed_sel == IDC_PLSEL_ROLE_LIST) {
        valid_opt = 0;

        /* reset content and populate the list */
        SendMessage(control_race, CB_RESETCONTENT, 0, 0);
        for (i = 0; races[i].noun; i++)
            if (ok_race(initrole, i, ROLE_NONE, ROLE_NONE)) {
                ind = SendMessage(
                    control_race, CB_ADDSTRING, (WPARAM) 0,
                    (LPARAM) NH_A2W(races[i].noun, wbuf, sizeof(wbuf)));
                SendMessage(control_race, CB_SETITEMDATA, (WPARAM) ind,
                            (LPARAM) i);
                if (i == initrace) {
                    SendMessage(control_race, CB_SETCURSEL, (WPARAM) ind,
                                (LPARAM) 0);
                    valid_opt = 1;
                }
            }

        /* set selection to the previously selected race
           if it is still valid */
        if (!valid_opt) {
            initrace = ROLE_NONE;
            initgend = ROLE_NONE;
            initalign = ROLE_NONE;
            SendMessage(control_race, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
        }

        /* trigger change of the genders list */
        changed_sel = IDC_PLSEL_RACE_LIST;
    }

    /* intialize genders list */
    if (changed_sel == IDC_PLSEL_RACE_LIST) {
        valid_opt = 0;

        /* reset content and populate the list */
        SendMessage(control_gender, CB_RESETCONTENT, 0, 0);
        for (i = 0; i < ROLE_GENDERS; i++)
            if (ok_gend(initrole, initrace, i, ROLE_NONE)) {
                ind = SendMessage(
                    control_gender, CB_ADDSTRING, (WPARAM) 0,
                    (LPARAM) NH_A2W(genders[i].adj, wbuf, sizeof(wbuf)));
                SendMessage(control_gender, CB_SETITEMDATA, (WPARAM) ind,
                            (LPARAM) i);
                if (i == initgend) {
                    SendMessage(control_gender, CB_SETCURSEL, (WPARAM) ind,
                                (LPARAM) 0);
                    valid_opt = 1;
                }
            }

        /* set selection to the previously selected gender
           if it is still valid */
        if (!valid_opt) {
            initgend = ROLE_NONE;
            initalign = ROLE_NONE;
            SendMessage(control_gender, CB_SETCURSEL, (WPARAM) -1,
                        (LPARAM) 0);
        }

        /* trigger change of the alignments list */
        changed_sel = IDC_PLSEL_GENDER_LIST;
    }

    /* intialize alignments list */
    if (changed_sel == IDC_PLSEL_GENDER_LIST) {
        valid_opt = 0;

        /* reset content and populate the list */
        SendMessage(control_align, CB_RESETCONTENT, 0, 0);
        for (i = 0; i < ROLE_ALIGNS; i++)
            if (ok_align(initrole, initrace, initgend, i)) {
                ind = SendMessage(
                    control_align, CB_ADDSTRING, (WPARAM) 0,
                    (LPARAM) NH_A2W(aligns[i].adj, wbuf, sizeof(wbuf)));
                SendMessage(control_align, CB_SETITEMDATA, (WPARAM) ind,
                            (LPARAM) i);
                if (i == initalign) {
                    SendMessage(control_align, CB_SETCURSEL, (WPARAM) ind,
                                (LPARAM) 0);
                    valid_opt = 1;
                }
            }

        /* set selection to the previously selected alignment
           if it is still valid */
        if (!valid_opt) {
            initalign = ROLE_NONE;
            SendMessage(control_align, CB_SETCURSEL, (WPARAM) -1, (LPARAM) 0);
        }
    }
}
Пример #8
0
/* initialize player selector dialog */
void
plselInitDialog(HWND hWnd)
{
    TCHAR wbuf[BUFSZ];

    /* set player name */
    SetDlgItemText(hWnd, IDC_PLSEL_NAME, NH_A2W(plname, wbuf, sizeof(wbuf)));

    /* check flags for consistency */
    if (flags.initrole >= 0) {
        if (flags.initrace >= 0
            && !validrace(flags.initrole, flags.initrace)) {
            flags.initrace = ROLE_NONE;
        }

        if (flags.initgend >= 0
            && !validgend(flags.initrole, flags.initrace, flags.initgend)) {
            flags.initgend = ROLE_NONE;
        }

        if (flags.initalign >= 0
            && !validalign(flags.initrole, flags.initrace, flags.initalign)) {
            flags.initalign = ROLE_NONE;
        }
    }

    /* populate select boxes */
    plselAdjustLists(hWnd, -1);

    /* intialize roles list */
    if (flags.initrole < 0
        || !ok_role(flags.initrole, ROLE_NONE, ROLE_NONE, ROLE_NONE)) {
        CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_CHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), FALSE);
    } else {
        CheckDlgButton(hWnd, IDC_PLSEL_ROLE_RANDOM, BST_UNCHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ROLE_LIST), TRUE);
        setComboBoxValue(hWnd, IDC_PLSEL_ROLE_LIST, flags.initrole);
    }

    /* intialize races list */
    if (flags.initrace < 0
        || !ok_race(flags.initrole, flags.initrace, ROLE_NONE, ROLE_NONE)) {
        CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_CHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), FALSE);
    } else {
        CheckDlgButton(hWnd, IDC_PLSEL_RACE_RANDOM, BST_UNCHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_RACE_LIST), TRUE);
        setComboBoxValue(hWnd, IDC_PLSEL_RACE_LIST, flags.initrace);
    }

    /* intialize genders list */
    if (flags.initgend < 0
        || !ok_gend(flags.initrole, flags.initrace, flags.initgend,
                    ROLE_NONE)) {
        CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_CHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), FALSE);
    } else {
        CheckDlgButton(hWnd, IDC_PLSEL_GENDER_RANDOM, BST_UNCHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_GENDER_LIST), TRUE);
        setComboBoxValue(hWnd, IDC_PLSEL_GENDER_LIST, flags.initgend);
    }

    /* intialize alignments list */
    if (flags.initalign < 0
        || !ok_align(flags.initrole, flags.initrace, flags.initgend,
                     flags.initalign)) {
        CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_CHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), FALSE);
    } else {
        CheckDlgButton(hWnd, IDC_PLSEL_ALIGN_RANDOM, BST_UNCHECKED);
        EnableWindow(GetDlgItem(hWnd, IDC_PLSEL_ALIGN_LIST), TRUE);
        setComboBoxValue(hWnd, IDC_PLSEL_ALIGN_LIST, flags.initalign);
    }
}