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

Prevent vehicles with only PROTRUSION left #60458

Merged
merged 1 commit into from
Aug 27, 2022
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
24 changes: 11 additions & 13 deletions src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1333,36 +1333,34 @@ bool vehicle::can_unmount( const int p, std::string &reason ) const
//First, find all the squares connected to the one we're removing
std::vector<vehicle_part> connected_parts;

for( int i = 0; i < 4; i++ ) {
const point next = parts[p].mount + point( i < 2 ? ( i == 0 ? -1 : 1 ) : 0,
i < 2 ? 0 : ( i == 2 ? -1 : 1 ) );
std::vector<int> parts_over_there = parts_at_relative( next, false );
//Ignore empty squares
for( const point &offset : four_adjacent_offsets ) {
const point next = parts[p].mount + offset;
const std::vector<int> parts_over_there = parts_at_relative( next, false );
if( !parts_over_there.empty() ) {
//Just need one part from the square to track the x/y
connected_parts.push_back( parts[parts_over_there[0]] );
}
}

/* If size = 0, it's the last part of the whole vehicle, so we're OK
* If size = 1, it's one protruding part (i.e., bicycle wheel), so OK
* Otherwise, it gets complicated... */
if( connected_parts.size() > 1 ) {

// run BFS to check path exists from first connected part to every other connected part
/* We'll take connected_parts[0] to be the target part.
* Every other part must have some path (that doesn't involve
* the part about to be removed) to the target part, in order
* for the part to be legally removable. */
for( const vehicle_part &next_part : connected_parts ) {
if( !is_connected( connected_parts[0], next_part, parts[p] ) ) {
//Removing that part would break the vehicle in two
reason = _( "Removing this part would split the vehicle." );
return false;
}
}

}

} else if( connected_parts.size() == 1 ) {
// prevent leaving vehicle with only a PROTRUSION part (wing mirror, forklift etc)
if( connected_parts[0].info().has_flag( "PROTRUSION" ) ) {
reason = _( "Remove other parts before removing last structural part." );
return false;
}
} // else it's last part that's ok to remove
}
}
//Anything not explicitly denied is permitted
Expand Down