|
|
1.1 root 1: /*
2: * Hero movement commands
3: *
4: * @(#)move.c 3.26 (Berkeley) 6/15/81
5: */
6:
7: #include <curses.h>
8: #include <ctype.h>
9: #include "rogue.h"
10:
11: /*
12: * Used to hold the new hero position
13: */
14:
15: coord nh;
16:
17: /*
18: * do_run:
19: * Start the hero running
20: */
21:
22: do_run(ch)
23: char ch;
24: {
25: running = TRUE;
26: after = FALSE;
27: runch = ch;
28: }
29:
30: /*
31: * do_move:
32: * Check to see that a move is legal. If it is handle the
33: * consequences (fighting, picking up, etc.)
34: */
35:
36: do_move(dy, dx)
37: int dy, dx;
38: {
39: register char ch;
40:
41: firstmove = FALSE;
42: if (no_move)
43: {
44: no_move--;
45: msg("You are still stuck in the bear trap");
46: return;
47: }
48: /*
49: * Do a confused move (maybe)
50: */
51: if (rnd(100) < 80 && on(player, ISHUH))
52: nh = *rndmove(&player);
53: else
54: {
55: nh.y = hero.y + dy;
56: nh.x = hero.x + dx;
57: }
58:
59: /*
60: * Check if he tried to move off the screen or make an illegal
61: * diagonal move, and stop him if he did.
62: */
63: if (nh.x < 0 || nh.x > COLS-1 || nh.y < 0 || nh.y > LINES - 1
64: || !diag_ok(&hero, &nh))
65: {
66: after = FALSE;
67: running = FALSE;
68: return;
69: }
70: if (running && ce(hero, nh))
71: after = running = FALSE;
72: ch = winat(nh.y, nh.x);
73: if (on(player, ISHELD) && ch != 'F')
74: {
75: msg("You are being held");
76: return;
77: }
78: switch(ch)
79: {
80: case ' ':
81: case '|':
82: case '-':
83: case SECRETDOOR:
84: after = running = FALSE;
85: return;
86: case TRAP:
87: ch = be_trapped(&nh);
88: if (ch == TRAPDOOR || ch == TELTRAP)
89: return;
90: goto move_stuff;
91: case GOLD:
92: case POTION:
93: case SCROLL:
94: case FOOD:
95: case WEAPON:
96: case ARMOR:
97: case RING:
98: case AMULET:
99: case STICK:
100: running = FALSE;
101: take = ch;
102: default:
103: move_stuff:
104: if (ch == PASSAGE && winat(hero.y, hero.x) == DOOR)
105: light(&hero);
106: else if (ch == DOOR)
107: {
108: running = FALSE;
109: if (winat(hero.y, hero.x) == PASSAGE)
110: light(&nh);
111: }
112: else if (ch == STAIRS)
113: running = FALSE;
114: else if (isupper(ch))
115: {
116: running = FALSE;
117: fight(&nh, ch, cur_weapon, FALSE);
118: return;
119: }
120: ch = winat(hero.y, hero.x);
121: wmove(cw, unc(hero));
122: waddch(cw, ch);
123: hero = nh;
124: wmove(cw, unc(hero));
125: waddch(cw, PLAYER);
126: }
127: }
128:
129: /*
130: * Called to illuminate a room.
131: * If it is dark, remove anything that might move.
132: */
133:
134: light(cp)
135: coord *cp;
136: {
137: register struct room *rp;
138: register int j, k;
139: register char ch, rch;
140: register struct linked_list *item;
141:
142: if ((rp = roomin(cp)) != NULL && !on(player, ISBLIND))
143: {
144: for (j = 0; j < rp->r_max.y; j++)
145: {
146: for (k = 0; k < rp->r_max.x; k++)
147: {
148: ch = show(rp->r_pos.y + j, rp->r_pos.x + k);
149: wmove(cw, rp->r_pos.y + j, rp->r_pos.x + k);
150: /*
151: * Figure out how to display a secret door
152: */
153: if (ch == SECRETDOOR)
154: {
155: if (j == 0 || j == rp->r_max.y - 1)
156: ch = '-';
157: else
158: ch = '|';
159: }
160: /*
161: * If the room is a dark room, we might want to remove
162: * monsters and the like from it (since they might
163: * move)
164: */
165: if (isupper(ch))
166: {
167: item = wake_monster(rp->r_pos.y+j, rp->r_pos.x+k);
168: if (((struct thing *) ldata(item))->t_oldch == ' ')
169: if (!(rp->r_flags & ISDARK))
170: ((struct thing *) ldata(item))->t_oldch =
171: mvwinch(stdscr, rp->r_pos.y+j, rp->r_pos.x+k);
172: }
173: if (rp->r_flags & ISDARK)
174: {
175: rch = mvwinch(cw, rp->r_pos.y+j, rp->r_pos.x+k);
176: switch (rch)
177: {
178: when DOOR:
179: case STAIRS:
180: case TRAP:
181: case '|':
182: case '-':
183: case ' ':
184: ch = rch;
185: when FLOOR:
186: ch = (on(player, ISBLIND) ? FLOOR : ' ');
187: otherwise:
188: ch = ' ';
189: }
190: }
191: mvwaddch(cw, rp->r_pos.y+j, rp->r_pos.x+k, ch);
192: }
193: }
194: }
195: }
196:
197: /*
198: * show:
199: * returns what a certain thing will display as to the un-initiated
200: */
201:
202: show(y, x)
203: register int y, x;
204: {
205: register char ch = winat(y, x);
206: register struct linked_list *it;
207: register struct thing *tp;
208:
209: if (ch == TRAP)
210: return (trap_at(y, x)->tr_flags & ISFOUND) ? TRAP : FLOOR;
211: else if (ch == 'M' || ch == 'I')
212: {
213: if ((it = find_mons(y, x)) == NULL)
214: msg("Can't find monster in show");
215: tp = (struct thing *) ldata(it);
216: if (ch == 'M')
217: ch = tp->t_disguise;
218: /*
219: * Hide invisible monsters
220: */
221: else if (off(player, CANSEE))
222: ch = mvwinch(stdscr, y, x);
223: }
224: return ch;
225: }
226:
227: /*
228: * be_trapped:
229: * The guy stepped on a trap.... Make him pay.
230: */
231:
232: be_trapped(tc)
233: register coord *tc;
234: {
235: register struct trap *tp;
236: register char ch;
237:
238: tp = trap_at(tc->y, tc->x);
239: count = running = FALSE;
240: mvwaddch(cw, tp->tr_pos.y, tp->tr_pos.x, TRAP);
241: tp->tr_flags |= ISFOUND;
242: switch (ch = tp->tr_type)
243: {
244: when TRAPDOOR:
245: level++;
246: new_level();
247: msg("You fell into a trap!");
248: when BEARTRAP:
249: no_move += BEARTIME;
250: msg("You are caught in a bear trap");
251: when SLEEPTRAP:
252: no_command += SLEEPTIME;
253: msg("A strange white mist envelops you and you fall asleep");
254: when ARROWTRAP:
255: if (swing(pstats.s_lvl-1, pstats.s_arm, 1))
256: {
257: msg("Oh no! An arrow shot you");
258: if ((pstats.s_hpt -= roll(1, 6)) <= 0)
259: {
260: msg("The arrow killed you.");
261: death('a');
262: }
263: }
264: else
265: {
266: register struct linked_list *item;
267: register struct object *arrow;
268:
269: msg("An arrow shoots past you.");
270: item = new_item(sizeof *arrow);
271: arrow = (struct object *) ldata(item);
272: arrow->o_type = WEAPON;
273: arrow->o_which = ARROW;
274: init_weapon(arrow, ARROW);
275: arrow->o_hplus = arrow->o_dplus = -1;
276: arrow->o_count = 1;
277: arrow->o_pos = hero;
278: fall(item, FALSE);
279: }
280: when TELTRAP:
281: teleport();
282: when DARTTRAP:
283: if (swing(pstats.s_lvl+1, pstats.s_arm, 1))
284: {
285: msg("A small dart just hit you in the shoulder");
286: if ((pstats.s_hpt -= roll(1, 4)) <= 0)
287: {
288: msg("The dart killed you.");
289: death('d');
290: }
291: if (!ISWEARING(R_SUSTSTR))
292: chg_str(-1);
293: }
294: else
295: msg("A small dart whizzes by your ear and vanishes.");
296: }
297: #if USG==1
298: ioctl(_tty_ch, TCFLSH, 0);
299: #else
300: raw(); /* flush typeahead */
301: noraw();
302: #endif
303: return(ch);
304: }
305:
306: /*
307: * trap_at:
308: * find the trap at (y,x) on screen.
309: */
310:
311: struct trap *
312: trap_at(y, x)
313: register int y, x;
314: {
315: register struct trap *tp, *ep;
316:
317: ep = &traps[ntraps];
318: for (tp = traps; tp < ep; tp++)
319: if (tp->tr_pos.y == y && tp->tr_pos.x == x)
320: break;
321: if (tp == ep)
322: debug(sprintf(prbuf, "Trap at %d,%d not in array", y, x));
323: return tp;
324: }
325:
326: /*
327: * rndmove:
328: * move in a random direction if the monster/person is confused
329: */
330:
331: coord *
332: rndmove(who)
333: struct thing *who;
334: {
335: register int x, y;
336: register char ch;
337: register int ex, ey, nopen = 0;
338: register struct linked_list *item;
339: register struct object *obj;
340: static coord ret; /* what we will be returning */
341: static coord dest;
342:
343: ret = who->t_pos;
344: /*
345: * Now go through the spaces surrounding the player and
346: * set that place in the array to true if the space can be
347: * moved into
348: */
349: ey = ret.y + 1;
350: ex = ret.x + 1;
351: for (y = who->t_pos.y - 1; y <= ey; y++)
352: if (y >= 0 && y < LINES)
353: for (x = who->t_pos.x - 1; x <= ex; x++)
354: {
355: if (x < 0 || x >= COLS)
356: continue;
357: ch = winat(y, x);
358: if (step_ok(ch))
359: {
360: dest.y = y;
361: dest.x = x;
362: if (!diag_ok(&who->t_pos, &dest))
363: continue;
364: if (ch == SCROLL)
365: {
366: item = NULL;
367: for (item = lvl_obj; item != NULL; item = next(item))
368: {
369: obj = (struct object *) ldata(item);
370: if (y == obj->o_pos.y && x == obj->o_pos.x)
371: break;
372: }
373: if (item != NULL && obj->o_which == S_SCARE)
374: continue;
375: }
376: if (rnd(++nopen) == 0)
377: ret = dest;
378: }
379: }
380: return &ret;
381: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.