Ejemplo n.º 1
0
/**
 *	rct2: 0x006B6F3E
 *
 * Note: When the user has selection by track type enabled, the categories are determined by the track type, not those in the rct_ride_entry.
 */
static void window_new_ride_populate_list()
{
	uint8 currentCategory = _windowNewRideCurrentTab;
	ride_list_item *nextListItem = _windowNewRideListItems;

	// For each ride type in the view order list
	for (int i = 0; i < countof(RideTypeViewOrder); i++) {
		uint8 rideType = RideTypeViewOrder[i];
		if (rideType == RIDE_TYPE_NULL)
			continue;

		if(gConfigInterface.select_by_track_type) {
			if(gRideCategories[rideType]!=currentCategory)
				continue;
		}

		char preferredVehicleName[9];
		safe_strcpy(preferredVehicleName, "        ", sizeof(preferredVehicleName));

		if (ride_type_is_invented(rideType)) {
			int dh = 0;
			uint8 *rideEntryIndexPtr = get_ride_entry_indices_for_ride_type(rideType);

			// For each ride entry for this ride type
			while (*rideEntryIndexPtr != 255) {
				uint8 rideEntryIndex = *rideEntryIndexPtr++;
				char rideEntryName[9];
				memcpy(rideEntryName,object_entry_groups[OBJECT_TYPE_RIDE].entries[rideEntryIndex].name,8);
				rideEntryName[8]=0;

				// Skip if vehicle type is not invented yet
				if (!ride_entry_is_invented(rideEntryIndex))
					continue;

				// Ride entries
				rct_ride_entry *rideEntry = get_ride_entry(rideEntryIndex);

				// Check if ride is in this category
				if (!gConfigInterface.select_by_track_type && (currentCategory != rideEntry->category[0] && currentCategory != rideEntry->category[1]))
					continue;

				// Skip if the vehicle isn't the preferred vehicle for this generic track type
				if (gConfigInterface.select_by_track_type && (!(rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) || rideTypeShouldLoseSeparateFlag(rideEntry))) {
					if (strcmp(preferredVehicleName, "        \0") == 0) {
						safe_strcpy(preferredVehicleName, rideEntryName, sizeof(preferredVehicleName));
						preferredVehicleName[8] = 0;
					} else {
						if (vehicle_preference_compare(rideType, preferredVehicleName, rideEntryName) == 1) {
							safe_strcpy(preferredVehicleName, rideEntryName, sizeof(preferredVehicleName));
							preferredVehicleName[8] = 0;
						} else {
							continue;
						}
					}
				}

				if ((rideEntry->flags & RIDE_ENTRY_FLAG_SEPARATE_RIDE) && !rideTypeShouldLoseSeparateFlag(rideEntry)) {
					dh &= ~4;
					nextListItem->type = rideType;
					nextListItem->entry_index = rideEntryIndex;
					nextListItem++;
				} else if (!(dh & 1)) {
					dh |= 5;
					nextListItem->type = rideType;
					nextListItem->entry_index = rideEntryIndex;
					nextListItem++;
				} else if (dh & 4) {
					if (rideType == rideEntry->ride_type[0]) {
						nextListItem--;
						nextListItem->type = rideType;
						nextListItem->entry_index = rideEntryIndex;
						nextListItem++;
					}
				}
			}
		}
	}

	nextListItem->type = 255;
	nextListItem->entry_index = 255;
	_trackSelectionByType = gConfigInterface.select_by_track_type;
}
Ejemplo n.º 2
0
/**
 *
 *  rct2: 0x006848D4
 */
void research_finish_item(rct_research_item* researchItem)
{
    gResearchLastItem = *researchItem;
    research_invalidate_related_windows();

    if (researchItem->type == RESEARCH_ENTRY_TYPE_RIDE)
    {
        // Ride
        uint32_t base_ride_type = researchItem->baseRideType;
        int32_t rideEntryIndex = researchItem->entryIndex;
        rct_ride_entry* rideEntry = get_ride_entry(rideEntryIndex);

        if (rideEntry != nullptr && base_ride_type != RIDE_TYPE_NULL)
        {
            bool ride_group_was_invented_before = false;
            bool ride_type_was_invented_before = ride_type_is_invented(base_ride_type);
            rct_string_id availabilityString;

            // Determine if the ride group this entry belongs to was invented before.
            if (RideGroupManager::RideTypeHasRideGroups(base_ride_type))
            {
                const RideGroup* rideGroup = RideGroupManager::GetRideGroup(base_ride_type, rideEntry);

                if (rideGroup->IsInvented())
                {
                    ride_group_was_invented_before = true;
                }
            }

            ride_type_set_invented(base_ride_type);
            openrct2_assert(
                base_ride_type < std::size(RideTypePossibleTrackConfigurations), "Invalid base_ride_type = %d", base_ride_type);

            ride_entry_set_invented(rideEntryIndex);

            bool seenRideEntry[MAX_RIDE_OBJECTS]{};

            rct_research_item* researchItem2 = gResearchItems;
            for (; researchItem2->rawValue != RESEARCHED_ITEMS_END; researchItem2++)
            {
                if (researchItem2->rawValue != RESEARCHED_ITEMS_SEPARATOR && researchItem2->type == RESEARCH_ENTRY_TYPE_RIDE)
                {
                    uint8_t index = researchItem2->entryIndex;
                    seenRideEntry[index] = true;
                }
            }

            // RCT2 made non-separated vehicles available at once, by removing all but one from research.
            // To ensure old files keep working, look for ride entries not in research, and make them available as well.
            for (int32_t i = 0; i < MAX_RIDE_OBJECTS; i++)
            {
                if (!seenRideEntry[i])
                {
                    rct_ride_entry* rideEntry2 = get_ride_entry(i);
                    if (rideEntry2 != nullptr)
                    {
                        for (uint8_t j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++)
                        {
                            if (rideEntry2->ride_type[j] == base_ride_type)
                            {
                                ride_entry_set_invented(i);
                                break;
                            }
                        }
                    }
                }
            }

            // If a vehicle should be listed separately (maze, mini golf, flat rides, shops)
            if (RideGroupManager::RideTypeIsIndependent(base_ride_type))
            {
                availabilityString = STR_NEWS_ITEM_RESEARCH_NEW_RIDE_AVAILABLE;
                set_format_arg(0, rct_string_id, rideEntry->naming.name);
            }
            // If a vehicle is the first to be invented for its ride group, show the ride group name.
            else if (
                !ride_type_was_invented_before
                || (RideGroupManager::RideTypeHasRideGroups(base_ride_type) && !ride_group_was_invented_before))
            {
                rct_ride_name naming = get_ride_naming(base_ride_type, rideEntry);
                availabilityString = STR_NEWS_ITEM_RESEARCH_NEW_RIDE_AVAILABLE;
                set_format_arg(0, rct_string_id, naming.name);
            }
            // If the vehicle should not be listed separately and it isn't the first to be invented for its ride group,
            // report it as a new vehicle for the existing ride group.
            else
            {
                availabilityString = STR_NEWS_ITEM_RESEARCH_NEW_VEHICLE_AVAILABLE;
                rct_ride_name baseRideNaming = get_ride_naming(base_ride_type, rideEntry);

                set_format_arg(0, rct_string_id, baseRideNaming.name);
                set_format_arg(2, rct_string_id, rideEntry->naming.name);
            }

            if (!gSilentResearch)
            {
                if (gConfigNotifications.ride_researched)
                {
                    news_item_add_to_queue(NEWS_ITEM_RESEARCH, availabilityString, researchItem->rawValue);
                }
            }

            research_invalidate_related_windows();
        }
    }
    else
    {
        // Scenery
        rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem->entryIndex);
        if (sceneryGroupEntry != nullptr)
        {
            scenery_group_set_invented(researchItem->entryIndex);

            set_format_arg(0, rct_string_id, sceneryGroupEntry->name);

            if (!gSilentResearch)
            {
                if (gConfigNotifications.ride_researched)
                {
                    news_item_add_to_queue(
                        NEWS_ITEM_RESEARCH, STR_NEWS_ITEM_RESEARCH_NEW_SCENERY_SET_AVAILABLE, researchItem->rawValue);
                }
            }

            research_invalidate_related_windows();
            init_scenery();
        }
    }
}