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

Function rnl

src/rnd.c:111–151  ·  view source on GitHub ↗

0 <= rnl(x) < x; sometimes subtracting Luck; good luck approaches 0, bad luck approaches (x-1) */

Source from the content-addressed store, hash-verified

109/* 0 <= rnl(x) < x; sometimes subtracting Luck;
110 good luck approaches 0, bad luck approaches (x-1) */
111int
112rnl(int x)
113{
114 int i, adjustment;
115
116#if (NH_DEVEL_STATUS != NH_STATUS_RELEASED)
117 if (x <= 0) {
118 impossible("rnl(%d) attempted", x);
119 return 0;
120 }
121#endif
122
123 adjustment = Luck;
124 if (x <= 15) {
125 /* for small ranges, use Luck/3 (rounded away from 0);
126 also guard against architecture-specific differences
127 of integer division involving negative values */
128 adjustment = (abs(adjustment) + 1) / 3 * sgn(adjustment);
129 /*
130 * 11..13 -> 4
131 * 8..10 -> 3
132 * 5.. 7 -> 2
133 * 2.. 4 -> 1
134 * -1,0,1 -> 0 (no adjustment)
135 * -4..-2 -> -1
136 * -7..-5 -> -2
137 * -10..-8 -> -3
138 * -13..-11-> -4
139 */
140 }
141
142 i = RND(x);
143 if (adjustment && rn2(37 + abs(adjustment))) {
144 i -= adjustment;
145 if (i < 0)
146 i = 0;
147 else if (i >= x)
148 i = x - 1;
149 }
150 return i;
151}
152
153/* 1 <= rnd(x) <= x */
154int

Callers 15

potionhitFunction · 0.85
dosearch0Function · 0.85
joustFunction · 0.85
level_teleFunction · 0.85
digFunction · 0.85
pleasedFunction · 0.85
prayer_doneFunction · 0.85
should_mulch_missileFunction · 0.85
doopen_indirFunction · 0.85
do_pitFunction · 0.85

Calls 4

sgnFunction · 0.85
RNDFunction · 0.85
rn2Function · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected