Re: auto prompt?!

From: George Greer (greerga@circlemud.org)
Date: 05/17/02


On Fri, 17 May 2002, Edward J Glamkowski wrote:

>In the help file for prompt there is an auto option to display HMV only
>when they are less the 30%.  This isn't implemented. Would be nice if it
>were imp'ed it in a future release of the stock code, or the reference
>removed from the help file.  I don't care which way, just so long as they
>are consistent :)

How's this?

Behavior:
  If PRF_DISP(HP|MANA|MOVE) -> display.
  IF PRF_DISPAUTO and value < 33% -> display.

Which leaves PRF_DISPAUTO | PRF_DISPHP | PRF_DISPMANA | PRF_DISPMOVE as a
useless state since PRF_DISPAUTO is effectively ignored.

--
George Greer
greerga@circlemud.org

Index: comm.c
===================================================================
RCS file: /home/circledb/.cvs/circle/src/comm.c,v
retrieving revision 1.114
diff -u -p -r1.114 comm.c
--- comm.c      2002/04/09 14:31:05     1.114
+++ comm.c      2002/05/18 00:32:38
@@ -995,33 +995,41 @@ char *make_prompt(struct descriptor_data
            "\r\n[ Return to continue, (q)uit, (r)efresh, (b)ack, or page number (%d/%d) ]",
            d->showstr_page, d->showstr_count);
   } else if (STATE(d) == CON_PLAYING && !IS_NPC(d->character)) {
-    int count;
+    int count, idx;
     size_t len = 0;
+    struct prompt_value_data {
+      bitvector_t pref;
+      long cur_value;
+      long max_value;
+      const char *format;
+    } prompt_display[] = {
+      { 0,             GET_INVIS_LEV(d->character),    0,                              "i%d " },
+      { PRF_DISPHP,    GET_HIT(d->character),          GET_MAX_HIT(d->character),      "%dH " },
+      { PRF_DISPMANA,  GET_MANA(d->character),         GET_MAX_MANA(d->character),     "%dM " },
+      { PRF_DISPMOVE,  GET_MOVE(d->character),         GET_MAX_MOVE(d->character),     "%dV " },
+    };

     *prompt = '\0';

-    if (GET_INVIS_LEV(d->character) && len < sizeof(prompt)) {
-      count = snprintf(prompt + len, sizeof(prompt) - len, "i%d ", GET_INVIS_LEV(d->character));
-      if (count >= 0)
-        len += count;
-    }
-
-    if (PRF_FLAGGED(d->character, PRF_DISPHP) && len < sizeof(prompt)) {
-      count = snprintf(prompt + len, sizeof(prompt) - len, "%dH ", GET_HIT(d->character));
-      if (count >= 0)
-        len += count;
-    }
+    for (idx = 0; idx < sizeof(prompt_display) / sizeof(struct prompt_value_data); idx++) {
+      if (prompt_display[idx].pref) {
+        if (PRF_FLAGGED(d->character, prompt_display[idx].pref))
+          /* Always display. */ ;
+        else if (PRF_FLAGGED(d->character, PRF_DISPAUTO) && prompt_display[idx].cur_value * 3 < prompt_display[idx].max_value)
+          /* Under 33%, display. */;
+        else
+          continue;
+      } else if (!prompt_display[idx].cur_value)
+        continue;

-    if (PRF_FLAGGED(d->character, PRF_DISPMANA) && len < sizeof(prompt)) {
-      count = snprintf(prompt + len, sizeof(prompt) - len, "%dM ", GET_MANA(d->character));
-      if (count >= 0)
+      count = snprintf(prompt + len, sizeof(prompt) - len, prompt_display[idx].format, prompt_display[idx].cur_value);
+      if (count > 0)
         len += count;
-    }
+      else
+        len = sizeof(prompt);  /* -1 return value: old versions of snprintf give when truncating. */

-    if (PRF_FLAGGED(d->character, PRF_DISPMOVE) && len < sizeof(prompt)) {
-      count = snprintf(prompt + len, sizeof(prompt) - len, "%dV ", GET_MOVE(d->character));
-      if (count >= 0)
-        len += count;
+      if (len >= sizeof(prompt))
+        break;
     }

     if (len < sizeof(prompt))
Index: act.other.c
===================================================================
RCS file: /home/circledb/.cvs/circle/src/act.other.c,v
retrieving revision 1.42
diff -u -p -r1.42 act.other.c
--- act.other.c 2002/02/01 02:04:17     1.42
+++ act.other.c 2002/05/18 00:31:20
@@ -739,9 +739,16 @@ ACMD(do_display)
   skip_spaces(&argument);

   if (!*argument) {
-    send_to_char(ch, "Usage: prompt { { H | M | V } | all | none }\r\n");
+    send_to_char(ch, "Usage: prompt { { H | M | V } | all | auto | none }\r\n");
     return;
   }
+
+  if (!str_cmp(argument, "auto")) {
+    TOGGLE_BIT(PRF_FLAGS(ch), PRF_DISPAUTO);
+    send_to_char(ch, "Auto prompt %sabled.\r\n", PRF_FLAGGED(ch, PRF_DISPAUTO) ? "en" : "dis");
+    return;
+  }
+
   if (!str_cmp(argument, "on") || !str_cmp(argument, "all"))
     SET_BIT(PRF_FLAGS(ch), PRF_DISPHP | PRF_DISPMANA | PRF_DISPMOVE);
   else if (!str_cmp(argument, "off") || !str_cmp(argument, "none"))
@@ -761,7 +768,7 @@ ACMD(do_display)
        SET_BIT(PRF_FLAGS(ch), PRF_DISPMOVE);
        break;
       default:
-       send_to_char(ch, "Usage: prompt { { H | M | V } | all | none }\r\n");
+       send_to_char(ch, "Usage: prompt { { H | M | V } | all | auto | none }\r\n");
        return;
       }
     }

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT