/* * Apply magic to armour */ static void a_m_aux_2(object_type *o_ptr, int level, int power) { int toac1 = randint1(5) + m_bonus(5, level); int toac2 = m_bonus(10, level); if (power == -2) o_ptr->to_a -= toac1 + toac2; else if (power == -1) o_ptr->to_a -= toac1; else if (power == 1) o_ptr->to_a += toac1; else if (power == 2) o_ptr->to_a += toac1 + toac2; /* Analyze type */ switch (o_ptr->tval) { case TV_DRAG_ARMOR: { /* Rating boost */ rating += object_power(o_ptr, FALSE, NULL, TRUE) / 15; /* Mention the item */ if (OPT(cheat_peek)) object_mention(o_ptr); break; } } }
/** * Copy artifact data to a normal object, and set various slightly hacky * globals. */ static void copy_artifact_data(object_type *o_ptr, const artifact_type *a_ptr) { /* Extract the other fields */ o_ptr->pval = a_ptr->pval; o_ptr->ac = a_ptr->ac; o_ptr->dd = a_ptr->dd; o_ptr->ds = a_ptr->ds; o_ptr->to_a = a_ptr->to_a; o_ptr->to_h = a_ptr->to_h; o_ptr->to_d = a_ptr->to_d; o_ptr->weight = a_ptr->weight; /* Hack -- extract the "cursed" flags */ if (cursed_p(a_ptr)) { bitflag curse_flags[OF_SIZE]; of_copy(curse_flags, a_ptr->flags); flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END); of_union(o_ptr->flags, curse_flags); } /* Mega-Hack -- increase the level rating * - a sizeable increase for any artifact (c.f. up to 30 for ego items) * - a bigger increase for more powerful artifacts */ rating += 30; rating += object_power(o_ptr, FALSE, NULL, TRUE) / 25; /* Set the good item flag */ good_item_flag = TRUE; /* Cheat -- peek at the item */ if (OPT(cheat_peek)) object_mention(o_ptr); }
/** * Copy artifact data to a normal object, and set various slightly hacky * globals. */ static void copy_artifact_data(object_type *o_ptr, const artifact_type *a_ptr) { /* Extract the other fields */ o_ptr->pval = a_ptr->pval; o_ptr->ac = a_ptr->ac; o_ptr->dd = a_ptr->dd; o_ptr->ds = a_ptr->ds; o_ptr->to_a = a_ptr->to_a; o_ptr->to_h = a_ptr->to_h; o_ptr->to_d = a_ptr->to_d; o_ptr->weight = a_ptr->weight; /* Hack -- extract the "cursed" flags */ if (cursed_p(a_ptr)) { bitflag curse_flags[OF_SIZE]; of_copy(curse_flags, a_ptr->flags); flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END); of_union(o_ptr->flags, curse_flags); } /* Mega-Hack -- increase the rating */ rating += 10; /* Mega-Hack -- increase the rating again */ if (a_ptr->cost > 50000L) rating += 10; /* Set the good item flag */ good_item_flag = TRUE; /* Cheat -- peek at the item */ if (OPT(cheat_peek)) object_mention(o_ptr); }
/* * 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; }
/** * Apply magic to an item known to be "armor" * * Hack -- note special processing for crown/helm * Hack -- note special processing for robe of permanence */ static void a_m_aux_2(object_type * o_ptr, int level, int power) { int toac1, toac2; /* Boots and handgear aren't as important to total AC. */ if ((o_ptr->tval == TV_BOOTS) || (o_ptr->tval == TV_GLOVES)) { toac1 = randint1(3) + m_bonus(4, level); toac2 = m_bonus(8, level); } else { toac1 = randint1(5) + m_bonus(5, level); toac2 = m_bonus(10, level); } /* Good */ if (power > 0) { /* Enchant */ o_ptr->to_a += toac1; /* Very good */ if (power > 1) { /* Enchant again */ o_ptr->to_a += toac2; } } /* Bad */ else if (power < 0) { /* Penalize */ o_ptr->to_a -= toac1; /* Very bad */ if (power < -1) { /* Penalize again */ o_ptr->to_a -= toac2; } } /* Analyze type */ switch (o_ptr->tval) { case TV_DRAG_ARMOR: { /* Mention the item */ if (OPT(cheat_peek)) object_mention(o_ptr); break; } case TV_HARD_ARMOR: case TV_SOFT_ARMOR: case TV_SHIELD: case TV_GLOVES: case TV_BOOTS: case TV_CROWN: case TV_HELM: case TV_CLOAK: { break; } } }
/** * Complete object creation by applying magic to it. * * Magic includes rolling for random bonuses, applying flags to ego-items, * charging charged items, fuelling lights, and trapping chests. * * The `good` argument forces the item to be at least `good`, and the `great` * argument does likewise. Setting `allow_artifacts` to TRUE allows artifacts * to be created here. * * If `good` or `great` are not set, then the `lev` argument controls the * quality of item. See the function itself for the specifics of the * calculations involved. */ void apply_magic(object_type *o_ptr, int lev, bool allow_artifacts, bool good, bool great) { int power = 0; /*u32b xtra = 0;*/ /*bool new = FALSE;*/ /* Chance of being `good` and `great` */ int good_chance = (lev+2) * 3; int great_chance = MIN(lev/4 + lev, 50); /* Limit depth */ if (lev > MAX_DEPTH - 1) lev = MAX_DEPTH - 1; /* Roll for "good" */ if (good || (randint0(100) < good_chance)) { /* Assume "good" */ power = 1; /* Roll for "great" */ if (great || (randint0(100) < great_chance)) power = 2; } /* Roll for "cursed" */ else if (randint0(100) < good_chance) { /* Assume "cursed" */ power = -1; /* Roll for "broken" */ if (randint0(100) < great_chance) power = -2; } /* Roll for artifact creation */ if (allow_artifacts) { int i; int rolls = 0; /* Get one roll if excellent */ if (power >= 2) rolls = 1; /* Get four rolls if forced great */ if (great) rolls = 4; /* Roll for artifacts if allowed */ for (i = 0; i < rolls; i++) { if (make_artifact(o_ptr)) return; } } /* Apply magic */ switch (o_ptr->tval) { case TV_DIGGING: case TV_HAFTED: case TV_POLEARM: case TV_SWORD: case TV_BOW: case TV_SHOT: case TV_ARROW: case TV_BOLT: { if (power == 2 || power == -2) { int ego_power; ego_power = make_ego_item(o_ptr, lev, (bool)(power > 0)); if (ego_power) power = ego_power; } if (power) a_m_aux_1(o_ptr, lev, power); break; } case TV_DRAG_ARMOR: case TV_HARD_ARMOR: case TV_SOFT_ARMOR: case TV_SHIELD: case TV_HELM: case TV_CROWN: case TV_CLOAK: case TV_GLOVES: case TV_BOOTS: { if (power == 2 || power == -2) { int ego_power; ego_power = make_ego_item(o_ptr, lev, (bool)(power > 0)); if (ego_power) power = ego_power; } if (power) a_m_aux_2(o_ptr, lev, power); break; } case TV_RING: case TV_AMULET: { if (!power && (randint0(100) < 50)) power = -1; a_m_aux_3(o_ptr, lev, power); break; } case TV_LIGHT: { if (power == 2 || power == -2) make_ego_item(o_ptr, lev, (bool)(power > 0)); /* Fuel it */ a_m_aux_4(o_ptr, lev, power); break; } default: { a_m_aux_4(o_ptr, lev, power); break; } } /* Hack -- analyze ego-items */ if (o_ptr->name2) { ego_item_type *e_ptr = &e_info[o_ptr->name2]; bitflag flags[OF_SIZE]; object_flags(o_ptr, flags); /* Extra powers */ if (e_ptr->xtra == OBJECT_XTRA_TYPE_SUSTAIN) of_on(o_ptr->flags, get_new_attr(flags, ego_sustains, N_ELEMENTS(ego_sustains))); else if (e_ptr->xtra == OBJECT_XTRA_TYPE_RESIST) of_on(o_ptr->flags, get_new_attr(flags, ego_resists, N_ELEMENTS(ego_resists))); else if (e_ptr->xtra == OBJECT_XTRA_TYPE_POWER) of_on(o_ptr->flags, get_new_attr(flags, ego_powers, N_ELEMENTS(ego_powers))); /* Hack -- acquire "cursed" flags */ if (cursed_p(e_ptr)) { bitflag curse_flags[OF_SIZE]; of_copy(curse_flags, e_ptr->flags); flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END); of_union(o_ptr->flags, curse_flags); } /* Hack -- apply extra penalties if needed */ if (cursed_p(o_ptr)) { /* Apply extra ego bonuses */ o_ptr->to_h -= randcalc(e_ptr->to_h, lev, RANDOMISE); o_ptr->to_d -= randcalc(e_ptr->to_d, lev, RANDOMISE); o_ptr->to_a -= randcalc(e_ptr->to_a, lev, RANDOMISE); /* Apply ego pval */ o_ptr->pval -= randcalc(e_ptr->pval, lev, RANDOMISE); /* Apply minimums */ if (o_ptr->to_h > -1 * e_ptr->min_to_h) o_ptr->to_h = -1 * e_ptr->min_to_h; if (o_ptr->to_d > -1 * e_ptr->min_to_d) o_ptr->to_d = -1 * e_ptr->min_to_d; if (o_ptr->to_a > -1 * e_ptr->min_to_a) o_ptr->to_a = -1 * e_ptr->min_to_a; if (o_ptr->pval > -1 * e_ptr->min_pval) o_ptr->pval = -1 * e_ptr->min_pval; } /* Hack -- apply extra bonuses if needed */ else { /* Apply extra ego bonuses */ o_ptr->to_h += randcalc(e_ptr->to_h, lev, RANDOMISE); o_ptr->to_d += randcalc(e_ptr->to_d, lev, RANDOMISE); o_ptr->to_a += randcalc(e_ptr->to_a, lev, RANDOMISE); /* Apply ego pval */ o_ptr->pval += randcalc(e_ptr->pval, lev, RANDOMISE); /* Apply minimums */ if (o_ptr->to_h < e_ptr->min_to_h) o_ptr->to_h = e_ptr->min_to_h; if (o_ptr->to_d < e_ptr->min_to_d) o_ptr->to_d = e_ptr->min_to_d; if (o_ptr->to_a < e_ptr->min_to_a) o_ptr->to_a = e_ptr->min_to_a; if (o_ptr->pval < e_ptr->min_pval) o_ptr->pval = e_ptr->min_pval; } /* Hack -- apply rating bonus */ rating += e_ptr->rating; /* Cheat -- describe the item */ if (OPT(cheat_peek)) object_mention(o_ptr); /* Done */ return; } /* Examine real objects */ if (o_ptr->k_idx) { object_kind *k_ptr = &k_info[o_ptr->k_idx]; /* Hack -- acquire "cursed" flag */ if (cursed_p(k_ptr)) { bitflag curse_flags[OF_SIZE]; of_copy(curse_flags, k_ptr->flags); flags_mask(curse_flags, OF_SIZE, OF_CURSE_MASK, FLAG_END); of_union(o_ptr->flags, curse_flags); } } }
/* * Apply magic to an item known to be a "ring" or "amulet" * * Hack -- note special rating boost for ring of speed * Hack -- note special rating boost for certain amulets * Hack -- note special "pval boost" code for ring of speed * Hack -- note that some items must be cursed (or blessed) */ static void a_m_aux_3(object_type *o_ptr, int level, int power) { /* Apply curses */ if (power < 0) { /* Rings */ if (o_ptr->tval == TV_RING) { switch (o_ptr->sval) { case SV_RING_STRENGTH: case SV_RING_CONSTITUTION: case SV_RING_DEXTERITY: case SV_RING_INTELLIGENCE: case SV_RING_SEARCHING: case SV_RING_DAMAGE: case SV_RING_ACCURACY: case SV_RING_PROTECTION: case SV_RING_SLAYING: { o_ptr->pval = -o_ptr->pval; o_ptr->to_h = -o_ptr->to_h; o_ptr->to_d = -o_ptr->to_d; o_ptr->to_a = -o_ptr->to_a; of_on(o_ptr->flags, OF_LIGHT_CURSE); break; } } } /* Amulets */ else if (o_ptr->tval == TV_AMULET) { switch (o_ptr->sval) { case SV_AMULET_WISDOM: case SV_AMULET_CHARISMA: case SV_AMULET_INFRAVISION: case SV_AMULET_SEARCHING: { o_ptr->pval = -o_ptr->pval; o_ptr->to_h = -o_ptr->to_h; o_ptr->to_d = -o_ptr->to_d; o_ptr->to_a = -o_ptr->to_a; of_on(o_ptr->flags, OF_LIGHT_CURSE); break; } } } } /* Apply magic (good or bad) according to type */ switch (o_ptr->tval) { case TV_RING: { /* Analyze */ switch (o_ptr->sval) { case SV_RING_SPEED: { /* Super-charge the ring */ while (randint0(100) < 50) o_ptr->pval++; if (power >= 0) { /* Rating boost */ rating += 25; /* Mention the item */ if (OPT(cheat_peek)) object_mention(o_ptr); } break; } } break; } case TV_AMULET: { /* Analyze */ switch (o_ptr->sval) { case SV_AMULET_THE_MAGI: case SV_AMULET_DEVOTION: case SV_AMULET_WEAPONMASTERY: case SV_AMULET_TRICKERY: { /* Boost the rating */ rating += 25; /* Mention the item */ if (OPT(cheat_peek)) object_mention(o_ptr); break; } } break; } } }
void apply_magic(object_type *o_ptr, s32b lev, bool okay, bool good, bool great) { s32b i, power; object_kind *k_ptr = &k_info[o_ptr->k_idx]; /* Uses level */ flags_mbonus_level = lev; call_lua("objects_get_power_level", "(O,d,b,b,b)", "d", o_ptr, lev, okay, good, great, &power); /* Initialize books */ if (has_flag(o_ptr, FLAG_GET_BOOK_SPELLS)) { call_lua("setup_object_spells", "(O,d)", "", o_ptr, get_flag(o_ptr, FLAG_GET_BOOK_SPELLS)); } /* No need to touch normal artifacts */ if ((has_flag(k_ptr, FLAG_NORM_ART))) { /* Ahah! we tried to trick us !! */ if (k_ptr->artifact || (((has_flag(k_ptr, FLAG_SPECIAL_GENE))) && (!k_allow_special[o_ptr->k_idx]))) { object_prep(o_ptr, lookup_kind(get_flag(k_ptr, FLAG_NORM_ART), flag_get2(&k_ptr->flags, FLAG_NORM_ART))); if (wizard) msg_print("We've been tricked!"); } else { k_ptr->artifact = TRUE; if (cheat_peek || p_ptr->precognition) object_mention(o_ptr); } /* Reset to default */ flags_mbonus_level = -1; return; } /* Mega hack */ if (hack_apply_magic_power) { if (hack_apply_magic_power == -99) power = 0; else power = hack_apply_magic_power; } hack_apply_magic_power = 0; o_ptr->elevel = 1; o_ptr->exp = 0; /* Special make code */ invoke_on_make(&k_ptr->flags, o_ptr, power); /* Generic on make for all items */ invoke_on_make_all_pre(o_ptr, power); /* Hack -- analyze artifacts */ if (o_ptr->artifact_id) { artifact_type *a_ptr = &a_info[o_ptr->artifact_id]; /* Hack -- Mark the artifact as "created" */ a_ptr->cur_num = 1; /* Extract the other fields */ o_ptr->ac = a_ptr->ac; o_ptr->dd = a_ptr->dd; o_ptr->ds = a_ptr->ds; o_ptr->to_a = a_ptr->to_a; o_ptr->to_h = a_ptr->to_h; o_ptr->to_d = a_ptr->to_d; o_ptr->weight = a_ptr->weight; o_ptr->number = 1; /* Transfer flags */ flag_add(&o_ptr->flags, &a_ptr->flags); /* Mega-Hack -- increase the rating */ rating += 10; /* Mega-Hack -- increase the rating again */ if (a_ptr->cost > 50000L) rating += 10; /* Set the good item flag */ good_item_flag = TRUE; /* Cheat -- peek at the item */ if ((cheat_peek) || (p_ptr->precognition)) object_mention(o_ptr); /* Special make code */ invoke_on_make(&a_ptr->flags, o_ptr, power); invoke_on_make_all(o_ptr, power); /* Hack -- extract the "cursed" flag */ if (has_flag(o_ptr, FLAG_CURSED)) o_ptr->ident |= (IDENT_CURSED); /* Done */ /* Reset to default */ flags_mbonus_level = -1; return; } if (o_ptr->art_name) rating += 40; /* Analyze ego-items */ else { ego_item_type *e_ptr; s32b j; s16b e_idx; bool did_ego = FALSE; for (i = 0; i < MAX_EGO_PER_OBJ; i++) { e_idx = o_ptr->ego_id[i]; if (!e_idx) continue; did_ego = TRUE; e_ptr = &e_info[e_idx]; /* Hack -- extra powers */ for (j = 0; j < MAX_EGO_FLAG_GROUPS; j++) { /* Rarity check */ if (magik(e_ptr->rar[j])) { /* Copy all flags */ flag_add(&o_ptr->flags, &e_ptr->flags[j]); /* Special make code */ invoke_on_make(&e_ptr->flags[j], o_ptr, power); } } /* Hack -- acquire "cursed" flag */ if (has_flag(o_ptr, FLAG_CURSED)) o_ptr->ident |= (IDENT_CURSED); /* Hack -- obtain bonuses */ if (e_ptr->max_to_h > 0) o_ptr->to_h += randint(e_ptr->max_to_h); if (e_ptr->max_to_h < 0) o_ptr->to_h -= randint( -e_ptr->max_to_h); if (e_ptr->max_to_d > 0) o_ptr->to_d += randint(e_ptr->max_to_d); if (e_ptr->max_to_d < 0) o_ptr->to_d -= randint( -e_ptr->max_to_d); if (e_ptr->max_to_a > 0) o_ptr->to_a += randint(e_ptr->max_to_a); if (e_ptr->max_to_a < 0) o_ptr->to_a -= randint( -e_ptr->max_to_a); /* Hack -- apply rating bonus */ rating += e_ptr->rating; } /* Cheat -- describe the item */ if ((did_ego) && ((cheat_peek) || (p_ptr->precognition))) object_mention(o_ptr); } /* Generic on make for all items */ invoke_on_make_all(o_ptr, power); /* Examine real objects */ if (o_ptr->k_idx) { /* Hack -- acquire "cursed" flag */ if (has_flag(o_ptr, FLAG_CURSED)) o_ptr->ident |= (IDENT_CURSED); } /* Reset to default */ flags_mbonus_level = -1; }