diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-10-12 01:49:12 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2008-10-12 01:49:12 +0000 |
commit | af9d6c8e0e2e3f58d255449716ad7875cde5ae07 (patch) | |
tree | 1a2d6ffcad7f74d1fbebaa349233928bd60d8d2e /crawl-ref/source | |
parent | 192cbf9887aae64c3ef02cde310ee3175a0d4fb5 (diff) | |
download | crawl-ref-af9d6c8e0e2e3f58d255449716ad7875cde5ae07.tar.gz crawl-ref-af9d6c8e0e2e3f58d255449716ad7875cde5ae07.zip |
General code improvements.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7220 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source')
-rw-r--r-- | crawl-ref/source/describe.cc | 7 | ||||
-rw-r--r-- | crawl-ref/source/fight.cc | 17 | ||||
-rw-r--r-- | crawl-ref/source/item_use.cc | 110 | ||||
-rw-r--r-- | crawl-ref/source/mon-util.cc | 8 | ||||
-rw-r--r-- | crawl-ref/source/player.cc | 6 | ||||
-rw-r--r-- | crawl-ref/source/religion.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/spells1.cc | 5 | ||||
-rw-r--r-- | crawl-ref/source/traps.cc | 18 | ||||
-rw-r--r-- | crawl-ref/source/view.cc | 2 |
9 files changed, 55 insertions, 121 deletions
diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 398533aef2..3c04ab10d9 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -2362,8 +2362,7 @@ void describe_monsters(const monsters& mons) if (mons_is_mimic(mons.type) && !(mons.flags & MF_KNOWN_MIMIC)) { item_def item; - const monsters *mon = &mons; - get_mimic_item( mon, item ); + get_mimic_item(&mons, item); describe_item(item); return; } @@ -2371,7 +2370,7 @@ void describe_monsters(const monsters& mons) std::ostringstream body; std::string title, prefix, suffix, quote; - std::string capname = mons.name(DESC_CAP_A); + const std::string capname = mons.name(DESC_CAP_A); title = capname; if (mons.has_base_name()) { @@ -2388,7 +2387,7 @@ void describe_monsters(const monsters& mons) body << getLongDescription(db_name); quote = getQuoteString(db_name); - std::string symbol = ""; + std::string symbol; symbol += get_monster_data(mons.type)->showchar; if (isupper(symbol[0])) symbol = "cap-" + symbol; diff --git a/crawl-ref/source/fight.cc b/crawl-ref/source/fight.cc index 314b1bad7f..913119784c 100644 --- a/crawl-ref/source/fight.cc +++ b/crawl-ref/source/fight.cc @@ -193,9 +193,9 @@ int calc_heavy_armour_penalty( bool random_factor ) int heavy_armour = 0; // heavy armour modifiers for shield borne - if (you.equip[EQ_SHIELD] != -1) + if (you.shield()) { - switch (you.inv[you.equip[EQ_SHIELD]].sub_type) + switch (you.shield()->sub_type) { case ARM_SHIELD: if (you.skills[SK_SHIELDS] < maybe_random2(7, random_factor)) @@ -4261,22 +4261,19 @@ int weapon_str_weight( object_class_type wpn_class, int wpn_type ) // Returns a value from 0 to 10 representing the weight of strength to // dexterity for the players currently wielded weapon. -static inline int player_weapon_str_weight( void ) +static inline int player_weapon_str_weight() { - const int weapon = you.equip[ EQ_WEAPON ]; + const item_def* weapon = you.weapon(); // unarmed, weighted slightly towards dex -- would have been more, // but then we'd be punishing Trolls and Ghouls who are strong and // get special unarmed bonuses. - if (weapon == -1) + if (!weapon) return (4); - int ret = weapon_str_weight( you.inv[weapon].base_type, you.inv[weapon].sub_type ); - - const bool shield = (you.equip[EQ_SHIELD] != -1); - const int hands = hands_reqd(you.inv[weapon], player_size()); + int ret = weapon_str_weight(weapon->base_type, weapon->sub_type); - if (hands == HANDS_HALF && !shield) + if (hands_reqd(*weapon, player_size()) == HANDS_HALF && !you.shield()) ret += 1; return (ret); diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 8d64311eb0..40e3ba032e 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -1050,7 +1050,8 @@ bool can_wear_armour(const item_def &item, bool verbose, bool ignore_temporary) bool do_wear_armour( int item, bool quiet ) { - if (!is_valid_item( you.inv[item] )) + const item_def &invitem = you.inv[item]; + if (!is_valid_item(invitem)) { if (!quiet) mpr("You don't have any such object."); @@ -1058,10 +1059,9 @@ bool do_wear_armour( int item, bool quiet ) return (false); } - if (!can_wear_armour(you.inv[item], !quiet, false)) + if (!can_wear_armour(invitem, !quiet, false)) return (false); - const item_def &invitem = you.inv[item]; const equipment_type slot = get_armour_slot(invitem); if (item == you.equip[EQ_WEAPON]) @@ -1078,8 +1078,8 @@ bool do_wear_armour( int item, bool quiet ) // if you're wielding something, if (you.weapon() // attempting to wear a shield, - && is_shield(you.inv[item]) - && is_shield_incompatible(*you.weapon(), &you.inv[item])) + && is_shield(invitem) + && is_shield_incompatible(*you.weapon(), &invitem)) { if (!quiet) mpr("You'd need three hands to do that!"); @@ -1090,6 +1090,7 @@ bool do_wear_armour( int item, bool quiet ) bool removedCloak = false; int cloak = -1; + // Removing body armour requires removing the cloak first. if (slot == EQ_BODY_ARMOUR && you.equip[EQ_CLOAK] != -1 && !cloak_is_being_removed()) { @@ -1121,48 +1122,24 @@ bool do_wear_armour( int item, bool quiet ) } } - if (slot == EQ_CLOAK && you.equip[EQ_CLOAK] != -1) + if ((slot == EQ_CLOAK + || slot == EQ_HELMET + || slot == EQ_GLOVES + || slot == EQ_BOOTS + || slot == EQ_SHIELD + || slot == EQ_BODY_ARMOUR) + && you.equip[slot] != -1) { - if (!takeoff_armour(you.equip[EQ_CLOAK])) + if (!takeoff_armour(you.equip[slot])) return (false); } - if (slot == EQ_HELMET && you.equip[EQ_HELMET] != -1) - { - if (!takeoff_armour(you.equip[EQ_HELMET])) - return (false); - } - - if (slot == EQ_GLOVES && you.equip[EQ_GLOVES] != -1) - { - if (!takeoff_armour(you.equip[EQ_GLOVES])) - return (false); - } - - if (slot == EQ_BOOTS && you.equip[EQ_BOOTS] != -1) - { - if (!takeoff_armour(you.equip[EQ_BOOTS])) - return (false); - } - - if (slot == EQ_SHIELD && you.equip[EQ_SHIELD] != -1) - { - if (!takeoff_armour(you.equip[EQ_SHIELD])) - return (false); - } - - if (slot == EQ_BODY_ARMOUR && you.equip[EQ_BODY_ARMOUR] != -1) - { - if (!takeoff_armour(you.equip[EQ_BODY_ARMOUR])) - return (false); - } - - if (!safe_to_remove_or_wear(you.inv[item], false)) + if (!safe_to_remove_or_wear(invitem, false)) return (false); you.turn_is_over = true; - int delay = armour_equip_delay( you.inv[item] ); + const int delay = armour_equip_delay(invitem); if (delay) start_delay( DELAY_ARMOUR_ON, delay, item ); @@ -1174,7 +1151,9 @@ bool do_wear_armour( int item, bool quiet ) bool takeoff_armour(int item) { - if (you.inv[item].base_type != OBJ_ARMOUR) + const item_def& invitem = you.inv[item]; + + if (invitem.base_type != OBJ_ARMOUR) { mpr("You aren't wearing that!"); return (false); @@ -1186,25 +1165,25 @@ bool takeoff_armour(int item) return (false); } - if (item_cursed( you.inv[item] )) + if (item_cursed( invitem )) { - for (int loopy = EQ_CLOAK; loopy <= EQ_BODY_ARMOUR; loopy++) + for (int i = EQ_CLOAK; i <= EQ_BODY_ARMOUR; i++) { - if (item == you.equip[loopy]) + if (item == you.equip[i]) { mprf("%s is stuck to your body!", - you.inv[item].name(DESC_CAP_YOUR).c_str()); + invitem.name(DESC_CAP_YOUR).c_str()); return (false); } } } - if (!safe_to_remove_or_wear(you.inv[item], true)) + if (!safe_to_remove_or_wear(invitem, true)) return (false); bool removedCloak = false; int cloak = -1; - const equipment_type slot = get_armour_slot(you.inv[item]); + const equipment_type slot = get_armour_slot(invitem); if (slot == EQ_BODY_ARMOUR) { @@ -1236,39 +1215,11 @@ bool takeoff_armour(int item) switch (slot) { case EQ_SHIELD: - if (item != you.equip[EQ_SHIELD]) - { - mpr("You aren't wearing that!"); - return (false); - } - break; - case EQ_CLOAK: - if (item != you.equip[EQ_CLOAK]) - { - mpr("You aren't wearing that!"); - return (false); - } - break; - case EQ_HELMET: - if (item != you.equip[EQ_HELMET]) - { - mpr("You aren't wearing that!"); - return (false); - } - break; - case EQ_GLOVES: - if (item != you.equip[EQ_GLOVES]) - { - mpr("You aren't wearing that!"); - return (false); - } - break; - case EQ_BOOTS: - if (item != you.equip[EQ_BOOTS]) + if (item != you.equip[slot]) { mpr("You aren't wearing that!"); return (false); @@ -1282,14 +1233,14 @@ bool takeoff_armour(int item) you.turn_is_over = true; - int delay = armour_equip_delay( you.inv[item] ); + const int delay = armour_equip_delay(invitem); start_delay( DELAY_ARMOUR_OFF, delay, item ); if (removedCloak) start_delay( DELAY_ARMOUR_ON, 1, cloak ); return (true); -} // end takeoff_armour() +} int get_next_fire_item(int current, int direction) { @@ -4939,8 +4890,7 @@ void tile_item_use(int idx) } // Use it - const int type = item.base_type; - switch (type) + switch (item.base_type) { case OBJ_WEAPONS: case OBJ_STAVES: @@ -4953,7 +4903,7 @@ void tile_item_use(int idx) return; } // Evoke misc. items and rods. - if (type == OBJ_MISCELLANY || item_is_rod(item)) + if (item.base_type == OBJ_MISCELLANY || item_is_rod(item)) { if (check_warning_inscriptions(item, OPER_EVOKE)) evoke_wielded(); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index d15988d629..53ab6b3931 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -5653,8 +5653,7 @@ void monsters::remove_enchantment_effect(const mon_enchant &me, bool quiet) else { snprintf(info, INFO_SIZE, " seems to regain %s courage.", - mons_pronoun(static_cast<monster_type>(this->type), - PRONOUN_NOCAP_POSSESSIVE)); + this->pronoun(PRONOUN_NOCAP_POSSESSIVE, true).c_str()); } if (!quiet) @@ -5704,7 +5703,7 @@ void monsters::remove_enchantment_effect(const mon_enchant &me, bool quiet) { // Enslaved monsters stop patrolling and forget their patrol point, // in case they were on order to wait. - patrol_point = coord_def(0, 0); + patrol_point.reset(); } // Reevaluate behaviour. @@ -5774,8 +5773,7 @@ void monsters::remove_enchantment_effect(const mon_enchant &me, bool quiet) if (you.can_see(this)) { - if (!mons_is_safe( static_cast<const monsters*>(this)) - && is_run_delay(current_delay_action())) + if (!mons_is_safe(this) && is_run_delay(current_delay_action())) { // Already set somewhere else. if (!seen_context.empty()) diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index cfec9d3b8a..1e38fb5282 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -6041,12 +6041,8 @@ static bool _equipment_make_berserk() if (!is_random_artefact(*item)) continue; - if (one_chance_in(20) - && randart_wpn_property(*item, - static_cast<randart_prop_type>(RAP_ANGRY))) - { + if (randart_wpn_property(*item, RAP_ANGRY) && one_chance_in(20)) return (true); - } } // nothing found diff --git a/crawl-ref/source/religion.cc b/crawl-ref/source/religion.cc index 533790577c..c669da1616 100644 --- a/crawl-ref/source/religion.cc +++ b/crawl-ref/source/religion.cc @@ -4852,8 +4852,7 @@ void beogh_idol_revenge() dummy.type = MONS_ORC; dummy.attitude = ATT_FRIENDLY; - did_god_conduct(DID_ATTACK_FRIEND, 8, true, - static_cast<const monsters *>(&dummy)); + did_god_conduct(DID_ATTACK_FRIEND, 8, true, &dummy); } } } diff --git a/crawl-ref/source/spells1.cc b/crawl-ref/source/spells1.cc index 04274d833e..aa10be5b51 100644 --- a/crawl-ref/source/spells1.cc +++ b/crawl-ref/source/spells1.cc @@ -759,10 +759,7 @@ static int _healing_spell(int healed, const coord_def where = coord_def(0,0)) if (monster->hit_points == monster->max_hit_points) simple_monster_message(monster, " is completely healed."); else - { - const monsters *mons = static_cast<const monsters*>(monster); - print_wounds(mons); - } + print_wounds(monster); if (you.religion == GOD_ELYVILON && !_mons_hostile(monster)) { diff --git a/crawl-ref/source/traps.cc b/crawl-ref/source/traps.cc index 6283c59aa5..5e100b44fd 100644 --- a/crawl-ref/source/traps.cc +++ b/crawl-ref/source/traps.cc @@ -148,7 +148,7 @@ bool trap_def::is_known(const actor* act) const rc = player_knows; else if (act->atype() == ACT_MONSTER) { - const monsters* monster = static_cast<const monsters*>(act); + const monsters* monster = dynamic_cast<const monsters*>(act); const bool mechanical = (this->category() == DNGN_TRAP_MECHANICAL); const int intel = mons_intel(monster); @@ -232,19 +232,19 @@ void monster_caught_in_net(monsters *mon, bolt &pbolt) if (mons_is_insubstantial(mon->type)) { if (mons_near(mon) && player_monster_visible(mon)) - mprf("The net passes right through %s!", mon->name(DESC_NOCAP_THE).c_str()); + mprf("The net passes right through %s!", + mon->name(DESC_NOCAP_THE).c_str()); return; } - const monsters* mons = static_cast<const monsters*>(mon); - bool mon_flies = mons->flight_mode() == FL_FLY; - if (mon_flies && (!mons_is_confused(mons) || one_chance_in(3))) + bool mon_flies = mon->flight_mode() == FL_FLY; + if (mon_flies && (!mons_is_confused(mon) || one_chance_in(3))) { simple_monster_message(mon, " darts out from under the net!"); return; } - if (mons->type == MONS_OOZE || mons->type == MONS_PULSATING_LUMP) + if (mon->type == MONS_OOZE || mon->type == MONS_PULSATING_LUMP) { simple_monster_message(mon, " oozes right through the net!"); return; @@ -356,7 +356,7 @@ void trap_def::trigger(actor& triggerer, bool flat_footed) monsters* m = NULL; if (triggerer.atype() == ACT_MONSTER) - m = static_cast<monsters*>(&triggerer); + m = dynamic_cast<monsters*>(&triggerer); // Anything stepping onto a trap almost always reveals it. // (We can rehide it later for the exceptions.) @@ -1177,9 +1177,7 @@ void trap_def::shoot_ammo(actor& act, bool was_known) } else if (act.atype() == ACT_MONSTER) { - // XXX reveal the trap XXX - - monsters* monster = static_cast<monsters *>(&act); + monsters* monster = dynamic_cast<monsters *>(&act); // Determine whether projectile hits. bool hit = (((20+(you.your_level*2))*random2(200))/100 diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index 0ef2d5c34b..c86c8f4edd 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -928,7 +928,7 @@ static void _handle_seen_interrupt(monsters* monster) else aid.context = "newly seen"; - if (!mons_is_safe( static_cast<const monsters*>(monster) ) + if (!mons_is_safe(monster) && !mons_class_flag( monster->type, M_NO_EXP_GAIN ) && !mons_is_mimic( monster->type )) { |