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

Function mstrength

src/mondata.c:427–497  ·  view source on GitHub ↗

This routine is designed to return an integer value which represents an approximation of monster strength. It uses a similar method of determination as "experience()" to arrive at the strength. */

Source from the content-addressed store, hash-verified

425 an approximation of monster strength. It uses a similar method of
426 determination as "experience()" to arrive at the strength. */
427int
428mstrength(struct permonst *ptr)
429{
430 int i, tmp2, n, tmp = ptr->mlevel;
431
432 if (tmp > 49) /* special fixed hp monster */
433 tmp = 2 * (tmp - 6) / 4;
434
435 /* for creation in groups */
436 n = (!!(ptr->geno & G_SGROUP));
437 n += (!!(ptr->geno & G_LGROUP)) << 1;
438
439 /* for ranged attacks */
440 if (mstrength_ranged_attk(ptr))
441 n++;
442
443 /* for higher ac values */
444 n += (ptr->ac < 4);
445 n += (ptr->ac < 0);
446
447 /* for very fast monsters */
448 n += (ptr->mmove >= 18);
449
450 /* for each attack and "special" attack */
451 for (i = 0; i < NATTK; i++) {
452 tmp2 = ptr->mattk[i].aatyp;
453 n += (tmp2 > 0);
454 n += (tmp2 == AT_MAGC);
455 n += (tmp2 == AT_WEAP && (ptr->mflags2 & M2_STRONG));
456 if (tmp2 == AT_EXPL) {
457 int tmp3 = ptr->mattk[i].adtyp;
458 /* {freezing,flaming,shocking} spheres are fairly weak but
459 can destroy equipment; {yellow,black} lights can't */
460 n += ((tmp3 == AD_COLD || tmp3 == AD_FIRE) ? 3
461 : (tmp3 == AD_ELEC) ? 5
462 : 0);
463 }
464 }
465
466 /* for each "special" damage type */
467 for (i = 0; i < NATTK; i++) {
468 tmp2 = ptr->mattk[i].adtyp;
469 if ((tmp2 == AD_DRLI) || (tmp2 == AD_STON) || (tmp2 == AD_DRST)
470 || (tmp2 == AD_DRDX) || (tmp2 == AD_DRCO) || (tmp2 == AD_WERE))
471 n += 2;
472 else if (strcmp(ptr->pmnames[NEUTRAL], "grid bug"))
473 n += (tmp2 != AD_PHYS);
474 n += ((int) (ptr->mattk[i].damd * ptr->mattk[i].damn) > 23);
475 }
476
477 /* Leprechauns are a special case. They have many hit dice so they can
478 hit and are hard to kill, but they don't really do much damage. */
479 if (!strcmp(ptr->pmnames[NEUTRAL], "leprechaun"))
480 n -= 2;
481
482 /* despite group and poison increments, soldier ants and killer bees are
483 underestimated by the formula, so have an artificial +1 difficulty */
484 if (!strcmp(ptr->pmnames[NEUTRAL], "killer bee") ||

Callers 1

wiz_mon_diffFunction · 0.85

Calls 1

mstrength_ranged_attkFunction · 0.85

Tested by

no test coverage detected