TBTR: Update template veh sprite IDs when loading savegame/GRFs.

This commit is contained in:
Jonathan G Rennison
2016-02-15 23:19:41 +00:00
parent 77ca326997
commit d688039a42
5 changed files with 40 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
#include "../stdafx.h"
#include "../tbtr_template_vehicle.h"
#include "../tbtr_template_vehicle_func.h"
#include "../train.h"
#include "saveload.h"
@@ -94,6 +96,37 @@ void AfterLoadTemplateVehicles()
}
}
void AfterLoadTemplateVehiclesUpdateImage()
{
TemplateVehicle *tv;
FOR_ALL_TEMPLATES(tv) {
if (tv->Prev() == NULL) {
StringID err;
Train* t = VirtualTrainFromTemplateVehicle(tv, err);
if (t != NULL) {
int tv_len = 0;
for (TemplateVehicle *u = tv; u != NULL; u = u->Next()) {
tv_len++;
}
int t_len = 0;
for (Train *u = t; u != NULL; u = u->Next()) {
t_len++;
}
if (t_len == tv_len) {
Train *v = t;
for (TemplateVehicle *u = tv; u != NULL; u = u->Next(), v = v->Next()) {
u->spritenum = v->spritenum;
u->cur_image = v->GetImage(DIR_W, EIT_PURCHASE);
u->image_width = v->GetDisplayImageWidth();
}
}
delete t;
}
}
}
}
extern const ChunkHandler _template_vehicle_chunk_handlers[] = {
{'TMPL', Save_TMPLS, Load_TMPLS, Ptrs_TMPLS, NULL, CH_ARRAY | CH_LAST},
};