[CODE] poofset

From: Anton Graham (darkimage@bigfoot.com)
Date: 01/29/01


After looking at the poofset snippet from Rasdan, I threw this
together.  Being a big believer in re-using code, I found the
use of two separate functions to be wasteful.  Further, the
original snippet would generate something like "Current Poofin:
Dionysus (null)" if the imm hadn't previously set his poof.
So, I redefined the default poofs as variables so that I
could reuse them.  This has the added asvantage of saving a few
bytes in the goto function.

What follows below is a patch against stock bpl17.

Dionysus <darkimage@bigfoot.com>

diff -u src.orig/act.wizard.c src/act.wizard.c
--- src.orig/act.wizard.c       Sat Jan 27 18:48:14 2001
+++ src/act.wizard.c    Sat Jan 27 19:09:46 2001
@@ -45,6 +45,8 @@

 /* for chars */
 extern const char *pc_class_types[];
+extern const char *D_POOFIN;
+extern const char *D_POOFOUT;

 /* extern functions */
 int level_exp(int chclass, int level);
@@ -242,20 +244,14 @@
   if ((location = find_target_room(ch, argument)) < 0)
     return;

-  if (POOFOUT(ch))
-    sprintf(buf, "$n %s", POOFOUT(ch));
-  else
-    strcpy(buf, "$n disappears in a puff of smoke.");
+  sprintf(buf, "$n %s", (POOFOUT(ch)) ? POOFOUT(ch) : D_POOFOUT);

   act(buf, TRUE, ch, 0, 0, TO_ROOM);
   char_from_room(ch);
   char_to_room(ch, location);

-  if (POOFIN(ch))
-    sprintf(buf, "$n %s", POOFIN(ch));
-  else
-    strcpy(buf, "$n appears with an ear-splitting bang.");
-
+  sprintf(buf, "$n %s", (POOFIN(ch)) ? POOFIN(ch) : D_POOFIN);
+
   act(buf, TRUE, ch, 0, 0, TO_ROOM);
   look_at_room(ch, 0);
 }
@@ -1440,7 +1436,8 @@
 ACMD(do_poofset)
 {
   char **msg;
+        int  is_poofin = (subcmd == SCMD_POOFIN);

   switch (subcmd) {
   case SCMD_POOFIN:    msg = &(POOFIN(ch));    break;
   case SCMD_POOFOUT:   msg = &(POOFOUT(ch));   break;
@@ -1449,15 +1446,17 @@

   skip_spaces(&argument);

-  if (*msg)
-    free(*msg);
-
-  if (!*argument)
-    *msg = NULL;
-  else
+  if (!*argument) {
+    sprintf(buf, "Current poof%s: %s %s\r\n", (is_poofin) ?
+                 "in" : "out", GET_NAME(ch), (*msg != NULL) ? *msg :
+                 ((is_poofin) ? D_POOFIN : D_POOFOUT));
+    send_to_char(buf, ch);
+  } else {
+    if (*msg)
+      free(*msg);
     *msg = str_dup(argument);
-
-  send_to_char(OK, ch);
+    send_to_char(OK, ch);
+  }
 }


diff -u src.orig/config.c src/config.c
--- src.orig/config.c   Sat Jan 27 18:48:14 2001
+++ src/config.c        Sat Jan 27 18:58:40 2001
@@ -290,3 +290,12 @@
 /* If yes, what is the lowest level which should be on the wizlist?  (All
    immort levels below the level you specify will go on the immlist instead.) */
 int min_wizlist_lev = LVL_GOD;
+
+/****************************************************************************/
+/****************************************************************************/
+
+/* Default poofs */
+
+const char *D_POOFOUT = "disappears in a puff of smoke.";
+const char *D_POOFIN  = "appears with an ear-splitting bang.";
+

--
Anton Graham                            GPG ID: 0x18F78541
<darkimage@bigfoot.com>                 RSA key available upon request
"When the going gets weird, the weird turn pro..."
  -- Hunter S. Thompson

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/03/01 PST