mirror of https://github.com/OpenTTD/OpenTTD
Add: [NewGRF] Callback for custom refit mask for engines/vehicles.
parent
a3ee05737f
commit
d2496b6ec4
|
@ -9111,6 +9111,25 @@ static void CalculateRefitMasks()
|
|||
/* Apply explicit refit includes/excludes. */
|
||||
ei->refit_mask |= _gted[engine].ctt_include_mask;
|
||||
ei->refit_mask &= ~_gted[engine].ctt_exclude_mask;
|
||||
|
||||
/* Custom refit mask callback. */
|
||||
const GRFFile *file = _gted[e->index].defaultcargo_grf;
|
||||
if (file == nullptr) file = e->GetGRF();
|
||||
if (file != nullptr && HasBit(e->info.callback_mask, CBM_VEHICLE_CUSTOM_REFIT)) {
|
||||
for (const CargoSpec *cs : CargoSpec::Iterate()) {
|
||||
uint8_t local_slot = file->cargo_map[cs->Index()];
|
||||
uint16_t callback = GetVehicleCallback(CBID_VEHICLE_CUSTOM_REFIT, cs->classes, local_slot, engine, nullptr);
|
||||
switch (callback) {
|
||||
case CALLBACK_FAILED:
|
||||
case 0:
|
||||
break; // Do nothing.
|
||||
case 1: SetBit(ei->refit_mask, cs->Index()); break;
|
||||
case 2: ClrBit(ei->refit_mask, cs->Index()); break;
|
||||
|
||||
default: ErrorUnknownCallbackResult(file->grfid, CBID_VEHICLE_CUSTOM_REFIT, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Clear invalid cargoslots (from default vehicles or pre-NewCargo GRFs) */
|
||||
|
|
|
@ -285,6 +285,12 @@ enum CallbackID {
|
|||
|
||||
/** Called to determine probability during build. */
|
||||
CBID_VEHICLE_BUILD_PROBABILITY = 0x162, // 15 bit callback
|
||||
|
||||
/**
|
||||
* Called to get custom engine refit mask. Called once
|
||||
* for each defined cargo after all NewGRFs are loaded.
|
||||
*/
|
||||
CBID_VEHICLE_CUSTOM_REFIT = 0x0163, // 15 bit callback
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -301,6 +307,7 @@ enum VehicleCallbackMask {
|
|||
CBM_VEHICLE_COLOUR_REMAP = 6, ///< Change colour mapping of vehicle
|
||||
CBM_VEHICLE_SOUND_EFFECT = 7, ///< Vehicle uses custom sound effects
|
||||
CBM_VEHICLE_NAME = 8, ///< Engine name
|
||||
CBM_VEHICLE_CUSTOM_REFIT = 9, ///< Custom refit mask
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue