diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-02 18:36:08 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-12-02 18:36:08 +0000 |
commit | 0d31b1337f7557390cf0ef3e929f90599faaf6ae (patch) | |
tree | c240e002c1f238fdfa2e10c5cea8ea162400bdca /crawl-ref/source | |
parent | 8148e4b2159d857790803b82b484f20e8bb9a981 (diff) | |
download | crawl-ref-0d31b1337f7557390cf0ef3e929f90599faaf6ae.tar.gz crawl-ref-0d31b1337f7557390cf0ef3e929f90599faaf6ae.zip |
Decks are now annotated with the list of cards drawn from them in the
examine screen. Tightened up lines a bit.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2981 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/decks.cc | 47 | ||||
-rw-r--r-- | crawl-ref/source/decks.h | 2 | ||||
-rw-r--r-- | crawl-ref/source/describe.cc | 18 | ||||
-rw-r--r-- | crawl-ref/source/itemname.cc | 11 |
4 files changed, 58 insertions, 20 deletions
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc index 255f8c4bff..47bedbb8fb 100644 --- a/crawl-ref/source/decks.cc +++ b/crawl-ref/source/decks.cc @@ -56,11 +56,13 @@ // 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, -// 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 -// brownie points from it again. +// card), deck.props["drawn_cards"] holds the list of drawn cards +// (with index 0 being the first drawn), 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 brownie points from +// it again. // // The card type and per-card flags are each stored as unsigned bytes, // for a maximum of 256 different kinds of cards and 8 bits of flags. @@ -240,7 +242,7 @@ static void set_card_and_flags(item_def& deck, int idx, card_type card, CrawlVector &flags = props["card_flags"]; if (idx == -1) - idx = (int) cards.size() - 1; + idx = static_cast<int>(cards.size()) - 1; cards[idx] = (char) card; flags[idx] = (char) _flags; @@ -437,6 +439,30 @@ static bool wielding_deck() return is_deck(you.inv[you.equip[EQ_WEAPON]]); } +static void remember_drawn_card(item_def& deck, card_type card) +{ + ASSERT( is_deck(deck) ); + CrawlHashTable &props = deck.props; + CrawlVector &drawn = props["drawn_cards"].get_vector(); + drawn.push_back( static_cast<char>(card) ); +} + +const std::vector<card_type> get_drawn_cards(const item_def& deck) +{ + std::vector<card_type> result; + if ( is_deck(deck) ) + { + const CrawlHashTable &props = deck.props; + const CrawlVector &drawn = props["drawn_cards"].get_vector(); + for ( unsigned int i = 0; i < drawn.size(); ++i ) + { + const char tmp = drawn[i]; + result.push_back(static_cast<card_type>(tmp)); + } + } + return result; +} + static bool check_buggy_deck(item_def& deck) { std::ostream& strm = msg::streams(MSGCH_DIAGNOSTICS); @@ -1085,6 +1111,8 @@ bool deck_triple_draw() // Note how many cards were removed from the deck. deck.plus2 += num_to_draw; + for ( int i = 0; i < num_to_draw; ++i ) + remember_drawn_card(deck, draws[i]); you.wield_change = true; // Make deck disappear *before* the card effect, since we @@ -1156,11 +1184,6 @@ static int xom_check_card(item_def &deck, card_type card, return amusement; } -// In general, if the next cards in a deck are known, they will -// be stored in plus2 (the next card) and special (up to 4 cards -// after that, bitpacked.) -// Hidden assumption: no more than 126 cards, otherwise the 5th -// card could clobber the sign bit in special. void evoke_deck( item_def& deck ) { if (check_buggy_deck(deck)) @@ -1183,6 +1206,7 @@ void evoke_deck( item_def& deck ) props["non_brownie_draws"]--; deck.plus2++; + remember_drawn_card(deck, card); // Get rid of the deck *before* the card effect because a card // might cause a wielded deck to be swapped out for something else, @@ -2646,6 +2670,7 @@ void init_deck(item_def &item) props["cards"].new_vector(SV_BYTE).resize(item.plus); props["card_flags"].new_vector(SV_BYTE).resize(item.plus); + props["cards_drawn"].new_vector(SV_BYTE); for (int i = 0; i < item.plus; i++) { diff --git a/crawl-ref/source/decks.h b/crawl-ref/source/decks.h index ac1a3b863b..4846db677e 100644 --- a/crawl-ref/source/decks.h +++ b/crawl-ref/source/decks.h @@ -146,4 +146,6 @@ int cards_in_deck(const item_def &deck); card_type get_card_and_flags(const item_def& deck, int idx, unsigned char& _flags); +const std::vector<card_type> get_drawn_cards(const item_def& deck); + #endif diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index e0a1b4b1d8..ea37a0c283 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -3171,6 +3171,19 @@ static std::string describe_misc_item( const item_def &item ) if ( is_deck(item) ) { + const std::vector<card_type> drawn_cards = get_drawn_cards(item); + if ( !drawn_cards.empty() ) + { + description += "Drawn card(s): "; + for ( unsigned int i = 0; i < drawn_cards.size(); ++i ) + { + if ( i != 0 ) + description += ", "; + description += card_name(drawn_cards[i]); + } + description += "$"; + } + const int num_cards = cards_in_deck(item); if ( top_card_is_known(item) ) { @@ -3188,6 +3201,7 @@ static std::string describe_misc_item( const item_def &item ) else break; } + description += "$"; } std::vector<card_type> seen_cards; @@ -3203,15 +3217,15 @@ static std::string describe_misc_item( const item_def &item ) { std::sort(seen_cards.begin(), seen_cards.end(), compare_card_names); - description += "$Seen cards: "; + description += "Seen card(s): "; for ( unsigned int i = 0; i < seen_cards.size(); ++i ) { if ( i != 0 ) description += ", "; description += card_name(seen_cards[i]); } + description += "$"; } - description += "$"; } return (description); diff --git a/crawl-ref/source/itemname.cc b/crawl-ref/source/itemname.cc index 08b505f846..0e25c80fde 100644 --- a/crawl-ref/source/itemname.cc +++ b/crawl-ref/source/itemname.cc @@ -1425,15 +1425,12 @@ std::string item_def::name_aux( description_level_type desc, if(top_card_is_known(*this)) buff << ", "; - buff << abs(this->plus2) << " card"; - - if (abs(this->plus2) > 1) - buff << "s"; - if (this->plus2 > 0) - buff << " drawn"; + buff << "drawn: "; else - buff << " left"; + buff << "left: "; + + buff << abs(this->plus2); } buff << "}"; |