Example #1
0
/*
 * mhitu: monster hits you
 *	  returns 1 if monster dies (e.g. 'y', 'F'), 0 otherwise
 */
bool
mhitu(struct monst *mtmp)
{
	struct permonst *mdat = mtmp->data;
	int tmp, ctmp;

	nomul(0);

	/* If swallowed, can only be affected by hissers and by u.ustuck */
	if (u.uswallow) {
		if (mtmp != u.ustuck) {
			if (mdat->mlet == 'c' && !rn2(13)) {
				pline("Outside, you hear %s's hissing!",
				      monnam(mtmp));
				pline("%s gets turned to stone!",
				      Monnam(u.ustuck));
				pline("And the same fate befalls you.");
				done_in_by(mtmp);
				/* "notreached": not return(1); */
			}
			return (0);
		}
		switch (mdat->mlet) {	/* now mtmp == u.ustuck */
		case ',':
			youswld(mtmp, (u.uac > 0) ? u.uac + 4 : 4,
				5, "The trapper");
			break;
		case '\'':
			youswld(mtmp, rnd(6), 7, "The lurker above");
			break;
		case 'P':
			youswld(mtmp, d(2, 4), 12, "The purple worm");
			break;
		default:
			/* This is not impossible! */
			pline("The mysterious monster totally digests you.");
			u.uhp = 0;
		}
		if (u.uhp < 1)
			done_in_by(mtmp);
		return (0);
	}

	if (mdat->mlet == 'c' && Stoned)
		return (0);

	/* make eels visible the moment they hit/miss us */
	if (mdat->mlet == ';' && mtmp->minvis && cansee(mtmp->mx, mtmp->my)) {
		mtmp->minvis = 0;
		pmon(mtmp);
	}
	if (!strchr("1&DuxynNF", mdat->mlet))
		tmp = hitu(mtmp, d(mdat->damn, mdat->damd));
	else
		tmp = 0;
	if (strchr(UNDEAD, mdat->mlet) && midnight())
		tmp += hitu(mtmp, d(mdat->damn, mdat->damd));

	ctmp = tmp && !mtmp->mcan &&
	    (!uarm || objects[uarm->otyp].a_can < rnd(3) || !rn2(50));
	switch (mdat->mlet) {
	case '1':
		if (wiz_hit(mtmp))	/* he disappeared */
			return (1);
		break;
	case '&':
		if (!mtmp->cham && !mtmp->mcan && !rn2(13)) {
			makemon(PM_DEMON, u.ux, u.uy);
		} else {
			hitu(mtmp, d(2, 6));
			hitu(mtmp, d(2, 6));
			hitu(mtmp, rnd(3));
			hitu(mtmp, rnd(3));
			hitu(mtmp, rn1(4, 2));
		}
		break;
	case ',':
		if (tmp)
			justswld(mtmp, "The trapper");
		break;
	case '\'':
		if (tmp)
			justswld(mtmp, "The lurker above");
		break;
	case ';':
		if (ctmp) {
			if (!u.ustuck && !rn2(10)) {
				pline("%s swings itself around you!",
				      Monnam(mtmp));
				u.ustuck = mtmp;
			} else if (u.ustuck == mtmp &&
				   levl[mtmp->mx][mtmp->my].typ == POOL) {
				pline("%s drowns you ...", Monnam(mtmp));
				done("drowned");
			}
		}
		break;
	case 'A':
		if (ctmp && rn2(2)) {
			if (Poison_resistance)
				pline("The sting doesn't seem to affect you.");
			else {
				pline("You feel weaker!");
				losestr(1);
			}
		}
		break;
	case 'C':
		hitu(mtmp, rnd(6));
		break;
	case 'c':
		if (!rn2(5)) {
			pline("You hear %s's hissing!", monnam(mtmp));
			if (ctmp || !rn2(20) || (flags.moonphase == NEW_MOON
			    && !carrying(DEAD_LIZARD)))
				Stoned = 5;
		}
		break;
	case 'D':
		if (rn2(6) || mtmp->mcan) {
			hitu(mtmp, d(3, 10));
			hitu(mtmp, rnd(8));
			hitu(mtmp, rnd(8));
			break;
		}
		kludge("%s breathes fire!", "The dragon");
		buzz(-1, mtmp->mx, mtmp->my, u.ux - mtmp->mx, u.uy - mtmp->my);
		break;
	case 'd':
		hitu(mtmp, d(2, (flags.moonphase == FULL_MOON) ? 3 : 4));
		break;
	case 'e':
		hitu(mtmp, d(3, 6));
		break;
	case 'F':
		if (mtmp->mcan)
			break;
		kludge("%s explodes!", "The freezing sphere");
		if (Cold_resistance)
			pline("You don't seem affected by it.");
		else {
			xchar dn;
			if (17 - (u.ulevel / 2) > rnd(20)) {
				pline("You get blasted!");
				dn = 6;
			} else {
				pline("You duck the blast...");
				dn = 3;
			}
			losehp_m(d(dn, 6), mtmp);
		}
		mondead(mtmp);
		return (1);
	case 'g':
		if (ctmp && multi >= 0 && !rn2(3)) {
			kludge("You are frozen by %ss juices", "the cube'");
			nomul(-rnd(10));
		}
		break;
	case 'h':
		if (ctmp && multi >= 0 && !rn2(5)) {
			nomul(-rnd(10));
			kludge("You are put to sleep by %ss bite!",
			       "the homunculus'");
		}
		break;
	case 'j':
		tmp = hitu(mtmp, rnd(3));
		tmp &= hitu(mtmp, rnd(3));
		if (tmp) {
			hitu(mtmp, rnd(4));
			hitu(mtmp, rnd(4));
		}
		break;
	case 'k':
		if ((hitu(mtmp, rnd(4)) || !rn2(3)) && ctmp)
			poisoned("bee's sting", mdat->mname);
		break;
	case 'L':
		if (tmp)
			stealgold(mtmp);
		break;
	case 'N':
		if (mtmp->mcan && !Blind) {
			pline("%s tries to seduce you, but you seem not interested.",
			    Amonnam(mtmp, "plain"));
			if (rn2(3))
				rloc(mtmp);
		} else if (steal(mtmp)) {
			rloc(mtmp);
			mtmp->mflee = 1;
		}
		break;
	case 'n':
		if (!uwep && !uarm && !uarmh && !uarms && !uarmg) {
			pline("%s hits! (I hope you don't mind)",
			      Monnam(mtmp));
			u.uhp += rnd(7);
			if (!rn2(7))
				u.uhpmax++;
			if (u.uhp > u.uhpmax)
				u.uhp = u.uhpmax;
			flags.botl = 1;
			if (!rn2(50))
				rloc(mtmp);
		} else {
			hitu(mtmp, d(2, 6));
			hitu(mtmp, d(2, 6));
		}
		break;
	case 'o':
		tmp = hitu(mtmp, rnd(6));
		if (hitu(mtmp, rnd(6)) && tmp &&	/* hits with both paws */
		    !u.ustuck && rn2(2)) {
			u.ustuck = mtmp;
			kludge("%s has grabbed you!", "The owlbear");
			u.uhp -= d(2, 8);
		} else if (u.ustuck == mtmp) {
			u.uhp -= d(2, 8);
			pline("You are being crushed.");
		}
		break;
	case 'P':
		if (ctmp && !rn2(4))
			justswld(mtmp, "The purple worm");
		else
			hitu(mtmp, d(2, 4));
		break;
	case 'Q':
		hitu(mtmp, rnd(2));
		hitu(mtmp, rnd(2));
		break;
	case 'R':
		if (tmp && uarmh && !uarmh->rustfree &&
		    (int)uarmh->spe >= -1) {
			pline("Your helmet rusts!");
			uarmh->spe--;
		} else if (ctmp && uarm && !uarm->rustfree &&	/* Mike Newton */
		    uarm->otyp < STUDDED_LEATHER_ARMOR &&
		    (int)uarm->spe >= -1) {
			pline("Your armor rusts!");
			uarm->spe--;
		}
		break;
	case 'S':
		if (ctmp && !rn2(8))
			poisoned("snake's bite", mdat->mname);
		break;
	case 's':
		if (tmp && !rn2(8))
			poisoned("scorpion's sting", mdat->mname);
		hitu(mtmp, rnd(8));
		hitu(mtmp, rnd(8));
		break;
	case 'T':
		hitu(mtmp, rnd(6));
		hitu(mtmp, rnd(6));
		break;
	case 't':
		if (!rn2(5))
			rloc(mtmp);
		break;
	case 'u':
		mtmp->mflee = 1;
		break;
	case 'U':
		hitu(mtmp, d(3, 4));
		hitu(mtmp, d(3, 4));
		break;
	case 'v':
		if (ctmp && !u.ustuck)
			u.ustuck = mtmp;
		break;
	case 'V':
		if (tmp)
			u.uhp -= 4;
		if (ctmp)
			losexp();
		break;
	case 'W':
		if (ctmp)
			losexp();
		break;
#ifndef NOWORM
	case 'w':
		if (tmp)
			wormhit(mtmp);
#endif /* NOWORM */
		break;
	case 'X':
		hitu(mtmp, rnd(5));
		hitu(mtmp, rnd(5));
		hitu(mtmp, rnd(5));
		break;
	case 'x':
		{
			long side = rn2(2) ? RIGHT_SIDE : LEFT_SIDE;
			pline("%s pricks in your %s leg!",
			    Monnam(mtmp), (side == RIGHT_SIDE) ? "right" : "left");
			set_wounded_legs(side, rnd(50));
			losehp_m(2, mtmp);
			break;
		}
	case 'y':
		if (mtmp->mcan)
			break;
		mondead(mtmp);
		if (!Blind) {
			pline("You are blinded by a blast of light!");
			Blind = d(4, 12);
			seeoff(0);
		}
		return (1);
	case 'Y':
		hitu(mtmp, rnd(6));
		break;
	}
	if (u.uhp < 1)
		done_in_by(mtmp);
	return (0);
}
Example #2
0
void
m_throw(struct monst *mon, int x, int y, int dx, int dy, int range,
        struct obj *obj, boolean verbose)
{
    struct monst *mtmp;
    struct obj *singleobj;
    struct tmp_sym *tsym = 0;
    int hitu, blindinc = 0;

    bhitpos.x = x;
    bhitpos.y = y;

    if (obj->quan == 1L) {
        /*
         * Remove object from minvent.  This cannot be done later on;
         * what if the player dies before then, leaving the monster
         * with 0 daggers?  (This caused the infamous 2^32-1 orcish
         * dagger bug).
         *
         * VENOM is not in minvent - it should already be OBJ_FREE.
         * The extract below does nothing.
         */

        /* not possibly_unwield, which checks the object's */
        /* location, not its existence */
        if (MON_WEP(mon) == obj) {
            setmnotwielded(mon, obj);
            MON_NOWEP(mon);
        }
        obj_extract_self(obj);
        singleobj = obj;
        obj = NULL;
    } else {
        singleobj = splitobj(obj, 1L);
        obj_extract_self(singleobj);
    }

    singleobj->owornmask = 0;   /* threw one of multiple weapons in hand? */
    singleobj->olev = level;    /* object is on the same level as monster */

    if ((singleobj->cursed || singleobj->greased) && (dx || dy) && !rn2(7)) {
        if (canseemon(mon) && flags.verbose) {
            if (is_ammo(singleobj))
                pline("%s misfires!", Monnam(mon));
            else
                pline("%s as %s throws it!", Tobjnam(singleobj, "slip"),
                      mon_nam(mon));
        }
        dx = rn2(3) - 1;
        dy = rn2(3) - 1;
        /* check validity of new direction */
        if (!dx && !dy) {
            drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
            return;
        }
    }

    /* pre-check for doors, walls and boundaries. Also need to pre-check for
       bars regardless of direction; the random chance for small objects
       hitting bars is skipped when reaching them at point blank range */
    if (!isok(bhitpos.x + dx, bhitpos.y + dy)
        || IS_ROCK(level->locations[bhitpos.x + dx][bhitpos.y + dy].typ)
        || closed_door(level, bhitpos.x + dx, bhitpos.y + dy)
        || (level->locations[bhitpos.x + dx][bhitpos.y + dy].typ == IRONBARS &&
            hits_bars(&singleobj, bhitpos.x, bhitpos.y, 0, 0))) {
        drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
        return;
    }

    /* Note: drop_throw may destroy singleobj.  Since obj must be destroyed
       early to avoid the dagger bug, anyone who modifies this code should be
       careful not to use either one after it's been freed. */
    tsym = tmpsym_initobj(singleobj);

    while (range-- > 0) {      /* Actually the loop is always exited by break */
        bhitpos.x += dx;
        bhitpos.y += dy;
        if ((mtmp = m_at(level, bhitpos.x, bhitpos.y)) != 0) {
            if (ohitmon(mtmp, singleobj, range, verbose))
                break;
        } else if (bhitpos.x == u.ux && bhitpos.y == u.uy) {
            action_interrupted();

            if (singleobj->oclass == GEM_CLASS &&
                singleobj->otyp <= LAST_GEM + 9
                /* 9 glass colors */
                && is_unicorn(youmonst.data) && !u_helpless(hm_all)) {
                if (singleobj->otyp > LAST_GEM) {
                    pline("You catch the %s.", xname(singleobj));
                    pline("You are not interested in %s junk.",
                          s_suffix(mon_nam(mon)));
                    makeknown(singleobj->otyp);
                    dropy(singleobj);
                } else {
                    pline("You accept %s gift in the spirit in which it was "
                          "intended.", s_suffix(mon_nam(mon)));
                    hold_another_object(singleobj, "You catch, but drop, %s.",
                                        xname(singleobj), "You catch:");
                }
                break;
            }
            if (singleobj->oclass == POTION_CLASS) {
                if (!Blind)
                    singleobj->dknown = 1;
                potionhit(&youmonst, singleobj, FALSE);
                break;
            }
            switch (singleobj->otyp) {
                int dam, hitv;

            case EGG:
                if (!touch_petrifies(&mons[singleobj->corpsenm])) {
                    impossible("monster throwing egg type %d",
                               singleobj->corpsenm);
                    hitu = 0;
                    break;
                }
                /* fall through */
            case CREAM_PIE:
            case BLINDING_VENOM:
                hitu = thitu(8, 0, singleobj, NULL);
                break;
            default:
                dam = dmgval(singleobj, &youmonst);
                hitv = 3 - distmin(u.ux, u.uy, mon->mx, mon->my);
                if (hitv < -4)
                    hitv = -4;
                if (is_elf(mon->data) &&
                    objects[singleobj->otyp].oc_skill == P_BOW) {
                    hitv++;
                    if (MON_WEP(mon) && MON_WEP(mon)->otyp == ELVEN_BOW)
                        hitv++;
                    if (singleobj->otyp == ELVEN_ARROW)
                        dam++;
                }
                if (bigmonst(youmonst.data))
                    hitv++;
                hitv += 8 + singleobj->spe;
                if (dam < 1)
                    dam = 1;
                if (objects[singleobj->otyp].oc_class == WEAPON_CLASS ||
                    objects[singleobj->otyp].oc_class == VENOM_CLASS) {
                    hitv += objects[singleobj->otyp].oc_hitbon;
                }
                hitu = thitu(hitv, dam, singleobj, NULL);
            }
            if (hitu && singleobj->opoisoned && is_poisonable(singleobj)) {
                poisoned(xname(singleobj), A_STR,
                         killer_msg_obj(POISONING, singleobj), -10);
            }
            if (hitu &&
                can_blnd(NULL, &youmonst,
                         (uchar) (singleobj->otyp ==
                                  BLINDING_VENOM ? AT_SPIT : AT_WEAP),
                         singleobj)) {
                blindinc = rnd(25);
                if (singleobj->otyp == CREAM_PIE) {
                    if (!Blind)
                        pline("Yecch!  You've been creamed.");
                    else
                        pline("There's something sticky all over your %s.",
                              body_part(FACE));
                } else if (singleobj->otyp == BLINDING_VENOM) {
                    int num_eyes = eyecount(youmonst.data);

                    /* venom in the eyes */
                    if (!Blind)
                        pline("The venom blinds you.");
                    else
                        pline("Your %s sting%s.",
                              (num_eyes ==
                               1) ? body_part(EYE) : makeplural(body_part(EYE)),
                              (num_eyes == 1) ? "s" : "");
                }
            }
            if (hitu && singleobj->otyp == VAMPIRE_BLOOD) {
                if (!Drain_resistance) {
                    losexp("vampire blood", FALSE);
                }
            }
            if (hitu && singleobj->otyp == EGG) {
                if (touched_monster(singleobj->corpsenm))
                    Stoned = 5;
            }
            action_interrupted();
            if (hitu || !range) {
                drop_throw(singleobj, hitu, u.ux, u.uy);
                break;
            }
        } else if (!range       /* reached end of path */
                   /* missile hits edge of screen */
                   || !isok(bhitpos.x + dx, bhitpos.y + dy)
                   /* missile hits the wall */
                   || IS_ROCK(level->
                              locations[bhitpos.x + dx][bhitpos.y + dy].typ)
                   /* missile hit closed door */
                   || closed_door(level, bhitpos.x + dx, bhitpos.y + dy)
                   /* missile might hit iron bars */
                   || (level->locations[bhitpos.x + dx][bhitpos.y + dy].typ ==
                       IRONBARS &&
                       hits_bars(&singleobj, bhitpos.x, bhitpos.y, !rn2(5), 0))
                   /* Thrown objects "sink" */
                   || IS_SINK(level->locations[bhitpos.x][bhitpos.y].typ)) {
            if (singleobj)      /* hits_bars might have destroyed it */
                drop_throw(singleobj, 0, bhitpos.x, bhitpos.y);
            break;
        }
        tmpsym_at(tsym, bhitpos.x, bhitpos.y);
        win_delay_output();
    }
    tmpsym_at(tsym, bhitpos.x, bhitpos.y);
    win_delay_output();
    tmpsym_end(tsym);

    if (blindinc) {
        u.ucreamed += blindinc;
        make_blinded(Blinded + (long)blindinc, FALSE);
        if (!Blind)
            pline("Your vision quickly clears.");
        else if (flags.verbose)
            pline("Use the command #wipe to clean your %s.", body_part(FACE));
    }
}
Example #3
0
void do_trap(trap_t *trap) // was dotrap
{
  Short ttype = get_trap_type(trap->trap_info);

  nomul(0);
  if (get_trap_seen(trap->trap_info) && !rund(5) && ttype != PIT) {
    StrPrintF(ScratchBuffer, "You escape a%s.", traps[ttype]);
    message(ScratchBuffer);
  } else {
    trap->trap_info |= SEEN_TRAP;
    switch(ttype) {
    case SLP_GAS_TRAP:
      message("A cloud of gas puts you to sleep!");
      nomul(-rnd(25));
      break;
    case BEAR_TRAP:
      if (Levitation) {
	message("You float over a bear trap.");
	break;
      }
      you.utrap = 4 + rund(4);
      you.utraptype = TT_BEARTRAP;
      message("A bear trap closes on your foot!");
      break;
    case PIERC:
      deltrap(trap);
      if (makemon(PM_PIERCER, you.ux, you.uy)) {
	message("A piercer suddenly drops from the ceiling!");
	if (uarmh)
	  message("Its blow glances off your helmet.");
	else
	  thing_hit_you(3, dice(4,6), "falling piercer");
      }
      break;
    case ARROW_TRAP:
      message("An arrow shoots out at you!");
      if (!thing_hit_you(8, rnd(6), "arrow")){
	mksobj_at(ARROW, you.ux, you.uy);
	fobj->quantity = 1;
      }
      break;
    case TRAPDOOR:
      if (!xdnstair) {
	message("A trap door in the ceiling opens and a rock falls on your head!");
	if (uarmh) message("Fortunately, you are wearing a helmet!");
	losehp((uarmh ? 2 : dice(2,10)), "falling rock");
	mksobj_at(ROCK, you.ux, you.uy);
	fobj->quantity = 1;
	stackobj(fobj);
	if (Invisible) newsym(you.ux, you.uy);
      } else {
	Short newlevel = dlevel + 1;
	while (!rund(4) && newlevel < 29)
	  newlevel++;
	message("A trap door opens up under you!");
	if (Levitation || you.ustuck) {
	  message("For some reason you don't fall in.");
	  break;
	}

	goto_level(newlevel, false);
      }
      break;
    case DART_TRAP:
      message("A little dart shoots out at you!");
      if (thing_hit_you(7, rnd(3), "little dart")) {
	if (!rund(6))
	  poisoned("dart", "poison dart");
      } else {
	mksobj_at(DART, you.ux, you.uy);
	fobj->quantity = 1;
      }
      break;
    case TELEP_TRAP:
      map_mode_teleport = TELE_TRAP;
      if (get_trap_once(trap->trap_info)) {
	deltrap(trap);
	newsym(you.ux,you.uy);
	vtele();
      } else {
	newsym(you.ux,you.uy);
	tele();
      }
      break;
    case PIT:
      if (Levitation) {
	message("A pit opens up under you!");
	message("You don't fall in!");
	break;
      }
      message("You fall into a pit!");
      you.utrap = rund(6) + 2;
      you.utraptype = TT_PIT;
      losehp(rnd(6),"fall into a pit");
      selftouch("Falling, you");
      break;
    default:
      StrPrintF(ScratchBuffer, "BUG: You hit a trap with info=%u",
		trap->trap_info);
      message(ScratchBuffer);
    }
  }
}