-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchase.c
310 lines (294 loc) · 7.35 KB
/
chase.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
/*
* Code for one object to chase another
*
* @(#)chase.c 3.17 (Berkeley) 6/15/81
*/
#include "rogue.h"
#include "chase.h"
#include "curses.h"
#include "io.h"
//coord ch_ret; /* Where chasing takes you */
/*
* runners:
* Make all the running monsters move.
*/
//
//void runners(void)
//{
// register struct linked_list *item;
// register struct monster *tp;
//
// for (item = mlist; item != NULL; item = next(item))
// {
// tp = (struct monster *) ldata(item);
// if (off(*tp, ISHELD) && on(*tp, ISRUN))
// {
// if (off(*tp, ISSLOW) || tp->t_turn)
// do_chase(tp);
// if (on(*tp, ISHASTE))
// do_chase(tp);
// tp->t_turn ^= TRUE;
// }
// }
//}
//
///*
// * do_chase:
// * Make one thing chase another.
// */
//
//do_chase(th)
//register struct monster *th;
//{
// register struct room *rer, *ree; /* room of chaser, room of chasee */
// register int mindist = 32767, i, dist;
// register bool stoprun = FALSE; /* TRUE means we are there */
// register char sch;
// coord this; /* Temporary destination for chaser */
//
// rer = roomin(&th->t_pos); /* Find room of chaser */
// ree = roomin(th->t_dest); /* Find room of chasee */
// /*
// * We don't count doors as inside rooms for this routine
// */
// if (mvwinch(stdscr, th->t_pos.y, th->t_pos.x) == DOOR)
// rer = NULL;
// this = *th->t_dest;
// /*
// * If the object of our desire is in a different room,
// * than we are and we ar not in a corridor, run to the
// * door nearest to our goal.
// */
// if (rer != NULL && rer != ree)
// for (i = 0; i < rer->r_nexits; i++) /* loop through doors */
// {
// dist = DISTANCE(th->t_dest->y, th->t_dest->x,
// rer->r_exit[i].y, rer->r_exit[i].x);
// if (dist < mindist) /* minimize distance */
// {
// this = rer->r_exit[i];
// mindist = dist;
// }
// }
// /*
// * this now contains what we want to run to this time
// * so we run to it. If we hit it we either want to fight it
// * or stop running
// */
// if (!chase(th, &this))
// {
// if (ce(this, hero))
// {
// attack(th);
// return;
// }
// else if (th->t_type != 'F')
// stoprun = TRUE;
// }
// else if (th->t_type == 'F')
// return;
// mvwaddch(cw, th->t_pos.y, th->t_pos.x, th->t_oldch);
// sch = mvwinch(cw, ch_ret.y, ch_ret.x);
// if (rer != NULL && (rer->r_flags & ISDARK) && sch == FLOOR
// && DISTANCE(ch_ret.y, ch_ret.x, th->t_pos.y, th->t_pos.x) < 3
// && off(player, ISBLIND))
// th->t_oldch = ' ';
// else
// th->t_oldch = sch;
//
// if (cansee(unc(ch_ret)) && !on(*th, ISINVIS))
// mvwaddch(cw, ch_ret.y, ch_ret.x, th->t_type);
// mvwaddch(mw, th->t_pos.y, th->t_pos.x, ' ');
// mvwaddch(mw, ch_ret.y, ch_ret.x, th->t_type);
// th->t_pos = ch_ret;
// /*
// * And stop running if need be
// */
// if (stoprun && ce(th->t_pos, *(th->t_dest)))
// th->t_flags &= ~ISRUN;
//}
//
///*
// * runto:
// * Set a mosnter running after something
// * or stop it from running (for when it dies)
// */
//
//runto(runner, spot)
//register coord *runner;
//coord *spot;
//{
// register struct linked_list *item;
// register struct monster *tp;
//
// /*
// * If we couldn't find him, something is funny
// */
// if ((item = find_mons(runner->y, runner->x)) == NULL)
// msg("CHASER '%s'", unctrl(winat(runner->y, runner->x)));
// tp = (struct monster *) ldata(item);
// /*
// * Start the beastie running
// */
// tp->t_dest = spot;
// tp->t_flags |= ISRUN;
// tp->t_flags &= ~ISHELD;
//}
//
///*
// * chase:
// * Find the spot for the chaser(er) to move closer to the
// * chasee(ee). Returns TRUE if we want to keep on chasing later
// * FALSE if we reach the goal.
// */
//
//chase(tp, ee)
//struct monster *tp;
//coord *ee;
//{
// register int x, y;
// register int dist, thisdist;
// register struct linked_list *item;
// register struct object *obj;
// register coord *er = &tp->t_pos;
// register char ch;
//
// /*
// * If the thing is confused, let it move randomly. Invisible
// * Stalkers are slightly confused all of the time, and bats are
// * quite confused all the time
// */
// if ((on(*tp, ISHUH) && rnd(10) < 8) || (tp->t_type == 'I' && rnd(100) < 20)
// || (tp->t_type == 'B' && rnd(100) < 50))
// {
// /*
// * get a valid random move
// */
// ch_ret = *rndmove(tp);
// dist = DISTANCE(ch_ret.y, ch_ret.x, ee->y, ee->x);
// /*
// * Small chance that it will become un-confused
// */
// if (rnd(1000) < 50)
// tp->t_flags &= ~ISHUH;
// }
// /*
// * Otherwise, find the empty spot next to the chaser that is
// * closest to the chasee.
// */
// else
// {
// register int ey, ex;
// /*
// * This will eventually hold where we move to get closer
// * If we can't find an empty spot, we stay where we are.
// */
// dist = DISTANCE(er->y, er->x, ee->y, ee->x);
// ch_ret = *er;
//
// ey = er->y + 1;
// ex = er->x + 1;
// for (x = er->x - 1; x <= ex; x++)
// for (y = er->y - 1; y <= ey; y++)
// {
// coord tryp;
//
// tryp.x = x;
// tryp.y = y;
// if (!diag_ok(er, &tryp))
// continue;
// ch = winat(y, x);
// if (step_ok(ch))
// {
// /*
// * If it is a scroll, it might be a scare monster scroll
// * so we need to look it up to see what type it is.
// */
// if (ch == SCROLL)
// {
// 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 we didn't find any scrolls at this place or it
// * wasn't a scare scroll, then this place counts
// */
// thisdist = DISTANCE(y, x, ee->y, ee->x);
// if (thisdist < dist)
// {
// ch_ret = tryp;
// dist = thisdist;
// }
// }
// }
// }
// return (dist != 0);
//}
/*
* roomin:
* Find what room some coordinates are in. NULL means they aren't
* in any room.
*/
struct room *roomin(coord *cp)
{
struct room *rp;
for (rp = rooms; rp < &rooms[MAXROOMS]; rp++)
if (inroom(rp, cp))
return rp;
return NULL;
}
/*
* find_mons:
* Find the monster from his corrdinates
*/
struct monster *find_mons(unsigned char y, unsigned char x)
{
register struct monster *monster;
char i;
for (i = 0; i < MONSTER_COUNT; i++)
{
monster = monsters + i;
if (monster->t_pos.y == y && monster->t_pos.x == x)
return monster;
}
return NULL;
}
/*
* diag_ok:
* Check to see if the move is legal if it is diagonal
*/
bool diag_ok(coord *sp, coord *ep)
{
if (ep->x == sp->x || ep->y == sp->y)
return TRUE;
return (step_ok(mvinch(ep->y, sp->x)) && step_ok(mvinch(sp->y, ep->x)));
}
///*
// * cansee:
// * returns true if the hero can see a certain coordinate.
// */
//
//cansee(y, x)
//register int y, x;
//{
// register struct room *rer;
// coord tp;
//
// if (on(player, ISBLIND))
// return FALSE;
// tp.y = y;
// tp.x = x;
// rer = roomin(&tp);
// /*
// * We can only see if the hero in the same room as
// * the coordinate and the room is lit or if it is close.
// */
// return (rer != NULL && rer == roomin(&hero) && !(rer->r_flags&ISDARK)) ||
// DISTANCE(y, x, hero.y, hero.x) < 3;
//}