PennMUSH Community

root/1.8.3/trunk/hdrs/flags.h

Revision 1032, 11.2 kB (checked in by shawnw, 1 year ago)

Merged 1.8.3p4 into trunk

Line 
1 /** \file flags.h
2  *
3  * \brief flag and powers stuff
4  */
5
6 #ifndef __FLAGS_H
7 #define __FLAGS_H
8
9 #include "mushtype.h"
10 #include "ptab.h"
11
12 typedef struct flag_info FLAG;
13
14 /** A flag.
15  * This structure represents a flag in the table of flags that are
16  * available for setting on objects in the game.
17  */
18 struct flag_info {
19   const char *name;     /**< Name of the flag */
20   char letter;          /**< Flag character, which may be nul */
21   int type;             /**< Bitflags of object types this flag applies to */
22   int bitpos;           /**< Bit position assigned to this flag for now */
23   uint32_t perms;            /**< Bitflags of who can set this flag */
24   uint32_t negate_perms;     /**< Bitflags of who can clear this flag */
25 };
26
27 typedef struct flag_alias FLAG_ALIAS;
28
29 /** A flag alias.
30  * A simple structure that associates an alias with a canonical flag name.
31  */
32 struct flag_alias {
33   const char *alias;            /**< The alias name */
34   const char *realname;         /**< The real name of the flag */
35 };
36
37 typedef struct flagspace FLAGSPACE;
38
39 /** A flagspace.
40  * A structure that contains all the information necessary to manage
41  * a set of flags, powers, or whatever.
42  */
43 struct flagspace {
44   const char *name;             /**< The name of this flagspace */
45   PTAB *tab;                    /**< Prefix table storing flags by name/alias */
46   FLAG **flags;                 /**< Variable-length array of pointers to canonical flags, indexed by bit */
47   int flagbits;                 /**< Current length of the flags array */
48   FLAG *flag_table;             /**< Pointer to flag table */
49   FLAG_ALIAS *flag_alias_table; /**< Pointer to flag alias table */
50 };
51
52
53 /* From flags.c */
54 extern int has_flag_in_space_by_name(const char *ns, dbref thing,
55                                      const char *flag, int type);
56 #define has_flag_by_name(x,y,z) has_flag_in_space_by_name("FLAG",x,y,z)
57 #define has_power_by_name(x,y,z) has_flag_in_space_by_name("POWER",x,y,z)
58 extern const char *unparse_flags(dbref thing, dbref player);
59 extern const char *flag_description(dbref player, dbref thing);
60 extern int sees_flag(const char *ns, dbref privs, dbref thing,
61                      const char *name);
62 extern void set_flag(dbref player, dbref thing, const char *flag, int negate,
63                      int hear, int listener);
64 extern void set_power(dbref player, dbref thing, const char *flag, int negate);
65 extern const char *power_description(dbref player, dbref thing);
66 extern int flaglist_check(const char *ns, dbref player, dbref it,
67                           const char *fstr, int type);
68 extern int flaglist_check_long(const char *ns, dbref player, dbref it,
69                                const char *fstr, int type);
70 extern FLAG *match_flag(const char *name);
71 extern FLAG *match_power(const char *name);
72 extern const char *show_command_flags(object_flag_type flags,
73                                       object_flag_type powers);
74 extern void twiddle_flag_internal(const char *ns, dbref thing, const char *flag,
75                                   int negate);
76 extern object_flag_type new_flag_bitmask(const char *ns);
77 extern object_flag_type clone_flag_bitmask(const char *ns,
78                                            object_flag_type given);
79 extern void copy_flag_bitmask(const char *ns, object_flag_type dest,
80                               object_flag_type given);
81 extern void destroy_flag_bitmask(object_flag_type bitmask);
82 extern void set_flag_bitmask(object_flag_type bitmask, int bit);
83 extern void clear_flag_bitmask(object_flag_type bitmask, int bit);
84 extern int has_bit(object_flag_type bitmask, int bitpos);
85 extern int has_all_bits(const char *ns, object_flag_type source,
86                         object_flag_type bitmask);
87 extern int null_flagmask(const char *ns, object_flag_type source);
88 extern int has_any_bits(const char *ns, object_flag_type source,
89                         object_flag_type bitmask);
90 extern object_flag_type string_to_bits(const char *ns, const char *str);
91 extern const char *bits_to_string(const char *ns, object_flag_type bitmask,
92                                   dbref privs, dbref thing);
93 extern void flag_write_all(FILE *, const char *);
94 extern void flag_read_all(FILE *, const char *);
95 extern int type_from_old_flags(long old_flags);
96 extern object_flag_type flags_from_old_flags(const char *ns, long old_flags,
97                                              long old_toggles, int type);
98 extern FLAG *add_flag_generic(const char *ns, const char *name,
99                               const char letter, int type, int perms,
100                               int negate_perms);
101 #define add_flag(n,l,t,p,x) add_flag_generic("FLAG",n,l,t,p,x)
102 #define add_power(n,l,t,p,x) add_flag_generic("POWER",n,l,t,p,x)
103 extern int alias_flag_generic(const char *ns, const char *name,
104                               const char *alias);
105 #define alias_flag(n,a) alias_flag_generic("FLAG",n,a);
106 #define alias_power(n,a) alias_flag_generic("POWER",n,a);
107 extern void do_list_flags(const char *ns, dbref player, const char *arg, int lc,
108                           const char *label);
109 extern char *list_all_flags(const char *ns, const char *name, dbref privs,
110                             int which);
111 extern void do_flag_info(const char *ns, dbref player, const char *name);
112 extern void do_flag_delete(const char *ns, dbref player, const char *name);
113 extern void do_flag_disable(const char *ns, dbref player, const char *name);
114 extern void do_flag_alias(const char *ns, dbref player, const char *name,
115                           const char *alias);
116 extern void do_flag_enable(const char *ns, dbref player, const char *name);
117 extern void do_flag_restrict(const char *ns, dbref player, const char *name,
118                              char *args_right[]);
119 extern void do_flag_type(const char *ns, dbref player, const char *name,
120                          char *type_string);
121 extern void do_flag_add(const char *ns, dbref player, const char *name,
122                         char *args_right[]);
123 extern void do_flag_letter(const char *ns, dbref player, const char *name,
124                            const char *letter);
125 extern const char *power_to_string(int pwr);
126 extern void decompile_flags_generic(dbref player, dbref thing, const char *name,
127                                     const char *ns, const char *command,
128                                     const char *prefix);
129 #define decompile_flags(p,t,n,r) decompile_flags_generic(p,t,n,"FLAG","@set",r)
130 #define decompile_powers(p,t,n,r) decompile_flags_generic(p,t,n,"POWER","@power",r)
131
132 #define twiddle_flag_bitmask(bm,b,neg) (neg ? clear_flag_bitmask(bm,b) : \
133                                                 set_flag_bitmask(bm,b))
134 #define has_all_flags_by_mask(x,bm) has_all_bits("FLAG",Flags(x),bm)
135 #define has_any_flags_by_mask(x,bm) has_any_bits("FLAG",Flags(x),bm)
136 #define has_all_powers_by_mask(x,bm) has_all_bits("POWER",Powers(x),bm)
137 #define has_any_powers_by_mask(x,bm) has_any_bits("POWER",Powers(x),bm)
138 #define twiddle_flag(n,thing,f,negate) \
139   do { \
140   if (n->tab == &ptab_flag) { \
141    twiddle_flag_bitmask(Flags(thing),f->bitpos,negate); \
142   } else { \
143    twiddle_flag_bitmask(Powers(thing),f->bitpos,negate); \
144   } } while (0)
145 #define set_flag_internal(t,f) twiddle_flag_internal("FLAG",t,f,0)
146 #define clear_flag_internal(t,f) twiddle_flag_internal("FLAG",t,f,1)
147 #define set_power_internal(t,f) twiddle_flag_internal("POWER",t,f,0)
148 #define clear_power_internal(t,f) twiddle_flag_internal("POWER",t,f,1)
149
150 /*---------------------------------------------------------------------
151  * Object types (no longer part of the flags)
152  */
153
154 #define TYPE_ROOM       0x1
155 #define TYPE_THING      0x2
156 #define TYPE_EXIT       0x4
157 #define TYPE_PLAYER     0x8
158 #define TYPE_GARBAGE    0x10
159 #define TYPE_MARKED     0x20
160 #define NOTYPE          0xFFFF
161
162
163
164 /*--------------------------------------------------------------------------
165  * Flag permissions
166  */
167
168 #define F_ANY           0x10U    /**< can be set by anyone - obsolete now */
169 #define F_INHERIT       0x20U    /**< must pass inherit check */
170 #define F_OWNED         0x40U    /**< can be set on owned objects */
171 #define F_ROYAL         0x80U    /**< can only be set by royalty */
172 #define F_WIZARD        0x100U   /**< can only be set by wizards */
173 #define F_GOD           0x200U   /**< can only be set by God */
174 #define F_INTERNAL      0x400U   /**< only the game can set this */
175 #define F_DARK          0x800U   /**< only God can see this flag */
176 #define F_MDARK         0x1000U  /**< admin/God can see this flag */
177 #define F_ODARK         0x2000U  /**< owner/admin/God can see this flag */
178 #define F_DISABLED      0x4000U  /**< flag can't be used */
179 #define F_LOG           0x8000U  /**< Log when the flag is set/cleared */
180
181 #define F_MAX           0x00800000U /**< Largest allowed flag bit */
182
183
184 /* Flags can be in the flaglist multiple times, thanks to aliases. Keep
185    a reference count of how many times, and free memory when it goes to 0. */
186 #define F_REF_MASK      0xFF000000U /**< Mask to get the reference count */
187 #define F_REF_NOT       0x00FFFFFFU /**< Everything but */
188 #define FLAG_REF(r)     (((r) & F_REF_MASK) >> 30)
189 #define ZERO_FLAG_REF(r) ((r) & F_REF_NOT)
190 #define INCR_FLAG_REF(r) ((r) + (1 << 30))
191 #define DECR_FLAG_REF(r) ((r) - (1 << 30))
192
193
194 /*--------------------------------------------------------------------------
195  * Powers table
196  */
197
198 #define CAN_BUILD       0x10    /* can use builder commands */
199 #define TEL_ANYWHERE    0x20    /* teleport self anywhere */
200 #define TEL_OTHER       0x40    /* teleport someone else */
201 #define SEE_ALL         0x80    /* can examine all and use priv WHO */
202 #define NO_PAY          0x100   /* Needs no money */
203 #define CHAT_PRIVS      0x200   /* can use restricted channels */
204 #define CAN_HIDE        0x400   /* can go DARK on the WHO list */
205 #define LOGIN_ANYTIME   0x800   /* not affected by restricted logins */
206 #define UNLIMITED_IDLE  0x1000  /* no inactivity timeout */
207 #define LONG_FINGERS    0x2000  /* can grab stuff remotely */
208 #define CAN_BOOT        0x4000  /* can boot off players */
209 #define CHANGE_QUOTAS   0x8000  /* can change other players' quotas */
210 #define SET_POLL        0x10000 /* can change the poll */
211 #define HUGE_QUEUE      0x20000 /* queue limit of db_top + 1 */
212 #define PS_ALL          0x40000 /* look at anyone's queue */
213 #define HALT_ANYTHING   0x80000 /* do @halt on others, and @allhalt */
214 #define SEARCH_EVERYTHING  0x100000     /* @stats, @search, @entrances all */
215 #define GLOBAL_FUNCS    0x200000        /* add global functions */
216 #define CREATE_PLAYER   0x400000        /* @pcreate */
217 #define IS_GUEST        0x800000        /* Guest, restrict access */
218 #define CAN_WALL        0x1000000       /* @wall */
219 #define CEMIT           0x2000000       /* Was: Can @cemit */
220 #define UNKILLABLE      0x4000000       /* Cannot be killed */
221 #define PEMIT_ALL       0x8000000       /* Can @pemit to HAVEN players */
222 #define NO_QUOTA        0x10000000      /* Has no quota restrictions */
223 #define LINK_ANYWHERE   0x20000000      /* Can @link an exit to any room */
224 #define OPEN_ANYWHERE   0x40000000      /* Can @open an exit from any room */
225 #define CAN_NSPEMIT     0x80000000      /* Can use @nspemit and nspemit() */
226
227 /* These powers are obsolete, but are kept around to implement
228  * DBF_SPLIT_IMMORTAL
229  */
230 #define CAN_DEBUG       0x4000000       /* Can set/unset the debug flag */
231 #define IMMORTAL        0x100   /* cannot be killed, uses no money */
232 #endif                          /* __FLAGS_H */
Note: See TracBrowser for help on using the browser.