-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.h
176 lines (136 loc) · 5.57 KB
/
db.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "copyright.h"
#ifndef __DB_H
#define __DB_H
#include <stdio.h>
extern void *malloc(unsigned long);
extern void *realloc(void *, unsigned long);
extern void free(void *);
#ifdef TEST_MALLOC
extern int malloc_count;
#define malloc(x) (malloc_count++, malloc(x))
#define free(x) (malloc_count--, free(x))
#endif /* TEST_MALLOC */
typedef int dbref; /* offset into db */
#define TYPE_ROOM 0x0
#define TYPE_THING 0x1
#define TYPE_EXIT 0x2
#define TYPE_PLAYER 0x3
#define NOTYPE 0x7 /* no particular type */
#define TYPE_MASK 0x7 /* room for expansion */
#define ANTILOCK 0x8 /* negates key (*OBSOLETE*) */
#define WIZARD 0x10 /* gets automatic control */
#define LINK_OK 0x20 /* anybody can link exits to this room */
#define DARK 0x40 /* contents of room are not printed */
#define TEMPLE 0x80 /* objects dropped in this room go home */
#define STICKY 0x100 /* this object goes home when dropped */
#ifdef RESTRICTED_BUILDING
#define BUILDER 0x200 /* this player can use construction commands */
#endif /* RESTRICTED_BUILDING */
#define HAVEN 0x400 /* this room prohibits killing */
#define ABODE 0x800 /* can link objects or players here */
#ifdef GENDER
#define GENDER_MASK 0x3000 /* 2 bits of gender */
#define GENDER_SHIFT 12 /* 0x1000 is 12 bits over (for shifting) */
#define GENDER_UNASSIGNED 0x0 /* unassigned - the default */
#define GENDER_NEUTER 0x1 /* neuter */
#define GENDER_FEMALE 0x2 /* for women */
#define GENDER_MALE 0x3 /* for men */
#ifdef ROBOT_MODE
#define ROBOT 0x4000 /* Can set OUTPUTPREFIX */
#endif ROBOT_MODE
#define UNWANTED 0x8000 /* can be chowned */
#define TABULAR_WHO 0x10000
#define REVERSED_WHO 0x20000
#define Genderof(x) ((db[(x)].flags & GENDER_MASK) >> GENDER_SHIFT)
#endif /* GENDER */
typedef int object_flag_type;
#define Flag(x,f) ((db[(x)].flags & (f)) != 0)
#define Typeof(x) (db[(x)].flags & TYPE_MASK)
#define Wizard(x) ((db[(x)].flags & WIZARD) != 0)
#ifdef ROBOT_MODE
#define Robot(x) ((db[(x)].flags & ROBOT) != 0)
#endif ROBOT_MODE
#define Dark(x) ((db[(x)].flags & DARK) != 0)
#ifdef GOD_PRIV
#define GOD ((dbref)1)
#define God(x) ((x)==GOD)
#endif GOD_PRIV
#ifdef RECYCLE
#define RECYCLER "Recycler"
#endif
#ifdef RESTRICTED_BUILDING
#define Builder(x) ((db[(x)].flags & (WIZARD|BUILDER)) != 0)
#endif /* RESTRICTED_BUILDING */
/* Boolean expressions, for locks */
typedef char boolexp_type;
#define BOOLEXP_AND 0
#define BOOLEXP_OR 1
#define BOOLEXP_NOT 2
#define BOOLEXP_CONST 3
struct boolexp {
boolexp_type type;
struct boolexp *sub1;
struct boolexp *sub2;
dbref thing;
};
#define TRUE_BOOLEXP ((struct boolexp *) 0)
/* special dbref's */
#define NOTHING (-1) /* null dbref */
#define AMBIGUOUS (-2) /* multiple possibilities, for matchers */
#define HOME (-3) /* virtual room, represents mover's home */
struct object {
const char *name;
const char *description;
dbref location; /* pointer to container */
/* for exits, pointer to destination */
dbref contents; /* pointer to first item */
dbref exits; /* pointer to first exit for rooms */
/* pointer to home for things and players */
dbref next; /* pointer to next in contents/exits chain */
/* the following are used for pickups for things, entry for exits */
struct boolexp *key; /* if not NOTHING, must have this to do op */
const char *fail_message; /* what you see if op fails */
const char *succ_message; /* what you see if op succeeds */
/* other messages get your name prepended, so if your name is "Foo", */
/* and osuccess = "disappears in a blast of gamma radiation." */
/* then others see "Foo disappears in a blast of gamma radiation." */
/* (At some point I may put in Maven-style %-substitutions.) */
const char *ofail; /* what others see if op fails */
const char *osuccess; /* what others see if op succeeds */
dbref owner; /* who controls this object */
int pennies; /* number of pennies object contains */
object_flag_type flags;
const char *password; /* password for players */
};
extern struct object *db;
extern dbref db_top;
extern const char *alloc_string(const char *s);
extern dbref new_object(); /* return a new object */
extern dbref getref (FILE *); /* Read a database reference from a file. */
extern void putref (FILE *, dbref); /* Write one ref to the file */
extern struct boolexp *getboolexp(FILE *); /* get a boolexp */
extern void putboolexp(FILE *, struct boolexp *); /* put a boolexp */
extern int db_write_object(FILE *, dbref); /* write one object to file */
extern dbref db_write(FILE *f); /* write db to file, return # of objects */
extern dbref db_read(FILE *f); /* read db from file, return # of objects */
/* Warning: destroys existing db contents! */
extern void free_boolexp(struct boolexp *);
extern void db_free(void);
extern dbref parse_dbref(const char *); /* parse a dbref */
#define DOLIST(var, first) \
for((var) = (first); (var) != NOTHING; (var) = db[(var)].next)
#define PUSH(thing, locative) \
((db[(thing)].next = (locative)), (locative) = (thing))
#define getloc(thing) (db[thing].location)
/*
Usage guidelines:
To refer to objects use db[object_ref]. Pointers to objects may
become invalid after a call to new_object().
The programmer is responsible for managing storage for string
components of entries; db_read will produce malloc'd strings. The
alloc_string routine is provided for generating malloc'd strings
duplicates of other strings. Note that db_free and db_read will
attempt to free any non-NULL string that exists in db when they are
invoked.
*/
#endif /* __DB_H */