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

Function can_pray

src/pray.c:2123–2173  ·  view source on GitHub ↗

determine prayer results in advance; also used for enlightenment */

Source from the content-addressed store, hash-verified

2121
2122/* determine prayer results in advance; also used for enlightenment */
2123boolean
2124can_pray(boolean praying) /* false means no messages should be given */
2125{
2126 int alignment;
2127
2128 gp.p_aligntyp = on_altar() ? a_align(u.ux, u.uy) : u.ualign.type;
2129 gp.p_trouble = in_trouble();
2130
2131 if (is_demon(gy.youmonst.data) /* ok if chaotic or none (Moloch) */
2132 && (gp.p_aligntyp == A_LAWFUL || gp.p_aligntyp != A_NEUTRAL)) {
2133 if (praying)
2134 pline_The("very idea of praying to a %s god is repugnant to you.",
2135 gp.p_aligntyp ? "lawful" : "neutral");
2136 return FALSE;
2137 }
2138
2139 if (praying)
2140 You("begin praying to %s.", align_gname(gp.p_aligntyp));
2141
2142 if (u.ualign.type && u.ualign.type == -gp.p_aligntyp)
2143 alignment = -u.ualign.record; /* Opposite alignment altar */
2144 else if (u.ualign.type != gp.p_aligntyp)
2145 alignment = u.ualign.record / 2; /* Different alignment altar */
2146 else
2147 alignment = u.ualign.record;
2148
2149 if (gp.p_aligntyp == A_NONE) /* praying to Moloch */
2150 gp.p_type = -2;
2151 else if ((gp.p_trouble > 0) ? (u.ublesscnt > 200) /* big trouble */
2152 : (gp.p_trouble < 0) ? (u.ublesscnt > 100) /* minor difficulty */
2153 : (u.ublesscnt > 0)) /* not in trouble */
2154 gp.p_type = 0; /* too soon... */
2155 else if ((int) Luck < 0 || u.ugangr || alignment < 0)
2156 gp.p_type = 1; /* too naughty... */
2157 else /* alignment >= 0 */ {
2158 if (on_altar() && u.ualign.type != gp.p_aligntyp)
2159 gp.p_type = 2;
2160 else
2161 gp.p_type = 3;
2162 }
2163
2164 if (is_undead(gy.youmonst.data) && !Inhell
2165 && (gp.p_aligntyp == A_LAWFUL
2166 || (gp.p_aligntyp == A_NEUTRAL && !rn2(10))))
2167 gp.p_type = -1;
2168 /* Note: when !praying, the random factor for neutrals makes the
2169 return value a non-deterministic approximation for enlightenment.
2170 This case should be uncommon enough to live with... */
2171
2172 return !praying ? (boolean) (gp.p_type == 3 && !Inhell) : TRUE;
2173}
2174
2175/* return TRUE if praying revived a pet corpse */
2176staticfn boolean

Callers 2

doprayFunction · 0.85
attributes_enlightenmentFunction · 0.85

Calls 5

in_troubleFunction · 0.85
pline_TheFunction · 0.85
YouFunction · 0.85
align_gnameFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected