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

Function bounded_increase

src/eat.c:2220–2255  ·  view source on GitHub ↗

increment a combat intrinsic with limits on its growth */

Source from the content-addressed store, hash-verified

2218
2219/* increment a combat intrinsic with limits on its growth */
2220staticfn int
2221bounded_increase(int old, int inc, int typ)
2222{
2223 int absold, absinc, sgnold, sgninc;
2224
2225 /* don't include any amount coming from worn rings (caller handles
2226 'protection' differently) */
2227 if (uright && uright->otyp == typ && typ != RIN_PROTECTION)
2228 old -= uright->spe;
2229 if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION)
2230 old -= uleft->spe;
2231 absold = abs(old), absinc = abs(inc);
2232 sgnold = sgn(old), sgninc = sgn(inc);
2233
2234 if (absinc == 0 || sgnold != sgninc || absold + absinc < 10) {
2235 ; /* use inc as-is */
2236 } else if (absold + absinc < 20) {
2237 absinc = rnd(absinc); /* 1..n */
2238 if (absold + absinc < 10)
2239 absinc = 10 - absold;
2240 inc = sgninc * absinc;
2241 } else if (absold + absinc < 40) {
2242 absinc = rn2(absinc) ? 1 : 0;
2243 if (absold + absinc < 20)
2244 absinc = rnd(20 - absold);
2245 inc = sgninc * absinc;
2246 } else {
2247 inc = 0; /* no further increase allowed via this method */
2248 }
2249 /* put amount from worn rings back */
2250 if (uright && uright->otyp == typ && typ != RIN_PROTECTION)
2251 old += uright->spe;
2252 if (uleft && uleft->otyp == typ && typ != RIN_PROTECTION)
2253 old += uleft->spe;
2254 return old + inc;
2255}
2256
2257staticfn void
2258accessory_has_effect(struct obj *otmp)

Callers 1

eataccessoryFunction · 0.85

Calls 3

sgnFunction · 0.85
rndFunction · 0.85
rn2Function · 0.85

Tested by

no test coverage detected