Last active
July 23, 2019 00:10
-
-
Save Petethegoat/d0ad7037f273dddd8ccc8999f1deb7fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int num_valid_controls = 0; | |
cata::optional<tripoint> vehicle_position; | |
cata::optional<vpart_reference> vehicle_controls; | |
for( const tripoint elem : m.points_in_radius( g->u.pos(), 1 ) ) { | |
if( const optional_vpart_position vp = m.veh_at( elem ) ) { | |
vehicle_controls = *vp.part_with_feature( "CONTROLS", true ); | |
if( vehicle_controls ) { | |
num_valid_controls++; | |
vehicle_position = elem; | |
} | |
} | |
} | |
if( num_valid_controls < 1 ) { | |
add_msg( _( "No vehicle controls found." ) ); | |
return; | |
} else if( num_valid_controls > 1 ) { | |
vehicle_position = choose_adjacent( _( "Control vehicle where?" ) ); | |
if( !vehicle_position ) { | |
return; | |
} | |
const optional_vpart_position vp = m.veh_at( *vehicle_position ); | |
if( vp ) { | |
vehicle_controls = *vp.part_with_feature( "CONTROLS", true ); | |
if( !vehicle_controls ) { | |
add_msg( _( "The vehicle doesn't have controls there." ) ); | |
return; | |
} | |
} else { | |
add_msg( _( "No vehicle there." ) ); | |
return; | |
} | |
} | |
// If we hit neither of those, there's only one set of vehicle controls, which should already have been found. | |
if( vehicle_controls ) { | |
veh = &vehicle_controls->vehicle(); | |
veh_part = vehicle_controls->part_index(); | |
if( veh->avail_part_with_feature( veh_part, "CONTROLS", true ) >= 0 ) { | |
if( !veh->handle_potential_theft( dynamic_cast<player &>( u ) ) ) { | |
return; | |
} | |
veh->use_controls( *vehicle_position ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment