mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r15378) -Fix: The subcargo returned by vehicle variable 0x42 should be the most-common-subcargo of the most-common-cargo. If nothing is transported 0x..FFFF00 should be returned.
This commit is contained in:
parent
841050ec83
commit
a5d515bfd6
|
@ -485,9 +485,9 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
case 0x42: { // Consist cargo information
|
case 0x42: { // Consist cargo information
|
||||||
const Vehicle *u;
|
const Vehicle *u;
|
||||||
byte cargo_classes = 0;
|
byte cargo_classes = 0;
|
||||||
uint8 common_cargo_best = 0;
|
CargoID common_cargo_best = CT_INVALID;
|
||||||
uint8 common_cargos[NUM_CARGO];
|
uint8 common_cargos[NUM_CARGO];
|
||||||
uint8 common_subtype_best = 0;
|
uint8 common_subtype_best = 0xFF; // Return 0xFF if nothing is carried
|
||||||
uint8 common_subtypes[256];
|
uint8 common_subtypes[256];
|
||||||
byte user_def_data = 0;
|
byte user_def_data = 0;
|
||||||
CargoID common_cargo_type = CT_PASSENGERS;
|
CargoID common_cargo_type = CT_PASSENGERS;
|
||||||
|
@ -505,17 +505,25 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
|
|
||||||
cargo_classes |= GetCargo(u->cargo_type)->classes;
|
cargo_classes |= GetCargo(u->cargo_type)->classes;
|
||||||
common_cargos[u->cargo_type]++;
|
common_cargos[u->cargo_type]++;
|
||||||
common_subtypes[u->cargo_subtype]++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pick the most common cargo type */
|
/* Pick the most common cargo type */
|
||||||
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
||||||
if (common_cargos[cargo] > common_cargo_best) {
|
if (common_cargos[cargo] > common_cargo_best) {
|
||||||
common_cargo_best = common_cargos[cargo];
|
common_cargo_best = common_cargos[cargo];
|
||||||
common_cargo_type = GetCargo(cargo)->bitnum;
|
common_cargo_type = cargo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Count subcargo types of common_cargo_type */
|
||||||
|
for (u = v; u != NULL; u = u->Next()) {
|
||||||
|
/* Skip empty engines and engines not carrying common_cargo_type */
|
||||||
|
if (u->cargo_cap == 0 || u->cargo_type != common_cargo_type) continue;
|
||||||
|
|
||||||
|
common_subtypes[u->cargo_subtype]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pick the most common subcargo type*/
|
||||||
for (uint i = 0; i < lengthof(common_subtypes); i++) {
|
for (uint i = 0; i < lengthof(common_subtypes); i++) {
|
||||||
if (common_subtypes[i] > common_subtype_best) {
|
if (common_subtypes[i] > common_subtype_best) {
|
||||||
common_subtype_best = common_subtypes[i];
|
common_subtype_best = common_subtypes[i];
|
||||||
|
@ -523,7 +531,8 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return cargo_classes | (common_cargo_type << 8) | (common_subtype << 16) | (user_def_data << 24);
|
uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : GetCargo(common_cargo_type)->bitnum);
|
||||||
|
return cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
case 0x43: // Company information
|
case 0x43: // Company information
|
||||||
|
|
Loading…
Reference in New Issue