called from resurrect() in addition to losedogs() */
| 417 | |
| 418 | /* called from resurrect() in addition to losedogs() */ |
| 419 | void |
| 420 | mon_arrive(struct monst *mtmp, int when) |
| 421 | { |
| 422 | struct trap *t; |
| 423 | coordxy xlocale, ylocale, xyloc, xyflags; |
| 424 | xint16 wander; |
| 425 | int num_segs; |
| 426 | boolean failed_to_place = FALSE; |
| 427 | stairway *stway; |
| 428 | d_level fromdlev; |
| 429 | |
| 430 | mtmp->mstate |= MON_STILL_ARRIVING; |
| 431 | mtmp->nmon = fmon; |
| 432 | fmon = mtmp; |
| 433 | if (mtmp->isshk) |
| 434 | set_residency(mtmp, FALSE); |
| 435 | |
| 436 | num_segs = mtmp->wormno; |
| 437 | /* baby long worms have no tail so don't use is_longworm() */ |
| 438 | if (mtmp->data == &mons[PM_LONG_WORM]) { |
| 439 | mtmp->wormno = get_wormno(); |
| 440 | if (mtmp->wormno) |
| 441 | initworm(mtmp, num_segs); |
| 442 | } else |
| 443 | mtmp->wormno = 0; |
| 444 | |
| 445 | /* some monsters might need to do something special upon arrival |
| 446 | _after_ the current level has been fully set up; see dochug() */ |
| 447 | mtmp->mstrategy |= STRAT_ARRIVE; |
| 448 | mtmp->mstate &= ~(MON_MIGRATING | MON_LIMBO); |
| 449 | |
| 450 | /* make sure mnexto(rloc_to(set_apparxy())) doesn't use stale data */ |
| 451 | mtmp->mux = u.ux, mtmp->muy = u.uy; |
| 452 | xyloc = mtmp->mtrack[0].x; |
| 453 | xyflags = mtmp->mtrack[0].y; |
| 454 | xlocale = mtmp->mtrack[1].x; |
| 455 | ylocale = mtmp->mtrack[1].y; |
| 456 | fromdlev.dnum = mtmp->mtrack[2].x; |
| 457 | fromdlev.dlevel = mtmp->mtrack[2].y; |
| 458 | mon_track_clear(mtmp); |
| 459 | /* in case Protection_from_shape_changers is different now from when |
| 460 | 'mtmp' went onto the migrating monsters list; that's handled in |
| 461 | getlev() when returning to a previously visited level and by the |
| 462 | special level code for monsters specified in the level, but needed |
| 463 | here for monsters migrating to a newly created level */ |
| 464 | restore_cham(mtmp); |
| 465 | |
| 466 | if (mtmp == u.usteed) |
| 467 | return; /* don't place steed on the map */ |
| 468 | if (when == With_you) { |
| 469 | /* When a monster accompanies you, sometimes it will arrive |
| 470 | at your intended destination and you'll end up next to |
| 471 | that spot. This code doesn't control the final outcome; |
| 472 | goto_level(do.c) decides who ends up at your target spot |
| 473 | when there is a monster there too. */ |
| 474 | if (!MON_AT(u.ux, u.uy) |
| 475 | && !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2)) |
| 476 | rloc_to(mtmp, u.ux, u.uy); |
no test coverage detected