diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-10-30 22:29:10 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-10-30 22:29:10 +0000 |
commit | a57cca76a917863b82323b0c61d3dae2dfe8d64a (patch) | |
tree | 2072041bc2386c8bb0dc1298dc42000735282312 /crawl-ref | |
parent | 6fa5b18a9ef1bb0656923fa3bf9e1118e1e2ecef (diff) | |
download | crawl-ref-a57cca76a917863b82323b0c61d3dae2dfe8d64a.tar.gz crawl-ref-a57cca76a917863b82323b0c61d3dae2dfe8d64a.zip |
'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
Diffstat (limited to 'crawl-ref')
-rw-r--r-- | crawl-ref/source/decks.cc | 21 | ||||
-rw-r--r-- | crawl-ref/source/decks.h | 4 | ||||
-rw-r--r-- | crawl-ref/source/describe.cc | 51 |
3 files changed, 58 insertions, 18 deletions
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc index ecd3940281..e3808cb5d0 100644 --- a/crawl-ref/source/decks.cc +++ b/crawl-ref/source/decks.cc @@ -54,7 +54,7 @@ // with, deck.plus2 is the number of cards drawn, deck.special is the // deck rarity, deck.props["cards"] holds the list of cards (with the // highest index card being the top card, and index 0 being the bottom -// card), deck.props.["card_flags"] holds the flags for each card, +// card), deck.props["card_flags"] holds the flags for each card, // deck.props["num_marked"] is the number of marked cards left in the // deck, and deck.props["non_brownie_draws"] is the number of // non-marked draws you have to make from that deck before earning @@ -141,7 +141,7 @@ static void check_odd_card(unsigned char flags) mpr("This card doesn't seem to belong here."); } -static unsigned long cards_in_deck(const item_def &deck) +int cards_in_deck(const item_def &deck) { ASSERT(is_deck(deck)); @@ -167,25 +167,26 @@ static void shuffle_deck(item_def &deck) // Don't use std::shuffle(), since we want to apply exactly the // same shuffling to both the cards vector and the flags vector. std::vector<long> pos; - for (unsigned long i = 0, size = cards.size(); i < size; i++) - pos.push_back(random2(size)); + for (unsigned long i = 0; i < cards.size(); i++) + pos.push_back(random2(cards.size())); - for (unsigned long i = 0, size = pos.size(); i < size; i++) + for (unsigned long i = 0; i < pos.size(); i++) { std::swap(cards[i], cards[pos[i]]); std::swap(flags[i], flags[pos[i]]); } } -static card_type get_card_and_flags(const item_def& deck, int idx, - unsigned char& _flags) +card_type get_card_and_flags(const item_def& deck, int idx, + unsigned char& _flags) { const CrawlHashTable &props = deck.props; const CrawlVector &cards = props["cards"].get_vector(); const CrawlVector &flags = props["card_flags"].get_vector(); - if (idx == -1) - idx = (int) cards.size() - 1; + // negative idx means read from the end + if (idx < 0) + idx += static_cast<int>(cards.size()); _flags = (unsigned char) flags[idx].get_byte(); @@ -2351,7 +2352,7 @@ void init_deck(item_def &item) set_card_and_flags(item, i, card, flags); } - ASSERT(cards_in_deck(item) == (unsigned long) item.plus); + ASSERT(cards_in_deck(item) == item.plus); props["num_marked"] = (char) 0; props["non_brownie_draws"] = (char) 0; diff --git a/crawl-ref/source/decks.h b/crawl-ref/source/decks.h index e028d822c8..299cbb391f 100644 --- a/crawl-ref/source/decks.h +++ b/crawl-ref/source/decks.h @@ -137,4 +137,8 @@ deck_rarity_type deck_rarity(const item_def &item); unsigned char deck_rarity_to_color(deck_rarity_type rarity); void init_deck(item_def &item); +int cards_in_deck(const item_def &deck); +card_type get_card_and_flags(const item_def& deck, int idx, + unsigned char& _flags); + #endif 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<card_type>(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<card_type>((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<card_type> 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 += "$"; } |