Esempio n. 1
0
/* stock a newly-created room with objects */
void
stock_room(int shp_indx, struct level *lev, struct mkroom *sroom)
{
    /* 
     * Someday soon we'll dispatch on the shdist field of shclass to do
     * different placements in this routine. Currently it only supports
     * shop-style placement (all squares except a row nearest the first
     * door get objects).
     */
    int sx, sy, sh;
    int rmno = (sroom - lev->rooms) + ROOMOFFSET;
    const struct shclass *shp = &shtypes[shp_indx];

    /* first, try to place a shopkeeper in the room */
    if ((sh = shkinit(shp, lev, sroom)) < 0)
        return;

    /* make sure no doorways without doors, and no */
    /* trapped doors, in shops.  */
    sx = lev->doors[sroom->fdoor].x;
    sy = lev->doors[sroom->fdoor].y;

    if (lev->locations[sx][sy].doormask == D_NODOOR) {
        lev->locations[sx][sy].doormask = D_ISOPEN;
        if (lev == level)
            newsym(sx, sy);
    }
    if (lev->locations[sx][sy].typ == SDOOR) {
        cvt_sdoor_to_door(&lev->locations[sx][sy], &lev->z);   /* .typ = DOOR */
        if (lev == level)
            newsym(sx, sy);
    }
    if (lev->locations[sx][sy].doormask & D_TRAPPED)
        lev->locations[sx][sy].doormask = D_LOCKED;

    if (lev->locations[sx][sy].doormask == D_LOCKED) {
        int m = sx, n = sy;

        if (inside_shop(lev, sx + 1, sy))
            m--;
        else if (inside_shop(lev, sx - 1, sy))
            m++;
        if (inside_shop(lev, sx, sy + 1))
            n--;
        else if (inside_shop(lev, sx, sy - 1))
            n++;
        make_engr_at(lev, m, n, "Closed for inventory", 0L, DUST);
    }

    for (sx = sroom->lx; sx <= sroom->hx; sx++)
        for (sy = sroom->ly; sy <= sroom->hy; sy++) {
            if (sroom->irregular) {
                if (lev->locations[sx][sy].edge ||
                    (int)lev->locations[sx][sy].roomno != rmno ||
                    distmin(sx, sy, lev->doors[sh].x, lev->doors[sh].y) <= 1)
                    continue;
            } else if ((sx == sroom->lx && lev->doors[sh].x == sx - 1) ||
                       (sx == sroom->hx && lev->doors[sh].x == sx + 1) ||
                       (sy == sroom->ly && lev->doors[sh].y == sy - 1) ||
                       (sy == sroom->hy && lev->doors[sh].y == sy + 1))
                continue;
            mkshobj_at(shp, lev, sx, sy);
        }

    /* 
     * Special monster placements (if any) should go here: that way,
     * monsters will sit on top of objects and not the other way around.
     */
}
Esempio n. 2
0
static int ready_weapon(struct obj *wep)
{
	/* Separated function so swapping works easily */
	int res = 0;

	if (!wep) {
	    /* No weapon */
	    if (uwep) {
		pline("You are empty %s.", body_part(HANDED));
		setuwep(NULL);
		res++;
	    } else
		pline("You are already empty %s.", body_part(HANDED));
	} else if (!uarmg && !Stone_resistance && wep->otyp == CORPSE
				&& touch_petrifies(&mons[wep->corpsenm])) {
	    /* Prevent wielding cockatrice when not wearing gloves --KAA */
	    char kbuf[BUFSZ];

	    pline("You wield the %s corpse in your bare %s.",
		mons[wep->corpsenm].mname, makeplural(body_part(HAND)));
	    sprintf(kbuf, "%s corpse", an(mons[wep->corpsenm].mname));
	    instapetrify(kbuf);
	} else if (uarms && bimanual(wep))
	    pline("You cannot wield a two-handed %s while wearing a shield.",
		is_sword(wep) ? "sword" :
		    wep->otyp == BATTLE_AXE ? "axe" : "weapon");
	else if (wep->oartifact && !touch_artifact(wep, &youmonst)) {
	    res++;	/* takes a turn even though it doesn't get wielded */
	} else {
	    /* Weapon WILL be wielded after this point */
	    res++;
	    if (will_weld(wep)) {
		const char *tmp = xname(wep), *thestr = "The ";
		if (strncmp(tmp, thestr, 4) && !strncmp(The(tmp),thestr,4))
		    tmp = thestr;
		else tmp = "";
		pline("%s%s %s to your %s!", tmp, aobjnam(wep, "weld"),
			(wep->quan == 1L) ? "itself" : "themselves", /* a3 */
			bimanual(wep) ?
				(const char *)makeplural(body_part(HAND))
				: body_part(HAND));
		wep->bknown = TRUE;
	    } else {
		/* The message must be printed before setuwep (since
		 * you might die and be revived from changing weapons),
		 * and the message must be before the death message and
		 * Lifesaved rewielding.  Yet we want the message to
		 * say "weapon in hand", thus this kludge.
		 */
		long dummy = wep->owornmask;
		wep->owornmask |= W_WEP;
		prinv(NULL, wep, 0L);
		wep->owornmask = dummy;
	    }
	    setuwep(wep);

	    /* KMH -- Talking artifacts are finally implemented */
	    arti_speak(wep);

	    if (artifact_light(wep) && !wep->lamplit) {
		begin_burn(wep, FALSE);
		if (!Blind)
		    pline("%s to glow brilliantly!", Tobjnam(wep, "begin"));
	    }

	    if (wep->unpaid) {
		struct monst *this_shkp;

		if ((this_shkp = shop_keeper(level, inside_shop(level, u.ux, u.uy))) !=
		    NULL) {
		    pline("%s says \"You be careful with my %s!\"",
			  shkname(this_shkp),
			  xname(wep));
		}
	    }
	}
	return res;
}