|
From: <gi...@cr...> - 2013-09-30 03:35:09
|
via d5eeb803e6b36a8e0c8102ddc2cc28d8f772b73c (commit)
from 4236123ae6e15c538fb1e9855986d7c035016ff2 (commit)
-----------------------------------------------------------------------
commit d5eeb803e6b36a8e0c8102ddc2cc28d8f772b73c
Author: Neil Moore <ne...@s-...>
Date: Sun Sep 29 22:52:04 2013 -0400
Constify, simplify, fix some types, and reformat.
-----------------------------------------------------------------------
Summary of changes:
crawl-ref/source/describe.cc | 104 ++++++++++++++++++++----------------------
1 files changed, 50 insertions(+), 54 deletions(-)
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index ee687b5..4235d08 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -324,7 +324,7 @@ static vector<string> _randart_propnames(const item_def& item,
break;
case 1: // e.g. F++
{
- int sval = min(abs(val), 3);
+ const int sval = min(abs(val), 3);
work << propanns[i].name
<< string(sval, (val > 0 ? '+' : '-'));
break;
@@ -800,11 +800,9 @@ static string _describe_weapon(const item_def &item, bool verbose)
append_weapon_stats(description, item);
}
- int spec_ench = get_weapon_brand(item);
- int damtype = get_vorpal_type(item);
-
- if (!is_artefact(item) && !verbose)
- spec_ench = SPWPN_NORMAL;
+ const int spec_ench = (is_artefact(item) || verbose)
+ ? get_weapon_brand(item) : SPWPN_NORMAL;
+ const int damtype = get_vorpal_type(item);
if (verbose)
{
@@ -1093,8 +1091,8 @@ static string _describe_ammo(const item_def &item)
}
}
- bool can_launch = has_launcher(item);
- bool can_throw = is_throwable(&you, item, true);
+ const bool can_launch = has_launcher(item);
+ const bool can_throw = is_throwable(&you, item, true);
bool need_new_line = true;
bool always_destroyed = false;
@@ -1707,23 +1705,19 @@ void append_spells(string &desc, const item_def &item)
bool is_dumpable_artefact(const item_def &item, bool verbose)
{
- bool ret = false;
-
if (is_known_artefact(item))
- ret = item_ident(item, ISFLAG_KNOW_PROPERTIES);
- else if (verbose && item.base_type == OBJ_ARMOUR
- && item_type_known(item))
+ return item_ident(item, ISFLAG_KNOW_PROPERTIES);
+ else if (!verbose || !item_type_known(item))
+ return false;
+ else if (item.base_type == OBJ_ARMOUR)
{
const int spec_ench = get_armour_ego_type(item);
- ret = (spec_ench >= SPARM_RUNNING && spec_ench <= SPARM_PRESERVATION);
- }
- else if (verbose && item.base_type == OBJ_JEWELLERY
- && item_type_known(item))
- {
- ret = true;
+ return (spec_ench >= SPARM_RUNNING && spec_ench <= SPARM_PRESERVATION);
}
+ else if (item.base_type == OBJ_JEWELLERY)
+ return true;
- return ret;
+ return false;
}
@@ -2299,7 +2293,7 @@ static void _show_item_description(const item_def &item)
string desc = get_item_description(item, true, false,
crawl_state.game_is_hints_tutorial());
- int num_lines = count_desc_lines(desc, lineWidth) + 1;
+ const int num_lines = count_desc_lines(desc, lineWidth) + 1;
// XXX: hack: Leave room for "Inscribe item?" and the blank line above
// it by removing item quote. This should really be taken care of
@@ -2318,7 +2312,7 @@ static void _show_item_description(const item_def &item)
static bool _describe_spells(const item_def &item)
{
- int c = getchm();
+ const int c = getchm();
if (c < 'a' || c > 'h') //jmf: was 'g', but 8=h
{
mesclr();
@@ -2327,8 +2321,7 @@ static bool _describe_spells(const item_def &item)
const int spell_index = letter_to_index(c);
- spell_type nthing =
- which_spell_in_book(item, spell_index);
+ const spell_type nthing = which_spell_in_book(item, spell_index);
if (nthing == SPELL_NO_SPELL)
return false;
@@ -2572,7 +2565,7 @@ static bool _actions_prompt(item_def &item, bool allow_inscribe)
}
#endif
- int slot = item.link;
+ const int slot = item.link;
ASSERT_RANGE(slot, 0, ENDOFPACK);
switch (action)
@@ -2758,12 +2751,12 @@ static void _adjust_item(item_def &item)
_safe_newline();
string prompt = "<cyan>Adjust to which letter? </cyan>";
formatted_string::parse_string(prompt).display();
- int keyin = getch_ck();
+ const int keyin = getch_ck();
if (isaalpha(keyin))
{
- int a = letter_to_index(item.slot);
- int b = letter_to_index(keyin);
+ const int a = letter_to_index(item.slot);
+ const int b = letter_to_index(keyin);
swap_inv_slots(a,b,true);
}
}
@@ -2835,7 +2828,7 @@ static int _get_spell_description(const spell_type spell,
+ " creatures summoned by this spell.";
}
- bool rod = item && item->base_type == OBJ_RODS;
+ const bool rod = item && item->base_type == OBJ_RODS;
if (god_hates_spell(spell, you.religion, rod))
{
@@ -2912,7 +2905,7 @@ void describe_spell(spell_type spelled, const item_def* item)
#endif
string desc;
- int mem_or_forget = _get_spell_description(spelled, desc, item);
+ const int mem_or_forget = _get_spell_description(spelled, desc, item);
print_description(desc);
mouse_control mc(MOUSE_MODE_MORE);
@@ -3043,7 +3036,8 @@ static string _describe_chimera(const monster_info& mi)
if (part2 == mi.base_type)
{
description += "another ";
- description += apply_description(DESC_PLAIN, get_monster_data(part2)->name);
+ description += apply_description(DESC_PLAIN,
+ get_monster_data(part2)->name);
}
else
description += apply_description(DESC_A, get_monster_data(part2)->name);
@@ -3055,24 +3049,29 @@ static string _describe_chimera(const monster_info& mi)
if (part2 == mi.base_type)
description += "yet ";
description += "another ";
- description += apply_description(DESC_PLAIN, get_monster_data(part3)->name);
+ description += apply_description(DESC_PLAIN,
+ get_monster_data(part3)->name);
}
else
description += apply_description(DESC_A, get_monster_data(part3)->name);
description += ". It has the body of ";
- description += apply_description(DESC_A, get_monster_data(mi.base_type)->name);
+ description += apply_description(DESC_A,
+ get_monster_data(mi.base_type)->name);
- bool has_wings = mi.props.exists("chimera_batty") || mi.props.exists("chimera_wings");
+ const bool has_wings = mi.props.exists("chimera_batty")
+ || mi.props.exists("chimera_wings");
if (mi.props.exists("chimera_legs"))
{
- monster_type leggy_part = get_chimera_part(&mi, mi.props["chimera_legs"].get_int());
+ const monster_type leggy_part =
+ get_chimera_part(&mi, mi.props["chimera_legs"].get_int());
if (has_wings)
description += ", ";
else
description += ", and ";
description += "the legs of ";
- description += apply_description(DESC_A, get_monster_data(leggy_part)->name);
+ description += apply_description(DESC_A,
+ get_monster_data(leggy_part)->name);
}
if (has_wings)
@@ -3093,7 +3092,8 @@ static string _describe_chimera(const monster_info& mi)
description += " and it moves like "; // Unseen horrors
break;
}
- description += apply_description(DESC_A, get_monster_data(wing_part)->name);
+ description += apply_description(DESC_A,
+ get_monster_data(wing_part)->name);
}
description += ".";
return description;
@@ -3156,13 +3156,13 @@ static string _monster_spells_description(const monster_info& mi)
const monsterentry *m = get_monster_data(mi.type);
mon_spellbook_type book = (m->sec);
- vector<mon_spellbook_type> books = mons_spellbook_list(mi.type);
-
+ const vector<mon_spellbook_type> books = mons_spellbook_list(mi.type);
+ const size_t num_books = books.size();
// If there are really really no spells, print nothing. Ghosts,
// player illusions, and random pan lords don't have consistent
// spell lists, and might not even have spells; omit them as well.
- if (books.size() == 0 || books[0] == MST_NO_SPELLS || book == MST_GHOST)
+ if (num_books == 0 || books[0] == MST_NO_SPELLS || book == MST_GHOST)
return "";
ostringstream result;
@@ -3186,8 +3186,7 @@ static string _monster_spells_description(const monster_info& mi)
}
// Loop through books and display spells/abilities for each of them
- int num_books = books.size();
- for (int i = 0; i < num_books; ++i)
+ for (size_t i = 0; i < num_books; ++i)
{
// Create spell list containing no duplicate/irrelevant entries
book = books[i];
@@ -3213,7 +3212,7 @@ static string _monster_spells_description(const monster_info& mi)
if (num_books > 1)
result << (caster ? " Book " : " Set ") << i+1 << ": ";
- for (unsigned int j = 0; j < book_spells.size(); ++j)
+ for (size_t j = 0; j < book_spells.size(); ++j)
{
const spell_type spell = book_spells[j];
if (j > 0)
@@ -3326,7 +3325,7 @@ static string _monster_stat_description(const monster_info& mi)
<< ".\n";
}
- int mr = mi.res_magic();
+ const int mr = mi.res_magic();
// How resistant is it? Same scale as the player.
if (mr >= 10)
{
@@ -3891,10 +3890,9 @@ static bool _print_final_god_abil_desc(int god, const string &final_msg,
{
// XXX: Handle the display better when the description and cost
// are too long for the screen.
- int spacesleft =
+ const int spacesleft =
get_number_of_cols() - 1 - strwidth(buf) - strwidth(cost);
- for (; spacesleft > 0; --spacesleft)
- buf += ' ';
+ buf += string(spacesleft, ' ');
buf += cost;
}
@@ -3987,7 +3985,7 @@ static string _religion_help(god_type god)
case GOD_SHINING_ONE:
{
- int halo_size = you.halo_radius2();
+ const int halo_size = you.halo_radius2();
if (halo_size >= 0)
{
if (!result.empty())
@@ -4218,7 +4216,7 @@ static string _describe_ash_skill_boost()
string skills;
map<skill_type, int8_t> boosted_skills = ash_get_boosted_skills(eq_type(i));
- int8_t bonus = boosted_skills.begin()->second;
+ const int8_t bonus = boosted_skills.begin()->second;
map<skill_type, int8_t>::iterator it = boosted_skills.begin();
// First, we keep only one magic school skill (conjuration).
@@ -4267,8 +4265,8 @@ static void _detailed_god_description(god_type which_god)
const int width = min(80, get_number_of_cols());
- string godname = uppercase_first(god_name(which_god, true));
- int len = get_number_of_cols() - strwidth(godname);
+ const string godname = uppercase_first(god_name(which_god, true));
+ const int len = get_number_of_cols() - strwidth(godname);
textcolor(god_colour(which_god));
cprintf("%s%s\n", string(len / 2, ' ').c_str(), godname.c_str());
textcolor(LIGHTGREY);
@@ -4691,9 +4689,7 @@ void describe_god(god_type which_god, bool give_title)
cprintf("None.\n");
}
- int bottom_line = get_number_of_lines();
- if (bottom_line > 30)
- bottom_line = 30;
+ const int bottom_line = min(30, get_number_of_lines());
// Only give this additional information for worshippers.
if (which_god == you.religion)
--
Dungeon Crawl Stone Soup
|