Source:NetHack 3.6.0/src/botl.c

From NetHackWiki
(Redirected from Source:NetHack 3.6.0/botl.c)
Jump to: navigation, search

Below is the full text to botl.c from the source code of NetHack 3.6.0. To link to a particular line, write [[Source:NetHack 3.6.0/src/botl.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	botl.c	$NHDT-Date: 1447978683 2015/11/20 00:18:03 $  $NHDT-Branch: master $:$NHDT-Revision: 1.69 $ */
  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 <limits.h>
  7.  
  8.  extern const char *hu_stat[]; /* defined in eat.c */
  9.  
  10.  const char *const enc_stat[] = { "",         "Burdened",  "Stressed",
  11.                                   "Strained", "Overtaxed", "Overloaded" };
  12.  
  13.  STATIC_OVL NEARDATA int mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */
  14.  STATIC_DCL const char *NDECL(rank);
  15.  

Status not via windowport

  1.  #ifndef STATUS_VIA_WINDOWPORT
  2.  
  3.  STATIC_DCL void NDECL(bot1);
  4.  STATIC_DCL void NDECL(bot2);
  5.  

bot1

  1.  STATIC_OVL void
  2.  bot1()
  3.  {
  4.      char newbot1[MAXCO];
  5.      register char *nb;
  6.      register int i, j;
  7.  
  8.      Strcpy(newbot1, plname);
  9.      if ('a' <= newbot1[0] && newbot1[0] <= 'z')
  10.          newbot1[0] += 'A' - 'a';
  11.      newbot1[10] = 0;
  12.      Sprintf(nb = eos(newbot1), " the ");
  13.  
  14.      if (Upolyd) {
  15.          char mbot[BUFSZ];
  16.          int k = 0;
  17.  
  18.          Strcpy(mbot, mons[u.umonnum].mname);
  19.          while (mbot[k] != 0) {
  20.              if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
  21.                  && mbot[k] <= 'z')
  22.                  mbot[k] += 'A' - 'a';
  23.              k++;
  24.          }
  25.          Strcpy(nb = eos(nb), mbot);
  26.      } else
  27.          Strcpy(nb = eos(nb), rank());
  28.  
  29.      Sprintf(nb = eos(nb), "  ");
  30.      i = mrank_sz + 15;
  31.      j = (int) ((nb + 2) - newbot1); /* strlen(newbot1) but less computation */
  32.      if ((i - j) > 0)
  33.          Sprintf(nb = eos(nb), "%*s", i - j, " "); /* pad with spaces */
  34.      if (ACURR(A_STR) > 18) {
  35.          if (ACURR(A_STR) > STR18(100))
  36.              Sprintf(nb = eos(nb), "St:%2d ", ACURR(A_STR) - 100);
  37.          else if (ACURR(A_STR) < STR18(100))
  38.              Sprintf(nb = eos(nb), "St:18/%02d ", ACURR(A_STR) - 18);
  39.          else
  40.              Sprintf(nb = eos(nb), "St:18/** ");
  41.      } else
  42.          Sprintf(nb = eos(nb), "St:%-1d ", ACURR(A_STR));
  43.      Sprintf(nb = eos(nb), "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d",
  44.              ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS),
  45.              ACURR(A_CHA));
  46.      Sprintf(nb = eos(nb),
  47.              (u.ualign.type == A_CHAOTIC)
  48.                  ? "  Chaotic"
  49.                  : (u.ualign.type == A_NEUTRAL) ? "  Neutral" : "  Lawful");
  50.  #ifdef SCORE_ON_BOTL
  51.      if (flags.showscore)
  52.          Sprintf(nb = eos(nb), " S:%ld", botl_score());
  53.  #endif
  54.      curs(WIN_STATUS, 1, 0);
  55.      putstr(WIN_STATUS, 0, newbot1);
  56.  }
  57.  

bot2

  1.  STATIC_OVL void
  2.  bot2()
  3.  {
  4.      char newbot2[MAXCO];
  5.      register char *nb;
  6.      int hp, hpmax;
  7.      int cap = near_capacity();
  8.  
  9.      hp = Upolyd ? u.mh : u.uhp;
  10.      hpmax = Upolyd ? u.mhmax : u.uhpmax;
  11.  
  12.      if (hp < 0)
  13.          hp = 0;
  14.      (void) describe_level(newbot2);
  15.      Sprintf(nb = eos(newbot2), "%s:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d",
  16.              encglyph(objnum_to_glyph(GOLD_PIECE)), money_cnt(invent), hp,
  17.              hpmax, u.uen, u.uenmax, u.uac);
  18.  
  19.      if (Upolyd)
  20.          Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel);
  21.      else if (flags.showexp)
  22.          Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel, u.uexp);
  23.      else
  24.          Sprintf(nb = eos(nb), " Exp:%u", u.ulevel);
  25.  
  26.      if (flags.time)
  27.          Sprintf(nb = eos(nb), " T:%ld", moves);
  28.      if (strcmp(hu_stat[u.uhs], "        ")) {
  29.          Sprintf(nb = eos(nb), " ");
  30.          Strcat(newbot2, hu_stat[u.uhs]);
  31.      }
  32.      if (Confusion)
  33.          Sprintf(nb = eos(nb), " Conf");
  34.      if (Sick) {
  35.          if (u.usick_type & SICK_VOMITABLE)
  36.              Sprintf(nb = eos(nb), " FoodPois");
  37.          if (u.usick_type & SICK_NONVOMITABLE)
  38.              Sprintf(nb = eos(nb), " Ill");
  39.      }
  40.      if (Blind)
  41.          Sprintf(nb = eos(nb), " Blind");
  42.      if (Stunned)
  43.          Sprintf(nb = eos(nb), " Stun");
  44.      if (Hallucination)
  45.          Sprintf(nb = eos(nb), " Hallu");
  46.      if (Slimed)
  47.          Sprintf(nb = eos(nb), " Slime");
  48.      if (cap > UNENCUMBERED)
  49.          Sprintf(nb = eos(nb), " %s", enc_stat[cap]);
  50.      curs(WIN_STATUS, 1, 1);
  51.      putmixed(WIN_STATUS, 0, newbot2);
  52.  }
  53.  

bot

  1.  void
  2.  bot()
  3.  {
  4.      if (youmonst.data) {
  5.          bot1();
  6.          bot2();
  7.      }
  8.      context.botl = context.botlx = 0;
  9.  }
  10.  
  11.  #endif /* !STATUS_VIA_WINDOWPORT */
  12.  

Status via all outputs

xlev_to_rank

  1.  /* convert experience level (1..30) to rank index (0..8) */
  2.  int
  3.  xlev_to_rank(xlev)
  4.  int xlev;
  5.  {
  6.      return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8;
  7.  }
  8.  

rank_to_xlev

  1.  #if 0 /* not currently needed */
  2.  /* convert rank index (0..8) to experience level (1..30) */
  3.  int
  4.  rank_to_xlev(rank)
  5.  int rank;
  6.  {
  7.      return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30;
  8.  }
  9.  #endif
  10.  

rank_of

  1.  const char *
  2.  rank_of(lev, monnum, female)
  3.  int lev;
  4.  short monnum;
  5.  boolean female;
  6.  {
  7.      register const struct Role *role;
  8.      register int i;
  9.  
  10.      /* Find the role */
  11.      for (role = roles; role->name.m; role++)
  12.          if (monnum == role->malenum || monnum == role->femalenum)
  13.              break;
  14.      if (!role->name.m)
  15.          role = &urole;
  16.  
  17.      /* Find the rank */
  18.      for (i = xlev_to_rank((int) lev); i >= 0; i--) {
  19.          if (female && role->rank[i].f)
  20.              return role->rank[i].f;
  21.          if (role->rank[i].m)
  22.              return role->rank[i].m;
  23.      }
  24.  
  25.      /* Try the role name, instead */
  26.      if (female && role->name.f)
  27.          return role->name.f;
  28.      else if (role->name.m)
  29.          return role->name.m;
  30.      return "Player";
  31.  }
  32.  

rank

  1.  STATIC_OVL const char *
  2.  rank()
  3.  {
  4.      return rank_of(u.ulevel, Role_switch, flags.female);
  5.  }
  6.  

title_to_mon

  1.  int
  2.  title_to_mon(str, rank_indx, title_length)
  3.  const char *str;
  4.  int *rank_indx, *title_length;
  5.  {
  6.      register int i, j;
  7.  
  8.      /* Loop through each of the roles */
  9.      for (i = 0; roles[i].name.m; i++)
  10.          for (j = 0; j < 9; j++) {
  11.              if (roles[i].rank[j].m
  12.                  && !strncmpi(str, roles[i].rank[j].m,
  13.                               strlen(roles[i].rank[j].m))) {
  14.                  if (rank_indx)
  15.                      *rank_indx = j;
  16.                  if (title_length)
  17.                      *title_length = strlen(roles[i].rank[j].m);
  18.                  return roles[i].malenum;
  19.              }
  20.              if (roles[i].rank[j].f
  21.                  && !strncmpi(str, roles[i].rank[j].f,
  22.                               strlen(roles[i].rank[j].f))) {
  23.                  if (rank_indx)
  24.                      *rank_indx = j;
  25.                  if (title_length)
  26.                      *title_length = strlen(roles[i].rank[j].f);
  27.                  return (roles[i].femalenum != NON_PM) ? roles[i].femalenum
  28.                                                        : roles[i].malenum;
  29.              }
  30.          }
  31.      return NON_PM;
  32.  }
  33.  

max_rank_sz

  1.  void
  2.  max_rank_sz()
  3.  {
  4.      register int i, r, maxr = 0;
  5.      for (i = 0; i < 9; i++) {
  6.          if (urole.rank[i].m && (r = strlen(urole.rank[i].m)) > maxr)
  7.              maxr = r;
  8.          if (urole.rank[i].f && (r = strlen(urole.rank[i].f)) > maxr)
  9.              maxr = r;
  10.      }
  11.      mrank_sz = maxr;
  12.      return;
  13.  }
  14.  

botl_score

  1.  #ifdef SCORE_ON_BOTL
  2.  long
  3.  botl_score()
  4.  {
  5.      long deepest = deepest_lev_reached(FALSE);
  6.      long utotal;
  7.  
  8.      utotal = money_cnt(invent) + hidden_gold();
  9.      if ((utotal -= u.umoney0) < 0L)
  10.          utotal = 0L;
  11.      utotal += u.urexp + (50 * (deepest - 1))
  12.            + (deepest > 30 ? 10000 : deepest > 20 ? 1000 * (deepest - 20) : 0);
  13.      if (utotal < u.urexp)
  14.          utotal = LONG_MAX; /* wrap around */
  15.      return utotal;
  16.  }
  17.  #endif /* SCORE_ON_BOTL */
  18.  

describe_level

  1.  /* provide the name of the current level for display by various ports */
  2.  int
  3.  describe_level(buf)
  4.  char *buf;
  5.  {
  6.      int ret = 1;
  7.  
  8.      /* TODO:    Add in dungeon name */
  9.      if (Is_knox(&u.uz))
  10.          Sprintf(buf, "%s ", dungeons[u.uz.dnum].dname);
  11.      else if (In_quest(&u.uz))
  12.          Sprintf(buf, "Home %d ", dunlev(&u.uz));
  13.      else if (In_endgame(&u.uz))
  14.          Sprintf(buf, Is_astralevel(&u.uz) ? "Astral Plane " : "End Game ");
  15.      else {
  16.          /* ports with more room may expand this one */
  17.          Sprintf(buf, "Dlvl:%-2d ", depth(&u.uz));
  18.          ret = 0;
  19.      }
  20.      return ret;
  21.  }
  22.  

Status via windowport

  1.  #ifdef STATUS_VIA_WINDOWPORT
  2.  /* =======================================================================*/
  3.  
  4.  /* structure that tracks the status details in the core */
  5.  struct istat_s {
  6.      long time;
  7.      unsigned anytype;
  8.      anything a;
  9.      char *val;
  10.      int valwidth;
  11.      enum statusfields idxmax;
  12.      enum statusfields fld;
  13.  };
  14.  
  15.  
  16.  STATIC_DCL void NDECL(init_blstats);
  17.  STATIC_DCL char *FDECL(anything_to_s, (char *, anything *, int));
  18.  STATIC_DCL void FDECL(s_to_anything, (anything *, char *, int));
  19.  STATIC_OVL int FDECL(percentage, (struct istat_s *, struct istat_s *));
  20.  STATIC_OVL int FDECL(compare_blstats, (struct istat_s *, struct istat_s *));
  21.  
  22.  #ifdef STATUS_HILITES
  23.  STATIC_DCL boolean FDECL(assign_hilite, (char *, char *, char *, char *,
  24.                                           BOOLEAN_P));
  25.  STATIC_DCL const char *FDECL(clridx_to_s, (char *, int));
  26.  #endif
  27.  
  28.  /* If entries are added to this, botl.h will require updating too */
  29.  STATIC_DCL struct istat_s initblstats[MAXBLSTATS] = {
  30.      { 0L, ANY_STR,  { (genericptr_t) 0 }, (char *) 0, 80,  0, BL_TITLE},
  31.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_STR},
  32.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_DX},
  33.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_CO},
  34.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_IN},
  35.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_WI},
  36.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_CH},
  37.      { 0L, ANY_STR,  { (genericptr_t) 0 }, (char *) 0, 40,  0, BL_ALIGN},
  38.      { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20,  0, BL_SCORE},
  39.      { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20,  0, BL_CAP},
  40.      { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 30,  0, BL_GOLD},
  41.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  BL_ENEMAX, BL_ENE},
  42.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_ENEMAX},
  43.      { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_XP},
  44.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_AC},
  45.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_HD},
  46.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 20,  0, BL_TIME},
  47.      { 0L, ANY_UINT, { (genericptr_t) 0 }, (char *) 0, 40,  0, BL_HUNGER},
  48.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  BL_HPMAX, BL_HP},
  49.      { 0L, ANY_INT,  { (genericptr_t) 0 }, (char *) 0, 10,  0, BL_HPMAX},
  50.      { 0L, ANY_STR,  { (genericptr_t) 0 }, (char *) 0, 80,  0, BL_LEVELDESC},
  51.      { 0L, ANY_LONG, { (genericptr_t) 0 }, (char *) 0, 20,  0, BL_EXP},
  52.      { 0L, ANY_MASK32,
  53.                      { (genericptr_t) 0 }, (char *) 0,  0,  0, BL_CONDITION}
  54.  };
  55.  
  56.  static struct fieldid_t {
  57.          const char *fieldname;
  58.          enum statusfields fldid;
  59.  } fieldids[] = {
  60.          {"title",               BL_TITLE},
  61.          {"strength",            BL_STR},
  62.          {"dexterity",           BL_DX},
  63.          {"constitution",        BL_CO},
  64.          {"intelligence",        BL_IN},
  65.          {"wisdom",              BL_WI},
  66.          {"charisma",            BL_CH},
  67.          {"alignment",           BL_ALIGN},
  68.          {"score",               BL_SCORE},
  69.          {"carrying-capacity",   BL_CAP},
  70.          {"gold",                BL_GOLD},
  71.          {"power",               BL_ENE},
  72.          {"power-max",           BL_ENEMAX},
  73.          {"experience-level",    BL_XP},
  74.          {"armor-class",         BL_AC},
  75.          {"HD",                  BL_HD},
  76.          {"time",                BL_TIME},
  77.          {"hunger",              BL_HUNGER},
  78.          {"hitpoints",           BL_HP},
  79.          {"hitpoints-max",       BL_HPMAX},
  80.          {"dungeon-level",       BL_LEVELDESC},
  81.          {"experience",          BL_EXP},
  82.          {"condition",           BL_CONDITION},
  83.  };
  84.  
  85.  struct istat_s blstats[2][MAXBLSTATS];
  86.  static boolean blinit = FALSE, update_all = FALSE;
  87.  

bot

  1.  void
  2.  bot()
  3.  {
  4.      char buf[BUFSZ];
  5.      register char *nb;
  6.      static int idx = 0, idx_p, idxmax;
  7.      boolean updated = FALSE;
  8.      unsigned anytype;
  9.      int i, pc, chg, cap;
  10.      struct istat_s *curr, *prev;
  11.      boolean valset[MAXBLSTATS], chgval = FALSE;
  12.  
  13.      if (!blinit)
  14.          panic("bot before init.");
  15.      if (!youmonst.data) {
  16.          context.botl = context.botlx = 0;
  17.          update_all = FALSE;
  18.          return;
  19.      }
  20.  
  21.      cap = near_capacity();
  22.      idx_p = idx;
  23.      idx = 1 - idx; /* 0 -> 1, 1 -> 0 */
  24.  
  25.      /* clear the "value set" indicators */
  26.      (void) memset((genericptr_t) valset, 0, MAXBLSTATS * sizeof(boolean));
  27.  
  28.      /*
  29.       *  Player name and title.
  30.       */
  31.      buf[0] = '\0';
  32.      Strcpy(buf, plname);
  33.      if ('a' <= buf[0] && buf[0] <= 'z')
  34.          buf[0] += 'A' - 'a';
  35.      buf[10] = 0;
  36.      Sprintf(nb = eos(buf), " the ");
  37.      if (Upolyd) {
  38.          char mbot[BUFSZ];
  39.          int k = 0;
  40.  
  41.          Strcpy(mbot, mons[u.umonnum].mname);
  42.          while (mbot[k] != 0) {
  43.              if ((k == 0 || (k > 0 && mbot[k - 1] == ' ')) && 'a' <= mbot[k]
  44.                  && mbot[k] <= 'z')
  45.                  mbot[k] += 'A' - 'a';
  46.              k++;
  47.          }
  48.          Sprintf1(nb = eos(nb), mbot);
  49.      } else
  50.          Sprintf1(nb = eos(nb), rank());
  51.      Sprintf(blstats[idx][BL_TITLE].val, "%-29s", buf);
  52.      valset[BL_TITLE] = TRUE; /* indicate val already set */
  53.  
  54.      /* Strength */
  55.  
  56.      buf[0] = '\0';
  57.      blstats[idx][BL_STR].a.a_int = ACURR(A_STR);
  58.      if (ACURR(A_STR) > 18) {
  59.          if (ACURR(A_STR) > STR18(100))
  60.              Sprintf(buf, "%2d", ACURR(A_STR) - 100);
  61.          else if (ACURR(A_STR) < STR18(100))
  62.              Sprintf(buf, "18/%02d", ACURR(A_STR) - 18);
  63.          else
  64.              Sprintf(buf, "18/**");
  65.      } else
  66.          Sprintf(buf, "%-1d", ACURR(A_STR));
  67.      Strcpy(blstats[idx][BL_STR].val, buf);
  68.      valset[BL_STR] = TRUE; /* indicate val already set */
  69.  
  70.      /*  Dexterity, constitution, intelligence, wisdom, charisma. */
  71.  
  72.      blstats[idx][BL_DX].a.a_int = ACURR(A_DEX);
  73.      blstats[idx][BL_CO].a.a_int = ACURR(A_CON);
  74.      blstats[idx][BL_IN].a.a_int = ACURR(A_INT);
  75.      blstats[idx][BL_WI].a.a_int = ACURR(A_WIS);
  76.      blstats[idx][BL_CH].a.a_int = ACURR(A_CHA);
  77.  
  78.      /* Alignment */
  79.  
  80.      Strcpy(blstats[idx][BL_ALIGN].val,
  81.             (u.ualign.type == A_CHAOTIC)
  82.                 ? "Chaotic"
  83.                 : (u.ualign.type == A_NEUTRAL) ? "Neutral" : "Lawful");
  84.  
  85.      /* Score */
  86.  
  87.      blstats[idx][BL_SCORE].a.a_long =
  88.  #ifdef SCORE_ON_BOTL
  89.          botl_score();
  90.  #else
  91.          0;
  92.  #endif
  93.      /*  Hit points  */
  94.  
  95.      blstats[idx][BL_HP].a.a_int = Upolyd ? u.mh : u.uhp;
  96.      blstats[idx][BL_HPMAX].a.a_int = Upolyd ? u.mhmax : u.uhpmax;
  97.      if (blstats[idx][BL_HP].a.a_int < 0)
  98.          blstats[idx][BL_HP].a.a_int = 0;
  99.  
  100.      /*  Dungeon level. */
  101.  
  102.      (void) describe_level(blstats[idx][BL_LEVELDESC].val);
  103.      valset[BL_LEVELDESC] = TRUE; /* indicate val already set */
  104.  
  105.      /* Gold */
  106.  
  107.      blstats[idx][BL_GOLD].a.a_long = money_cnt(invent);
  108.      /*
  109.       * The tty port needs to display the current symbol for gold
  110.       * as a field header, so to accommodate that we pass gold with
  111.       * that already included. If a window port needs to use the text
  112.       * gold amount without the leading "$:" the port will have to
  113.       * add 2 to the value pointer it was passed in status_update()
  114.       * for the BL_GOLD case.
  115.       *
  116.       * Another quirk of BL_GOLD is that the field display may have
  117.       * changed if a new symbol set was loaded, or we entered or left
  118.       * the rogue level.
  119.       */
  120.  
  121.      Sprintf(blstats[idx][BL_GOLD].val, "%s:%ld",
  122.              encglyph(objnum_to_glyph(GOLD_PIECE)),
  123.              blstats[idx][BL_GOLD].a.a_long);
  124.      valset[BL_GOLD] = TRUE; /* indicate val already set */
  125.  
  126.      /* Power (magical energy) */
  127.  
  128.      blstats[idx][BL_ENE].a.a_int = u.uen;
  129.      blstats[idx][BL_ENEMAX].a.a_int = u.uenmax;
  130.  
  131.      /* Armor class */
  132.  
  133.      blstats[idx][BL_AC].a.a_int = u.uac;
  134.  
  135.      /* Monster level (if Upolyd) */
  136.  
  137.      if (Upolyd)
  138.          blstats[idx][BL_HD].a.a_int = mons[u.umonnum].mlevel;
  139.      else
  140.          blstats[idx][BL_HD].a.a_int = 0;
  141.  
  142.      /* Experience */
  143.  
  144.      blstats[idx][BL_XP].a.a_int = u.ulevel;
  145.      blstats[idx][BL_EXP].a.a_int = u.uexp;
  146.  
  147.      /* Time (moves) */
  148.  
  149.      blstats[idx][BL_TIME].a.a_long = moves;
  150.  
  151.      /* Hunger */
  152.  
  153.      blstats[idx][BL_HUNGER].a.a_uint = u.uhs;
  154.      *(blstats[idx][BL_HUNGER].val) = '\0';
  155.      if (strcmp(hu_stat[u.uhs], "        ") != 0)
  156.          Strcpy(blstats[idx][BL_HUNGER].val, hu_stat[u.uhs]);
  157.      valset[BL_HUNGER] = TRUE;
  158.  
  159.      /* Carrying capacity */
  160.  
  161.      *(blstats[idx][BL_CAP].val) = '\0';
  162.      blstats[idx][BL_CAP].a.a_int = cap;
  163.      if (cap > UNENCUMBERED)
  164.          Strcpy(blstats[idx][BL_CAP].val, enc_stat[cap]);
  165.      valset[BL_CAP] = TRUE;
  166.  
  167.      /* Conditions */
  168.  
  169.      if (Blind)
  170.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_BLIND;
  171.      else
  172.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_BLIND;
  173.  
  174.      if (Confusion)
  175.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_CONF;
  176.      else
  177.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_CONF;
  178.  
  179.      if (Sick && u.usick_type & SICK_VOMITABLE)
  180.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_FOODPOIS;
  181.      else
  182.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_FOODPOIS;
  183.  
  184.      if (Sick && u.usick_type & SICK_NONVOMITABLE)
  185.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_ILL;
  186.      else
  187.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_ILL;
  188.  
  189.      if (Hallucination)
  190.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_HALLU;
  191.      else
  192.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_HALLU;
  193.  
  194.      if (Stunned)
  195.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_STUNNED;
  196.      else
  197.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_STUNNED;
  198.  
  199.      if (Slimed)
  200.          blstats[idx][BL_CONDITION].a.a_ulong |= BL_MASK_SLIMED;
  201.      else
  202.          blstats[idx][BL_CONDITION].a.a_ulong &= ~BL_MASK_SLIMED;
  203.  
  204.      /*
  205.       *  Now pass the changed values to window port.
  206.       */
  207.      for (i = 0; i < MAXBLSTATS; i++) {
  208.          if (((i == BL_SCORE) && !flags.showscore)
  209.              || ((i == BL_EXP) && !flags.showexp)
  210.              || ((i == BL_TIME) && !flags.time)
  211.              || ((i == BL_HD) && !Upolyd)
  212.              || ((i == BL_XP || i == BL_EXP) && Upolyd))
  213.              continue;
  214.          anytype = blstats[idx][i].anytype;
  215.          curr = &blstats[idx][i];
  216.          prev = &blstats[idx_p][i];
  217.          chg = 0;
  218.          if (update_all || ((chg = compare_blstats(prev, curr)) != 0)
  219.              || ((chgval = (valset[i] && strcmp(blstats[idx][i].val,
  220.                                                 blstats[idx_p][i].val)))
  221.                  != 0)) {
  222.              idxmax = blstats[idx][i].idxmax;
  223.              pc = (idxmax) ? percentage(curr, &blstats[idx][idxmax]) : 0;
  224.              if (!valset[i])
  225.                  (void) anything_to_s(curr->val, &curr->a, anytype);
  226.              if (anytype != ANY_MASK32) {
  227.                  status_update(i, (genericptr_t) curr->val,
  228.                                valset[i] ? chgval : chg, pc);
  229.              } else {
  230.                  status_update(i,
  231.                                /* send pointer to mask */
  232.                                (genericptr_t) &curr->a.a_ulong, chg, 0);
  233.              }
  234.              updated = TRUE;
  235.          }
  236.      }
  237.      /*
  238.       * It is possible to get here, with nothing having been pushed
  239.       * to the window port, when none of the info has changed. In that
  240.       * case, we need to force a call to status_update() when
  241.       * context.botlx is set. The tty port in particular has a problem
  242.       * if that isn't done, since it sets context.botlx when a menu or
  243.       * text display obliterates the status line.
  244.       *
  245.       * To work around it, we call status_update() with fictitious
  246.       * index of BL_FLUSH (-1).
  247.       */
  248.      if (context.botlx && !updated)
  249.          status_update(BL_FLUSH, (genericptr_t) 0, 0, 0);
  250.  
  251.      context.botl = context.botlx = 0;
  252.      update_all = FALSE;
  253.  }
  254.  

status_initialize

  1.  void
  2.  status_initialize(reassessment)
  3.  boolean
  4.      reassessment; /* TRUE = just reassess fields w/o other initialization*/
  5.  {
  6.      int i;
  7.      const char *fieldfmt = (const char *)0;
  8.      const char *fieldname = (const char *)0;
  9.  
  10.      if (!reassessment) {
  11.          init_blstats();
  12.          (*windowprocs.win_status_init)();
  13.          blinit = TRUE;
  14.  #ifdef STATUS_HILITES
  15.          status_notify_windowport(TRUE);
  16.  #endif
  17.      }
  18.      for (i = 0; i < MAXBLSTATS; ++i) {
  19.          enum statusfields fld = initblstats[i].fld;
  20.  
  21.          switch (fld) {
  22.          case BL_TITLE:
  23.              fieldfmt = "%s";
  24.              fieldname = "title";
  25.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  26.              break;
  27.          case BL_STR:
  28.              fieldfmt = " St:%s";
  29.              fieldname = "strength";
  30.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  31.              break;
  32.          case BL_DX:
  33.              fieldfmt = " Dx:%s";
  34.              fieldname = "dexterity";
  35.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  36.              break;
  37.          case BL_CO:
  38.              fieldfmt = " Co:%s";
  39.              fieldname = "constitution";
  40.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  41.              break;
  42.          case BL_IN:
  43.              fieldfmt = " In:%s";
  44.              fieldname = "intelligence";
  45.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  46.              break;
  47.          case BL_WI:
  48.              fieldfmt = " Wi:%s";
  49.              fieldname = "wisdom";
  50.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  51.              break;
  52.          case BL_CH:
  53.              fieldfmt = " Ch:%s";
  54.              fieldname = "charisma";
  55.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  56.              break;
  57.          case BL_ALIGN:
  58.              fieldfmt = " %s";
  59.              fieldname = "alignment";
  60.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  61.              break;
  62.          case BL_SCORE:
  63.              fieldfmt = " S:%s";
  64.              fieldname = "score";
  65.              status_enablefield(fld, fieldname, fieldfmt,
  66.                                 (!flags.showscore) ? FALSE : TRUE);
  67.              break;
  68.          case BL_CAP:
  69.              fieldfmt = " %s";
  70.              fieldname = "carrying-capacity";
  71.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  72.              break;
  73.          case BL_GOLD:
  74.              fieldfmt = " %s";
  75.              fieldname = "gold";
  76.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  77.              break;
  78.          case BL_ENE:
  79.              fieldfmt = " Pw:%s";
  80.              fieldname = "power";
  81.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  82.              break;
  83.          case BL_ENEMAX:
  84.              fieldfmt = "(%s)";
  85.              fieldname = "power-max";
  86.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  87.              break;
  88.          case BL_XP:
  89.              fieldfmt = " Xp:%s";
  90.              fieldname = "experience-level";
  91.              status_enablefield(fld, fieldname, fieldfmt,
  92.                                     (Upolyd) ? FALSE : TRUE);
  93.              break;
  94.          case BL_AC:
  95.              fieldfmt = " AC:%s";
  96.              fieldname = "armor-class";
  97.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  98.              break;
  99.          case BL_HD:
  100.              fieldfmt = " HD:%s";
  101.              fieldname = "HD";
  102.              status_enablefield(fld, fieldname, fieldfmt,
  103.                                     (!Upolyd) ? FALSE : TRUE);
  104.              break;
  105.          case BL_TIME:
  106.              fieldfmt = " T:%s";
  107.              fieldname = "time";
  108.              status_enablefield(fld, fieldname, fieldfmt,
  109.                                     (!flags.time) ? FALSE : TRUE);
  110.              break;
  111.          case BL_HUNGER:
  112.              fieldfmt = " %s";
  113.              fieldname = "hunger";
  114.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  115.              break;
  116.          case BL_HP:
  117.              fieldfmt = " HP:%s";
  118.              fieldname = "hitpoints";
  119.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  120.              break;
  121.          case BL_HPMAX:
  122.              fieldfmt = "(%s)";
  123.              fieldname = "hitpoint-max";
  124.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  125.              break;
  126.          case BL_LEVELDESC:
  127.              fieldfmt = "%s";
  128.              fieldname = "dungeon-level";
  129.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  130.              break;
  131.          case BL_EXP:
  132.              fieldfmt = "/%s";
  133.              fieldname = "experience";
  134.              status_enablefield(fld, fieldname, fieldfmt,
  135.                                    (!flags.showexp || Upolyd) ? FALSE : TRUE);
  136.              break;
  137.          case BL_CONDITION:
  138.              fieldfmt = "%S";
  139.              fieldname = "condition";
  140.              status_enablefield(fld, fieldname, fieldfmt, TRUE);
  141.              break;
  142.          case BL_FLUSH:
  143.          default:
  144.              break;
  145.          }
  146.      }
  147.      update_all = TRUE;
  148.  }
  149.  

status_finish

  1.  void
  2.  status_finish()
  3.  {
  4.      int i;
  5.  
  6.      /* call the window port cleanup routine first */
  7.      (*windowprocs.win_status_finish)();
  8.  
  9.      /* free memory that we alloc'd now */
  10.      for (i = 0; i < MAXBLSTATS; ++i) {
  11.          if (blstats[0][i].val)
  12.              free((genericptr_t) blstats[0][i].val);
  13.          if (blstats[1][i].val)
  14.              free((genericptr_t) blstats[1][i].val);
  15.      }
  16.  }
  17.  

init_blstats

  1.  STATIC_OVL void
  2.  init_blstats()
  3.  {
  4.      static boolean initalready = FALSE;
  5.      int i, j;
  6.  
  7.      if (initalready) {
  8.          impossible("init_blstats called more than once.");
  9.          return;
  10.      }
  11.  
  12.      initalready = TRUE;
  13.      for (i = BEFORE; i <= NOW; ++i) {
  14.          for (j = 0; j < MAXBLSTATS; ++j) {
  15.              blstats[i][j] = initblstats[j];
  16.              blstats[i][j].a = zeroany;
  17.              if (blstats[i][j].valwidth) {
  18.                  blstats[i][j].val = (char *) alloc(blstats[i][j].valwidth);
  19.                  blstats[i][j].val[0] = '\0';
  20.              } else
  21.                  blstats[i][j].val = (char *) 0;
  22.          }
  23.      }
  24.  }
  25.  

anything_to_s

  1.  STATIC_OVL char *
  2.  anything_to_s(buf, a, anytype)
  3.  char *buf;
  4.  anything *a;
  5.  int anytype;
  6.  {
  7.      if (!buf)
  8.          return (char *) 0;
  9.  
  10.      switch (anytype) {
  11.      case ANY_ULONG:
  12.          Sprintf(buf, "%lu", a->a_ulong);
  13.          break;
  14.      case ANY_MASK32:
  15.          Sprintf(buf, "%lx", a->a_ulong);
  16.          break;
  17.      case ANY_LONG:
  18.          Sprintf(buf, "%ld", a->a_long);
  19.          break;
  20.      case ANY_INT:
  21.          Sprintf(buf, "%d", a->a_int);
  22.          break;
  23.      case ANY_UINT:
  24.          Sprintf(buf, "%u", a->a_uint);
  25.          break;
  26.      case ANY_IPTR:
  27.          Sprintf(buf, "%d", *a->a_iptr);
  28.          break;
  29.      case ANY_LPTR:
  30.          Sprintf(buf, "%ld", *a->a_lptr);
  31.          break;
  32.      case ANY_ULPTR:
  33.          Sprintf(buf, "%lu", *a->a_ulptr);
  34.          break;
  35.      case ANY_UPTR:
  36.          Sprintf(buf, "%u", *a->a_uptr);
  37.          break;
  38.      case ANY_STR: /* do nothing */
  39.          ;
  40.          break;
  41.      default:
  42.          buf[0] = '\0';
  43.      }
  44.      return buf;
  45.  }
  46.  

s_to_anything

  1.  STATIC_OVL void
  2.  s_to_anything(a, buf, anytype)
  3.  anything *a;
  4.  char *buf;
  5.  int anytype;
  6.  {
  7.      if (!buf || !a)
  8.          return;
  9.  
  10.      switch (anytype) {
  11.      case ANY_LONG:
  12.          a->a_long = atol(buf);
  13.          break;
  14.      case ANY_INT:
  15.          a->a_int = atoi(buf);
  16.          break;
  17.      case ANY_UINT:
  18.          a->a_uint = (unsigned) atoi(buf);
  19.          break;
  20.      case ANY_ULONG:
  21.          a->a_ulong = (unsigned long) atol(buf);
  22.          break;
  23.      case ANY_IPTR:
  24.          if (a->a_iptr)
  25.              *a->a_iptr = atoi(buf);
  26.          break;
  27.      case ANY_UPTR:
  28.          if (a->a_uptr)
  29.              *a->a_uptr = (unsigned) atoi(buf);
  30.          break;
  31.      case ANY_LPTR:
  32.          if (a->a_lptr)
  33.              *a->a_lptr = atol(buf);
  34.          break;
  35.      case ANY_ULPTR:
  36.          if (a->a_ulptr)
  37.              *a->a_ulptr = (unsigned long) atol(buf);
  38.          break;
  39.      case ANY_MASK32:
  40.          a->a_ulong = (unsigned long) atol(buf);
  41.          break;
  42.      default:
  43.          a->a_void = 0;
  44.          break;
  45.      }
  46.      return;
  47.  }
  48.  

compare_blstats

  1.  STATIC_OVL int
  2.  compare_blstats(bl1, bl2)
  3.  struct istat_s *bl1, *bl2;
  4.  {
  5.      int anytype, result = 0;
  6.  
  7.      if (!bl1 || !bl2) {
  8.          panic("compare_blstat: bad istat pointer %s, %s",
  9.                fmt_ptr((genericptr_t) bl1), fmt_ptr((genericptr_t) bl2));
  10.      }
  11.  
  12.      anytype = bl1->anytype;
  13.      if ((!bl1->a.a_void || !bl2->a.a_void)
  14.          && (anytype == ANY_IPTR || anytype == ANY_UPTR || anytype == ANY_LPTR
  15.              || anytype == ANY_ULPTR)) {
  16.          panic("compare_blstat: invalid pointer %s, %s",
  17.                fmt_ptr((genericptr_t) bl1->a.a_void),
  18.                fmt_ptr((genericptr_t) bl2->a.a_void));
  19.      }
  20.  
  21.      switch (anytype) {
  22.      case ANY_INT:
  23.          result = (bl1->a.a_int < bl2->a.a_int)
  24.                       ? 1
  25.                       : (bl1->a.a_int > bl2->a.a_int) ? -1 : 0;
  26.          break;
  27.      case ANY_IPTR:
  28.          result = (*bl1->a.a_iptr < *bl2->a.a_iptr)
  29.                       ? 1
  30.                       : (*bl1->a.a_iptr > *bl2->a.a_iptr) ? -1 : 0;
  31.          break;
  32.      case ANY_LONG:
  33.          result = (bl1->a.a_long < bl2->a.a_long)
  34.                       ? 1
  35.                       : (bl1->a.a_long > bl2->a.a_long) ? -1 : 0;
  36.          break;
  37.      case ANY_LPTR:
  38.          result = (*bl1->a.a_lptr < *bl2->a.a_lptr)
  39.                       ? 1
  40.                       : (*bl1->a.a_lptr > *bl2->a.a_lptr) ? -1 : 0;
  41.          break;
  42.      case ANY_UINT:
  43.          result = (bl1->a.a_uint < bl2->a.a_uint)
  44.                       ? 1
  45.                       : (bl1->a.a_uint > bl2->a.a_uint) ? -1 : 0;
  46.          break;
  47.      case ANY_UPTR:
  48.          result = (*bl1->a.a_uptr < *bl2->a.a_uptr)
  49.                       ? 1
  50.                       : (*bl1->a.a_uptr > *bl2->a.a_uptr) ? -1 : 0;
  51.          break;
  52.      case ANY_ULONG:
  53.          result = (bl1->a.a_ulong < bl2->a.a_ulong)
  54.                       ? 1
  55.                       : (bl1->a.a_ulong > bl2->a.a_ulong) ? -1 : 0;
  56.          break;
  57.      case ANY_ULPTR:
  58.          result = (*bl1->a.a_ulptr < *bl2->a.a_ulptr)
  59.                       ? 1
  60.                       : (*bl1->a.a_ulptr > *bl2->a.a_ulptr) ? -1 : 0;
  61.          break;
  62.      case ANY_STR:
  63.          if (strcmp(bl1->val, bl2->val) == 0)
  64.              result = 0;
  65.          else
  66.              result = 1;
  67.          break;
  68.      case ANY_MASK32:
  69.          if (bl1->a.a_ulong == bl2->a.a_ulong)
  70.              result = 0;
  71.          else
  72.              result = 1;
  73.          break;
  74.      default:
  75.          result = 1;
  76.      }
  77.      return result;
  78.  }
  79.  

percentage

  1.  STATIC_OVL int
  2.  percentage(bl, maxbl)
  3.  struct istat_s *bl, *maxbl;
  4.  {
  5.      int result = 0;
  6.      int anytype;
  7.  
  8.      if (!bl || !maxbl) {
  9.          impossible("percentage: bad istat pointer %s, %s",
  10.                     fmt_ptr((genericptr_t) bl), fmt_ptr((genericptr_t) maxbl));
  11.          return 0;
  12.      }
  13.  
  14.      anytype = bl->anytype;
  15.      if (maxbl->a.a_void) {
  16.          switch (anytype) {
  17.          case ANY_INT:
  18.              result = ((100 * bl->a.a_int) / maxbl->a.a_int);
  19.              break;
  20.          case ANY_LONG:
  21.              result = (int) ((100L * bl->a.a_long) / maxbl->a.a_long);
  22.              break;
  23.          case ANY_UINT:
  24.              result = (int) ((100U * bl->a.a_uint) / maxbl->a.a_uint);
  25.              break;
  26.          case ANY_ULONG:
  27.              result = (int) ((100UL * bl->a.a_ulong) / maxbl->a.a_ulong);
  28.              break;
  29.          case ANY_IPTR:
  30.              result = ((100 * (*bl->a.a_iptr)) / (*maxbl->a.a_iptr));
  31.              break;
  32.          case ANY_LPTR:
  33.              result = (int) ((100L * (*bl->a.a_lptr)) / (*maxbl->a.a_lptr));
  34.              break;
  35.          case ANY_UPTR:
  36.              result = (int) ((100U * (*bl->a.a_uptr)) / (*maxbl->a.a_uptr));
  37.              break;
  38.          case ANY_ULPTR:
  39.              result = (int) ((100UL * (*bl->a.a_ulptr)) / (*maxbl->a.a_ulptr));
  40.              break;
  41.          }
  42.      }
  43.      return result;
  44.  }
  45.  
  46.  

set_status_hilites

  1.  #ifdef STATUS_HILITES
  2.  
  3.  /****************************************************************************/
  4.  /* Core status hiliting support */
  5.  /****************************************************************************/
  6.  
  7.  struct hilite_s {
  8.      boolean set;
  9.      unsigned anytype;
  10.      anything threshold;
  11.      int behavior;
  12.      int coloridx[2];
  13.  };
  14.  
  15.  struct hilite_s status_hilites[MAXBLSTATS];
  16.  
  17.  /*
  18.   * This is the parser for the hilite options
  19.   * Example:
  20.   *    OPTION=hilite_status: hitpoints/10%/red/normal
  21.   *
  22.   * set_hilite_status() separates each hilite entry into its 4 component
  23.   * strings, then calls assign_hilite() to make the adjustments.
  24.   */
  25.  boolean
  26.  set_status_hilites(op, from_configfile)
  27.  char *op;
  28.  boolean from_configfile;
  29.  {
  30.      char hsbuf[4][QBUFSZ];
  31.      boolean rslt, badopt = FALSE;
  32.      int fldnum, num = 0, ccount = 0;
  33.      char c;
  34.  
  35.      num = fldnum = 0;
  36.      hsbuf[0][0] = hsbuf[1][0] = hsbuf[2][0] = hsbuf[3][0] = '\0';
  37.      while (*op && fldnum < 4 && ccount < (QBUFSZ - 2)) {
  38.          c = lowc(*op);
  39.          if (c == ' ') {
  40.              if (fldnum >= 2) {
  41.                  rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0],
  42.                                       &hsbuf[3][0], from_configfile);
  43.                  if (!rslt) {
  44.                      badopt = TRUE;
  45.                      break;
  46.                  }
  47.              }
  48.              hsbuf[0][0] = hsbuf[1][0] = '\0';
  49.              hsbuf[2][0] = hsbuf[3][0] = '\0';
  50.              fldnum = 0;
  51.              ccount = 0;
  52.          } else if (c == '/') {
  53.              fldnum++;
  54.              ccount = 0;
  55.          } else {
  56.              hsbuf[fldnum][ccount++] = c;
  57.              hsbuf[fldnum][ccount] = '\0';
  58.          }
  59.          op++;
  60.      }
  61.      if (fldnum >= 2 && !badopt) {
  62.          rslt = assign_hilite(&hsbuf[0][0], &hsbuf[1][0], &hsbuf[2][0],
  63.                               &hsbuf[3][0], from_configfile);
  64.          if (!rslt)
  65.              badopt = TRUE;
  66.      }
  67.      if (badopt)
  68.          return FALSE;
  69.      return TRUE;
  70.  }
  71.  

clear_status_hilites

  1.  void
  2.  clear_status_hilites(from_configfile)
  3.  boolean from_configfile;
  4.  {
  5.      int i;
  6.      anything it;
  7.      it = zeroany;
  8.      for (i = 0; i < MAXBLSTATS; ++i) {
  9.          (void) memset((genericptr_t) &status_hilites[i], 0,
  10.                        sizeof(struct hilite_s));
  11.          /* notify window port */
  12.          if (!from_configfile)
  13.              status_threshold(i, blstats[0][i].anytype, it, 0, 0, 0);
  14.      }
  15.  }
  16.  

assign_hilite

  1.  STATIC_OVL boolean
  2.  assign_hilite(sa, sb, sc, sd, from_configfile)
  3.  char *sa, *sb, *sc, *sd;
  4.  boolean from_configfile;
  5.  {
  6.      char *tmp, *how;
  7.      int i = -1, dt = -1, idx = -1;
  8.      int coloridx[2] = { -1, -1 };
  9.      boolean inverse[2] = { FALSE, FALSE };
  10.      boolean bold[2] = { FALSE, FALSE };
  11.      boolean normal[2] = { 0, 0 };
  12.      boolean percent = FALSE, down_up = FALSE, changed = FALSE;
  13.      anything threshold;
  14.      enum statusfields fld = BL_FLUSH;
  15.      threshold.a_void = 0;
  16.  
  17.      /* Example:
  18.       *  hilite_status: hitpoints/10%/red/normal
  19.       */
  20.  
  21.      /* field name to statusfield */
  22.      for (i = 0; sa && i < SIZE(fieldids); ++i) {
  23.          if (strcmpi(sa, fieldids[i].fieldname) == 0) {
  24.              idx = i;
  25.              fld = fieldids[i].fldid;
  26.              break;
  27.          }
  28.      }
  29.      if (idx == -1)
  30.          return FALSE;
  31.      status_hilites[idx].set = FALSE; /* mark it "unset" */
  32.  
  33.      /* threshold */
  34.      if (!sb)
  35.          return FALSE;
  36.      if ((strcmpi(sb, "updown") == 0) || (strcmpi(sb, "downup") == 0)
  37.          || (strcmpi(sb, "up") == 0) || (strcmpi(sb, "down") == 0)) {
  38.          down_up = TRUE;
  39.      } else if ((strcmpi(sb, "changed") == 0)
  40.                 && (fld == BL_TITLE || fld == BL_ALIGN || fld == BL_LEVELDESC
  41.                     || fld == BL_CONDITION)) {
  42.          changed = TRUE; /* changed is only thing allowed */
  43.      } else {
  44.          tmp = sb;
  45.          while (*tmp) {
  46.              if (*tmp == '%') {
  47.                  *tmp = '\0';
  48.                  percent = TRUE;
  49.                  break;
  50.              } else if (!index("0123456789", *tmp))
  51.                  return FALSE;
  52.              tmp++;
  53.          }
  54.          if (strlen(sb) > 0) {
  55.              dt = blstats[0][idx].anytype;
  56.              if (percent)
  57.                  dt = ANY_INT;
  58.              (void) s_to_anything(&threshold, sb, dt);
  59.          } else
  60.              return FALSE;
  61.          if (percent && (threshold.a_int < 1 || threshold.a_int > 100))
  62.              return FALSE;
  63.          if (!threshold.a_void && (strcmp(sb, "0") != 0))
  64.              return FALSE;
  65.      }
  66.  
  67.      /* actions */
  68.      for (i = 0; i < 2; ++i) {
  69.          if (!i)
  70.              how = sc;
  71.          else
  72.              how = sd;
  73.          if (!how) {
  74.              if (!i)
  75.                  return FALSE;
  76.              else
  77.                  break; /* sc is mandatory; sd is not */
  78.          }
  79.  
  80.          if (strcmpi(how, "bold") == 0) {
  81.              bold[i] = TRUE;
  82.          } else if (strcmpi(how, "inverse") == 0) {
  83.              inverse[i] = TRUE;
  84.          } else if (strcmpi(how, "normal") == 0) {
  85.              normal[i] = TRUE;
  86.          } else {
  87.              int k;
  88.              char colorname[BUFSZ];
  89.              for (k = 0; k < CLR_MAX; ++k) {
  90.                  /* we have to make a copy to change space to dash */
  91.                  (void) strcpy(colorname, c_obj_colors[k]);
  92.                  for (tmp = index(colorname, ' '); tmp;
  93.                       tmp = index(colorname, ' '))
  94.                      *tmp = '-';
  95.                  if (strcmpi(how, colorname) == 0) {
  96.                      coloridx[i] = k;
  97.                      break;
  98.                  }
  99.              }
  100.              if (k >= CLR_MAX)
  101.                  return FALSE;
  102.          }
  103.      }
  104.  
  105.      /* Assign the values */
  106.  
  107.      for (i = 0; i < 2; ++i) {
  108.          if (inverse[i])
  109.              status_hilites[idx].coloridx[i] = BL_HILITE_INVERSE;
  110.          else if (bold[i])
  111.              status_hilites[idx].coloridx[i] = BL_HILITE_BOLD;
  112.          else if (coloridx[i])
  113.              status_hilites[idx].coloridx[i] = coloridx[i];
  114.          else
  115.              status_hilites[idx].coloridx[i] = BL_HILITE_NONE;
  116.      }
  117.  
  118.      if (percent)
  119.          status_hilites[idx].behavior = BL_TH_VAL_PERCENTAGE;
  120.      else if (down_up)
  121.          status_hilites[idx].behavior = BL_TH_UPDOWN;
  122.      else if (threshold.a_void)
  123.          status_hilites[idx].behavior = BL_TH_VAL_ABSOLUTE;
  124.      else
  125.          status_hilites[idx].behavior = BL_TH_NONE;
  126.  
  127.      if (status_hilites[idx].behavior != BL_TH_NONE) {
  128.          status_hilites[idx].threshold = threshold;
  129.          status_hilites[idx].set = TRUE;
  130.      }
  131.      status_hilites[idx].anytype = dt;
  132.  
  133.      /* Now finally, we notify the window port */
  134.      if (!from_configfile)
  135.          status_threshold(idx, status_hilites[idx].anytype,
  136.                          status_hilites[idx].threshold,
  137.                          status_hilites[idx].behavior,
  138.                          status_hilites[idx].coloridx[0],
  139.                          status_hilites[idx].coloridx[1]);
  140.  
  141.      return TRUE;
  142.  }
  143.  

status_notify_windowport

  1.  void
  2.  status_notify_windowport(all)
  3.  boolean all;
  4.  {
  5.      int idx;
  6.      anything it;
  7.  
  8.      it = zeroany;
  9.      for (idx = 0; idx < MAXBLSTATS; ++idx) {
  10.          if (status_hilites[idx].set)
  11.              status_threshold(idx, status_hilites[idx].anytype,
  12.                              status_hilites[idx].threshold,
  13.                              status_hilites[idx].behavior,
  14.                              status_hilites[idx].coloridx[0],
  15.                              status_hilites[idx].coloridx[1]);
  16.          else
  17.              status_threshold(idx, blstats[0][idx].anytype, it, 0, 0, 0);
  18.  
  19.      }
  20.  }
  21.  

get_status_hilites

  1.  /*
  2.   * get_status_hilites
  3.   *
  4.   * Returns a string containing all the status hilites in the
  5.   * same format that is used to specify a status hilite preference
  6.   * in the config file.
  7.   */
  8.  char *
  9.  get_status_hilites(buf, bufsiz)
  10.  char *buf;
  11.  int bufsiz;
  12.  {
  13.      int i, j, k, coloridx;
  14.      const char *text = (char *) 0;
  15.      char tmp[BUFSZ], colorname[BUFSZ];
  16.      boolean val_percentage, val_absolute, up_down;
  17.      boolean added_one = FALSE;
  18.  
  19.      if (!buf)
  20.          return (char *) 0;
  21.      *buf = '\0';
  22.  
  23.      bufsiz--; /* required trailing null */
  24.      for (i = 0; i < MAXBLSTATS; ++i) {
  25.          val_percentage = val_absolute = up_down = FALSE;
  26.          if (status_hilites[i].set) {
  27.              if (!added_one)
  28.                  added_one = TRUE;
  29.              else {
  30.                  Strcat(buf, " ");
  31.                  bufsiz--;
  32.              }
  33.              k = strlen(fieldids[i].fieldname);
  34.              if (k < bufsiz) {
  35.                  Strcat(buf, fieldids[i].fieldname);
  36.                  bufsiz -= k;
  37.              }
  38.              if (bufsiz > 1) {
  39.                  Strcat(buf, "/");
  40.                  bufsiz--;
  41.              }
  42.              if (status_hilites[i].behavior == BL_TH_VAL_PERCENTAGE) {
  43.                  val_percentage = TRUE;
  44.              } else if (status_hilites[i].behavior == BL_TH_VAL_ABSOLUTE) {
  45.                  val_absolute = TRUE;
  46.              } else if (status_hilites[i].behavior == BL_TH_UPDOWN) {
  47.                  up_down = TRUE;
  48.                  text = "updown";
  49.              }
  50.  
  51.              if (status_hilites[i].behavior != BL_TH_UPDOWN) {
  52.                  anything_to_s(tmp, &status_hilites[i].threshold,
  53.                            blstats[0][i].anytype);
  54.                  text = tmp;
  55.              }
  56.              k = strlen(text);
  57.              if (k < (bufsiz - 1)) {
  58.                  Strcat(buf, text);
  59.                  if (val_percentage)
  60.                      Strcat(buf, "%"), k++;
  61.                  bufsiz -= k;
  62.              }
  63.              for (j = 0; j < 2; ++j) {
  64.                  if (bufsiz > 1) {
  65.                      Strcat(buf, "/");
  66.                      bufsiz--;
  67.                  }
  68.                  coloridx = status_hilites[i].coloridx[j];
  69.                  if (coloridx < 0) {
  70.                      if (coloridx == BL_HILITE_BOLD)
  71.                          text = "bold";
  72.                      else if (coloridx == BL_HILITE_INVERSE)
  73.                          text = "inverse";
  74.                      else
  75.                          text = "normal";
  76.                  } else {
  77.                      char *blank;
  78.                      (void) strcpy(colorname, c_obj_colors[coloridx]);
  79.                      for (blank = index(colorname, ' '); blank;
  80.                           blank = index(colorname, ' '))
  81.                          *blank = '-';
  82.                      text = colorname;
  83.                  }
  84.                  k = strlen(text);
  85.                  if (k < bufsiz) {
  86.                      Strcat(buf, text);
  87.                      bufsiz -= k;
  88.                  }
  89.              }
  90.          }
  91.      }
  92.      return buf;
  93.  }
  94.  

clridx_to_s

  1.  STATIC_OVL const char *
  2.  clridx_to_s(buf, idx)
  3.  char *buf;
  4.  int idx;
  5.  {
  6.      static const char *a[] = { "bold", "inverse", "normal" };
  7.      char* p = 0;
  8.  
  9.      if (buf) {
  10.          buf[0] = '\0';
  11.          if (idx < 0 && idx >= BL_HILITE_BOLD)
  12.              Strcpy(buf, a[idx + 3]);
  13.          else if (idx >= 0 && idx < CLR_MAX)
  14.              Strcpy(buf, c_obj_colors[idx]);
  15.          /* replace spaces with - */
  16.          for(p = buf; *p; p++)
  17.              if(*p == ' ') *p = '-';
  18.      }
  19.      return buf;
  20.  }
  21.  

status_hilite_menu

  1.  boolean
  2.  status_hilite_menu()
  3.  {
  4.      int i, j, k, pick_cnt, pick_idx, opt_idx;
  5.      menu_item *statfield_picks = (menu_item *) 0;
  6.      const char *fieldname;
  7.      int field_picks[MAXBLSTATS], res;
  8.      struct hilite_s hltemp[MAXBLSTATS];
  9.      char buf[BUFSZ], thresholdbuf[BUFSZ], below[BUFSZ], above[BUFSZ];
  10.      winid tmpwin;
  11.      anything any;
  12.  
  13.      tmpwin = create_nhwindow(NHW_MENU);
  14.      start_menu(tmpwin);
  15.      for (i = 0; i < MAXBLSTATS; i++) {
  16.          (void) memset(&hltemp[i], 0, sizeof(struct hilite_s));
  17.          fieldname = fieldids[i].fieldname;
  18.          any.a_int = i + 1;
  19.          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE, fieldname,
  20.                   MENU_UNSELECTED);
  21.          field_picks[i] = 0;
  22.      }
  23.      end_menu(tmpwin, "Change hilite on which status field(s):");
  24.      if ((pick_cnt = select_menu(tmpwin, PICK_ANY, &statfield_picks)) > 0) {
  25.          for (pick_idx = 0; pick_idx < pick_cnt; ++pick_idx) {
  26.              opt_idx = statfield_picks[pick_idx].item.a_int - 1;
  27.              field_picks[opt_idx] = 1;
  28.          }
  29.          free((genericptr_t) statfield_picks);
  30.          statfield_picks = (menu_item *) 0;
  31.      }
  32.      destroy_nhwindow(tmpwin);
  33.      if (pick_cnt < 0)
  34.          return FALSE;
  35.  
  36.      for (i = 0; i < MAXBLSTATS; i++) {
  37.          if (field_picks[i]) {
  38.              menu_item *pick = (menu_item *) 0;
  39.              Sprintf(buf, "Threshold behavior options for %s:",
  40.                      fieldids[i].fieldname);
  41.              tmpwin = create_nhwindow(NHW_MENU);
  42.              start_menu(tmpwin);
  43.              if (i == BL_CONDITION) {
  44.                  any = zeroany;
  45.                  any.a_int = BL_TH_CONDITION + 1;
  46.                  add_menu(tmpwin, NO_GLYPH, &any, 'c', 0, ATR_NONE,
  47.                           "Condition bitmask threshold.", MENU_UNSELECTED);
  48.              }
  49.              any = zeroany;
  50.              any.a_int = BL_TH_NONE + 1;
  51.              add_menu(tmpwin, NO_GLYPH, &any, 'n', 0, ATR_NONE, "None",
  52.                       MENU_UNSELECTED);
  53.              if (i != BL_CONDITION) {
  54.                  if (blstats[0][i].idxmax > 0) {
  55.                      any = zeroany;
  56.                      any.a_int = BL_TH_VAL_PERCENTAGE + 1;
  57.                      add_menu(tmpwin, NO_GLYPH, &any, 'p', 0, ATR_NONE,
  58.                               "Percentage threshold.", MENU_UNSELECTED);
  59.                  }
  60.                  any = zeroany;
  61.                  any.a_int = BL_TH_UPDOWN + 1;
  62.                  add_menu(tmpwin, NO_GLYPH, &any, 'u', 0, ATR_NONE,
  63.                           "UpDown threshold.", MENU_UNSELECTED);
  64.                  any = zeroany;
  65.                  any.a_int = BL_TH_VAL_ABSOLUTE + 1;
  66.                  add_menu(tmpwin, NO_GLYPH, &any, 'v', 0, ATR_NONE,
  67.                           "Value threshold.", MENU_UNSELECTED);
  68.              }
  69.              end_menu(tmpwin, buf);
  70.              if ((res = select_menu(tmpwin, PICK_ONE, &pick)) > 0) {
  71.                  hltemp[i].behavior = pick->item.a_int - 1;
  72.                  free((genericptr_t) pick);
  73.              }
  74.              destroy_nhwindow(tmpwin);
  75.              if (res < 0)
  76.                  return FALSE;
  77.  
  78.              if (hltemp[i].behavior == BL_TH_UPDOWN) {
  79.                  Sprintf(below, "%s decreases", fieldids[i].fieldname);
  80.                  Sprintf(above, "%s increases", fieldids[i].fieldname);
  81.              } else if (hltemp[i].behavior) {
  82.                  /* Have them enter the threshold*/
  83.                  Sprintf(
  84.                      buf, "Set %s threshold to what%s?", fieldids[i].fieldname,
  85.                      (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE)
  86.                          ? " percentage"
  87.                          : (hltemp[i].behavior == BL_TH_CONDITION) ? " mask"
  88.                                                                    : "");
  89.                  getlin(buf, thresholdbuf);
  90.                  if (thresholdbuf[0] == '\033')
  91.                      return FALSE;
  92.                  (void) s_to_anything(&hltemp[i].threshold, thresholdbuf,
  93.                                       blstats[0][i].anytype);
  94.                  if (!hltemp[i].threshold.a_void)
  95.                      return FALSE;
  96.  
  97.                  Sprintf(below, "%s falls below %s%s", fieldids[i].fieldname,
  98.                          thresholdbuf,
  99.                          (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%"
  100.                                                                       : "");
  101.                  Sprintf(above, "%s rises above %s%s", fieldids[i].fieldname,
  102.                          thresholdbuf,
  103.                          (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%"
  104.                                                                       : "");
  105.              }
  106.              for (j = 0; j < 2 && (hltemp[i].behavior != BL_TH_NONE); ++j) {
  107.                  char prompt[QBUFSZ];
  108.                  /* j == 0 below, j == 1 above */
  109.                  menu_item *pick2 = (menu_item *) 0;
  110.  
  111.                  Sprintf(prompt, "Display how when %s?", j ? above : below);
  112.                  tmpwin = create_nhwindow(NHW_MENU);
  113.                  start_menu(tmpwin);
  114.                  for (k = -3; k < CLR_MAX; ++k) {
  115.                      /* if (k == -1) continue; */
  116.                      any = zeroany;
  117.                      any.a_int = (k >= 0) ? k + 1 : k;
  118.                      if (k > 0)
  119.                          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  120.                                   c_obj_colors[k], MENU_UNSELECTED);
  121.                      else if (k == -1)
  122.                          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  123.                                   "normal", MENU_UNSELECTED);
  124.                      else if (k == -2)
  125.                          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  126.                                   "inverse", MENU_UNSELECTED);
  127.                      else if (k == -3)
  128.                          add_menu(tmpwin, NO_GLYPH, &any, 0, 0, ATR_NONE,
  129.                                   "bold", MENU_UNSELECTED);
  130.                  }
  131.                  end_menu(tmpwin, prompt);
  132.                  if ((res = select_menu(tmpwin, PICK_ONE, &pick2)) > 0) {
  133.                      hltemp[i].coloridx[j] = (pick2->item.a_char > 0)
  134.                                                  ? pick2->item.a_int - 1
  135.                                                  : pick2->item.a_int;
  136.                      free((genericptr_t) pick2);
  137.                  }
  138.                  destroy_nhwindow(tmpwin);
  139.                  if (res < 0)
  140.                      return FALSE;
  141.              }
  142.          }
  143.      }
  144.      buf[0] = '\0';
  145.      for (i = 0; i < MAXBLSTATS; i++) {
  146.          if (field_picks[i]) {
  147.              Sprintf(eos(buf), "%s/%s%s/", fieldids[i].fieldname,
  148.                      (hltemp[i].behavior == BL_TH_UPDOWN)
  149.                          ? "updown"
  150.                          : anything_to_s(thresholdbuf, &hltemp[i].threshold,
  151.                                          blstats[0][i].anytype),
  152.                      (hltemp[i].behavior == BL_TH_VAL_PERCENTAGE) ? "%" : "");
  153.              /* borrow thresholdbuf for use with these last two */
  154.              Sprintf(eos(buf), "%s/",
  155.                      clridx_to_s(thresholdbuf, hltemp[i].coloridx[0]));
  156.              Sprintf(eos(buf), "%s ",
  157.                      clridx_to_s(thresholdbuf, hltemp[i].coloridx[1]));
  158.          }
  159.      }
  160.      return set_status_hilites(buf, FALSE);
  161.  }
  162.  #endif /*STATUS_HILITES*/
  163.  #endif /*STATUS_VIA_WINDOWPORT*/
  164.  
  165.  /*botl.c*/