Skip to content

Commit 83a6f10

Browse files
authored
Merge pull request #83806 from CleverRaven/trop/0.I-branch-bp-fix-the-loops-on-autodriving-routes-1763415362974
fix the loops on autodriving routes
2 parents 4a226e6 + fb769d8 commit 83a6f10

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
@@ -1298,7 +1298,6 @@ std::optional<navigation_step> vehicle::autodrive_controller::compute_next_step(
12981298
square_dist( first_step.pos.xy().raw(), second_step.pos.xy().raw() ) !=
12991299
square_dist( first_step.pos.xy().raw(), veh_pos.xy().raw() ) &&
13001300
first_step.steering_dir == second_step.steering_dir ) {
1301-
data.path.pop_back();
13021301
maintain_speed = true;
13031302
data.path.clear();
13041303
} else {
@@ -1438,8 +1437,12 @@ autodrive_result vehicle::do_autodrive( map &here, Character &driver )
14381437
const tripoint_abs_ms veh_pos = pos_abs();
14391438
const tripoint_abs_omt veh_omt = project_to<coords::omt>( veh_pos );
14401439
std::vector<tripoint_abs_omt> &omt_path = driver.omt_path;
1441-
while( !omt_path.empty() && veh_omt.xy() == omt_path.back().xy() ) {
1442-
omt_path.pop_back();
1440+
const auto veh_on_path = std::find_if( omt_path.rbegin(),
1441+
omt_path.rend(), [xy = veh_omt.xy()]( const auto & path ) {
1442+
return path.xy() == xy;
1443+
} );
1444+
if( veh_on_path != omt_path.rend() ) {
1445+
omt_path.erase( ( veh_on_path + 1 ).base(), omt_path.end() );
14431446
}
14441447
if( omt_path.empty() ) {
14451448
stop_autodriving( false );

0 commit comments

Comments
 (0)