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

Function init_oclass_probs

src/o_init.c:239–265  ·  view source on GitHub ↗

Compute the total probability of each object class. * Assumes svb.bases[] has already been set. */

Source from the content-addressed store, hash-verified

237/* Compute the total probability of each object class.
238 * Assumes svb.bases[] has already been set. */
239void
240init_oclass_probs(void)
241{
242 int i;
243 short sum;
244 int oclass;
245 for (oclass = 0; oclass < MAXOCLASSES; ++oclass) {
246 sum = 0;
247 /* note: for ILLOBJ_CLASS, bases[oclass+1]-1 isn't the last item
248 in the class; but all the generic items have probability 0 so
249 adding them to 'sum' has no impact */
250 for (i = svb.bases[oclass]; i < svb.bases[oclass + 1]; ++i) {
251 sum += objects[i].oc_prob;
252 }
253 if (sum <= 0 && oclass != ILLOBJ_CLASS
254 && svb.bases[oclass] != svb.bases[oclass + 1]) {
255 impossible("%s (%d) probability total for oclass %d",
256 !sum ? "zero" : "negative", sum, oclass);
257 /* gracefully fail by setting all members of this class to 1 */
258 for (i = svb.bases[oclass]; i < svb.bases[oclass + 1]; ++i) {
259 objects[i].oc_prob = 1;
260 sum++;
261 }
262 }
263 go.oclass_prob_totals[oclass] = sum;
264 }
265}
266
267/* retrieve the range of objects that otyp shares descriptions with */
268void

Callers 2

init_objectsFunction · 0.85
dorecoverFunction · 0.85

Calls 1

impossibleFunction · 0.70

Tested by

no test coverage detected