From cba36e09a9f04f7e691fac4f1c720c9935227298 Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 17 Nov 2008 21:02:13 +0000 Subject: Clean up handling of thrown items (mostly large rocks) again. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7467 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/describe.cc | 2 +- crawl-ref/source/externs.h | 8 ++++++-- crawl-ref/source/item_use.cc | 7 +++---- crawl-ref/source/itemprop.cc | 32 +++++++++++++++++++++++--------- crawl-ref/source/itemprop.h | 7 +++---- crawl-ref/source/mon-util.cc | 29 ++++++----------------------- crawl-ref/source/monstuff.cc | 16 ++++++++-------- crawl-ref/source/monstuff.h | 4 ++-- crawl-ref/source/player.cc | 4 ++-- crawl-ref/source/quiver.cc | 3 +-- crawl-ref/source/tilereg.cc | 4 ++-- crawl-ref/source/tutorial.cc | 6 +++--- 12 files changed, 60 insertions(+), 62 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index a451e69122..9e6054a103 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -1142,7 +1142,7 @@ static std::string _describe_ammo( const item_def &item ) } bool can_launch = has_launcher(item); - bool can_throw = is_throwable(item, you.body_size(), true); + bool can_throw = is_throwable(&you, item, true); bool need_new_line = true; if (item.special && item_type_known(item)) diff --git a/crawl-ref/source/externs.h b/crawl-ref/source/externs.h index 926ae8c12b..d879d2b59d 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -331,6 +331,9 @@ public: virtual int stat_hp() const = 0; virtual int stat_maxhp() const = 0; + + virtual bool can_throw_large_rocks() const = 0; + virtual int armour_class() const = 0; virtual int melee_evasion(const actor *attacker) const = 0; virtual int shield_bonus() const = 0; @@ -935,7 +938,7 @@ public: bool cannot_act() const; - bool can_throw_rocks() const; + bool can_throw_large_rocks() const; int armour_class() const; int melee_evasion(const actor *attacker) const; @@ -1286,6 +1289,8 @@ public: bool has_spell(spell_type spell) const; + bool can_throw_large_rocks() const; + int armour_class() const; int melee_evasion(const actor *attacker) const; @@ -1345,7 +1350,6 @@ private: bool drop_item(int eslot, int near); bool wants_weapon(const item_def &item) const; bool wants_armour(const item_def &item) const; - bool can_throw_rocks() const; void lose_pickup_energy(); bool check_set_valid_home(const coord_def &place, coord_def &chosen, diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index 3cfb3de676..4b472bb6a5 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -1847,7 +1847,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus, { range = 1 + random2( you.strength / 5 ); max_range = you.strength / 5; - if (you.can_throw_rocks()) + if (you.can_throw_large_rocks()) { range += random_range(4, 7); max_range += 7; @@ -2342,7 +2342,7 @@ bool throw_it(bolt &pbolt, int throw_2, bool teleport, int acc_bonus, switch (wepType) { case MI_LARGE_ROCK: - if (you.can_throw_rocks()) + if (you.can_throw_large_rocks()) baseHit = 1; break; case MI_DART: @@ -4848,8 +4848,7 @@ void tile_item_use_secondary(int idx) { const item_def item = you.inv[idx]; - if (item.base_type == OBJ_WEAPONS - && is_throwable(item, you.body_size())) + if (item.base_type == OBJ_WEAPONS && is_throwable(&you, item)) { if (check_warning_inscriptions(item, OPER_FIRE)) fire_thing(idx); // fire weapons diff --git a/crawl-ref/source/itemprop.cc b/crawl-ref/source/itemprop.cc index 79735afe46..1a417abe2a 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -2063,24 +2063,39 @@ bool has_launcher(const item_def &ammo) } // Returns true if item can be reasonably thrown without a launcher. -bool is_throwable(const item_def &wpn, size_type bodysize, bool force) +bool is_throwable(const actor *actor, const item_def &wpn, bool force) { + size_type bodysize = actor->body_size(); + if (wpn.base_type == OBJ_WEAPONS) - return (Weapon_prop[ Weapon_index[wpn.sub_type] ].throwable); + return (Weapon_prop[Weapon_index[wpn.sub_type]].throwable); else if (wpn.base_type == OBJ_MISSILES) { - if (!force && bodysize < SIZE_MEDIUM - && (wpn.sub_type == MI_JAVELIN || wpn.sub_type == MI_THROWING_NET)) + if (!force) { - return (false); + if ((bodysize < SIZE_LARGE + || !actor->can_throw_large_rocks()) + && wpn.sub_type == MI_LARGE_ROCK) + { + return (false); + } + + if (bodysize < SIZE_MEDIUM + && (wpn.sub_type == MI_JAVELIN + || wpn.sub_type == MI_THROWING_NET)) + { + return (false); + } } - return (Missile_prop[ Missile_index[wpn.sub_type] ].throwable); + + return (Missile_prop[Missile_index[wpn.sub_type]].throwable); } + return (false); } // Decide if something is launched or thrown. -launch_retval is_launched(actor *actor, const item_def *launcher, +launch_retval is_launched(const actor *actor, const item_def *launcher, const item_def &missile) { if (missile.base_type == OBJ_MISSILES @@ -2090,8 +2105,7 @@ launch_retval is_launched(actor *actor, const item_def *launcher, return (LRET_LAUNCHED); } - return (is_throwable(missile, actor->body_size()) ? LRET_THROWN - : LRET_FUMBLED); + return (is_throwable(actor, missile) ? LRET_THROWN : LRET_FUMBLED); } // diff --git a/crawl-ref/source/itemprop.h b/crawl-ref/source/itemprop.h index d60c62c201..786ca39b1a 100644 --- a/crawl-ref/source/itemprop.h +++ b/crawl-ref/source/itemprop.h @@ -690,10 +690,9 @@ missile_type fires_ammo_type(weapon_type wtype); const char *ammo_name(missile_type ammo); const char *ammo_name(const item_def &bow); bool has_launcher(const item_def &ammo); -bool is_throwable(const item_def &wpn, size_type bodysize = SIZE_MEDIUM, - bool force = false); -launch_retval is_launched(actor *actor, const item_def *launcher, - const item_def &missile); +bool is_throwable(const actor *actor, const item_def &wpn, bool force = false); +launch_retval is_launched(const actor *actor, const item_def *launcher, + const item_def &missile); // staff/rod functions: bool item_is_rod( const item_def &item ); diff --git a/crawl-ref/source/mon-util.cc b/crawl-ref/source/mon-util.cc index edc9fbd46b..9b78057767 100644 --- a/crawl-ref/source/mon-util.cc +++ b/crawl-ref/source/mon-util.cc @@ -3513,7 +3513,7 @@ item_def *monsters::weapon(int which_attack) } -bool monsters::can_throw_rocks() const +bool monsters::can_throw_large_rocks() const { return (type == MONS_STONE_GIANT || ::mons_species(this->type) == MONS_CYCLOPS @@ -3548,28 +3548,10 @@ bool monsters::can_use_missile(const item_def &item) const if (type == MONS_DEEP_ELF_BLADEMASTER) return (false); - if (item.base_type == OBJ_WEAPONS) - return (is_throwable(item)); - - if (item.base_type != OBJ_MISSILES) - return (false); - - if ((item.sub_type == MI_THROWING_NET || item.sub_type == MI_JAVELIN) - && body_size(PSIZE_BODY) < SIZE_MEDIUM) - { - return (false); - } - - if (item.sub_type == MI_LARGE_ROCK && !can_throw_rocks()) - return (false); - - // Stones and darts don't need any launcher, and are always okay. - // Other missile types that don't need any launcher should be okay - // if we've gotten this far. - if (item.sub_type == MI_STONE || item.sub_type == MI_DART - || !has_launcher(item)) + if (item.base_type == OBJ_WEAPONS + || item.base_type == OBJ_MISSILES && !has_launcher(item)) { - return (true); + return (is_throwable(this, item)); } item_def *launch; @@ -4056,7 +4038,8 @@ bool monsters::pickup_throwable_weapon(item_def &item, int near) item_def *launch = NULL; const int exist_missile = mons_pick_best_missile(this, &launch, true); if (exist_missile == NON_ITEM - || (_q_adj_damage(mons_missile_damage(launch, &mitm[exist_missile]), + || (_q_adj_damage(mons_missile_damage(this, launch, + &mitm[exist_missile]), mitm[exist_missile].quantity) < _q_adj_damage(mons_thrown_weapon_damage(&item), item.quantity))) { diff --git a/crawl-ref/source/monstuff.cc b/crawl-ref/source/monstuff.cc index 00ed42a243..9b1cbb25cb 100644 --- a/crawl-ref/source/monstuff.cc +++ b/crawl-ref/source/monstuff.cc @@ -5420,11 +5420,16 @@ int mons_thrown_weapon_damage(const item_def *weap) return std::max(0, (property(*weap, PWPN_DAMAGE) + weap->plus2 / 2)); } +int mons_weapon_damage_rating(const item_def &launcher) +{ + return (property(launcher, PWPN_DAMAGE) + launcher.plus2); +} + // Returns a rough estimate of damage from firing/throwing missile. -int mons_missile_damage(const item_def *launch, +int mons_missile_damage(monsters *mons, const item_def *launch, const item_def *missile) { - if (!missile || (!launch && !is_throwable(*missile))) + if (!missile || (!launch && !is_throwable(mons, *missile))) return (0); const int missile_damage = property(*missile, PWPN_DAMAGE) / 2 + 1; @@ -5432,11 +5437,6 @@ int mons_missile_damage(const item_def *launch, return std::max(0, launch_damage + missile_damage); } -int mons_weapon_damage_rating(const item_def &launcher) -{ - return (property(launcher, PWPN_DAMAGE) + launcher.plus2); -} - // Given the monster's current weapon and alt weapon (either or both of // which may be NULL), works out whether using missiles or throwing the // main weapon (with returning brand) is better. If using missiles that @@ -5465,7 +5465,7 @@ int mons_pick_best_missile(monsters *mons, item_def **launcher, launch = NULL; const int tdam = mons_thrown_weapon_damage(melee); - const int fdam = mons_missile_damage(launch, missiles); + const int fdam = mons_missile_damage(mons, launch, missiles); if (!tdam && !fdam) return (NON_ITEM); diff --git a/crawl-ref/source/monstuff.h b/crawl-ref/source/monstuff.h index cbc301a19f..93448c5aac 100644 --- a/crawl-ref/source/monstuff.h +++ b/crawl-ref/source/monstuff.h @@ -199,10 +199,10 @@ void seen_monster(monsters *monster); bool shift_monster(monsters *mon, coord_def p = coord_def(0,0) ); int mons_weapon_damage_rating(const item_def &launcher); +int mons_missile_damage(monsters *mons, const item_def *launch, + const item_def *missile); int mons_pick_best_missile(monsters *mons, item_def **launcher, bool ignore_melee = false); -int mons_missile_damage(const item_def *launch, - const item_def *missile); int mons_thrown_weapon_damage(const item_def *weap); int mons_natural_regen_rate(monsters *monster); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index ca7ca02412..39c4d506cc 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -6865,9 +6865,9 @@ bool player::cannot_act() const return (asleep() || cannot_move()); } -bool player::can_throw_rocks() const +bool player::can_throw_large_rocks() const { - return (species == SP_OGRE || species == SP_TROLL); + return (player_genus(GENPC_OGRE) || species == SP_TROLL); } void player::put_to_sleep(int) diff --git a/crawl-ref/source/quiver.cc b/crawl-ref/source/quiver.cc index c1582ab6ff..c94622fe1b 100644 --- a/crawl-ref/source/quiver.cc +++ b/crawl-ref/source/quiver.cc @@ -533,8 +533,7 @@ static bool _item_matches(const item_def &item, fire_type types, return (true); } } - else if (item.base_type == OBJ_WEAPONS - && is_throwable(item, you.body_size())) + else if (item.base_type == OBJ_WEAPONS && is_throwable(&you, item)) { if ((types & FIRE_RETURNING) && item.special == SPWPN_RETURNING diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index 5852f4b8c1..0a039a2830 100644 --- a/crawl-ref/source/tilereg.cc +++ b/crawl-ref/source/tilereg.cc @@ -1555,12 +1555,12 @@ bool InventoryRegion::update_tip_text(std::string& tip) case OBJ_STAVES: case OBJ_MISCELLANY: tip += "Wield (w)"; - if (is_throwable(item, you.body_size())) + if (is_throwable(&you, item)) tip += "\n[Ctrl-L-Click] Fire (f)"; break; case OBJ_WEAPONS + EQUIP_OFFSET: tip += "Unwield"; - if (is_throwable(item, you.body_size())) + if (is_throwable(&you, item)) tip += "\n[Ctrl-L-Click] Fire (f)"; break; case OBJ_MISCELLANY + EQUIP_OFFSET: diff --git a/crawl-ref/source/tutorial.cc b/crawl-ref/source/tutorial.cc index 0030107fe4..f0aabd9cc0 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -3023,7 +3023,7 @@ void tutorial_describe_item(const item_def &item) } } - if (is_throwable(item, you.body_size()) && !long_text) + if (is_throwable(&you, item) && !long_text) { ostr << "\n\nSome weapons (including this one), can also be " "fired. "; @@ -3048,7 +3048,7 @@ void tutorial_describe_item(const item_def &item) "reading a scroll of remove curse or one of the " "enchantment scrolls."; - if (!wielded && is_throwable(item, you.body_size())) + if (!wielded && is_throwable(&you, item)) ostr << " (Throwing it is safe, though.)"; Options.tutorial_events[TUT_YOU_CURSED] = false; @@ -3057,7 +3057,7 @@ void tutorial_describe_item(const item_def &item) break; } case OBJ_MISSILES: - if (is_throwable(item, you.body_size())) + if (is_throwable(&you, item)) { ostr << item.name(DESC_CAP_YOUR) << " can be fired without the use of a launcher. "; -- cgit v1.2.3-54-g00ecf