summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2007-02-24 19:26:45 +0000
committerpeter1138 <peter1138@openttd.org>2007-02-24 19:26:45 +0000
commit0cf5ebee797e7b30232d583e1922b7c8fb07776b (patch)
tree86c90fd6df9d2e03d49fe46198f7eb6fc88803d4
parent12b1804d4e8519b3691a404f3556f80c95142f90 (diff)
downloadopenttd-0cf5ebee797e7b30232d583e1922b7c8fb07776b.tar.xz
(svn r8885) -Codechange: (NewGRF) If a default cargo type property is out of range then choose the cargo type from its refit list.
-rw-r--r--src/newgrf.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index 12e794543..d05e52635 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -364,7 +364,8 @@ static bool RailVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
if (ctype < NUM_CARGO) {
rvi[i].cargo_type = ctype;
} else {
- grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, ignoring", ctype);
+ rvi[i].cargo_type = CT_INVALID;
+ grfmsg(2, "RailVehicleChangeInfo: Invalid cargo type %d, using first refittable", ctype);
}
}
break;
@@ -555,7 +556,8 @@ static bool RoadVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
if (cargo < NUM_CARGO) {
rvi[i].cargo_type = cargo;
} else {
- grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, ignoring", cargo);
+ rvi[i].cargo_type = CT_INVALID;
+ grfmsg(2, "RoadVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
}
}
break;
@@ -665,17 +667,11 @@ static bool ShipVehicleChangeInfo(uint engine, int numinfo, int prop, byte **buf
FOR_EACH_OBJECT {
uint8 cargo = grf_load_byte(&buf);
- // XXX: Need to consult this with patchman yet.
-#if 0
- // Documentation claims this is already the
- // per-landscape cargo type id, but newships.grf
- // assume otherwise.
- cargo = local_cargo_id_ctype[cargo];
-#endif
if (cargo < NUM_CARGO) {
svi[i].cargo_type = cargo;
} else {
- grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, ignoring", cargo);
+ svi[i].cargo_type = CT_INVALID;
+ grfmsg(2, "ShipVehicleChangeInfo: Invalid cargo type %d, using first refittable", cargo);
}
}
break;
@@ -3713,6 +3709,28 @@ static void CalculateRefitMasks(void)
}
}
_engine_info[engine].refit_mask = ((mask & ~not_mask) ^ xor_mask) & _cargo_mask;
+
+ if (_engine_info[engine].refit_mask == 0) continue;
+
+ /* Check if this engine's cargo type is valid. If not, set to the first refittable
+ * cargo type. Apparently cargo_type isn't a common property... */
+ switch (GetEngine(engine)->type) {
+ case VEH_Train: {
+ RailVehicleInfo *rvi = &_rail_vehicle_info[engine];
+ if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
+ break;
+ }
+ case VEH_Road: {
+ RoadVehicleInfo *rvi = &_road_vehicle_info[engine - ROAD_ENGINES_INDEX];
+ if (rvi->cargo_type == CT_INVALID) rvi->cargo_type = FindFirstRefittableCargo(engine);
+ break;
+ }
+ case VEH_Ship: {
+ ShipVehicleInfo *svi = &_ship_vehicle_info[engine - SHIP_ENGINES_INDEX];
+ if (svi->cargo_type == CT_INVALID) svi->cargo_type = FindFirstRefittableCargo(engine);
+ break;
+ }
+ }
}
}