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

Function obj_shuffle_range

src/o_init.c:268–318  ·  view source on GitHub ↗

retrieve the range of objects that otyp shares descriptions with */

Source from the content-addressed store, hash-verified

266
267/* retrieve the range of objects that otyp shares descriptions with */
268void
269obj_shuffle_range(
270 int otyp, /* input: representative item */
271 int *lo_p, int *hi_p) /* output: range that item belongs among */
272{
273 int i, ocls = objects[otyp].oc_class;
274
275 /* default is just the object itself */
276 *lo_p = *hi_p = otyp;
277
278 switch (ocls) {
279 case ARMOR_CLASS:
280 if (otyp >= HELMET && otyp <= HELM_OF_TELEPATHY)
281 *lo_p = HELMET, *hi_p = HELM_OF_TELEPATHY;
282 else if (otyp >= LEATHER_GLOVES && otyp <= GAUNTLETS_OF_DEXTERITY)
283 *lo_p = LEATHER_GLOVES, *hi_p = GAUNTLETS_OF_DEXTERITY;
284 else if (otyp >= CLOAK_OF_PROTECTION && otyp <= CLOAK_OF_DISPLACEMENT)
285 *lo_p = CLOAK_OF_PROTECTION, *hi_p = CLOAK_OF_DISPLACEMENT;
286 else if (otyp >= SPEED_BOOTS && otyp <= LEVITATION_BOOTS)
287 *lo_p = SPEED_BOOTS, *hi_p = LEVITATION_BOOTS;
288 break;
289 case POTION_CLASS:
290 /* potion of water has the only fixed description */
291 *lo_p = svb.bases[POTION_CLASS];
292 *hi_p = POT_WATER - 1;
293 break;
294 case AMULET_CLASS:
295 case SCROLL_CLASS:
296 case SPBOOK_CLASS:
297 /* exclude non-magic types and also unique ones */
298 *lo_p = svb.bases[ocls];
299 for (i = *lo_p; objects[i].oc_class == ocls; i++)
300 if (objects[i].oc_unique || !objects[i].oc_magic)
301 break;
302 *hi_p = i - 1;
303 break;
304 case RING_CLASS:
305 case WAND_CLASS:
306 case VENOM_CLASS:
307 /* entire class */
308 *lo_p = svb.bases[ocls];
309 *hi_p = svb.bases[ocls + 1] - 1;
310 break;
311 }
312
313 /* artifact checking might ask about item which isn't part of any range
314 but fell within the classes that do have ranges specified above */
315 if (otyp < *lo_p || otyp > *hi_p)
316 *lo_p = *hi_p = otyp;
317 return;
318}
319
320/* randomize object descriptions */
321staticfn void

Callers 2

shuffle_allFunction · 0.85
restrict_nameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected