|
@@ -484,25 +484,25 @@ static uint32 VehicleGetVariable(const R
|
|
|
{
|
|
|
Vehicle *v = const_cast<Vehicle*>(GRV(object));
|
|
|
|
|
|
if (v == NULL) {
|
|
|
/* Vehicle does not exist, so we're in a purchase list */
|
|
|
switch (variable) {
|
|
|
case 0x43: return _current_company | (LiveryHelper(object->u.vehicle.self_type, NULL) << 24); // Owner information
|
|
|
case 0x46: return 0; // Motion counter
|
|
|
case 0x47: { // Vehicle cargo info
|
|
|
const Engine *e = Engine::Get(object->u.vehicle.self_type);
|
|
|
CargoID cargo_type = e->GetDefaultCargoType();
|
|
|
if (cargo_type != CT_INVALID) {
|
|
|
const CargoSpec *cs = GetCargo(cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(cargo_type);
|
|
|
return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(e->index)->cargo_map[cargo_type];
|
|
|
} else {
|
|
|
return 0x000000FF;
|
|
|
}
|
|
|
}
|
|
|
case 0x48: return Engine::Get(object->u.vehicle.self_type)->flags; // Vehicle Type Info
|
|
|
case 0x49: return _cur_year; // 'Long' format build year
|
|
|
case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year
|
|
|
case 0xDA: return INVALID_VEHICLE; // Next vehicle
|
|
|
case 0xF2: return 0; // Cargo subtype
|
|
|
}
|
|
|
|
|
@@ -540,25 +540,25 @@ static uint32 VehicleGetVariable(const R
|
|
|
uint8 common_subtype = 0xFF; // Return 0xFF if nothing is carried
|
|
|
|
|
|
/* Reset our arrays */
|
|
|
memset(common_cargos, 0, sizeof(common_cargos));
|
|
|
memset(common_subtypes, 0, sizeof(common_subtypes));
|
|
|
|
|
|
for (u = v; u != NULL; u = u->Next()) {
|
|
|
if (v->type == VEH_TRAIN) user_def_data |= Train::From(u)->tcache.user_def_data;
|
|
|
|
|
|
/* Skip empty engines */
|
|
|
if (u->cargo_cap == 0) continue;
|
|
|
|
|
|
cargo_classes |= GetCargo(u->cargo_type)->classes;
|
|
|
cargo_classes |= CargoSpec::Get(u->cargo_type)->classes;
|
|
|
common_cargos[u->cargo_type]++;
|
|
|
}
|
|
|
|
|
|
/* Pick the most common cargo type */
|
|
|
uint common_cargo_best_amount = 0;
|
|
|
for (CargoID cargo = 0; cargo < NUM_CARGO; cargo++) {
|
|
|
if (common_cargos[cargo] > common_cargo_best_amount) {
|
|
|
common_cargo_best_amount = common_cargos[cargo];
|
|
|
common_cargo_type = cargo;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -570,25 +570,25 @@ static uint32 VehicleGetVariable(const R
|
|
|
common_subtypes[u->cargo_subtype]++;
|
|
|
}
|
|
|
|
|
|
/* Pick the most common subcargo type*/
|
|
|
uint common_subtype_best_amount = 0;
|
|
|
for (uint i = 0; i < lengthof(common_subtypes); i++) {
|
|
|
if (common_subtypes[i] > common_subtype_best_amount) {
|
|
|
common_subtype_best_amount = common_subtypes[i];
|
|
|
common_subtype = i;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : GetCargo(common_cargo_type)->bitnum);
|
|
|
uint8 common_bitnum = (common_cargo_type == CT_INVALID ? 0xFF : CargoSpec::Get(common_cargo_type)->bitnum);
|
|
|
v->vcache.cached_var42 = cargo_classes | (common_bitnum << 8) | (common_subtype << 16) | (user_def_data << 24);
|
|
|
SetBit(v->vcache.cache_valid, 2);
|
|
|
}
|
|
|
return v->vcache.cached_var42;
|
|
|
|
|
|
case 0x43: // Company information
|
|
|
if (!HasBit(v->vcache.cache_valid, 3)) {
|
|
|
v->vcache.cached_var43 = v->owner | (Company::IsHumanID(v->owner) ? 0 : 0x10000) | (LiveryHelper(v->engine_type, v) << 24);
|
|
|
SetBit(v->vcache.cache_valid, 3);
|
|
|
}
|
|
|
return v->vcache.cached_var43;
|
|
|
|
|
@@ -643,25 +643,25 @@ static uint32 VehicleGetVariable(const R
|
|
|
}
|
|
|
|
|
|
case 0x46: // Motion counter
|
|
|
return v->motion_counter;
|
|
|
|
|
|
case 0x47: { // Vehicle cargo info
|
|
|
/* Format: ccccwwtt
|
|
|
* tt - the cargo type transported by the vehicle,
|
|
|
* translated if a translation table has been installed.
|
|
|
* ww - cargo unit weight in 1/16 tons, same as cargo prop. 0F.
|
|
|
* cccc - the cargo class value of the cargo transported by the vehicle.
|
|
|
*/
|
|
|
const CargoSpec *cs = GetCargo(v->cargo_type);
|
|
|
const CargoSpec *cs = CargoSpec::Get(v->cargo_type);
|
|
|
|
|
|
return (cs->classes << 16) | (cs->weight << 8) | GetEngineGRF(v->engine_type)->cargo_map[v->cargo_type];
|
|
|
}
|
|
|
|
|
|
case 0x48: return Engine::Get(v->engine_type)->flags; // Vehicle Type Info
|
|
|
case 0x49: return v->build_year;
|
|
|
|
|
|
/* Variables which use the parameter */
|
|
|
case 0x60: // Count consist's engine ID occurance
|
|
|
//EngineID engine = GetNewEngineID(GetEngineGRF(v->engine_type), v->type, parameter);
|
|
|
if (v->type != VEH_TRAIN) return Engine::Get(v->engine_type)->internal_id == parameter;
|
|
|
|