mirror of https://github.com/OpenTTD/OpenTTD
(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.
parent
a4de62577d
commit
1ffc700797
|
@ -265,6 +265,9 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
v->cur_image = u->cur_image = 0xEA0;
|
v->cur_image = u->cur_image = 0xEA0;
|
||||||
|
|
||||||
|
v->random_bits = VehicleRandomBits();
|
||||||
|
u->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
VehiclePositionChanged(v);
|
VehiclePositionChanged(v);
|
||||||
VehiclePositionChanged(u);
|
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->vehstatus = VS_HIDDEN | VS_UNCLICKABLE;
|
||||||
w->subtype = 6;
|
w->subtype = 6;
|
||||||
w->cur_image = SPR_ROTOR_STOPPED;
|
w->cur_image = SPR_ROTOR_STOPPED;
|
||||||
|
w->random_bits = VehicleRandomBits();
|
||||||
VehiclePositionChanged(w);
|
VehiclePositionChanged(w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -187,6 +187,7 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
|
|
||||||
v->type = VEH_Road;
|
v->type = VEH_Road;
|
||||||
v->cur_image = 0xC15;
|
v->cur_image = 0xC15;
|
||||||
|
v->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
VehiclePositionChanged(v);
|
VehiclePositionChanged(v);
|
||||||
|
|
||||||
|
|
|
@ -888,6 +888,7 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->build_year = _cur_year;
|
v->build_year = _cur_year;
|
||||||
v->cur_image = 0x0E5E;
|
v->cur_image = 0x0E5E;
|
||||||
v->type = VEH_Ship;
|
v->type = VEH_Ship;
|
||||||
|
v->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
VehiclePositionChanged(v);
|
VehiclePositionChanged(v);
|
||||||
|
|
||||||
|
|
|
@ -492,6 +492,7 @@ static void AddArticulatedParts(const RailVehicleInfo *rvi, Vehicle **vl)
|
||||||
u->subtype = 0;
|
u->subtype = 0;
|
||||||
SetArticulatedPart(u);
|
SetArticulatedPart(u);
|
||||||
u->cur_image = 0xAC2;
|
u->cur_image = 0xAC2;
|
||||||
|
u->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
VehiclePositionChanged(u);
|
VehiclePositionChanged(u);
|
||||||
}
|
}
|
||||||
|
@ -572,6 +573,7 @@ static int32 CmdBuildRailWagon(EngineID engine, TileIndex tile, uint32 flags)
|
||||||
v->build_year = _cur_year;
|
v->build_year = _cur_year;
|
||||||
v->type = VEH_Train;
|
v->type = VEH_Train;
|
||||||
v->cur_image = 0xAC2;
|
v->cur_image = 0xAC2;
|
||||||
|
v->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
AddArticulatedParts(rvi, vl);
|
AddArticulatedParts(rvi, vl);
|
||||||
|
|
||||||
|
@ -652,6 +654,7 @@ void AddRearEngineToMultiheadedTrain(Vehicle *v, Vehicle *u, bool building)
|
||||||
u->value = v->value;
|
u->value = v->value;
|
||||||
u->type = VEH_Train;
|
u->type = VEH_Train;
|
||||||
u->cur_image = 0xAC2;
|
u->cur_image = 0xAC2;
|
||||||
|
u->random_bits = VehicleRandomBits();
|
||||||
VehiclePositionChanged(u);
|
VehiclePositionChanged(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -746,6 +749,7 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
v->build_year = _cur_year;
|
v->build_year = _cur_year;
|
||||||
v->type = VEH_Train;
|
v->type = VEH_Train;
|
||||||
v->cur_image = 0xAC2;
|
v->cur_image = 0xAC2;
|
||||||
|
v->random_bits = VehicleRandomBits();
|
||||||
|
|
||||||
v->subtype = 0;
|
v->subtype = 0;
|
||||||
SetFrontEngine(v);
|
SetFrontEngine(v);
|
||||||
|
|
17
vehicle.c
17
vehicle.c
|
@ -254,16 +254,19 @@ static Vehicle *InitializeVehicle(Vehicle *v)
|
||||||
v->next_shared = NULL;
|
v->next_shared = NULL;
|
||||||
v->prev_shared = NULL;
|
v->prev_shared = NULL;
|
||||||
v->depot_list = NULL;
|
v->depot_list = NULL;
|
||||||
/* random_bits is used to pick out a random sprite for vehicles
|
v->random_bits = 0;
|
||||||
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);
|
|
||||||
return v;
|
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)
|
Vehicle *ForceAllocateSpecialVehicle(void)
|
||||||
{
|
{
|
||||||
/* This stays a strange story.. there should always be room for special
|
/* 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);
|
Vehicle *FindVehicleOnTileZ(TileIndex tile, byte z);
|
||||||
|
|
||||||
void InitializeTrains(void);
|
void InitializeTrains(void);
|
||||||
|
byte VehicleRandomBits(void);
|
||||||
|
|
||||||
bool CanFillVehicle(Vehicle *v);
|
bool CanFillVehicle(Vehicle *v);
|
||||||
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
|
bool CanRefitTo(EngineID engine_type, CargoID cid_to);
|
||||||
|
|
Loading…
Reference in New Issue