Feature: Randomize direction of rail vehicle on build based on probability callback. (#11489)
This allows NewGRF authors to indicate that the game should randomly flip rail vehicles on build, without needing to use random bits nor duplicate sprites to handle it themselves. To use this functionality, test for callback 162 (CBID_VEHICLE_BUILD_PROBABILITY) and var10 = 0 (values other than 0 are reserved for future use), and return a value between 0 and 100 inclusive. The return value is a percentage chance of reversing the vehicle. A value of 0 will always build a forward facing vehicle, and 100 will always build a reverse facing vehicle.
This commit is contained in:
@@ -1192,6 +1192,20 @@ int GetEngineProperty(EngineID engine, PropertyID property, int orig_value, cons
|
||||
return orig_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for vehicle build probablity type.
|
||||
* @param v Vehicle whose build probability to test.
|
||||
* @param type Build probability type to test for.
|
||||
* @returns True iff the probability result says so.
|
||||
*/
|
||||
bool TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
|
||||
{
|
||||
uint16_t p = GetVehicleCallback(CBID_VEHICLE_BUILD_PROBABILITY, std::underlying_type<BuildProbabilityType>::type(type), 0, engine, v);
|
||||
if (p == CALLBACK_FAILED) return false;
|
||||
|
||||
const uint16_t PROBABILITY_RANGE = 100;
|
||||
return p + RandomRange(PROBABILITY_RANGE) >= PROBABILITY_RANGE;
|
||||
}
|
||||
|
||||
static void DoTriggerVehicle(Vehicle *v, VehicleTrigger trigger, uint16_t base_random_bits, bool first)
|
||||
{
|
||||
|
Reference in New Issue
Block a user