(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.

pull/155/head
peter1138 19 years ago
parent 139d1ed1eb
commit 901068fd6e

@ -265,6 +265,9 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->cur_image = u->cur_image = 0xEA0;
v->random_bits = VehicleRandomBits();
u->random_bits = VehicleRandomBits();
VehiclePositionChanged(v);
VehiclePositionChanged(u);
@ -286,6 +289,7 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
w->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
w->subtype = 6;
w->cur_image = SPR_ROTOR_STOPPED;
w->random_bits = VehicleRandomBits();
VehiclePositionChanged(w);
}

@ -187,6 +187,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->type = VEH_Road;
v->cur_image = 0xC15;
v->random_bits = VehicleRandomBits();
VehiclePositionChanged(v);

@ -888,6 +888,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->build_year = _cur_year;
v->cur_image = 0x0E5E;
v->type = VEH_Ship;
v->random_bits = VehicleRandomBits();
VehiclePositionChanged(v);

@ -492,6 +492,7 @@ static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl)
u->subtype = 0;
SetArticulatedPart(u);
u->cur_image = 0xAC2;
u->random_bits = VehicleRandomBits();
VehiclePositionChanged(u);
}
@ -572,6 +573,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
v->build_year = _cur_year;
v->type = VEH_Train;
v->cur_image = 0xAC2;
v->random_bits = VehicleRandomBits();
AddArticulatedParts(rvi, vl);
@ -652,6 +654,7 @@ void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building)
u->value = v->value;
u->type = VEH_Train;
u->cur_image = 0xAC2;
u->random_bits = VehicleRandomBits();
VehiclePositionChanged(u);
}
@ -746,6 +749,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
v->build_year = _cur_year;
v->type = VEH_Train;
v->cur_image = 0xAC2;
v->random_bits = VehicleRandomBits();
v->subtype = 0;
SetFrontEngine(v);

@ -254,16 +254,19 @@ static Vehicle *InitializeVehicle(Vehicle *v)
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

@ -271,6 +271,7 @@ void CallVehicleTicks(void);
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z);
void InitializeTrains(void);
byte VehicleRandomBits(void);
bool CanFillVehicle(Vehicle *v);
bool CanRefitTo(EngineID engine_type, CargoID cid_to);

Loading…
Cancel
Save