Re: [CODE] Whois command for C30bpl18 with ASCII

From: Daniel A. Koepke (
Date: 09/10/01

On Sun, 9 Sep 2001, NeoStar wrote:

> [... snip ...]

A simple recrafting of your code, see below for motivations behind the
changes I've made:

    char buf[MAX_STRING_LENGTH];
    char arg[MAX_INPUT_LENGTH];
    struct char_data *vict;
    bool loaded = FALSE;

    one_argument(argument, arg);

    if (!*arg) {
      send_to_char("USAGE: whois <who>\r\n", ch); /* #3 */
    } else if (!(vict = get_player_vis(ch, arg, NULL, FIND_CHAR_WORLD))) {
      CREATE(vict, struct char_data, 1);
      CREATE(vict->player_specials, struct player_special_data, 1);
      loaded = TRUE;

      if (load_char(arg, vict) == -1) {
        send_to_char("No such player exists.\r\n", ch);

    sprintf(buf, "%s %s is a level %d %s.\r\n",
            GET_NAME(vict), GET_TITLE(vict), GET_LEVEL(vict),
    send_to_char(buf, ch);

    if (loaded) extract_char_final(victim);

Motivations behind significant changes:

REMOVAL OF whois_char() FUNCTION -- Modularity is nice, but whois_char()
is a special-purpose function that encapsulates very little code.  If code
is compact and has only a specific purpose, then encapsulation in its own
procedure is generally not worth the trouble behind it.

REMOVAL OF classnum VARIABLE -- The CLASS_xxx #defines are numbers.  The
GET_CLASS(ch) macro returns a number.  CLASS_xxx are preprocessor macros
that are convenient ways of referring to these numbers.

REMOVAL OF vclass[] ARRAY -- There is a global pc_class_types[] array
defined in class.c that has the names of the classes.  It's better to use
this array because it provides a centralized location, so that the
addition of new classes does not require hunt-and-peck coding to fix
other, unknown dependencies.  Also, when you add arrays of this sort, if
they're general purpose add them to an appropriate file (class.c,
constants.c, etc.) and, if you're going to provide an array-size, use a
#define'd constant in structs.h or wherever for it.  This eliminates the
dependency on magic numbers.  If you use the macro throughout, changing
the macro suffices to make all of the code that relies upon it working.
Compare vclass[5] with vclass[NUM_CLASSES+1].

NO GLOBAL BUFFER RELIANCE -- I removed the reliance on global buffers.
Using local space is much more safe and no more expensive: it's guaranteed
not to have unintended side-effects on other code.

RESTRUCTURING OF do_whois -- Combined else { if () ; } into else if { ; }
which is more terse and clear.  If a character can't be found in the game,
we try to load him.  We use the same two lines of code (formerly from
whois_char()) for both cases, and add a special case at the end to
cleanup.  This ensures conistency the same way whois_char() did.


   | FAQ: |
   | Archives: |

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