boolean teleport_pet(struct monst * mtmp, boolean force_it) { struct obj *otmp; if (mtmp == u.usteed) return FALSE; if (mtmp->mleashed) { otmp = get_mleash(mtmp); if (!otmp) { impossible("%s is leashed, without a leash.", Monnam(mtmp)); goto release_it; } if (otmp->cursed && !force_it) { yelp(mtmp); return FALSE; } else { pline("Your leash goes slack."); release_it: m_unleash(mtmp, FALSE); return TRUE; } } return TRUE; }
void abuse_dog(struct monst *mtmp) { if (!mtmp->mtame) return; if (Aggravate_monster || Conflict) mtmp->mtame /= 2; else mtmp->mtame--; if (mtmp->mtame && !mtmp->isminion) EDOG(mtmp)->abuse++; if (!mtmp->mtame && mtmp->mleashed) m_unleash(mtmp, TRUE); /* don't make a sound if pet is in the middle of leaving the level */ /* newsym isn't necessary in this case either */ if (mtmp->mx != COLNO) { if (mtmp->mtame && rn2(mtmp->mtame)) yelp(mtmp); else growl(mtmp); /* give them a moment's worry */ if (!mtmp->mtame && mtmp->dlevel == level) newsym(mtmp->mx, mtmp->my); } }
void migrate_to_level( struct monst *mtmp, xchar tolev, /* destination level */ xchar xyloc, /* MIGR_xxx destination xy location: */ coord *cc) /* optional destination coordinates */ { struct obj *obj; d_level new_lev; xchar xyflags; int num_segs = 0; /* count of worm segments */ if (mtmp->isshk) set_residency(mtmp, TRUE); if (mtmp->wormno) { int cnt; /* **** NOTE: worm is truncated to # segs = max wormno size **** */ cnt = count_wsegs(mtmp); num_segs = min(cnt, MAX_NUM_WORMS - 1); wormgone(mtmp); } /* set minvent's obj->no_charge to 0 */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (Has_contents(obj)) picked_container(obj); /* does the right thing */ obj->no_charge = 0; } if (mtmp->mleashed) { mtmp->mtame--; m_unleash(mtmp, TRUE); } relmon(mtmp); mtmp->nmon = migrating_mons; migrating_mons = mtmp; newsym(mtmp->mx,mtmp->my); new_lev.dnum = ledger_to_dnum((xchar)tolev); new_lev.dlevel = ledger_to_dlev((xchar)tolev); /* overload mtmp->[mx,my], mtmp->[mux,muy], and mtmp->mtrack[] as */ /* destination codes (setup flag bits before altering mx or my) */ xyflags = (depth(&new_lev) < depth(&u.uz)); /* 1 => up */ if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) xyflags |= 2; mtmp->wormno = num_segs; mtmp->mlstmv = moves; mtmp->mtrack[1].x = cc ? cc->x : mtmp->mx; mtmp->mtrack[1].y = cc ? cc->y : mtmp->my; mtmp->mtrack[0].x = xyloc; mtmp->mtrack[0].y = xyflags; mtmp->mux = new_lev.dnum; mtmp->muy = new_lev.dlevel; mtmp->mx = mtmp->my = 0; /* this implies migration */ }
/* The player kicks or whips the steed */ void kick_steed(void) { char He[4]; if (!u.usteed) return; /* [ALI] Various effects of kicking sleeping/paralyzed steeds */ if (u.usteed->msleeping || !u.usteed->mcanmove) { /* We assume a message has just been output of the form "You kick <steed>." */ strcpy(He, mhe(u.usteed)); *He = highc(*He); if ((u.usteed->mcanmove || u.usteed->mfrozen) && !rn2(2)) { if (u.usteed->mcanmove) u.usteed->msleeping = 0; else if (u.usteed->mfrozen > 2) u.usteed->mfrozen -= 2; else { u.usteed->mfrozen = 0; u.usteed->mcanmove = 1; } if (u.usteed->msleeping || !u.usteed->mcanmove) pline("%s stirs.", He); else pline("%s rouses %sself!", He, mhim(u.usteed)); } else pline("%s does not respond.", He); return; } /* Make the steed less tame and check if it resists */ if (u.usteed->mtame) u.usteed->mtame--; if (!u.usteed->mtame && u.usteed->mleashed) m_unleash(u.usteed, TRUE); if (!u.usteed->mtame || (u.ulevel + u.usteed->mtame < rnd(MAXULEV / 2 + 5))) { newsym(u.usteed->mx, u.usteed->my); dismount_steed(DISMOUNT_THROWN); return; } pline("%s gallops!", Monnam(u.usteed)); u.ugallop += rn1(20, 30); return; }
/* * Called during pet revival or pet life-saving. * If you killed the pet, it revives wild. * If you abused the pet a lot while alive, it revives wild. * If you abused the pet at all while alive, it revives untame. * If the pet wasn't abused and was very tame, it might revive tame. */ void wary_dog(struct monst *mtmp, boolean was_dead) { struct edog *edog; boolean quietly = was_dead; mtmp->meating = 0; if (!mtmp->mtame) return; edog = !mtmp->isminion ? EDOG(mtmp) : 0; /* if monster was starving when it died, undo that now */ if (edog && edog->mhpmax_penalty) { mtmp->mhpmax += edog->mhpmax_penalty; mtmp->mhp += edog->mhpmax_penalty; /* heal it */ edog->mhpmax_penalty = 0; } if (edog && (edog->killed_by_u == 1 || edog->abuse > 2)) { msethostility(mtmp, TRUE, FALSE); if (edog->abuse >= 0 && edog->abuse < 10) if (!rn2_on_rng(edog->abuse + 1, rng_dog_untame)) msethostility(mtmp, FALSE, FALSE); if (!quietly && cansee(mtmp->mx, mtmp->my)) { if (haseyes(youmonst.data)) { if (haseyes(mtmp->data)) pline("%s %s to look you in the %s.", Monnam(mtmp), mtmp->mpeaceful ? "seems unable" : "refuses", body_part(EYE)); else pline("%s avoids your gaze.", Monnam(mtmp)); } } } else { /* chance it goes wild anyway - Pet Semetary */ if (rn2_on_rng(mtmp->mtame, rng_dog_untame) == mtmp->mtame - 1) msethostility(mtmp, TRUE, FALSE); } if (!mtmp->mtame) { newsym(mtmp->mx, mtmp->my); /* a life-saved monster might be leashed; don't leave it that way if it's no longer tame */ if (mtmp->mleashed) m_unleash(mtmp, TRUE); } /* if its still a pet, start a clean pet-slate now */ if (edog && mtmp->mtame) { edog->revivals++; edog->killed_by_u = 0; edog->abuse = 0; if (was_dead || edog->hungrytime < moves + 500L) edog->hungrytime = moves + 500L; if (was_dead) { edog->droptime = 0L; edog->dropdist = 10000; edog->whistletime = 0L; edog->apport = 5; } /* else lifesaved, so retain current values */ } }
void migrate_to_level(struct monst *mtmp, xchar tolev, /* destination level */ xchar xyloc, /* MIGR_xxx destination xy location: */ coord * cc) { /* optional destination coordinates */ struct obj *obj; d_level new_lev; xchar xyflags; int num_segs = 0; /* count of worm segments */ if (mtmp->isshk) set_residency(mtmp, TRUE); if (mtmp->wormno) { int cnt; /* **** NOTE: worm is truncated to # segs = max wormno size **** */ cnt = count_wsegs(mtmp); num_segs = min(cnt, MAX_NUM_WORMS - 1); wormgone(mtmp); } /* set minvent's obj->no_charge to 0 */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (Has_contents(obj)) picked_container(obj); /* does the right thing */ obj->no_charge = 0; } if (mtmp->mleashed) { mtmp->mtame--; m_unleash(mtmp, TRUE); } relmon(mtmp); mtmp->nmon = migrating_mons; migrating_mons = mtmp; if (mtmp->dlevel == level) newsym(mtmp->mx, mtmp->my); /* The dlevel pointer is meaningless for a migrating monster. Set it to NULL so that any uses of it are detected quickly via the resulting segfault. */ mtmp->dlevel = NULL; new_lev.dnum = ledger_to_dnum((xchar) tolev); new_lev.dlevel = ledger_to_dlev((xchar) tolev); /* set migration data */ xyflags = (depth(&new_lev) < depth(&u.uz)); /* 1 => up */ if (In_W_tower(mtmp->mx, mtmp->my, &u.uz)) xyflags |= 2; mtmp->wormno = num_segs; mtmp->mlstmv = moves; mtmp->xlocale = cc ? cc->x : mtmp->mx; mtmp->ylocale = cc ? cc->y : mtmp->my; mtmp->xyloc = xyloc; mtmp->xyflags = xyflags; mtmp->mux = new_lev.dnum; mtmp->muy = new_lev.dlevel; mtmp->mx = COLNO; mtmp->my = ROWNO; /* this implies migration */ }
/* called when you move to another level * pets_only: true for ascension or final escape */ void keepdogs(boolean pets_only) { struct monst *mtmp, *mtmp2; struct obj *obj; int num_segs; boolean stay_behind; for (mtmp = level->monlist; mtmp; mtmp = mtmp2) { mtmp2 = mtmp->nmon; if (DEADMONSTER(mtmp)) continue; if (pets_only && !mtmp->mtame) continue; if (((monnear(mtmp, u.ux, u.uy) && levl_follower(mtmp)) || (mtmp == u.usteed) || /* the wiz will level t-port from anywhere to chase the amulet; if you don't have it, will chase you only if in range. -3. */ (Uhave_amulet && mtmp->iswiz)) && ((!mtmp->msleeping && mtmp->mcanmove) /* eg if level teleport or new trap, steed has no control to avoid following */ || (mtmp == u.usteed)) /* monster won't follow if it hasn't noticed you yet */ && !(mtmp->mstrategy & STRAT_WAITFORU)) { stay_behind = FALSE; if (!pets_only && mtmp->mtame && mtmp->meating) { if (canseemon(mtmp)) pline("%s is still eating.", Monnam(mtmp)); stay_behind = TRUE; } else if (mon_has_amulet(mtmp)) { if (canseemon(mtmp)) pline("%s seems very disoriented for a moment.", Monnam(mtmp)); stay_behind = TRUE; } else if (!pets_only && mtmp->mtame && mtmp->mtrapped) { if (canseemon(mtmp)) pline("%s is still trapped.", Monnam(mtmp)); stay_behind = TRUE; } if (mtmp == u.usteed) stay_behind = FALSE; if (stay_behind) { if (mtmp->mleashed) { pline("%s leash suddenly comes loose.", humanoid(mtmp->data) ? (mtmp->female ? "Her" : "His") : "Its"); m_unleash(mtmp, FALSE); } continue; } if (mtmp->isshk) set_residency(mtmp, TRUE); if (mtmp->wormno) { int cnt; /* NOTE: worm is truncated to # segs = max wormno size */ cnt = count_wsegs(mtmp); num_segs = min(cnt, MAX_NUM_WORMS - 1); wormgone(mtmp); } else num_segs = 0; /* set minvent's obj->no_charge to 0 */ for (obj = mtmp->minvent; obj; obj = obj->nobj) { if (Has_contents(obj)) picked_container(obj); /* does the right thing */ obj->no_charge = 0; } relmon(mtmp); newsym(mtmp->mx, mtmp->my); mtmp->mx = COLNO; /* avoid mnexto()/MON_AT() problem */ mtmp->my = ROWNO; mtmp->wormno = num_segs; mtmp->mlstmv = moves; mtmp->nmon = turnstate.migrating_pets; turnstate.migrating_pets = mtmp; } else if (mtmp->iswiz) { /* we want to be able to find him when his next resurrection chance comes up, but have him resume his present location if player returns to this level before that time */ migrate_to_level(mtmp, ledger_no(&u.uz), MIGR_EXACT_XY, NULL); } else if (mtmp->mleashed) { /* this can happen if your quest leader ejects you from the "home" level while a leashed pet isn't next to you */ pline("%s leash goes slack.", s_suffix(Monnam(mtmp))); m_unleash(mtmp, FALSE); } } }
/* heal monster for time spent elsewhere */ void mon_catchup_elapsed_time(struct monst *mtmp, long nmv) { int imv = 0; /* avoid zillions of casts and lint warnings */ /* Without this, if a monster is deleted during level creation (e.g. statue trap) and the player comes to the level later, it'll have healed itself out of the "deleted" state, thoroughly confusing dmonsfree(). */ if (DEADMONSTER(mtmp)) return; if (nmv >= LARGEST_INT) /* paranoia */ imv = LARGEST_INT - 1; else imv = (int)nmv; /* might stop being afraid, blind or frozen */ /* set to 1 and allow final decrement in movemon() */ if (mtmp->mblinded) { if (imv >= (int)mtmp->mblinded) mtmp->mblinded = 1; else mtmp->mblinded -= imv; } if (mtmp->mfrozen) { if (imv >= (int)mtmp->mfrozen) mtmp->mfrozen = 1; else mtmp->mfrozen -= imv; } if (mtmp->mfleetim) { if (imv >= (int)mtmp->mfleetim) mtmp->mfleetim = 1; else mtmp->mfleetim -= imv; } /* might recover from temporary trouble */ if (mtmp->mtrapped && rn2(imv + 1) > 40 / 2) mtmp->mtrapped = 0; if (mtmp->mconf && rn2(imv + 1) > 50 / 2) mtmp->mconf = 0; if (mtmp->mstun && rn2(imv + 1) > 10 / 2) mtmp->mstun = 0; /* might finish eating or be able to use special ability again */ if (imv > mtmp->meating) mtmp->meating = 0; else mtmp->meating -= imv; if (imv > mtmp->mspec_used) mtmp->mspec_used = 0; else mtmp->mspec_used -= imv; /* reduce tameness for every 150 moves you are separated */ if (mtmp->mtame) { int wilder = (imv + 75) / 150; /* The rng_dog_untame RNG is only semi-synched, because the argument changes. This gives better results than rng_main, and we can't match exactly due to different pet-wrangling habits. Note: not msethostility; we're off-level right now. */ if (mtmp->mtame > wilder) mtmp->mtame -= wilder; /* less tame */ else if (mtmp->mtame > rn2_on_rng(wilder, rng_dog_untame)) mtmp->mtame = 0; /* untame */ else mtmp->mtame = mtmp->mpeaceful = 0; /* hostile! */ } /* check to see if it would have died as a pet; if so, go wild instead of dying the next time we call dog_move() */ if (mtmp->mtame && !mtmp->isminion && (carnivorous(mtmp->data) || herbivorous(mtmp->data))) { const struct edog *edog = CONST_EDOG(mtmp); if ((moves > edog->hungrytime + 500 && mtmp->mhp < 3) || (moves > edog->hungrytime + 750)) mtmp->mtame = mtmp->mpeaceful = 0; } if (!mtmp->mtame && mtmp->mleashed) { /* leashed monsters should always be with hero, consequently never losing any time to be accounted for later */ impossible("catching up for leashed monster?"); m_unleash(mtmp, FALSE); } /* recover lost hit points */ if (!regenerates(mtmp->data)) imv /= 20; if (mtmp->mhp + imv >= mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; else mtmp->mhp += imv; }
/* Start riding, with the given monster */ boolean mount_steed(struct monst * mtmp, /* The animal */ boolean force) { /* Quietly force this animal */ struct obj *otmp; const struct permonst *ptr; /* Sanity checks */ if (u.usteed) { pline("You are already riding %s.", mon_nam(u.usteed)); return FALSE; } /* Is the player in the right form? */ if (Hallucination && !force) { pline("Maybe you should find a designated driver."); return FALSE; } /* While riding Wounded_legs refers to the steed's, not the hero's legs. That opens up a potential abuse where the player can mount a steed, then dismount immediately to heal leg damage, because leg damage is always healed upon dismount (Wounded_legs context switch). By preventing a hero with Wounded_legs from mounting a steed, the potential for abuse is minimized, if not eliminated altogether. */ if (Wounded_legs) { pline("Your %s are in no shape for riding.", makeplural(body_part(LEG))); if (force && wizard && yn("Heal your legs?") == 'y') LWounded_legs = RWounded_legs = 0; else return FALSE; } if (Upolyd && (!humanoid(youmonst.data) || verysmall(youmonst.data) || bigmonst(youmonst.data) || slithy(youmonst.data))) { pline("You won't fit on a saddle."); return FALSE; } if (!force && (near_capacity() > SLT_ENCUMBER)) { pline("You can't do that while carrying so much stuff."); return FALSE; } /* Can the player reach and see the monster? */ if (!mtmp || (!force && ((Blind && !Blind_telepat) || mtmp->mundetected || mtmp->m_ap_type == M_AP_FURNITURE || mtmp->m_ap_type == M_AP_OBJECT))) { pline("I see nobody there."); return FALSE; } struct test_move_cache cache; init_test_move_cache(&cache); if (Engulfed || u.ustuck || u.utrap || Punished || !test_move(u.ux, u.uy, mtmp->mx - u.ux, mtmp->my - u.uy, 0, TEST_MOVE, &cache)) { if (Punished || !(Engulfed || u.ustuck || u.utrap)) pline("You are unable to swing your %s over.", body_part(LEG)); else pline("You are stuck here for now."); return FALSE; } /* Is this a valid monster? */ otmp = which_armor(mtmp, os_saddle); if (!otmp) { pline("%s is not saddled.", Monnam(mtmp)); return FALSE; } ptr = mtmp->data; if (touch_petrifies(ptr) && !Stone_resistance) { pline("You touch %s.", mon_nam(mtmp)); instapetrify(killer_msg(STONING, msgcat("attempting to ride ", an(mtmp->data->mname)))); } if (!mtmp->mtame || mtmp->isminion) { pline("I think %s would mind.", mon_nam(mtmp)); return FALSE; } if (mtmp->mtrapped) { struct trap *t = t_at(level, mtmp->mx, mtmp->my); pline("You can't mount %s while %s's trapped in %s.", mon_nam(mtmp), mhe(mtmp), t ? an(trapexplain[t->ttyp - 1]) : "ice"); return FALSE; } if (!force && !Role_if(PM_KNIGHT) && !(--mtmp->mtame)) { /* no longer tame */ newsym(mtmp->mx, mtmp->my); pline("%s resists%s!", Monnam(mtmp), mtmp->mleashed ? " and its leash comes off" : ""); if (mtmp->mleashed) m_unleash(mtmp, FALSE); return FALSE; } if (!force && Underwater && !is_swimmer(ptr)) { pline("You can't ride that creature while under water."); return FALSE; } if (!can_saddle(mtmp) || !can_ride(mtmp)) { pline("You can't ride such a creature."); return 0; } /* Is the player impaired? */ if (!force && !is_floater(ptr) && !is_flyer(ptr) && Levitation && !Lev_at_will) { pline("You cannot reach %s.", mon_nam(mtmp)); return FALSE; } if (!force && uarm && is_metallic(uarm) && greatest_erosion(uarm)) { pline("Your %s armor is too stiff to be able to mount %s.", uarm->oeroded ? "rusty" : "corroded", mon_nam(mtmp)); return FALSE; } if (!force && (Confusion || Fumbling || Glib || Wounded_legs || otmp->cursed || ((u.ulevel + mtmp->mtame < rnd(MAXULEV / 2 + 5)) && (!Role_if(PM_KNIGHT))))) { if (Levitation) { pline("%s slips away from you.", Monnam(mtmp)); return FALSE; } pline("You slip while trying to get on %s.", mon_nam(mtmp)); const char *buf = msgcat( "slipped while mounting ", /* "a saddled mumak" or "a saddled pony called Dobbin" */ x_monnam(mtmp, ARTICLE_A, NULL, SUPPRESS_IT | SUPPRESS_INVISIBLE | SUPPRESS_HALLUCINATION, TRUE)); losehp(rn1(5, 10), buf); return FALSE; } /* Success */ maybewakesteed(mtmp); if (!force) { if (Levitation && !is_floater(ptr) && !is_flyer(ptr)) /* Must have Lev_at_will at this point */ pline("%s magically floats up!", Monnam(mtmp)); pline("You mount %s.", mon_nam(mtmp)); } /* setuwep handles polearms differently when you're mounted */ if (uwep && is_pole(uwep)) u.bashmsg = TRUE; u.usteed = mtmp; remove_monster(level, mtmp->mx, mtmp->my); teleds(mtmp->mx, mtmp->my, TRUE); return TRUE; }
/* heal monster for time spent elsewhere */ void mon_catchup_elapsed_time(struct monst *mtmp, long nmv) { int imv = 0; /* avoid zillions of casts and lint warnings */ if (nmv >= LARGEST_INT) /* paranoia */ imv = LARGEST_INT - 1; else imv = (int)nmv; /* might stop being afraid, blind or frozen */ /* set to 1 and allow final decrement in movemon() */ if (mtmp->mblinded) { if (imv >= (int) mtmp->mblinded) mtmp->mblinded = 1; else mtmp->mblinded -= imv; } if (mtmp->mfrozen) { if (imv >= (int) mtmp->mfrozen) mtmp->mfrozen = 1; else mtmp->mfrozen -= imv; } if (mtmp->mfleetim) { if (imv >= (int) mtmp->mfleetim) mtmp->mfleetim = 1; else mtmp->mfleetim -= imv; } /* might recover from temporary trouble */ if (mtmp->mtrapped && rn2(imv + 1) > 40/2) mtmp->mtrapped = 0; if (mtmp->mconf && rn2(imv + 1) > 50/2) mtmp->mconf = 0; if (mtmp->mstun && rn2(imv + 1) > 10/2) mtmp->mstun = 0; /* might finish eating or be able to use special ability again */ if (imv > mtmp->meating) mtmp->meating = 0; else mtmp->meating -= imv; if (imv > mtmp->mspec_used) mtmp->mspec_used = 0; else mtmp->mspec_used -= imv; /* reduce tameness for every 150 moves you are separated */ if (mtmp->mtame) { int wilder = (imv + 75) / 150; if (mtmp->mtame > wilder) mtmp->mtame -= wilder; /* less tame */ else if (mtmp->mtame > rn2(wilder)) mtmp->mtame = 0; /* untame */ else mtmp->mtame = mtmp->mpeaceful = 0; /* hostile! */ } /* check to see if it would have died as a pet; if so, go wild instead * of dying the next time we call dog_move() */ if (mtmp->mtame && !mtmp->isminion && (carnivorous(mtmp->data) || herbivorous(mtmp->data))) { struct edog *edog = EDOG(mtmp); if ((moves > edog->hungrytime + 500 && mtmp->mhp < 3) || (moves > edog->hungrytime + 750)) mtmp->mtame = mtmp->mpeaceful = 0; } if (!mtmp->mtame && mtmp->mleashed) { /* leashed monsters should always be with hero, consequently never losing any time to be accounted for later */ impossible("catching up for leashed monster?"); m_unleash(mtmp, FALSE); } /* recover lost hit points */ if (!regenerates(mtmp->data)) imv /= 20; if (mtmp->mhp + imv >= mtmp->mhpmax) mtmp->mhp = mtmp->mhpmax; else mtmp->mhp += imv; }