Skip to content

Commit

Permalink
Fix OpenTTD#7469: Desync when using build and refit feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterN committed Apr 4, 2019
1 parent 24fc251 commit b904804
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/vehicle_cmd.cpp
Expand Up @@ -31,6 +31,7 @@
#include "ship.h"
#include "newgrf.h"
#include "company_base.h"
#include "core/random_func.hpp"

#include "table/strings.h"

Expand Down Expand Up @@ -131,6 +132,11 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
DoCommandFlag subflags = flags;
if (refitting) subflags |= DC_EXEC;

/* Vehicle construction needs random bits, so we have to save the random
* seeds to prevent desyncs. */
SavedRandomSeeds saved_seeds;
if (flags != subflags) SaveRandomSeeds(&saved_seeds);

Vehicle *v = NULL;
switch (type) {
case VEH_TRAIN: value.AddCost(CmdBuildRailVehicle(tile, subflags, e, GB(p1, 24, 8), &v)); break;
Expand Down Expand Up @@ -179,6 +185,8 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
}

if (flags != subflags) RestoreRandomSeeds(saved_seeds);

return value;
}

Expand Down

0 comments on commit b904804

Please sign in to comment.