summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-25 17:57:03 +0000
committerharanp <haranp@c06c8d41-db1a-0410-9941-cceddc491573>2009-01-25 17:57:03 +0000
commitf24dd0d78e1448c19a53aa23c8e136138e3c2a74 (patch)
tree591987c9f14dcb2e90787f4b507f61b9dad1a14f /crawl-ref
parentd54f454b7fc085b792e569ed131bc7be460768f7 (diff)
downloadcrawl-ref-f24dd0d78e1448c19a53aa23c8e136138e3c2a74.tar.gz
crawl-ref-f24dd0d78e1448c19a53aa23c8e136138e3c2a74.zip
Code quality fixes.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8742 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/source/command.cc3
-rw-r--r--crawl-ref/source/debug.cc9
-rw-r--r--crawl-ref/source/decks.cc5
-rw-r--r--crawl-ref/source/directn.cc6
-rw-r--r--crawl-ref/source/hiscores.cc6
-rw-r--r--crawl-ref/source/mon-util.cc13
-rw-r--r--crawl-ref/source/shopping.cc66
7 files changed, 44 insertions, 64 deletions
diff --git a/crawl-ref/source/command.cc b/crawl-ref/source/command.cc
index 96c9b25c3c..b5fcc0fa4a 100644
--- a/crawl-ref/source/command.cc
+++ b/crawl-ref/source/command.cc
@@ -1013,10 +1013,9 @@ static std::vector<std::string> _get_god_keys()
{
std::vector<std::string> names;
- for (int i = ((int) GOD_NO_GOD) + 1; i < NUM_GODS; i++)
+ for (int i = GOD_NO_GOD + 1; i < NUM_GODS; i++)
{
god_type which_god = static_cast<god_type>(i);
-
names.push_back(god_name(which_god));
}
diff --git a/crawl-ref/source/debug.cc b/crawl-ref/source/debug.cc
index 6b3c1b91b8..9b83b3f748 100644
--- a/crawl-ref/source/debug.cc
+++ b/crawl-ref/source/debug.cc
@@ -973,7 +973,7 @@ static void _rune_from_specs(const char* _specs, item_def &item)
NUM_RUNE_TYPES
};
- item.plus = static_cast<int>(types[keyin - 'a']);
+ item.plus = types[keyin - 'a'];
return;
}
@@ -1109,9 +1109,8 @@ static void _deck_from_specs(const char* _specs, item_def &item)
}
}
- int base = static_cast<int>(DECK_RARITY_COMMON);
- deck_rarity_type rarity =
- static_cast<deck_rarity_type>(base + rarity_val);
+ const deck_rarity_type rarity =
+ static_cast<deck_rarity_type>(DECK_RARITY_COMMON + rarity_val);
item.special = rarity;
int num = _debug_prompt_for_int("How many cards? ", false);
@@ -5298,7 +5297,7 @@ void debug_pathfind(int mid)
if (success)
{
std::vector<coord_def> path = mp.backtrack();
- std::string path_str = "";
+ std::string path_str;
mpr("Here's the shortest path: ");
for (unsigned int i = 0; i < path.size(); i++)
{
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index cfa3527d62..a8a95a2441 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -195,7 +195,7 @@ int cards_in_deck(const item_def &deck)
const CrawlHashTable &props = deck.props;
ASSERT(props.exists("cards"));
- return static_cast<unsigned long>(props["cards"].get_vector().size());
+ return (props["cards"].get_vector().size());
}
static void _shuffle_deck(item_def &deck)
@@ -1813,8 +1813,7 @@ static bool _damaging_card(card_type card, int power, deck_rarity_type rarity)
}
snprintf(info, INFO_SIZE, "You have drawn %s. Aim where? ",
- card_name(card));
-
+ card_name(card));
bolt beam;
beam.range = LOS_RADIUS;
diff --git a/crawl-ref/source/directn.cc b/crawl-ref/source/directn.cc
index d4635d0959..dc6584537b 100644
--- a/crawl-ref/source/directn.cc
+++ b/crawl-ref/source/directn.cc
@@ -684,11 +684,11 @@ static void _fill_monster_list(bool full_info)
// Get the unique entries.
mlist.clear();
- int start = 0, end = 1;
- while (start < (int) temp.size())
+ unsigned int start = 0, end = 1;
+ while (start < temp.size())
{
mlist.push_back(temp[start]);
- for (end = start + 1; end < (int) temp.size(); ++end)
+ for (end = start + 1; end < temp.size(); ++end)
{
if (monster_pane_info::less_than(temp[start], temp[end],
full_info))
diff --git a/crawl-ref/source/hiscores.cc b/crawl-ref/source/hiscores.cc
index 57a381ab11..074b5e8e89 100644
--- a/crawl-ref/source/hiscores.cc
+++ b/crawl-ref/source/hiscores.cc
@@ -432,8 +432,7 @@ static const char *kill_method_names[] =
const char *kill_method_name(kill_method_type kmt)
{
- ASSERT(NUM_KILLBY ==
- (int) sizeof(kill_method_names) / sizeof(*kill_method_names));
+ ASSERT(NUM_KILLBY == ARRAYSZ(kill_method_names));
if (kmt == NUM_KILLBY)
return ("");
@@ -443,8 +442,7 @@ const char *kill_method_name(kill_method_type kmt)
kill_method_type str_to_kill_method(const std::string &s)
{
- ASSERT(NUM_KILLBY ==
- (int) sizeof(kill_method_names) / sizeof(*kill_method_names));
+ ASSERT(NUM_KILLBY == ARRAYSZ(kill_method_names));
for (int i = 0; i < NUM_KILLBY; ++i)
{
diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc
index d5d9a49b3f..0367f124c2 100644
--- a/crawl-ref/source/mon-util.cc
+++ b/crawl-ref/source/mon-util.cc
@@ -2118,16 +2118,9 @@ static std::string _str_monam(const monsters& mon, description_level_type desc,
if (mon.number < 11)
{
- result += (mon.number == 1) ? "one" :
- (mon.number == 2) ? "two" :
- (mon.number == 3) ? "three" :
- (mon.number == 4) ? "four" :
- (mon.number == 5) ? "five" :
- (mon.number == 6) ? "six" :
- (mon.number == 7) ? "seven" :
- (mon.number == 8) ? "eight" :
- (mon.number == 9) ? "nine"
- : "ten";
+ const char* cardinals[] = {"one", "two", "three", "four", "five",
+ "six", "seven", "eight", "nine", "ten"};
+ result += cardinals[mon.number - 1];
}
else
{
diff --git a/crawl-ref/source/shopping.cc b/crawl-ref/source/shopping.cc
index 7c82c806cd..3a10ca6ea8 100644
--- a/crawl-ref/source/shopping.cc
+++ b/crawl-ref/source/shopping.cc
@@ -77,7 +77,7 @@ static std::string _purchase_keys(const std::string &s)
std::string list = "<w>" + s.substr(0, 1);
char last = s[0];
- for (int i = 1; i < (int) s.length(); ++i)
+ for (unsigned int i = 1; i < s.length(); ++i)
{
if (s[i] == s[i - 1] + 1)
continue;
@@ -121,14 +121,10 @@ static void _list_shop_keys(const std::string &purchasable)
static std::vector<int> _shop_get_stock(int shopidx)
{
std::vector<int> result;
-
- int itty = igrd[0][5 + shopidx];
-
- while ( itty != NON_ITEM )
- {
- result.push_back( itty );
- itty = mitm[itty].link;
- }
+ // Shop items are heaped up at this cell.
+ const coord_def stack_location(0, 5 + shopidx);
+ for (stack_iterator si(stack_location); si; ++si)
+ result.push_back(si.link());
return result;
}
@@ -157,8 +153,8 @@ static std::string _shop_print_stock( const std::vector<int>& stock,
std::string purchasable;
for (unsigned int i = 0; i < stock.size(); ++i)
{
- const int gp_value = _shop_get_item_value(mitm[stock[i]], shop.greed,
- id);
+ const item_def& item = mitm[stock[i]];
+ const int gp_value = _shop_get_item_value(item, shop.greed, id);
const bool can_afford = (you.gold >= gp_value);
cgotoxy(1, i+1, GOTO_CRT);
@@ -193,8 +189,8 @@ static std::string _shop_print_stock( const std::vector<int>& stock,
if (Options.menu_colour_shops)
{
// Colour stock according to menu colours.
- const std::string colprf = menu_colour_item_prefix(mitm[stock[i]]);
- const int col = menu_colour(mitm[stock[i]].name(DESC_NOCAP_A),
+ const std::string colprf = menu_colour_item_prefix(item);
+ const int col = menu_colour(item.name(DESC_NOCAP_A),
colprf, "shop");
textcolor(col != -1 ? col : LIGHTGREY);
}
@@ -202,11 +198,10 @@ static std::string _shop_print_stock( const std::vector<int>& stock,
textcolor(i % 2 ? LIGHTGREY : WHITE);
cprintf("%-56s%5d gold",
- mitm[stock[i]].name(DESC_NOCAP_A, false, id).substr(0, 56).
- c_str(),
+ item.name(DESC_NOCAP_A, false, id).substr(0, 56).c_str(),
gp_value);
- si.add_item(mitm[stock[i]], gp_value);
+ si.add_item(item, gp_value);
}
textcolor(LIGHTGREY);
@@ -252,14 +247,13 @@ static bool _in_a_shop( int shopidx )
StashTrack.get_shop(shop.pos).reset();
std::vector<int> stock = _shop_get_stock(shopidx);
- for (unsigned int k = 0; k < stock.size(); k++)
+
+ // Autoinscribe randarts in the shop.
+ for (unsigned int i = 0; i < stock.size(); i++)
{
- if (Options.autoinscribe_randarts
- && is_random_artefact(mitm[stock[k]]))
- {
- mitm[stock[k]].inscription =
- randart_auto_inscription(mitm[stock[k]]);
- }
+ item_def& item = mitm[stock[i]];
+ if (Options.autoinscribe_randarts && is_random_artefact(item))
+ item.inscription = randart_auto_inscription(item);
}
// Deselect all.
@@ -342,7 +336,8 @@ static bool _in_a_shop( int shopidx )
// Do purchase.
if (total_cost > you.gold)
{
- _shop_print("I'm sorry, you don't seem to have enough money.", 1);
+ _shop_print("I'm sorry, you don't seem to have enough money.",
+ 1);
_shop_more();
}
else if (!total_cost)
@@ -1773,15 +1768,13 @@ shop_struct *get_shop(const coord_def& where)
if (grd(where) != DNGN_ENTER_SHOP)
return (NULL);
- // Find shop.
- for (int shoppy = 0; shoppy < MAX_SHOPS; shoppy ++)
+ // Check all shops for one at the correct position.
+ for (int i = 0; i < MAX_SHOPS; i ++)
{
- // Find shop index plus a little bit of paranoia.
- if (env.shop[shoppy].pos == where
- && env.shop[shoppy].type != SHOP_UNASSIGNED)
- {
- return (&env.shop[shoppy]);
- }
+ shop_struct& shop = env.shop[i];
+ // A little bit of paranoia.
+ if (shop.pos == where && shop.type != SHOP_UNASSIGNED)
+ return (&shop);
}
return (NULL);
}
@@ -1838,11 +1831,10 @@ std::string shop_name(const coord_def& where)
if (shop_type != SHOP_GENERAL
&& shop_type != SHOP_GENERAL_ANTIQUE && shop_type != SHOP_DISTILLERY)
{
- int temp = where.x + where.y % 4;
- sh_name += (temp == 0) ? " Shoppe" :
- (temp == 1) ? " Boutique" :
- (temp == 2) ? " Emporium"
- : " Shop";
+ const char* suffixnames[] = {"Shoppe", "Boutique", "Emporium", "Shop"};
+ const int temp = where.x + where.y % 4;
+ sh_name += ' ';
+ sh_name += suffixnames[temp];
}
return (sh_name);