Source:NetHack 3.6.0/src/o init.c

From NetHackWiki
(Redirected from Source:O init.c)
Jump to: navigation, search

Below is the full text to o_init.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/o_init.c#line123]], for example.

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

Top of file

  1.  /* NetHack 3.6	o_init.c	$NHDT-Date: 1446892449 2015/11/07 10:34:09 $  $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */
  2.  /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3.  /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5.  #include "hack.h"
  6.  #include "lev.h" /* save & restore info */
  7.  
  8.  STATIC_DCL void FDECL(setgemprobs, (d_level *));
  9.  STATIC_DCL void FDECL(shuffle, (int, int, BOOLEAN_P));
  10.  STATIC_DCL void NDECL(shuffle_all);
  11.  STATIC_DCL boolean FDECL(interesting_to_discover, (int));
  12.  STATIC_DCL char *FDECL(oclass_to_name, (CHAR_P, char *));
  13.  
  14.  static NEARDATA short disco[NUM_OBJECTS] = DUMMY;
  15.  

shuffle_tiles

  1.  #ifdef USE_TILES
  2.  STATIC_DCL void NDECL(shuffle_tiles);
  3.  extern short glyph2tile[]; /* from tile.c */
  4.  
  5.  /* Shuffle tile assignments to match descriptions, so a red potion isn't
  6.   * displayed with a blue tile and so on.
  7.   *
  8.   * Tile assignments are not saved, and shouldn't be so that a game can
  9.   * be resumed on an otherwise identical non-tile-using binary, so we have
  10.   * to reshuffle the assignments from oc_descr_idx information when a game
  11.   * is restored.  So might as well do that the first time instead of writing
  12.   * another routine.
  13.   */
  14.  STATIC_OVL void
  15.  shuffle_tiles()
  16.  {
  17.      int i;
  18.      short tmp_tilemap[NUM_OBJECTS];
  19.  
  20.      for (i = 0; i < NUM_OBJECTS; i++)
  21.          tmp_tilemap[i] = glyph2tile[objects[i].oc_descr_idx + GLYPH_OBJ_OFF];
  22.  
  23.      for (i = 0; i < NUM_OBJECTS; i++)
  24.          glyph2tile[i + GLYPH_OBJ_OFF] = tmp_tilemap[i];
  25.  }
  26.  #endif /* USE_TILES */
  27.  

setgemprobs

  1.  STATIC_OVL void
  2.  setgemprobs(dlev)
  3.  d_level *dlev;
  4.  {
  5.      int j, first, lev;
  6.  
  7.      if (dlev)
  8.          lev = (ledger_no(dlev) > maxledgerno()) ? maxledgerno()
  9.                                                  : ledger_no(dlev);
  10.      else
  11.          lev = 0;
  12.      first = bases[GEM_CLASS];
  13.  
  14.      for (j = 0; j < 9 - lev / 3; j++)
  15.          objects[first + j].oc_prob = 0;
  16.      first += j;
  17.      if (first > LAST_GEM || objects[first].oc_class != GEM_CLASS
  18.          || OBJ_NAME(objects[first]) == (char *) 0) {
  19.          raw_printf("Not enough gems? - first=%d j=%d LAST_GEM=%d", first, j,
  20.                     LAST_GEM);
  21.          wait_synch();
  22.      }
  23.      for (j = first; j <= LAST_GEM; j++)
  24.          objects[j].oc_prob = (171 + j - first) / (LAST_GEM + 1 - first);
  25.  }
  26.  

shuffle

  1.  /* shuffle descriptions on objects o_low to o_high */
  2.  STATIC_OVL void
  3.  shuffle(o_low, o_high, domaterial)
  4.  int o_low, o_high;
  5.  boolean domaterial;
  6.  {
  7.      int i, j, num_to_shuffle;
  8.      short sw;
  9.      int color;
  10.  
  11.      for (num_to_shuffle = 0, j = o_low; j <= o_high; j++)
  12.          if (!objects[j].oc_name_known)
  13.              num_to_shuffle++;
  14.      if (num_to_shuffle < 2)
  15.          return;
  16.  
  17.      for (j = o_low; j <= o_high; j++) {
  18.          if (objects[j].oc_name_known)
  19.              continue;
  20.          do
  21.              i = j + rn2(o_high - j + 1);
  22.          while (objects[i].oc_name_known);
  23.          sw = objects[j].oc_descr_idx;
  24.          objects[j].oc_descr_idx = objects[i].oc_descr_idx;
  25.          objects[i].oc_descr_idx = sw;
  26.          sw = objects[j].oc_tough;
  27.          objects[j].oc_tough = objects[i].oc_tough;
  28.          objects[i].oc_tough = sw;
  29.          color = objects[j].oc_color;
  30.          objects[j].oc_color = objects[i].oc_color;
  31.          objects[i].oc_color = color;
  32.  
  33.          /* shuffle material */
  34.          if (domaterial) {
  35.              sw = objects[j].oc_material;
  36.              objects[j].oc_material = objects[i].oc_material;
  37.              objects[i].oc_material = sw;
  38.          }
  39.      }
  40.  }
  41.  

init_objects

  1.  void
  2.  init_objects()
  3.  {
  4.      register int i, first, last, sum;
  5.      register char oclass;
  6.  #ifdef TEXTCOLOR
  7.  #define COPY_OBJ_DESCR(o_dst, o_src) \
  8.      o_dst.oc_descr_idx = o_src.oc_descr_idx, o_dst.oc_color = o_src.oc_color
  9.  #else
  10.  #define COPY_OBJ_DESCR(o_dst, o_src) o_dst.oc_descr_idx = o_src.oc_descr_idx
  11.  #endif
  12.  
  13.      /* bug fix to prevent "initialization error" abort on Intel Xenix.
  14.       * reported by mikew@semike
  15.       */
  16.      for (i = 0; i < MAXOCLASSES; i++)
  17.          bases[i] = 0;
  18.      /* initialize object descriptions */
  19.      for (i = 0; i < NUM_OBJECTS; i++)
  20.          objects[i].oc_name_idx = objects[i].oc_descr_idx = i;
  21.      /* init base; if probs given check that they add up to 1000,
  22.         otherwise compute probs */
  23.      first = 0;
  24.      while (first < NUM_OBJECTS) {
  25.          oclass = objects[first].oc_class;
  26.          last = first + 1;
  27.          while (last < NUM_OBJECTS && objects[last].oc_class == oclass)
  28.              last++;
  29.          bases[(int) oclass] = first;
  30.  
  31.          if (oclass == GEM_CLASS) {
  32.              setgemprobs((d_level *) 0);
  33.  
  34.              if (rn2(2)) { /* change turquoise from green to blue? */
  35.                  COPY_OBJ_DESCR(objects[TURQUOISE], objects[SAPPHIRE]);
  36.              }
  37.              if (rn2(2)) { /* change aquamarine from green to blue? */
  38.                  COPY_OBJ_DESCR(objects[AQUAMARINE], objects[SAPPHIRE]);
  39.              }
  40.              switch (rn2(4)) { /* change fluorite from violet? */
  41.              case 0:
  42.                  break;
  43.              case 1: /* blue */
  44.                  COPY_OBJ_DESCR(objects[FLUORITE], objects[SAPPHIRE]);
  45.                  break;
  46.              case 2: /* white */
  47.                  COPY_OBJ_DESCR(objects[FLUORITE], objects[DIAMOND]);
  48.                  break;
  49.              case 3: /* green */
  50.                  COPY_OBJ_DESCR(objects[FLUORITE], objects[EMERALD]);
  51.                  break;
  52.              }
  53.          }
  54.      check:
  55.          sum = 0;
  56.          for (i = first; i < last; i++)
  57.              sum += objects[i].oc_prob;
  58.          if (sum == 0) {
  59.              for (i = first; i < last; i++)
  60.                  objects[i].oc_prob = (1000 + i - first) / (last - first);
  61.              goto check;
  62.          }
  63.          if (sum != 1000)
  64.              error("init-prob error for class %d (%d%%)", oclass, sum);
  65.          first = last;
  66.      }
  67.      /* shuffle descriptions */
  68.      shuffle_all();
  69.  #ifdef USE_TILES
  70.      shuffle_tiles();
  71.  #endif
  72.      objects[WAN_NOTHING].oc_dir = rn2(2) ? NODIR : IMMEDIATE;
  73.  }
  74.  

obj_shuffle_range

  1.  /* retrieve the range of objects that otyp shares descriptions with */
  2.  void
  3.  obj_shuffle_range(otyp, lo_p, hi_p)
  4.  int otyp;         /* input: representative item */
  5.  int *lo_p, *hi_p; /* output: range that item belongs among */
  6.  {
  7.      int i, ocls = objects[otyp].oc_class;
  8.  
  9.      /* default is just the object itself */
  10.      *lo_p = *hi_p = otyp;
  11.  
  12.      switch (ocls) {
  13.      case ARMOR_CLASS:
  14.          if (otyp >= HELMET && otyp <= HELM_OF_TELEPATHY)
  15.              *lo_p = HELMET, *hi_p = HELM_OF_TELEPATHY;
  16.          else if (otyp >= LEATHER_GLOVES && otyp <= GAUNTLETS_OF_DEXTERITY)
  17.              *lo_p = LEATHER_GLOVES, *hi_p = GAUNTLETS_OF_DEXTERITY;
  18.          else if (otyp >= CLOAK_OF_PROTECTION && otyp <= CLOAK_OF_DISPLACEMENT)
  19.              *lo_p = CLOAK_OF_PROTECTION, *hi_p = CLOAK_OF_DISPLACEMENT;
  20.          else if (otyp >= SPEED_BOOTS && otyp <= LEVITATION_BOOTS)
  21.              *lo_p = SPEED_BOOTS, *hi_p = LEVITATION_BOOTS;
  22.          break;
  23.      case POTION_CLASS:
  24.          /* potion of water has the only fixed description */
  25.          *lo_p = bases[POTION_CLASS];
  26.          *hi_p = POT_WATER - 1;
  27.          break;
  28.      case AMULET_CLASS:
  29.      case SCROLL_CLASS:
  30.      case SPBOOK_CLASS:
  31.          /* exclude non-magic types and also unique ones */
  32.          *lo_p = bases[ocls];
  33.          for (i = *lo_p; objects[i].oc_class == ocls; i++)
  34.              if (objects[i].oc_unique || !objects[i].oc_magic)
  35.                  break;
  36.          *hi_p = i - 1;
  37.          break;
  38.      case RING_CLASS:
  39.      case WAND_CLASS:
  40.      case VENOM_CLASS:
  41.          /* entire class */
  42.          *lo_p = bases[ocls];
  43.          for (i = *lo_p; objects[i].oc_class == ocls; i++)
  44.              continue;
  45.          *hi_p = i - 1;
  46.          break;
  47.      }
  48.  
  49.      /* artifact checking might ask about item which isn't part of any range
  50.         but fell within the classes that do have ranges specified above */
  51.      if (otyp < *lo_p || otyp > *hi_p)
  52.          *lo_p = *hi_p = otyp;
  53.      return;
  54.  }
  55.  

shuffle_all

  1.  /* randomize object descriptions */
  2.  STATIC_OVL void
  3.  shuffle_all()
  4.  {
  5.      /* entire classes; obj_shuffle_range() handles their exceptions */
  6.      static char shuffle_classes[] = {
  7.          AMULET_CLASS, POTION_CLASS, RING_CLASS,  SCROLL_CLASS,
  8.          SPBOOK_CLASS, WAND_CLASS,   VENOM_CLASS,
  9.      };
  10.      /* sub-class type ranges (one item from each group) */
  11.      static short shuffle_types[] = {
  12.          HELMET, LEATHER_GLOVES, CLOAK_OF_PROTECTION, SPEED_BOOTS,
  13.      };
  14.      int first, last, idx;
  15.  
  16.      /* do whole classes (amulets, &c) */
  17.      for (idx = 0; idx < SIZE(shuffle_classes); idx++) {
  18.          obj_shuffle_range(bases[(int) shuffle_classes[idx]], &first, &last);
  19.          shuffle(first, last, TRUE);
  20.      }
  21.      /* do type ranges (helms, &c) */
  22.      for (idx = 0; idx < SIZE(shuffle_types); idx++) {
  23.          obj_shuffle_range(shuffle_types[idx], &first, &last);
  24.          shuffle(first, last, FALSE);
  25.      }
  26.      return;
  27.  }
  28.  

find_skates

  1.  /* find the object index for snow boots; used [once] by slippery ice code */
  2.  int
  3.  find_skates()
  4.  {
  5.      register int i;
  6.      register const char *s;
  7.  
  8.      for (i = SPEED_BOOTS; i <= LEVITATION_BOOTS; i++)
  9.          if ((s = OBJ_DESCR(objects[i])) != 0 && !strcmp(s, "snow boots"))
  10.              return i;
  11.  
  12.      impossible("snow boots not found?");
  13.      return -1; /* not 0, or caller would try again each move */
  14.  }
  15.  

oinit

  1.  /* level dependent initialization */
  2.  void
  3.  oinit()
  4.  {
  5.      setgemprobs(&u.uz);
  6.  }
  7.  

savenames

  1.  void
  2.  savenames(fd, mode)
  3.  int fd, mode;
  4.  {
  5.      register int i;
  6.      unsigned int len;
  7.  
  8.      if (perform_bwrite(mode)) {
  9.          bwrite(fd, (genericptr_t) bases, sizeof bases);
  10.          bwrite(fd, (genericptr_t) disco, sizeof disco);
  11.          bwrite(fd, (genericptr_t) objects,
  12.                 sizeof(struct objclass) * NUM_OBJECTS);
  13.      }
  14.      /* as long as we use only one version of Hack we
  15.         need not save oc_name and oc_descr, but we must save
  16.         oc_uname for all objects */
  17.      for (i = 0; i < NUM_OBJECTS; i++)
  18.          if (objects[i].oc_uname) {
  19.              if (perform_bwrite(mode)) {
  20.                  len = strlen(objects[i].oc_uname) + 1;
  21.                  bwrite(fd, (genericptr_t) &len, sizeof len);
  22.                  bwrite(fd, (genericptr_t) objects[i].oc_uname, len);
  23.              }
  24.              if (release_data(mode)) {
  25.                  free((genericptr_t) objects[i].oc_uname);
  26.                  objects[i].oc_uname = 0;
  27.              }
  28.          }
  29.  }
  30.  

restnames

  1.  void
  2.  restnames(fd)
  3.  register int fd;
  4.  {
  5.      register int i;
  6.      unsigned int len;
  7.  
  8.      mread(fd, (genericptr_t) bases, sizeof bases);
  9.      mread(fd, (genericptr_t) disco, sizeof disco);
  10.      mread(fd, (genericptr_t) objects, sizeof(struct objclass) * NUM_OBJECTS);
  11.      for (i = 0; i < NUM_OBJECTS; i++)
  12.          if (objects[i].oc_uname) {
  13.              mread(fd, (genericptr_t) &len, sizeof len);
  14.              objects[i].oc_uname = (char *) alloc(len);
  15.              mread(fd, (genericptr_t) objects[i].oc_uname, len);
  16.          }
  17.  #ifdef USE_TILES
  18.      shuffle_tiles();
  19.  #endif
  20.  }
  21.  

discover_object

  1.  void
  2.  discover_object(oindx, mark_as_known, credit_hero)
  3.  register int oindx;
  4.  boolean mark_as_known;
  5.  boolean credit_hero;
  6.  {
  7.      if (!objects[oindx].oc_name_known) {
  8.          register int dindx, acls = objects[oindx].oc_class;
  9.  
  10.          /* Loop thru disco[] 'til we find the target (which may have been
  11.             uname'd) or the next open slot; one or the other will be found
  12.             before we reach the next class...
  13.           */
  14.          for (dindx = bases[acls]; disco[dindx] != 0; dindx++)
  15.              if (disco[dindx] == oindx)
  16.                  break;
  17.          disco[dindx] = oindx;
  18.  
  19.          if (mark_as_known) {
  20.              objects[oindx].oc_name_known = 1;
  21.              if (credit_hero)
  22.                  exercise(A_WIS, TRUE);
  23.          }
  24.          if (moves > 1L)
  25.              update_inventory();
  26.      }
  27.  }
  28.  

undiscover_object

  1.  /* if a class name has been cleared, we may need to purge it from disco[] */
  2.  void
  3.  undiscover_object(oindx)
  4.  register int oindx;
  5.  {
  6.      if (!objects[oindx].oc_name_known) {
  7.          register int dindx, acls = objects[oindx].oc_class;
  8.          register boolean found = FALSE;
  9.  
  10.          /* find the object; shift those behind it forward one slot */
  11.          for (dindx = bases[acls]; dindx < NUM_OBJECTS && disco[dindx] != 0
  12.                                    && objects[dindx].oc_class == acls;
  13.               dindx++)
  14.              if (found)
  15.                  disco[dindx - 1] = disco[dindx];
  16.              else if (disco[dindx] == oindx)
  17.                  found = TRUE;
  18.  
  19.          /* clear last slot */
  20.          if (found)
  21.              disco[dindx - 1] = 0;
  22.          else
  23.              impossible("named object not in disco");
  24.          update_inventory();
  25.      }
  26.  }
  27.  

interesting_to_discover

  1.  STATIC_OVL boolean
  2.  interesting_to_discover(i)
  3.  register int i;
  4.  {
  5.      /* Pre-discovered objects are now printed with a '*' */
  6.      return (boolean) (objects[i].oc_uname != (char *) 0
  7.                        || (objects[i].oc_name_known
  8.                            && OBJ_DESCR(objects[i]) != (char *) 0));
  9.  }
  10.  

dodiscovered

  1.  /* items that should stand out once they're known */
  2.  static short uniq_objs[] = {
  3.      AMULET_OF_YENDOR, SPE_BOOK_OF_THE_DEAD, CANDELABRUM_OF_INVOCATION,
  4.      BELL_OF_OPENING,
  5.  };
  6.  
  7.  /* the '\' command - show discovered object types */
  8.  int
  9.  dodiscovered() /* free after Robert Viduya */
  10.  {
  11.      register int i, dis;
  12.      int ct = 0;
  13.      char *s, oclass, prev_class, classes[MAXOCLASSES], buf[BUFSZ];
  14.      winid tmpwin;
  15.  
  16.      tmpwin = create_nhwindow(NHW_MENU);
  17.      putstr(tmpwin, 0, "Discoveries");
  18.      putstr(tmpwin, 0, "");
  19.  
  20.      /* gather "unique objects" into a pseudo-class; note that they'll
  21.         also be displayed individually within their regular class */
  22.      for (i = dis = 0; i < SIZE(uniq_objs); i++)
  23.          if (objects[uniq_objs[i]].oc_name_known) {
  24.              if (!dis++)
  25.                  putstr(tmpwin, iflags.menu_headings, "Unique items");
  26.              Sprintf(buf, "  %s", OBJ_NAME(objects[uniq_objs[i]]));
  27.              putstr(tmpwin, 0, buf);
  28.              ++ct;
  29.          }
  30.      /* display any known artifacts as another pseudo-class */
  31.      ct += disp_artifact_discoveries(tmpwin);
  32.  
  33.      /* several classes are omitted from packorder; one is of interest here */
  34.      Strcpy(classes, flags.inv_order);
  35.      if (!index(classes, VENOM_CLASS)) {
  36.          s = eos(classes);
  37.          *s++ = VENOM_CLASS;
  38.          *s = '\0';
  39.      }
  40.  
  41.      for (s = classes; *s; s++) {
  42.          oclass = *s;
  43.          prev_class = oclass + 1; /* forced different from oclass */
  44.          for (i = bases[(int) oclass];
  45.               i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) {
  46.              if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) {
  47.                  ct++;
  48.                  if (oclass != prev_class) {
  49.                      putstr(tmpwin, iflags.menu_headings,
  50.                             let_to_name(oclass, FALSE, FALSE));
  51.                      prev_class = oclass;
  52.                  }
  53.                  Sprintf(buf, "%s %s",
  54.                          (objects[dis].oc_pre_discovered ? "*" : " "),
  55.                          obj_typename(dis));
  56.                  putstr(tmpwin, 0, buf);
  57.              }
  58.          }
  59.      }
  60.      if (ct == 0) {
  61.          You("haven't discovered anything yet...");
  62.      } else
  63.          display_nhwindow(tmpwin, TRUE);
  64.      destroy_nhwindow(tmpwin);
  65.  
  66.      return 0;
  67.  }
  68.  

oclass_to_name

  1.  /* lower case let_to_name() output, which differs from def_oc_syms[].name */
  2.  STATIC_OVL char *
  3.  oclass_to_name(oclass, buf)
  4.  char oclass;
  5.  char *buf;
  6.  {
  7.      char *s;
  8.  
  9.      Strcpy(buf, let_to_name(oclass, FALSE, FALSE));
  10.      for (s = buf; *s; ++s)
  11.          *s = lowc(*s);
  12.      return buf;
  13.  }
  14.  

doclassdisco

  1.  /* the '`' command - show discovered object types for one class */
  2.  int
  3.  doclassdisco()
  4.  {
  5.      static NEARDATA const char
  6.          prompt[] = "View discoveries for which sort of objects?",
  7.          havent_discovered_any[] = "haven't discovered any %s yet.",
  8.          unique_items[] = "unique items",
  9.          artifact_items[] = "artifacts";
  10.      char *s, c, oclass, menulet, allclasses[MAXOCLASSES],
  11.          discosyms[2 + MAXOCLASSES + 1], buf[BUFSZ];
  12.      int i, ct, dis, xtras;
  13.      boolean traditional;
  14.      winid tmpwin;
  15.      anything any;
  16.      menu_item *pick_list = 0;
  17.  
  18.      discosyms[0] = '\0';
  19.      traditional = (flags.menu_style == MENU_TRADITIONAL
  20.                     || flags.menu_style == MENU_COMBINATION);
  21.      tmpwin = !traditional ? create_nhwindow(NHW_MENU) : WIN_ERR;
  22.      any = zeroany;
  23.      menulet = 'a';
  24.  
  25.      /* check whether we've discovered any unique objects */
  26.      for (i = 0; i < SIZE(uniq_objs); i++)
  27.          if (objects[uniq_objs[i]].oc_name_known) {
  28.              Strcat(discosyms, "u");
  29.              if (!traditional) {
  30.                  any.a_int = 'u';
  31.                  add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE,
  32.                           unique_items, MENU_UNSELECTED);
  33.              }
  34.              break;
  35.          }
  36.  
  37.      /* check whether we've discovered any artifacts */
  38.      if (disp_artifact_discoveries(WIN_ERR) > 0) {
  39.          Strcat(discosyms, "a");
  40.          if (!traditional) {
  41.              any.a_int = 'a';
  42.              add_menu(tmpwin, NO_GLYPH, &any, menulet++, 0, ATR_NONE,
  43.                       artifact_items, MENU_UNSELECTED);
  44.          }
  45.      }
  46.  
  47.      /* collect classes with discoveries, in packorder ordering; several
  48.         classes are omitted from packorder and one is of interest here */
  49.      Strcpy(allclasses, flags.inv_order);
  50.      if (!index(allclasses, VENOM_CLASS))
  51.          Sprintf(eos(allclasses), "%c", VENOM_CLASS);
  52.      /* construct discosyms[] */
  53.      for (s = allclasses; *s; ++s) {
  54.          oclass = *s;
  55.          c = def_oc_syms[(int) oclass].sym;
  56.          for (i = bases[(int) oclass];
  57.               i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i)
  58.              if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) {
  59.                  if (!index(discosyms, c)) {
  60.                      Sprintf(eos(discosyms), "%c", c);
  61.                      if (!traditional) {
  62.                          any.a_int = c;
  63.                          add_menu(tmpwin, NO_GLYPH, &any, menulet++, c,
  64.                                   ATR_NONE, oclass_to_name(oclass, buf),
  65.                                   MENU_UNSELECTED);
  66.                      }
  67.                  }
  68.              }
  69.      }
  70.  
  71.      /* there might not be anything for us to do... */
  72.      if (!discosyms[0]) {
  73.          You(havent_discovered_any, "items");
  74.          if (tmpwin != WIN_ERR)
  75.              destroy_nhwindow(tmpwin);
  76.          return 0;
  77.      }
  78.  
  79.      /* have player choose a class */
  80.      c = '\0'; /* class not chosen yet */
  81.      if (traditional) {
  82.          /* we'll prompt even if there's only one viable class; we add all
  83.             nonviable classes as unseen acceptable choices so player can ask
  84.             for discoveries of any class whether it has discoveries or not */
  85.          for (s = allclasses, xtras = 0; *s; ++s) {
  86.              c = def_oc_syms[(int) *s].sym;
  87.              if (!index(discosyms, c)) {
  88.                  if (!xtras++)
  89.                      Sprintf(eos(discosyms), "%c", '\033');
  90.                  Sprintf(eos(discosyms), "%c", c);
  91.              }
  92.          }
  93.          /* get the class (via its symbol character) */
  94.          c = yn_function(prompt, discosyms, '\0');
  95.          savech(c);
  96.          if (!c)
  97.              clear_nhwindow(WIN_MESSAGE);
  98.      } else {
  99.          /* menustyle:full or menustyle:partial */
  100.          if (!discosyms[1] && flags.menu_style == MENU_PARTIAL) {
  101.              /* only one class; menustyle:partial normally jumps past class
  102.                 filtering straight to final menu so skip class filter here */
  103.              c = discosyms[0];
  104.          } else {
  105.              /* more than one choice, or menustyle:full which normally has
  106.                 an intermediate class selection menu before the final menu */
  107.              end_menu(tmpwin, prompt);
  108.              i = select_menu(tmpwin, PICK_ONE, &pick_list);
  109.              if (i > 0) {
  110.                  c = pick_list[0].item.a_int;
  111.                  free((genericptr_t) pick_list);
  112.              } /* else c stays 0 */
  113.          }
  114.          destroy_nhwindow(tmpwin);
  115.      }
  116.      if (!c)
  117.          return 0; /* player declined to make a selection */
  118.  
  119.      /*
  120.       * show discoveries for object class c
  121.       */
  122.      tmpwin = create_nhwindow(NHW_MENU);
  123.      ct = 0;
  124.      switch (c) {
  125.      case 'u':
  126.          putstr(tmpwin, iflags.menu_headings,
  127.                 upstart(strcpy(buf, unique_items)));
  128.          for (i = 0; i < SIZE(uniq_objs); i++)
  129.              if (objects[uniq_objs[i]].oc_name_known) {
  130.                  Sprintf(buf, "  %s", OBJ_NAME(objects[uniq_objs[i]]));
  131.                  putstr(tmpwin, 0, buf);
  132.                  ++ct;
  133.              }
  134.          if (!ct)
  135.              You(havent_discovered_any, unique_items);
  136.          break;
  137.      case 'a':
  138.          /* disp_artifact_discoveries() includes a header */
  139.          ct = disp_artifact_discoveries(tmpwin);
  140.          if (!ct)
  141.              You(havent_discovered_any, artifact_items);
  142.          break;
  143.      default:
  144.          oclass = def_char_to_objclass(c);
  145.          Sprintf(buf, "Discovered %s", let_to_name(oclass, FALSE, FALSE));
  146.          putstr(tmpwin, iflags.menu_headings, buf);
  147.          for (i = bases[(int) oclass];
  148.               i < NUM_OBJECTS && objects[i].oc_class == oclass; ++i) {
  149.              if ((dis = disco[i]) != 0 && interesting_to_discover(dis)) {
  150.                  Sprintf(buf, "%s %s",
  151.                          objects[dis].oc_pre_discovered ? "*" : " ",
  152.                          obj_typename(dis));
  153.                  putstr(tmpwin, 0, buf);
  154.                  ++ct;
  155.              }
  156.          }
  157.          if (!ct)
  158.              You(havent_discovered_any, oclass_to_name(oclass, buf));
  159.          break;
  160.      }
  161.      if (ct)
  162.          display_nhwindow(tmpwin, TRUE);
  163.      destroy_nhwindow(tmpwin);
  164.      return 0;
  165.  }
  166.  

rename_disco

  1.  /* put up nameable subset of discoveries list as a menu */
  2.  void
  3.  rename_disco()
  4.  {
  5.      register int i, dis;
  6.      int ct = 0, mn = 0, sl;
  7.      char *s, oclass, prev_class;
  8.      winid tmpwin;
  9.      anything any;
  10.      menu_item *selected = 0;
  11.  
  12.      any = zeroany;
  13.      tmpwin = create_nhwindow(NHW_MENU);
  14.      start_menu(tmpwin);
  15.  
  16.      /*
  17.       * Skip the "unique objects" section (each will appear within its
  18.       * regular class if it is nameable) and the artifacts section.
  19.       * We assume that classes omitted from packorder aren't nameable
  20.       * so we skip venom too.
  21.       */
  22.  
  23.      /* for each class, show discoveries in that class */
  24.      for (s = flags.inv_order; *s; s++) {
  25.          oclass = *s;
  26.          prev_class = oclass + 1; /* forced different from oclass */
  27.          for (i = bases[(int) oclass];
  28.               i < NUM_OBJECTS && objects[i].oc_class == oclass; i++) {
  29.              dis = disco[i];
  30.              if (!dis || !interesting_to_discover(dis))
  31.                  continue;
  32.              ct++;
  33.              if (!objtyp_is_callable(dis))
  34.                  continue;
  35.              mn++;
  36.  
  37.              if (oclass != prev_class) {
  38.                  any.a_int = 0;
  39.                  add_menu(tmpwin, NO_GLYPH, &any, ' ', iflags.menu_headings,
  40.                           ATR_NONE, let_to_name(oclass, FALSE, FALSE),
  41.                           MENU_UNSELECTED);
  42.                  prev_class = oclass;
  43.              }
  44.              any.a_int = dis;
  45.              add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  46.                       obj_typename(dis), MENU_UNSELECTED);
  47.          }
  48.      }
  49.      if (ct == 0) {
  50.          You("haven't discovered anything yet...");
  51.      } else if (mn == 0) {
  52.          pline("None of your discoveries can be assigned names...");
  53.      } else {
  54.          end_menu(tmpwin, "Pick an object type to name");
  55.          dis = STRANGE_OBJECT;
  56.          sl = select_menu(tmpwin, PICK_ONE, &selected);
  57.          if (sl > 0) {
  58.              dis = selected[0].item.a_int;
  59.              free((genericptr_t) selected);
  60.          }
  61.          if (dis != STRANGE_OBJECT) {
  62.              struct obj odummy;
  63.  
  64.              odummy = zeroobj;
  65.              odummy.otyp = dis;
  66.              odummy.oclass = objects[dis].oc_class;
  67.              odummy.quan = 1L;
  68.              odummy.known = !objects[dis].oc_uses_known;
  69.              odummy.dknown = 1;
  70.              docall(&odummy);
  71.          }
  72.      }
  73.      destroy_nhwindow(tmpwin);
  74.      return;
  75.  }
  76.  
  77.  /*o_init.c*/