hack.c revision 1.1 1 1.1 cgd /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 1.1 cgd /* hack.c - version 1.0.3 */
3 1.1 cgd
4 1.1 cgd #include "hack.h"
5 1.1 cgd #include <stdio.h>
6 1.1 cgd
7 1.1 cgd extern char news0();
8 1.1 cgd extern char *nomovemsg;
9 1.1 cgd extern char *exclam();
10 1.1 cgd extern struct obj *addinv();
11 1.1 cgd extern boolean hmon();
12 1.1 cgd
13 1.1 cgd /* called on movement:
14 1.1 cgd 1. when throwing ball+chain far away
15 1.1 cgd 2. when teleporting
16 1.1 cgd 3. when walking out of a lit room
17 1.1 cgd */
18 1.1 cgd unsee() {
19 1.1 cgd register x,y;
20 1.1 cgd register struct rm *lev;
21 1.1 cgd
22 1.1 cgd /*
23 1.1 cgd if(u.udispl){
24 1.1 cgd u.udispl = 0;
25 1.1 cgd newsym(u.udisx, u.udisy);
26 1.1 cgd }
27 1.1 cgd */
28 1.1 cgd #ifndef QUEST
29 1.1 cgd if(seehx){
30 1.1 cgd seehx = 0;
31 1.1 cgd } else
32 1.1 cgd #endif QUEST
33 1.1 cgd for(x = u.ux-1; x < u.ux+2; x++)
34 1.1 cgd for(y = u.uy-1; y < u.uy+2; y++) {
35 1.1 cgd if(!isok(x, y)) continue;
36 1.1 cgd lev = &levl[x][y];
37 1.1 cgd if(!lev->lit && lev->scrsym == '.') {
38 1.1 cgd lev->scrsym =' ';
39 1.1 cgd lev->new = 1;
40 1.1 cgd on_scr(x,y);
41 1.1 cgd }
42 1.1 cgd }
43 1.1 cgd }
44 1.1 cgd
45 1.1 cgd /* called:
46 1.1 cgd in hack.eat.c: seeoff(0) - blind after eating rotten food
47 1.1 cgd in hack.mon.c: seeoff(0) - blinded by a yellow light
48 1.1 cgd in hack.mon.c: seeoff(1) - swallowed
49 1.1 cgd in hack.do.c: seeoff(0) - blind after drinking potion
50 1.1 cgd in hack.do.c: seeoff(1) - go up or down the stairs
51 1.1 cgd in hack.trap.c:seeoff(1) - fall through trapdoor
52 1.1 cgd */
53 1.1 cgd seeoff(mode) /* 1 to redo @, 0 to leave them */
54 1.1 cgd { /* 1 means misc movement, 0 means blindness */
55 1.1 cgd register x,y;
56 1.1 cgd register struct rm *lev;
57 1.1 cgd
58 1.1 cgd if(u.udispl && mode){
59 1.1 cgd u.udispl = 0;
60 1.1 cgd levl[u.udisx][u.udisy].scrsym = news0(u.udisx,u.udisy);
61 1.1 cgd }
62 1.1 cgd #ifndef QUEST
63 1.1 cgd if(seehx) {
64 1.1 cgd seehx = 0;
65 1.1 cgd } else
66 1.1 cgd #endif QUEST
67 1.1 cgd if(!mode) {
68 1.1 cgd for(x = u.ux-1; x < u.ux+2; x++)
69 1.1 cgd for(y = u.uy-1; y < u.uy+2; y++) {
70 1.1 cgd if(!isok(x, y)) continue;
71 1.1 cgd lev = &levl[x][y];
72 1.1 cgd if(!lev->lit && lev->scrsym == '.')
73 1.1 cgd lev->seen = 0;
74 1.1 cgd }
75 1.1 cgd }
76 1.1 cgd }
77 1.1 cgd
78 1.1 cgd domove()
79 1.1 cgd {
80 1.1 cgd xchar oldx,oldy;
81 1.1 cgd register struct monst *mtmp;
82 1.1 cgd register struct rm *tmpr,*ust;
83 1.1 cgd struct trap *trap;
84 1.1 cgd register struct obj *otmp;
85 1.1 cgd
86 1.1 cgd u_wipe_engr(rnd(5));
87 1.1 cgd
88 1.1 cgd if(inv_weight() > 0){
89 1.1 cgd pline("You collapse under your load.");
90 1.1 cgd nomul(0);
91 1.1 cgd return;
92 1.1 cgd }
93 1.1 cgd if(u.uswallow) {
94 1.1 cgd u.dx = u.dy = 0;
95 1.1 cgd u.ux = u.ustuck->mx;
96 1.1 cgd u.uy = u.ustuck->my;
97 1.1 cgd } else {
98 1.1 cgd if(Confusion) {
99 1.1 cgd do {
100 1.1 cgd confdir();
101 1.1 cgd } while(!isok(u.ux+u.dx, u.uy+u.dy) ||
102 1.1 cgd IS_ROCK(levl[u.ux+u.dx][u.uy+u.dy].typ));
103 1.1 cgd }
104 1.1 cgd if(!isok(u.ux+u.dx, u.uy+u.dy)){
105 1.1 cgd nomul(0);
106 1.1 cgd return;
107 1.1 cgd }
108 1.1 cgd }
109 1.1 cgd
110 1.1 cgd ust = &levl[u.ux][u.uy];
111 1.1 cgd oldx = u.ux;
112 1.1 cgd oldy = u.uy;
113 1.1 cgd if(!u.uswallow && (trap = t_at(u.ux+u.dx, u.uy+u.dy)) && trap->tseen)
114 1.1 cgd nomul(0);
115 1.1 cgd if(u.ustuck && !u.uswallow && (u.ux+u.dx != u.ustuck->mx ||
116 1.1 cgd u.uy+u.dy != u.ustuck->my)) {
117 1.1 cgd if(dist(u.ustuck->mx, u.ustuck->my) > 2){
118 1.1 cgd /* perhaps it fled (or was teleported or ... ) */
119 1.1 cgd u.ustuck = 0;
120 1.1 cgd } else {
121 1.1 cgd if(Blind) pline("You cannot escape from it!");
122 1.1 cgd else pline("You cannot escape from %s!",
123 1.1 cgd monnam(u.ustuck));
124 1.1 cgd nomul(0);
125 1.1 cgd return;
126 1.1 cgd }
127 1.1 cgd }
128 1.1 cgd if(u.uswallow || (mtmp = m_at(u.ux+u.dx,u.uy+u.dy))) {
129 1.1 cgd /* attack monster */
130 1.1 cgd
131 1.1 cgd nomul(0);
132 1.1 cgd gethungry();
133 1.1 cgd if(multi < 0) return; /* we just fainted */
134 1.1 cgd
135 1.1 cgd /* try to attack; note that it might evade */
136 1.1 cgd if(attack(u.uswallow ? u.ustuck : mtmp))
137 1.1 cgd return;
138 1.1 cgd }
139 1.1 cgd /* not attacking an animal, so we try to move */
140 1.1 cgd if(u.utrap) {
141 1.1 cgd if(u.utraptype == TT_PIT) {
142 1.1 cgd pline("You are still in a pit.");
143 1.1 cgd u.utrap--;
144 1.1 cgd } else {
145 1.1 cgd pline("You are caught in a beartrap.");
146 1.1 cgd if((u.dx && u.dy) || !rn2(5)) u.utrap--;
147 1.1 cgd }
148 1.1 cgd return;
149 1.1 cgd }
150 1.1 cgd tmpr = &levl[u.ux+u.dx][u.uy+u.dy];
151 1.1 cgd if(IS_ROCK(tmpr->typ) ||
152 1.1 cgd (u.dx && u.dy && (tmpr->typ == DOOR || ust->typ == DOOR))){
153 1.1 cgd flags.move = 0;
154 1.1 cgd nomul(0);
155 1.1 cgd return;
156 1.1 cgd }
157 1.1 cgd while(otmp = sobj_at(ENORMOUS_ROCK, u.ux+u.dx, u.uy+u.dy)) {
158 1.1 cgd register xchar rx = u.ux+2*u.dx, ry = u.uy+2*u.dy;
159 1.1 cgd register struct trap *ttmp;
160 1.1 cgd nomul(0);
161 1.1 cgd if(isok(rx,ry) && !IS_ROCK(levl[rx][ry].typ) &&
162 1.1 cgd (levl[rx][ry].typ != DOOR || !(u.dx && u.dy)) &&
163 1.1 cgd !sobj_at(ENORMOUS_ROCK, rx, ry)) {
164 1.1 cgd if(m_at(rx,ry)) {
165 1.1 cgd pline("You hear a monster behind the rock.");
166 1.1 cgd pline("Perhaps that's why you cannot move it.");
167 1.1 cgd goto cannot_push;
168 1.1 cgd }
169 1.1 cgd if(ttmp = t_at(rx,ry))
170 1.1 cgd switch(ttmp->ttyp) {
171 1.1 cgd case PIT:
172 1.1 cgd pline("You push the rock into a pit!");
173 1.1 cgd deltrap(ttmp);
174 1.1 cgd delobj(otmp);
175 1.1 cgd pline("It completely fills the pit!");
176 1.1 cgd continue;
177 1.1 cgd case TELEP_TRAP:
178 1.1 cgd pline("You push the rock and suddenly it disappears!");
179 1.1 cgd delobj(otmp);
180 1.1 cgd continue;
181 1.1 cgd }
182 1.1 cgd if(levl[rx][ry].typ == POOL) {
183 1.1 cgd levl[rx][ry].typ = ROOM;
184 1.1 cgd mnewsym(rx,ry);
185 1.1 cgd prl(rx,ry);
186 1.1 cgd pline("You push the rock into the water.");
187 1.1 cgd pline("Now you can cross the water!");
188 1.1 cgd delobj(otmp);
189 1.1 cgd continue;
190 1.1 cgd }
191 1.1 cgd otmp->ox = rx;
192 1.1 cgd otmp->oy = ry;
193 1.1 cgd /* pobj(otmp); */
194 1.1 cgd if(cansee(rx,ry)) atl(rx,ry,otmp->olet);
195 1.1 cgd if(Invisible) newsym(u.ux+u.dx, u.uy+u.dy);
196 1.1 cgd
197 1.1 cgd { static long lastmovetime;
198 1.1 cgd /* note: this var contains garbage initially and
199 1.1 cgd after a restore */
200 1.1 cgd if(moves > lastmovetime+2 || moves < lastmovetime)
201 1.1 cgd pline("With great effort you move the enormous rock.");
202 1.1 cgd lastmovetime = moves;
203 1.1 cgd }
204 1.1 cgd } else {
205 1.1 cgd pline("You try to move the enormous rock, but in vain.");
206 1.1 cgd cannot_push:
207 1.1 cgd if((!invent || inv_weight()+90 <= 0) &&
208 1.1 cgd (!u.dx || !u.dy || (IS_ROCK(levl[u.ux][u.uy+u.dy].typ)
209 1.1 cgd && IS_ROCK(levl[u.ux+u.dx][u.uy].typ)))){
210 1.1 cgd pline("However, you can squeeze yourself into a small opening.");
211 1.1 cgd break;
212 1.1 cgd } else
213 1.1 cgd return;
214 1.1 cgd }
215 1.1 cgd }
216 1.1 cgd if(u.dx && u.dy && IS_ROCK(levl[u.ux][u.uy+u.dy].typ) &&
217 1.1 cgd IS_ROCK(levl[u.ux+u.dx][u.uy].typ) &&
218 1.1 cgd invent && inv_weight()+40 > 0) {
219 1.1 cgd pline("You are carrying too much to get through.");
220 1.1 cgd nomul(0);
221 1.1 cgd return;
222 1.1 cgd }
223 1.1 cgd if(Punished &&
224 1.1 cgd DIST(u.ux+u.dx, u.uy+u.dy, uchain->ox, uchain->oy) > 2){
225 1.1 cgd if(carried(uball)) {
226 1.1 cgd movobj(uchain, u.ux, u.uy);
227 1.1 cgd goto nodrag;
228 1.1 cgd }
229 1.1 cgd
230 1.1 cgd if(DIST(u.ux+u.dx, u.uy+u.dy, uball->ox, uball->oy) < 3){
231 1.1 cgd /* leave ball, move chain under/over ball */
232 1.1 cgd movobj(uchain, uball->ox, uball->oy);
233 1.1 cgd goto nodrag;
234 1.1 cgd }
235 1.1 cgd
236 1.1 cgd if(inv_weight() + (int) uball->owt/2 > 0) {
237 1.1 cgd pline("You cannot %sdrag the heavy iron ball.",
238 1.1 cgd invent ? "carry all that and also " : "");
239 1.1 cgd nomul(0);
240 1.1 cgd return;
241 1.1 cgd }
242 1.1 cgd
243 1.1 cgd movobj(uball, uchain->ox, uchain->oy);
244 1.1 cgd unpobj(uball); /* BAH %% */
245 1.1 cgd uchain->ox = u.ux;
246 1.1 cgd uchain->oy = u.uy;
247 1.1 cgd nomul(-2);
248 1.1 cgd nomovemsg = "";
249 1.1 cgd nodrag: ;
250 1.1 cgd }
251 1.1 cgd u.ux += u.dx;
252 1.1 cgd u.uy += u.dy;
253 1.1 cgd if(flags.run) {
254 1.1 cgd if(tmpr->typ == DOOR ||
255 1.1 cgd (xupstair == u.ux && yupstair == u.uy) ||
256 1.1 cgd (xdnstair == u.ux && ydnstair == u.uy))
257 1.1 cgd nomul(0);
258 1.1 cgd }
259 1.1 cgd
260 1.1 cgd if(tmpr->typ == POOL && !Levitation)
261 1.1 cgd drown(); /* not necessarily fatal */
262 1.1 cgd
263 1.1 cgd /*
264 1.1 cgd if(u.udispl) {
265 1.1 cgd u.udispl = 0;
266 1.1 cgd newsym(oldx,oldy);
267 1.1 cgd }
268 1.1 cgd */
269 1.1 cgd if(!Blind) {
270 1.1 cgd #ifdef QUEST
271 1.1 cgd setsee();
272 1.1 cgd #else
273 1.1 cgd if(ust->lit) {
274 1.1 cgd if(tmpr->lit) {
275 1.1 cgd if(tmpr->typ == DOOR)
276 1.1 cgd prl1(u.ux+u.dx,u.uy+u.dy);
277 1.1 cgd else if(ust->typ == DOOR)
278 1.1 cgd nose1(oldx-u.dx,oldy-u.dy);
279 1.1 cgd } else {
280 1.1 cgd unsee();
281 1.1 cgd prl1(u.ux+u.dx,u.uy+u.dy);
282 1.1 cgd }
283 1.1 cgd } else {
284 1.1 cgd if(tmpr->lit) setsee();
285 1.1 cgd else {
286 1.1 cgd prl1(u.ux+u.dx,u.uy+u.dy);
287 1.1 cgd if(tmpr->typ == DOOR) {
288 1.1 cgd if(u.dy) {
289 1.1 cgd prl(u.ux-1,u.uy);
290 1.1 cgd prl(u.ux+1,u.uy);
291 1.1 cgd } else {
292 1.1 cgd prl(u.ux,u.uy-1);
293 1.1 cgd prl(u.ux,u.uy+1);
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd }
297 1.1 cgd nose1(oldx-u.dx,oldy-u.dy);
298 1.1 cgd }
299 1.1 cgd #endif QUEST
300 1.1 cgd } else {
301 1.1 cgd pru();
302 1.1 cgd }
303 1.1 cgd if(!flags.nopick) pickup(1);
304 1.1 cgd if(trap) dotrap(trap); /* fall into pit, arrow trap, etc. */
305 1.1 cgd (void) inshop();
306 1.1 cgd if(!Blind) read_engr_at(u.ux,u.uy);
307 1.1 cgd }
308 1.1 cgd
309 1.1 cgd movobj(obj, ox, oy)
310 1.1 cgd register struct obj *obj;
311 1.1 cgd register int ox, oy;
312 1.1 cgd {
313 1.1 cgd /* Some dirty programming to get display right */
314 1.1 cgd freeobj(obj);
315 1.1 cgd unpobj(obj);
316 1.1 cgd obj->nobj = fobj;
317 1.1 cgd fobj = obj;
318 1.1 cgd obj->ox = ox;
319 1.1 cgd obj->oy = oy;
320 1.1 cgd }
321 1.1 cgd
322 1.1 cgd dopickup(){
323 1.1 cgd if(!g_at(u.ux,u.uy) && !o_at(u.ux,u.uy)) {
324 1.1 cgd pline("There is nothing here to pick up.");
325 1.1 cgd return(0);
326 1.1 cgd }
327 1.1 cgd if(Levitation) {
328 1.1 cgd pline("You cannot reach the floor.");
329 1.1 cgd return(1);
330 1.1 cgd }
331 1.1 cgd pickup(0);
332 1.1 cgd return(1);
333 1.1 cgd }
334 1.1 cgd
335 1.1 cgd pickup(all)
336 1.1 cgd {
337 1.1 cgd register struct gold *gold;
338 1.1 cgd register struct obj *obj, *obj2;
339 1.1 cgd register int wt;
340 1.1 cgd
341 1.1 cgd if(Levitation) return;
342 1.1 cgd while(gold = g_at(u.ux,u.uy)) {
343 1.1 cgd pline("%ld gold piece%s.", gold->amount, plur(gold->amount));
344 1.1 cgd u.ugold += gold->amount;
345 1.1 cgd flags.botl = 1;
346 1.1 cgd freegold(gold);
347 1.1 cgd if(flags.run) nomul(0);
348 1.1 cgd if(Invisible) newsym(u.ux,u.uy);
349 1.1 cgd }
350 1.1 cgd
351 1.1 cgd /* check for more than one object */
352 1.1 cgd if(!all) {
353 1.1 cgd register int ct = 0;
354 1.1 cgd
355 1.1 cgd for(obj = fobj; obj; obj = obj->nobj)
356 1.1 cgd if(obj->ox == u.ux && obj->oy == u.uy)
357 1.1 cgd if(!Punished || obj != uchain)
358 1.1 cgd ct++;
359 1.1 cgd if(ct < 2)
360 1.1 cgd all++;
361 1.1 cgd else
362 1.1 cgd pline("There are several objects here.");
363 1.1 cgd }
364 1.1 cgd
365 1.1 cgd for(obj = fobj; obj; obj = obj2) {
366 1.1 cgd obj2 = obj->nobj; /* perhaps obj will be picked up */
367 1.1 cgd if(obj->ox == u.ux && obj->oy == u.uy) {
368 1.1 cgd if(flags.run) nomul(0);
369 1.1 cgd
370 1.1 cgd /* do not pick up uchain */
371 1.1 cgd if(Punished && obj == uchain)
372 1.1 cgd continue;
373 1.1 cgd
374 1.1 cgd if(!all) {
375 1.1 cgd char c;
376 1.1 cgd
377 1.1 cgd pline("Pick up %s ? [ynaq]", doname(obj));
378 1.1 cgd while(!index("ynaq ", (c = readchar())))
379 1.1 cgd bell();
380 1.1 cgd if(c == 'q') return;
381 1.1 cgd if(c == 'n') continue;
382 1.1 cgd if(c == 'a') all = 1;
383 1.1 cgd }
384 1.1 cgd
385 1.1 cgd if(obj->otyp == DEAD_COCKATRICE && !uarmg){
386 1.1 cgd pline("Touching the dead cockatrice is a fatal mistake.");
387 1.1 cgd pline("You turn to stone.");
388 1.1 cgd killer = "cockatrice cadaver";
389 1.1 cgd done("died");
390 1.1 cgd }
391 1.1 cgd
392 1.1 cgd if(obj->otyp == SCR_SCARE_MONSTER){
393 1.1 cgd if(!obj->spe) obj->spe = 1;
394 1.1 cgd else {
395 1.1 cgd /* Note: perhaps the 1st pickup failed: you cannot
396 1.1 cgd carry anymore, and so we never dropped it -
397 1.1 cgd let's assume that treading on it twice also
398 1.1 cgd destroys the scroll */
399 1.1 cgd pline("The scroll turns to dust as you pick it up.");
400 1.1 cgd delobj(obj);
401 1.1 cgd continue;
402 1.1 cgd }
403 1.1 cgd }
404 1.1 cgd
405 1.1 cgd wt = inv_weight() + obj->owt;
406 1.1 cgd if(wt > 0) {
407 1.1 cgd if(obj->quan > 1) {
408 1.1 cgd /* see how many we can lift */
409 1.1 cgd extern struct obj *splitobj();
410 1.1 cgd int savequan = obj->quan;
411 1.1 cgd int iw = inv_weight();
412 1.1 cgd int qq;
413 1.1 cgd for(qq = 1; qq < savequan; qq++){
414 1.1 cgd obj->quan = qq;
415 1.1 cgd if(iw + weight(obj) > 0)
416 1.1 cgd break;
417 1.1 cgd }
418 1.1 cgd obj->quan = savequan;
419 1.1 cgd qq--;
420 1.1 cgd /* we can carry qq of them */
421 1.1 cgd if(!qq) goto too_heavy;
422 1.1 cgd pline("You can only carry %s of the %s lying here.",
423 1.1 cgd (qq == 1) ? "one" : "some",
424 1.1 cgd doname(obj));
425 1.1 cgd (void) splitobj(obj, qq);
426 1.1 cgd /* note: obj2 is set already, so we'll never
427 1.1 cgd * encounter the other half; if it should be
428 1.1 cgd * otherwise then write
429 1.1 cgd * obj2 = splitobj(obj,qq);
430 1.1 cgd */
431 1.1 cgd goto lift_some;
432 1.1 cgd }
433 1.1 cgd too_heavy:
434 1.1 cgd pline("There %s %s here, but %s.",
435 1.1 cgd (obj->quan == 1) ? "is" : "are",
436 1.1 cgd doname(obj),
437 1.1 cgd !invent ? "it is too heavy for you to lift"
438 1.1 cgd : "you cannot carry anymore");
439 1.1 cgd break;
440 1.1 cgd }
441 1.1 cgd lift_some:
442 1.1 cgd if(inv_cnt() >= 52) {
443 1.1 cgd pline("Your knapsack cannot accomodate anymore items.");
444 1.1 cgd break;
445 1.1 cgd }
446 1.1 cgd if(wt > -5) pline("You have a little trouble lifting");
447 1.1 cgd freeobj(obj);
448 1.1 cgd if(Invisible) newsym(u.ux,u.uy);
449 1.1 cgd addtobill(obj); /* sets obj->unpaid if necessary */
450 1.1 cgd { int pickquan = obj->quan;
451 1.1 cgd int mergquan;
452 1.1 cgd if(!Blind) obj->dknown = 1; /* this is done by prinv(),
453 1.1 cgd but addinv() needs it already for merging */
454 1.1 cgd obj = addinv(obj); /* might merge it with other objects */
455 1.1 cgd mergquan = obj->quan;
456 1.1 cgd obj->quan = pickquan; /* to fool prinv() */
457 1.1 cgd prinv(obj);
458 1.1 cgd obj->quan = mergquan;
459 1.1 cgd }
460 1.1 cgd }
461 1.1 cgd }
462 1.1 cgd }
463 1.1 cgd
464 1.1 cgd /* stop running if we see something interesting */
465 1.1 cgd /* turn around a corner if that is the only way we can proceed */
466 1.1 cgd /* do not turn left or right twice */
467 1.1 cgd lookaround(){
468 1.1 cgd register x,y,i,x0,y0,m0,i0 = 9;
469 1.1 cgd register int corrct = 0, noturn = 0;
470 1.1 cgd register struct monst *mtmp;
471 1.1 cgd #ifdef lint
472 1.1 cgd /* suppress "used before set" message */
473 1.1 cgd x0 = y0 = 0;
474 1.1 cgd #endif lint
475 1.1 cgd if(Blind || flags.run == 0) return;
476 1.1 cgd if(flags.run == 1 && levl[u.ux][u.uy].typ == ROOM) return;
477 1.1 cgd #ifdef QUEST
478 1.1 cgd if(u.ux0 == u.ux+u.dx && u.uy0 == u.uy+u.dy) goto stop;
479 1.1 cgd #endif QUEST
480 1.1 cgd for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
481 1.1 cgd if(x == u.ux && y == u.uy) continue;
482 1.1 cgd if(!levl[x][y].typ) continue;
483 1.1 cgd if((mtmp = m_at(x,y)) && !mtmp->mimic &&
484 1.1 cgd (!mtmp->minvis || See_invisible)){
485 1.1 cgd if(!mtmp->mtame || (x == u.ux+u.dx && y == u.uy+u.dy))
486 1.1 cgd goto stop;
487 1.1 cgd } else mtmp = 0; /* invisible M cannot influence us */
488 1.1 cgd if(x == u.ux-u.dx && y == u.uy-u.dy) continue;
489 1.1 cgd switch(levl[x][y].scrsym){
490 1.1 cgd case '|':
491 1.1 cgd case '-':
492 1.1 cgd case '.':
493 1.1 cgd case ' ':
494 1.1 cgd break;
495 1.1 cgd case '+':
496 1.1 cgd if(x != u.ux && y != u.uy) break;
497 1.1 cgd if(flags.run != 1) goto stop;
498 1.1 cgd /* fall into next case */
499 1.1 cgd case CORR_SYM:
500 1.1 cgd corr:
501 1.1 cgd if(flags.run == 1 || flags.run == 3) {
502 1.1 cgd i = DIST(x,y,u.ux+u.dx,u.uy+u.dy);
503 1.1 cgd if(i > 2) break;
504 1.1 cgd if(corrct == 1 && DIST(x,y,x0,y0) != 1)
505 1.1 cgd noturn = 1;
506 1.1 cgd if(i < i0) {
507 1.1 cgd i0 = i;
508 1.1 cgd x0 = x;
509 1.1 cgd y0 = y;
510 1.1 cgd m0 = mtmp ? 1 : 0;
511 1.1 cgd }
512 1.1 cgd }
513 1.1 cgd corrct++;
514 1.1 cgd break;
515 1.1 cgd case '^':
516 1.1 cgd if(flags.run == 1) goto corr; /* if you must */
517 1.1 cgd if(x == u.ux+u.dx && y == u.uy+u.dy) goto stop;
518 1.1 cgd break;
519 1.1 cgd default: /* e.g. objects or trap or stairs */
520 1.1 cgd if(flags.run == 1) goto corr;
521 1.1 cgd if(mtmp) break; /* d */
522 1.1 cgd stop:
523 1.1 cgd nomul(0);
524 1.1 cgd return;
525 1.1 cgd }
526 1.1 cgd }
527 1.1 cgd #ifdef QUEST
528 1.1 cgd if(corrct > 0 && (flags.run == 4 || flags.run == 5)) goto stop;
529 1.1 cgd #endif QUEST
530 1.1 cgd if(corrct > 1 && flags.run == 2) goto stop;
531 1.1 cgd if((flags.run == 1 || flags.run == 3) && !noturn && !m0 && i0 &&
532 1.1 cgd (corrct == 1 || (corrct == 2 && i0 == 1))) {
533 1.1 cgd /* make sure that we do not turn too far */
534 1.1 cgd if(i0 == 2) {
535 1.1 cgd if(u.dx == y0-u.uy && u.dy == u.ux-x0)
536 1.1 cgd i = 2; /* straight turn right */
537 1.1 cgd else
538 1.1 cgd i = -2; /* straight turn left */
539 1.1 cgd } else if(u.dx && u.dy) {
540 1.1 cgd if((u.dx == u.dy && y0 == u.uy) ||
541 1.1 cgd (u.dx != u.dy && y0 != u.uy))
542 1.1 cgd i = -1; /* half turn left */
543 1.1 cgd else
544 1.1 cgd i = 1; /* half turn right */
545 1.1 cgd } else {
546 1.1 cgd if((x0-u.ux == y0-u.uy && !u.dy) ||
547 1.1 cgd (x0-u.ux != y0-u.uy && u.dy))
548 1.1 cgd i = 1; /* half turn right */
549 1.1 cgd else
550 1.1 cgd i = -1; /* half turn left */
551 1.1 cgd }
552 1.1 cgd i += u.last_str_turn;
553 1.1 cgd if(i <= 2 && i >= -2) {
554 1.1 cgd u.last_str_turn = i;
555 1.1 cgd u.dx = x0-u.ux, u.dy = y0-u.uy;
556 1.1 cgd }
557 1.1 cgd }
558 1.1 cgd }
559 1.1 cgd
560 1.1 cgd /* something like lookaround, but we are not running */
561 1.1 cgd /* react only to monsters that might hit us */
562 1.1 cgd monster_nearby() {
563 1.1 cgd register int x,y;
564 1.1 cgd register struct monst *mtmp;
565 1.1 cgd if(!Blind)
566 1.1 cgd for(x = u.ux-1; x <= u.ux+1; x++) for(y = u.uy-1; y <= u.uy+1; y++){
567 1.1 cgd if(x == u.ux && y == u.uy) continue;
568 1.1 cgd if((mtmp = m_at(x,y)) && !mtmp->mimic && !mtmp->mtame &&
569 1.1 cgd !mtmp->mpeaceful && !index("Ea", mtmp->data->mlet) &&
570 1.1 cgd !mtmp->mfroz && !mtmp->msleep && /* aplvax!jcn */
571 1.1 cgd (!mtmp->minvis || See_invisible))
572 1.1 cgd return(1);
573 1.1 cgd }
574 1.1 cgd return(0);
575 1.1 cgd }
576 1.1 cgd
577 1.1 cgd #ifdef QUEST
578 1.1 cgd cansee(x,y) xchar x,y; {
579 1.1 cgd register int dx,dy,adx,ady,sdx,sdy,dmax,d;
580 1.1 cgd if(Blind) return(0);
581 1.1 cgd if(!isok(x,y)) return(0);
582 1.1 cgd d = dist(x,y);
583 1.1 cgd if(d < 3) return(1);
584 1.1 cgd if(d > u.uhorizon*u.uhorizon) return(0);
585 1.1 cgd if(!levl[x][y].lit)
586 1.1 cgd return(0);
587 1.1 cgd dx = x - u.ux; adx = abs(dx); sdx = sgn(dx);
588 1.1 cgd dy = y - u.uy; ady = abs(dy); sdy = sgn(dy);
589 1.1 cgd if(dx == 0 || dy == 0 || adx == ady){
590 1.1 cgd dmax = (dx == 0) ? ady : adx;
591 1.1 cgd for(d = 1; d <= dmax; d++)
592 1.1 cgd if(!rroom(sdx*d,sdy*d))
593 1.1 cgd return(0);
594 1.1 cgd return(1);
595 1.1 cgd } else if(ady > adx){
596 1.1 cgd for(d = 1; d <= ady; d++){
597 1.1 cgd if(!rroom(sdx*( (d*adx)/ady ), sdy*d) ||
598 1.1 cgd !rroom(sdx*( (d*adx-1)/ady+1 ), sdy*d))
599 1.1 cgd return(0);
600 1.1 cgd }
601 1.1 cgd return(1);
602 1.1 cgd } else {
603 1.1 cgd for(d = 1; d <= adx; d++){
604 1.1 cgd if(!rroom(sdx*d, sdy*( (d*ady)/adx )) ||
605 1.1 cgd !rroom(sdx*d, sdy*( (d*ady-1)/adx+1 )))
606 1.1 cgd return(0);
607 1.1 cgd }
608 1.1 cgd return(1);
609 1.1 cgd }
610 1.1 cgd }
611 1.1 cgd
612 1.1 cgd rroom(x,y) register int x,y; {
613 1.1 cgd return(IS_ROOM(levl[u.ux+x][u.uy+y].typ));
614 1.1 cgd }
615 1.1 cgd
616 1.1 cgd #else
617 1.1 cgd
618 1.1 cgd cansee(x,y) xchar x,y; {
619 1.1 cgd if(Blind || u.uswallow) return(0);
620 1.1 cgd if(dist(x,y) < 3) return(1);
621 1.1 cgd if(levl[x][y].lit && seelx <= x && x <= seehx && seely <= y &&
622 1.1 cgd y <= seehy) return(1);
623 1.1 cgd return(0);
624 1.1 cgd }
625 1.1 cgd #endif QUEST
626 1.1 cgd
627 1.1 cgd sgn(a) register int a; {
628 1.1 cgd return((a > 0) ? 1 : (a == 0) ? 0 : -1);
629 1.1 cgd }
630 1.1 cgd
631 1.1 cgd #ifdef QUEST
632 1.1 cgd setsee()
633 1.1 cgd {
634 1.1 cgd register x,y;
635 1.1 cgd
636 1.1 cgd if(Blind) {
637 1.1 cgd pru();
638 1.1 cgd return;
639 1.1 cgd }
640 1.1 cgd for(y = u.uy-u.uhorizon; y <= u.uy+u.uhorizon; y++)
641 1.1 cgd for(x = u.ux-u.uhorizon; x <= u.ux+u.uhorizon; x++) {
642 1.1 cgd if(cansee(x,y))
643 1.1 cgd prl(x,y);
644 1.1 cgd }
645 1.1 cgd }
646 1.1 cgd
647 1.1 cgd #else
648 1.1 cgd
649 1.1 cgd setsee()
650 1.1 cgd {
651 1.1 cgd register x,y;
652 1.1 cgd
653 1.1 cgd if(Blind) {
654 1.1 cgd pru();
655 1.1 cgd return;
656 1.1 cgd }
657 1.1 cgd if(!levl[u.ux][u.uy].lit) {
658 1.1 cgd seelx = u.ux-1;
659 1.1 cgd seehx = u.ux+1;
660 1.1 cgd seely = u.uy-1;
661 1.1 cgd seehy = u.uy+1;
662 1.1 cgd } else {
663 1.1 cgd for(seelx = u.ux; levl[seelx-1][u.uy].lit; seelx--);
664 1.1 cgd for(seehx = u.ux; levl[seehx+1][u.uy].lit; seehx++);
665 1.1 cgd for(seely = u.uy; levl[u.ux][seely-1].lit; seely--);
666 1.1 cgd for(seehy = u.uy; levl[u.ux][seehy+1].lit; seehy++);
667 1.1 cgd }
668 1.1 cgd for(y = seely; y <= seehy; y++)
669 1.1 cgd for(x = seelx; x <= seehx; x++) {
670 1.1 cgd prl(x,y);
671 1.1 cgd }
672 1.1 cgd if(!levl[u.ux][u.uy].lit) seehx = 0; /* seems necessary elsewhere */
673 1.1 cgd else {
674 1.1 cgd if(seely == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seely-1);
675 1.1 cgd if(seehy == u.uy) for(x = u.ux-1; x <= u.ux+1; x++) prl(x,seehy+1);
676 1.1 cgd if(seelx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seelx-1,y);
677 1.1 cgd if(seehx == u.ux) for(y = u.uy-1; y <= u.uy+1; y++) prl(seehx+1,y);
678 1.1 cgd }
679 1.1 cgd }
680 1.1 cgd #endif QUEST
681 1.1 cgd
682 1.1 cgd nomul(nval)
683 1.1 cgd register nval;
684 1.1 cgd {
685 1.1 cgd if(multi < 0) return;
686 1.1 cgd multi = nval;
687 1.1 cgd flags.mv = flags.run = 0;
688 1.1 cgd }
689 1.1 cgd
690 1.1 cgd abon()
691 1.1 cgd {
692 1.1 cgd if(u.ustr == 3) return(-3);
693 1.1 cgd else if(u.ustr < 6) return(-2);
694 1.1 cgd else if(u.ustr < 8) return(-1);
695 1.1 cgd else if(u.ustr < 17) return(0);
696 1.1 cgd else if(u.ustr < 69) return(1); /* up to 18/50 */
697 1.1 cgd else if(u.ustr < 118) return(2);
698 1.1 cgd else return(3);
699 1.1 cgd }
700 1.1 cgd
701 1.1 cgd dbon()
702 1.1 cgd {
703 1.1 cgd if(u.ustr < 6) return(-1);
704 1.1 cgd else if(u.ustr < 16) return(0);
705 1.1 cgd else if(u.ustr < 18) return(1);
706 1.1 cgd else if(u.ustr == 18) return(2); /* up to 18 */
707 1.1 cgd else if(u.ustr < 94) return(3); /* up to 18/75 */
708 1.1 cgd else if(u.ustr < 109) return(4); /* up to 18/90 */
709 1.1 cgd else if(u.ustr < 118) return(5); /* up to 18/99 */
710 1.1 cgd else return(6);
711 1.1 cgd }
712 1.1 cgd
713 1.1 cgd losestr(num) /* may kill you; cause may be poison or monster like 'A' */
714 1.1 cgd register num;
715 1.1 cgd {
716 1.1 cgd u.ustr -= num;
717 1.1 cgd while(u.ustr < 3) {
718 1.1 cgd u.ustr++;
719 1.1 cgd u.uhp -= 6;
720 1.1 cgd u.uhpmax -= 6;
721 1.1 cgd }
722 1.1 cgd flags.botl = 1;
723 1.1 cgd }
724 1.1 cgd
725 1.1 cgd losehp(n,knam)
726 1.1 cgd register n;
727 1.1 cgd register char *knam;
728 1.1 cgd {
729 1.1 cgd u.uhp -= n;
730 1.1 cgd if(u.uhp > u.uhpmax)
731 1.1 cgd u.uhpmax = u.uhp; /* perhaps n was negative */
732 1.1 cgd flags.botl = 1;
733 1.1 cgd if(u.uhp < 1) {
734 1.1 cgd killer = knam; /* the thing that killed you */
735 1.1 cgd done("died");
736 1.1 cgd }
737 1.1 cgd }
738 1.1 cgd
739 1.1 cgd losehp_m(n,mtmp)
740 1.1 cgd register n;
741 1.1 cgd register struct monst *mtmp;
742 1.1 cgd {
743 1.1 cgd u.uhp -= n;
744 1.1 cgd flags.botl = 1;
745 1.1 cgd if(u.uhp < 1)
746 1.1 cgd done_in_by(mtmp);
747 1.1 cgd }
748 1.1 cgd
749 1.1 cgd losexp() /* hit by V or W */
750 1.1 cgd {
751 1.1 cgd register num;
752 1.1 cgd extern long newuexp();
753 1.1 cgd
754 1.1 cgd if(u.ulevel > 1)
755 1.1 cgd pline("Goodbye level %u.", u.ulevel--);
756 1.1 cgd else
757 1.1 cgd u.uhp = -1;
758 1.1 cgd num = rnd(10);
759 1.1 cgd u.uhp -= num;
760 1.1 cgd u.uhpmax -= num;
761 1.1 cgd u.uexp = newuexp();
762 1.1 cgd flags.botl = 1;
763 1.1 cgd }
764 1.1 cgd
765 1.1 cgd inv_weight(){
766 1.1 cgd register struct obj *otmp = invent;
767 1.1 cgd register int wt = (u.ugold + 500)/1000;
768 1.1 cgd register int carrcap;
769 1.1 cgd if(Levitation) /* pugh@cornell */
770 1.1 cgd carrcap = MAX_CARR_CAP;
771 1.1 cgd else {
772 1.1 cgd carrcap = 5*(((u.ustr > 18) ? 20 : u.ustr) + u.ulevel);
773 1.1 cgd if(carrcap > MAX_CARR_CAP) carrcap = MAX_CARR_CAP;
774 1.1 cgd if(Wounded_legs & LEFT_SIDE) carrcap -= 10;
775 1.1 cgd if(Wounded_legs & RIGHT_SIDE) carrcap -= 10;
776 1.1 cgd }
777 1.1 cgd while(otmp){
778 1.1 cgd wt += otmp->owt;
779 1.1 cgd otmp = otmp->nobj;
780 1.1 cgd }
781 1.1 cgd return(wt - carrcap);
782 1.1 cgd }
783 1.1 cgd
784 1.1 cgd inv_cnt(){
785 1.1 cgd register struct obj *otmp = invent;
786 1.1 cgd register int ct = 0;
787 1.1 cgd while(otmp){
788 1.1 cgd ct++;
789 1.1 cgd otmp = otmp->nobj;
790 1.1 cgd }
791 1.1 cgd return(ct);
792 1.1 cgd }
793 1.1 cgd
794 1.1 cgd long
795 1.1 cgd newuexp()
796 1.1 cgd {
797 1.1 cgd return(10*(1L << (u.ulevel-1)));
798 1.1 cgd }
799