summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2011-11-08 17:25:51 +0000
committerfrosch <frosch@openttd.org>2011-11-08 17:25:51 +0000
commitb374b92bfb06745d21701d398bb0c78a395498b4 (patch)
tree77ffbd443909200f40248d10ae79a792c36b0710
parent48f75a6a8d497aa0764eb298e9059bd075506a05 (diff)
downloadopenttd-b374b92bfb06745d21701d398bb0c78a395498b4.tar.xz
(svn r23145) -Change: [NewGRF v8] Determine the 'first' refittable cargo of vehicles using the cargo ordering from the cargo translation table.
-rw-r--r--src/newgrf.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index f4873e74b..40906a9ce 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -7971,6 +7971,7 @@ static void CalculateRefitMasks()
EngineID engine = e->index;
EngineInfo *ei = &e->info;
bool only_defaultcargo; ///< Set if the vehicle shall carry only the default cargo
+ const uint8 *cargo_map_for_first_refittable = NULL;
/* Did the newgrf specify any refitting? If not, use defaults. */
if (_gted[engine].refitmask_valid) {
@@ -7982,9 +7983,13 @@ static void CalculateRefitMasks()
* Note: After applying the translations, the vehicle may end up carrying no defined cargo. It becomes unavailable in that case. */
only_defaultcargo = (ei->refit_mask == 0 && _gted[engine].cargo_allowed == 0);
+ const GRFFile *file = _gted[engine].refitmask_grf;
+ if (file == NULL) file = e->GetGRF();
+ if (file != NULL && file->grf_version >= 8 && file->cargo_max != 0) {
+ cargo_map_for_first_refittable = file->cargo_map;
+ }
+
if (ei->refit_mask != 0) {
- const GRFFile *file = _gted[engine].refitmask_grf;
- if (file == NULL) file = e->GetGRF();
if (file != NULL && file->cargo_max != 0) {
/* Apply cargo translation table to the refit mask */
uint num_cargo = min(32, file->cargo_max);
@@ -8045,7 +8050,23 @@ static void CalculateRefitMasks()
/* Check if this engine's cargo type is valid. If not, set to the first refittable
* cargo type. Finally disable the vehicle, if there is still no cargo. */
- if (ei->cargo_type == CT_INVALID && ei->refit_mask != 0) ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask);
+ if (ei->cargo_type == CT_INVALID && ei->refit_mask != 0) {
+ if (cargo_map_for_first_refittable == NULL) {
+ /* Use first refittable cargo slot */
+ ei->cargo_type = (CargoID)FindFirstBit(ei->refit_mask);
+ } else {
+ /* Use first refittable cargo from cargo translation table */
+ byte best_local_slot = 0xFF;
+ CargoID cargo_type;
+ FOR_EACH_SET_CARGO_ID(cargo_type, ei->refit_mask) {
+ byte local_slot = cargo_map_for_first_refittable[cargo_type];
+ if (local_slot < best_local_slot) {
+ best_local_slot = local_slot;
+ ei->cargo_type = cargo_type;
+ }
+ }
+ }
+ }
if (ei->cargo_type == CT_INVALID) ei->climates = 0;
/* Clear refit_mask for not refittable ships */