-
Notifications
You must be signed in to change notification settings - Fork 0
/
move.c
333 lines (293 loc) · 8.35 KB
/
move.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
329
330
331
332
333
#include <stdlib.h>
#include "copyright.h"
#include "db.h"
#include "config.h"
#include "interface.h"
#include "match.h"
#include "externs.h"
void moveto(dbref what, dbref where)
{
dbref loc;
/* remove what from old loc */
if((loc = db[what].location) != NOTHING) {
db[loc].contents = remove_first(db[loc].contents, what);
}
/* test for special cases */
switch(where) {
case NOTHING:
db[what].location = NOTHING;
return; /* NOTHING doesn't have contents */
case HOME:
where = db[what].exits; /* home */
break;
}
/* now put what in where */
PUSH(what, db[where].contents);
db[what].location = where;
}
static void send_contents(dbref loc, dbref dest)
{
dbref first;
dbref rest;
first = db[loc].contents;
db[loc].contents = NOTHING;
/* blast locations of everything in list */
DOLIST(rest, first) {
db[rest].location = NOTHING;
}
while(first != NOTHING) {
rest = db[first].next;
if(Typeof(first) != TYPE_THING) {
moveto(first, loc);
} else {
moveto(first, (db[first].flags & STICKY) ? HOME : dest);
}
first = rest;
}
db[loc].contents = reverse(db[loc].contents);
}
void maybe_dropto(dbref loc, dbref dropto)
{
dbref thing;
if(loc == dropto) return; /* bizarre special case */
/* check for players */
DOLIST(thing, db[loc].contents) {
if(Typeof(thing) == TYPE_PLAYER) return;
}
/* no players, send everything to the dropto */
send_contents(loc, dropto);
}
void enter_room(dbref player, dbref loc)
{
dbref old;
dbref dropto;
char buf[BUFFER_LEN];
/* check for room == HOME */
if(loc == HOME) loc = db[player].exits; /* home */
/* get old location */
old = db[player].location;
/* check for self-loop */
/* self-loops don't do move or other player notification */
/* but you still get autolook and penny check */
if(loc != old) {
if(old != NOTHING) {
/* notify others unless DARK */
if(!Dark(old) && !Dark(player)) {
sprintf(buf, "%s has left.", db[player].name);
notify_except(db[old].contents, player, buf);
}
}
/* go there */
moveto(player, loc);
/* if old location has STICKY dropto, send stuff through it */
if(old != NOTHING
&& (dropto = db[old].location) != NOTHING
&& (db[old].flags & STICKY)) {
maybe_dropto(old, dropto);
}
/* tell other folks in new location if not DARK */
if(!Dark(loc) && !Dark(player)) {
sprintf(buf, "%s has arrived.", db[player].name);
notify_except(db[loc].contents, player, buf);
}
}
/* autolook */
look_room(player, loc);
/* check for pennies */
if(!controls(player, loc)
&& db[player].pennies <= MAX_PENNIES
&& random() % PENNY_RATE == 0) {
notify(player, "You found a penny!");
db[player].pennies++;
}
}
void send_home(dbref thing)
{
switch(Typeof(thing)) {
case TYPE_PLAYER:
/* send his possessions home first! */
/* that way he sees them when he arrives */
send_contents(thing, HOME);
enter_room(thing, db[thing].exits); /* home */
break;
case TYPE_THING:
moveto(thing, db[thing].exits); /* home */
break;
default:
/* no effect */
break;
}
}
int can_move(dbref player, const char *direction)
{
if(!string_compare(direction, "home")) return 1;
/* otherwise match on exits */
init_match(player, direction, TYPE_EXIT);
match_exit();
return(last_match_result() != NOTHING);
}
void do_move(dbref player, const char *direction)
{
dbref exit;
dbref loc;
char buf[BUFFER_LEN];
if(!string_compare(direction, "home")) {
/* send him home */
/* but steal all his possessions */
if((loc = db[player].location) != NOTHING) {
/* tell everybody else */
sprintf(buf, "%s goes home.", db[player].name);
notify_except(db[loc].contents, player, buf);
}
/* give the player the messages */
notify(player, "There's no place like home...");
notify(player, "There's no place like home...");
notify(player, "There's no place like home...");
notify(player, "You wake up back home, without your possessions.");
send_home(player);
} else {
/* find the exit */
init_match_check_keys(player, direction, TYPE_EXIT);
match_exit();
switch(exit = match_result()) {
case NOTHING:
notify(player, "You can't go that way.");
break;
case AMBIGUOUS:
notify(player, "I don't know which way you mean!");
break;
default:
/* we got one */
/* check to see if we got through */
if(can_doit(player, exit, "You can't go that way.")) {
enter_room(player, db[exit].location);
}
break;
}
}
}
void do_get(dbref player, const char *what)
{
dbref loc;
dbref thing;
init_match_check_keys(player, what, TYPE_THING);
match_neighbor();
match_exit();
if(Wizard(player)) match_absolute(); /* the wizard has long fingers */
if((thing = noisy_match_result()) != NOTHING) {
if(db[thing].location == player) {
notify(player, "You already have that!");
return;
}
switch(Typeof(thing)) {
case TYPE_THING:
if(can_doit(player, thing, "You can't pick that up.")) {
moveto(thing, player);
notify(player, "Taken.");
}
break;
case TYPE_EXIT:
if(!controls(player, thing)) {
notify(player, "You can't pick that up.");
} else if(db[thing].location != NOTHING) {
notify(player, "You can't pick up a linked exit.");
#ifdef RESTRICTED_BUILDING
} else if(!Builder(player)) {
notify(player, "Only authorized builders may pick up exits.");
#endif /* RESTRICTED_BUILDING */
} else {
/* take it out of location */
if((loc = getloc(player)) == NOTHING) return;
if(!member(thing, db[loc].exits)) {
notify(player,
"You can't pick up an exit from another room.");
return;
}
db[loc].exits = remove_first(db[loc].exits, thing);
PUSH(thing, db[player].contents);
db[thing].location = player;
notify(player, "Exit taken.");
}
break;
default:
notify(player, "You can't take that!");
break;
}
}
}
void do_drop(dbref player, const char *name)
{
dbref loc;
dbref thing;
char buf[BUFFER_LEN];
int reward;
if((loc = getloc(player)) == NOTHING) return;
init_match(player, name, TYPE_THING);
match_possession();
switch(thing = match_result()) {
case NOTHING:
notify(player, "You don't have that!");
break;
case AMBIGUOUS:
notify(player, "I don't know which you mean!");
break;
default:
if(db[thing].location != player &&
!(Typeof(thing) == TYPE_EXIT) && db[thing].location == NOTHING) {
/* Should not ever happen. */
notify(player, "You can't drop that.");
} else if(Typeof(thing) == TYPE_EXIT) {
/* special behavior for exits */
if(!controls(player, loc)) {
notify(player, "You can't put an exit down here.");
return;
}
/* else we can put it down */
moveto(thing, NOTHING); /* take it out of the pack */
PUSH(thing, db[loc].exits);
notify(player, "Exit dropped.");
} else if(db[loc].flags & TEMPLE) {
/* sacrifice time */
send_home(thing);
sprintf(buf,
"%s is consumed in a burst of flame!", db[thing].name);
notify(player, buf);
#ifndef TINKER
sprintf(buf, "%s sacrifices %s.", db[player].name, db[thing].name);
#else TINKER
sprintf(buf, "%s donates %s.", db[player].name, db[thing].name);
#endif TINKER
notify_except(db[loc].contents, player, buf);
/* check for reward */
if(!controls(player, thing)) {
reward = db[thing].pennies;
if(reward < 1 || db[player].pennies > MAX_PENNIES) {
reward = 1;
} else if(reward > MAX_OBJECT_ENDOWMENT) {
reward = MAX_OBJECT_ENDOWMENT;
}
db[player].pennies += reward;
sprintf(buf,
"You have received %d %s for your donation.",
reward,
reward == 1 ? "penny" : "pennies");
notify(player, buf);
}
} else if(db[thing].flags & STICKY) {
send_home(thing);
notify(player, "Dropped.");
} else if(db[loc].location != NOTHING && !(db[loc].flags & STICKY)) {
/* location has immediate dropto */
moveto(thing, db[loc].location);
notify(player, "Dropped.");
} else if((db[thing].flags & DARK) && !can_link_to(player,Typeof(thing),loc)) {
notify(player, "You cannot drop that DARK object here.");
} else {
moveto(thing, loc);
notify(player, "Dropped.");
sprintf(buf, "%s dropped %s.", db[player].name, db[thing].name);
notify_except(db[loc].contents, player, buf);
}
break;
}
}