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

Function shkveg

src/shknam.c:407–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405}
406
407staticfn int
408shkveg(void)
409{
410 int i, j, maxprob, prob;
411 char oclass = FOOD_CLASS;
412 int ok[NUM_OBJECTS];
413
414 (void) memset((genericptr_t) ok, 0, sizeof ok); /* lint suppression */
415 j = maxprob = 0;
416 for (i = svb.bases[(int) oclass]; i < NUM_OBJECTS; ++i) {
417 if (objects[i].oc_class != oclass)
418 break;
419
420 if (veggy_item((struct obj *) 0, i)) {
421 ok[j++] = i;
422 maxprob += objects[i].oc_prob;
423 }
424 }
425 if (maxprob < 1)
426 panic("shkveg no veggy objects");
427 prob = rnd(maxprob);
428
429 j = 0;
430 i = ok[0];
431 while ((prob -= objects[i].oc_prob) > 0) {
432 j++;
433 i = ok[j];
434 }
435
436 if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i]))
437 panic("shkveg probtype error, oclass=%d i=%d", (int) oclass, i);
438 return i;
439}
440
441/* make a random item for health food store */
442staticfn void

Callers 1

mkveggy_atFunction · 0.85

Calls 3

veggy_itemFunction · 0.85
rndFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected