From 4059d9e8a7b3919a4c183d9db85b3fa94665399d Mon Sep 17 00:00:00 2001 From: Gymnasiast Date: Wed, 14 Jun 2017 15:08:56 +0200 Subject: [PATCH] Clean up boosters, ride_type_null, max rides per entry, formatting --- src/openrct2/interface/console.c | 2 +- src/openrct2/management/research.c | 6 +++--- src/openrct2/object/ObjectRepository.cpp | 2 +- src/openrct2/object/RideObject.cpp | 12 +++--------- src/openrct2/ride/ride.c | 14 ++++++++++++++ src/openrct2/ride/ride.h | 1 + src/openrct2/windows/editor_object_selection.c | 16 ++++++++-------- src/openrct2/windows/new_campaign.c | 4 ++++ src/openrct2/windows/new_ride.c | 14 +++++++------- test/testpaint/main.cpp | 2 +- 10 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/openrct2/interface/console.c b/src/openrct2/interface/console.c index 66caadba91..bef48fe76d 100644 --- a/src/openrct2/interface/console.c +++ b/src/openrct2/interface/console.c @@ -1129,7 +1129,7 @@ static sint32 cc_load_object(const utf8 **argv, sint32 argc) { for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { rideType = rideEntry->ride_type[j]; - if (rideType != 255) + if (rideType != RIDE_TYPE_NULL) research_insert(true, 0x10000 | (rideType << 8) | groupIndex, rideEntry->category[0]); } diff --git a/src/openrct2/management/research.c b/src/openrct2/management/research.c index 8f99663c90..8eb0413fcf 100644 --- a/src/openrct2/management/research.c +++ b/src/openrct2/management/research.c @@ -551,7 +551,7 @@ void research_populate_list_random() sint32 researched = (scenario_rand() & 0xFF) > 128; for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { sint32 rideType = rideEntry->ride_type[j]; - if (rideType != 255) + if (rideType != RIDE_TYPE_NULL) research_insert(researched, 0x10000 | (rideType << 8) | i, rideEntry->category[0]); } } @@ -577,7 +577,7 @@ void research_populate_list_researched() for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { sint32 rideType = rideEntry->ride_type[j]; - if (rideType != 255) + if (rideType != RIDE_TYPE_NULL) research_insert(true, 0x10000 | (rideType << 8) | i, rideEntry->category[0]); } } @@ -639,7 +639,7 @@ void research_insert_ride_entry(uint8 entryIndex, bool researched) uint8 category = rideEntry->category[0]; for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { uint8 rideType = rideEntry->ride_type[i]; - if (rideType != 255) { + if (rideType != RIDE_TYPE_NULL) { research_insert(researched, 0x10000 | (rideType << 8) | entryIndex, category); } } diff --git a/src/openrct2/object/ObjectRepository.cpp b/src/openrct2/object/ObjectRepository.cpp index 3b6cad5dff..1125e54a01 100644 --- a/src/openrct2/object/ObjectRepository.cpp +++ b/src/openrct2/object/ObjectRepository.cpp @@ -498,7 +498,7 @@ private: { stream->WriteValue(item.RideCategory[i]); } - for (sint32 i = 0; i < 3; i++) + for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { stream->WriteValue(item.RideType[i]); } diff --git a/src/openrct2/object/RideObject.cpp b/src/openrct2/object/RideObject.cpp index 832dac1ec9..925d2f7072 100644 --- a/src/openrct2/object/RideObject.cpp +++ b/src/openrct2/object/RideObject.cpp @@ -79,16 +79,10 @@ void RideObject::ReadLegacy(IReadObjectContext * context, IStream * stream) GetStringTable()->Read(context, stream, OBJ_STRING_ID_DESCRIPTION); // Add boosters if the track type is eligible - for (sint32 i = 0; i < 3; i++) + for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { - if ( - _legacyType.ride_type[i] == RIDE_TYPE_LOOPING_ROLLER_COASTER || - _legacyType.ride_type[i] == RIDE_TYPE_CORKSCREW_ROLLER_COASTER || - _legacyType.ride_type[i] == RIDE_TYPE_TWISTER_ROLLER_COASTER || - _legacyType.ride_type[i] == RIDE_TYPE_VERTICAL_DROP_ROLLER_COASTER || - _legacyType.ride_type[i] == RIDE_TYPE_GIGA_COASTER || - _legacyType.ride_type[i] == RIDE_TYPE_JUNIOR_ROLLER_COASTER - ) { + if (ride_type_supports_boosters(_legacyType.ride_type[i])) + { _legacyType.enabledTrackPieces |= (1ULL << TRACK_BOOSTER); } } diff --git a/src/openrct2/ride/ride.c b/src/openrct2/ride/ride.c index a264acb7a4..2b19038d75 100644 --- a/src/openrct2/ride/ride.c +++ b/src/openrct2/ride/ride.c @@ -8580,3 +8580,17 @@ uint8 ride_entry_get_first_non_null_ride_type(rct_ride_entry * rideEntry) } return RIDE_TYPE_NULL; } + +bool ride_type_supports_boosters(uint8 rideType) +{ + if (rideType == RIDE_TYPE_LOOPING_ROLLER_COASTER || + rideType == RIDE_TYPE_CORKSCREW_ROLLER_COASTER || + rideType == RIDE_TYPE_TWISTER_ROLLER_COASTER || + rideType == RIDE_TYPE_VERTICAL_DROP_ROLLER_COASTER || + rideType == RIDE_TYPE_GIGA_COASTER || + rideType == RIDE_TYPE_JUNIOR_ROLLER_COASTER) + { + return true; + } + return false; +} diff --git a/src/openrct2/ride/ride.h b/src/openrct2/ride/ride.h index 2cbcdc2753..291bfae558 100644 --- a/src/openrct2/ride/ride.h +++ b/src/openrct2/ride/ride.h @@ -1186,5 +1186,6 @@ bool ride_has_ratings(const rct_ride * ride); const char * ride_type_get_enum_name(sint32 rideType); uint8 ride_entry_get_first_non_null_ride_type(rct_ride_entry * rideEntry); +bool ride_type_supports_boosters(uint8 rideType); #endif diff --git a/src/openrct2/windows/editor_object_selection.c b/src/openrct2/windows/editor_object_selection.c index 40bdfb2d32..f9ae198ee5 100644 --- a/src/openrct2/windows/editor_object_selection.c +++ b/src/openrct2/windows/editor_object_selection.c @@ -504,9 +504,9 @@ static void setup_track_manager_objects() if (object_type == OBJECT_TYPE_RIDE) { *selectionFlags |= OBJECT_SELECTION_FLAG_6; - for (uint8 j = 0; j < 3; j++) { + for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { uint8 rideType = item->RideType[j]; - if (rideType != 0xFF && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_TRACK)) { + if (rideType != RIDE_TYPE_NULL && ride_type_has_flag(rideType, RIDE_TYPE_FLAG_HAS_TRACK)) { *selectionFlags &= ~OBJECT_SELECTION_FLAG_6; break; } @@ -530,9 +530,9 @@ static void setup_track_designer_objects() if (objectType == OBJECT_TYPE_RIDE){ *selectionFlags |= OBJECT_SELECTION_FLAG_6; - for (uint8 j = 0; j < 3; j++) { + for (uint8 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { uint8 rideType = item->RideType[j]; - if (rideType != 0xFF) { + if (rideType != RIDE_TYPE_NULL) { if (RideData4[rideType].flags & RIDE_TYPE_FLAG4_SHOW_IN_TRACK_DESIGNER) { *selectionFlags &= ~OBJECT_SELECTION_FLAG_6; break; @@ -1853,8 +1853,8 @@ static bool filter_chunks(const ObjectRepositoryItem * item) } else { uint8 rideType = 0; - for (sint32 i = 0; i < 3; i++) { - if (item->RideType[i] != 255) { + for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { + if (item->RideType[i] != RIDE_TYPE_NULL) { rideType = item->RideType[i]; break; } @@ -1895,9 +1895,9 @@ static void filter_update_counts() static rct_string_id get_ride_type_string_id(const ObjectRepositoryItem * item) { rct_string_id result = STR_NONE; - for (sint32 i = 0; i < 3; i++) { + for (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) { uint8 rideType = item->RideType[i]; - if (rideType != 255) { + if (rideType != RIDE_TYPE_NULL) { result = RideNaming[rideType].name; break; } diff --git a/src/openrct2/windows/new_campaign.c b/src/openrct2/windows/new_campaign.c index fa6261f261..74f92438bf 100644 --- a/src/openrct2/windows/new_campaign.c +++ b/src/openrct2/windows/new_campaign.c @@ -208,8 +208,12 @@ static void window_new_campaign_get_shop_items() // numItems = 0; for (i = 0; i < 64; i++) + { if (items & (1LL << i)) + { window_new_campaign_shop_items[numItems++] = i; + } + } window_new_campaign_shop_items[numItems] = 255; } diff --git a/src/openrct2/windows/new_ride.c b/src/openrct2/windows/new_ride.c index ade08073df..780f17aed8 100644 --- a/src/openrct2/windows/new_ride.c +++ b/src/openrct2/windows/new_ride.c @@ -426,7 +426,7 @@ static void window_new_ride_scroll_to_focused_ride(rct_window *w) sint32 focusRideType = _windowNewRideHighlightedItem[_windowNewRideCurrentTab].ride_type_and_entry; sint32 count = 0, row = 0; ride_list_item *listItem = _windowNewRideListItems; - while (listItem->type != 255 || listItem->entry_index != 255) { + while (listItem->type != RIDE_TYPE_NULL || listItem->entry_index != 255) { if (listItem->type == focusRideType) { row = count / 5; break; @@ -730,7 +730,7 @@ static void window_new_ride_scrollgetsize(rct_window *w, sint32 scrollIndex, sin ride_list_item *listItem = _windowNewRideListItems; sint32 count = 0; - while (listItem->type != 255 || listItem->entry_index != 255) { + while (listItem->type != RIDE_TYPE_NULL || listItem->entry_index != 255) { count++; listItem++; } @@ -746,7 +746,7 @@ static void window_new_ride_scrollmousedown(rct_window *w, sint32 scrollIndex, s ride_list_item item; item = window_new_ride_scroll_get_ride_list_item_at(w, x, y); - if (item.type == 255 && item.entry_index == 255) + if (item.type == RIDE_TYPE_NULL && item.entry_index == 255) return; _windowNewRideHighlightedItem[_windowNewRideCurrentTab] = item; @@ -821,7 +821,7 @@ static void window_new_ride_paint(rct_window *w, rct_drawpixelinfo *dpi) if (_windowNewRideCurrentTab != WINDOW_NEW_RIDE_PAGE_RESEARCH) { ride_list_item item = { .ride_type_and_entry = w->new_ride.highlighted_ride_id }; - if (item.type != 255 || item.entry_index != 255) + if (item.type != RIDE_TYPE_NULL || item.entry_index != 255) window_new_ride_paint_ride_information(w, dpi, item, w->x + 3, w->y + w->height - 52, w->width - 6); } else { window_research_development_page_paint(w, dpi, WIDX_CURRENTLY_IN_DEVELOPMENT_GROUP); @@ -842,7 +842,7 @@ static void window_new_ride_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, s sint32 x = 1; sint32 y = 1; ride_list_item *listItem = _windowNewRideListItems; - while (listItem->type != 255 || listItem->entry_index != 255) { + while (listItem->type != RIDE_TYPE_NULL || listItem->entry_index != 255) { rct_ride_entry *rideEntry; // Draw flat button rectangle sint32 flags = 0; @@ -894,7 +894,7 @@ static ride_list_item window_new_ride_scroll_get_ride_list_item_at(rct_window *w sint32 index = column + (row * 5); ride_list_item *listItem = _windowNewRideListItems; - while (listItem->type != 255 || listItem->entry_index != 255) { + while (listItem->type != RIDE_TYPE_NULL || listItem->entry_index != 255) { if (index-- == 0) return *listItem; listItem++; @@ -995,7 +995,7 @@ static void window_new_ride_paint_ride_information(rct_window *w, rct_drawpixeli static void window_new_ride_select(rct_window *w) { ride_list_item item = { .ride_type_and_entry = w->new_ride.selected_ride_id }; - if (item.type == 255) + if (item.type == RIDE_TYPE_NULL) return; window_close(w); diff --git a/test/testpaint/main.cpp b/test/testpaint/main.cpp index a565ef6626..03476e67f7 100644 --- a/test/testpaint/main.cpp +++ b/test/testpaint/main.cpp @@ -466,7 +466,7 @@ int main(int argc, char *argv[]) { } for (uint8 rideType = 0; rideType < RIDE_TYPE_COUNT; rideType++) { - if (specificRideType != 0xFF && rideType != specificRideType) { + if (specificRideType != RIDE_TYPE_NULL && rideType != specificRideType) { continue; }