Merge branch 'template_train_replacement' into template_train_replacement-sx
# Conflicts: # projects/openttd_vs100.vcxproj # projects/openttd_vs100.vcxproj.filters # projects/openttd_vs140.vcxproj # projects/openttd_vs140.vcxproj.filters # projects/openttd_vs80.vcproj # projects/openttd_vs90.vcproj # source.list
This commit is contained in:
@@ -775,6 +775,9 @@ bool AfterLoadGame()
|
||||
/* Update all vehicles */
|
||||
AfterLoadVehicles(true);
|
||||
|
||||
/* Update template vehicles */
|
||||
AfterLoadTemplateVehicles();
|
||||
|
||||
/* Make sure there is an AI attached to an AI company */
|
||||
{
|
||||
Company *c;
|
||||
|
@@ -44,6 +44,8 @@
|
||||
#include "../fios.h"
|
||||
#include "../error.h"
|
||||
|
||||
#include "../tbtr_template_vehicle.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "saveload_internal.h"
|
||||
@@ -454,6 +456,8 @@ extern const ChunkHandler _linkgraph_chunk_handlers[];
|
||||
extern const ChunkHandler _airport_chunk_handlers[];
|
||||
extern const ChunkHandler _object_chunk_handlers[];
|
||||
extern const ChunkHandler _persistent_storage_chunk_handlers[];
|
||||
extern const ChunkHandler _template_replacement_chunk_handlers[];
|
||||
extern const ChunkHandler _template_vehicle_chunk_handlers[];
|
||||
|
||||
/** Array of all chunks in a savegame, \c NULL terminated. */
|
||||
static const ChunkHandler * const _chunk_handlers[] = {
|
||||
@@ -491,6 +495,8 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
||||
_airport_chunk_handlers,
|
||||
_object_chunk_handlers,
|
||||
_persistent_storage_chunk_handlers,
|
||||
_template_replacement_chunk_handlers,
|
||||
_template_vehicle_chunk_handlers,
|
||||
NULL,
|
||||
};
|
||||
|
||||
@@ -1265,6 +1271,7 @@ static size_t ReferenceToInt(const void *obj, SLRefType rt)
|
||||
switch (rt) {
|
||||
case REF_VEHICLE_OLD: // Old vehicles we save as new ones
|
||||
case REF_VEHICLE: return ((const Vehicle*)obj)->index + 1;
|
||||
case REF_TEMPLATE_VEHICLE: return ((const TemplateVehicle*)obj)->index + 1;
|
||||
case REF_STATION: return ((const Station*)obj)->index + 1;
|
||||
case REF_TOWN: return ((const Town*)obj)->index + 1;
|
||||
case REF_ORDER: return ((const Order*)obj)->index + 1;
|
||||
@@ -1324,6 +1331,10 @@ static void *IntToReference(size_t index, SLRefType rt)
|
||||
if (Vehicle::IsValidID(index)) return Vehicle::Get(index);
|
||||
SlErrorCorrupt("Referencing invalid Vehicle");
|
||||
|
||||
case REF_TEMPLATE_VEHICLE:
|
||||
if (TemplateVehicle::IsValidID(index)) return TemplateVehicle::Get(index);
|
||||
SlErrorCorrupt("Referencing invalid TemplateVehicle");
|
||||
|
||||
case REF_STATION:
|
||||
if (Station::IsValidID(index)) return Station::Get(index);
|
||||
SlErrorCorrupt("Referencing invalid Station");
|
||||
|
@@ -88,6 +88,7 @@ enum SLRefType {
|
||||
REF_STORAGE = 9, ///< Load/save a reference to a persistent storage.
|
||||
REF_LINK_GRAPH = 10, ///< Load/save a reference to a link graph.
|
||||
REF_LINK_GRAPH_JOB = 11, ///< Load/save a reference to a link graph job.
|
||||
REF_TEMPLATE_VEHICLE = 12, ///< Load/save a reference to a template vehicle
|
||||
};
|
||||
|
||||
/** Highest possible savegame version. */
|
||||
|
@@ -28,6 +28,7 @@ const SaveLoad *GetBaseStationDescription();
|
||||
|
||||
void AfterLoadVehicles(bool part_of_load);
|
||||
void FixupTrainLengths();
|
||||
void AfterLoadTemplateVehicles();
|
||||
void AfterLoadStations();
|
||||
void AfterLoadRoadStops();
|
||||
void AfterLoadLabelMaps();
|
||||
|
35
src/saveload/tbtr_template_replacement_sl.cpp
Normal file
35
src/saveload/tbtr_template_replacement_sl.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "../tbtr_template_vehicle.h"
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
static const SaveLoad _template_replacement_desc[] = {
|
||||
SLE_VAR(TemplateReplacement, sel_template, SLE_UINT16),
|
||||
SLE_VAR(TemplateReplacement, group, SLE_UINT16),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void Save_TMPL_RPLS()
|
||||
{
|
||||
TemplateReplacement *tr;
|
||||
|
||||
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
|
||||
SlSetArrayIndex(tr->index);
|
||||
SlObject(tr, _template_replacement_desc);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_TMPL_RPLS()
|
||||
{
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
TemplateReplacement *tr = new (index) TemplateReplacement();
|
||||
SlObject(tr, _template_replacement_desc);
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _template_replacement_chunk_handlers[] = {
|
||||
{'TRPL', Save_TMPL_RPLS, Load_TMPL_RPLS, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
};
|
99
src/saveload/tbtr_template_veh_sl.cpp
Normal file
99
src/saveload/tbtr_template_veh_sl.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "../tbtr_template_vehicle.h"
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
const SaveLoad* GTD() {
|
||||
|
||||
static const SaveLoad _template_veh_desc[] = {
|
||||
SLE_REF(TemplateVehicle, next, REF_TEMPLATE_VEHICLE),
|
||||
|
||||
SLE_VAR(TemplateVehicle, reuse_depot_vehicles, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, keep_remaining_vehicles, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, refit_as_template, SLE_UINT8),
|
||||
|
||||
SLE_VAR(TemplateVehicle, owner, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, owner_b, SLE_UINT8),
|
||||
|
||||
SLE_VAR(TemplateVehicle, engine_type, SLE_UINT16),
|
||||
SLE_VAR(TemplateVehicle, cargo_type, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, cargo_cap, SLE_UINT16),
|
||||
SLE_VAR(TemplateVehicle, cargo_subtype, SLE_UINT8),
|
||||
|
||||
SLE_VAR(TemplateVehicle, subtype, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, railtype, SLE_UINT8),
|
||||
|
||||
SLE_VAR(TemplateVehicle, index, SLE_UINT32),
|
||||
|
||||
SLE_VAR(TemplateVehicle, real_consist_length, SLE_UINT16),
|
||||
|
||||
SLE_VAR(TemplateVehicle, max_speed, SLE_UINT16),
|
||||
SLE_VAR(TemplateVehicle, power, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, weight, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, max_te, SLE_UINT32),
|
||||
|
||||
SLE_VAR(TemplateVehicle, spritenum, SLE_UINT8),
|
||||
SLE_VAR(TemplateVehicle, cur_image, SLE_UINT32),
|
||||
SLE_VAR(TemplateVehicle, image_width, SLE_UINT32),
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad * const _ret[] = {
|
||||
_template_veh_desc,
|
||||
};
|
||||
|
||||
return _ret[0];
|
||||
}
|
||||
|
||||
static void Save_TMPLS()
|
||||
{
|
||||
TemplateVehicle *tv;
|
||||
|
||||
FOR_ALL_TEMPLATES(tv) {
|
||||
SlSetArrayIndex(tv->index);
|
||||
SlObject(tv, GTD());
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_TMPLS()
|
||||
{
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
TemplateVehicle *tv = new (index) TemplateVehicle(); //TODO:check with veh sl code
|
||||
SlObject(tv, GTD());
|
||||
}
|
||||
}
|
||||
|
||||
static void Ptrs_TMPLS()
|
||||
{
|
||||
TemplateVehicle *tv;
|
||||
FOR_ALL_TEMPLATES(tv) {
|
||||
SlObject(tv, GTD());
|
||||
}
|
||||
}
|
||||
|
||||
void AfterLoadTemplateVehicles()
|
||||
{
|
||||
TemplateVehicle *tv;
|
||||
|
||||
FOR_ALL_TEMPLATES(tv) {
|
||||
/* Reinstate the previous pointer */
|
||||
if (tv->next != NULL) tv->next->previous = tv;
|
||||
tv->first =NULL;
|
||||
}
|
||||
FOR_ALL_TEMPLATES(tv) {
|
||||
/* Fill the first pointers */
|
||||
if (tv->previous == NULL) {
|
||||
for (TemplateVehicle *u = tv; u != NULL; u = u->Next()) {
|
||||
u->first = tv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _template_vehicle_chunk_handlers[] = {
|
||||
{'TMPL', Save_TMPLS, Load_TMPLS, Ptrs_TMPLS, NULL, CH_ARRAY | CH_LAST},
|
||||
};
|
Reference in New Issue
Block a user