TBTR: Handle leftover template vehicles without owners in old saves.

This commit is contained in:
Jonathan G Rennison
2017-01-21 01:35:31 +00:00
parent 285ba41699
commit d4157b3662
2 changed files with 11 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
#include "../tbtr_template_vehicle.h"
#include "../tbtr_template_vehicle_func.h"
#include "../train.h"
#include "../company_base.h"
#include "../core/backup_type.hpp"
#include "../core/random_func.hpp"
@@ -107,6 +108,15 @@ void AfterLoadTemplateVehiclesUpdateImage()
SavedRandomSeeds saved_seeds;
SaveRandomSeeds(&saved_seeds);
if (!SlXvIsFeaturePresent(XSLFI_TEMPLATE_REPLACEMENT, 3)) {
FOR_ALL_TEMPLATES(tv) {
if (tv->Prev() == NULL && !Company::IsValidID(tv->owner)) {
// clean up leftover template vehicles which no longer have a valid owner
delete tv;
}
}
}
FOR_ALL_TEMPLATES(tv) {
if (tv->Prev() == NULL) {
Backup<CompanyByte> cur_company(_current_company, tv->owner, FILE_LINE);