Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: turrets aiming moving vehicle it cannot see #3180

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,37 +486,45 @@ int gun_actor::get_max_range() const
}
return max_range;
}
namespace
{

static std::optional<tripoint> find_target_vehicle( monster &z, int range )
auto find_target_vehicle( monster &z, int range ) -> std::optional<tripoint>
{
const auto is_different_plane = []( const wrapped_vehicle & v, const monster & m ) -> bool {
return !fov_3d && v.pos.z != m.pos().z;
};

map &here = get_map();
bool found = false;
tripoint aim_at;
for( wrapped_vehicle &v : here.get_vehicles() ) {
if( ( !fov_3d && v.pos.z != z.pos().z ) || v.v->velocity == 0 ) {
if( is_different_plane( v, z ) || v.v->velocity == 0 ) {
continue;
}

bool found_controls = false;

for( const vpart_reference &vp : v.v->get_avail_parts( "CONTROLS" ) ) {
if( z.sees( vp.pos() ) ) {
int new_dist = rl_dist( z.pos(), vp.pos() );
if( new_dist <= range ) {

aim_at = vp.pos();
range = new_dist;
found = true;
found_controls = true;
}
if( !z.sees( vp.pos() ) ) {
continue;
}

int new_dist = rl_dist( z.pos(), vp.pos() );
if( new_dist <= range ) {
aim_at = vp.pos();
range = new_dist;
found = true;
found_controls = true;
}
}


if( !found_controls ) {
std::vector<tripoint> line = here.find_clear_path( z.pos(), v.v->global_pos3() );
tripoint prev_point = z.pos();
for( tripoint &i : line ) {
if( here.floor_between( prev_point, i ) ) {
if( !z.sees( i ) || here.floor_between( prev_point, i ) ) {
break;
}
optional_vpart_position vp = here.veh_at( i );
Expand All @@ -543,6 +551,9 @@ static std::optional<tripoint> find_target_vehicle( monster &z, int range )
}
}

} // namespace


bool gun_actor::call( monster &z ) const
{
Creature *target;
Expand Down