MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / TestVehicleBuildProbability

Function TestVehicleBuildProbability

src/newgrf_engine.cpp:1251–1258  ·  view source on GitHub ↗

* Test for vehicle build probability type. * @param v Vehicle whose build probability to test. * @param type Build probability type to test for. * @returns True or false depending on the probability result, or std::nullopt if the callback failed. */

Source from the content-addressed store, hash-verified

1249 * @returns True or false depending on the probability result, or std::nullopt if the callback failed.
1250 */
1251std::optional<bool> TestVehicleBuildProbability(Vehicle *v, EngineID engine, BuildProbabilityType type)
1252{
1253 uint16_t p = GetVehicleCallback(CBID_VEHICLE_BUILD_PROBABILITY, to_underlying(type), 0, engine, v);
1254 if (p == CALLBACK_FAILED) return std::nullopt;
1255
1256 const uint16_t PROBABILITY_RANGE = 100;
1257 return p + RandomRange(PROBABILITY_RANGE) >= PROBABILITY_RANGE;
1258}
1259
1260static void DoTriggerVehicleRandomisation(Vehicle *v, VehicleRandomTrigger trigger, uint16_t base_random_bits, bool first)
1261{

Callers 6

BuildReplacementVehicleFunction · 0.85
AddArticulatedPartsFunction · 0.85
CmdBuildRailWagonFunction · 0.85
CmdBuildRailVehicleFunction · 0.85
CmdCloneVehicleFunction · 0.85

Calls 3

GetVehicleCallbackFunction · 0.85
to_underlyingFunction · 0.85
RandomRangeFunction · 0.85

Tested by

no test coverage detected