Part of #12497: Remove extra SPRITE_INDEX_NULL check (#12538)

* refactor: deleted double check of SPRITE_INDEX_NULL in Staff* ride_get_mechanic(Ride* ride)

* refactor: deleted double check of SPRITE_INDEX_NULL in Ride.cpp file

* refactor: deleted double check of SPRITE_INDEX_NULL in windows/Ride.cpp in function static rct_string_id window_ride_get_status_vehicle

* refactor: deleted double check of SPRITE_INDEX_NULL in ride/Ride.cpp

* refactor: deleted double check in FormatStatusTo
This commit is contained in:
Łukasz Pękalski 2020-08-02 09:28:11 +02:00 committed by GitHub
parent f49bfa777a
commit 0f78d452a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 27 deletions

View File

@ -149,6 +149,7 @@ The following people are not part of the development team, but have been contrib
* Deanna Baris (dbaris)
* Chaitanya Thengdi (chaitanyathengdi)
* Sidney Kuyateh (autinerd)
* Łukasz Pękalski (Lukasz-Pe)
## Toolchain
* (Balletie) - macOS

View File

@ -1626,15 +1626,14 @@ rct_window* window_ride_open_vehicle(Vehicle* vehicle)
int32_t numPeepsLeft = vehicle->num_peeps;
for (int32_t i = 0; i < 32 && numPeepsLeft > 0; i++)
{
uint16_t peepSpriteIndex = vehicle->peep[i];
if (peepSpriteIndex == SPRITE_INDEX_NULL)
Peep* peep = GetEntity<Peep>(vehicle->peep[i]);
if (peep != nullptr)
continue;
numPeepsLeft--;
rct_window* w2 = window_find_by_number(WC_PEEP, peepSpriteIndex);
rct_window* w2 = window_find_by_number(WC_PEEP, vehicle->peep[i]);
if (w2 == nullptr)
{
Peep* peep = GetEntity<Peep>(peepSpriteIndex);
auto intent = Intent(WC_PEEP);
intent.putExtra(INTENT_EXTRA_PEEP, peep);
context_open_intent(&intent);
@ -2457,12 +2456,7 @@ static void window_ride_main_update(rct_window* w)
if (w->ride.view <= ride->num_vehicles)
{
int32_t vehicleIndex = w->ride.view - 1;
uint16_t vehicleSpriteIndex = ride->vehicles[vehicleIndex];
if (vehicleSpriteIndex == SPRITE_INDEX_NULL)
return;
Vehicle* vehicle = GetEntity<Vehicle>(vehicleSpriteIndex);
Vehicle* vehicle = GetEntity<Vehicle>(ride->vehicles[w->ride.view - 1]);
if (vehicle == nullptr
|| (vehicle->status != VEHICLE_STATUS_TRAVELLING && vehicle->status != VEHICLE_STATUS_TRAVELLING_CABLE_LIFT
&& vehicle->status != VEHICLE_STATUS_TRAVELLING_DODGEMS
@ -2675,12 +2669,7 @@ static rct_string_id window_ride_get_status_vehicle(rct_window* w, void* argumen
if (ride == nullptr)
return STR_EMPTY;
auto vehicleIndex = w->ride.view - 1;
auto vehicleSpriteIndex = ride->vehicles[vehicleIndex];
if (vehicleSpriteIndex == SPRITE_INDEX_NULL)
return STR_EMPTY;
auto vehicle = GetEntity<Vehicle>(vehicleSpriteIndex);
auto vehicle = GetEntity<Vehicle>(ride->vehicles[w->ride.view - 1]);
if (vehicle == nullptr)
return STR_EMPTY;

View File

@ -835,9 +835,7 @@ void Ride::FormatStatusTo(Formatter& ft) const
{
ft.Add<rct_string_id>(STR_TEST_RUN);
}
else if (
mode == RIDE_MODE_RACE && !(lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING)
&& race_winner != SPRITE_INDEX_NULL)
else if (mode == RIDE_MODE_RACE && !(lifecycle_flags & RIDE_LIFECYCLE_PASS_STATION_NO_STOPPING))
{
auto peep = GetEntity<Peep>(race_winner);
if (peep != nullptr)
@ -2751,15 +2749,10 @@ Peep* find_closest_mechanic(const CoordsXY& entrancePosition, int32_t forInspect
Staff* ride_get_mechanic(Ride* ride)
{
if (ride->mechanic != SPRITE_INDEX_NULL)
auto staff = GetEntity<Staff>(ride->mechanic);
if (staff != nullptr && staff->IsMechanic())
{
auto peep = GetEntity<Peep>(ride->mechanic);
if (peep != nullptr)
{
auto staff = peep->AsStaff();
if (staff != nullptr && staff->IsMechanic())
return staff;
}
return staff;
}
return nullptr;
}