diff --git a/savegame_json.cpp b/savegame_json.cpp index e608058998ece..917877339a8a9 100644 --- a/savegame_json.cpp +++ b/savegame_json.cpp @@ -1431,6 +1431,11 @@ void vehicle::json_load(picojson::value & parsed, game * g ) { } parray = NULL; } + /* After loading, check if the vehicle is from the old rules and is missing + * frames. */ + if ( savegame_loading_version < 11 ) { + add_missing_frames(); + } find_external_parts (); find_exhaust (); insides_dirty = true; diff --git a/savegame_legacy.cpp b/savegame_legacy.cpp index 26d2aa84665ec..9252274b5993b 100644 --- a/savegame_legacy.cpp +++ b/savegame_legacy.cpp @@ -1062,6 +1062,9 @@ void vehicle::load_legacy(std::ifstream &stin) { } parts.push_back (new_part); } + /* After loading, check if the vehicle is from the old rules and is missing + * frames. */ + add_missing_frames(); find_external_parts (); find_exhaust (); insides_dirty = true; diff --git a/vehicle.cpp b/vehicle.cpp index ec7570f40fa2c..ba41a400f92dd 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -78,11 +78,6 @@ void vehicle::load (std::ifstream &stin) } else { load_legacy(stin); } - - /* After loading, check if the vehicle is from the old rules and is missing - * frames. */ - add_missing_frames(); - } /** Checks all parts to see if frames are missing (as they might be when @@ -91,9 +86,9 @@ void vehicle::add_missing_frames() { //No need to check the same (x, y) spot more than once std::set< std::pair > locations_checked; - for(std::vector::iterator it = parts.begin(); it != parts.end(); it++) { - int next_x = it->mount_dx; - int next_y = it->mount_dy; + for (int i = 0; i < parts.size(); i++) { + int next_x = parts[i].mount_dx; + int next_y = parts[i].mount_dy; std::pair mount_location = std::make_pair(next_x, next_y); if(locations_checked.count(mount_location) == 0) { @@ -108,7 +103,15 @@ void vehicle::add_missing_frames() } if(!found) { //No frame here! Install one. - install_part(next_x, next_y, "frame_vertical", -1, true); + vehicle_part new_part; + new_part.id = "frame_vertical"; + new_part.mount_dx = next_x; + new_part.mount_dy = next_y; + new_part.hp = vehicle_part_types["frame_vertical"].durability; + new_part.amount = 0; + new_part.blood = 0; + new_part.bigness = 0; + parts.push_back (new_part); } }