/* put the object at the given location */ void place_object(register struct obj *otmp, int x, int y) { register struct obj *otmp2 = level.objects[x][y]; if (otmp->where != OBJ_FREE) panic("place_object: obj not free (%d,%d,%d)", otmp->where, otmp->otyp, otmp->invlet); obj_no_longer_held(otmp); if (otmp->otyp == BOULDER) block_point(x,y); /* vision */ /* obj goes under boulders */ if (otmp2 && (otmp2->otyp == BOULDER)) { otmp->nexthere = otmp2->nexthere; otmp2->nexthere = otmp; } else { otmp->nexthere = otmp2; level.objects[x][y] = otmp; } /* set the new object's location */ otmp->ox = x; otmp->oy = y; otmp->where = OBJ_FLOOR; /* add to floor chain */ otmp->nobj = fobj; fobj = otmp; if (otmp->timed) obj_timer_checks(otmp, x, y, 0); }
/* put the object at the given location */ void place_object(struct obj *otmp, struct level *lev, int x, int y) { struct obj *otmp2 = lev->objects[x][y]; if (otmp->where != OBJ_FREE) panic("place_object: obj not free"); obj_no_longer_held(otmp); if (otmp->otyp == BOULDER) block_point(x,y); /* vision */ /* obj goes under boulders */ if (otmp2 && (otmp2->otyp == BOULDER)) { otmp->nexthere = otmp2->nexthere; otmp2->nexthere = otmp; } else { otmp->nexthere = otmp2; lev->objects[x][y] = otmp; } /* set the new object's location */ otmp->ox = x; otmp->oy = y; otmp->where = OBJ_FLOOR; set_obj_level(lev, otmp); /* set the level recursively for containers */ /* add to floor chain */ otmp->nobj = lev->objlist; lev->objlist = otmp; if (otmp->timed) obj_timer_checks(otmp, x, y, 0); }
/* * Add obj to container, make sure obj is "free". Returns (merged) obj. * The input obj may be deleted in the process. */ struct obj *add_to_container(struct obj *container, struct obj *obj) { struct obj *otmp; if (obj->where != OBJ_FREE) panic("add_to_container: obj not free"); if (container->where != OBJ_INVENT && container->where != OBJ_MINVENT) obj_no_longer_held(obj); /* merge if possible */ for (otmp = container->cobj; otmp; otmp = otmp->nobj) if (merged(&otmp, &obj)) return otmp; obj->where = OBJ_CONTAINED; obj->ocontainer = container; obj->nobj = container->cobj; container->cobj = obj; return obj; }
/* called from resurrect() in addition to losedogs() */ void mon_arrive(struct monst *mtmp, boolean with_you) { struct trap *t; struct obj *otmp; xchar xlocale, ylocale, xyloc, xyflags, wander; int num_segs; mtmp->dlevel = level; mtmp->nmon = level->monlist; level->monlist = mtmp; if (mtmp->isshk) set_residency(mtmp, FALSE); num_segs = mtmp->wormno; /* baby long worms have no tail so don't use is_longworm() */ if ((mtmp->data == &mons[PM_LONG_WORM]) && (mtmp->wormno = get_wormno(mtmp->dlevel)) != 0) { initworm(mtmp, num_segs); /* tail segs are not yet initialized or displayed */ } else mtmp->wormno = 0; /* some monsters might need to do something special upon arrival _after_ the current level has been fully set up; see dochug() */ mtmp->mstrategy |= STRAT_ARRIVE; xyloc = mtmp->xyloc; xyflags = mtmp->xyflags; xlocale = mtmp->xlocale; ylocale = mtmp->ylocale; for (otmp = mtmp->minvent; otmp; otmp = otmp->nobj) set_obj_level(mtmp->dlevel, otmp); if (mtmp == u.usteed) return; /* don't place steed on the map */ if (with_you) { /* When a monster accompanies you, sometimes it will arrive at your intended destination and you'll end up next to that spot. This code doesn't control the final outcome; goto_level(do.c) decides who ends up at your target spot when there is a monster there too. */ if (!MON_AT(level, u.ux, u.uy) && !rn2(mtmp->mtame ? 10 : mtmp->mpeaceful ? 5 : 2)) rloc_to(mtmp, u.ux, u.uy); else mnexto(mtmp); return; } /* * The monster arrived on this level independently of the player. * Its coordinate fields were overloaded for use as flags that * specify its final destination. */ if (mtmp->mlstmv < moves - 1L) { /* heal monster for time spent in limbo */ long nmv = moves - 1L - mtmp->mlstmv; mon_catchup_elapsed_time(mtmp, nmv); mtmp->mlstmv = moves - 1L; /* let monster move a bit on new level (see placement code below) */ wander = (xchar) min(nmv, 8); } else wander = 0; switch (xyloc) { case MIGR_APPROX_XY: /* {x,y}locale set above */ break; case MIGR_EXACT_XY: wander = 0; break; case MIGR_NEAR_PLAYER: xlocale = u.ux, ylocale = u.uy; break; case MIGR_STAIRS_UP: xlocale = level->upstair.sx, ylocale = level->upstair.sy; break; case MIGR_STAIRS_DOWN: xlocale = level->dnstair.sx, ylocale = level->dnstair.sy; break; case MIGR_LADDER_UP: xlocale = level->upladder.sx, ylocale = level->upladder.sy; break; case MIGR_LADDER_DOWN: xlocale = level->dnladder.sx, ylocale = level->dnladder.sy; break; case MIGR_SSTAIRS: xlocale = level->sstairs.sx, ylocale = level->sstairs.sy; break; case MIGR_PORTAL: if (In_endgame(&u.uz)) { /* there is no arrival portal for endgame levels */ /* BUG[?]: for simplicity, this code relies on the fact that we know that the current endgame levels always build upwards and never have any exclusion subregion inside their TELEPORT_REGION settings. */ xlocale = rn1(level->updest.hx - level->updest.lx + 1, level->updest.lx); ylocale = rn1(level->updest.hy - level->updest.ly + 1, level->updest.ly); break; } /* find the arrival portal */ for (t = level->lev_traps; t; t = t->ntrap) if (t->ttyp == MAGIC_PORTAL) break; if (t) { xlocale = t->tx, ylocale = t->ty; break; } else { impossible("mon_arrive: no corresponding portal?"); } /*FALLTHRU*/ default: case MIGR_RANDOM: xlocale = COLNO; ylocale = ROWNO; break; } if ((xlocale != COLNO) && wander) { /* monster moved a bit; pick a nearby location */ /* mnearto() deals w/stone, et al */ char *r = in_rooms(level, xlocale, ylocale, 0); if (r && *r) { coord c; /* somexy() handles irregular level->rooms */ if (somexy(level, &level->rooms[*r - ROOMOFFSET], &c, rng_main)) xlocale = c.x, ylocale = c.y; else { xlocale = COLNO; ylocale = ROWNO; } } else { /* not in a room */ int i, j; i = max(0, xlocale - wander); j = min(COLNO - 1, xlocale + wander); xlocale = rn1(j - i, i); i = max(0, ylocale - wander); j = min(ROWNO - 1, ylocale + wander); ylocale = rn1(j - i, i); } } /* moved a bit */ mtmp->mx = COLNO; /* (already is 0) */ mtmp->my = xyflags; if (xlocale != COLNO) mnearto(mtmp, xlocale, ylocale, FALSE); else { if (!rloc(mtmp, TRUE)) { /* Failed to place migrating monster, probably because the level is full. Dump the monster's cargo and leave the monster dead. */ struct obj *obj; while ((obj = mtmp->minvent) != 0) { obj_extract_self(obj); obj_no_longer_held(obj); if (obj->owornmask & W_MASK(os_wep)) setmnotwielded(mtmp, obj); obj->owornmask = 0L; if (xlocale != COLNO && ylocale != ROWNO) place_object(obj, level, xlocale, ylocale); else { rloco(obj); get_obj_location(obj, &xlocale, &ylocale, 0); } } mkcorpstat(CORPSE, NULL, mtmp->data, level, xlocale, ylocale, FALSE, rng_main); mongone(mtmp); } } mtmp->mux = COLNO; mtmp->muy = ROWNO; }