diff --git a/src/openrct2/Cheats.cpp b/src/openrct2/Cheats.cpp index 2a5449dc30..bc0f7113a3 100644 --- a/src/openrct2/Cheats.cpp +++ b/src/openrct2/Cheats.cpp @@ -377,9 +377,9 @@ static void cheat_remove_all_guests() ride->last_peep_in_queue[stationIndex] = SPRITE_INDEX_NULL; } - for (size_t trainIndex = 0; trainIndex < 32; trainIndex++) + for (auto trainIndex : ride->vehicles) { - spriteIndex = ride->vehicles[trainIndex]; + spriteIndex = trainIndex; while (spriteIndex != SPRITE_INDEX_NULL) { vehicle = GET_VEHICLE(spriteIndex); @@ -387,9 +387,9 @@ static void cheat_remove_all_guests() vehicle->num_peeps = 0; vehicle->next_free_seat = 0; - for (size_t peepInTrainIndex = 0; peepInTrainIndex < 32; peepInTrainIndex++) + for (auto &peepInTrainIndex : vehicle->peep) { - vehicle->peep[peepInTrainIndex] = SPRITE_INDEX_NULL; + peepInTrainIndex = SPRITE_INDEX_NULL; } spriteIndex = vehicle->next_vehicle_on_train; @@ -460,9 +460,9 @@ static void cheat_own_all_land() } // Completely unown peep spawn points - for (sint32 i = 0; i < MAX_PEEP_SPAWNS; i++) { - sint32 x = gPeepSpawns[i].x; - sint32 y = gPeepSpawns[i].y; + for (const auto &spawn : gPeepSpawns) { + sint32 x = spawn.x; + sint32 y = spawn.y; if (x != PEEP_SPAWN_UNDEFINED) { rct_tile_element * surfaceElement = map_get_surface_element_at(x >> 5, y >> 5); surfaceElement->properties.surface.ownership = OWNERSHIP_UNOWNED; diff --git a/src/openrct2/Editor.cpp b/src/openrct2/Editor.cpp index 83fbfbac62..ac9897917d 100644 --- a/src/openrct2/Editor.cpp +++ b/src/openrct2/Editor.cpp @@ -297,11 +297,11 @@ namespace Editor map_remove_all_rides(); // - for (sint32 i = 0; i < MAX_BANNERS; i++) + for (auto &banner : gBanners) { - if (gBanners[i].type == 255) + if (banner.type == 255) { - gBanners[i].flags &= ~BANNER_FLAG_LINKED_TO_RIDE; + banner.flags &= ~BANNER_FLAG_LINKED_TO_RIDE; } } @@ -551,17 +551,17 @@ namespace Editor } } - for (sint32 i = 0; i < MAX_PARK_ENTRANCES; i++) + for (const auto &parkEntrance : gParkEntrances) { - if (gParkEntrances[i].x == LOCATION_NULL) + if (parkEntrance.x == LOCATION_NULL) { continue; } - sint32 x = gParkEntrances[i].x; - sint32 y = gParkEntrances[i].y; - sint32 z = gParkEntrances[i].z / 8; - sint32 direction = gParkEntrances[i].direction ^2; + sint32 x = parkEntrance.x; + sint32 y = parkEntrance.y; + sint32 z = parkEntrance.z / 8; + sint32 direction = parkEntrance.direction ^ 2; switch (footpath_is_connected_to_map_edge(x, y, z, direction, 0)) { diff --git a/src/openrct2/EditorObjectSelectionSession.cpp b/src/openrct2/EditorObjectSelectionSession.cpp index a8db64b948..1f2ead1eeb 100644 --- a/src/openrct2/EditorObjectSelectionSession.cpp +++ b/src/openrct2/EditorObjectSelectionSession.cpp @@ -48,16 +48,19 @@ static void setup_track_manager_objects() { sint32 numObjects = (sint32)object_repository_get_items_count(); const ObjectRepositoryItem * items = object_repository_get_items(); - for (sint32 i = 0; i < numObjects; i++) { + for (sint32 i = 0; i < numObjects; i++) + { uint8 * selectionFlags = &_objectSelectionFlags[i]; const ObjectRepositoryItem * item = &items[i]; uint8 object_type = item->ObjectEntry.flags & 0xF; - if (object_type == OBJECT_TYPE_RIDE) { + if (object_type == OBJECT_TYPE_RIDE) + { *selectionFlags |= OBJECT_SELECTION_FLAG_6; - for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { - uint8 rideType = item->RideType[j]; - if (rideType != RIDE_TYPE_NULL && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_TRACK)) { + for (auto rideType : item->RideType) + { + if (rideType != RIDE_TYPE_NULL && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_TRACK)) + { *selectionFlags &= ~OBJECT_SELECTION_FLAG_6; break; } @@ -74,17 +77,21 @@ static void setup_track_designer_objects() { sint32 numObjects = (sint32)object_repository_get_items_count(); const ObjectRepositoryItem * items = object_repository_get_items(); - for (sint32 i = 0; i < numObjects; i++) { + for (sint32 i = 0; i < numObjects; i++) + { uint8 * selectionFlags = &_objectSelectionFlags[i]; const ObjectRepositoryItem * item = &items[i]; uint8 objectType = item->ObjectEntry.flags & 0xF; - if (objectType == OBJECT_TYPE_RIDE){ + if (objectType == OBJECT_TYPE_RIDE) + { *selectionFlags |= OBJECT_SELECTION_FLAG_6; - for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { - uint8 rideType = item->RideType[j]; - if (rideType != RIDE_TYPE_NULL) { - if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_SHOW_IN_TRACK_DESIGNER) { + for (uint8 rideType : item->RideType) + { + if (rideType != RIDE_TYPE_NULL) + { + if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_SHOW_IN_TRACK_DESIGNER) + { *selectionFlags &= ~OBJECT_SELECTION_FLAG_6; break; } @@ -268,8 +275,9 @@ static void remove_selected_objects_from_research(const rct_object_entry* instal if (entry_type == OBJECT_TYPE_RIDE){ rct_ride_entry* rideEntry = (rct_ride_entry*)object_entry_groups[entry_type].chunks[entry_index]; - for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { - research_remove(entry_index | rideEntry->ride_type[j] << 8 | 0x10000); + for (auto rideType : rideEntry->ride_type) + { + research_remove(entry_index | rideType << 8 | 0x10000); } } else if (entry_type == OBJECT_TYPE_SCENERY_GROUP){ @@ -308,9 +316,11 @@ void unload_unselected_objects() */ static void window_editor_object_selection_select_default_objects() { - if (_numSelectedObjectsForType[0] == 0) { - for (sint32 i = 0; i < (sint32)Util::CountOf(DefaultSelectedObjects); i++) { - window_editor_object_selection_select_object(0, 7, &DefaultSelectedObjects[i]); + if (_numSelectedObjectsForType[0] == 0) + { + for (const auto &defaultSelectedObject : DefaultSelectedObjects) + { + window_editor_object_selection_select_object(0, 7, &defaultSelectedObject); } } } @@ -333,8 +343,9 @@ static void window_editor_object_selection_select_required_objects() */ void reset_selected_object_count_and_size() { - for (uint8 objectType = 0; objectType < 11; objectType++) { - _numSelectedObjectsForType[objectType] = 0; + for (auto &objectType : _numSelectedObjectsForType) + { + objectType = 0; } sint32 numObjects = (sint32)object_repository_get_items_count(); diff --git a/src/openrct2/Game.cpp b/src/openrct2/Game.cpp index 7c60b4caad..ba97399d6c 100644 --- a/src/openrct2/Game.cpp +++ b/src/openrct2/Game.cpp @@ -1134,14 +1134,12 @@ void game_convert_strings_to_utf8() rct2_to_utf8_self(gScenarioDetails, 256); // User strings - for (sint32 i = 0; i < MAX_USER_STRINGS; i++) + for (auto * string : gUserStrings) { - utf8 * userString = gUserStrings[i]; - - if (!str_is_null_or_empty(userString)) + if (!str_is_null_or_empty(string)) { - rct2_to_utf8_self(userString, RCT12_USER_STRING_MAX_LENGTH); - utf8_remove_formatting(userString, true); + rct2_to_utf8_self(string, RCT12_USER_STRING_MAX_LENGTH); + utf8_remove_formatting(string, true); } } @@ -1174,10 +1172,8 @@ void game_convert_strings_to_rct2(rct_s6_data * s6) utf8_to_rct2_self(s6->scenario_description, sizeof(s6->scenario_description)); // User strings - for (sint32 i = 0; i < MAX_USER_STRINGS; i++) + for (auto * userString : s6->custom_strings) { - char * userString = s6->custom_strings[i]; - if (!str_is_null_or_empty(userString)) { utf8_to_rct2_self(userString, RCT12_USER_STRING_MAX_LENGTH); @@ -1185,13 +1181,11 @@ void game_convert_strings_to_rct2(rct_s6_data * s6) } // News items - for (sint32 i = 0; i < MAX_NEWS_ITEMS; i++) + for (auto &newsItem : s6->news_items) { - rct12_news_item * newsItem = &s6->news_items[i]; - - if (!str_is_null_or_empty(newsItem->Text)) + if (!str_is_null_or_empty(newsItem.Text)) { - utf8_to_rct2_self(newsItem->Text, sizeof(newsItem->Text)); + utf8_to_rct2_self(newsItem.Text, sizeof(newsItem.Text)); } } } diff --git a/src/openrct2/ObjectList.cpp b/src/openrct2/ObjectList.cpp index 1f047a03fc..8c481833fb 100644 --- a/src/openrct2/ObjectList.cpp +++ b/src/openrct2/ObjectList.cpp @@ -148,8 +148,8 @@ sint32 find_object_in_entry_group(const rct_object_entry* entry, uint8* entry_ty void get_type_entry_index(size_t index, uint8 * outObjectType, uint8 * outEntryIndex) { uint8 objectType = OBJECT_TYPE_RIDE; - for (size_t i = 0; i < OBJECT_TYPE_COUNT; i++) { - size_t groupCount = object_entry_group_counts[i]; + for (auto groupCount : object_entry_group_counts) + { if (index >= groupCount) { index -= groupCount; objectType++; diff --git a/src/openrct2/actions/RideCreateAction.hpp b/src/openrct2/actions/RideCreateAction.hpp index 718e60a07f..32318c23e9 100644 --- a/src/openrct2/actions/RideCreateAction.hpp +++ b/src/openrct2/actions/RideCreateAction.hpp @@ -153,9 +153,9 @@ public: ride->queue_time[i] = 0; } - for (size_t i = 0; i < MAX_VEHICLES_PER_RIDE; i++) + for (auto &vehicle : ride->vehicles) { - ride->vehicles[i] = SPRITE_INDEX_NULL; + vehicle = SPRITE_INDEX_NULL; } ride->status = RIDE_STATUS_CLOSED; diff --git a/src/openrct2/actions/RideDemolishAction.hpp b/src/openrct2/actions/RideDemolishAction.hpp index f536d4dcfa..5ca240309e 100644 --- a/src/openrct2/actions/RideDemolishAction.hpp +++ b/src/openrct2/actions/RideDemolishAction.hpp @@ -87,15 +87,14 @@ public: sub_6CB945(_rideIndex); news_item_disable_news(NEWS_ITEM_RIDE, _rideIndex); - for (sint32 i = 0; i < MAX_BANNERS; i++) + for (auto &banner : gBanners) { - rct_banner *banner = &gBanners[i]; - if (banner->type != BANNER_NULL && - banner->flags & BANNER_FLAG_LINKED_TO_RIDE && - banner->colour == _rideIndex) + if (banner.type != BANNER_NULL && + banner.flags & BANNER_FLAG_LINKED_TO_RIDE && + banner.colour == _rideIndex) { - banner->flags &= 0xFB; - banner->string_idx = STR_DEFAULT_SIGN; + banner.flags &= 0xFB; + banner.string_idx = STR_DEFAULT_SIGN; } } diff --git a/src/openrct2/audio/Audio.cpp b/src/openrct2/audio/Audio.cpp index 71ff2b1d62..97eda31ab0 100644 --- a/src/openrct2/audio/Audio.cpp +++ b/src/openrct2/audio/Audio.cpp @@ -306,15 +306,14 @@ void audio_start_title_music() void audio_stop_ride_music() { - for (sint32 i = 0; i < AUDIO_MAX_RIDE_MUSIC; i++) + for (auto &rideMusic : gRideMusicList) { - rct_ride_music * rideMusic = &gRideMusicList[i]; - if (rideMusic->ride_id != RIDE_ID_NULL) + if (rideMusic.ride_id != RIDE_ID_NULL) { - rideMusic->ride_id = RIDE_ID_NULL; - if (rideMusic->sound_channel != nullptr) + rideMusic.ride_id = RIDE_ID_NULL; + if (rideMusic.sound_channel != nullptr) { - Mixer_Stop_Channel(rideMusic->sound_channel); + Mixer_Stop_Channel(rideMusic.sound_channel); } } } @@ -352,9 +351,8 @@ void audio_init_ride_sounds_and_info() sint32 deviceNum = 0; audio_init_ride_sounds(deviceNum); - for (size_t m = 0; m < Util::CountOf(gRideMusicInfoList); m++) + for (auto * rideMusicInfo : gRideMusicInfoList) { - rct_ride_music_info * rideMusicInfo = gRideMusicInfoList[m]; const utf8 * path = context_get_path_legacy(rideMusicInfo->path_id); if (File::Exists(path)) { @@ -382,18 +380,16 @@ void audio_init_ride_sounds_and_info() void audio_init_ride_sounds(sint32 device) { audio_close(); - for (sint32 i = 0; i < AUDIO_MAX_VEHICLE_SOUNDS; i++) + for (auto &vehicleSound : gVehicleSoundList) { - rct_vehicle_sound * vehicleSound = &gVehicleSoundList[i]; - vehicleSound->id = SOUND_ID_NULL; + vehicleSound.id = SOUND_ID_NULL; } gAudioCurrentDevice = device; config_save_default(); - for (sint32 i = 0; i < AUDIO_MAX_RIDE_MUSIC; i++) + for (auto &rideMusic : gRideMusicList) { - rct_ride_music * rideMusic = &gRideMusicList[i]; - rideMusic->ride_id = RIDE_ID_NULL; + rideMusic.ride_id = RIDE_ID_NULL; } } @@ -441,19 +437,18 @@ void audio_stop_vehicle_sounds() return; } - for (size_t i = 0; i < Util::CountOf(gVehicleSoundList); i++) + for (auto &vehicleSound : gVehicleSoundList) { - rct_vehicle_sound * vehicleSound = &gVehicleSoundList[i]; - if (vehicleSound->id != SOUND_ID_NULL) + if (vehicleSound.id != SOUND_ID_NULL) { - vehicleSound->id = SOUND_ID_NULL; - if (vehicleSound->sound1_id != SOUND_ID_NULL) + vehicleSound.id = SOUND_ID_NULL; + if (vehicleSound.sound1_id != SOUND_ID_NULL) { - Mixer_Stop_Channel(vehicleSound->sound1_channel); + Mixer_Stop_Channel(vehicleSound.sound1_channel); } - if (vehicleSound->sound2_id != SOUND_ID_NULL) + if (vehicleSound.sound2_id != SOUND_ID_NULL) { - Mixer_Stop_Channel(vehicleSound->sound2_channel); + Mixer_Stop_Channel(vehicleSound.sound2_channel); } } } diff --git a/src/openrct2/interface/Theme.cpp b/src/openrct2/interface/Theme.cpp index d10f0020ac..cb95d8d5d7 100644 --- a/src/openrct2/interface/Theme.cpp +++ b/src/openrct2/interface/Theme.cpp @@ -234,12 +234,11 @@ static const PredefinedTheme PredefinedThemes[] = { static const WindowThemeDesc * GetWindowThemeDescriptor(rct_windowclass windowClass) { - for (size_t i = 0; i < Util::CountOf(WindowThemeDescriptors); i++) + for (const auto &desc : WindowThemeDescriptors) { - const WindowThemeDesc * desc = &WindowThemeDescriptors[i]; - if (desc->WindowClass == windowClass) + if (desc.WindowClass == windowClass) { - return desc; + return &desc; } } return nullptr; @@ -247,12 +246,11 @@ static const WindowThemeDesc * GetWindowThemeDescriptor(rct_windowclass windowCl static const WindowThemeDesc * GetWindowThemeDescriptor(const utf8 * windowClassSZ) { - for (size_t i = 0; i < Util::CountOf(WindowThemeDescriptors); i++) + for (const auto &desc : WindowThemeDescriptors) { - const WindowThemeDesc * desc = &WindowThemeDescriptors[i]; - if (String::Equals(desc->WindowClassSZ, windowClassSZ)) + if (String::Equals(desc.WindowClassSZ, windowClassSZ)) { - return desc; + return &desc; } } return nullptr; diff --git a/src/openrct2/management/Award.cpp b/src/openrct2/management/Award.cpp index c5d5ba9974..1f6a71eba6 100644 --- a/src/openrct2/management/Award.cpp +++ b/src/openrct2/management/Award.cpp @@ -573,9 +573,9 @@ static bool award_is_deserved_most_dazzling_ride_colours(sint32 awardType, sint3 countedRides++; mainTrackColour = ride->track_colour_main[0]; - for (uint32 j = 0; j < Util::CountOf(dazzling_ride_colours); j++) + for (auto dazzling_ride_colour : dazzling_ride_colours) { - if (mainTrackColour == dazzling_ride_colours[j]) + if (mainTrackColour == dazzling_ride_colour) { colourfulRides++; break; @@ -672,10 +672,10 @@ static bool award_is_deserved(sint32 awardType, sint32 activeAwardTypes) void award_reset() { - for (sint32 i = 0; i < MAX_AWARDS; i++) + for (auto &award : gCurrentAwards) { - gCurrentAwards[i].Time = 0; - gCurrentAwards[i].Type = 0; + award.Time = 0; + award.Type = 0; } } @@ -726,10 +726,10 @@ void award_update_all() } // Decrease award times - for (sint32 i = 0; i < MAX_AWARDS; i++) + for (auto &award : gCurrentAwards) { - if (gCurrentAwards[i].Time != 0) - if (--gCurrentAwards[i].Time == 0) + if (award.Time != 0) + if (--award.Time == 0) window_invalidate_by_class(WC_PARK_INFORMATION); } } diff --git a/src/openrct2/management/NewsItem.cpp b/src/openrct2/management/NewsItem.cpp index c3f39db4a1..4fb22deef6 100644 --- a/src/openrct2/management/NewsItem.cpp +++ b/src/openrct2/management/NewsItem.cpp @@ -90,9 +90,9 @@ void news_item_init_queue() news_item_get(11)->Type = NEWS_ITEM_NULL; // Throttles for warning types (PEEP_*_WARNING) - for (uint32 i = 0; i < Util::CountOf(gPeepWarningThrottle); i++) + for (auto &warningThrottle : gPeepWarningThrottle) { - gPeepWarningThrottle[i] = 0; + warningThrottle = 0; } auto intent = Intent(INTENT_ACTION_INVALIDATE_TICKER_NEWS); diff --git a/src/openrct2/management/Research.cpp b/src/openrct2/management/Research.cpp index c60bfa2f92..b75014ab49 100644 --- a/src/openrct2/management/Research.cpp +++ b/src/openrct2/management/Research.cpp @@ -242,9 +242,9 @@ void research_finish_item(uint32 entryIndex) continue; } - for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) + for (auto rideType : rideEntry2->ride_type) { - if (rideEntry2->ride_type[j] == base_ride_type) + if (rideType == base_ride_type) { ride_entry_set_invented(i); break; @@ -413,19 +413,19 @@ void research_reset_current_item() ebp->category = cat; } - for (sint32 i = 0; i < MAX_RESEARCHED_RIDE_TYPES; ++i) + for (auto &researchedRideType : gResearchedRideTypes) { - gResearchedRideTypes[i] = 0; + researchedRideType = 0; } - for (sint32 i = 0; i < MAX_RESEARCHED_RIDE_ENTRIES; ++i) + for (auto &researchedRideEntry : gResearchedRideEntries) { - gResearchedRideEntries[i] = 0; + researchedRideEntry = 0; } - for (sint32 i = 0; i < MAX_RESEARCHED_SCENERY_ITEMS; i++) + for (auto &researchedSceneryItem : gResearchedSceneryItems) { - gResearchedSceneryItems[i] = 0xFFFFFFFF; + researchedSceneryItem = 0xFFFFFFFF; } for (sint32 i = 0; i < MAX_SCENERY_GROUP_OBJECTS; ++i) @@ -634,9 +634,8 @@ void research_populate_list_random() } sint32 researched = (scenario_rand() & 0xFF) > 128; - for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) + for (auto rideType : rideEntry->ride_type) { - sint32 rideType = rideEntry->ride_type[j]; if (rideType != RIDE_TYPE_NULL) { research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]); @@ -669,9 +668,8 @@ void research_populate_list_researched() continue; } - for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) + for (auto rideType : rideEntry->ride_type) { - sint32 rideType = rideEntry->ride_type[j]; if (rideType != RIDE_TYPE_NULL) { research_insert(true, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]); @@ -742,9 +740,8 @@ void research_insert_ride_entry(uint8 entryIndex, bool researched) { rct_ride_entry * rideEntry = get_ride_entry(entryIndex); uint8 category = rideEntry->category[0]; - for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) + for (auto rideType : rideEntry->ride_type) { - uint8 rideType = rideEntry->ride_type[i]; if (rideType != RIDE_TYPE_NULL) { research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | entryIndex, category); @@ -828,23 +825,23 @@ bool scenery_group_is_invented(sint32 sgIndex) void reset_researched_scenery_items() { - for (sint32 i = 0; i < MAX_RESEARCHED_SCENERY_ITEMS; i++) + for (auto &researchedSceneryItem : gResearchedSceneryItems) { - gResearchedSceneryItems[i] = 0xFFFFFFFF; + researchedSceneryItem = 0xFFFFFFFF; } } void reset_researched_ride_types_and_entries() { // Iteration endpoint used to be 4 for unknown reasons, likely a mistake - for (sint32 i = 0; i < MAX_RESEARCHED_RIDE_TYPES; i++) + for (auto &researchedRideType : gResearchedRideTypes) { - gResearchedRideTypes[i] = 0xFFFFFFFF; + researchedRideType = 0xFFFFFFFF; } - for (sint32 i = 0; i < MAX_RESEARCHED_RIDE_ENTRIES; i++) + for (auto &researchedRideEntry : gResearchedRideEntries) { - gResearchedRideEntries[i] = 0xFFFFFFFF; + researchedRideEntry = 0xFFFFFFFF; } } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index a60ad02626..e7987ab2fd 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -55,9 +55,9 @@ struct ObjectEntryHash size_t operator()(const rct_object_entry &entry) const { uint32 hash = 5381; - for (sint32 i = 0; i < 8; i++) + for (auto i : entry.name) { - hash = ((hash << 5) + hash) + entry.name[i]; + hash = ((hash << 5) + hash) + i; } return hash; } diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 494e0e5d60..5137efbbb3 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -30,9 +30,9 @@ RideObject::~RideObject() { - for (sint32 i = 0; i < 4; i++) + for (auto &peepLoadingPosition : _peepLoadingPositions) { - Memory::Free(_peepLoadingPositions[i]); + Memory::Free(peepLoadingPosition); } } @@ -40,9 +40,9 @@ void RideObject::ReadLegacy(IReadObjectContext * context, IStream * stream) { stream->Seek(8, STREAM_SEEK_CURRENT); _legacyType.flags = stream->ReadValue(); - for (sint32 i = 0; i < RCT2_MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) + for (auto &rideType : _legacyType.ride_type) { - _legacyType.ride_type[i] = stream->ReadValue(); + rideType = stream->ReadValue(); } _legacyType.min_cars_in_train = stream->ReadValue(); _legacyType.max_cars_in_train = stream->ReadValue(); @@ -55,10 +55,9 @@ void RideObject::ReadLegacy(IReadObjectContext * context, IStream * stream) _legacyType.rear_vehicle = stream->ReadValue(); _legacyType.third_vehicle = stream->ReadValue(); _legacyType.pad_019 = stream->ReadValue(); - for (sint32 i = 0; i < RCT2_MAX_VEHICLES_PER_RIDE_ENTRY; i++) + for (auto &vehicleEntry : _legacyType.vehicles) { - rct_ride_entry_vehicle * entry = &_legacyType.vehicles[i]; - ReadLegacyVehicle(context, stream, entry); + ReadLegacyVehicle(context, stream, &vehicleEntry); } stream->Seek(4, STREAM_SEEK_CURRENT); _legacyType.excitement_multiplier = stream->ReadValue(); @@ -317,9 +316,9 @@ void RideObject::DrawPreview(rct_drawpixelinfo * dpi, sint32 width, sint32 heigh { uint32 imageId = _legacyType.images_offset; - for (size_t i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) + for (auto rideType : _legacyType.ride_type) { - if (_legacyType.ride_type[i] != RIDE_TYPE_NULL) + if (rideType != RIDE_TYPE_NULL) break; else imageId++; @@ -442,9 +441,9 @@ void RideObject::PerformFixes() std::string identifier = GetIdentifier(); // Add boosters if the track type is eligible - for (sint32 i = 0; i < RCT2_MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) + for (auto rideType : _legacyType.ride_type) { - if (ride_type_supports_boosters(_legacyType.ride_type[i])) + if (ride_type_supports_boosters(rideType)) { _legacyType.enabledTrackPieces |= (1ULL << TRACK_BOOSTER); } diff --git a/src/openrct2/paint/Paint.cpp b/src/openrct2/paint/Paint.cpp index 413e0a72a4..905169c0fe 100644 --- a/src/openrct2/paint/Paint.cpp +++ b/src/openrct2/paint/Paint.cpp @@ -64,9 +64,9 @@ static void paint_session_init(paint_session * session, rct_drawpixelinfo * dpi) session->NextFreePaintStruct = session->PaintStructs; session->UnkF1AD28 = nullptr; session->UnkF1AD2C = nullptr; - for (sint32 i = 0; i < MAX_PAINT_QUADRANTS; i++) + for (auto &quadrant : session->Quadrants) { - session->Quadrants[i] = nullptr; + quadrant = nullptr; } session->QuadrantBackIndex = -1; session->QuadrantFrontIndex = 0; diff --git a/src/openrct2/paint/tile_element/Surface.cpp b/src/openrct2/paint/tile_element/Surface.cpp index f175f5d92a..0ad1c146d1 100644 --- a/src/openrct2/paint/tile_element/Surface.cpp +++ b/src/openrct2/paint/tile_element/Surface.cpp @@ -1105,17 +1105,15 @@ void surface_paint(paint_session * session, uint8 direction, uint16 height, rct_ gCurrentViewportFlags & VIEWPORT_FLAG_LAND_OWNERSHIP) { const LocationXY16& pos = session->MapPosition; - for (sint32 i = 0; i < MAX_PEEP_SPAWNS; ++i) + for (auto &spawn : gPeepSpawns) { - const rct2_peep_spawn * spawn = &gPeepSpawns[i]; - - if ((spawn->x & 0xFFE0) == pos.x && (spawn->y & 0xFFE0) == pos.y) + if ((spawn.x & 0xFFE0) == pos.x && (spawn.y & 0xFFE0) == pos.y) { - sub_98196C(session, SPR_TERRAIN_SELECTION_SQUARE_SIMPLE, 0, 0, 32, 32, 16, spawn->z * 16, rotation); + sub_98196C(session, SPR_TERRAIN_SELECTION_SQUARE_SIMPLE, 0, 0, 32, 32, 16, spawn.z * 16, rotation); - const sint32 offset = ((spawn->direction ^ 2) + rotation) & 3; + const sint32 offset = ((spawn.direction ^ 2) + rotation) & 3; const uint32 image_id = (PEEP_SPAWN_ARROW_0 + offset) | 0x20380000; - sub_98196C(session, image_id, 0, 0, 32, 32, 19, spawn->z * 16, rotation); + sub_98196C(session, image_id, 0, 0, 32, 32, 19, spawn.z * 16, rotation); } } } @@ -1362,7 +1360,7 @@ void surface_paint(paint_session * session, uint8 direction, uint16 height, rct_ uint8 al = regs.al | regs.ah; - for (sint32 i = 0; i < 4; i++) + for (const auto& fenceData : _tileSurfaceBoundaries) { const sint32 bit = al & 1; al >>= 1; @@ -1370,8 +1368,6 @@ void surface_paint(paint_session * session, uint8 direction, uint16 height, rct_ if (bit == 0) continue; - const tile_surface_boundary_data& fenceData = _tileSurfaceBoundaries[i]; - sint32 local_height = height; sint32 image_id = 0; diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index c4dc61f56c..3f7c5711b2 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -10361,12 +10361,12 @@ static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep bool pathLoop = false; /* Check the peep->pathfind_history to see if this junction has * already been visited by the peep while heading for this goal. */ - for (sint32 i = 0; i < 4; ++i) + for (auto &pathfindHistory : peep->pathfind_history) { - if (peep->pathfind_history[i].x == x >> 5 && peep->pathfind_history[i].y == y >> 5 && - peep->pathfind_history[i].z == z) + if (pathfindHistory.x == x >> 5 && pathfindHistory.y == y >> 5 && + pathfindHistory.z == z) { - if (peep->pathfind_history[i].direction == 0) + if (pathfindHistory.direction == 0) { /* If all directions have already been tried while * heading to this goal, this is a loop. */ @@ -10377,7 +10377,7 @@ static void peep_pathfind_heuristic_search(sint16 x, sint16 y, uint8 z, rct_peep /* The peep remembers walking through this junction * before, but has not yet tried all directions. * Limit the edges to search to those not yet tried. */ - edges &= peep->pathfind_history[i].direction; + edges &= pathfindHistory.direction; } break; } @@ -10633,10 +10633,10 @@ sint32 peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep * pe /* If the peep remembers walking through this junction * previously while heading for its goal, retrieve the * directions it has not yet tried. */ - for (sint32 i = 0; i < 4; ++i) + for (auto &pathfindHistory : peep->pathfind_history) { - if (peep->pathfind_history[i].x == x / 32 && peep->pathfind_history[i].y == y / 32 && - peep->pathfind_history[i].z == z) + if (pathfindHistory.x == x / 32 && pathfindHistory.y == y / 32 && + pathfindHistory.z == z) { /* Fix broken pathfind_history[i].direction @@ -10645,9 +10645,9 @@ sint32 peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep * pe * changes or in earlier code .directions was * initialised to 0xF rather than the permitted * edges. */ - peep->pathfind_history[i].direction &= permitted_edges; + pathfindHistory.direction &= permitted_edges; - edges = peep->pathfind_history[i].direction; + edges = pathfindHistory.direction; #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) @@ -10668,8 +10668,8 @@ sint32 peep_pathfind_choose_direction(sint16 x, sint16 y, uint8 z, rct_peep * pe * the paths or the pathfinding itself * has changed (been fixed) since * the game was saved. */ - peep->pathfind_history[i].direction = permitted_edges; - edges = peep->pathfind_history[i].direction; + pathfindHistory.direction = permitted_edges; + edges = pathfindHistory.direction; #if defined(DEBUG_LEVEL_1) && DEBUG_LEVEL_1 if (gPathFindDebug) @@ -13491,9 +13491,9 @@ static void peep_pick_ride_to_go_on(rct_peep * peep) if (peep->x == LOCATION_NULL) return; - for (uint32 i = 0; i < Util::CountOf(_peepRideConsideration); i++) + for (auto &rideConsideration : _peepRideConsideration) { - _peepRideConsideration[i] = 0; + rideConsideration = 0; } // FIX Originally checked for a toy, likely a mistake and should be a map, @@ -13632,9 +13632,9 @@ static void peep_head_for_nearest_ride_type(rct_peep * peep, sint32 rideType) } } - for (uint32 i = 0; i < Util::CountOf(_peepRideConsideration); i++) + for (auto &rideConsideration : _peepRideConsideration) { - _peepRideConsideration[i] = 0; + rideConsideration = 0; } // FIX Originally checked for a toy,.likely a mistake and should be a map @@ -13764,9 +13764,9 @@ static void peep_head_for_nearest_ride_with_flags(rct_peep * peep, sint32 rideTy return; } - for (uint32 i = 0; i < Util::CountOf(_peepRideConsideration); i++) + for (auto &rideConsideration : _peepRideConsideration) { - _peepRideConsideration[i] = 0; + rideConsideration = 0; } // FIX Originally checked for a toy,.likely a mistake and should be a map diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index c6164e7b42..796d6dfb2c 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -1260,9 +1260,9 @@ private: void FixVehiclePeepLinks(rct_vehicle * vehicle, const uint16 * spriteIndexMap) { - for (int i = 0; i < 32; i++) + for (auto &peep : vehicle->peep) { - vehicle->peep[i] = MapSpriteIndex(vehicle->peep[i], spriteIndexMap); + peep = MapSpriteIndex(peep, spriteIndexMap); } } @@ -1506,9 +1506,9 @@ private: void FixRidePeepLinks(Ride * ride, const uint16 * spriteIndexMap) { - for (sint32 i = 0; i < RCT12_MAX_STATIONS_PER_RIDE; i++) + for (auto &peep : ride->last_peep_in_queue) { - ride->last_peep_in_queue[i] = MapSpriteIndex(ride->last_peep_in_queue[i], spriteIndexMap); + peep = MapSpriteIndex(peep, spriteIndexMap); } ride->mechanic = MapSpriteIndex(ride->mechanic, spriteIndexMap); if (ride->type == RIDE_TYPE_SPIRAL_SLIDE) @@ -1565,12 +1565,11 @@ private: void ImportLitter() { - - for (size_t i = 0; i < RCT1_MAX_SPRITES; i++) + for (auto &sprite : _s4.sprites) { - if (_s4.sprites[i].unknown.sprite_identifier == SPRITE_IDENTIFIER_LITTER) + if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_LITTER) { - rct_litter * srcLitter = &_s4.sprites[i].litter; + rct_litter * srcLitter = &sprite.litter; rct_litter * litter = (rct_litter *) create_sprite(SPRITE_IDENTIFIER_LITTER); move_sprite_to_list((rct_sprite *) litter, SPRITE_LIST_LITTER * 2); @@ -1594,11 +1593,11 @@ private: void ImportMiscSprites() { - for (size_t i = 0; i < RCT1_MAX_SPRITES; i++) + for (auto &sprite : _s4.sprites) { - if (_s4.sprites[i].unknown.sprite_identifier == SPRITE_IDENTIFIER_MISC) + if (sprite.unknown.sprite_identifier == SPRITE_IDENTIFIER_MISC) { - rct1_unk_sprite * src = &_s4.sprites[i].unknown; + rct1_unk_sprite * src = &sprite.unknown; rct_unk_sprite * dst = (rct_unk_sprite *) create_sprite(SPRITE_IDENTIFIER_MISC); move_sprite_to_list((rct_sprite *) dst, SPRITE_LIST_MISC * 2); diff --git a/src/openrct2/ride/CableLift.cpp b/src/openrct2/ride/CableLift.cpp index f3cd46c79c..b57beecfd1 100644 --- a/src/openrct2/ride/CableLift.cpp +++ b/src/openrct2/ride/CableLift.cpp @@ -77,9 +77,9 @@ rct_vehicle * cable_lift_segment_create(sint32 rideIndex, current->scream_sound_id = 0xFF; current->vehicle_sprite_type = 0; current->bank_rotation = 0; - for (sint32 j = 0; j < 32; j++) + for (auto &peep : current->peep) { - current->peep[j] = SPRITE_INDEX_NULL; + peep = SPRITE_INDEX_NULL; } current->var_CD = 0; current->sprite_direction = direction << 3; diff --git a/src/openrct2/ride/Vehicle.cpp b/src/openrct2/ride/Vehicle.cpp index 082abad25e..ca928c4dbd 100644 --- a/src/openrct2/ride/Vehicle.cpp +++ b/src/openrct2/ride/Vehicle.cpp @@ -1028,28 +1028,27 @@ void vehicle_sounds_update() { vehicle_update_sound_params(&get_sprite(i)->vehicle); } - for (uint32 i = 0; i < Util::CountOf(gVehicleSoundList); i++) + for (auto &vehicle_sound : gVehicleSoundList) { - rct_vehicle_sound * vehicle_sound = &gVehicleSoundList[i]; - if (vehicle_sound->id != SOUND_ID_NULL) + if (vehicle_sound.id != SOUND_ID_NULL) { for (rct_vehicle_sound_params * vehicle_sound_params = &gVehicleSoundParamsList[0]; vehicle_sound_params != gVehicleSoundParamsListEnd; vehicle_sound_params++) { - if (vehicle_sound->id == vehicle_sound_params->id) + if (vehicle_sound.id == vehicle_sound_params->id) { goto label26; } } - if (vehicle_sound->sound1_id != SOUND_ID_NULL) + if (vehicle_sound.sound1_id != SOUND_ID_NULL) { - Mixer_Stop_Channel(vehicle_sound->sound1_channel); + Mixer_Stop_Channel(vehicle_sound.sound1_channel); } - if (vehicle_sound->sound2_id != SOUND_ID_NULL) + if (vehicle_sound.sound2_id != SOUND_ID_NULL) { - Mixer_Stop_Channel(vehicle_sound->sound2_channel); + Mixer_Stop_Channel(vehicle_sound.sound2_channel); } - vehicle_sound->id = SOUND_ID_NULL; + vehicle_sound.id = SOUND_ID_NULL; } label26:; } @@ -2310,10 +2309,8 @@ static void vehicle_update_waiting_for_passengers(rct_vehicle * vehicle) if (ride->depart_flags & RIDE_DEPART_LEAVE_WHEN_ANOTHER_ARRIVES) { - - for (sint32 i = 0; i < MAX_VEHICLES_PER_RIDE; ++i) + for (auto train_id : ride->vehicles) { - uint16 train_id = ride->vehicles[i]; if (train_id == SPRITE_INDEX_NULL) continue; @@ -4625,15 +4622,15 @@ static void vehicle_update_boat_location(rct_vehicle * vehicle) } static const sint8 rotations[] = { 0, 1, -1, 2 }; - for (sint32 i = 0; i < 4; i++) + for (auto rotation : rotations) { - if (randDirection + rotations[i] == curDirection) + if (randDirection + rotation == curDirection) { continue; } - sint16 x = vehicle->track_x + TileDirectionDelta[(randDirection + rotations[i]) & 3].x; - sint16 y = vehicle->track_y + TileDirectionDelta[(randDirection + rotations[i]) & 3].y; + sint16 x = vehicle->track_x + TileDirectionDelta[(randDirection + rotation) & 3].x; + sint16 y = vehicle->track_y + TileDirectionDelta[(randDirection + rotation) & 3].y; if (vehicle_is_boat_on_water(vehicle, x, y)) { @@ -6454,10 +6451,10 @@ bool vehicle_update_dodgems_collision(rct_vehicle * vehicle, sint16 x, sint16 y, LocationXY8 location = { static_cast(x / 32), static_cast(y / 32) }; uint8 rideIndex = vehicle->ride; - for (uint32 i = 0; i < Util::CountOf(Unk9A37C4); i++) + for (auto xy_offset : Unk9A37C4) { - location.x += Unk9A37C4[i].x; - location.y += Unk9A37C4[i].y; + location.x += xy_offset.x; + location.y += xy_offset.y; uint16 spriteIdx = sprite_get_first_in_quadrant(location.x * 32, location.y * 32); while (spriteIdx != SPRITE_INDEX_NULL) @@ -7657,10 +7654,10 @@ static bool vehicle_update_motion_collision_detection(rct_vehicle * vehicle, sin bool mayCollide = false; uint16 collideId = SPRITE_INDEX_NULL; rct_vehicle * collideVehicle = NULL; - for (uint32 i = 0; i < Util::CountOf(Unk9A37C4); i++) + for (auto xy_offset : Unk9A37C4) { - location.x += Unk9A37C4[i].x; - location.y += Unk9A37C4[i].y; + location.x += xy_offset.x; + location.y += xy_offset.y; collideId = sprite_get_first_in_quadrant(location.x * 32, location.y * 32); for (; collideId != SPRITE_INDEX_NULL; collideId = collideVehicle->next_in_quadrant) diff --git a/src/openrct2/ride/coaster/VirginiaReel.cpp b/src/openrct2/ride/coaster/VirginiaReel.cpp index 30bdbd97ab..df738898da 100644 --- a/src/openrct2/ride/coaster/VirginiaReel.cpp +++ b/src/openrct2/ride/coaster/VirginiaReel.cpp @@ -214,12 +214,12 @@ void vehicle_visual_virginia_reel(paint_session * session, sint32 x, sint32 imag riding_peep_sprites[((ecx / 8) + i) & 3] = vehicle->peep_tshirt_colours[i]; } sint32 draw_order[4] = { 0, 1, 3, 2 }; - for (uint32 i = 0; i < Util::CountOf(draw_order); i++) + for (auto i : draw_order) { - if (riding_peep_sprites[draw_order[i]] != 0xFF) + if (riding_peep_sprites[i] != 0xFF) { - image_id = (baseImage_id + ((draw_order[i] + 1) * 72)) | - SPRITE_ID_PALETTE_COLOUR_1(riding_peep_sprites[draw_order[i]]); + image_id = (baseImage_id + ((i + 1) * 72)) | + SPRITE_ID_PALETTE_COLOUR_1(riding_peep_sprites[i]); sub_98199C(session, image_id, 0, 0, bb->length_x, bb->length_y, bb->length_z, z, bb->offset_x, bb->offset_y, bb->offset_z + z, rotation); } diff --git a/src/openrct2/world/Entrance.cpp b/src/openrct2/world/Entrance.cpp index cd99dd7bb4..7c3696941d 100644 --- a/src/openrct2/world/Entrance.cpp +++ b/src/openrct2/world/Entrance.cpp @@ -687,17 +687,17 @@ extern "C" void fix_park_entrance_locations(void) { // Fix gParkEntrance locations for which the tile_element no longer exists - for (uint8 entranceNum = 0; entranceNum < MAX_PARK_ENTRANCES; ++entranceNum) + for (auto &entrance : gParkEntrances) { - if (gParkEntrances[entranceNum].x == LOCATION_NULL) + if (entrance.x == LOCATION_NULL) continue; if (map_get_park_entrance_element_at( - gParkEntrances[entranceNum].x, - gParkEntrances[entranceNum].y, - gParkEntrances[entranceNum].z >> 3, false) == NULL) + entrance.x, + entrance.y, + entrance.z >> 3, false) == NULL) { - gParkEntrances[entranceNum].x = LOCATION_NULL; + entrance.x = LOCATION_NULL; } } } diff --git a/src/openrct2/world/MapGen.cpp b/src/openrct2/world/MapGen.cpp index c1f9119a2e..e96ab20639 100644 --- a/src/openrct2/world/MapGen.cpp +++ b/src/openrct2/world/MapGen.cpp @@ -498,9 +498,9 @@ static uint8 perm[512]; static void noise_rand() { - for (uint32 i = 0; i < Util::CountOf(perm); i++) + for (auto &i : perm) { - perm[i] = util_rand() & 0xFF; + i = util_rand() & 0xFF; } }