Skip to content

Commit

Permalink
feat: allow using MOUNTABLE terrains nearby when firing heavy weapon (
Browse files Browse the repository at this point in the history
cataclysmbnteam#3751)

* feat: allow using `MOUNTABLE` terrains nearby when firing heavy weapon

* fix:  check if the potential support is passable

Co-authored-by: Chaosvolt <chaosvolt@users.noreply.github.com>

---------

Co-authored-by: Chaosvolt <chaosvolt@users.noreply.github.com>
  • Loading branch information
scarf005 and chaosvolt authored Nov 26, 2023
1 parent 6e26380 commit 7d22ba6
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ static constexpr int AIF_DURATION_LIMIT = 10;

static projectile make_gun_projectile( const item &gun );
static void cycle_action( item &weap, const tripoint &pos );
bool can_use_heavy_weapon( const Character &who, const map &m, const tripoint &pos );
dispersion_sources calculate_dispersion( const map &m, const Character &who, const item &gun,
int at_recoil, bool burst );

Expand Down Expand Up @@ -773,10 +772,14 @@ void npc::pretend_fire( npc *source, int shots, item &gun )
}
}

bool can_use_heavy_weapon( const Character &who, const map &m, const tripoint &pos )

namespace
{
if( who.is_mounted() && who.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
return true;

auto is_mountable( const map &m, const tripoint &pos ) -> bool
{
if( m.impassable( pos ) ) {
return false;
}

// usage of any attached bipod is dependent upon terrain
Expand All @@ -785,19 +788,37 @@ bool can_use_heavy_weapon( const Character &who, const map &m, const tripoint &p
}

if( const optional_vpart_position vp = m.veh_at( pos ) ) {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return vp->vehicle().has_part( pos, "MOUNTABLE" );
}

return false;
}

auto is_mountable_nearby( const map &m, const tripoint &pos ) -> bool
{
const auto &xs = closest_points_first( pos, 1 );
return std::any_of( xs.begin(), xs.end(),
[&m]( const tripoint & x ) -> bool { return is_mountable( m, x ); } );
}

auto can_use_heavy_weapon( const Character &who, const map &m, const tripoint &pos ) -> bool
{
if( who.is_mounted() && who.mounted_creature->has_flag( MF_RIDEABLE_MECH ) ) {
return true;
}
return is_mountable_nearby( m, pos );
}

} // namespace


dispersion_sources calculate_dispersion( const map &m, const Character &who, const item &gun,
int at_recoil, bool burst )
{
bool bipod = can_use_heavy_weapon( who, m, who.pos() );
const bool bipod = can_use_heavy_weapon( who, m, who.pos() );

int gun_recoil = gun.gun_recoil( bipod );
int eff_recoil = at_recoil + ( burst ? ranged::burst_penalty( who, gun, gun_recoil ) : 0 );
const int gun_recoil = gun.gun_recoil( bipod );
const int eff_recoil = at_recoil + ( burst ? ranged::burst_penalty( who, gun, gun_recoil ) : 0 );
dispersion_sources dispersion( ranged::get_weapon_dispersion( who, gun ) );
dispersion.add_range( eff_recoil );
return dispersion;
Expand Down Expand Up @@ -2072,6 +2093,7 @@ double ranged::recoil_vehicle( const Character &who )

if( who.in_vehicle ) {
if( const optional_vpart_position vp = get_map().veh_at( who.pos() ) ) {
// NOLINTNEXTLINE(bugprone-unchecked-optional-access)
return static_cast<double>( std::abs( vp->vehicle().velocity ) ) * 3 / 100;
}
}
Expand Down Expand Up @@ -3732,8 +3754,8 @@ bool ranged::gunmode_checks_common( avatar &you, const map &m, std::vector<std::
return result;
}

bool ranged::gunmode_checks_weapon( avatar &you, const map &m, std::vector<std::string> &messages,
const gun_mode &gmode )
auto ranged::gunmode_checks_weapon( avatar &you, const map &m, std::vector<std::string> &messages,
const gun_mode &gmode ) -> bool
{
bool result = true;

Expand Down

0 comments on commit 7d22ba6

Please sign in to comment.