Skip to content

Commit

Permalink
fix: AoE ammo fired from vehicle turrets no longer wrecks the vehicle…
Browse files Browse the repository at this point in the history
… it's fired from (cataclysmbnteam#5517)

clang sucks
  • Loading branch information
chaosvolt authored Oct 5, 2024
1 parent c0095a5 commit 5ac3d7a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ int ranged::fire_gun( Character &who, const tripoint &target, int max_shots, ite
double length = trig_dist( who.pos(), aim );
rl_vec3d vec_pos( who.pos() );
rl_vec3d new_aim = vec_pos + rl_vec3d( length, 0, 0 ).rotated( new_angle );
ranged::execute_shaped_attack( *shape->create( vec_pos, new_aim ), projectile, who, &gun );
ranged::execute_shaped_attack( *shape->create( vec_pos, new_aim ), projectile, who, &gun, in_veh );
}
curshot++;

Expand Down
2 changes: 1 addition & 1 deletion src/ranged.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ std::optional<shape_factory> get_shape_factory( const item &gun );

/** AoE attack, with area given by shape */
void execute_shaped_attack( const shape &sh, const projectile &proj, Creature &attacker,
item *source_weapon );
item *source_weapon, const vehicle *in_veh = nullptr );

std::map<tripoint, double> expected_coverage( const shape &sh, const map &here, int bash_power );

Expand Down
14 changes: 11 additions & 3 deletions src/ranged_aoe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace ranged
{

void execute_shaped_attack( const shape &sh, const projectile &proj, Creature &attacker,
item *source_weapon )
item *source_weapon, const vehicle *in_veh )
{
map &here = get_map();
const auto sigdist_to_coverage = []( const double sigdist ) {
Expand Down Expand Up @@ -84,14 +84,22 @@ void execute_shaped_attack( const shape &sh, const projectile &proj, Creature &a
}

double current_coverage = parent_coverage;
if( aoe_permeable( p ) ) {
bool firing_over_veh = false;
if( in_veh != nullptr ) {
const optional_vpart_position other = here.veh_at( p );
if( in_veh == veh_pointer_or_null( other ) ) {
// Don't blast a vehicle with its own turret
firing_over_veh = true;
}
}
if( aoe_permeable( p ) || firing_over_veh ) {
// noop
} else {
projectile proj_copy = proj;
// Origin and target are same point so AoE can bypass cover mechanics
here.shoot( p, p, proj_copy, false );
// There should be a nicer way than rechecking after shoot
if( !aoe_permeable( p ) ) {
if( !aoe_permeable( p ) && !firing_over_veh ) {
continue;
}

Expand Down

0 comments on commit 5ac3d7a

Please sign in to comment.