コード例 #1
0
ファイル: mondata.c プロジェクト: clockfort/bingehack4
const char *
locomotion(const struct permonst *ptr, const char *def)
{
    int capitalize = (*def == highc(*def));

    return (is_floater(ptr) ? levitate[capitalize]
            : (is_flyer(ptr) &&
               ptr->msize <= MZ_SMALL) ? flys[capitalize] :
            (is_flyer(ptr) && ptr->msize > MZ_SMALL) ?
            flyl[capitalize] : slithy(ptr) ? slither[capitalize] :
            amorphous(ptr) ? ooze[capitalize] : !ptr->
            mmove ? immobile[capitalize] : nolimbs(ptr) ? crawl[capitalize] :
            def);

}
コード例 #2
0
ファイル: steed.c プロジェクト: FredrIQ/nhfourk
/* The player kicks or whips the steed */
void
kick_steed(void)
{
    char He[4];

    if (!u.usteed)
        return;

    /* [ALI] Various effects of kicking sleeping/paralyzed steeds */
    if (u.usteed->msleeping || !u.usteed->mcanmove) {
        /* We assume a message has just been output of the form "You kick
           <steed>." */
        strcpy(He, mhe(u.usteed));
        *He = highc(*He);
        if ((u.usteed->mcanmove || u.usteed->mfrozen) && !rn2(2)) {
            if (u.usteed->mcanmove)
                u.usteed->msleeping = 0;
            else if (u.usteed->mfrozen > 2)
                u.usteed->mfrozen -= 2;
            else {
                u.usteed->mfrozen = 0;
                u.usteed->mcanmove = 1;
            }
            if (u.usteed->msleeping || !u.usteed->mcanmove)
                pline("%s stirs.", He);
            else
                pline("%s rouses %sself!", He, mhim(u.usteed));
        } else
            pline("%s does not respond.", He);
        return;
    }

    /* Make the steed less tame and check if it resists */
    if (u.usteed->mtame)
        u.usteed->mtame--;
    if (!u.usteed->mtame && u.usteed->mleashed)
        m_unleash(u.usteed, TRUE);
    if (!u.usteed->mtame ||
            (u.ulevel + u.usteed->mtame < rnd(MAXULEV / 2 + 5))) {
        newsym(u.usteed->mx, u.usteed->my);
        dismount_steed(DISMOUNT_THROWN);
        return;
    }

    pline("%s gallops!", Monnam(u.usteed));
    u.ugallop += rn1(20, 30);
    return;
}
コード例 #3
0
ファイル: gl_image.c プロジェクト: Arc0re/acehack
void sdlgl_load_face_dirs(const char *filename, char *face_dirs)
{
  FILE *fp;

  int mon = 0;
  int ch;

#ifdef FILE_AREAS
  fp = fopen_datafile_area(FILE_AREA_SHARE, filename, RDTMODE, FALSE);
#else
  fp = fopen_datafile(filename, RDTMODE, FALSE);
#endif
  if (!fp)
  {
    sdlgl_error("Failed to open file: %s\n", filename);
    return;  /* NOT REACHED */
  }

  while ((ch = fgetc(fp)) != EOF)
  {
    ch = highc(ch);

    if (isspace(ch) || !isprint(ch))
      continue;

    if (ch != '.' && ch != 'L' && ch != 'R')
    {
      sdlgl_warning("Ignoring bad character `%c' in face file: %s\n",
          ch, filename);
      continue;
    }

    face_dirs[mon++] = ch;

    if (mon >= SIZE(tile_16_face_dirs))
    {
      sdlgl_warning("Too many monsters in face file: %s\n", filename);
      break;
    }
  }

  fclose(fp);
}
コード例 #4
0
ファイル: gl_role.c プロジェクト: Arc0re/acehack
/* may return ROLE_RANDOM, or ROLE_NONE when the list is empty (which
 * can only mean that the role/race/gender/alignment combination that
 * the user supplied on the command line was not possible), or
 * ROLE_QUIT if the user pressed escape.
 */
static int do_player_selection_menu(const char *type,
    int (* func)(int what, char *buf))
{
  int i, kind;
  int valid = 0, total = 0, last = -1;

  winid window;
  anything any;
  int attr, choice;

  menu_item *selected = NULL;

  int used_accs[52] = { 0, };
  char accel;
  
  char name[BUFSZ];
  char prompt[BUFSZ];
  char randstr[BUFSZ];

  /* count valid entries */
  for (i=0; ; i++)
  {
    kind = (* func)(i, name);

    if (kind < 0)
      break;

    total++;

    if (kind > 0)
    {
      valid++;
      last = i;
    }
  }
  
  if (valid == 0)
    return ROLE_NONE;

  assert(last >= 0);

  /* -AJA- this is disabled -- it's better IMHO to show the user the
   *       single choice, letting them press ESC and pick some other
   *       role/race/gender if they're not satisfied.
   */
#if 0
  if (valid == 1)
    return last;
#endif
 
  /* create menu */

  sprintf(prompt,  "Pick your %s", type);
  sprintf(randstr, "Random %s", type);
 
  window = Sdlgl_create_nhwindow(NHW_MENU);
  assert(window != WIN_ERR);

  Sdlgl_start_menu(window);

  for (i=0; i < total; i++)
  {
    kind = (* func)(i, name);
    any.a_void = 0;
    attr = ATR_NONE;

    /* choose accelerator key */
    accel = lowc(name[0]);

    if (accel < 'a' || accel > 'z')
      accel = 0;
    else
    {
      if (! used_accs[accel - 'a'])
        used_accs[accel - 'a'] = 1;
      else
      {
        accel = highc(accel);

        if (! used_accs[accel - 'A' + 26])
          used_accs[accel - 'A' + 26] = 1;
        else
          accel = 0;
      }
    }

    if (kind > 0)
    {
      /* must add one, zero is not allowed */
      any.a_int = 1 + i;
    }
    else
    {
      /* shift name right (to align), and make dim */
      memmove(name + 5, name, strlen(name) + 1);
      memcpy(name, "     ", 5);
      attr = ATR_DIM;
    }

    Sdlgl_add_menu(window, NO_GLYPH, &any, accel,
        0 /* no groupacc */, attr, name, MENU_UNSELECTED);
  }

  /* add `Random' line (unless there's only one choice) */
  if (valid > 1)
  {
    any.a_int = 1 + total;

    Sdlgl_add_menu(window, NO_GLYPH, &any, '*',
          0 /* no groupacc */, ATR_NONE, randstr, MENU_UNSELECTED);
  }

  Sdlgl_end_menu(window, prompt);

  /* get result back from menu */

  i = Sdlgl_select_menu(window, PICK_ONE, &selected);
  Sdlgl_destroy_nhwindow(window);

  if (i <= 0)
    return ROLE_QUIT;

  assert(i == 1 && selected);

  choice = selected[0].item.a_int - 1;
  free(selected);

  assert(0 <= choice && choice <= total);

  if (choice == total)
    return ROLE_RANDOM;

  return choice;
}
コード例 #5
0
ファイル: questpgr.c プロジェクト: thejoshwolfe/nethack
static void
convert_line (void)
{
        char *c, *cc;
        char xbuf[BUFSZ];

        cc = out_line;
        for (c = xcrypt(in_line, xbuf); *c; c++) {

            *cc = 0;
            switch(*c) {

                case '\r':
                case '\n':
                        *(++cc) = 0;
                        return;

                case '%':
                        if (*(c+1)) {
                            convert_arg(*(++c));
                            switch (*(++c)) {

                                        /* insert "a"/"an" prefix */
                                case 'A': strcat(cc, An(cvt_buf));
                                    cc += strlen(cc);
                                    continue; /* for */
                                case 'a': strcat(cc, an(cvt_buf));
                                    cc += strlen(cc);
                                    continue; /* for */

                                        /* capitalize */
                                case 'C': cvt_buf[0] = highc(cvt_buf[0]);
                                    break;

                                        /* pluralize */
                                case 'P': cvt_buf[0] = highc(cvt_buf[0]);
                                case 'p': strcpy(cvt_buf, makeplural(cvt_buf));
                                    break;

                                        /* append possessive suffix */
                                case 'S': cvt_buf[0] = highc(cvt_buf[0]);
                                case 's': strcpy(cvt_buf, "TODO: s_suffix(cvt_buf)");
                                    break;

                                        /* strip any "the" prefix */
                                case 't': if (!strncmpi(cvt_buf, "the ", 4)) {
                                        strcat(cc, &cvt_buf[4]);
                                        cc += strlen(cc);
                                        continue; /* for */
                                    }
                                    break;

                                default: --c;   /* undo switch increment */
                                    break;
                            }
                            strcat(cc, cvt_buf);
                            cc += strlen(cvt_buf);
                            break;
                        }       /* else fall through */

                default:
                        *cc++ = *c;
                        break;
            }
        }
        if (cc >= out_line + sizeof out_line)
            panic("convert_line: overflow");
        *cc = 0;
        return;
}
コード例 #6
0
ファイル: pager.c プロジェクト: DanielT/NitroHack
/* quick: use cursor && don't search for "more info" */
static int do_look(boolean quick)
{
    char out_str[BUFSZ];
    char firstmatch[BUFSZ];
    int i, ans = 0, objplur = 0;
    int found;		/* count of matching syms found */
    coord cc;		/* screen pos of unknown glyph */
    boolean save_verbose;	/* saved value of flags.verbose */
    boolean from_screen;	/* question from the screen */
    struct nh_desc_buf descbuf;
    struct obj *otmp;

    if (quick) {
	from_screen = TRUE;	/* yes, we want to use the cursor */
    } else {
	i = ynq("Specify unknown object by cursor?");
	if (i == 'q') return 0;
	from_screen = (i == 'y');
    }

    if (from_screen) {
	cc.x = u.ux;
	cc.y = u.uy;
    } else {
	getlin("Specify what? (type the word)", out_str);
	if (out_str[0] == '\0' || out_str[0] == '\033')
	    return 0;

	/* the ability to specify symbols is gone: it is simply impossible to
	 * know how the window port is displaying things (tiles?) and even if
	 * charaters are used it may not be possible to type them (utf8)
	 */
	
	checkfile(out_str, NULL, TRUE, TRUE);
	return 0;
    }
    /* Save the verbose flag, we change it later. */
    save_verbose = flags.verbose;
    flags.verbose = flags.verbose && !quick;
    
    /*
     * we're identifying from the screen.
     */
    do {
	/* Reset some variables. */
	found = 0;
	out_str[0] = '\0';
	objplur = 0;

	if (flags.verbose)
	    pline("Please move the cursor to %s.",
		    what_is_an_unknown_object);
	else
	    pline("Pick an object.");

	ans = getpos(&cc, FALSE, what_is_an_unknown_object);
	if (ans < 0 || cc.x < 0) {
	    flags.verbose = save_verbose;
	    return 0;	/* done */
	}
	flags.verbose = FALSE;	/* only print long question once */

	nh_describe_pos(cc.x, cc.y, &descbuf);
	
	otmp = vobj_at(cc.x, cc.y);
	if (otmp && is_plural(otmp))
	    objplur = 1;
	
	out_str[0] = '\0';
	if (append_str(out_str, descbuf.effectdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.effectdesc);
	
	if (append_str(out_str, descbuf.invisdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.invisdesc);
	
	if (append_str(out_str, descbuf.mondesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.mondesc);
	
	if (append_str(out_str, descbuf.objdesc, objplur))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.objdesc);
	
	if (append_str(out_str, descbuf.trapdesc, 0))
	    if (++found == 1)
		strcpy (firstmatch, descbuf.trapdesc);
	
	if (append_str(out_str, descbuf.bgdesc, 0))
	    if (!found) {
		found++; /* only increment found if nothing else was seen,
		so that checkfile can be called below */
		strcpy (firstmatch, descbuf.bgdesc);
	    }
	

	/* Finally, print out our explanation. */
	if (found) {
	    out_str[0] = highc(out_str[0]);
	    pline("%s.", out_str);
	    /* check the data file for information about this thing */
	    if (found == 1 && ans != LOOK_QUICK && ans != LOOK_ONCE &&
			(ans == LOOK_VERBOSE || !quick)) {
		checkfile(firstmatch, NULL, FALSE, ans == LOOK_VERBOSE);
	    }
	} else {
	    pline("I've never heard of such things.");
	}
    } while (!quick && ans != LOOK_ONCE);

    flags.verbose = save_verbose;

    return 0;
}
コード例 #7
0
ファイル: nds_win.c プロジェクト: paulog/nethackds
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;
    }
  }
}
コード例 #8
0
ファイル: music.c プロジェクト: FredrIQ/fiqhack
/* Some countries name the notes of the scale A to G. In others, "B" refers
   specifically to B flat, and a B natural is called H. This function places
   both onto the same seven-note scale. */
static char
highc_htob(char c)
{
    c = highc(c);
    return c == 'H' ? 'B' : c;
}
コード例 #9
0
ファイル: hacklib.c プロジェクト: DanielT/NitroHack
char *upstart(char *s)	/* convert first character of a string to uppercase */
{
    if (s) *s = highc(*s);
    return s;
}
コード例 #10
0
ファイル: wintty.c プロジェクト: saihack/NetHack
void
tty_player_selection()
{
    char pbuf[QBUFSZ];
    char pick, pc;
    int i, linecount;

    linecount = wins[BASE_WINDOW]->cury+1;
    if ((pc = highc(pl_character[0])) != 0) {
	if(index(pl_classes, pc) != (char*) 0)
	    goto got_suffix;
	tty_putstr(BASE_WINDOW, 0, "");
	Sprintf(pbuf, "Unknown role: %c", pc);
	tty_putstr(BASE_WINDOW, 0, pbuf);
	linecount += 2;
	pl_character[0] = pc = 0;
    }

#define PICK_PROMPT "Shall I pick a character for you? [Y, N, or Q(quit)] "
    tty_putstr(BASE_WINDOW, 0, "");
    tty_putstr(BASE_WINDOW, 0, PICK_PROMPT);

    while(!index("yYnNqQ", (pick = readchar())) && !index(quitchars, pick))
	tty_nhbell();

    pick = index(quitchars, pick) ? 'Y' : highc(pick);

    tty_putsym(BASE_WINDOW, (int)strlen(PICK_PROMPT)+1, linecount, pick); /* echo */

    if (pick == 'Q') {
	clearlocks();
	tty_exit_nhwindows(NULL);
	terminate(0);
    }

    if (pick == 'Y') {
	tty_putstr(BASE_WINDOW, 0, "");
	goto beginner;
    }

    tty_curs(BASE_WINDOW, 1, linecount+2);
    tty_putstr(BASE_WINDOW, 0, "What kind of character are you:");
    tty_putstr(BASE_WINDOW, 0, "");
    Sprintf(pbuf, " 	 %s,", An(roles[0]));
    for(i = 1; roles[i]; i++) {
	Sprintf(eos(pbuf), " %s", an(roles[i]));
	if((((i + 1) % 4) == 0) && roles[i+1]) {
	    Strcat(pbuf, ",");
	    tty_putstr(BASE_WINDOW, 0, pbuf);
	    linecount++;
	    Strcpy(pbuf, "        ");
	}
	else if(roles[i+1] && roles[i+2])	Strcat(pbuf, ",");
	if(roles[i+1] && !roles[i+2])	Strcat(pbuf, " or");
    }
    Strcat(pbuf ,"?");
    tty_putstr(BASE_WINDOW, 0, pbuf);
    Strcpy(pbuf, "         [");
    for(i = 0; roles[i]; i++)
	Sprintf(eos(pbuf), "%c,", pl_classes[i]);
    Strcat(pbuf, " or Q] ");
    tty_putstr(BASE_WINDOW, 0, pbuf);
    linecount += 5;

    while ((pc = readchar()) != 0) {
	if ((pc = highc(pc)) == 'Q') {
	    clearlocks();
	    tty_exit_nhwindows(NULL);
	    terminate(0);
	}
	if(index(pl_classes, pc) != (char *) 0) {
	    tty_putsym(BASE_WINDOW, (int)strlen(pbuf)+1, linecount, pc); /* echo */
	    tty_putstr(BASE_WINDOW, 0, "");
	    tty_display_nhwindow(BASE_WINDOW, TRUE);
	    break;
	}
	if(pc == '\n') {
	    pc = 0;
	    break;
	}
	tty_nhbell();
    }

beginner:
    if(!pc) {
	i = rn2((int)strlen(pl_classes));
	pc = pl_classes[i];
	tty_putstr(BASE_WINDOW, 0, "");
	Sprintf(pbuf, "This game you will be %s.", an(roles[i]));
	tty_putstr(BASE_WINDOW, 0, pbuf);
	tty_putstr(BASE_WINDOW, 0, "");
	tty_display_nhwindow(BASE_WINDOW, TRUE);
	getret();
    }
got_suffix:

    tty_clear_nhwindow(BASE_WINDOW);
    pl_character[0] = pc;
    return;
}
コード例 #11
0
/* prompt the player to choose a role */
static int vultures_player_selection_role (void)
{
	winid window;
	anything identifier;
	menu_item *menu_list;
	int chosen, items, item = 0;
	char thisch, lastch;

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

	/* add all possible roles to a menu */
	for (chosen = 0; roles[chosen].name.m || roles[chosen].name.f; chosen++)
	{
		identifier.a_int = chosen + 1;
		if (ok_role(chosen, flags.initrace, flags.initgend, flags.initalign))
		{
			items++;
			item = chosen;

			if (flags.initgend == 1 && roles[chosen].name.f)
			{
				thisch = lowc(roles[chosen].name.f[0]);
				if (thisch == lastch)
					thisch = highc(thisch);
				vultures_add_menu (window, NO_GLYPH, &identifier, thisch, 0, 0,
								roles[chosen].name.f, (chosen == flags.initrole));
			}
			else
			{
				thisch = lowc(roles[chosen].name.m[0]);
				if (thisch == lastch)
					thisch = highc(thisch);
				vultures_add_menu (window, NO_GLYPH, &identifier, thisch, 0, 0,
								roles[chosen].name.m, (chosen==flags.initrole));
			}
			lastch = thisch;
		}
	}

	/* if the menu contains only one item, select that automatically */
	if (items == 1)
	{
		flags.initrole = 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.initrole<0));

	/* Don't use the rolename here, otherwise we might get "Pick a role for your wizard"
	* which is rather silly. */
	vultures_end_menu(window, "Pick a role for your character");

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

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

	flags.initrole = -1;
	vultures_destroy_nhwindow(window);
	return 0;
}
コード例 #12
0
/* prompt the player to choose an alignment */
static int vultures_player_selection_alignment (void)
{
	winid window;
	anything identifier;
	menu_item *menu_list;
	int chosen, items, item = 0;
	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 the potential alignments for this character to a menu */
	while (chosen < ROLE_ALIGNS)
	{
		identifier.a_int = chosen + 1;
		if (ok_align(flags.initrole, flags.initrace, flags.initgend, chosen))
		{
			items++;
			item = chosen;
			thisch = lowc(aligns[chosen].adj[0]);
			if (thisch == lastch)
				thisch = highc(thisch);
			lastch = thisch;
			vultures_add_menu ( window, NO_GLYPH, &identifier, thisch, 0, 0,
								aligns[chosen].adj, (chosen == flags.initalign));
		}
		chosen++;
	}

	/* if there is only one possible alignment, select it automatically */
	if (items == 1)
	{
		flags.initalign = 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.initalign < 0));

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

	/* let the player pick an alignment */
	if (vultures_select_menu (window, PICK_ONE, &menu_list)==1)
	{
		chosen = menu_list->item.a_int;
		if (chosen == -1)
			chosen = pick_align(flags.initrole, flags.initrace, flags.initgend, PICK_RANDOM);
		else
			chosen--;

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

	flags.initalign = -1;
	vultures_destroy_nhwindow(window);
	return 0;
}
コード例 #13
0
/* 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;
}
コード例 #14
0
/* prompt the player to choose a race */
static int vultures_player_selection_race (void)
{
	winid window;
	anything identifier;
	menu_item *menu_list;
	int chosen, items, item = 0;
	char rolename[BUFSZ];
	char selection[BUFSZ];
	char thisch, lastch;

	menu_list = 0;
	window = vultures_create_nhwindow(NHW_MENU);
	vultures_start_menu(window);

	items = 0;
	lastch = 0;

	/* add all possible races to a menu */
	for (chosen = 0; races[chosen].noun; chosen++)
	{
		identifier.a_int = chosen + 1;
		if (ok_race(flags.initrole, chosen, flags.initgend, flags.initalign))
		{
			items++;
			item = chosen;
			thisch = lowc(races[chosen].noun[0]);
			if (thisch == lastch)
				thisch = highc(thisch);
			lastch = thisch;
			vultures_add_menu(window, NO_GLYPH, &identifier, thisch, 0, 0,
							races[chosen].noun, chosen==flags.initrace);
		}
	}

	/* if the menu contains only one item, select that automatically */
	if (items == 1) {
		flags.initrace = 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.initrace<0));

	vultures_player_selection_rolename((char *)&rolename);
	sprintf(selection,"Pick the race 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_race(flags.initrole, flags.initgend, flags.initalign, PICK_RANDOM);
		else
			chosen--;

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

	flags.initrace = -1;
	vultures_destroy_nhwindow(window);
	return 0;

}