summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2010-03-23 11:05:28 +0000
committerpeter1138 <peter1138@openttd.org>2010-03-23 11:05:28 +0000
commitd790f3db3a30f8b7c0f987a4d434358cf3695a85 (patch)
treebbe2729f7377f62fd8ec4f4b3732468989b825af
parentf13dfb7b2c03ad3a73d5dec1e6c817fd5a91798e (diff)
downloadopenttd-d790f3db3a30f8b7c0f987a4d434358cf3695a85.tar.xz
(svn r19502) -Codechange: During NewGRF loading, store rail type labels in temporary data and process after loading has finished. This avoids deactivated rail vehicles being reactivated if the climate property is set after the rail type property.
-rw-r--r--src/newgrf.cpp35
-rw-r--r--src/rail_type.h5
2 files changed, 28 insertions, 12 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 600578430..6f9b54deb 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -188,6 +188,7 @@ enum {
struct GRFTempEngineData {
uint16 cargo_allowed;
uint16 cargo_disallowed;
+ RailTypeLabel railtypelabel;
bool refitmask_valid; ///< Did the newgrf set any refittability property? If not, default refittability will be applied.
uint8 rv_max_speed; ///< Temporary storage of RV prop 15, maximum speed in mph/0.8
};
@@ -529,20 +530,14 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
uint8 tracktype = buf->ReadByte();
if (tracktype < _cur_grffile->railtype_max) {
- RailType railtype = GetRailTypeByLabel(_cur_grffile->railtype_list[tracktype]);
- if (railtype == INVALID_RAILTYPE) {
- /* Rail type is not available, so disable this engine */
- ei[i].climates = 0x80;
- } else {
- rvi[i].railtype = railtype;
- }
+ _gted[e->index].railtypelabel = _cur_grffile->railtype_list[tracktype];
break;
}
switch (tracktype) {
- case 0: rvi->railtype = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC : RAILTYPE_RAIL; break;
- case 1: rvi->railtype = RAILTYPE_MONO; break;
- case 2: rvi->railtype = RAILTYPE_MAGLEV; break;
+ case 0: _gted[e->index].railtypelabel = rvi->engclass >= 2 ? RAILTYPE_ELECTRIC_LABEL : RAILTYPE_RAIL_LABEL; break;
+ case 1: _gted[e->index].railtypelabel = RAILTYPE_MONO_LABEL; break;
+ case 2: _gted[e->index].railtypelabel = RAILTYPE_MAGLEV_LABEL; break;
default:
grfmsg(1, "RailVehicleChangeInfo: Invalid track type %d specified, ignoring", tracktype);
break;
@@ -663,8 +658,8 @@ static ChangeInfoResult RailVehicleChangeInfo(uint engine, int numinfo, int prop
if (_cur_grffile->railtype_max == 0) {
/* Use traction type to select between normal and electrified
* rail only when no translation list is in place. */
- if (rvi->railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) rvi->railtype = RAILTYPE_ELECTRIC;
- if (rvi->railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) rvi->railtype = RAILTYPE_RAIL;
+ if (rvi->railtype == RAILTYPE_RAIL && engclass >= EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_ELECTRIC_LABEL;
+ if (rvi->railtype == RAILTYPE_ELECTRIC && engclass < EC_ELECTRIC) _gted[e->index].railtypelabel = RAILTYPE_RAIL_LABEL;
}
rvi->engclass = engclass;
@@ -6051,6 +6046,12 @@ static void ResetNewGRFData()
/* Allocate temporary refit/cargo class data */
_gted = CallocT<GRFTempEngineData>(Engine::GetPoolSize());
+ /* Fill rail type label temporary data for default trains */
+ Engine *e;
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ _gted[e->index].railtypelabel = GetRailTypeInfo(e->u.rail.railtype)->label;
+ }
+
/* Reset GRM reservations */
memset(&_grm_engines, 0, sizeof(_grm_engines));
memset(&_grm_cargos, 0, sizeof(_grm_cargos));
@@ -6835,6 +6836,16 @@ static void AfterLoadGRFs()
}
}
+ FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) {
+ RailType railtype = GetRailTypeByLabel(_gted[e->index].railtypelabel);
+ if (railtype == INVALID_RAILTYPE) {
+ /* Rail type is not available, so disable this engine */
+ e->info.climates = 0x80;
+ } else {
+ e->u.rail.railtype = railtype;
+ }
+ }
+
SetYearEngineAgingStops();
FinalisePriceBaseMultipliers();
diff --git a/src/rail_type.h b/src/rail_type.h
index 18a769841..1ad5d9698 100644
--- a/src/rail_type.h
+++ b/src/rail_type.h
@@ -16,6 +16,11 @@
typedef uint32 RailTypeLabel;
+static const RailTypeLabel RAILTYPE_RAIL_LABEL = 'RAIL';
+static const RailTypeLabel RAILTYPE_ELECTRIC_LABEL = 'ELRL';
+static const RailTypeLabel RAILTYPE_MONO_LABEL = 'MONO';
+static const RailTypeLabel RAILTYPE_MAGLEV_LABEL = 'MGLV';
+
/**
* Enumeration for all possible railtypes.
*