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

Function rnd_defensive_item

src/muse.c:1221–1270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219}
1220
1221int
1222rnd_defensive_item(struct monst *mtmp)
1223{
1224 struct permonst *pm = mtmp->data;
1225 int difficulty = mons[(monsndx(pm))].difficulty;
1226 int trycnt = 0;
1227
1228 if (is_animal(pm) || attacktype(pm, AT_EXPL) || mindless(mtmp->data)
1229 || pm->mlet == S_GHOST || pm->mlet == S_KOP)
1230 return 0;
1231 try_again:
1232 switch (rn2(8 + (difficulty > 3) + (difficulty > 6) + (difficulty > 8))) {
1233 case 6:
1234 case 9:
1235 if (noteleport_level(mtmp) && ++trycnt < 2)
1236 goto try_again;
1237 if (!rn2(3))
1238 return WAN_TELEPORTATION;
1239 FALLTHROUGH;
1240 /*FALLTHRU*/
1241 case 0:
1242 case 1:
1243 return SCR_TELEPORTATION;
1244 case 8:
1245 case 10:
1246 if (!rn2(3))
1247 return WAN_CREATE_MONSTER;
1248 FALLTHROUGH;
1249 /*FALLTHRU*/
1250 case 2:
1251 return SCR_CREATE_MONSTER;
1252 case 3:
1253 return POT_HEALING;
1254 case 4:
1255 return POT_EXTRA_HEALING;
1256 case 5:
1257 return (mtmp->data != &mons[PM_PESTILENCE]) ? POT_FULL_HEALING
1258 : POT_SICKNESS;
1259 case 7: /* wand of digging */
1260 /* usually avoid digging in Sokoban */
1261 if (Sokoban && rn2(4))
1262 goto try_again;
1263 /* some creatures shouldn't dig down to another level when hurt */
1264 if (is_floater(pm) || mtmp->isshk || mtmp->isgd || mtmp->ispriest)
1265 return 0;
1266 return WAN_DIGGING;
1267 }
1268 /*NOTREACHED*/
1269 return 0;
1270}
1271
1272#define MUSE_WAN_DEATH 1
1273#define MUSE_WAN_SLEEP 2

Callers 2

mk_mplayerFunction · 0.85
m_initinvFunction · 0.85

Calls 3

attacktypeFunction · 0.85
rn2Function · 0.85
noteleport_levelFunction · 0.85

Tested by

no test coverage detected