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

Function mkobj

src/mkobj.c:269–301  ·  view source on GitHub ↗

mkobj(): select a type of item from a class, use mksobj() to create it; result is always non-Null */

Source from the content-addressed store, hash-verified

267/* mkobj(): select a type of item from a class, use mksobj() to create it;
268 result is always non-Null */
269struct obj *
270mkobj(int oclass, boolean artif)
271{
272 int tprob, i, prob;
273
274 if (oclass == RANDOM_CLASS) {
275 const struct icp *iprobs = Is_rogue_level(&u.uz)
276 ? (const struct icp *) rogueprobs
277 : Inhell ? (const struct icp *) hellprobs
278 : (const struct icp *) mkobjprobs;
279
280 for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++)
281 continue;
282 oclass = iprobs->iclass;
283 }
284
285 if (oclass == SPBOOK_no_NOVEL) {
286 i = rnd_class(svb.bases[SPBOOK_CLASS], SPE_BLANK_PAPER);
287 oclass = SPBOOK_CLASS; /* for sanity check below */
288 } else {
289 prob = rnd(go.oclass_prob_totals[oclass]);
290 i = svb.bases[oclass];
291 while ((prob -= objects[i].oc_prob) > 0)
292 ++i;
293 }
294
295 if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) {
296 impossible("probtype error, oclass=%d i=%d", (int) oclass, i);
297 i = svb.bases[oclass];
298 }
299
300 return mksobj(i, TRUE, artif);
301}
302
303staticfn void
304mkbox_cnts(struct obj *box)

Callers 15

fill_zooFunction · 0.85
mk_mplayerFunction · 0.85
potion_dipFunction · 0.85
l_obj_new_readobjnamFunction · 0.85
readobjnamFunction · 0.85
give_spellFunction · 0.85
xkilledFunction · 0.85
mkobj_atFunction · 0.85
mkbox_cntsFunction · 0.85
mksobj_initFunction · 0.85
hornoplentyFunction · 0.85
set_mimic_symFunction · 0.85

Calls 4

rndFunction · 0.85
rnd_classFunction · 0.85
mksobjFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected