summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-23 21:14:20 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2007-10-23 21:14:20 +0000
commit11adfeb2d7e54e3a43e518785c4d34cb3d4e8df1 (patch)
tree3ac81c28321340b54afd099f219caf7ea58be6ab /crawl-ref
parentd01f16731de6b52c31bf8c600ccdbca515b960d7 (diff)
downloadcrawl-ref-11adfeb2d7e54e3a43e518785c4d34cb3d4e8df1.tar.gz
crawl-ref-11adfeb2d7e54e3a43e518785c4d34cb3d4e8df1.zip
Some code cleanup.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@2524 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/decks.cc121
-rw-r--r--crawl-ref/source/religion.cc174
-rw-r--r--crawl-ref/source/state.cc4
-rw-r--r--crawl-ref/source/store.h42
4 files changed, 176 insertions, 165 deletions
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index 1a05dea1ad..ee8d342add 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -58,7 +58,7 @@
// brownie points from it again.
//
// The card type and per-card flags are each stored as unsigned bytes,
-// for a maximum of 256 differetn kinds of cards and 8 bits of flags.
+// for a maximum of 256 different kinds of cards and 8 bits of flags.
#define VECFROM(x) (x), (x) + ARRAYSIZE(x)
#define DEFVEC(Z) static std::vector<card_type> Z(VECFROM(a_##Z))
@@ -144,7 +144,7 @@ static unsigned long cards_in_deck(const item_def &deck)
const CrawlHashTable &props = deck.props;
ASSERT(props.exists("cards"));
- return (unsigned long) props["cards"].get_vector().size();
+ return static_cast<unsigned long>(props["cards"].get_vector().size());
}
static void shuffle_deck(item_def &deck)
@@ -410,11 +410,11 @@ static bool wielding_deck()
static bool check_buggy_deck(item_def& deck)
{
+ std::ostream& strm = msg::streams(MSGCH_DIAGNOSTICS);
if (!is_deck(deck))
{
crawl_state.zero_turns_taken();
-
- mpr("This isn't a deck at all!");
+ strm << "This isn't a deck at all!" << std::endl;
return true;
}
@@ -428,18 +428,17 @@ static bool check_buggy_deck(item_def& deck)
crawl_state.zero_turns_taken();
if (!props.exists("cards"))
- msg::stream << "Seems this deck never had any cards in the "
- "first place!";
+ strm << "Seems this deck never had any cards in the first place!";
else if (props["cards"].get_type() != SV_VEC)
- msg::stream << "'cards' property isn't a vector.";
+ strm << "'cards' property isn't a vector.";
else
{
if (props["cards"].get_vector().get_type() != SV_BYTE)
- msg::stream << "'cards' vector doesn't contain bytes. ";
+ strm << "'cards' vector doesn't contain bytes.";
if (cards_in_deck(deck) == 0)
{
- msg::stream << "Strange, this deck is already empty.";
+ strm << "Strange, this deck is already empty.";
int cards_left = 0;
if (deck.plus2 >= 0)
@@ -449,16 +448,15 @@ static bool check_buggy_deck(item_def& deck)
if (cards_left != 0)
{
- msg::stream << " But there should be been ";
- msg::stream << cards_left;
- msg::stream << " cards left.";
+ strm << " But there should be been " << cards_left
+ << " cards left.";
}
}
}
- msg::stream << std::endl;
-
- mpr("A swarm of software bugs snatches the deck from you and "
- "whisk it away.");
+ strm << std::endl
+ << "A swarm of software bugs snatches the deck from you "
+ "and whisks it away."
+ << std::endl;
if ( deck.link == you.equip[EQ_WEAPON] )
unwield_item();
@@ -501,8 +499,8 @@ static bool check_buggy_deck(item_def& deck)
if (num_buggy > 0)
{
- mprf("%d buggy cards found in the deck, discarding them.",
- num_buggy);
+ strm << num_buggy << " buggy cards found in the deck, discarding them."
+ << std::endl;
deck.plus2 += num_buggy;
@@ -512,13 +510,13 @@ static bool check_buggy_deck(item_def& deck)
problems = true;
}
- if (num_cards <= 0)
+ if (num_cards == 0)
{
crawl_state.zero_turns_taken();
- mpr("Oops, all of the cards seem to be gone.");
- mpr("A swarm of software bugs snatches the deck from you and "
- "whisk it away.");
+ strm << "Oops, all of the cards seem to be gone." << std::endl
+ << "A swarm of software bugs snatches the deck from you "
+ "and whisks it away." << std::endl;
if ( deck.link == you.equip[EQ_WEAPON] )
unwield_item();
@@ -529,14 +527,15 @@ static bool check_buggy_deck(item_def& deck)
return true;
}
- if ((long) num_cards > deck.plus)
+ if (static_cast<long>(num_cards) > deck.plus)
{
if (deck.plus == 0)
- mpr("Deck was created with zero cards???");
+ strm << "Deck was created with zero cards???" << std::endl;
else if (deck.plus < 0)
- mpr("Deck was created with *negative* cards?!");
+ strm << "Deck was created with *negative* cards?!" << std::endl;
else
- mpr("Deck has more cards than it was created with?");
+ strm << "Deck has more cards than it was created with?"
+ << std::endl;
deck.plus = num_cards;
problems = true;
@@ -545,70 +544,79 @@ static bool check_buggy_deck(item_def& deck)
if (num_cards > num_flags)
{
#ifdef WIZARD
- mprf("%d more cards than flags.", num_cards - num_flags);
+ strm << (num_cards - num_flags) << " more cards than flags.";
#else
- mpr("More cards than flags.");
+ strm << "More cards than flags.";
#endif
+ strm << std::endl;
for (unsigned int i = num_flags + 1; i <= num_cards; i++)
- flags[i] = (char) 0;
+ flags[i] = static_cast<char>(0);
problems = true;
}
else if (num_flags > num_cards)
{
#ifdef WIZARD
- mprf("%d more flags than cards.", num_flags - num_cards);
+ strm << (num_cards - num_flags) << " more cards than flags.";
#else
- mpr("More flags than cards.");
+ strm << "More cards than flags.";
#endif
+ strm << std::endl;
+
for (unsigned int i = num_flags; i > num_cards; i--)
flags.erase(i);
problems = true;
}
- if (props["num_marked"].get_byte() > (char) num_cards)
+ if (props["num_marked"].get_byte() > static_cast<char>(num_cards))
{
- mpr("More cards marked than in the deck?");
- props["num_marked"] = (char) num_marked;
+ strm << "More cards marked than in the deck?" << std::endl;
+ props["num_marked"] = static_cast<char>(num_marked);
problems = true;
}
- else if (props["num_marked"].get_byte() != (char) num_marked)
+ else if (props["num_marked"].get_byte() != static_cast<char>(num_marked))
{
#ifdef WIZARD
- mprf("Oops, counted %d marked cards, but num_marked is %d.",
- (int) num_marked, (int) props["num_marked"].get_byte());
+
+ strm << "Oops, counted " << static_cast<int>(num_marked)
+ << " marked cards, but num_marked is "
+ << (static_cast<int>(props["num_marked"].get_byte()));
#else
- mpr("Oops, book-keeping on marked cards is wrong.");
+ strm << "Oops, book-keeping on marked cards is wrong.";
#endif
- props["num_marked"] = (char) num_marked;
+ strm << std::endl;
+
+ props["num_marked"] = static_cast<char>(num_marked);
problems = true;
}
if (deck.plus2 >= 0)
{
- if (deck.plus != (deck.plus2 + (long) num_cards))
+ if (deck.plus != (deck.plus2 + static_cast<long>(num_cards)))
{
#ifdef WIZARD
- mprf("Have you used %d cards, or %d? Oops.",
- deck.plus2, deck.plus - num_cards);
+ strm << "Have you used " << deck.plus2 << " cards, or "
+ << (deck.plus - num_cards) << "? Oops.";
#else
- mpr("Oops, book-keeping on used cards is wrong.");
+ strm << "Oops, book-keeping on used cards is wrong.";
#endif
+ strm << std::endl;
deck.plus2 = deck.plus - num_cards;
problems = true;
}
}
else
{
- if (-deck.plus2 != (long) num_cards)
+ if (-deck.plus2 != static_cast<long>(num_cards))
{
#ifdef WIZARD
- mprf("There are %d cards left, not %d. Oops.",
- num_cards, -deck.plus2);
+ strm << "There are " << num_cards << " cards left, not "
+ << (-deck.plus2) << ". Oops.";
#else
- mpr("Oops, book-keeping on cards left is wrong.");
+ strm << "Oops, book-keeping on cards left is wrong.";
#endif
+ strm << std::endl;
deck.plus2 = -num_cards;
problems = true;
}
@@ -748,7 +756,7 @@ bool deck_peek()
deck.props["num_marked"] = (char) 2;
}
- // "Shuffle" the two cards (even if they're teh same, since
+ // "Shuffle" the two cards (even if they're the same, since
// the flags might differ).
if (coinflip())
{
@@ -801,7 +809,7 @@ bool deck_peek()
// Mark a deck: look at the next four cards, mark them, and shuffle
// them back into the deck without losing any cards. The player won't
-// know whate order they're in, and the if the top card is non-marked
+// know what order they're in, and the if the top card is non-marked
// then the player won't know what the next card is.
// Return false if the operation was failed/aborted along the way.
bool deck_mark()
@@ -1481,8 +1489,8 @@ static void elixir_card(int power, deck_rarity_type rarity)
you.hp = you.hp_max;
you.magic_points = you.max_magic_points;
}
- you.redraw_hit_points = 1;
- you.redraw_magic_points = 1;
+ you.redraw_hit_points = true;
+ you.redraw_magic_points = true;
}
static void battle_lust_card(int power, deck_rarity_type rarity)
@@ -1769,7 +1777,7 @@ static void shuffle_card(int power, deck_rarity_type rarity)
cause = "the capriciousness of Xom";
else
{
- cause = "the 'helpfullness' of ";
+ cause = "the 'helpfulness' of ";
cause += god_name(which_god);
}
}
@@ -1816,6 +1824,8 @@ static void helix_card(int power, deck_rarity_type rarity)
}
if ( numfound )
delete_mutation(which_mut);
+ else
+ mpr("You feel transcendent for a moment.");
}
static void dowsing_card(int power, deck_rarity_type rarity)
@@ -2215,7 +2225,7 @@ deck_rarity_type deck_rarity(const item_def &item)
unsigned char deck_rarity_to_color(deck_rarity_type rarity)
{
- switch(rarity)
+ switch (rarity)
{
case DECK_RARITY_COMMON:
{
@@ -2224,10 +2234,7 @@ unsigned char deck_rarity_to_color(deck_rarity_type rarity)
}
case DECK_RARITY_RARE:
- if (coinflip())
- return (MAGENTA);
- else
- return (BROWN);
+ return (coinflip() ? MAGENTA : BROWN);
case DECK_RARITY_LEGENDARY:
return LIGHTMAGENTA;
diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc
index 172160cfe0..2b7ec23128 100644
--- a/crawl-ref/source/religion.cc
+++ b/crawl-ref/source/religion.cc
@@ -553,6 +553,94 @@ static void show_pure_deck_chances()
}
#endif
+static void give_nemelex_gift()
+{
+ if (random2(MAX_PIETY) <= you.piety
+ && one_chance_in(3)
+ && !you.attribute[ATTR_CARD_COUNTDOWN]
+ && !grid_destroys_items(grd[you.x_pos][you.y_pos]))
+ {
+ misc_item_type gift_type;
+ if ( random2(MAX_PIETY) <= you.piety )
+ {
+ // make a pure deck
+ const misc_item_type pure_decks[] = {
+ MISC_DECK_OF_ESCAPE,
+ MISC_DECK_OF_DESTRUCTION,
+ MISC_DECK_OF_DUNGEONS,
+ MISC_DECK_OF_SUMMONING,
+ MISC_DECK_OF_WONDERS
+ };
+ int weights[5];
+ get_pure_deck_weights(weights);
+ gift_type = pure_decks[choose_random_weighted(weights, weights+5)];
+
+#if DEBUG_GIFTS || DEBUG_CARDS
+ show_pure_deck_chances();
+#endif
+ }
+ else
+ {
+ // make a mixed deck
+ const misc_item_type mixed_decks[] = {
+ MISC_DECK_OF_WAR,
+ MISC_DECK_OF_CHANGES,
+ MISC_DECK_OF_DEFENSE
+ };
+ gift_type = RANDOM_ELEMENT(mixed_decks);
+ }
+
+ int thing_created = items( 1, OBJ_MISCELLANY, gift_type,
+ true, 1, MAKE_ITEM_RANDOM_RACE );
+
+ if (thing_created != NON_ITEM)
+ {
+ // Piety|Common | Rare |Legendary
+ // --------------------------------
+ // 0: 95.00%, 5.00%, 0.00%
+ // 20: 86.00%, 10.50%, 3.50%
+ // 40: 77.00%, 16.00%, 7.00%
+ // 60: 68.00%, 21.50%, 10.50%
+ // 80: 59.00%, 27.00%, 14.00%
+ // 100: 50.00%, 32.50%, 17.50%
+ // 120: 41.00%, 38.00%, 21.00%
+ // 140: 32.00%, 43.50%, 24.50%
+ // 160: 23.00%, 49.00%, 28.00%
+ // 180: 14.00%, 54.50%, 31.50%
+ // 200: 5.00%, 60.00%, 35.00%
+ int common_weight = 95 - (90 * you.piety / MAX_PIETY);
+ int rare_weight = 5 + (55 * you.piety / MAX_PIETY);
+ int legend_weight = 0 + (35 * you.piety / MAX_PIETY);
+
+ deck_rarity_type rarity = static_cast<deck_rarity_type>(
+ random_choose_weighted(common_weight,
+ DECK_RARITY_COMMON,
+ rare_weight,
+ DECK_RARITY_RARE,
+ legend_weight,
+ DECK_RARITY_LEGENDARY,
+ 0));
+
+ item_def &deck(mitm[thing_created]);
+
+ deck.special = rarity;
+ deck.colour = deck_rarity_to_color(rarity);
+
+ move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
+ origin_acquired(deck, you.religion);
+
+ simple_god_message(" grants you a gift!");
+ more();
+ canned_msg(MSG_SOMETHING_APPEARS);
+
+ you.attribute[ATTR_CARD_COUNTDOWN] = 10;
+ inc_gift_timeout(5 + random2avg(9, 2));
+ you.num_gifts[you.religion]++;
+ take_note(Note(NOTE_GOD_GIFT, you.religion));
+ }
+ }
+}
+
static void do_god_gift(bool prayed_for)
{
// Zin worshippers are the only ones that can pray to ask Zin for stuff.
@@ -591,91 +679,7 @@ static void do_god_gift(bool prayed_for)
break;
case GOD_NEMELEX_XOBEH:
- if (random2(MAX_PIETY) <= you.piety
- && one_chance_in(3)
- && !you.attribute[ATTR_CARD_COUNTDOWN]
- && !grid_destroys_items(grd[you.x_pos][you.y_pos]))
- {
- misc_item_type gift_type;
- if ( random2(MAX_PIETY) <= you.piety )
- {
- // make a pure deck
- const misc_item_type pure_decks[] = {
- MISC_DECK_OF_ESCAPE,
- MISC_DECK_OF_DESTRUCTION,
- MISC_DECK_OF_DUNGEONS,
- MISC_DECK_OF_SUMMONING,
- MISC_DECK_OF_WONDERS
- };
- int weights[5];
- get_pure_deck_weights(weights);
- gift_type = pure_decks[choose_random_weighted(weights,
- weights+5)];
-
-#if DEBUG_GIFTS || DEBUG_CARDS
- show_pure_deck_chances();
-#endif
- }
- else
- {
- // make a mixed deck
- const misc_item_type mixed_decks[] = {
- MISC_DECK_OF_WAR,
- MISC_DECK_OF_CHANGES,
- MISC_DECK_OF_DEFENSE
- };
- gift_type = RANDOM_ELEMENT(mixed_decks);
- }
-
- int thing_created = items( 1, OBJ_MISCELLANY, gift_type,
- true, 1, MAKE_ITEM_RANDOM_RACE );
-
- if (thing_created != NON_ITEM)
- {
- // Piety|Common | Rare |Legendary
- // --------------------------------
- // 0: 95.00%, 5.00%, 0.00%
- // 20: 86.00%, 10.50%, 3.50%
- // 40: 77.00%, 16.00%, 7.00%
- // 60: 68.00%, 21.50%, 10.50%
- // 80: 59.00%, 27.00%, 14.00%
- // 100: 50.00%, 32.50%, 17.50%
- // 120: 41.00%, 38.00%, 21.00%
- // 140: 32.00%, 43.50%, 24.50%
- // 160: 23.00%, 49.00%, 28.00%
- // 180: 14.00%, 54.50%, 31.50%
- // 200: 5.00%, 60.00%, 35.00%
- int common_weight = 95 - (90 * you.piety / MAX_PIETY);
- int rare_weight = 5 + (55 * you.piety / MAX_PIETY);
- int legend_weight = 0 + (35 * you.piety / MAX_PIETY);
-
- deck_rarity_type rarity = (deck_rarity_type)
- random_choose_weighted(common_weight,
- DECK_RARITY_COMMON,
- rare_weight,
- DECK_RARITY_RARE,
- legend_weight,
- DECK_RARITY_LEGENDARY,
- 0);
-
- item_def &deck(mitm[thing_created]);
-
- deck.special = rarity;
- deck.colour = deck_rarity_to_color(rarity);
-
- move_item_to_grid( &thing_created, you.x_pos, you.y_pos );
- origin_acquired(deck, you.religion);
-
- simple_god_message(" grants you a gift!");
- more();
- canned_msg(MSG_SOMETHING_APPEARS);
-
- you.attribute[ATTR_CARD_COUNTDOWN] = 10;
- inc_gift_timeout(5 + random2avg(9, 2));
- you.num_gifts[you.religion]++;
- take_note(Note(NOTE_GOD_GIFT, you.religion));
- }
- }
+ give_nemelex_gift();
break;
case GOD_OKAWARU:
diff --git a/crawl-ref/source/state.cc b/crawl-ref/source/state.cc
index 2d086dd724..ea89679f12 100644
--- a/crawl-ref/source/state.cc
+++ b/crawl-ref/source/state.cc
@@ -109,8 +109,8 @@ void game_state::cant_cmd_again(std::string reason)
cancel_cmd_again(reason);
}
-// The mehtod is called to prevent the "no repeating zero turns
-// commands" message that input() generates (in the abscence of
+// The method is called to prevent the "no repeating zero turns
+// commands" message that input() generates (in the absence of
// cancelling the repeition) for a repeated command that took no
// turns. A wrapper around cancel_cmd_repeat(), its only purpose it
// to make it clear why cancel_cmd_repeat() is being called.
diff --git a/crawl-ref/source/store.h b/crawl-ref/source/store.h
index b65298b514..434c0cd74d 100644
--- a/crawl-ref/source/store.h
+++ b/crawl-ref/source/store.h
@@ -151,11 +151,11 @@ public:
void set_item(const item_def &val);
public:
- // NOTE: All operators will assert if the alue is of the wrong
+ // NOTE: All operators will assert if the value is of the wrong
// type for the operation. If the value has no type yet, the
// operation will set it to the appropriate type. If the value
// has no type yet and the operation modifies the existing value
- // rather than replacing it (i.e., ++) the value will be set to a
+ // rather than replacing it (e.g., ++) the value will be set to a
// default before the operation is done.
// If the value is a hash table or vector, the container's values
@@ -231,7 +231,7 @@ protected:
// By default a hash table's value data types are heterogeneous. To
// make it homogeneous (which causes dynamic type checking) you have
// to give a type to the hash table constructor; once it's been
-// created it's type (or lack of type) is immutable.
+// created its type (or lack of type) is immutable.
//
// An empty hash table will take up only 1 byte in the savefile. A
// non-empty hash table will have an overhead of 3 bytes for the hash
@@ -268,6 +268,11 @@ public:
bool exists(const std::string key) const;
void assert_validity() const;
+ // NOTE: If the const versions of get_value() or [] are given a
+ // key which doesn't exist, they will assert.
+ const CrawlStoreValue& get_value(const std::string &key) const;
+ const CrawlStoreValue& operator[] (const std::string &key) const;
+
// NOTE: If get_value() or [] is given a key which doesn't exist
// in the table, an unset/empty CrawlStoreValue will be created
// with that key and returned. If it is not then given a value
@@ -278,11 +283,6 @@ public:
CrawlStoreValue& get_value(const std::string &key);
CrawlStoreValue& operator[] (const std::string &key);
- // NOTE: If the const versions of get_value() or [] are given a
- // key which doesn't exist, they will assert.
- const CrawlStoreValue& get_value(const std::string &key) const;
- const CrawlStoreValue& operator[] (const std::string &key) const;
-
// std::map style interface
hash_size size() const;
bool empty() const;
@@ -290,11 +290,11 @@ public:
void erase(const std::string key);
void clear();
- iterator begin();
- iterator end();
-
const_iterator begin() const;
const_iterator end() const;
+
+ iterator begin();
+ iterator end();
};
// A CrawlVector is the vector version of CrawlHashTable, except that
@@ -335,20 +335,20 @@ public:
void set_max_size(vec_size size);
vec_size get_max_size() const;
- CrawlStoreValue& get_value(const vec_size &index);
- CrawlStoreValue& operator[] (const vec_size &index);
-
// NOTE: If the const versions of get_value() or [] are given a
// index which doesn't exist, they will assert.
const CrawlStoreValue& get_value(const vec_size &index) const;
const CrawlStoreValue& operator[] (const vec_size &index) const;
+ CrawlStoreValue& get_value(const vec_size &index);
+ CrawlStoreValue& operator[] (const vec_size &index);
+
// std::vector style interface
vec_size size() const;
bool empty() const;
// NOTE: push_back() and insert() have val passed by value rather
- // than by reference so that coversion constructors will work.
+ // than by reference so that conversion constructors will work.
CrawlStoreValue& pop_back();
void push_back(CrawlStoreValue val);
void insert(const vec_size index, CrawlStoreValue val);
@@ -358,11 +358,11 @@ public:
void erase(const vec_size index);
void clear();
- iterator begin();
- iterator end();
-
const_iterator begin() const;
const_iterator end() const;
+
+ iterator begin();
+ iterator end();
};
// A wrapper for non-heterogeneous hash tables, so that the values can
@@ -384,11 +384,11 @@ public:
void wrap(CrawlHashTable& table);
void wrap(CrawlHashTable* table);
- CrawlHashTable* get_table();
- T& operator[] (const std::string &key);
-
const CrawlHashTable* get_table() const;
const T operator[] (const std::string &key) const;
+
+ CrawlHashTable* get_table();
+ T& operator[] (const std::string &key);
};
typedef CrawlTableWrapper<bool, SV_BOOL> CrawlBoolTable;