summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2019-04-04 22:37:18 +0100
committerPeterN <peter@fuzzle.org>2019-04-04 23:29:43 +0100
commit8114bad0334f856e2d55be9fb5eb05c46c039960 (patch)
tree744b26905b654d5b4cdb5f698ec9551ec8806077 /src
parentc99f731f89533071669769f3d89950667f3be8f4 (diff)
downloadopenttd-8114bad0334f856e2d55be9fb5eb05c46c039960.tar.xz
Fix #7469: Desync when using build and refit feature.
Diffstat (limited to 'src')
-rw-r--r--src/vehicle_cmd.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 059f60837..eb7fc9654 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -31,6 +31,7 @@
#include "ship.h"
#include "newgrf.h"
#include "company_base.h"
+#include "core/random_func.hpp"
#include "table/strings.h"
@@ -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;
@@ -179,6 +185,8 @@ CommandCost CmdBuildVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
}
+ if (flags != subflags) RestoreRandomSeeds(saved_seeds);
+
return value;
}