From c79074eb5aec50fd5b854f10d4377b4e988a696f Mon Sep 17 00:00:00 2001 From: dolorous Date: Mon, 17 Nov 2008 19:51:48 +0000 Subject: Make all the checks for throwable items consistent. git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@7465 c06c8d41-db1a-0410-9941-cceddc491573 --- crawl-ref/source/describe.cc | 4 +-- crawl-ref/source/externs.h | 6 ++--- crawl-ref/source/item_use.cc | 2 +- crawl-ref/source/itemprop.cc | 59 ++++++++++++++++++++++---------------------- crawl-ref/source/itemprop.h | 18 +++++++------- crawl-ref/source/player.cc | 2 +- crawl-ref/source/tilereg.cc | 4 +-- crawl-ref/source/tutorial.cc | 2 +- 8 files changed, 48 insertions(+), 49 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/describe.cc b/crawl-ref/source/describe.cc index 70d0f3a711..a451e69122 100644 --- a/crawl-ref/source/describe.cc +++ b/crawl-ref/source/describe.cc @@ -802,7 +802,7 @@ void append_weapon_stats(std::string &description, const item_def &item) // describe_weapon // //--------------------------------------------------------------- -static std::string _describe_weapon( const item_def &item, bool verbose) +static std::string _describe_weapon(const item_def &item, bool verbose) { std::string description; @@ -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); + bool can_throw = is_throwable(item, you.body_size(), 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 926aca17df..926ae8c12b 100644 --- a/crawl-ref/source/externs.h +++ b/crawl-ref/source/externs.h @@ -248,7 +248,7 @@ public: virtual bool can_pass_through(int x, int y) const; virtual bool can_pass_through(const coord_def &c) const; - virtual size_type body_size(int psize = PSIZE_TORSO, + virtual size_type body_size(int psize = PSIZE_BODY, bool base = false) const = 0; virtual int body_weight() const = 0; virtual int total_weight() const = 0; @@ -847,7 +847,7 @@ public: bool floundering() const; bool extra_balanced() const; bool can_pass_through_feat(dungeon_feature_type grid) const; - size_type body_size(int psize = PSIZE_TORSO, bool base = false) const; + size_type body_size(int psize = PSIZE_BODY, bool base = false) const; int body_weight() const; int total_weight() const; int damage_type(int attk = -1); @@ -1185,7 +1185,7 @@ public: bool floundering() const; bool extra_balanced() const; bool can_pass_through_feat(dungeon_feature_type grid) const; - size_type body_size(int psize = PSIZE_TORSO, bool base = false) const; + size_type body_size(int psize = PSIZE_BODY, bool base = false) const; int body_weight() const; int total_weight() const; int damage_type(int attk = -1); diff --git a/crawl-ref/source/item_use.cc b/crawl-ref/source/item_use.cc index e3fab070c6..3cfb3de676 100644 --- a/crawl-ref/source/item_use.cc +++ b/crawl-ref/source/item_use.cc @@ -4849,7 +4849,7 @@ void tile_item_use_secondary(int idx) const item_def item = you.inv[idx]; if (item.base_type == OBJ_WEAPONS - && is_throwable(item, player_size(PSIZE_BODY))) + && is_throwable(item, you.body_size())) { 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 4290ed583e..79735afe46 100644 --- a/crawl-ref/source/itemprop.cc +++ b/crawl-ref/source/itemprop.cc @@ -2010,51 +2010,35 @@ int get_inv_in_hand( void ) // // Launcher and ammo functions: // -missile_type fires_ammo_type( const item_def &item ) +missile_type fires_ammo_type(const item_def &item) { if (item.base_type != OBJ_WEAPONS) return (MI_NONE); - return (Weapon_prop[ Weapon_index[item.sub_type] ].ammo); + return (Weapon_prop[Weapon_index[item.sub_type]].ammo); } -missile_type fires_ammo_type( weapon_type wtype ) +missile_type fires_ammo_type(weapon_type wtype) { item_def wpn; wpn.base_type = OBJ_WEAPONS; - wpn.sub_type = wtype; + wpn.sub_type = wtype; return (fires_ammo_type(wpn)); } -bool is_range_weapon( const item_def &item ) -{ - return (fires_ammo_type( item ) != MI_NONE); -} - -// Decide if something is launched or thrown. -launch_retval is_launched(actor *actor, const item_def *launcher, - const item_def &missile) +bool is_range_weapon(const item_def &item) { - if (missile.base_type == OBJ_MISSILES - && launcher - && missile.launched_by(*launcher)) - { - return (LRET_LAUNCHED); - } - - return (is_throwable(missile, actor->body_size()) ? LRET_THROWN - : LRET_FUMBLED); + return (fires_ammo_type(item) != MI_NONE); } -bool is_range_weapon_type( weapon_type wtype ) +bool is_range_weapon_type(weapon_type wtype) { item_def wpn; - wpn.base_type = OBJ_WEAPONS; wpn.sub_type = wtype; - return (is_range_weapon( wpn )); + return (is_range_weapon(wpn)); } const char *ammo_name(missile_type ammo) @@ -2063,14 +2047,14 @@ const char *ammo_name(missile_type ammo) : Missile_prop[ Missile_index[ammo] ].name); } -const char *ammo_name( const item_def &bow ) +const char *ammo_name(const item_def &bow) { - ASSERT( is_range_weapon( bow ) ); - return ammo_name(fires_ammo_type( bow )); + ASSERT(is_range_weapon(bow)); + return ammo_name(fires_ammo_type(bow)); } // Returns true if item has an associated launcher. -bool has_launcher( const item_def &ammo ) +bool has_launcher(const item_def &ammo) { ASSERT(ammo.base_type == OBJ_MISSILES); return (ammo.sub_type != MI_LARGE_ROCK @@ -2079,13 +2063,13 @@ 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 is_throwable(const item_def &wpn, size_type bodysize, bool force) { if (wpn.base_type == OBJ_WEAPONS) return (Weapon_prop[ Weapon_index[wpn.sub_type] ].throwable); else if (wpn.base_type == OBJ_MISSILES) { - if (bodysize < SIZE_MEDIUM + if (!force && bodysize < SIZE_MEDIUM && (wpn.sub_type == MI_JAVELIN || wpn.sub_type == MI_THROWING_NET)) { return (false); @@ -2095,6 +2079,21 @@ bool is_throwable( const item_def &wpn, size_type bodysize ) return (false); } +// Decide if something is launched or thrown. +launch_retval is_launched(actor *actor, const item_def *launcher, + const item_def &missile) +{ + if (missile.base_type == OBJ_MISSILES + && launcher + && missile.launched_by(*launcher)) + { + return (LRET_LAUNCHED); + } + + return (is_throwable(missile, actor->body_size()) ? LRET_THROWN + : LRET_FUMBLED); +} + // // Staff/rod functions: // diff --git a/crawl-ref/source/itemprop.h b/crawl-ref/source/itemprop.h index d17a48510d..d60c62c201 100644 --- a/crawl-ref/source/itemprop.h +++ b/crawl-ref/source/itemprop.h @@ -683,15 +683,15 @@ skill_type range_skill( const item_def &item ); skill_type range_skill( object_class_type wclass, int wtype ); // launcher and ammo functions: -bool is_range_weapon( const item_def &item ); -bool is_range_weapon_type( weapon_type wtype ); -missile_type fires_ammo_type( const item_def &item ); -missile_type fires_ammo_type( weapon_type wtype ); -const char * ammo_name( const item_def &bow ); -const char * ammo_name( missile_type mtyp ); -bool has_launcher( const item_def &ammo ); -bool is_throwable( const item_def &wpn, - size_type bodysize = SIZE_MEDIUM ); +bool is_range_weapon(const item_def &item); +bool is_range_weapon_type(weapon_type wtype); +missile_type fires_ammo_type(const item_def &item); +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); diff --git a/crawl-ref/source/player.cc b/crawl-ref/source/player.cc index 779c441f89..ca7ca02412 100644 --- a/crawl-ref/source/player.cc +++ b/crawl-ref/source/player.cc @@ -2251,7 +2251,7 @@ bool player_is_shapechanged(void) // that wears armour and wields weapons (which is different for some hybrids). // base defaults to "false", meaning consider our current size, not our // natural one. -size_type player_size( int psize, bool base ) +size_type player_size(int psize, bool base) { return you.body_size(psize, base); } diff --git a/crawl-ref/source/tilereg.cc b/crawl-ref/source/tilereg.cc index 1e2660f0f2..5852f4b8c1 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, player_size(PSIZE_BODY))) + if (is_throwable(item, you.body_size())) tip += "\n[Ctrl-L-Click] Fire (f)"; break; case OBJ_WEAPONS + EQUIP_OFFSET: tip += "Unwield"; - if (is_throwable(item, player_size(PSIZE_BODY))) + if (is_throwable(item, you.body_size())) 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 bdbda0c402..0030107fe4 100644 --- a/crawl-ref/source/tutorial.cc +++ b/crawl-ref/source/tutorial.cc @@ -3057,7 +3057,7 @@ void tutorial_describe_item(const item_def &item) break; } case OBJ_MISSILES: - if ( is_throwable(item, player_size()) ) + if (is_throwable(item, you.body_size())) { ostr << item.name(DESC_CAP_YOUR) << " can be fired without the use of a launcher. "; -- cgit v1.2.3-54-g00ecf