Re: Code: More of Racewar...

From: Daniel A. Koepke (dkoepke@california.com)
Date: 07/29/99


Today, Malikite spake to the list:

> ok here is an easier way,

Allow me to explain a little more clearly.

> DON'T save the "An Ogre" to your Pfiles ....

Instead, save an integer representation of the race.  Basically, an
enumeration.  Look at how classes are implemented: one number stands for
one class.  CLASS_MAGIC_USER is 0, CLASS_CLERIC is 1, etc.  The names of
the classes are stored in pc_class_names[], which resides in class.c.
These names are not saved in the player file, since it's a waste of space
to do that (people can't change the name of the class they belong to on an
individual basis; if the name changes, it's global).  Instead, only the
integer representing an index to this array is saved.  Thus,

In structs.h,

    #define RACE_HUMAN     0
    #define RACE_DWARF     1
    #define RACE_ELF       2
    #define RACE_OGRE      3
    #define RACE_KOBOLD    4
    #define RACE_DROW      5
    #define NUM_RACES      6

In any .c file you see fit,

    const char * pc_race_names [NUM_RACES] = {
        "Human",
        "Dwarf",
        "Elf",
        "Ogre",
        "Kobold",
        "Drow"
    };

You then store one of the RACE_xxx values on the player.  Again, see how
classes are done.  This would be done in exactly the same manner.  Now, to
represent the race war, you can create an array like this to signify which
races hate each other,

    const bool racial_hatred [NUM_RACES][NUM_RACES] = {
       /* XXX        Hum,   Dwa,   Elf,   Ogr,   Kob,   Dro */
       /* Hum */ { FALSE,  TRUE, FALSE,  TRUE,  TRUE,  TRUE },
       /* Dwa */ {  TRUE, FALSE, FALSE,  TRUE,  TRUE,  TRUE },
       /* Elf */ { FALSE, FALSE, FALSE,  TRUE,  TRUE,  TRUE },
       /* Ogr */ {  TRUE,  TRUE,  TRUE, FALSE, FALSE,  TRUE },
       /* Kob */ {  TRUE,  TRUE,  TRUE, FALSE, FALSE, FALSE },
       /* Dro */ {  TRUE,  TRUE,  TRUE,  TRUE,  TRUE, FALSE }
    };

In this table, TRUE means a race hates another one, FALSE means it
doesn't.  You'll note, then, that I have a fairly black-and-white system
in which the only diversions are that Humans and Dwarves don't get along
and Ogres and Drows don't get along; otherwise, it's a pretty simple,
standard Humans, Dwarves, and Elves hate Ogres, Kobols, and Drows (and
vice-versa).  Using this table is easy.  For instance, find the following
lines in "list_one_char()" (act.informative.c),

    if (IS_NPC(i)) {
      strcpy(buf, i->player.short_descr);
      CAP(buf);
    } else {
      sprintf(buf, "%s %s", i->player.name, GET_TITLE(i));

and change them to,

    if (IS_NPC(i)) {
      strcpy(buf, i->player.short_descr);
      CAP(buf);
    } else if (racial_hatred[GET_RACE(ch)][GET_RACE(i)])
      sprintf(buf, "%s %s", ANA(pc_race_names[GET_RACE(i)]),
              pc_race_names[GET_RACE(i)]);
    else
      sprintf(buf, "%s %s", i->player.name, GET_TITLE(i));

Assuming that you've created a GET_RACE macro to mirror the functionality
of GET_CLASS.  See utils.h.

This is all as easy as a cut and paste job, really.  The tables/arrays are
easy enough to figure out and generate on your own.  So this is an
incredibly easy thing to start with.  Of course, it *won't* make your mud
unique: there are lots of muds that do this very thing (well, more than
this).  See MUME or any of the Muds that Owen Emlen and others use to
(does?) operate.

> just use the list for it ... IE :   race_ab(GET_RACE(ch))

You mean, of course, "race_ab[GET_RACE(ch)]," since it's an array... :)
Oh, and please snip quoted messages, so that we don't get the entire thing
after yours.  This will bring you into accordance with the list rules
which is a *very* good thing.

-dak : Dual PPro?  Well, now...


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST