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

Function peace_minded

src/makemon.c:2267–2308  ·  view source on GitHub ↗

* Alignment vs. yours determines monster's attitude to you. * (Some "animal" types are co-aligned, but also hungry.) */

Source from the content-addressed store, hash-verified

2265 * (Some "animal" types are co-aligned, but also hungry.)
2266 */
2267boolean
2268peace_minded(struct permonst *ptr)
2269{
2270 aligntyp mal = ptr->maligntyp, ual = u.ualign.type;
2271
2272 if (always_peaceful(ptr))
2273 return TRUE;
2274 if (always_hostile(ptr))
2275 return FALSE;
2276 if (ptr->msound == MS_LEADER || ptr->msound == MS_GUARDIAN)
2277 return TRUE;
2278 if (ptr->msound == MS_NEMESIS)
2279 return FALSE;
2280 if (ptr == &mons[PM_ERINYS])
2281 return !u.ualign.abuse;
2282
2283 if (race_peaceful(ptr))
2284 return TRUE;
2285 if (race_hostile(ptr))
2286 return FALSE;
2287
2288 /* the monster is hostile if its alignment is different from the
2289 * player's */
2290 if (sgn(mal) != sgn(ual))
2291 return FALSE;
2292
2293 /* Negative monster hostile to player with Amulet. */
2294 if (mal < A_NEUTRAL && u.uhave.amulet)
2295 return FALSE;
2296
2297 /* minions are hostile to players that have strayed at all */
2298 if (is_minion(ptr))
2299 return (boolean) (u.ualign.record >= 0);
2300
2301 /* Last case: a chance of a co-aligned monster being
2302 * hostile. This chance is greater if the player has strayed
2303 * (u.ualign.record negative) or the monster is not strongly aligned.
2304 */
2305 return (boolean) (!!rn2(16 + (u.ualign.record < -15 ? -15
2306 : u.ualign.record))
2307 && !!rn2(2 + abs(mal)));
2308}
2309
2310/* Set malign to have the proper effect on player alignment if monster is
2311 * killed. Negative numbers mean it's bad to kill this monster; positive

Callers 3

getlevFunction · 0.85
m_initgrpFunction · 0.85
makemonFunction · 0.85

Calls 2

sgnFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected