Cleanup: Remove unnecessary VehicleRandomBits()

Simple Random() assignment to byte does the same.
This commit is contained in:
Peter Nelson 2023-04-23 21:22:17 +01:00 committed by PeterN
parent ca497ce356
commit 4a5e413a6c
7 changed files with 10 additions and 19 deletions

View File

@ -344,8 +344,8 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
u->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); u->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
u->random_bits = VehicleRandomBits(); u->random_bits = Random();
v->vehicle_flags = 0; v->vehicle_flags = 0;
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
@ -375,7 +375,7 @@ CommandCost CmdBuildAircraft(DoCommandFlag flags, TileIndex tile, const Engine *
w->spritenum = 0xFF; w->spritenum = 0xFF;
w->subtype = AIR_ROTOR; w->subtype = AIR_ROTOR;
w->sprite_cache.sprite_seq.Set(SPR_ROTOR_STOPPED); w->sprite_cache.sprite_seq.Set(SPR_ROTOR_STOPPED);
w->random_bits = VehicleRandomBits(); w->random_bits = Random();
/* Use rotor's air.state to store the rotor animation frame */ /* Use rotor's air.state to store the rotor animation frame */
w->state = HRS_ROTOR_STOPPED; w->state = HRS_ROTOR_STOPPED;
w->UpdateDeltaXY(); w->UpdateDeltaXY();

View File

@ -8,6 +8,7 @@
/** @file articulated_vehicles.cpp Implementation of articulated vehicles. */ /** @file articulated_vehicles.cpp Implementation of articulated vehicles. */
#include "stdafx.h" #include "stdafx.h"
#include "core/random_func.hpp"
#include "train.h" #include "train.h"
#include "roadveh.h" #include "roadveh.h"
#include "vehicle_func.h" #include "vehicle_func.h"
@ -405,7 +406,7 @@ void AddArticulatedParts(Vehicle *first)
v->engine_type = engine_type; v->engine_type = engine_type;
v->value = 0; v->value = 0;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
if (flip_image) v->spritenum++; if (flip_image) v->spritenum++;

View File

@ -303,7 +303,7 @@ CommandCost CmdBuildRoadVehicle(DoCommandFlag flags, TileIndex tile, const Engin
v->build_year = TimerGameCalendar::year; v->build_year = TimerGameCalendar::year;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
v->SetFrontEngine(); v->SetFrontEngine();
v->roadtype = rt; v->roadtype = rt;

View File

@ -905,7 +905,7 @@ CommandCost CmdBuildShip(DoCommandFlag flags, TileIndex tile, const Engine *e, V
v->date_of_last_service = TimerGameCalendar::date; v->date_of_last_service = TimerGameCalendar::date;
v->build_year = TimerGameCalendar::year; v->build_year = TimerGameCalendar::year;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
v->UpdateCache(); v->UpdateCache();

View File

@ -656,7 +656,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const
v->date_of_last_service = TimerGameCalendar::date; v->date_of_last_service = TimerGameCalendar::date;
v->build_year = TimerGameCalendar::year; v->build_year = TimerGameCalendar::year;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
v->group_id = DEFAULT_GROUP; v->group_id = DEFAULT_GROUP;
@ -721,7 +721,7 @@ static void AddRearEngineToMultiheadedTrain(Train *v)
u->date_of_last_service = v->date_of_last_service; u->date_of_last_service = v->date_of_last_service;
u->build_year = v->build_year; u->build_year = v->build_year;
u->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); u->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
u->random_bits = VehicleRandomBits(); u->random_bits = Random();
v->SetMultiheaded(); v->SetMultiheaded();
u->SetMultiheaded(); u->SetMultiheaded();
v->SetNext(u); v->SetNext(u);
@ -786,7 +786,7 @@ CommandCost CmdBuildRailVehicle(DoCommandFlag flags, TileIndex tile, const Engin
v->date_of_last_service = TimerGameCalendar::date; v->date_of_last_service = TimerGameCalendar::date;
v->build_year = TimerGameCalendar::year; v->build_year = TimerGameCalendar::year;
v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY); v->sprite_cache.sprite_seq.Set(SPR_IMG_QUERY);
v->random_bits = VehicleRandomBits(); v->random_bits = Random();
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE); if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SetBit(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent); v->SetServiceIntervalIsPercent(Company::Get(_current_company)->settings.vehicle.servint_ispercent);

View File

@ -359,15 +359,6 @@ Vehicle::Vehicle(VehicleType type)
this->last_loading_station = INVALID_STATION; this->last_loading_station = INVALID_STATION;
} }
/**
* Get a value for a vehicle's random_bits.
* @return A random value from 0 to 255.
*/
byte VehicleRandomBits()
{
return GB(Random(), 0, 8);
}
/* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash /* Size of the hash, 6 = 64 x 64, 7 = 128 x 128. Larger sizes will (in theory) reduce hash
* lookup times at the expense of memory usage. */ * lookup times at the expense of memory usage. */
const int HASH_BITS = 7; const int HASH_BITS = 7;

View File

@ -50,7 +50,6 @@ uint8 CalcPercentVehicleFilled(const Vehicle *v, StringID *colour);
void VehicleLengthChanged(const Vehicle *u); void VehicleLengthChanged(const Vehicle *u);
byte VehicleRandomBits();
void ResetVehicleHash(); void ResetVehicleHash();
void ResetVehicleColourMap(); void ResetVehicleColourMap();