From c59c58e7a4e34a1f46ece4a45096b955d6caba65 Mon Sep 17 00:00:00 2001 From: haranp Date: Sat, 7 Jul 2007 10:17:07 +0000 Subject: Describing items now works better in shops (fixes 1749246.) More consistency in type-ID vs. artefacts: knowing the type-ID of a specific ring won't property-ID or type-ID an artefact ring of the same type, and vice versa. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1781 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/dat/mini.des | 6 ++-- crawl-ref/source/describe.cc | 16 ++++----- crawl-ref/source/effects.cc | 3 +- crawl-ref/source/item_use.cc | 78 ++++++++++++++++++------------------------- crawl-ref/source/itemname.cc | 46 +++++++++++++------------ crawl-ref/source/itemname.h | 1 + crawl-ref/source/shopping.cc | 15 ++++++++- crawl-ref/source/spells1.cc | 14 +++++--- 8 files changed, 93 insertions(+), 86 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/dat/mini.des b/crawl-ref/source/dat/mini.des index 9d07dcc9c5..7566b4a70f 100644 --- a/crawl-ref/source/dat/mini.des +++ b/crawl-ref/source/dat/mini.des @@ -1220,8 +1220,8 @@ ENDMAP # # Shoal:$ is hand-hacked to force lots of minivaults. NAME: shoalhut_rune -PLACE: Shoal:5 -TAGS: water_ok +PLACE: Shoal:$ +TAGS: water_ok has_rune MONS: cyclops CHANCE: 1000 MAP @@ -1237,7 +1237,7 @@ ENDMAP # # Shoal:$ is hand-hacked to force lots of minivaults. NAME: shoalhut_norune -PLACE: Shoal:5 +PLACE: Shoal:$ TAGS: water_ok allow_dup MONS: cyclops CHANCE: 1000 diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 0c95a37d5a..1065984586 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -1817,7 +1817,7 @@ static std::string describe_stick( const item_def &item ) description.reserve(64); - if (get_ident_type( OBJ_WANDS, item.sub_type ) != ID_KNOWN_TYPE) + if ( !item_type_known(item) ) description += "A stick. Maybe it's magical. "; else { @@ -2150,7 +2150,7 @@ static std::string describe_food( const item_def &item ) //--------------------------------------------------------------- static const char* describe_potion( const item_def &item ) { - if (get_ident_type( OBJ_POTIONS, item.sub_type ) != ID_KNOWN_TYPE) + if ( !item_type_known(item) ) return "A small bottle of liquid.$"; switch (static_cast(item.sub_type)) @@ -2233,7 +2233,7 @@ static std::string describe_scroll( const item_def &item ) description.reserve(64); - if (get_ident_type( OBJ_SCROLLS, item.sub_type ) != ID_KNOWN_TYPE) + if ( !item_type_known(item) ) description += "A scroll of paper covered in magical writing."; else { @@ -2401,10 +2401,7 @@ static std::string describe_jewellery( const item_def &item, bool verbose) description += unrandart_descrip(1, item); description += "$"; } - else if ((!is_random_artefact( item ) - && get_ident_type( OBJ_JEWELLERY, item.sub_type ) != ID_KNOWN_TYPE) - || (is_random_artefact( item ) - && !item_type_known(item))) + else if ( !item_type_known(item) ) { description += "A piece of jewellery."; } @@ -3124,7 +3121,7 @@ bool is_dumpable_artefact( const item_def &item, bool verbose) { bool ret = false; - if (is_random_artefact( item ) || is_fixed_artefact( item )) + if (is_artefact( item ) ) { ret = item_ident( item, ISFLAG_KNOW_PROPERTIES ); } @@ -3135,8 +3132,7 @@ bool is_dumpable_artefact( const item_def &item, bool verbose) ret = (spec_ench >= SPARM_RUNNING && spec_ench <= SPARM_PRESERVATION); } else if (item.base_type == OBJ_JEWELLERY - && (verbose - && get_ident_type(OBJ_JEWELLERY, item.sub_type) == ID_KNOWN_TYPE)) + && (verbose && item_type_known(item))) { ret = true; } diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc index 656618228e..6b5825d3a7 100644 --- a/crawl-ref/source/effects.cc +++ b/crawl-ref/source/effects.cc @@ -798,7 +798,8 @@ bool acquirement(object_class_type force_class, int agent) if (one_chance_in(3)) type_wanted = AMU_RAGE + random2(10); - if (get_ident_type(OBJ_JEWELLERY, type_wanted) == ID_UNKNOWN_TYPE) + if (get_ident_type(OBJ_JEWELLERY, type_wanted) == + ID_UNKNOWN_TYPE) { break; } diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 2a9d33aad3..d57bf9ded2 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -2615,7 +2615,8 @@ void zap_wand(void) return; } - if (you.inv[item_slot].base_type != OBJ_WANDS) + item_def& wand = you.inv[item_slot]; + if (wand.base_type != OBJ_WANDS) { canned_msg(MSG_NOTHING_HAPPENS); return; @@ -2625,22 +2626,22 @@ void zap_wand(void) if (you.equip[EQ_WEAPON] == item_slot) you.wield_change = true; - if ( you.inv[item_slot].plus < 1 ) + if ( wand.plus < 1 ) { // it's an empty wand, inscribe it that way canned_msg(MSG_NOTHING_HAPPENS); - you.inv[item_slot].plus2 = ZAPCOUNT_EMPTY; + wand.plus2 = ZAPCOUNT_EMPTY; you.turn_is_over = true; return; } - const bool alreadyknown = item_type_known(you.inv[item_slot]); + const bool alreadyknown = item_type_known(wand); const bool dangerous = player_in_a_dangerous_place(); if (alreadyknown) { - if (you.inv[item_slot].sub_type == WAND_HASTING - || you.inv[item_slot].sub_type == WAND_HEALING - || you.inv[item_slot].sub_type == WAND_INVISIBILITY) + if (wand.sub_type == WAND_HASTING + || wand.sub_type == WAND_HEALING + || wand.sub_type == WAND_INVISIBILITY) { targ_mode = TARG_FRIEND; } @@ -2669,7 +2670,7 @@ void zap_wand(void) // blargh! blech! this is just begging to be a problem ... // not to mention work-around after work-around as wands are // added, removed, or altered {dlb}: - char type_zapped = you.inv[item_slot].sub_type; + char type_zapped = wand.sub_type; if (type_zapped == WAND_ENSLAVEMENT) type_zapped = ZAP_ENSLAVEMENT; @@ -2702,48 +2703,36 @@ void zap_wand(void) zapping( static_cast(type_zapped), 30 + roll_dice(2, you.skills[SK_EVOCATIONS]), beam ); - if (beam.obvious_effect == 1 || you.inv[item_slot].sub_type == WAND_FIREBALL) + if ((beam.obvious_effect || wand.sub_type == WAND_FIREBALL) && + !alreadyknown) { - if (get_ident_type( you.inv[item_slot].base_type, - you.inv[item_slot].sub_type ) != ID_KNOWN_TYPE) - { - set_ident_type( you.inv[item_slot].base_type, - you.inv[item_slot].sub_type, ID_KNOWN_TYPE ); - - mpr(you.inv[item_slot].name(DESC_INVENTORY_EQUIP).c_str()); - - // update if wielding - if (you.equip[EQ_WEAPON] == item_slot) - you.wield_change = true; - } + set_ident_type( wand.base_type, wand.sub_type, ID_KNOWN_TYPE ); + mpr(wand.name(DESC_INVENTORY_EQUIP).c_str()); } else { - set_ident_type( you.inv[item_slot].base_type, - you.inv[item_slot].sub_type, ID_TRIED_TYPE ); + set_ident_type( wand.base_type, wand.sub_type, ID_TRIED_TYPE ); } // take off a charge - you.inv[item_slot].plus--; + wand.plus--; // increment zap count - if ( you.inv[item_slot].plus2 >= 0 ) - you.inv[item_slot].plus2++; + if ( wand.plus2 >= 0 ) + wand.plus2++; - if (get_ident_type( you.inv[item_slot].base_type, - you.inv[item_slot].sub_type ) == ID_KNOWN_TYPE - && (item_ident( you.inv[item_slot], ISFLAG_KNOW_PLUSES ) + if (item_type_known(wand) + && (item_ident( wand, ISFLAG_KNOW_PLUSES ) || you.skills[SK_EVOCATIONS] > 5 + random2(15))) { - if (!item_ident( you.inv[item_slot], ISFLAG_KNOW_PLUSES )) + if (!item_ident( wand, ISFLAG_KNOW_PLUSES )) { mpr("Your skill with magical items lets you calculate the power of this device..."); } mprf("This wand has %d charge%s left.", - you.inv[item_slot].plus, - (you.inv[item_slot].plus == 1) ? "" : "s" ); - set_ident_flags( you.inv[item_slot], ISFLAG_KNOW_PLUSES ); + wand.plus, (wand.plus == 1) ? "" : "s" ); + set_ident_flags( wand, ISFLAG_KNOW_PLUSES ); } exercise( SK_EVOCATIONS, 1 ); @@ -3322,15 +3311,16 @@ void read_scroll(void) return; } - if (you.inv[item_slot].base_type != OBJ_BOOKS - && you.inv[item_slot].base_type != OBJ_SCROLLS) + item_def& scroll = you.inv[item_slot]; + + if (scroll.base_type != OBJ_BOOKS && scroll.base_type != OBJ_SCROLLS) { mpr("You can't read that!"); return; } // here we try to read a book {dlb}: - if (you.inv[item_slot].base_type == OBJ_BOOKS) + if (scroll.base_type == OBJ_BOOKS) { handle_read_book( item_slot ); return; @@ -3356,16 +3346,16 @@ void read_scroll(void) } // decrement and handle inventory if any scroll other than paper {dlb}: - const int scroll_type = you.inv[item_slot].sub_type; - if (scroll_type != SCR_PAPER) + const int scroll_type = scroll.sub_type; + if (scroll_type != SCR_PAPER && + (scroll_type != SCR_IMMOLATION || you.duration[DUR_CONF])) { mpr("As you read the scroll, it crumbles to dust."); // Actual removal of scroll done afterwards. -- bwr } - bool alreadyknown = get_ident_type( OBJ_SCROLLS, you.inv[item_slot].sub_type ) == ID_KNOWN_TYPE; - - bool dangerous = player_in_a_dangerous_place(); + const bool alreadyknown = item_type_known(scroll); + const bool dangerous = player_in_a_dangerous_place(); // scrolls of paper are also exempted from this handling {dlb}: if (scroll_type != SCR_PAPER) @@ -3463,10 +3453,8 @@ void read_scroll(void) torment( TORMENT_SCROLL, you.x_pos, you.y_pos ); // is only naughty if you know you're doing it - if (get_ident_type( OBJ_SCROLLS, SCR_TORMENT ) == ID_KNOWN_TYPE) - { + if (!item_type_known(scroll)) did_god_conduct(DID_UNHOLY, 10); - } break; case SCR_IMMOLATION: @@ -3492,7 +3480,7 @@ void read_scroll(void) break; case SCR_IDENTIFY: - if ( get_ident_type( OBJ_SCROLLS, scroll_type ) != ID_KNOWN_TYPE ) + if ( !item_type_known(scroll) ) { mpr("This is a scroll of identify!"); more(); diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index eb1e7aaf0e..4b823cef70 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -47,24 +47,6 @@ static bool is_random_name_vowel( char let ); static char retvow(int sed); static char retlet(int sed); -static bool is_tried_type( object_class_type basetype, int subtype ) -{ - if ( subtype >= 50 ) - return false; - - switch ( basetype ) - { - case OBJ_SCROLLS: - return type_ids[IDTYPE_SCROLLS][subtype] == ID_TRIED_TYPE; - case OBJ_POTIONS: - return type_ids[IDTYPE_POTIONS][subtype] == ID_TRIED_TYPE; - case OBJ_WANDS: - return type_ids[IDTYPE_WANDS][subtype] == ID_TRIED_TYPE; - default: - return false; - } -} - bool is_vowel( const char chr ) { const char low = tolower( chr ); @@ -231,10 +213,10 @@ std::string item_def::name(description_level_type descrip, } } - const bool tried = !ident && is_tried_type(this->base_type,this->sub_type); + const bool tried = !ident && item_type_tried(*this); if ( with_inscription && !(this->inscription.empty()) ) { - buff << " {"; + buff << " {"; if ( tried ) buff << "tried, "; buff << this->inscription << "}"; @@ -1505,11 +1487,16 @@ static item_type_id_type objtype_to_idtype(object_class_type base_type) } } -bool item_type_known( const item_def &item ) +bool item_type_known( const item_def& item ) { if (item_ident(item, ISFLAG_KNOW_TYPE)) return (true); + // Artefacts have different descriptions from other items, + // so we can't use general item knowledge for them. + if ( is_artefact(item) ) + return false; + const item_type_id_type idt = objtype_to_idtype(item.base_type); if ( idt != NUM_IDTYPE && item.sub_type < 50 ) return ( type_ids[idt][item.sub_type] == ID_KNOWN_TYPE ); @@ -1517,6 +1504,23 @@ bool item_type_known( const item_def &item ) return false; } +bool item_type_tried( const item_def& item ) +{ + if ( item_type_known(item) ) + return false; + + // Well, if we ever put in scroll or potion artefacts, this + // might be necessary... + if ( is_artefact(item) ) + return false; + + const item_type_id_type idt = objtype_to_idtype(item.base_type); + if (idt != NUM_IDTYPE && item.sub_type < 50) + return ( type_ids[idt][item.sub_type] == ID_TRIED_TYPE ); + else + return false; +} + id_arr& get_typeid_array() { return type_ids; diff --git a/crawl-ref/source/itemname.h b/crawl-ref/source/itemname.h index d04cd55246..e3dbdd23d4 100644 --- a/crawl-ref/source/itemname.h +++ b/crawl-ref/source/itemname.h @@ -34,6 +34,7 @@ std::string quant_name( const item_def &item, int quant, description_level_type des, bool terse = false ); bool item_type_known( const item_def &item ); +bool item_type_tried( const item_def &item ); bool is_interesting_item( const item_def& item ); diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc index 9f722b94bd..6836137cca 100644 --- a/crawl-ref/source/shopping.cc +++ b/crawl-ref/source/shopping.cc @@ -259,7 +259,20 @@ static void in_a_shop( char shoppy ) goto purchase; } - describe_item( mitm[shop_items[ft]] ); + // A hack to make the description more useful. + // In theory, the user could kill the process at this + // point and end up with valid ID for the item. + // That's not very useful, though, because it doesn't set + // type-ID and once you can access the item (by buying it) + // you have its full ID anyway. Worst case, it won't get + // noted when you buy it. + item_def& item = mitm[shop_items[ft]]; + const unsigned long old_flags = item.flags; + if ( id_stock ) + item.flags |= ISFLAG_IDENT_MASK; + describe_item(item); + if ( id_stock ) + item.flags = old_flags; goto print_stock; } diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index 724d2bc037..e78ef07a83 100644 --- a/crawl-ref/source/spells1.cc +++ b/crawl-ref/source/spells1.cc @@ -39,6 +39,7 @@ #include "monstuff.h" #include "mon-util.h" #include "player.h" +#include "randart.h" #include "skills2.h" #include "spells3.h" #include "spells4.h" @@ -374,7 +375,10 @@ void identify(int power) canned_msg( MSG_OK ); return; } - if ( fully_identified(you.inv[item_slot]) ) + + item_def& item(you.inv[item_slot]); + + if ( fully_identified(item) ) { mpr("Choose an unidentified item, or Esc to abort."); if ( Options.auto_list ) @@ -382,13 +386,13 @@ void identify(int power) continue; } - set_ident_type( you.inv[item_slot].base_type, - you.inv[item_slot].sub_type, ID_KNOWN_TYPE ); + if ( !is_artefact(item) ) + set_ident_type( item.base_type, item.sub_type, ID_KNOWN_TYPE ); - set_ident_flags( you.inv[item_slot], ISFLAG_IDENT_MASK ); + set_ident_flags( item, ISFLAG_IDENT_MASK ); // output identified item - mpr(you.inv[item_slot].name(DESC_INVENTORY_EQUIP).c_str()); + mpr(item.name(DESC_INVENTORY_EQUIP).c_str()); if (item_slot == you.equip[EQ_WEAPON]) you.wield_change = true; -- cgit v1.2.3-54-g00ecf