MCPcopy Index your code
hub / github.com/NetHack/NetHack / use_leash

Function use_leash

src/apply.c:768–818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

766}
767
768staticfn int
769use_leash(struct obj *obj)
770{
771 coord cc;
772 struct monst *mtmp;
773
774 if (u.uswallow) {
775 /* if the leash isn't in use, assume we're trying to leash
776 the engulfer; if it is use, distinguish between removing
777 it from the engulfer versus from some other creature
778 (note: the two in-use cases can't actually occur; all
779 leashes are released when the hero gets engulfed) */
780 You_cant((!obj->leashmon
781 ? "leash %s from inside."
782 : (obj->leashmon == (int) u.ustuck->m_id)
783 ? "unleash %s from inside."
784 : "unleash anything from inside %s."),
785 noit_mon_nam(u.ustuck));
786 return ECMD_OK;
787 }
788 if (!obj->leashmon && number_leashed() >= MAXLEASHED) {
789 You("cannot leash any more pets.");
790 return ECMD_OK;
791 }
792
793 if (!get_adjacent_loc((char *) 0, (char *) 0, u.ux, u.uy, &cc))
794 return ECMD_OK;
795
796 if (u_at(cc.x, cc.y)) {
797 if (u.usteed && u.dz > 0) {
798 mtmp = u.usteed;
799 use_leash_core(obj, mtmp, &cc, 1);
800 return ECMD_TIME;
801 }
802 pline("Leash yourself? Very funny...");
803 return ECMD_OK;
804 }
805
806 /*
807 * From here on out, return value is 1 == a move is used.
808 */
809
810 if (!(mtmp = m_at(cc.x, cc.y))) {
811 There("is no creature there.");
812 (void) unmap_invisible(cc.x, cc.y);
813 return ECMD_TIME;
814 }
815
816 use_leash_core(obj, mtmp, &cc, canspotmon(mtmp));
817 return ECMD_TIME;
818}
819
820staticfn void
821use_leash_core(struct obj *obj, struct monst *mtmp, coord *cc, int spotmon)

Callers 1

doapplyFunction · 0.85

Calls 9

You_cantFunction · 0.85
noit_mon_namFunction · 0.85
number_leashedFunction · 0.85
YouFunction · 0.85
get_adjacent_locFunction · 0.85
use_leash_coreFunction · 0.85
ThereFunction · 0.85
unmap_invisibleFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected