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

Some cleanup of vehicle code #76052

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
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
36 changes: 2 additions & 34 deletions src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,16 +1394,10 @@ void vehicle_prototype::save_vehicle_as_prototype( const vehicle &veh, JsonOut &
int mount_min_y = 123;
int mount_max_y = -123;
// Form a map of existing real parts
// Structural parts first
// get_all_parts() gets all non-fake parts
// The parts are already in installation order
for( const vpart_reference &vpr : veh.get_all_parts() ) {
const vehicle_part &p = vpr.part();
if( p.is_fake ) {
continue;
}
if( p.info().location == part_location_structure ) {
vp_map[p.mount].push_front( &p );
continue;
}
mount_max_y = mount_max_y < p.mount.y ? p.mount.y : mount_max_y;
mount_min_y = mount_min_y > p.mount.y ? p.mount.y : mount_min_y;
vp_map[p.mount].push_back( &p );
Expand Down Expand Up @@ -1443,32 +1437,6 @@ void vehicle_prototype::save_vehicle_as_prototype( const vehicle &veh, JsonOut &
return;
};
for( auto &vp_pos : vp_map ) {
auto fake = make_shared_fast<vehicle>( vproto_id() );
vehicle &fakev = *fake;
auto iter = vp_pos.second.begin();
// Ensure that the entries in the list can be installed in order.
// Might be a infinite loop if debug hammerspace created improper parts combination.
// So add a iteration limit to avoid this.
int iteration = 0;
for( ; iter != vp_pos.second.end(); ) {
vehicle_part g = **iter;
if( fakev.can_mount( point_zero, g.info() ).success() ) {
fakev.install_part( point_zero, std::move( g ) );
iter++;
continue;
}
iteration++;
auto iter2 = std::next( iter, 1 );
vp_pos.second.splice( vp_pos.second.end(), vp_pos.second, iter );
iter = iter2;
// It's impossible to hit this limit when a single mount point has fewer than 50 parts.
// So we can assume only infinite loop hits this limit.
if( iteration > 1250 ) {
debugmsg( "Error exporting vehicle: mount point (%d,%d) has illegal vehicle part sequence.",
vp_pos.first.x, vp_pos.first.y );
return;
}
}
json.start_object();
json.member( "x", vp_pos.first.x );
json.member( "y", vp_pos.first.y );
Expand Down
2 changes: 1 addition & 1 deletion src/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,7 @@ bool vehicle::is_connected( const vehicle_part &to, const vehicle_part &from,
}

// 2022-08-27 assuming structure part is on 0th index is questionable but it worked before so...
vehicle_part vp_next = parts[ parts_there[ 0 ] ];
const vehicle_part &vp_next = parts[ parts_there[ 0 ] ];

if( vp_next.info().location != part_location_structure || // not a structure part
vp_next.info().has_flag( "PROTRUSION" ) || // protrusions are not really a structure
Expand Down
Loading