mkobj(): select a type of item from a class, use mksobj() to create it; result is always non-Null */
| 267 | /* mkobj(): select a type of item from a class, use mksobj() to create it; |
| 268 | result is always non-Null */ |
| 269 | struct obj * |
| 270 | mkobj(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 | |
| 303 | staticfn void |
| 304 | mkbox_cnts(struct obj *box) |
no test coverage detected