Remove rest of FOR_ALL_RIDES instances

This commit is contained in:
Ted John 2019-08-04 16:00:15 +01:00
parent e23638548a
commit a863c7ae50
18 changed files with 328 additions and 445 deletions

View File

@ -54,7 +54,6 @@ ForEachMacros:
- FOR_ALL_PEEPS
- FOR_ALL_GUESTS
- FOR_ALL_STAFF
- FOR_ALL_RIDES
IncludeBlocks: 'Regroup'
IncludeCategories:
- Regex: '^"'

View File

@ -1030,20 +1030,17 @@ static void window_editor_objective_options_rides_resize(rct_window* w)
*/
static void window_editor_objective_options_rides_update(rct_window* w)
{
int32_t i, numItems;
Ride* ride;
w->frame_no++;
window_event_invalidate_call(w);
window_event_resize_call(w);
widget_invalidate(w, WIDX_TAB_2);
numItems = 0;
FOR_ALL_RIDES (i, ride)
auto numItems = 0;
for (auto& ride : GetRideManager())
{
if (ride->IsRide())
if (ride.IsRide())
{
w->list_item_positions[numItems] = i;
w->list_item_positions[numItems] = ride.id;
numItems++;
}
}

View File

@ -177,25 +177,23 @@ rct_window* window_new_campaign_open(int16_t campaignType)
*/
static void window_new_campaign_get_shop_items()
{
int32_t i, numItems;
Ride* ride;
uint64_t items = 0;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
continue;
auto itemType = rideEntry->shop_item;
if (itemType != SHOP_ITEM_NONE && shop_item_is_food_or_drink(itemType))
{
items |= 1ULL << itemType;
}
}
uint8_t itemType = rideEntry->shop_item;
if (itemType != SHOP_ITEM_NONE && shop_item_is_food_or_drink(itemType))
items |= 1ULL << itemType;
}
//
numItems = 0;
for (i = 0; i < 64; i++)
auto numItems = 0;
for (auto i = 0; i < 64; i++)
{
if (items & (1ULL << i))
{

View File

@ -442,77 +442,59 @@ private:
void FixBrokenRides() const
{
ride_id_t rideIndex;
Ride* ride;
FOR_ALL_RIDES (rideIndex, ride)
for (auto& ride : GetRideManager())
{
if ((ride->mechanic_status != RIDE_MECHANIC_STATUS_FIXING)
&& (ride->lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)))
if ((ride.mechanic_status != RIDE_MECHANIC_STATUS_FIXING)
&& (ride.lifecycle_flags & (RIDE_LIFECYCLE_BREAKDOWN_PENDING | RIDE_LIFECYCLE_BROKEN_DOWN)))
{
auto mechanic = ride_get_assigned_mechanic(ride);
auto mechanic = ride_get_assigned_mechanic(&ride);
if (mechanic != nullptr)
{
mechanic->RemoveFromRide();
}
ride_fix_breakdown(ride, 0);
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST;
ride_fix_breakdown(&ride, 0);
ride.window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST;
}
}
}
void RenewRides() const
{
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
ride->Renew();
ride.Renew();
}
window_invalidate_by_class(WC_RIDE);
}
void MakeDestructible() const
{
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE)
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK)
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
ride.lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE;
ride.lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
}
window_invalidate_by_class(WC_RIDE);
}
void ResetRideCrashStatus() const
{
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
// Reset crash status
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_CRASHED;
// Reset crash history
ride->last_crash_type = RIDE_CRASH_TYPE_NONE;
// Reset crash status and history
ride.lifecycle_flags &= ~RIDE_LIFECYCLE_CRASHED;
ride.last_crash_type = RIDE_CRASH_TYPE_NONE;
}
window_invalidate_by_class(WC_RIDE);
}
void Set10MinuteInspection() const
{
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
// Set inspection interval to 10 minutes
ride->inspection_interval = RIDE_INSPECTION_EVERY_10_MINUTES;
ride.inspection_interval = RIDE_INSPECTION_EVERY_10_MINUTES;
}
window_invalidate_by_class(WC_RIDE);
}
@ -654,36 +636,34 @@ private:
void RemoveAllGuests() const
{
Peep* peep;
rct_vehicle* vehicle;
uint16_t spriteIndex, nextSpriteIndex;
ride_id_t rideIndex;
Ride* ride;
FOR_ALL_RIDES (rideIndex, ride)
for (auto& ride : GetRideManager())
{
ride->num_riders = 0;
ride.num_riders = 0;
for (size_t stationIndex = 0; stationIndex < MAX_STATIONS; stationIndex++)
{
ride->stations[stationIndex].QueueLength = 0;
ride->stations[stationIndex].LastPeepInQueue = SPRITE_INDEX_NULL;
ride.stations[stationIndex].QueueLength = 0;
ride.stations[stationIndex].LastPeepInQueue = SPRITE_INDEX_NULL;
}
for (auto trainIndex : ride->vehicles)
for (auto trainIndex : ride.vehicles)
{
spriteIndex = trainIndex;
while (spriteIndex != SPRITE_INDEX_NULL)
{
vehicle = GET_VEHICLE(spriteIndex);
auto vehicle = GET_VEHICLE(spriteIndex);
for (size_t i = 0, offset = 0; i < vehicle->num_peeps; i++)
{
while (vehicle->peep[i + offset] == SPRITE_INDEX_NULL)
{
offset++;
}
peep = GET_PEEP(vehicle->peep[i + offset]);
vehicle->mass -= peep->mass;
auto peep = GET_PEEP(vehicle->peep[i + offset]);
if (peep != nullptr)
{
vehicle->mass -= peep->mass;
}
}
for (auto& peepInTrainIndex : vehicle->peep)
@ -701,7 +681,7 @@ private:
for (spriteIndex = gSpriteListHead[SPRITE_LIST_PEEP]; spriteIndex != SPRITE_INDEX_NULL; spriteIndex = nextSpriteIndex)
{
peep = &(get_sprite(spriteIndex)->peep);
auto peep = &(get_sprite(spriteIndex)->peep);
nextSpriteIndex = peep->next;
if (peep->type == PEEP_TYPE_GUEST)
{

View File

@ -368,11 +368,9 @@ static int32_t cc_rides(InteractiveConsole& console, const arguments_t& argv)
auto price = arg1;
if (int_valid[0])
{
uint16_t rideId{};
Ride* ride;
FOR_ALL_RIDES (rideId, ride)
for (const auto& ride : GetRideManager())
{
auto rideSetPrice = RideSetPriceAction(rideId, price, true);
auto rideSetPrice = RideSetPriceAction(ride.id, price, true);
GameActions::Execute(&rideSetPrice);
}
}

View File

@ -18,6 +18,8 @@
#include "../world/Park.h"
#include "NewsItem.h"
#include <algorithm>
#define NEGATIVE 0
#define POSITIVE 1
@ -144,20 +146,16 @@ static bool award_is_deserved_most_tidy(int32_t activeAwardTypes)
/** At least 6 open roller coasters. */
static bool award_is_deserved_best_rollercoasters([[maybe_unused]] int32_t activeAwardTypes)
{
int32_t i, rollerCoasters;
Ride* ride;
rct_ride_entry* rideEntry;
rollerCoasters = 0;
FOR_ALL_RIDES (i, ride)
auto rollerCoasters = 0;
for (const auto& ride : GetRideManager())
{
rideEntry = get_ride_entry(ride->subtype);
auto rideEntry = ride.GetRideEntry();
if (rideEntry == nullptr)
{
continue;
}
if (ride->status != RIDE_STATUS_OPEN || (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
if (ride.status != RIDE_STATUS_OPEN || (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
{
continue;
}
@ -169,7 +167,6 @@ static bool award_is_deserved_best_rollercoasters([[maybe_unused]] int32_t activ
rollerCoasters++;
}
return (rollerCoasters >= 6);
}
@ -250,12 +247,10 @@ static bool award_is_deserved_worst_value(int32_t activeAwardTypes)
/** No more than 2 people who think the vandalism is bad and no crashes. */
static bool award_is_deserved_safest([[maybe_unused]] int32_t activeAwardTypes)
{
int32_t i, peepsWhoDislikeVandalism;
uint16_t spriteIndex;
Peep* peep;
Ride* ride;
peepsWhoDislikeVandalism = 0;
auto peepsWhoDislikeVandalism = 0;
FOR_ALL_GUESTS (spriteIndex, peep)
{
if (peep->outside_of_park != 0)
@ -268,10 +263,12 @@ static bool award_is_deserved_safest([[maybe_unused]] int32_t activeAwardTypes)
return false;
// Check for rides that have crashed maybe?
FOR_ALL_RIDES (i, ride)
const auto& rideManager = GetRideManager();
if (std::any_of(rideManager.begin(), rideManager.end(), [](const Ride& ride) {
return ride.last_crash_type != RIDE_CRASH_TYPE_NONE;
}))
{
if (ride->last_crash_type != RIDE_CRASH_TYPE_NONE)
return false;
return false;
}
return true;
@ -310,36 +307,28 @@ static bool award_is_deserved_best_staff(int32_t activeAwardTypes)
/** At least 7 shops, 4 unique, one shop per 128 guests and no more than 12 hungry guests. */
static bool award_is_deserved_best_food(int32_t activeAwardTypes)
{
int32_t i, hungryPeeps, shops, uniqueShops;
uint64_t shopTypes;
Ride* ride;
rct_ride_entry* rideEntry;
uint16_t spriteIndex;
Peep* peep;
if (activeAwardTypes & (1 << PARK_AWARD_WORST_FOOD))
return false;
shops = 0;
uniqueShops = 0;
shopTypes = 0;
FOR_ALL_RIDES (i, ride)
auto shops = 0;
auto uniqueShops = 0;
auto shopTypes = 0;
for (const auto& ride : GetRideManager())
{
if (ride->status != RIDE_STATUS_OPEN)
if (ride.status != RIDE_STATUS_OPEN)
continue;
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_SELLS_FOOD))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_SELLS_FOOD))
continue;
shops++;
rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
auto rideEntry = get_ride_entry(ride.subtype);
if (rideEntry != nullptr)
{
continue;
}
if (!(shopTypes & (1ULL << rideEntry->shop_item)))
{
shopTypes |= (1ULL << rideEntry->shop_item);
uniqueShops++;
if (!(shopTypes & (1ULL << rideEntry->shop_item)))
{
shopTypes |= (1ULL << rideEntry->shop_item);
uniqueShops++;
}
}
}
@ -347,7 +336,9 @@ static bool award_is_deserved_best_food(int32_t activeAwardTypes)
return false;
// Count hungry peeps
hungryPeeps = 0;
auto hungryPeeps = 0;
uint16_t spriteIndex;
Peep* peep;
FOR_ALL_GUESTS (spriteIndex, peep)
{
if (peep->outside_of_park != 0)
@ -356,43 +347,34 @@ static bool award_is_deserved_best_food(int32_t activeAwardTypes)
if (peep->thoughts[0].freshness <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY)
hungryPeeps++;
}
return (hungryPeeps <= 12);
}
/** No more than 2 unique shops, less than one shop per 256 guests and more than 15 hungry guests. */
static bool award_is_deserved_worst_food(int32_t activeAwardTypes)
{
int32_t i, hungryPeeps, shops, uniqueShops;
uint64_t shopTypes;
Ride* ride;
rct_ride_entry* rideEntry;
uint16_t spriteIndex;
Peep* peep;
if (activeAwardTypes & (1 << PARK_AWARD_BEST_FOOD))
return false;
shops = 0;
uniqueShops = 0;
shopTypes = 0;
FOR_ALL_RIDES (i, ride)
auto shops = 0;
auto uniqueShops = 0;
auto shopTypes = 0;
for (const auto& ride : GetRideManager())
{
if (ride->status != RIDE_STATUS_OPEN)
if (ride.status != RIDE_STATUS_OPEN)
continue;
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_SELLS_FOOD))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_SELLS_FOOD))
continue;
shops++;
rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
continue;
}
if (!(shopTypes & (1ULL << rideEntry->shop_item)))
{
shopTypes |= (1ULL << rideEntry->shop_item);
uniqueShops++;
if (!(shopTypes & (1ULL << rideEntry->shop_item)))
{
shopTypes |= (1ULL << rideEntry->shop_item);
uniqueShops++;
}
}
}
@ -400,7 +382,9 @@ static bool award_is_deserved_worst_food(int32_t activeAwardTypes)
return false;
// Count hungry peeps
hungryPeeps = 0;
auto hungryPeeps = 0;
uint16_t spriteIndex;
Peep* peep;
FOR_ALL_GUESTS (spriteIndex, peep)
{
if (peep->outside_of_park != 0)
@ -409,25 +393,17 @@ static bool award_is_deserved_worst_food(int32_t activeAwardTypes)
if (peep->thoughts[0].freshness <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_HUNGRY)
hungryPeeps++;
}
return (hungryPeeps > 15);
}
/** At least 4 restrooms, 1 restroom per 128 guests and no more than 16 guests who think they need the restroom. */
static bool award_is_deserved_best_restrooms([[maybe_unused]] int32_t activeAwardTypes)
{
uint32_t i, numRestrooms, guestsWhoNeedRestroom;
Ride* ride;
uint16_t spriteIndex;
Peep* peep;
// Count open restrooms
numRestrooms = 0;
FOR_ALL_RIDES (i, ride)
{
if (ride->type == RIDE_TYPE_TOILETS && ride->status == RIDE_STATUS_OPEN)
numRestrooms++;
}
const auto& rideManager = GetRideManager();
auto numRestrooms = std::count_if(rideManager.begin(), rideManager.end(), [](const Ride& ride) {
return ride.type == RIDE_TYPE_TOILETS && ride.status == RIDE_STATUS_OPEN;
});
// At least 4 open restrooms
if (numRestrooms < 4)
@ -438,7 +414,9 @@ static bool award_is_deserved_best_restrooms([[maybe_unused]] int32_t activeAwar
return false;
// Count number of guests who are thinking they need the restroom
guestsWhoNeedRestroom = 0;
auto guestsWhoNeedRestroom = 0;
uint16_t spriteIndex;
Peep* peep;
FOR_ALL_GUESTS (spriteIndex, peep)
{
if (peep->outside_of_park != 0)
@ -447,35 +425,30 @@ static bool award_is_deserved_best_restrooms([[maybe_unused]] int32_t activeAwar
if (peep->thoughts[0].freshness <= 5 && peep->thoughts[0].type == PEEP_THOUGHT_TYPE_BATHROOM)
guestsWhoNeedRestroom++;
}
return (guestsWhoNeedRestroom <= 16);
}
/** More than half of the rides have satisfaction <= 6 and park rating <= 650. */
static bool award_is_deserved_most_disappointing(int32_t activeAwardTypes)
{
uint32_t i, countedRides, disappointingRides;
Ride* ride;
if (activeAwardTypes & (1 << PARK_AWARD_BEST_VALUE))
return false;
if (gParkRating > 650)
return false;
// Count the number of disappointing rides
countedRides = 0;
disappointingRides = 0;
FOR_ALL_RIDES (i, ride)
auto countedRides = 0;
auto disappointingRides = 0;
for (const auto& ride : GetRideManager())
{
if (ride->excitement == RIDE_RATING_UNDEFINED || ride->popularity == 0xFF)
continue;
countedRides++;
// Unpopular
if (ride->popularity <= 6)
disappointingRides++;
if (ride_has_ratings(&ride) && ride.popularity != 0xFF)
{
countedRides++;
if (ride.popularity <= 6)
{
disappointingRides++;
}
}
}
// Half of the rides are disappointing
@ -485,20 +458,16 @@ static bool award_is_deserved_most_disappointing(int32_t activeAwardTypes)
/** At least 6 open water rides. */
static bool award_is_deserved_best_water_rides([[maybe_unused]] int32_t activeAwardTypes)
{
int32_t i, waterRides;
Ride* ride;
rct_ride_entry* rideEntry;
waterRides = 0;
FOR_ALL_RIDES (i, ride)
auto waterRides = 0;
for (const auto& ride : GetRideManager())
{
rideEntry = get_ride_entry(ride->subtype);
auto rideEntry = ride.GetRideEntry();
if (rideEntry == nullptr)
{
continue;
}
if (ride->status != RIDE_STATUS_OPEN || (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
if (ride.status != RIDE_STATUS_OPEN || (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
{
continue;
}
@ -517,22 +486,19 @@ static bool award_is_deserved_best_water_rides([[maybe_unused]] int32_t activeAw
/** At least 6 custom designed rides. */
static bool award_is_deserved_best_custom_designed_rides(int32_t activeAwardTypes)
{
int32_t i, customDesignedRides;
Ride* ride;
if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
return false;
customDesignedRides = 0;
FOR_ALL_RIDES (i, ride)
auto customDesignedRides = 0;
for (const auto& ride : GetRideManager())
{
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_TRACK))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_HAS_TRACK))
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_NOT_CUSTOM_DESIGN)
continue;
if (ride->excitement < RIDE_RATING(5, 50))
if (ride.excitement < RIDE_RATING(5, 50))
continue;
if (ride->status != RIDE_STATUS_OPEN || (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
if (ride.status != RIDE_STATUS_OPEN || (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
continue;
customDesignedRides++;
@ -541,29 +507,25 @@ static bool award_is_deserved_best_custom_designed_rides(int32_t activeAwardType
return (customDesignedRides >= 6);
}
/** At least 5 colourful rides and more than half of the rides are colourful. */
static constexpr const uint8_t dazzling_ride_colours[] = { COLOUR_BRIGHT_PURPLE, COLOUR_BRIGHT_GREEN, COLOUR_LIGHT_ORANGE,
COLOUR_BRIGHT_PINK };
static bool award_is_deserved_most_dazzling_ride_colours(int32_t activeAwardTypes)
{
int32_t i, countedRides, colourfulRides;
Ride* ride;
uint8_t mainTrackColour;
/** At least 5 colourful rides and more than half of the rides are colourful. */
static constexpr const colour_t dazzling_ride_colours[] = { COLOUR_BRIGHT_PURPLE, COLOUR_BRIGHT_GREEN, COLOUR_LIGHT_ORANGE,
COLOUR_BRIGHT_PINK };
if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
return false;
countedRides = 0;
colourfulRides = 0;
FOR_ALL_RIDES (i, ride)
auto countedRides = 0;
auto colourfulRides = 0;
for (const auto& ride : GetRideManager())
{
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_TRACK))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_HAS_TRACK))
continue;
countedRides++;
mainTrackColour = ride->track_colour[0].main;
auto mainTrackColour = ride.track_colour[0].main;
for (auto dazzling_ride_colour : dazzling_ride_colours)
{
if (mainTrackColour == dazzling_ride_colour)
@ -603,20 +565,16 @@ static bool award_is_deserved_most_confusing_layout([[maybe_unused]] int32_t act
/** At least 10 open gentle rides. */
static bool award_is_deserved_best_gentle_rides([[maybe_unused]] int32_t activeAwardTypes)
{
int32_t i, gentleRides;
Ride* ride;
rct_ride_entry* rideEntry;
gentleRides = 0;
FOR_ALL_RIDES (i, ride)
auto gentleRides = 0;
for (const auto& ride : GetRideManager())
{
rideEntry = get_ride_entry(ride->subtype);
auto rideEntry = ride.GetRideEntry();
if (rideEntry == nullptr)
{
continue;
}
if (ride->status != RIDE_STATUS_OPEN || (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
if (ride.status != RIDE_STATUS_OPEN || (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED))
{
continue;
}

View File

@ -179,30 +179,27 @@ void finance_pay_interest()
*/
void finance_pay_ride_upkeep()
{
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_EVER_BEEN_OPENED))
if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_EVER_BEEN_OPENED))
{
ride->Renew();
ride.Renew();
}
if (ride->status != RIDE_STATUS_CLOSED && !(gParkFlags & PARK_FLAGS_NO_MONEY))
if (ride.status != RIDE_STATUS_CLOSED && !(gParkFlags & PARK_FLAGS_NO_MONEY))
{
int16_t upkeep = ride->upkeep_cost;
int16_t upkeep = ride.upkeep_cost;
if (upkeep != -1)
{
ride->total_profit -= upkeep;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
ride.total_profit -= upkeep;
ride.window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
finance_payment(upkeep, RCT_EXPENDITURE_TYPE_RIDE_RUNNING_COSTS);
}
}
if (ride->last_crash_type != RIDE_CRASH_TYPE_NONE)
if (ride.last_crash_type != RIDE_CRASH_TYPE_NONE)
{
ride->last_crash_type--;
ride.last_crash_type--;
}
}
}
@ -283,13 +280,11 @@ void finance_update_daily_profit()
current_profit -= current_loan / 600;
// Ride costs
Ride* ride;
int32_t i;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->status != RIDE_STATUS_CLOSED && ride->upkeep_cost != MONEY16_UNDEFINED)
if (ride.status != RIDE_STATUS_CLOSED && ride.upkeep_cost != MONEY16_UNDEFINED)
{
current_profit -= 2 * ride->upkeep_cost;
current_profit -= 2 * ride.upkeep_cost;
}
}
}

View File

@ -161,10 +161,6 @@ void marketing_set_guest_campaign(Peep* peep, int32_t campaignType)
bool marketing_is_campaign_type_applicable(int32_t campaignType)
{
int32_t i;
Ride* ride;
rct_ride_entry* rideEntry;
switch (campaignType)
{
case ADVERTISING_CAMPAIGN_PARK_ENTRY_FREE:
@ -180,9 +176,9 @@ bool marketing_is_campaign_type_applicable(int32_t campaignType)
// fall-through
case ADVERTISING_CAMPAIGN_RIDE:
// Check if any rides exist
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->IsRide())
if (ride.IsRide())
{
return true;
}
@ -191,17 +187,16 @@ bool marketing_is_campaign_type_applicable(int32_t campaignType)
case ADVERTISING_CAMPAIGN_FOOD_OR_DRINK_FREE:
// Check if any food or drink stalls exist
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
continue;
}
if (shop_item_is_food_or_drink(rideEntry->shop_item)
|| shop_item_is_food_or_drink(rideEntry->shop_item_secondary))
{
return true;
if (shop_item_is_food_or_drink(rideEntry->shop_item)
|| shop_item_is_food_or_drink(rideEntry->shop_item_secondary))
{
return true;
}
}
}
return false;

View File

@ -1912,13 +1912,11 @@ std::bitset<MAX_RIDES> Guest::FindRidesToGoOn()
if (item_standard_flags & PEEP_ITEM_MAP)
{
// Consider rides that peep hasn't been on yet
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (!HasRidden(ride))
if (!HasRidden(&ride))
{
rideConsideration[i] = true;
rideConsideration[ride.id] = true;
}
}
}
@ -1951,13 +1949,11 @@ std::bitset<MAX_RIDES> Guest::FindRidesToGoOn()
}
// Always take the tall rides into consideration (realistic as you can usually see them from anywhere in the park)
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->highest_drop_height > 66 || ride->excitement >= RIDE_RATING(8, 00))
if (ride.highest_drop_height > 66 || ride.excitement >= RIDE_RATING(8, 00))
{
rideConsideration[i] = true;
rideConsideration[ride.id] = true;
}
}
}
@ -3154,8 +3150,6 @@ static void peep_leave_park(Peep* peep)
*/
static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
{
Ride* ride;
if (peep->state != PEEP_STATE_SITTING && peep->state != PEEP_STATE_WATCHING && peep->state != PEEP_STATE_WALKING)
{
return;
@ -3166,8 +3160,8 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
return;
if (peep->guest_heading_to_ride_id != RIDE_ID_NULL)
{
ride = get_ride(peep->guest_heading_to_ride_id);
if (ride->type == rideType)
auto ride = get_ride(peep->guest_heading_to_ride_id);
if (ride != nullptr && ride->type == rideType)
{
return;
}
@ -3179,12 +3173,11 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
if ((peep->item_standard_flags & PEEP_ITEM_MAP) && rideType != RIDE_TYPE_FIRST_AID)
{
// Consider all rides in the park
int32_t i;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->type == rideType)
if (ride.type == rideType)
{
rideConsideration[i >> 5] |= (1u << (i & 0x1F));
rideConsideration[ride.id >> 5] |= (1u << (ride.id & 0x1F));
}
}
}
@ -3206,8 +3199,8 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
continue;
ride_id_t rideIndex = tileElement->AsTrack()->GetRideIndex();
ride = get_ride(rideIndex);
if (ride->type == rideType)
auto ride = get_ride(rideIndex);
if (ride != nullptr && ride->type == rideType)
{
rideConsideration[rideIndex >> 5] |= (1u << (rideIndex & 0x1F));
}
@ -3226,8 +3219,8 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
if (!(rideConsideration[i >> 5] & (1u << (i & 0x1F))))
continue;
ride = get_ride(i);
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL))
auto ride = get_ride(i);
if (ride != nullptr && !(ride->lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL))
{
if (peep->ShouldGoOnRide(ride, 0, false, true))
{
@ -3242,14 +3235,17 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
int32_t closestRideDistance = std::numeric_limits<int32_t>::max();
for (int32_t i = 0; i < numPotentialRides; i++)
{
ride = get_ride(potentialRides[i]);
int32_t rideX = ride->stations[0].Start.x * 32;
int32_t rideY = ride->stations[0].Start.y * 32;
int32_t distance = abs(rideX - peep->x) + abs(rideY - peep->y);
if (distance < closestRideDistance)
auto ride = get_ride(potentialRides[i]);
if (ride != nullptr)
{
closestRideIndex = potentialRides[i];
closestRideDistance = distance;
int32_t rideX = ride->stations[0].Start.x * 32;
int32_t rideY = ride->stations[0].Start.y * 32;
int32_t distance = abs(rideX - peep->x) + abs(rideY - peep->y);
if (distance < closestRideDistance)
{
closestRideIndex = potentialRides[i];
closestRideDistance = distance;
}
}
}
if (closestRideIndex == RIDE_ID_NULL)
@ -3270,8 +3266,6 @@ static void peep_head_for_nearest_ride_type(Guest* peep, int32_t rideType)
*/
static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeFlags)
{
Ride* ride;
if (peep->state != PEEP_STATE_SITTING && peep->state != PEEP_STATE_WATCHING && peep->state != PEEP_STATE_WALKING)
{
return;
@ -3282,8 +3276,9 @@ static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeF
return;
if (peep->guest_heading_to_ride_id != RIDE_ID_NULL)
{
ride = get_ride(peep->guest_heading_to_ride_id);
if (ride_type_has_flag(
auto ride = get_ride(peep->guest_heading_to_ride_id);
if (ride != nullptr
&& ride_type_has_flag(
ride->type, RIDE_TYPE_FLAG_IS_BATHROOM | RIDE_TYPE_FLAG_SELLS_DRINKS | RIDE_TYPE_FLAG_SELLS_FOOD))
{
return;
@ -3301,12 +3296,11 @@ static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeF
if (peep->item_standard_flags & PEEP_ITEM_MAP)
{
// Consider all rides in the park
int32_t i;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride_type_has_flag(ride->type, rideTypeFlags))
if (ride_type_has_flag(ride.type, rideTypeFlags))
{
rideConsideration[i >> 5] |= (1u << (i & 0x1F));
rideConsideration[ride.id >> 5] |= (1u << (ride.id & 0x1F));
}
}
}
@ -3328,8 +3322,8 @@ static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeF
continue;
ride_id_t rideIndex = tileElement->AsTrack()->GetRideIndex();
ride = get_ride(rideIndex);
if (ride_type_has_flag(ride->type, rideTypeFlags))
auto ride = get_ride(rideIndex);
if (ride != nullptr && ride_type_has_flag(ride->type, rideTypeFlags))
{
rideConsideration[rideIndex >> 5] |= (1u << (rideIndex & 0x1F));
}
@ -3348,8 +3342,8 @@ static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeF
if (!(rideConsideration[i >> 5] & (1u << (i & 0x1F))))
continue;
ride = get_ride(i);
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL))
auto ride = get_ride(i);
if (ride != nullptr && !(ride->lifecycle_flags & RIDE_LIFECYCLE_QUEUE_FULL))
{
if (peep->ShouldGoOnRide(ride, 0, false, true))
{
@ -3364,14 +3358,17 @@ static void peep_head_for_nearest_ride_with_flags(Guest* peep, int32_t rideTypeF
int32_t closestRideDistance = std::numeric_limits<int32_t>::max();
for (int32_t i = 0; i < numPotentialRides; i++)
{
ride = get_ride(potentialRides[i]);
int32_t rideX = ride->stations[0].Start.x * 32;
int32_t rideY = ride->stations[0].Start.y * 32;
int32_t distance = abs(rideX - peep->x) + abs(rideY - peep->y);
if (distance < closestRideDistance)
auto ride = get_ride(potentialRides[i]);
if (ride != nullptr)
{
closestRideIndex = potentialRides[i];
closestRideDistance = distance;
int32_t rideX = ride->stations[0].Start.x * 32;
int32_t rideY = ride->stations[0].Start.y * 32;
int32_t distance = abs(rideX - peep->x) + abs(rideY - peep->y);
if (distance < closestRideDistance)
{
closestRideIndex = potentialRides[i];
closestRideDistance = distance;
}
}
}
if (closestRideIndex == RIDE_ID_NULL)

View File

@ -1081,16 +1081,14 @@ private:
void FixRideVehicleLinks(const uint16_t* spriteIndexMap)
{
uint8_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
for (uint8_t j = 0; j < std::size(ride->vehicles); j++)
for (uint8_t j = 0; j < std::size(ride.vehicles); j++)
{
uint16_t originalIndex = ride->vehicles[j];
uint16_t originalIndex = ride.vehicles[j];
if (originalIndex != SPRITE_INDEX_NULL)
{
ride->vehicles[j] = spriteIndexMap[originalIndex];
ride.vehicles[j] = spriteIndexMap[originalIndex];
}
}
}
@ -1368,15 +1366,13 @@ private:
}
}
int i;
Ride* ride;
Peep* peep;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
FixRidePeepLinks(ride, spriteIndexMap);
FixRidePeepLinks(&ride, spriteIndexMap);
}
int32_t i;
Peep* peep;
FOR_ALL_GUESTS (i, peep)
{
FixPeepNextInQueue(peep, spriteIndexMap);
@ -3018,13 +3014,11 @@ private:
*/
void SetDefaultNames()
{
ride_id_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->custom_name.empty())
if (ride.custom_name.empty())
{
ride->SetNameToDefault();
ride.SetNameToDefault();
}
}
}

View File

@ -868,7 +868,7 @@ void Ride::FormatStatusTo(void* argsV) const
}
}
int32_t ride_get_total_length(Ride* ride)
int32_t ride_get_total_length(const Ride* ride)
{
int32_t i, totalLength = 0;
for (i = 0; i < ride->num_stations; i++)

View File

@ -1016,7 +1016,7 @@ struct RideManager
size_t _endIndex{};
public:
using difference_type = ride_id_t;
using difference_type = intptr_t;
using value_type = Ride;
using pointer = const Ride*;
using reference = const Ride&;
@ -1147,7 +1147,7 @@ void ride_remove_peeps(Ride* ride);
void ride_clear_blocked_tiles(Ride* ride);
Staff* ride_get_mechanic(Ride* ride);
Staff* ride_get_assigned_mechanic(Ride* ride);
int32_t ride_get_total_length(Ride* ride);
int32_t ride_get_total_length(const Ride* ride);
int32_t ride_get_total_time(Ride* ride);
TrackColour ride_get_track_colour(Ride* ride, int32_t colourScheme);
vehicle_colour ride_get_vehicle_colour(Ride* ride, int32_t vehicleIndex);
@ -1283,8 +1283,4 @@ LocationXY16 ride_get_rotated_coords(int16_t x, int16_t y, int16_t z);
void determine_ride_entrance_and_exit_locations();
void ride_clear_leftover_entrances(Ride* ride);
#define FOR_ALL_RIDES(i, ride) \
for (auto& __ride : GetRideManager()) \
if ((ride = &__ride) != nullptr && (i = __ride.id) != RIDE_ID_NULL)
#endif

View File

@ -809,14 +809,10 @@ static void ride_ratings_calculate_value(Ride* ride)
}
// Other ride of same type penalty
int32_t otherRidesOfSameType = 0;
Ride* ride2;
int32_t i;
FOR_ALL_RIDES (i, ride2)
{
if (ride2->type == ride->type && ride2->status == RIDE_STATUS_OPEN)
otherRidesOfSameType++;
}
const auto& rideManager = GetRideManager();
auto otherRidesOfSameType = std::count_if(rideManager.begin(), rideManager.end(), [ride](const Ride& r) {
return r.status == RIDE_STATUS_OPEN && r.type == ride->type;
});
if (otherRidesOfSameType > 1)
value -= value / 4;
@ -2005,9 +2001,9 @@ static void ride_ratings_calculate_boat_hire(Ride* ride)
ride->unreliability_factor = 7;
set_unreliability_factor(ride);
// NOTE In the original game, the ratings were zeroed before calling set_unreliability_factor which is unusual as rest of
// the calculation functions do this before hand. This is because set_unreliability_factor alters the value of
// ebx (excitement). This is assumed to be a bug and therefore fixed.
// NOTE In the original game, the ratings were zeroed before calling set_unreliability_factor which is unusual as rest
// of the calculation functions do this before hand. This is because set_unreliability_factor alters the value of ebx
// (excitement). This is assumed to be a bug and therefore fixed.
rating_tuple ratings;
ride_ratings_set(&ratings, RIDE_RATING(1, 90), RIDE_RATING(0, 80), RIDE_RATING(0, 90));

View File

@ -78,30 +78,26 @@ const ShopItemDescriptor ShopItems[SHOP_ITEM_COUNT] = {
money32 shop_item_get_common_price(Ride* forRide, int32_t shopItem)
{
rct_ride_entry* rideEntry;
Ride* ride;
int32_t i;
FOR_ALL_RIDES (i, ride)
for (const auto& ride : GetRideManager())
{
if (ride != forRide)
if (&ride != forRide)
{
rideEntry = get_ride_entry(ride->subtype);
auto rideEntry = ride.GetRideEntry();
if (rideEntry == nullptr)
{
continue;
}
if (rideEntry->shop_item == shopItem)
{
return ride->price;
return ride.price;
}
if (rideEntry->shop_item_secondary == shopItem)
{
return ride->price_secondary;
return ride.price_secondary;
}
if (shop_item_is_photo(shopItem) && (ride->lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO))
if (shop_item_is_photo(shopItem) && (ride.lifecycle_flags & RIDE_LIFECYCLE_ON_RIDE_PHOTO))
{
return ride->price_secondary;
return ride.price_secondary;
}
}
}

View File

@ -49,6 +49,7 @@
#include "ScenarioSources.h"
#include <algorithm>
#include <bitset>
const rct_string_id ScenarioCategoryStringIds[SCENARIO_CATEGORY_COUNT] = {
STR_BEGINNER_PARKS, STR_CHALLENGING_PARKS, STR_EXPERT_PARKS, STR_REAL_PARKS, STR_OTHER_PARKS,
@ -516,24 +517,23 @@ uint32_t scenario_rand_max(uint32_t max)
static bool scenario_prepare_rides_for_save()
{
int32_t isFiveCoasterObjective = gScenarioObjectiveType == OBJECTIVE_FINISH_5_ROLLERCOASTERS;
int32_t i;
Ride* ride;
uint8_t rcs = 0;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
const rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
// If there are more than 5 roller coasters, only mark the first five.
if (isFiveCoasterObjective && rideEntry != nullptr
&& (ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER) && rcs < 5))
const auto* rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
ride->lifecycle_flags |= RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
rcs++;
}
else
{
ride->lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
// If there are more than 5 roller coasters, only mark the first five.
if (isFiveCoasterObjective && (ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER) && rcs < 5))
{
ride.lifecycle_flags |= RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
rcs++;
}
else
{
ride.lifecycle_flags &= ~RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK;
}
}
}
@ -554,7 +554,7 @@ static bool scenario_prepare_rides_for_save()
if (isFiveCoasterObjective)
{
ride = get_ride(it.element->AsTrack()->GetRideIndex());
auto ride = get_ride(it.element->AsTrack()->GetRideIndex());
// In the previous step, this flag was set on the first five roller coasters.
if (ride != nullptr && ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK)
@ -733,30 +733,27 @@ static void scenario_objective_check_park_value_by()
**/
static void scenario_objective_check_10_rollercoasters()
{
int32_t i, rcs = 0;
uint8_t type_already_counted[256] = {};
Ride* ride;
FOR_ALL_RIDES (i, ride)
auto rcs = 0;
std::bitset<RIDE_TYPE_COUNT> type_already_counted;
for (const auto& ride : GetRideManager())
{
uint8_t subtype_id = ride->subtype;
rct_ride_entry* rideEntry = get_ride_entry(subtype_id);
if (rideEntry == nullptr)
if (ride.status == RIDE_STATUS_OPEN && ride.excitement >= RIDE_RATING(6, 00) && ride.subtype < RIDE_TYPE_COUNT)
{
continue;
}
if (rideEntry != nullptr && ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER)
&& ride->status == RIDE_STATUS_OPEN && ride->excitement >= RIDE_RATING(6, 00)
&& type_already_counted[subtype_id] == 0)
{
type_already_counted[subtype_id]++;
rcs++;
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
if (ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER) && !type_already_counted[ride.subtype])
{
type_already_counted[ride.subtype] = true;
rcs++;
}
}
}
}
if (rcs >= 10)
{
scenario_success();
}
}
/**
@ -830,59 +827,59 @@ static void scenario_objective_check_monthly_ride_income()
*/
static void scenario_objective_check_10_rollercoasters_length()
{
int32_t i, rcs = 0;
uint8_t type_already_counted[256] = {};
int16_t objective_length = gScenarioObjectiveNumGuests;
Ride* ride;
FOR_ALL_RIDES (i, ride)
const auto objective_length = gScenarioObjectiveNumGuests;
std::bitset<RIDE_TYPE_COUNT> type_already_counted;
auto rcs = 0;
for (const auto& ride : GetRideManager())
{
uint8_t subtype_id = ride->subtype;
rct_ride_entry* rideEntry = get_ride_entry(subtype_id);
if (rideEntry == nullptr)
if (ride.status == RIDE_STATUS_OPEN && ride.excitement >= RIDE_RATING(7, 00) && ride.subtype < RIDE_TYPE_COUNT)
{
continue;
}
if (ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER) && ride->status == RIDE_STATUS_OPEN
&& ride->excitement >= RIDE_RATING(7, 00) && type_already_counted[subtype_id] == 0)
{
if ((ride_get_total_length(ride) >> 16) > objective_length)
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
type_already_counted[subtype_id]++;
rcs++;
if (ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER) && !type_already_counted[ride.subtype])
{
if ((ride_get_total_length(&ride) >> 16) > objective_length)
{
type_already_counted[ride.subtype] = true;
rcs++;
}
}
}
}
}
if (rcs >= 10)
{
scenario_success();
}
}
static void scenario_objective_check_finish_5_rollercoasters()
{
money32 objectiveRideExcitement = gScenarioObjectiveCurrency;
const auto objectiveRideExcitement = gScenarioObjectiveCurrency;
// Originally, this did not check for null rides, neither did it check if
// the rides are even rollercoasters, never mind the right rollercoasters to be finished.
int32_t i;
Ride* ride;
int32_t rcs = 0;
FOR_ALL_RIDES (i, ride)
auto rcs = 0;
for (const auto& ride : GetRideManager())
{
const rct_ride_entry* rideEntry = get_ride_entry(ride->subtype);
if (rideEntry == nullptr)
if (ride.status != RIDE_STATUS_CLOSED && ride.excitement >= objectiveRideExcitement)
{
continue;
auto rideEntry = ride.GetRideEntry();
if (rideEntry != nullptr)
{
if ((ride.lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK)
&& ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER))
{
rcs++;
}
}
}
if (ride->status != RIDE_STATUS_CLOSED && ride->excitement >= objectiveRideExcitement
&& (ride->lifecycle_flags & RIDE_LIFECYCLE_INDESTRUCTIBLE_TRACK) && // Set on partially finished coasters
ride_entry_has_category(rideEntry, RIDE_CATEGORY_ROLLERCOASTER))
rcs++;
}
if (rcs >= 5)
{
scenario_success();
}
}
static void scenario_objective_check_replay_loan_and_park_value()

View File

@ -209,8 +209,6 @@ WallElement* banner_get_scrolling_wall_tile_element(BannerIndex bannerIndex)
*/
uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z)
{
Ride* ride;
static constexpr const LocationXY16 NeighbourCheckOrder[] = { { 32, 0 }, { -32, 0 }, { 0, 32 },
{ 0, -32 }, { -32, +32 }, { +32, -32 },
{ +32, +32 }, { -32, +32 }, { 0, 0 } };
@ -224,15 +222,14 @@ uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z)
}
}
uint8_t index;
ride_id_t rideIndex = RIDE_ID_NULL;
int32_t resultDistance = std::numeric_limits<int32_t>::max();
FOR_ALL_RIDES (index, ride)
auto rideIndex = RIDE_ID_NULL;
auto resultDistance = std::numeric_limits<int32_t>::max();
for (auto& ride : GetRideManager())
{
if (ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_IS_SHOP))
if (ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_IS_SHOP))
continue;
LocationXY8 location = ride->overall_view;
LocationXY8 location = ride.overall_view;
if (location.xy == RCT_XY8_UNDEFINED)
continue;
@ -242,10 +239,9 @@ uint8_t banner_get_closest_ride_index(int32_t x, int32_t y, int32_t z)
if (distance < resultDistance)
{
resultDistance = distance;
rideIndex = index;
rideIndex = ride.id;
}
}
return rideIndex;
}

View File

@ -421,16 +421,13 @@ int32_t Park::CalculateParkRating() const
int32_t totalRideUptime = 0;
int32_t totalRideIntensity = 0;
int32_t totalRideExcitement = 0;
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
totalRideUptime += 100 - ride->downtime;
if (ride->excitement != RIDE_RATING_UNDEFINED)
totalRideUptime += 100 - ride.downtime;
if (ride_has_ratings(&ride))
{
totalRideExcitement += ride->excitement / 8;
totalRideIntensity += ride->intensity / 8;
totalRideExcitement += ride.excitement / 8;
totalRideIntensity += ride.intensity / 8;
excitingRideCount++;
}
rideCount++;
@ -524,21 +521,19 @@ money32 Park::CalculateCompanyValue() const
money16 Park::CalculateTotalRideValueForMoney() const
{
money16 totalRideValue = 0;
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->status != RIDE_STATUS_OPEN)
if (ride.status != RIDE_STATUS_OPEN)
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
continue;
// Add ride value
if (ride->value != RIDE_VALUE_UNDEFINED)
if (ride.value != RIDE_VALUE_UNDEFINED)
{
money16 rideValue = (money16)(ride->value - ride->price);
money16 rideValue = (money16)(ride.value - ride.price);
if (rideValue > 0)
{
totalRideValue += rideValue * 2;
@ -553,44 +548,42 @@ uint32_t Park::CalculateSuggestedMaxGuests() const
uint32_t suggestedMaxGuests = 0;
// TODO combine the two ride loops
int32_t i;
Ride* ride;
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->status != RIDE_STATUS_OPEN)
if (ride.status != RIDE_STATUS_OPEN)
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
continue;
// Add guest score for ride type
suggestedMaxGuests += rideBonusValue[ride->type];
suggestedMaxGuests += rideBonusValue[ride.type];
}
// If difficult guest generation, extra guests are available for good rides
if (gParkFlags & PARK_FLAGS_DIFFICULT_GUEST_GENERATION)
{
suggestedMaxGuests = std::min<uint32_t>(suggestedMaxGuests, 1000);
FOR_ALL_RIDES (i, ride)
for (auto& ride : GetRideManager())
{
if (ride->lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_CRASHED)
continue;
if (ride->lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
if (ride.lifecycle_flags & RIDE_LIFECYCLE_BROKEN_DOWN)
continue;
if (!(ride->lifecycle_flags & RIDE_LIFECYCLE_TESTED))
if (!(ride.lifecycle_flags & RIDE_LIFECYCLE_TESTED))
continue;
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_TRACK))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_HAS_TRACK))
continue;
if (!ride_type_has_flag(ride->type, RIDE_TYPE_FLAG_HAS_DATA_LOGGING))
if (!ride_type_has_flag(ride.type, RIDE_TYPE_FLAG_HAS_DATA_LOGGING))
continue;
if (ride->stations[0].SegmentLength < (600 << 16))
if (ride.stations[0].SegmentLength < (600 << 16))
continue;
if (ride->excitement < RIDE_RATING(6, 00))
if (ride.excitement < RIDE_RATING(6, 00))
continue;
// Bonus guests for good ride
suggestedMaxGuests += rideBonusValue[ride->type] * 2;
suggestedMaxGuests += rideBonusValue[ride.type] * 2;
}
}

View File

@ -50,16 +50,16 @@ public:
}
protected:
static Ride* FindRideByName(const char* name, ride_id_t* outRideIndex)
static Ride* FindRideByName(const char* name)
{
Ride* ride;
FOR_ALL_RIDES ((*outRideIndex), ride)
for (auto& ride : GetRideManager())
{
auto thisName = ride->GetName();
auto thisName = ride.GetName();
if (!_strnicmp(thisName.c_str(), name, sizeof(thisName)))
return ride;
{
return &ride;
}
}
return nullptr;
}
@ -197,8 +197,7 @@ TEST_P(SimplePathfindingTest, CanFindPathFromStartToGoal)
ASSERT_PRED_FORMAT1(AssertIsStartPosition, scenario.start);
TileCoordsXYZ pos = scenario.start;
ride_id_t rideIndex;
Ride* ride = FindRideByName(scenario.name, &rideIndex);
auto ride = FindRideByName(scenario.name);
ASSERT_NE(ride, nullptr);
auto entrancePos = ride_get_entrance_location(ride, 0);
@ -206,8 +205,8 @@ TEST_P(SimplePathfindingTest, CanFindPathFromStartToGoal)
entrancePos.x - TileDirectionDelta[entrancePos.direction].x,
entrancePos.y - TileDirectionDelta[entrancePos.direction].y, entrancePos.z);
const auto succeeded = FindPath(&pos, goal, scenario.steps, rideIndex) ? ::testing::AssertionSuccess()
: ::testing::AssertionFailure()
const auto succeeded = FindPath(&pos, goal, scenario.steps, ride->id) ? ::testing::AssertionSuccess()
: ::testing::AssertionFailure()
<< "Failed to find path from " << scenario.start << " to " << goal << " in " << scenario.steps << " steps; reached "
<< pos << " before giving up.";
@ -236,8 +235,7 @@ TEST_P(ImpossiblePathfindingTest, CannotFindPathFromStartToGoal)
TileCoordsXYZ pos = scenario.start;
ASSERT_PRED_FORMAT1(AssertIsStartPosition, scenario.start);
ride_id_t rideIndex;
Ride* ride = FindRideByName(scenario.name, &rideIndex);
auto ride = FindRideByName(scenario.name);
ASSERT_NE(ride, nullptr);
auto entrancePos = ride_get_entrance_location(ride, 0);
@ -245,7 +243,7 @@ TEST_P(ImpossiblePathfindingTest, CannotFindPathFromStartToGoal)
entrancePos.x + TileDirectionDelta[entrancePos.direction].x,
entrancePos.y + TileDirectionDelta[entrancePos.direction].y, entrancePos.z);
EXPECT_FALSE(FindPath(&pos, goal, 10000, rideIndex));
EXPECT_FALSE(FindPath(&pos, goal, 10000, ride->id));
}
INSTANTIATE_TEST_CASE_P(