diff options
author | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-08 22:09:25 +0000 |
---|---|---|
committer | j-p-e-g <j-p-e-g@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-08 22:09:25 +0000 |
commit | f55a8b913e4fb43166f6a3cbd083a4a0f5154358 (patch) | |
tree | eb282082a88a6f133eeefc11651769d856dacbf0 | |
parent | 1b7c5aa3c413b3469ada00e521b37aeca57abdd5 (diff) | |
download | crawl-ref-f55a8b913e4fb43166f6a3cbd083a4a0f5154358.tar.gz crawl-ref-f55a8b913e4fb43166f6a3cbd083a4a0f5154358.zip |
Implement FR 2489034: Disallow known scrolls of enchant
armour/recharging on armour that cannot be enchanted or items that
cannot be recharged, respectively.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8337 c06c8d41-db1a-0410-9941-cceddc491573
-rw-r--r-- | crawl-ref/source/effects.cc | 152 | ||||
-rw-r--r-- | crawl-ref/source/invent.cc | 2 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 42 | ||||
-rw-r--r-- | crawl-ref/source/itemprop.cc | 45 | ||||
-rw-r--r-- | crawl-ref/source/itemprop.h | 3 |
5 files changed, 149 insertions, 95 deletions
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index 025c97d392..34fb13bc91 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -1875,99 +1875,115 @@ bool acquirement(object_class_type class_wanted, int agent, bool recharge_wand(int item_slot) { - if (item_slot == -1) + do { - item_slot = prompt_invent_item( "Charge which item?", MT_INVLIST, - OSEL_RECHARGE, true, true, false ); - } + if (item_slot == -1) + { + item_slot = prompt_invent_item( "Charge which item?", MT_INVLIST, + OSEL_RECHARGE, true, true, false ); + } + if (prompt_failed(item_slot)) + return (false); - if (prompt_failed(item_slot)) - return (false); + item_def &wand = you.inv[ item_slot ]; - item_def &wand = you.inv[ item_slot ]; + if (!item_is_rechargeable(wand, true, true)) + { + mpr("Choose an item to recharge, or Esc to abort."); + if (Options.auto_list) + more(); - // Weapons of electrocution can be "charged", i.e. gain +1 damage. - if (wand.base_type == OBJ_WEAPONS - && get_weapon_brand(wand) == SPWPN_ELECTROCUTION) - { - // Might fail because of already high enchantment. - if (enchant_weapon( ENCHANT_TO_DAM, false, wand )) + // Try again. + item_slot = -1; + continue; + } + + // Weapons of electrocution can be "charged", i.e. gain +1 damage. + if (wand.base_type == OBJ_WEAPONS + && get_weapon_brand(wand) == SPWPN_ELECTROCUTION) { - you.wield_change = true; + // Might fail because of already high enchantment. + if (enchant_weapon( ENCHANT_TO_DAM, false, wand )) + { + you.wield_change = true; - if (!item_ident(wand, ISFLAG_KNOW_TYPE)) - set_ident_flags(wand, ISFLAG_KNOW_TYPE); + if (!item_ident(wand, ISFLAG_KNOW_TYPE)) + set_ident_flags(wand, ISFLAG_KNOW_TYPE); - return (true); + return (true); + } + return (false); } - return (false); - } - if (wand.base_type != OBJ_WANDS && !item_is_rod(wand)) - return (false); + if (wand.base_type != OBJ_WANDS && !item_is_rod(wand)) + return (false); - int charge_gain = 0; - if (wand.base_type == OBJ_WANDS) - { - charge_gain = wand_charge_value(wand.sub_type); + int charge_gain = 0; + if (wand.base_type == OBJ_WANDS) + { + charge_gain = wand_charge_value(wand.sub_type); - // Reinitialize zap counts. - wand.plus2 = ZAPCOUNT_RECHARGED; + // Reinitialize zap counts. + wand.plus2 = ZAPCOUNT_RECHARGED; - const int new_charges = - std::max<int>( - wand.plus, - std::min(charge_gain * 3, - wand.plus + - 1 + random2avg( ((charge_gain - 1) * 3) + 1, 3 ))); + const int new_charges = + std::max<int>( + wand.plus, + std::min(charge_gain * 3, + wand.plus + + 1 + random2avg( ((charge_gain - 1) * 3) + 1, 3 ))); - const bool charged = (new_charges > wand.plus); + const bool charged = (new_charges > wand.plus); - std::string desc; - if (charged && item_ident(wand, ISFLAG_KNOW_PLUSES)) - { - snprintf(info, INFO_SIZE, " and now has %d charges", new_charges); - desc = info; + std::string desc; + if (charged && item_ident(wand, ISFLAG_KNOW_PLUSES)) + { + snprintf(info, INFO_SIZE, " and now has %d charges", new_charges); + desc = info; + } + mprf("%s %s for a moment%s.", + wand.name(DESC_CAP_YOUR).c_str(), + charged? "glows" : "flickers", + desc.c_str()); + + wand.plus = new_charges; + + if (!charged) + wand.plus2 = ZAPCOUNT_MAX_CHARGED; } - mprf("%s %s for a moment%s.", - wand.name(DESC_CAP_YOUR).c_str(), - charged? "glows" : "flickers", - desc.c_str()); + else // It's a rod. + { + bool work = false; - wand.plus = new_charges; + if (wand.plus2 < MAX_ROD_CHARGE * ROD_CHARGE_MULT) + { + wand.plus2 += ROD_CHARGE_MULT; - if (!charged) - wand.plus2 = ZAPCOUNT_MAX_CHARGED; - } - else // It's a rod. - { - bool work = false; + if (wand.plus2 > MAX_ROD_CHARGE * ROD_CHARGE_MULT) + wand.plus2 = MAX_ROD_CHARGE * ROD_CHARGE_MULT; - if (wand.plus2 < MAX_ROD_CHARGE * ROD_CHARGE_MULT) - { - wand.plus2 += ROD_CHARGE_MULT; + work = true; + } - if (wand.plus2 > MAX_ROD_CHARGE * ROD_CHARGE_MULT) - wand.plus2 = MAX_ROD_CHARGE * ROD_CHARGE_MULT; + if (wand.plus < wand.plus2) + { + wand.plus = wand.plus2; + work = true; + } - work = true; - } + if (!work) + return (false); - if (wand.plus < wand.plus2) - { - wand.plus = wand.plus2; - work = true; + mprf("%s glows for a moment.", wand.name(DESC_CAP_YOUR).c_str()); } - if (!work) - return (false); - - mprf("%s glows for a moment.", wand.name(DESC_CAP_YOUR).c_str()); + you.wield_change = true; + return (true); } + while (true); - you.wield_change = true; - return (true); -} // end recharge_wand() + return (false); +} // Sets foe target of friendly monsters. // If allow_patrol is true, patrolling monsters get MHITNOT instead. diff --git a/crawl-ref/source/invent.cc b/crawl-ref/source/invent.cc index 5c63d757d9..461107161a 100644 --- a/crawl-ref/source/invent.cc +++ b/crawl-ref/source/invent.cc @@ -875,7 +875,7 @@ static bool _item_class_selected(const item_def &i, int selector) return (itype == OBJ_SCROLLS || itype == OBJ_BOOKS); case OSEL_RECHARGE: - return (item_is_rechargeable(i, true)); + return (item_is_rechargeable(i, true, true)); case OSEL_ENCH_ARM: return (is_enchantable_armour(i, true, true)); diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 731d10567b..94a0c150b9 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -4167,24 +4167,40 @@ bool enchant_armour(int &ac_change, bool quiet, item_def &arm) static bool _handle_enchant_armour(int item_slot) { - if (item_slot == -1) + do { - item_slot = prompt_invent_item("Enchant which item?", MT_INVLIST, - OSEL_ENCH_ARM, true, true, false); - } + if (item_slot == -1) + { + item_slot = prompt_invent_item("Enchant which item?", MT_INVLIST, + OSEL_ENCH_ARM, true, true, false); + } + if (prompt_failed(item_slot)) + return (false); - if (prompt_failed(item_slot)) - return (false); + item_def& arm(you.inv[item_slot]); - item_def& arm(you.inv[item_slot]); + if (!is_enchantable_armour(arm, true, true)) + { + mpr("Choose some type of armour to enchant, or Esc to abort."); + if (Options.auto_list) + more(); - int ac_change; - bool result = enchant_armour(ac_change, false, arm); + item_slot = -1; + continue; + } - if (ac_change) - you.redraw_armour_class = true; + // Okay, we may actually (attempt to) enchant something. + int ac_change; + bool result = enchant_armour(ac_change, false, arm); - return (result); + if (ac_change) + you.redraw_armour_class = true; + + return (result); + } + while (true); + + return (false); } static void handle_read_book(int item_slot) @@ -4262,7 +4278,7 @@ static bool _scroll_modify_item(item_def scroll) } break; case SCR_RECHARGING: - if (item_is_rechargeable(item)) + if (item_is_rechargeable(item, true)) { // Might still fail on highly enchanted weapons of electrocution. // (If so, already prints the "Nothing happens" message.) diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index b7b1c8e326..ac3411bc0f 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -1327,17 +1327,24 @@ bool check_armour_shape( const item_def &item, bool quiet ) return (true); } -// If known is true, only returns true for *known* weapons of electrocution, -// and returns false for wands/rods known to be fully charged. -bool item_is_rechargeable(const item_def &it, bool known) +// Returns whether a wand or rod can be charged, or a weapon of electrocution +// enchanted. +// If unknown is true, wands with unknown charges and weapons with unknown +// brand will also return true. +// If hide_charged is true, wands known to be full will return false. +// (This distinction is necessary because even full wands/rods give a message.) +bool item_is_rechargeable(const item_def &it, bool unknown, bool hide_charged) { // These are obvious... if (it.base_type == OBJ_WANDS) { + if (unknown && !hide_charged) + return (true); + // Don't offer wands already maximally charged. - if (known && (it.plus2 == ZAPCOUNT_MAX_CHARGED - || item_ident(it, ISFLAG_KNOW_PLUSES) - && it.plus >= 3 * wand_charge_value(it.sub_type))) + if (it.plus2 == ZAPCOUNT_MAX_CHARGED + || item_ident(it, ISFLAG_KNOW_PLUSES) + && it.plus >= 3 * wand_charge_value(it.sub_type)) { return (false); } @@ -1345,20 +1352,34 @@ bool item_is_rechargeable(const item_def &it, bool known) } else if (item_is_rod(it)) { - if (known && item_ident(it, ISFLAG_KNOW_PLUSES)) + if (unknown && !hide_charged) + return (true); + + if (item_ident(it, ISFLAG_KNOW_PLUSES)) { return (it.plus2 < MAX_ROD_CHARGE * ROD_CHARGE_MULT || it.plus < it.plus2); } return (true); } + else if (it.base_type == OBJ_WEAPONS) + { + if (unknown && !item_type_known(it)) // Could be electrocution. + return (true); - // ...but electric weapons can also be charged. - return (it.base_type == OBJ_WEAPONS - && !is_random_artefact(it) - && !is_fixed_artefact(it) + // Weapons of electrocution can get +1 to-dam this way. + if (!is_artefact(it) && get_weapon_brand(it) == SPWPN_ELECTROCUTION - && (!known || item_type_known(it))); + && item_type_known(it) + && (unknown && !item_ident(it, ISFLAG_KNOW_PLUSES ) + || item_ident(it, ISFLAG_KNOW_PLUSES ) + && it.plus2 < MAX_WPN_ENCHANT)) + { + return (true); + } + } + + return (false); } // Max. charges are 3 times this value. diff --git a/crawl-ref/source/itemprop.h b/crawl-ref/source/itemprop.h index 3051c31ef4..b617aa90c9 100644 --- a/crawl-ref/source/itemprop.h +++ b/crawl-ref/source/itemprop.h @@ -635,7 +635,8 @@ int fit_armour_size( const item_def &item, size_type size ); bool check_armour_size( const item_def &item, size_type size ); bool check_armour_shape( const item_def &item, bool quiet ); -bool item_is_rechargeable(const item_def &it, bool known = false); +bool item_is_rechargeable(const item_def &it, bool unknown = false, + bool hide_charged = false); int wand_charge_value(int type); bool is_enchantable_weapon(const item_def &wpn, bool uncurse); bool is_enchantable_armour(const item_def &arm, bool uncurse, |