-
Notifications
You must be signed in to change notification settings - Fork 0
/
look.c
328 lines (292 loc) · 7.63 KB
/
look.c
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include "copyright.h"
/* commands which look at things */
#include "db.h"
#include "config.h"
#include "interface.h"
#include "match.h"
#include "externs.h"
static void look_contents(dbref player, dbref loc, const char *contents_name)
{
dbref thing;
dbref can_see_loc;
/* check to see if he can see the location */
can_see_loc = (!Dark(loc) || controls(player, loc));
/* check to see if there is anything there */
DOLIST(thing, db[loc].contents) {
if(can_see(player, thing, can_see_loc)) {
/* something exists! show him everything */
notify(player, contents_name);
DOLIST(thing, db[loc].contents) {
if(can_see(player, thing, can_see_loc)) {
notify(player, unparse_object(player, thing));
}
}
break; /* we're done */
}
}
}
static void look_simple(dbref player, dbref thing)
{
if(db[thing].description) {
notify(player, db[thing].description);
} else {
notify(player, "You see nothing special.");
}
}
void look_room(dbref player, dbref loc)
{
/* tell him the name, and the number if he can link to it */
notify(player, unparse_object(player, loc));
/* tell him the description */
if(db[loc].description) notify(player, db[loc].description);
/* tell him the appropriate messages if he has the key */
can_doit(player, loc, 0);
/* tell him the contents */
look_contents(player, loc, "Contents:");
}
void do_look_around(dbref player)
{
dbref loc;
if((loc = getloc(player)) == NOTHING) return;
look_room(player, loc);
}
void do_look_at(dbref player, const char *name)
{
dbref thing;
if(*name == '\0') {
if((thing = getloc(player)) != NOTHING) {
look_room(player, thing);
}
} else {
/* look at a thing here */
init_match(player, name, NOTYPE);
match_exit();
match_neighbor();
match_possession();
if(Wizard(player)) {
match_absolute();
match_player();
}
match_here();
match_me();
if((thing = noisy_match_result()) != NOTHING) {
switch(Typeof(thing)) {
case TYPE_ROOM:
look_room(player, thing);
break;
case TYPE_PLAYER:
look_simple(player, thing);
look_contents(player, thing, "Carrying:");
break;
default:
look_simple(player, thing);
break;
}
}
}
}
#if 0
static const char *flag_description(dbref thing)
{
static char buf[BUFFER_LEN];
strcpy(buf, "Type: ");
switch(Typeof(thing)) {
case TYPE_ROOM:
strcat(buf, "Room");
break;
case TYPE_EXIT:
strcat(buf, "Exit");
break;
case TYPE_THING:
strcat(buf, "Thing");
break;
case TYPE_PLAYER:
strcat(buf, "Player");
break;
default:
strcat(buf, "***UNKNOWN TYPE***");
break;
}
if(db[thing].flags & ~TYPE_MASK) {
/* print flags */
strcat(buf, " Flags:");
if(db[thing].flags & WIZARD) strcat(buf, " WIZARD");
if(db[thing].flags & STICKY) strcat(buf, " STICKY");
if(db[thing].flags & DARK) strcat(buf, " DARK");
if(db[thing].flags & LINK_OK) strcat(buf, " LINK_OK");
if(db[thing].flags & TEMPLE) strcat(buf, " TEMPLE");
#ifdef RESTRICTED_BUILDING
if(db[thing].flags & BUILDER) strcat(buf, " BUILDER");
#endif /* RESTRICTED_BUILDING */
}
return buf;
}
#endif /* 0 */
void do_examine(dbref player, const char *name)
{
dbref thing;
dbref content;
dbref exit;
char buf[BUFFER_LEN];
if(*name == '\0') {
if((thing = getloc(player)) == NOTHING) return;
} else {
/* look it up */
init_match(player, name, NOTYPE);
match_exit();
match_neighbor();
match_possession();
match_absolute();
/* only Wizards can examine other players */
if(Wizard(player)) match_player();
match_here();
match_me();
/* get result */
if((thing = noisy_match_result()) == NOTHING) return;
}
if(!can_link(player, thing)) {
sprintf(buf, "Owner: %s", db[db[thing].owner].name);
notify(player, buf);
if(db[thing].description) notify(player, db[thing].description);
return;
}
notify(player, unparse_object(player, thing));
sprintf(buf, "Owner: %s Key: %s Pennies: %d",
db[db[thing].owner].name,
unparse_boolexp(player, db[thing].key),
db[thing].pennies);
notify(player, buf);
if(db[thing].description) notify(player, db[thing].description);
if(db[thing].fail_message) {
sprintf(buf, "Fail: %s", db[thing].fail_message);
notify(player, buf);
}
if(db[thing].succ_message) {
sprintf(buf, "Success: %s", db[thing].succ_message);
notify(player, buf);
}
if(db[thing].ofail) {
sprintf(buf, "Ofail: %s", db[thing].ofail);
notify(player, buf);
}
if(db[thing].osuccess) {
sprintf(buf, "Osuccess: %s", db[thing].osuccess);
notify(player, buf);
}
/* show him the contents */
if(db[thing].contents != NOTHING) {
notify(player, "Contents:");
DOLIST(content, db[thing].contents) {
notify(player, unparse_object(player, content));
}
}
switch(Typeof(thing)) {
case TYPE_ROOM:
/* tell him about exits */
if(db[thing].exits != NOTHING) {
notify(player, "Exits:");
DOLIST(exit, db[thing].exits) {
notify(player, unparse_object(player, exit));
}
} else {
notify(player, "No exits.");
}
/* print dropto if present */
if(db[thing].location != NOTHING) {
sprintf(buf, "Dropped objects go to: %s",
unparse_object(player, db[thing].location));
notify(player, buf);
}
break;
case TYPE_THING:
case TYPE_PLAYER:
/* print home */
sprintf(buf, "Home: %s",
unparse_object(player, db[thing].exits)); /* home */
notify(player, buf);
/* print location if player can link to it */
if(db[thing].location != NOTHING
&& (controls(player, db[thing].location)
|| can_link_to(player, Typeof(thing), db[thing].location))) {
sprintf(buf, "Location: %s",
unparse_object(player, db[thing].location));
notify(player, buf);
}
break;
case TYPE_EXIT:
/* print destination */
switch(db[thing].location) {
case NOTHING:
break;
case HOME:
notify(player, "Destination: *HOME*");
break;
default:
sprintf(buf, "%s: %s",
(Typeof(db[thing].location) == TYPE_ROOM
? "Destination" : "Carried by"),
unparse_object(player, db[thing].location));
notify(player, buf);
break;
}
break;
default:
/* do nothing */
break;
}
}
void do_score(dbref player)
{
char buf[BUFFER_LEN];
sprintf(buf, "You have %d %s.",
db[player].pennies,
db[player].pennies == 1 ? "penny" : "pennies");
notify(player, buf);
}
void do_inventory(dbref player)
{
dbref thing;
if((thing = db[player].contents) == NOTHING) {
notify(player, "You aren't carrying anything.");
} else {
notify(player, "You are carrying:");
DOLIST(thing, thing) {
notify(player, unparse_object(player, thing));
}
}
do_score(player);
}
void do_find(dbref player, const char *name)
{
dbref i;
if(!payfor(player, FIND_COST)) {
notify(player, "You don't have enough pennies.");
} else {
for(i = 0; i < db_top; i++) {
if(Typeof(i) != TYPE_EXIT
&& controls(player, i)
&& (!*name || string_match(db[i].name, name))) {
notify(player, unparse_object(player, i));
}
}
notify(player, "***End of List***");
}
}
void do_owned(dbref player, const char *sowner)
{
dbref owner,i;
if(!Wizard(player)) {
#ifndef TINKER
notify(player,"Only a Wizard can check the ownership list. Use @find.");
#else TINKER
notify(player,"Only a Tinker can check the ownership list. Use @find.");
#endif TINKER
} else if ((owner = lookup_player(sowner)) == NOTHING) {
notify(player,"I couldn't find that player.");
} else {
for(i = 0; i < db_top; i++)
if(Typeof(i) != TYPE_EXIT && db[i].owner == owner)
notify(player, unparse_object(player, i));
notify(player, "***End of List***");
}
}