(svn r3352) - NewGRF: Move initialization of vehicle random_bits to DC_EXEC blocks to allow use of Random() instead of InteractiveRandom(), which will alleviate some possible network desyncs.
--- a/aircraft_cmd.c Wed Dec 28 09:40:26 2005 +0000
+++ b/aircraft_cmd.c Wed Dec 28 22:29:59 2005 +0000
@@ -265,6 +265,9 @@
v->cur_image = u->cur_image = 0xEA0;
+ v->random_bits = VehicleRandomBits();
+ u->random_bits = VehicleRandomBits();
+
VehiclePositionChanged(v);
VehiclePositionChanged(u);
@@ -286,6 +289,7 @@
w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
w->subtype = 6;
w->cur_image = SPR_ROTOR_STOPPED;
+ w->random_bits = VehicleRandomBits();
VehiclePositionChanged(w);
}
--- a/roadveh_cmd.c Wed Dec 28 09:40:26 2005 +0000
+++ b/roadveh_cmd.c Wed Dec 28 22:29:59 2005 +0000
@@ -187,6 +187,7 @@
v->type = VEH_Road;
v->cur_image = 0xC15;
+ v->random_bits = VehicleRandomBits();
VehiclePositionChanged(v);
--- a/ship_cmd.c Wed Dec 28 09:40:26 2005 +0000
+++ b/ship_cmd.c Wed Dec 28 22:29:59 2005 +0000
@@ -888,6 +888,7 @@
v->build_year = _cur_year;
v->cur_image = 0x0E5E;
v->type = VEH_Ship;
+ v->random_bits = VehicleRandomBits();
VehiclePositionChanged(v);
--- a/train_cmd.c Wed Dec 28 09:40:26 2005 +0000
+++ b/train_cmd.c Wed Dec 28 22:29:59 2005 +0000
@@ -492,6 +492,7 @@
u->subtype = 0;
SetArticulatedPart(u);
u->cur_image = 0xAC2;
+ u->random_bits = VehicleRandomBits();
VehiclePositionChanged(u);
}
@@ -572,6 +573,7 @@
v->build_year = _cur_year;
v->type = VEH_Train;
v->cur_image = 0xAC2;
+ v->random_bits = VehicleRandomBits();
AddArticulatedParts(rvi, vl);
@@ -652,6 +654,7 @@
u->value = v->value;
u->type = VEH_Train;
u->cur_image = 0xAC2;
+ u->random_bits = VehicleRandomBits();
VehiclePositionChanged(u);
}
@@ -746,6 +749,7 @@
v->build_year = _cur_year;
v->type = VEH_Train;
v->cur_image = 0xAC2;
+ v->random_bits = VehicleRandomBits();
v->subtype = 0;
SetFrontEngine(v);
--- a/vehicle.c Wed Dec 28 09:40:26 2005 +0000
+++ b/vehicle.c Wed Dec 28 22:29:59 2005 +0000
@@ -254,16 +254,19 @@
v->next_shared = NULL;
v->prev_shared = NULL;
v->depot_list = NULL;
- /* random_bits is used to pick out a random sprite for vehicles
- which are technical the same (newgrf stuff).
- Because RandomRange() results in desyncs, and because it does
- not really matter that one client has other visual vehicles than
- the other, it can be InteractiveRandomRange() without any problem
- */
- v->random_bits = InteractiveRandomRange(256);
+ v->random_bits = 0;
return v;
}
+/**
+ * Get a value for a vehicle's random_bits.
+ * @return A random value from 0 to 255.
+ */
+byte VehicleRandomBits(void)
+{
+ return GB(Random(), 0, 8);
+}
+
Vehicle *ForceAllocateSpecialVehicle(void)
{
/* This stays a strange story.. there should always be room for special
--- a/vehicle.h Wed Dec 28 09:40:26 2005 +0000
+++ b/vehicle.h Wed Dec 28 22:29:59 2005 +0000
@@ -271,6 +271,7 @@
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z);
void InitializeTrains(void);
+byte VehicleRandomBits(void);
bool CanFillVehicle(Vehicle *v);
bool CanRefitTo(EngineID engine_type, CargoID cid_to);