Adding flags

Submitted by javelin on Sat, 2003-02-01 17:41

N.B. This discussion applies to the PennMUSH flag system as of PennMUSH 1.7.7p5. If you're using an earlier version of PennMUSH, you need to find an older edition of Javelin's Guide for PennMUSH Gods

The easiest way to add flags in PennMUSH is to log in as #1 and use @flag. If you don't need your flags to have any special hardcoded effects, this is definitely the way to go.

So from here on out, I'll assume that you are coding your own hardcoded system (e.g. a space system) that you expect to distribute, and your system needs to automatically add a SPACE flag to the database and be able to test it in hardcode in order to implement special effects.

Adding the flag

Adding a new flag is as easy as adding a call to add_flag() in the local_flags() function of src/flaglocal.c, like this:

add_flag("SPACE", '&', NOTYPE, F_ANY, F_ANY);

The arguments, in order, are:

  1. The flag's name, in "quotes".
  2. The flag's character, in 'single quotes'. If you don't want to assign a character to the flag, use '\0'
  3. The set of object types to which the flag can be applied. NOTYPE means all. Otherwise you can use a bitwise-OR combination of TYPE_ROOM, TYPE_PLAYER, TYPE_THING, and TYPE_EXIT
  4. Permissions required to set the flag. See listing in hdrs/flags.h
  5. Permissions required to clear the flag. See listing in hdrs/flags.h

Adding a macro

To make the use of your flag in code easier, add a macro that checks to see if an object has the flag. In PennMUSH, these macros are usually defined in hdrs/dbdefs.h. If your flag only applies to a single object type, you can define it with the IS() macro, like Floating():

#define Floating(x)     (IS(x, TYPE_ROOM, "FLOATING"))

If your flag applies to multiple (or all) object types, use the has_flag_by_name() function instead, like this:

#define Audible(x)      (has_flag_by_name(x, "AUDIBLE", NOTYPE))