From 289e154fe46ad920d68244a89ce739e7de86bef1 Mon Sep 17 00:00:00 2001 From: Michael Steenbeek Date: Thu, 28 Sep 2017 12:31:24 +0200 Subject: [PATCH] Fix #6315: Not all researched items in S4 are available --- .../windows/EditorInventionsList.cpp | 16 -------- src/openrct2/game.c | 2 +- src/openrct2/management/research.c | 38 ++++++++++++++----- src/openrct2/management/research.h | 3 ++ src/openrct2/rct1.h | 8 +++- src/openrct2/rct1/S4Importer.cpp | 16 +++++--- 6 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/openrct2-ui/windows/EditorInventionsList.cpp b/src/openrct2-ui/windows/EditorInventionsList.cpp index 14e0ed59c8..949a926c7a 100644 --- a/src/openrct2-ui/windows/EditorInventionsList.cpp +++ b/src/openrct2-ui/windows/EditorInventionsList.cpp @@ -307,23 +307,7 @@ static void research_always_researched_setup() research_scenery_sets_setup(); } -/** - * - * rct2: 0x00685A79 - * Do not use the research list outside of the inventions list window with the flags - */ -static void research_remove_flags() -{ - for (rct_research_item* research = gResearchItems; - research->entryIndex != RESEARCHED_ITEMS_END_2; - research++){ - // Clear the always researched flags. - if (research->entryIndex > RESEARCHED_ITEMS_SEPARATOR){ - research->entryIndex &= 0x00FFFFFF; - } - } -} /** * diff --git a/src/openrct2/game.c b/src/openrct2/game.c index 14115b1ab2..f2d9705829 100644 --- a/src/openrct2/game.c +++ b/src/openrct2/game.c @@ -1085,7 +1085,7 @@ void game_fix_save_vars() break; } if (researchItem->entryIndex == RESEARCHED_ITEMS_END_2) break; - if (researchItem->entryIndex & 0x10000) { + if (researchItem->entryIndex & RESEARCH_ENTRY_RIDE_MASK) { uint8 entryIndex = researchItem->entryIndex & 0xFF; rct_ride_entry *rideEntry = get_ride_entry(entryIndex); if (rideEntry == NULL || rideEntry == (rct_ride_entry*)-1) { diff --git a/src/openrct2/management/research.c b/src/openrct2/management/research.c index b3e812a25f..62aa953e9c 100644 --- a/src/openrct2/management/research.c +++ b/src/openrct2/management/research.c @@ -181,7 +181,8 @@ void research_finish_item(sint32 entryIndex) gResearchLastItemSubject = (uint32)entryIndex; research_invalidate_related_windows(); - if (entryIndex >= 0x10000) { + if (entryIndex >= RESEARCH_ENTRY_RIDE_MASK) + { // Ride sint32 base_ride_type = research_get_ride_base_type(entryIndex); sint32 rideEntryIndex = entryIndex & 0xFF; @@ -428,7 +429,7 @@ void research_remove_non_separate_vehicle_types() researchItem != gResearchItems && researchItem->entryIndex != RESEARCHED_ITEMS_SEPARATOR && researchItem->entryIndex != RESEARCHED_ITEMS_END && - researchItem->entryIndex >= 0x10000 + researchItem->entryIndex >= RESEARCH_ENTRY_RIDE_MASK ) { rct_ride_entry *rideEntry = get_ride_entry(researchItem->entryIndex & 0xFF); if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE | RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME))) { @@ -437,7 +438,7 @@ void research_remove_non_separate_vehicle_types() do { if ( researchItem2->entryIndex != RESEARCHED_ITEMS_SEPARATOR && - researchItem2->entryIndex >= 0x10000 + researchItem2->entryIndex >= RESEARCH_ENTRY_RIDE_MASK ) { rideEntry = get_ride_entry(researchItem2->entryIndex & 0xFF); if (!(rideEntry->flags & (RIDE_ENTRY_FLAG_SEPARATE_RIDE | RIDE_ENTRY_FLAG_SEPARATE_RIDE_NAME))) { @@ -555,7 +556,7 @@ void research_populate_list_random() for (sint32 j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++) { sint32 rideType = rideEntry->ride_type[j]; if (rideType != RIDE_TYPE_NULL) - research_insert(researched, 0x10000 | (rideType << 8) | i, rideEntry->category[0]); + research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]); } } @@ -581,7 +582,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 != RIDE_TYPE_NULL) - research_insert(true, 0x10000 | (rideType << 8) | i, rideEntry->category[0]); + research_insert(true, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]); } } @@ -640,10 +641,12 @@ 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 (sint32 i = 0; i < MAX_RIDE_TYPES_PER_RIDE_ENTRY; i++) + { uint8 rideType = rideEntry->ride_type[i]; - if (rideType != RIDE_TYPE_NULL) { - research_insert(researched, 0x10000 | (rideType << 8) | entryIndex, category); + if (rideType != RIDE_TYPE_NULL) + { + research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | entryIndex, category); } } } @@ -721,7 +724,7 @@ void reset_researched_ride_types_and_entries() */ rct_string_id research_item_get_name(uint32 researchItem) { - if (researchItem >= 0x10000) + if (researchItem >= RESEARCH_ENTRY_RIDE_MASK) { rct_ride_entry *rideEntry = get_ride_entry(researchItem & 0xFF); if (rideEntry == NULL || rideEntry == (rct_ride_entry*)-1) @@ -787,3 +790,20 @@ rct_string_id research_get_friendly_base_ride_type_name(uint8 trackType, rct_rid } } } + +/** + * + * rct2: 0x00685A79 + * Do not use the research list outside of the inventions list window with the flags + */ +void research_remove_flags() +{ + for (rct_research_item * research = gResearchItems; research->entryIndex != RESEARCHED_ITEMS_END_2; research++) + { + // Clear the always researched flags. + if (research->entryIndex > RESEARCHED_ITEMS_SEPARATOR) + { + research->entryIndex &= 0x00FFFFFF; + } + } +} diff --git a/src/openrct2/management/research.h b/src/openrct2/management/research.h index 00acf674cb..33e5e94791 100644 --- a/src/openrct2/management/research.h +++ b/src/openrct2/management/research.h @@ -47,6 +47,8 @@ enum{ #define MAX_RESEARCHED_RIDE_ENTRIES 8 #define MAX_RESEARCHED_TRACK_TYPES 128 +#define RESEARCH_ENTRY_RIDE_MASK 0x10000 + enum { RESEARCH_FUNDING_NONE, RESEARCH_FUNDING_MINIMUM, @@ -122,6 +124,7 @@ void reset_researched_ride_types_and_entries(); rct_string_id research_item_get_name(uint32 researchItem); uint8 research_get_ride_base_type(sint32 researchItem); rct_string_id research_get_friendly_base_ride_type_name(uint8 trackType, rct_ride_entry * rideEntry); +void research_remove_flags(); #ifdef __cplusplus } diff --git a/src/openrct2/rct1.h b/src/openrct2/rct1.h index 36668650e9..7f5cea7803 100644 --- a/src/openrct2/rct1.h +++ b/src/openrct2/rct1.h @@ -889,7 +889,9 @@ enum { RCT1_RIDE_TYPE_ENTERPRISE, RCT1_RIDE_TYPE_COFFEE_SHOP, RCT1_RIDE_TYPE_FRIED_CHICKEN_STALL, - RCT1_RIDE_TYPE_LEMONADE_STALL + RCT1_RIDE_TYPE_LEMONADE_STALL, + + RCT1_RIDE_TYPE_COUNT }; enum { @@ -981,7 +983,9 @@ enum { RCT1_VEHICLE_TYPE_AMERICAN_STYLE_STEAM_TRAIN, RCT1_VEHICLE_TYPE_AIR_POWERED_COASTER_TRAIN, RCT1_VEHICLE_TYPE_SUSPENDED_WILD_MOUSE_CARS, // Inverted Hairpin in RCT2 - RCT1_VEHICLE_TYPE_ENTERPRISE_WHEEL + RCT1_VEHICLE_TYPE_ENTERPRISE_WHEEL, + + RCT1_VEHICLE_TYPE_COUNT }; enum { diff --git a/src/openrct2/rct1/S4Importer.cpp b/src/openrct2/rct1/S4Importer.cpp index d8272e9fc5..77dfd2a140 100644 --- a/src/openrct2/rct1/S4Importer.cpp +++ b/src/openrct2/rct1/S4Importer.cpp @@ -33,6 +33,7 @@ #include "../ride/station.h" #include "../scenario/ScenarioSources.h" #include "Tables.h" +#include "../object_list.h" extern "C" { @@ -114,8 +115,8 @@ private: EntryList _waterEntry; // Lookup tables for converting from RCT1 hard coded types to the new dynamic object entries - uint8 _rideTypeToRideEntryMap[96]; - uint8 _vehicleTypeToRideEntryMap[96]; + uint8 _rideTypeToRideEntryMap[RCT1_RIDE_TYPE_COUNT]; + uint8 _vehicleTypeToRideEntryMap[RCT1_VEHICLE_TYPE_COUNT]; uint8 _smallSceneryTypeToEntryMap[256]; uint8 _largeSceneryTypeToEntryMap[256]; uint8 _wallTypeToEntryMap[256]; @@ -124,8 +125,8 @@ private: uint8 _sceneryThemeTypeToEntryMap[24]; // Research - uint8 _researchRideEntryUsed[128]; - uint8 _researchRideTypeUsed[128]; + uint8 _researchRideEntryUsed[MAX_RIDE_OBJECTS]; + uint8 _researchRideTypeUsed[RCT1_RIDE_TYPE_COUNT]; public: ParkLoadResult Load(const utf8 * path) override @@ -665,9 +666,9 @@ private: else { const char * entryName = RCT1::GetSceneryGroupObject(sceneryThemeType); - if (_sceneryGroupEntries.GetCount() >= 19) + if (_sceneryGroupEntries.GetCount() >= MAX_SCENERY_GROUP_OBJECTS) { - Console::WriteLine("Warning: More than 19 (max scenery groups) in RCT1 park."); + Console::WriteLine("Warning: More than %d (max scenery groups) in RCT1 park.", MAX_SCENERY_GROUP_OBJECTS); Console::WriteLine(" [%s] scenery group not added.", entryName); } else @@ -2017,6 +2018,9 @@ private: gResearchNextCategory = _s4.next_research_category; // gResearchExpectedDay = // gResearchExpectedMonth = + + // This is needed to fix Research. Not sure why. + research_reset_current_item(); } void InsertResearchVehicle(const rct1_research_item * researchItem, bool researched)