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

Function corpse_intrinsic

src/eat.c:1330–1373  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1328}
1329
1330RESTORE_WARNING_FORMAT_NONLITERAL
1331
1332/* Choose (one of) the intrinsics granted by a corpse, and return it.
1333 * If this corpse gives no intrinsics, return 0.
1334 * For the special not-real-prop cases of strength gain from giants
1335 * return fake prop value of -1.
1336 * Non-deterministic; should only be called once per corpse.
1337 */
1338int
1339corpse_intrinsic(struct permonst *ptr)
1340{
1341 /* Check the monster for all of the intrinsics. If this
1342 * monster can give more than one, pick one to try to give
1343 * from among all it can give.
1344 */
1345 boolean conveys_STR = is_giant(ptr);
1346 int i;
1347 int count = 0; /* number of possible intrinsics */
1348 int prop = 0; /* which one we will try to give */
1349
1350 if (conveys_STR) {
1351 count = 1;
1352 prop = -1; /* use -1 as fake prop index for STR */
1353 debugpline1("\"Intrinsic\" strength, %d", prop);
1354 }
1355 for (i = 1; i <= LAST_PROP; i++) {
1356 if (!intrinsic_possible(i, ptr))
1357 continue;
1358 ++count;
1359 /* a 1 in count chance of replacing the old choice
1360 with this one, and a count-1 in count chance
1361 of keeping the old choice (note that 1 in 1 and
1362 0 in 1 are what we want for the first candidate) */
1363 if (!rn2(count)) {
1364 debugpline2("Intrinsic %d replacing %d", i, prop);
1365 prop = i;
1366 }
1367 }
1368 /* if strength is the only candidate, give it 50% chance */
1369 if (conveys_STR && count == 1 && !rn2(2))
1370 prop = 0;
1371
1372 return prop;
1373}
1374
1375void
1376violated_vegetarian(void)

Callers 2

cpostfxFunction · 0.85
mon_givitFunction · 0.85

Calls 2

intrinsic_possibleFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected