From a57cca76a917863b82323b0c61d3dae2dfe8d64a Mon Sep 17 00:00:00 2001 From: haranp Date: Tue, 30 Oct 2007 22:29:10 +0000 Subject: 'v' now describes decks properly. There is a small information leak: if you know (from Peek Deck) that the deck contains a card X somewhere, and then you draw card X which happens not to be the seen card X in the internal structure, you can still see from the 'v' output that there is another X card hiding in there. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2692 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/describe.cc | 51 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'crawl-ref/source/describe.cc') diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 350c7a51f4..a75966984c 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -2971,6 +2971,10 @@ static std::string describe_staff( const item_def &item ) return (description); } +static bool compare_card_names(card_type a, card_type b) +{ + return std::string(card_name(a)) < std::string(card_name(b)); +} //--------------------------------------------------------------- // @@ -3186,16 +3190,47 @@ static std::string describe_misc_item( const item_def &item ) description += "$"; - if ( is_deck(item) && item.plus2 != 0 ) + if ( is_deck(item) ) { - description += "$Next card(s): "; - description += card_name(static_cast(item.plus2 - 1)); - long spec = item.special; - while ( spec ) + const int num_cards = cards_in_deck(item); + if ( top_card_is_known(item) ) { - description += ", "; - description += card_name(static_cast((spec & 0xFF)-1)); - spec >>= 8; + description += "Next card(s): "; + for ( int i = 0; i < num_cards; ++i ) + { + unsigned char flags; + const card_type card = get_card_and_flags(item, -i-1, flags); + if ( flags & CFLAG_MARKED ) + { + if ( i != 0 ) + description += ", "; + description += card_name(card); + } + else + break; + } + } + + std::vector seen_cards; + for ( int i = 0; i < num_cards; ++i ) + { + unsigned char flags; + const card_type card = get_card_and_flags(item, -i-1, flags); + // This *might* leak a bit of information...oh well. + if ( (flags & CFLAG_SEEN) && !(flags & CFLAG_MARKED) ) + seen_cards.push_back(card); + } + if ( !seen_cards.empty() ) + { + std::sort(seen_cards.begin(), seen_cards.end(), + compare_card_names); + description += "$Seen cards: "; + for ( unsigned int i = 0; i < seen_cards.size(); ++i ) + { + if ( i != 0 ) + description += ", "; + description += card_name(seen_cards[i]); + } } description += "$"; } -- cgit v1.2.3-54-g00ecf