Mercurial > hg > openttd
changeset 2804:0aefdd86456b draft
(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.
author | peter1138 <peter1138@openttd.org> |
---|---|
date | Wed, 28 Dec 2005 22:29:59 +0000 |
parents | 078b4099f2c3 |
children | d72403d38246 |
files | aircraft_cmd.c roadveh_cmd.c ship_cmd.c train_cmd.c vehicle.c vehicle.h |
diffstat | 6 files changed, 21 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/aircraft_cmd.c +++ b/aircraft_cmd.c @@ -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 +++ b/roadveh_cmd.c @@ -187,6 +187,7 @@ v->type = VEH_Road; v->cur_image = 0xC15; + v->random_bits = VehicleRandomBits(); VehiclePositionChanged(v);
--- a/ship_cmd.c +++ b/ship_cmd.c @@ -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 +++ b/train_cmd.c @@ -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 +++ b/vehicle.c @@ -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