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

Function use_defensive

src/muse.c:795–1219  ·  view source on GitHub ↗

Perform a defensive action for a monster. Must be called immediately * after find_defensive(). Return values are 0: did something, 1: died, * 2: did something and can't attack again (i.e. teleported). */

Source from the content-addressed store, hash-verified

793 * 2: did something and can't attack again (i.e. teleported).
794 */
795int
796use_defensive(struct monst *mtmp)
797{
798 static const char MissingDefensiveItem[] = "use_defensive: no %s";
799 int i, fleetim;
800 struct obj *otmp = gm.m.defensive;
801 boolean vis, vismon, oseen;
802 struct trap *t;
803 stairway *stway;
804
805 if ((i = precheck(mtmp, otmp)) != 0)
806 return i;
807 vis = cansee(mtmp->mx, mtmp->my);
808 vismon = canseemon(mtmp);
809 oseen = otmp && vismon;
810
811 /* when using defensive choice to run away, we want monster to avoid
812 rushing right straight back; don't override if already scared */
813 fleetim = !mtmp->mflee ? (33 - (30 * mtmp->mhp / mtmp->mhpmax)) : 0;
814#define m_flee(m) \
815 if (fleetim && !m->iswiz) { \
816 monflee(m, fleetim, FALSE, FALSE); \
817 }
818
819 switch (gm.m.has_defense) {
820 case MUSE_UNICORN_HORN:
821 /* unlike most defensive cases, unicorn horn object is optional */
822 if (vismon) {
823 if (otmp)
824 pline_mon(mtmp, "%s uses a unicorn horn!", Monnam(mtmp));
825 else
826 pline_The("tip of %s's horn glows!", mon_nam(mtmp));
827 }
828 if (!mtmp->mcansee) {
829 mcureblindness(mtmp, vismon);
830 } else if (mtmp->mconf || mtmp->mstun) {
831 mtmp->mconf = mtmp->mstun = 0;
832 if (vismon)
833 pline_mon(mtmp, "%s seems steadier now.", Monnam(mtmp));
834 } else {
835 impossible("No need for unicorn horn?");
836 }
837 return 2;
838 case MUSE_BUGLE:
839 if (!otmp)
840 panic(MissingDefensiveItem, "bugle");
841 if (vismon) {
842 pline_mon(mtmp, "%s plays %s!", Monnam(mtmp), doname(otmp));
843 } else if (!Deaf) {
844 Soundeffect(se_bugle_playing_reveille, 100);
845 You_hear("a bugle playing reveille!");
846 }
847 awaken_soldiers(mtmp);
848 return 2;
849 case MUSE_WAN_TELEPORTATION_SELF:
850 if (!otmp)
851 panic(MissingDefensiveItem, "wand of teleportation");
852 if ((mtmp->isshk && inhishop(mtmp)) || mtmp->isgd || mtmp->ispriest)

Callers 2

dochugFunction · 0.85
m_moveFunction · 0.85

Calls 15

canseemonFunction · 0.85
pline_monFunction · 0.85
MonnamFunction · 0.85
pline_TheFunction · 0.85
mon_namFunction · 0.85
mcureblindnessFunction · 0.85
donameFunction · 0.85
You_hearFunction · 0.85
awaken_soldiersFunction · 0.85
inhishopFunction · 0.85
mzapwandFunction · 0.85
m_teleFunction · 0.85

Tested by

no test coverage detected