TBTR: Handle leftover template vehicles without owners in old saves.
This commit is contained in:
@@ -45,7 +45,7 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
|
|||||||
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
|
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
|
||||||
|
|
||||||
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||||
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 2, 2, "template_replacement", NULL, NULL, "TRPL,TMPL" },
|
{ XSLFI_TEMPLATE_REPLACEMENT, XSCF_NULL, 3, 3, "template_replacement", NULL, NULL, "TRPL,TMPL" },
|
||||||
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
|
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "../tbtr_template_vehicle.h"
|
#include "../tbtr_template_vehicle.h"
|
||||||
#include "../tbtr_template_vehicle_func.h"
|
#include "../tbtr_template_vehicle_func.h"
|
||||||
#include "../train.h"
|
#include "../train.h"
|
||||||
|
#include "../company_base.h"
|
||||||
#include "../core/backup_type.hpp"
|
#include "../core/backup_type.hpp"
|
||||||
#include "../core/random_func.hpp"
|
#include "../core/random_func.hpp"
|
||||||
|
|
||||||
@@ -107,6 +108,15 @@ void AfterLoadTemplateVehiclesUpdateImage()
|
|||||||
SavedRandomSeeds saved_seeds;
|
SavedRandomSeeds saved_seeds;
|
||||||
SaveRandomSeeds(&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) {
|
FOR_ALL_TEMPLATES(tv) {
|
||||||
if (tv->Prev() == NULL) {
|
if (tv->Prev() == NULL) {
|
||||||
Backup<CompanyByte> cur_company(_current_company, tv->owner, FILE_LINE);
|
Backup<CompanyByte> cur_company(_current_company, tv->owner, FILE_LINE);
|
||||||
|
Reference in New Issue
Block a user