-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmove.c
400 lines (374 loc) · 9.73 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
* Hero movement commands
*
* @(#)move.c 3.26 (Berkeley) 6/15/81
*
* BUG FIX! Mike Hibler @ New Mexico Tech
* This fixes the infamous "arrow bug". The "arrow bug" was one in
* which you would repeatedly go into an arrow trap until "an arrow
* shoots past you". When you picked it up and identified it, more
* times then not, you discovered that it was something like:
* (+32756, +75643)
* which, when wielded, made you pretty indestructable. It also
* gave you big points in a "total win" situation. The problem was
* that the o_hplus and o_dplus fields were never initialized after
* the arrow was created. The solution was, obviously, to initialize
* these fields. The fix itself is in the routine "be_trapped" under
* the ARROWTRAP case.
*/
#include "curses.h"
#include <ctype.h>
#include "rogue.h"
#include "move.h"
#include "io.h"
#include "chase.h"
/*
* Used to hold the new hero position
*/
coord nh;
/*
* do_run:
* Start the hero running
*/
//
//do_run(ch)
//char ch;
//{
// running = TRUE;
// after = FALSE;
// runch = ch;
//}
/*
* do_move:
* Check to see that a move is legal. If it is handle the
* consequences (fighting, picking up, etc.)
*/
void do_move(char dy, char dx)
{
register char ch;
firstmove = FALSE;
if (no_move)
{
no_move--;
msg("You are still stuck in the bear trap");
return;
}
/*
* Do a confused move (maybe)
*/
// if (rnd(100) < 80 && on(player, ISHUH))
// nh = *rndmove(&player);
// else
// {
nh.y = hero.y + dy;
nh.x = hero.x + dx;
// }
/*
* Check if he tried to move off the screen or make an illegal
* diagonal move, and stop him if he did.
*/
if (nh.x < 0 || nh.x > COLS-1 || nh.y < 0 || nh.y > LINES - 1
|| !diag_ok(&hero, &nh)
)
{
after = FALSE;
running = FALSE;
return;
}
if (running && ce(hero, nh))
after = running = FALSE;
ch = winat(nh.y, nh.x);
if (on(player, ISHELD) && ch != 'F')
{
msg("You are being held");
return;
}
switch(ch)
{
case ' ':
case '|':
case '-':
case SECRETDOOR:
after = running = FALSE;
return;
// case TRAP:
// ch = be_trapped(&nh);
// if (ch == TRAPDOOR || ch == TELTRAP)
// return;
// goto move_stuff;
case GOLD:
// case POTION:
// case SCROLL:
// case FOOD:
// case WEAPON:
// case ARMOR:
// case RING:
// case AMULET:
// case STICK:
running = FALSE;
take = ch;
default:
move_stuff:
if (ch == PASSAGE && winat(hero.y, hero.x) == DOOR) //going into passage, currently on door
light(&hero); //darken?
else if (ch == DOOR) // going onto door
{
running = FALSE;
if (winat(hero.y, hero.x) == PASSAGE) //passage to door
light(&nh);
}
else if (ch == STAIRS)
running = FALSE;
// else if (isupper(ch))
// {
// running = FALSE;
// fight(&nh, ch, cur_weapon, FALSE);
// return;
// }
ch = winat(hero.y, hero.x);
wmove(cw, unc(hero));
waddch(cw, ch);
hero = nh;
wmove(cw, unc(hero));
waddch(cw, PLAYER);
}
}
/*
* Called to illuminate a room.
* If it is dark, remove anything that might move.
*/
void light(coord *cp)
{
register struct room *rp;
register int j, k;
register char ch, rch;
register struct linked_list *item;
if ((rp = roomin(cp)) != NULL && !on(player, ISBLIND))
{
for (j = 0; j < rp->r_max.y; j++)
{
for (k = 0; k < rp->r_max.x; k++)
{
ch = show(rp->r_pos.y + j, rp->r_pos.x + k);
wmove(cw, rp->r_pos.y + j, rp->r_pos.x + k);
/*
* Figure out how to display a secret door
*/
if (ch == SECRETDOOR)
{
if (j == 0 || j == rp->r_max.y - 1)
ch = '-';
else
ch = '|';
}
/*
* If the room is a dark room, we might want to remove
* monsters and the like from it (since they might
* move)
*/
// if (isupper(ch))
// {
// item = wake_monster(rp->r_pos.y+j, rp->r_pos.x+k);
// if (((struct monster *) ldata(item))->t_oldch == ' ')
// if (!(rp->r_flags & ISDARK))
// ((struct monster *) ldata(item))->t_oldch = mvwinch(stdscr, rp->r_pos.y+j, rp->r_pos.x+k);
// }
if (rp->r_flags & ISDARK)
{
rch = mvwinch(cw, rp->r_pos.y+j, rp->r_pos.x+k);
switch (rch)
{
when DOOR:
case STAIRS:
case TRAP:
case '|':
case '-':
case ' ':
ch = rch;
when FLOOR:
ch = (on(player, ISBLIND) ? FLOOR : ' ');
otherwise:
ch = ' ';
}
}
mvwaddch(cw, rp->r_pos.y+j, rp->r_pos.x+k, ch);
}
}
}
}
/*
* show:
* returns what a certain thing will display as to the un-initiated
*/
char show(unsigned char y, unsigned char x)
{
register char ch = winat(y, x);
register struct linked_list *it;
register struct monster *tp;
if (ch == TRAP)
return (trap_at(y, x)->tr_flags & ISFOUND) ? TRAP : FLOOR;
else if (ch == 'M' || ch == 'I')
{
// if ((it = find_mons(y, x)) == NULL)
// msg("Can't find monster in show", 0);
tp = (struct monster *) ldata(it);
if (ch == 'M')
ch = tp->t_disguise;
/*
* Hide invisible monsters
*/
else if (off(player, CANSEE))
ch = mvwinch(stdscr, y, x);
}
return ch;
}
/*
* be_trapped:
* The guy stepped on a trap.... Make him pay.
*/
//
//be_trapped(tc)
//register coord *tc;
//{
// register struct trap *tp;
// register char ch;
//
// tp = trap_at(tc->y, tc->x);
// count = running = FALSE;
// mvwaddch(cw, tp->tr_pos.y, tp->tr_pos.x, TRAP);
// tp->tr_flags |= ISFOUND;
// switch (ch = tp->tr_type)
// {
// when TRAPDOOR:
// level++;
// new_level();
// msg("You fell into a trap!");
// when BEARTRAP:
// no_move += BEARTIME;
// msg("You are caught in a bear trap");
// when SLEEPTRAP:
// no_command += SLEEPTIME;
// msg("A strange white mist envelops you and you fall asleep");
// when ARROWTRAP:
// if (swing(pstats.s_lvl-1, pstats.s_arm, 1))
// {
// msg("Oh no! An arrow shot you");
// if ((pstats.s_hpt -= roll(1, 6)) <= 0)
// {
// msg("The arrow killed you.");
// death('a');
// }
// }
// else
// {
// register struct linked_list *item;
// register struct object *arrow;
//
// msg("An arrow shoots past you.");
// item = new_item(sizeof *arrow);
// arrow = (struct object *) ldata(item);
// arrow->o_type = WEAPON;
// arrow->o_which = ARROW;
// init_weapon(arrow, ARROW);
// arrow->o_count = 1;
// arrow->o_pos = hero;
// /* BUG FIX! This fixes the infamous "arrow bug". */
// arrow->o_hplus = arrow->o_dplus = 0;
// if (rnd(100) < 15)
// arrow->o_hplus += rnd(3)+1;
// /* End of BUG FIX! */
// fall(item, FALSE);
// }
// when TELTRAP:
// teleport();
// when DARTTRAP:
// if (swing(pstats.s_lvl+1, pstats.s_arm, 1))
// {
// msg("A small dart just hit you in the shoulder");
// if ((pstats.s_hpt -= roll(1, 4)) <= 0)
// {
// msg("The dart killed you.");
// death('d');
// }
// if (!ISWEARING(R_SUSTSTR))
// chg_str(-1);
// }
// else
// msg("A small dart whizzes by your ear and vanishes.");
// }
// raw(); /* flush typeahead */
// noraw();
// return(ch);
//}
//
/*
* trap_at:
* find the trap at (y,x) on screen.
*/
struct trap *trap_at(unsigned char y, unsigned char x)
{
register struct trap *tp, *ep;
ep = &traps[ntraps];
for (tp = traps; tp < ep; tp++)
if (tp->tr_pos.y == y && tp->tr_pos.x == x)
break;
// if (tp == ep)
// debug(sprintf(prbuf, "Trap at %d,%d not in array", y, x));
return tp;
}
///*
// * rndmove:
// * move in a random direction if the monster/person is confused
// */
//
//coord *
//rndmove(who)
//struct monster *who;
//{
// register int x, y;
// register char ch;
// register int ex, ey, nopen = 0;
// register struct linked_list *item;
// register struct object *obj;
// static coord ret; /* what we will be returning */
// static coord dest;
//
// ret = who->t_pos;
// /*
// * Now go through the spaces surrounding the player and
// * set that place in the array to true if the space can be
// * moved into
// */
// ey = ret.y + 1;
// ex = ret.x + 1;
// for (y = who->t_pos.y - 1; y <= ey; y++)
// if (y >= 0 && y < LINES)
// for (x = who->t_pos.x - 1; x <= ex; x++)
// {
// if (x < 0 || x >= COLS)
// continue;
// ch = winat(y, x);
// if (step_ok(ch))
// {
// dest.y = y;
// dest.x = x;
// if (!diag_ok(&who->t_pos, &dest))
// continue;
// if (ch == SCROLL)
// {
// item = NULL;
// for (item = lvl_obj; item != NULL; item = next(item))
// {
// obj = (struct object *) ldata(item);
// if (y == obj->o_pos.y && x == obj->o_pos.x)
// break;
// }
// if (item != NULL && obj->o_which == S_SCARE)
// continue;
// }
// if (rnd(++nopen) == 0)
// ret = dest;
// }
// }
// return &ret;
//}