MCPcopy Create free account
hub / github.com/NetHack/NetHack / use_leash_core

Function use_leash_core

src/apply.c:820–876  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820staticfn void
821use_leash_core(struct obj *obj, struct monst *mtmp, coord *cc, int spotmon)
822{
823 if (!spotmon && !glyph_is_invisible(levl[cc->x][cc->y].glyph)) {
824 /* for the unleash case, we don't verify whether this unseen
825 monster is the creature attached to the current leash */
826 You("fail to %sleash something.", obj->leashmon ? "un" : "");
827 /* trying again will work provided the monster is tame
828 (and also that it doesn't change location by retry time) */
829 map_invisible(cc->x, cc->y);
830 } else if (!mtmp->mtame) {
831 pline("%s %s leashed!", Monnam(mtmp),
832 (!obj->leashmon) ? "cannot be" : "is not");
833 } else if (!obj->leashmon) {
834 /* applying a leash which isn't currently in use */
835 if (mtmp->mleashed) {
836 pline("This %s is already leashed.",
837 spotmon ? l_monnam(mtmp) : "creature");
838 } else if (unsolid(mtmp->data)) {
839 pline("The leash would just fall off.");
840 } else if (nolimbs(mtmp->data) && !has_head(mtmp->data)) {
841 pline("%s has no extremities the leash would fit.",
842 Monnam(mtmp));
843 } else if (!leashable(mtmp)) {
844 char lmonbuf[BUFSZ];
845 char *lmonnam = l_monnam(mtmp);
846
847 if (cc->x != mtmp->mx || cc->y != mtmp->my) {
848 Sprintf(lmonbuf, "%s tail", s_suffix(lmonnam));
849 lmonnam = lmonbuf;
850 }
851 pline("The leash won't fit onto %s%s.", spotmon ? "your " : "",
852 lmonnam);
853 } else {
854 You("slip the leash around %s%s.", spotmon ? "your " : "",
855 l_monnam(mtmp));
856 mtmp->mleashed = 1;
857 obj->leashmon = (int) mtmp->m_id;
858 mtmp->msleeping = 0;
859 update_inventory();
860 }
861 } else {
862 /* applying a leash which is currently in use */
863 if (obj->leashmon != (int) mtmp->m_id) {
864 pline("This leash is not attached to that creature.");
865 } else if (obj->cursed) {
866 pline_The("leash would not come off!");
867 set_bknown(obj, 1);
868 } else {
869 mtmp->mleashed = 0;
870 obj->leashmon = 0;
871 update_inventory();
872 You("remove the leash from %s%s.",
873 spotmon ? "your " : "", l_monnam(mtmp));
874 }
875 }
876}
877

Callers 1

use_leashFunction · 0.85

Calls 10

YouFunction · 0.85
map_invisibleFunction · 0.85
MonnamFunction · 0.85
l_monnamFunction · 0.85
leashableFunction · 0.85
s_suffixFunction · 0.85
update_inventoryFunction · 0.85
pline_TheFunction · 0.85
set_bknownFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected