MCPcopy Index your code
hub / github.com/NetHack/NetHack / md_stop

Function md_stop

src/mail.c:247–274  ·  view source on GitHub ↗

* Try to choose a stopping point as near as possible to the starting * position while still adjacent to the hero. If all else fails, try * enexto(). Use enexto() as a last resort because enexto() chooses * its point randomly, which is not what we want. */

Source from the content-addressed store, hash-verified

245 * its point randomly, which is not what we want.
246 */
247staticfn boolean
248md_stop(coord *stopp, /* stopping position (we fill it in) */
249 coord *startp) /* starting position (read only) */
250{
251 coordxy x, y, distance, min_distance = -1;
252
253 for (x = u.ux - 1; x <= u.ux + 1; x++)
254 for (y = u.uy - 1; y <= u.uy + 1; y++) {
255 if (!isok(x, y) || u_at(x, y))
256 continue;
257
258 if (accessible(x, y) && !MON_AT(x, y)) {
259 distance = dist2(x, y, startp->x, startp->y);
260 if (min_distance < 0 || distance < min_distance
261 || (distance == min_distance && rn2(2))) {
262 stopp->x = x;
263 stopp->y = y;
264 min_distance = distance;
265 }
266 }
267 }
268
269 /* If we didn't find a good spot, try enexto(). */
270 if (min_distance < 0 && !enexto(stopp, u.ux, u.uy, &mons[PM_MAIL_DAEMON]))
271 return FALSE;
272
273 return TRUE;
274}
275
276/* Let the mail daemon have a larger vocabulary. */
277staticfn NEARDATA const char *mail_text[] = { "Gangway!", "Look out!",

Callers 1

newmailFunction · 0.85

Calls 5

isokFunction · 0.85
accessibleFunction · 0.85
dist2Function · 0.85
rn2Function · 0.85
enextoFunction · 0.85

Tested by

no test coverage detected