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:
@@ -661,6 +661,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const
|
||||
|
||||
v->group_id = DEFAULT_GROUP;
|
||||
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(v->flags, VRF_REVERSE_DIRECTION);
|
||||
AddArticulatedParts(v);
|
||||
|
||||
v->UpdatePosition();
|
||||
@@ -728,6 +729,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
|
||||
v->SetMultiheaded();
|
||||
u->SetMultiheaded();
|
||||
v->SetNext(u);
|
||||
if (TestVehicleBuildProbability(u, u->engine_type, BuildProbabilityType::Reversed)) SetBit(u->flags, VRF_REVERSE_DIRECTION);
|
||||
u->UpdatePosition();
|
||||
|
||||
/* Now we need to link the front and rear engines together */
|
||||
@@ -799,6 +801,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engin
|
||||
v->SetFrontEngine();
|
||||
v->SetEngine();
|
||||
|
||||
if (TestVehicleBuildProbability(v, v->engine_type, BuildProbabilityType::Reversed)) SetBit(v->flags, VRF_REVERSE_DIRECTION);
|
||||
v->UpdatePosition();
|
||||
|
||||
if (rvi->railveh_type == RAILVEH_MULTIHEAD) {
|
||||
|
Reference in New Issue
Block a user