summaryrefslogtreecommitdiffstats
path: root/crawl-ref
diff options
context:
space:
mode:
authorHaran Pilpel <haranp@users.sourceforge.net>2010-01-13 10:01:03 +0200
committerHaran Pilpel <haranp@users.sourceforge.net>2010-01-13 10:01:03 +0200
commitcce3c6e018e1ec88a1b49eaf2fbfde88f51ada01 (patch)
treed075743f82d153e2c17f5da43d5e5fb0dffb1636 /crawl-ref
parent253d9973468723045300b5025e2de1e96e350a99 (diff)
downloadcrawl-ref-cce3c6e018e1ec88a1b49eaf2fbfde88f51ada01.tar.gz
crawl-ref-cce3c6e018e1ec88a1b49eaf2fbfde88f51ada01.zip
Various cleanups, use you.weapon() more often, fix a note in README.txt.
Diffstat (limited to 'crawl-ref')
-rw-r--r--crawl-ref/README.txt2
-rw-r--r--crawl-ref/source/abl-show.cc24
-rw-r--r--crawl-ref/source/abl-show.h2
-rw-r--r--crawl-ref/source/decks.cc2
-rw-r--r--crawl-ref/source/describe.cc4
-rw-r--r--crawl-ref/source/effects.cc23
-rw-r--r--crawl-ref/source/fight.cc4
-rw-r--r--crawl-ref/source/food.cc7
-rw-r--r--crawl-ref/source/godabil.cc2
-rw-r--r--crawl-ref/source/it_use3.cc8
-rw-r--r--crawl-ref/source/item_use.cc15
-rw-r--r--crawl-ref/source/wiz-fsim.cc37
12 files changed, 56 insertions, 74 deletions
diff --git a/crawl-ref/README.txt b/crawl-ref/README.txt
index ad4c59b64a..94fc9b6e4e 100644
--- a/crawl-ref/README.txt
+++ b/crawl-ref/README.txt
@@ -159,6 +159,6 @@ patches for bug fixes as well as implementation of new features are very much
welcome. If you want to code a cool feature that is likely to be accepted but
unlikely to be coded by the devteam, search the Feature Requests tracker on
the Sourceforge site for Groups "Patches Welcome".
-Please be sure to read docs/coding_conventions.txt first.
+Please be sure to read docs/develop/coding_conventions.txt first.
Thank you, and have fun crawling!
diff --git a/crawl-ref/source/abl-show.cc b/crawl-ref/source/abl-show.cc
index 66c878dcb3..27d7c0522c 100644
--- a/crawl-ref/source/abl-show.cc
+++ b/crawl-ref/source/abl-show.cc
@@ -347,7 +347,7 @@ static const ability_def Ability_List[] =
{ ABIL_RENOUNCE_RELIGION, "Renounce Religion", 0, 0, 0, 0, ABFLAG_NONE },
};
-const struct ability_def & get_ability_def( ability_type abil )
+const ability_def & get_ability_def(ability_type abil)
{
for (unsigned int i = 0;
i < sizeof(Ability_List) / sizeof(Ability_List[0]); i++)
@@ -359,7 +359,7 @@ const struct ability_def & get_ability_def( ability_type abil )
return (Ability_List[0]);
}
-bool string_matches_ability_name(const std::string key)
+bool string_matches_ability_name(const std::string& key)
{
for (int i = ABIL_SPIT_POISON; i <= ABIL_RENOUNCE_RELIGION; ++i)
{
@@ -367,7 +367,7 @@ bool string_matches_ability_name(const std::string key)
if (abil.ability == ABIL_NON_ABILITY)
continue;
- std::string name = lowercase_string(ability_name(abil.ability));
+ const std::string name = lowercase_string(ability_name(abil.ability));
if (name.find(key) != std::string::npos)
return (true);
}
@@ -846,11 +846,11 @@ std::vector<const char*> get_ability_names()
return result;
}
-static void _print_talent_description(talent tal)
+static void _print_talent_description(const talent& tal)
{
clrscr();
- std::string name = get_ability_def(tal.which).name;
+ const std::string& name = get_ability_def(tal.which).name;
// XXX: The suffix is necessary to distinguish between similarly
// named spells. Yes, this is a hack.
@@ -2025,17 +2025,9 @@ static bool _do_ability(const ability_def& abil)
case ABIL_JIYVA_SLIMIFY:
{
- std::string msg;
- int has_weapon = you.equip[EQ_WEAPON];
-
- if (has_weapon == -1)
- msg = "your " + you.hand_name(true);
- else
- {
- item_def& weapon = *you.weapon();
- msg = weapon.name(DESC_NOCAP_YOUR);
- }
-
+ const item_def* const weapon = you.weapon();
+ const std::string msg = (weapon) ? weapon->name(DESC_NOCAP_YOUR)
+ : ("your " + you.hand_name(true));
mprf(MSGCH_DURATION, "A thick mucus forms on %s.", msg.c_str());
you.increase_duration(DUR_SLIMIFY,
you.skills[SK_INVOCATIONS] * 3 / 2 + 3,
diff --git a/crawl-ref/source/abl-show.h b/crawl-ref/source/abl-show.h
index 1bd1a6afab..eb04a885af 100644
--- a/crawl-ref/source/abl-show.h
+++ b/crawl-ref/source/abl-show.h
@@ -84,7 +84,7 @@ int choose_ability_menu(const std::vector<talent>& talents);
bool activate_ability();
std::vector<talent> your_talents(bool check_confused);
-bool string_matches_ability_name(const std::string key);
+bool string_matches_ability_name(const std::string& key);
std::string print_abilities(void);
void set_god_ability_slots(void);
diff --git a/crawl-ref/source/decks.cc b/crawl-ref/source/decks.cc
index 3834bdbbd9..3f13ec4b56 100644
--- a/crawl-ref/source/decks.cc
+++ b/crawl-ref/source/decks.cc
@@ -1868,7 +1868,7 @@ static void _blade_card(int power, deck_rarity_type rarity)
if (!brand_weapon(RANDOM_ELEMENT(brands), random2(power/4)))
{
- if (you.equip[EQ_WEAPON] == -1)
+ if (!you.weapon())
mprf("Your %s twitch.", your_hand(true).c_str());
else
mpr("Your weapon vibrates for a moment.");
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc
index 6d98503ee8..43c23017cf 100644
--- a/crawl-ref/source/describe.cc
+++ b/crawl-ref/source/describe.cc
@@ -3854,9 +3854,9 @@ std::string get_skill_description(int skill, bool need_title)
unarmed_attacks.push_back("deliver a kick");
}
- if (you.equip[EQ_WEAPON] == -1)
+ if (!you.weapon())
unarmed_attacks.push_back("throw a punch");
- else if (you.equip[EQ_SHIELD] == -1)
+ else if (!you.shield())
unarmed_attacks.push_back("punch with your free hand");
if (!unarmed_attacks.empty())
diff --git a/crawl-ref/source/effects.cc b/crawl-ref/source/effects.cc
index 9f18a9d5b8..ee09fc5689 100644
--- a/crawl-ref/source/effects.cc
+++ b/crawl-ref/source/effects.cc
@@ -1275,19 +1275,18 @@ static bool _try_give_plain_armour(item_def &arm)
// Consider shield slot filled in some cases.
if (armour_slots[i] == EQ_SHIELD)
{
- if (you.equip[EQ_WEAPON] == -1)
- {
- if (you.skills[SK_UNARMED_COMBAT] > random2(8))
- continue;
- }
- else
+ const item_def* weapon = you.weapon();
+
+ // Unarmed fighters don't need shields.
+ if (!weapon && you.skills[SK_UNARMED_COMBAT] > random2(8))
+ continue;
+
+ // Two-handed weapons and ranged weapons conflict with shields.
+ if (weapon
+ && (hands_reqd(*weapon, you.body_size()) == HANDS_TWO)
+ || is_range_weapon(*weapon))
{
- const item_def weapon = you.inv[you.equip[EQ_WEAPON]];
- const hands_reqd_type hand = hands_reqd(weapon, you.body_size());
- if (hand == HANDS_TWO || is_range_weapon(weapon))
- {
- continue;
- }
+ continue;
}
}
diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc
index ef9f525e0f..d59ea2770f 100644
--- a/crawl-ref/source/fight.cc
+++ b/crawl-ref/source/fight.cc
@@ -2020,7 +2020,7 @@ bool melee_attack::player_monattk_hit_effects(bool mondied)
}
else if (you.species == SP_VAMPIRE
&& damage_brand == SPWPN_VAMPIRICISM
- && you.equip[EQ_WEAPON] != -1
+ && you.weapon()
&& _player_vampire_draws_blood(defender_as_monster(),
damage_done, false,
(mondied ? 1 : 10)))
@@ -2029,7 +2029,7 @@ bool melee_attack::player_monattk_hit_effects(bool mondied)
}
// Vampiric *weapon* effects for the killing blow.
else if (mondied && damage_brand == SPWPN_VAMPIRICISM
- && you.equip[EQ_WEAPON] != -1
+ && you.weapon()
&& you.species != SP_VAMPIRE) // vampires get their bonus elsewhere
{
if (defender->holiness() == MH_NATURAL
diff --git a/crawl-ref/source/food.cc b/crawl-ref/source/food.cc
index 5e2babce82..b728901810 100644
--- a/crawl-ref/source/food.cc
+++ b/crawl-ref/source/food.cc
@@ -126,12 +126,9 @@ void set_hunger(int new_hunger_level, bool suppress_msg)
// care of by calling wield_effects(). {gdl}
void weapon_switch(int targ)
{
- if (you.equip[EQ_WEAPON] != -1
- && !check_old_item_warning(you.inv[you.equip[EQ_WEAPON]],
- OPER_WIELD))
- {
+ // Give the player an option to abort.
+ if (you.weapon() && !check_old_item_warning(*you.weapon(), OPER_WIELD))
return;
- }
if (targ == -1) // Unarmed Combat.
{
diff --git a/crawl-ref/source/godabil.cc b/crawl-ref/source/godabil.cc
index e0a0aa06f1..33bdfb1da6 100644
--- a/crawl-ref/source/godabil.cc
+++ b/crawl-ref/source/godabil.cc
@@ -1539,7 +1539,7 @@ void cheibriados_time_bend(int pow)
void cheibriados_time_step(int pow) // pow is the number of turns to skip
{
- coord_def old_pos = you.pos();
+ const coord_def old_pos = you.pos();
mpr("You step out of the flow of time.");
flash_view(LIGHTBLUE);
diff --git a/crawl-ref/source/it_use3.cc b/crawl-ref/source/it_use3.cc
index 81dfb15479..ea3a383bc5 100644
--- a/crawl-ref/source/it_use3.cc
+++ b/crawl-ref/source/it_use3.cc
@@ -90,12 +90,12 @@ void noisy_equipment()
// Disallow anything with VISUAL in it.
if (!msg.empty() && msg.find("VISUAL") != std::string::npos)
- msg = "";
+ msg.clear();
if (!msg.empty())
{
- std::string param = "";
- std::string::size_type pos = msg.find(":");
+ std::string param;
+ const std::string::size_type pos = msg.find(":");
if (pos != std::string::npos)
param = msg.substr(0, pos);
@@ -113,7 +113,7 @@ void noisy_equipment()
else if (param == "PLAIN")
channel = MSGCH_PLAIN;
else if (param == "SPELL" || param == "ENCHANT")
- msg = ""; // disallow these as well, channel stays TALK
+ msg.clear(); // disallow these as well, channel stays TALK
else if (param != "TALK")
match = false;
diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc
index f438fc122a..b161502515 100644
--- a/crawl-ref/source/item_use.cc
+++ b/crawl-ref/source/item_use.cc
@@ -321,15 +321,13 @@ bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages,
if (item_slot == PROMPT_GOT_SPECIAL) // '-' or bare hands
{
- if (you.equip[EQ_WEAPON] != -1)
+ if (const item_def* wpn = you.weapon())
{
- item_def& wpn = *you.weapon();
// Can we safely unwield this item?
- if (has_warning_inscription(wpn, OPER_WIELD))
+ if (has_warning_inscription(*wpn, OPER_WIELD))
{
- std::string prompt = "Really unwield ";
- prompt += wpn.name(DESC_INVENTORY);
- prompt += '?';
+ const std::string prompt =
+ "Really unwield " + wpn->name(DESC_INVENTORY) + "?";
if (!yesno(prompt.c_str(), false, 'n'))
return (false);
}
@@ -367,12 +365,13 @@ bool wield_weapon(bool auto_wield, int slot, bool show_weff_messages,
if (!safe_to_remove_or_wear(new_wpn, false))
return (false);
- // Go ahead and wield the weapon.
- if (you.equip[EQ_WEAPON] != -1 && !unwield_item(show_weff_messages))
+ // Unwield any old weapon.
+ if (you.weapon() && !unwield_item(show_weff_messages))
return (false);
const unsigned int old_talents = your_talents(false).size();
+ // Go ahead and wield the weapon.
you.equip[EQ_WEAPON] = item_slot;
// Any oddness on wielding taken care of here.
diff --git a/crawl-ref/source/wiz-fsim.cc b/crawl-ref/source/wiz-fsim.cc
index 8a9929cdc8..b5451a7748 100644
--- a/crawl-ref/source/wiz-fsim.cc
+++ b/crawl-ref/source/wiz-fsim.cc
@@ -265,33 +265,28 @@ static std::string _fsim_wskill(int missile_slot)
static std::string _fsim_weapon(int missile_slot)
{
- std::string item_buf;
- if (you.equip[EQ_WEAPON] != -1 || missile_slot != -1)
+ if (const item_def* weapon = you.weapon())
{
- if (you.equip[EQ_WEAPON] != -1)
+ std::string item_buf = weapon->name(DESC_PLAIN, true);
+
+ // If it's a ranged weapon, add the description of the missile
+ // if applicable.
+ if (is_range_weapon(*weapon))
{
- const item_def &weapon = you.inv[ you.equip[EQ_WEAPON] ];
- item_buf = weapon.name(DESC_PLAIN, true);
- if (is_range_weapon(weapon))
- {
- const int missile =
- (missile_slot == -1 ? you.m_quiver->get_fire_item()
- : missile_slot);
+ const int missile =
+ (missile_slot == -1 ? you.m_quiver->get_fire_item()
+ : missile_slot);
- if (missile < ENDOFPACK && missile >= 0)
- {
- return item_buf + " with "
- + you.inv[missile].name(DESC_PLAIN);
- }
- }
+ if (missile < ENDOFPACK && missile >= 0)
+ item_buf += " with " + you.inv[missile].name(DESC_PLAIN);
}
- else
- return you.inv[missile_slot].name(DESC_PLAIN);
+
+ return item_buf;
}
+ else if (missile_slot != -1)
+ return you.inv[missile_slot].name(DESC_PLAIN);
else
return "unarmed";
-
- return item_buf;
}
static std::string _fsim_time_string()
@@ -518,7 +513,7 @@ int fsim_kit_equip(const std::string &kit)
}
}
}
- else if (you.equip[EQ_WEAPON] != -1)
+ else if (you.weapon())
unwield_item(false);
if (!missile.empty())