forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtravel.c
More file actions
executable file
·336 lines (318 loc) · 6.6 KB
/
Copy pathtravel.c
File metadata and controls
executable file
·336 lines (318 loc) · 6.6 KB
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
334
335
336
/* module TRAVEL.C *
* Routine to handle motion requests */
#include <stdio.h>
#include <stdlib.h>
#include "advent.h"
#include "advdec.h"
#include "advcave.h"
struct trav travel[MAXTRAV];
static int kalflg;
static int bcrossing = 0;
static int phuce[2][4] = {158, 160, 167, 166,
160, 158, 166, 167};
_PROTOTYPE(static void goback, (void));
_PROTOTYPE(static void ck_kal, (void));
_PROTOTYPE(static void dotrav, (void));
_PROTOTYPE(static void badmove, (void));
_PROTOTYPE(static void spcmove, (int rdest));
void domove()
{
gettrav(g.loc, travel);
switch (motion) {
case NULLX:
break;
case BACK:
goback();
break;
case CAVE:
if (outside(g.loc))
rspeak(57);
else
rspeak(58);
break;
default:
g.oldloc2 = g.oldloc;
g.oldloc = g.loc;
dotrav();
}
newtravel = TRUE;
return;
}
/*
Routine to handle request to return
from whence we came!
*/
static void goback()
{
int kk, k2, want, temp;
struct trav strav[MAXTRAV];
want = forced(g.oldloc) ? g.oldloc2 : g.oldloc;
g.oldloc2 = g.oldloc;
g.oldloc = g.loc;
k2 = 0;
if (want == g.loc) {
rspeak(91);
ck_kal();
return;
}
for (kk = 0; travel[kk].tdest != -1; ++kk) {
if (!travel[kk].tcond && travel[kk].tdest == want) {
motion = travel[kk].tverb;
dotrav();
return;
}
if (!travel[kk].tcond) {
temp = travel[kk].tdest;
gettrav(temp, strav);
if (forced(temp) && strav[0].tdest == want)
k2 = temp;
}
}
if (k2) {
motion = travel[k2].tverb;
dotrav();
} else
rspeak(140);
ck_kal();
return;
}
static void ck_kal()
{
if (g.newloc >= 242 && g.newloc <= 247) {
if (g.newloc == 242)
kalflg = 0;
else if (g.newloc == (g.oldloc + 1))
kalflg++;
else
kalflg = -10;
}
}
/*
Routine to figure out a new location
given current location and a motion.
*/
static void dotrav()
{
unsigned char mvflag, hitflag, kk;
int rdest, rverb, rcond, robject;
int pctt;
g.newloc = g.loc;
mvflag = hitflag = 0;
pctt = ranz(100);
for (kk = 0; travel[kk].tdest >= 0 && !mvflag; ++kk) {
rdest = travel[kk].tdest;
rverb = travel[kk].tverb;
rcond = travel[kk].tcond;
robject = rcond % 100;
if ((rverb != 1) && (rverb != motion) && !hitflag)
continue;
++hitflag;
switch (rcond / 100) {
case 0:
if ((rcond == 0) || (pctt < rcond))
++mvflag;
break;
case 1:
if (robject == 0)
++mvflag;
else if (toting(robject))
++mvflag;
break;
case 2:
if (toting(robject) || at(robject))
++mvflag;
break;
case 3:
case 4:
case 5:
case 7:
if (g.prop[robject] != (rcond / 100) - 3)
++mvflag;
break;
default:
bug(37);
}
}
if (!mvflag)
badmove();
else if (rdest > 500)
rspeak(rdest - 500);
else if (rdest > 300)
spcmove(rdest);
else {
g.newloc = rdest;
ck_kal();
}
newtravel = TRUE;
return;
}
/*
The player tried a poor move option.
*/
static void badmove()
{
int msg;
msg = 12;
if (motion >= 43 && motion <= 50)
msg = 9;
if (motion == 29 || motion == 30)
msg = 9;
if (motion == 7 || motion == 36 || motion == 37)
msg = 10;
if (motion == 11 || motion == 19)
msg = 11;
if (motion == 62 || motion == 65 || motion == 82)
msg = 42;
if (motion == 17)
msg = 80;
rspeak(msg);
return;
}
/*
Routine to handle very special movement.
*/
static void spcmove(rdest)
int rdest;
{
int load, obj, k;
switch (rdest - 300) {
case 1: /* plover movement via alcove */
load = burden(0);
if (!load || (load == burden(EMERALD) && holding(EMERALD)))
g.newloc = (99 + 100) - g.loc;
else
rspeak(117);
break;
case 2: /* trying to remove plover, bad
route */
if (enclosed(EMERALD))
extract(EMERALD);
drop(EMERALD, g.loc);
g.newloc = 33;
break;
case 3: /* troll bridge */
if (g.prop[TROLL] == 1) {
pspeak(TROLL, 1);
g.prop[TROLL] = 0;
move(TROLL2, 0);
move((TROLL2 + MAXOBJ), 0);
move(TROLL, plac[TROLL]);
move((TROLL + MAXOBJ), fixd[TROLL]);
juggle(CHASM);
g.newloc = g.loc;
} else {
g.newloc = plac[TROLL] + fixd[TROLL] - g.loc;
if (g.prop[TROLL] == 0)
g.prop[TROLL] = 1;
if (toting(BEAR)) {
rspeak(162);
g.prop[CHASM] = 1;
g.prop[TROLL] = 2;
drop(BEAR, g.newloc);
g.fixed[BEAR] = -1;
g.prop[BEAR] = 3;
if (g.prop[SPICES] < 0)
++g.tally2;
g.oldloc2 = g.newloc;
death();
}
}
break;
case 4:
/* Growing or shrinking in area of tiny door. Each time he
does this, everything must be moved to the new loc.
Presumably, all his possesions are shrunk or streched along
with him. Phuce[2][4] is an array containg four pairs of
"here" (K) and "there" (KK) locations. */
k = phuce[0][g.loc - 161];
g.newloc = phuce[1][g.loc - 161];
for (obj = 1; obj < MAXOBJ; obj++) {
if (obj == BOAT)
continue;
if (g.place[obj] == k && (g.fixed[obj] == 0 || g.fixed[obj] == -1))
move(obj, g.newloc);
}
break;
case 5:
/* Phone booth in rotunda. Trying to shove past gnome, to get
into phone booth. */
if ((g.prop[BOOTH] == 0 && pct(35)) || g.visited[g.loc] == 1) {
rspeak(263);
g.prop[BOOTH] = 1;
move(GNOME, 188);
} else {
if (g.prop[BOOTH] == 1)
rspeak(253);
else
g.newloc = 189;
}
break;
case 6:
/* Collapsing clay bridge. He can cross with three (or fewer)
thing. If more, of if carrying obviously heavy things, he
may end up in the drink. */
g.newloc = g.loc == 235 ? 190 : 235;
bcrossing++;
load = burden(0);
if (load > 4) {
k = (load + bcrossing) * 6 - 10;
if (!pct(k))
rspeak(318);
else {
rspeak(319);
g.newloc = 236;
if (holding(LAMP))
move(LAMP, 236);
if (toting(AXE) && enclosed(AXE))
extract(AXE);
if (holding(AXE))
move(AXE, 208);
for (obj = 1; obj < MAXOBJ; obj++)
if (toting(obj))
destroy(obj);
g.prop[CHASM2] = 1;
}
}
break;
case 7:
/* Kaleidoscope code is here. */
if (kalflg == 5) {
g.newloc = 248;
g.oldloc = 247;
} else {
g.newloc = 242 + ranz(5);
g.oldloc = g.newloc - 1;
kalflg = g.newloc == 242 ? 0 : -10;
}
break;
default:
bug(38);
}
return;
}
/*
Routine to fill travel array for a given location
*/
void gettrav(loc, travel)
int loc;
struct trav *travel;
{
int i;
long t, *lptr;
lptr = cave[loc - 1];
for (i = 0; i < MAXTRAV; i++) {
t = *lptr++;
if (!(t)) {
travel->tdest = -1; /* end of array */
return; /* terminate for loop */
}
travel->tverb = (int) (t % 1000);
t /= 1000;
travel->tdest = (int) (t % 1000);
t /= 1000;
travel->tcond = (int) (t % 1000);
travel++;
}
bug(25);
return;
}