Skip to content

Commit 6c17168

Browse files
committed
fix the loops on autodriving routes
fixes #83776
1 parent 310fa55 commit 6c17168

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/vehicle_autodrive.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,6 @@ std::optional<navigation_step> vehicle::autodrive_controller::compute_next_step(
13031303
square_dist( first_step.pos.xy().raw(), second_step.pos.xy().raw() ) !=
13041304
square_dist( first_step.pos.xy().raw(), veh_pos.xy().raw() ) &&
13051305
first_step.steering_dir == second_step.steering_dir ) {
1306-
data.path.pop_back();
13071306
maintain_speed = true;
13081307
data.path.clear();
13091308
} else {
@@ -1443,8 +1442,12 @@ autodrive_result vehicle::do_autodrive( map &here, Character &driver )
14431442
const tripoint_abs_ms veh_pos = pos_abs();
14441443
const tripoint_abs_omt veh_omt = project_to<coords::omt>( veh_pos );
14451444
std::vector<tripoint_abs_omt> &omt_path = driver.omt_path;
1446-
while( !omt_path.empty() && veh_omt.xy() == omt_path.back().xy() ) {
1447-
omt_path.pop_back();
1445+
const auto veh_on_path = std::find_if( omt_path.rbegin(),
1446+
omt_path.rend(), [xy = veh_omt.xy()]( const auto & path ) {
1447+
return path.xy() == xy;
1448+
} );
1449+
if( veh_on_path != omt_path.rend() ) {
1450+
omt_path.erase( ( veh_on_path + 1 ).base(), omt_path.end() );
14481451
}
14491452
if( omt_path.empty() ) {
14501453
stop_autodriving( false );

0 commit comments

Comments
 (0)