/** * Attempt to make an object * * \param c is the current dungeon level. * \param lev is the creation level of the object (not necessarily == depth). * \param good is whether the object is to be good * \param great is whether the object is to be great * \param extra_roll is whether we get an extra roll in apply_magic() * \param value is the value to be returned to the calling function * \param tval is the desired tval, or 0 if we allow any tval * * \return a pointer to the newly allocated object, or NULL on failure. */ struct object *make_object(struct chunk *c, int lev, bool good, bool great, bool extra_roll, s32b *value, int tval) { int base; struct object_kind *kind; struct object *new_obj; /* Try to make a special artifact */ if (one_in_(good ? 10 : 1000)) { new_obj = make_artifact_special(lev); if (new_obj) { if (value) *value = object_value_real(new_obj, 1, false); return new_obj; } /* If we failed to make an artifact, the player gets a good item */ good = true; } /* Base level for the object */ base = (good ? (lev + 10) : lev); /* Try to choose an object kind */ kind = get_obj_num(base, good || great, tval); if (!kind) return NULL; /* Make the object, prep it and apply magic */ new_obj = object_new(); object_prep(new_obj, kind, lev, RANDOMISE); if (one_in_(20) && tval_is_wearable(new_obj)) { apply_curse(new_obj, &lev); } apply_magic(new_obj, lev, true, good, great, extra_roll); apply_curse_knowledge(new_obj); /* Generate multiple items */ if (kind->gen_mult_prob >= randint1(100)) new_obj->number = randcalc(kind->stack_size, lev, RANDOMISE); if (new_obj->number > z_info->stack_size) new_obj->number = z_info->stack_size; /* Get the value */ if (value) *value = object_value_real(new_obj, new_obj->number, false); /* Boost of 20% per level OOD for uncursed objects */ if ((!new_obj->curses) && (kind->alloc_min > c->depth)) { if (value) *value += (kind->alloc_min - c->depth) * (*value / 5); } return new_obj; }
/** * Attempt to make an object * * \param c is the current dungeon level. * \param lev is the creation level of the object (not necessarily == depth). * \param good is whether the object is to be good * \param great is whether the object is to be great * \param extra_roll is whether we get an extra roll in apply_magic() * \param value is the value to be returned to the calling function * \param tval is the desired tval, or 0 if we allow any tval * * \return a pointer to the newly allocated object, or NULL on failure. */ struct object *make_object(struct chunk *c, int lev, bool good, bool great, bool extra_roll, s32b *value, int tval) { int base; object_kind *kind; struct object *new_obj; /* Try to make a special artifact */ if (one_in_(good ? 10 : 1000)) { new_obj = make_artifact_special(lev); if (new_obj) { if (value) *value = object_value_real(new_obj, 1, FALSE, TRUE); return new_obj; } /* If we failed to make an artifact, the player gets a good item */ good = TRUE; } /* Base level for the object */ base = (good ? (lev + 10) : lev); /* Try to choose an object kind */ kind = get_obj_num(base, good || great, tval); if (!kind) return NULL; /* Make the object, prep it and apply magic */ new_obj = object_new(); object_prep(new_obj, kind, lev, RANDOMISE); apply_magic(new_obj, lev, TRUE, good, great, extra_roll); /* Generate multiple items */ if (kind->gen_mult_prob >= randint1(100)) new_obj->number = randcalc(kind->stack_size, lev, RANDOMISE); if (new_obj->number > z_info->stack_size) new_obj->number = z_info->stack_size; /* Return value, increased for uncursed out-of-depth objects */ if (value) *value = object_value_real(new_obj, new_obj->number, FALSE, TRUE); /* This seems to imply objects get less value from being > 1 but < 5 * levels out of depth - should it be *value +=... - NRM */ if (!cursed_p(new_obj->flags) && (kind->alloc_min > c->depth)) { if (value) *value = (kind->alloc_min - c->depth) * (*value / 5); } return new_obj; }
/* * Attempt to make an object (normal or good/great) * * This routine plays nasty games to generate the "special artifacts". * * We assume that the given object has been "wiped". */ bool make_object(object_type *j_ptr, int lev, bool good, bool great) { int k_idx, base; object_kind *k_ptr; /* Try to make a special artifact */ if (one_in_(good ? 10 : 1000)) { if (make_artifact_special(j_ptr, lev)) return TRUE; /* If we failed to make an artifact, the player gets a great item */ good = great = TRUE; } /* Base level for the object */ base = (good ? (lev + 10) : lev); /* Get the object */ k_idx = get_obj_num(base, good || great); if (!k_idx) return FALSE; /* Prepare the object */ object_prep(j_ptr, &k_info[k_idx], lev, RANDOMISE); /* Apply magic (allow artifacts) */ apply_magic(j_ptr, lev, TRUE, good, great); /* Generate multiple items */ k_ptr = &k_info[j_ptr->k_idx]; if (k_ptr->gen_mult_prob >= 100 || k_ptr->gen_mult_prob >= randint1(100)) { j_ptr->number = randcalc(k_ptr->stack_size, lev, RANDOMISE); } /* Notice "okay" out-of-depth objects */ if (!cursed_p(j_ptr) && (k_info[j_ptr->k_idx].level > p_ptr->depth)) { /* Rating increase */ rating += (k_info[j_ptr->k_idx].alloc_min - p_ptr->depth); /* Cheat -- peek at items */ if (OPT(cheat_peek)) object_mention(j_ptr); } return TRUE; }
/** * Attempt to make an object * * \param c is the current dungeon level. * \param j_ptr is the object struct to be populated. * \param lev is the creation level of the object (not necessarily == depth). * \param good is whether the object is to be good * \param great is whether the object is to be great * \param value is the value to be returned to the calling function * \param tval is the desired tval, or 0 if we allow any tval * * Returns the whether or not creation worked. */ bool make_object(struct cave *c, object_type *j_ptr, int lev, bool good, bool great, bool extra_roll, s32b *value, int tval) { int base; object_kind *kind; /* Try to make a special artifact */ if (one_in_(good ? 10 : 1000)) { if (make_artifact_special(j_ptr, lev)) { if (value) *value = object_value_real(j_ptr, 1, FALSE, TRUE); return TRUE; } /* If we failed to make an artifact, the player gets a good item */ good = TRUE; } /* Base level for the object */ base = (good ? (lev + 10) : lev); /* Get the object, prep it and apply magic */ kind = get_obj_num(base, good || great, tval); if (!kind) return FALSE; object_prep(j_ptr, kind, lev, RANDOMISE); apply_magic(j_ptr, lev, TRUE, good, great, extra_roll); /* Generate multiple items */ if (kind->gen_mult_prob >= randint1(100)) j_ptr->number = randcalc(kind->stack_size, lev, RANDOMISE); if (j_ptr->number >= MAX_STACK_SIZE) j_ptr->number = MAX_STACK_SIZE - 1; /* Return value, increased for uncursed out-of-depth objects */ if (value) *value = object_value_real(j_ptr, j_ptr->number, FALSE, TRUE); if (!cursed_p(j_ptr->flags) && (kind->alloc_min > c->depth)) { if (value) *value = (kind->alloc_min - c->depth) * (*value / 5); } return TRUE; }