Refactor access to ResearchItem's rawValue

This commit is contained in:
Gymnasiast 2020-01-26 15:17:37 +01:00
parent e6c32230bc
commit 66dbb5e166
No known key found for this signature in database
GPG Key ID: DBFFF47AB2CA3EDD
5 changed files with 48 additions and 36 deletions

View File

@ -1297,11 +1297,11 @@ static void editor_load_selected_objects()
{
rct_ride_entry* rideEntry = get_ride_entry(entryIndex);
uint8_t rideType = ride_entry_get_first_non_null_ride_type(rideEntry);
research_insert(1, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | entryIndex, rideEntry->category[0]);
research_insert_ride_entry(rideType, entryIndex, rideEntry->category[0], true);
}
else if (objectType == OBJECT_TYPE_SCENERY_GROUP)
{
research_insert(1, entryIndex, RESEARCH_CATEGORY_SCENERY_GROUP);
research_insert_scenery_group_entry(entryIndex, true);
}
}
}

View File

@ -1081,7 +1081,7 @@ static int32_t cc_load_object(InteractiveConsole& console, const arguments_t& ar
console.WriteLineError("Unable to load object.");
return 1;
}
int32_t groupIndex = object_manager_get_loaded_object_entry_index(loadedObject);
uint32_t groupIndex = object_manager_get_loaded_object_entry_index(loadedObject);
uint8_t objectType = object_entry_get_type(entry);
if (objectType == OBJECT_TYPE_RIDE)
@ -1095,8 +1095,7 @@ static int32_t cc_load_object(InteractiveConsole& console, const arguments_t& ar
for (int32_t j = 0; j < MAX_RIDE_TYPES_PER_RIDE_ENTRY; j++)
{
rideType = rideEntry->ride_type[j];
if (rideType != RIDE_TYPE_NULL)
research_insert(true, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | groupIndex, rideEntry->category[0]);
research_insert_ride_entry(rideType, groupIndex, rideEntry->category[0], true);
}
gSilentResearch = true;
@ -1105,7 +1104,7 @@ static int32_t cc_load_object(InteractiveConsole& console, const arguments_t& ar
}
else if (objectType == OBJECT_TYPE_SCENERY_GROUP)
{
research_insert(true, groupIndex, RESEARCH_CATEGORY_SCENERY_GROUP);
research_insert_scenery_group_entry(groupIndex, true);
gSilentResearch = true;
research_reset_current_item();

View File

@ -356,11 +356,13 @@ void news_item_open_subject(int32_t type, int32_t subject)
context_open_window(WC_FINANCES);
break;
case NEWS_ITEM_RESEARCH:
if (subject >= RESEARCH_ENTRY_RIDE_MASK)
{
auto item = ResearchItem(subject, 0);
if (item.type == RESEARCH_ENTRY_TYPE_RIDE)
{
auto intent = Intent(INTENT_ACTION_NEW_RIDE_OF_TYPE);
intent.putExtra(INTENT_EXTRA_RIDE_TYPE, subject >> 8);
intent.putExtra(INTENT_EXTRA_RIDE_ENTRY_INDEX, subject & 0xFF);
intent.putExtra(INTENT_EXTRA_RIDE_TYPE, item.baseRideType);
intent.putExtra(INTENT_EXTRA_RIDE_ENTRY_INDEX, item.entryIndex);
context_open_intent(&intent);
break;
}
@ -386,6 +388,7 @@ void news_item_open_subject(int32_t type, int32_t subject)
if (window != nullptr)
window_event_mouse_down_call(window, WC_SCENERY__WIDX_SCENERY_TAB_1 + subject);
break;
}
case NEWS_ITEM_PEEPS:
{
auto intent = Intent(WC_GUEST_LIST);

View File

@ -409,19 +409,18 @@ void research_reset_current_item()
*
* rct2: 0x006857FA
*/
static void research_insert_unresearched(uint32_t rawValue, uint8_t category)
static void research_insert_unresearched(ResearchItem item)
{
gResearchItemsUninvented.push_back({ rawValue, category });
gResearchItemsUninvented.push_back(item);
}
/**
*
* rct2: 0x00685826
*/
static void research_insert_researched(uint32_t rawValue, uint8_t category)
static void research_insert_researched(ResearchItem item)
{
// First check to make sure that entry is not already accounted for
ResearchItem item = { rawValue, category };
if (item.Exists())
{
return;
@ -456,15 +455,15 @@ void research_remove(ResearchItem* researchItem)
}
}
void research_insert(int32_t researched, int32_t rawValue, uint8_t category)
void research_insert(ResearchItem item, bool researched)
{
if (researched)
{
research_insert_researched(rawValue, category);
research_insert_researched(item);
}
else
{
research_insert_unresearched(rawValue, category);
research_insert_unresearched(item);
}
}
@ -488,15 +487,12 @@ void research_populate_list_random()
int32_t researched = (scenario_rand() & 0xFF) > 128;
for (auto rideType : rideEntry->ride_type)
{
if (rideType != RIDE_TYPE_NULL)
{
research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]);
}
research_insert_ride_entry(rideType, i, rideEntry->category[0], researched);
}
}
// Scenery
for (int32_t i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
for (uint32_t i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
{
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(i);
if (sceneryGroupEntry == nullptr)
@ -505,7 +501,7 @@ void research_populate_list_random()
}
int32_t researched = (scenario_rand() & 0xFF) > 85;
research_insert(researched, i, RESEARCH_CATEGORY_SCENERY_GROUP);
research_insert_scenery_group_entry(i, researched);
}
}
@ -522,15 +518,12 @@ void research_populate_list_researched()
for (auto rideType : rideEntry->ride_type)
{
if (rideType != RIDE_TYPE_NULL)
{
research_insert(true, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | i, rideEntry->category[0]);
}
research_insert_ride_entry(rideType, i, rideEntry->category[0], true);
}
}
// Scenery
for (int32_t i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
for (uint32_t i = 0; i < MAX_SCENERY_GROUP_OBJECTS; i++)
{
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(i);
if (sceneryGroupEntry == nullptr)
@ -538,26 +531,35 @@ void research_populate_list_researched()
continue;
}
research_insert(true, i, RESEARCH_CATEGORY_SCENERY_GROUP);
research_insert_scenery_group_entry(i, true);
}
}
bool research_insert_ride_entry(uint8_t rideType, uint8_t entryIndex, uint8_t category, bool researched)
{
if (rideType != RIDE_TYPE_NULL)
{
research_insert(
{ static_cast<uint32_t>(RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | entryIndex), category }, researched);
return true;
}
return false;
}
void research_insert_ride_entry(uint8_t entryIndex, bool researched)
{
rct_ride_entry* rideEntry = get_ride_entry(entryIndex);
uint8_t category = rideEntry->category[0];
for (auto rideType : rideEntry->ride_type)
{
if (rideType != RIDE_TYPE_NULL)
{
research_insert(researched, RESEARCH_ENTRY_RIDE_MASK | (rideType << 8) | entryIndex, category);
}
research_insert_ride_entry(rideType, entryIndex, category, researched);
}
}
void research_insert_scenery_group_entry(uint8_t entryIndex, bool researched)
{
research_insert(researched, entryIndex, RESEARCH_CATEGORY_SCENERY_GROUP);
research_insert({ entryIndex, RESEARCH_CATEGORY_SCENERY_GROUP }, researched);
}
bool ride_type_is_invented(uint32_t rideType)
@ -758,7 +760,7 @@ void research_fix()
}
else
{
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue);
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.entryIndex);
if (sceneryGroupEntry == nullptr)
{
it = gResearchItemsInvented.erase(it);
@ -786,7 +788,7 @@ void research_fix()
}
else
{
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.rawValue);
rct_scenery_group_entry* sceneryGroupEntry = get_scenery_group_entry(researchItem.entryIndex);
if (sceneryGroupEntry == nullptr)
{
it = gResearchItemsUninvented.erase(it);

View File

@ -37,6 +37,13 @@ struct ResearchItem
bool Exists() const;
bool IsAlwaysResearched() const;
rct_string_id GetName() const;
ResearchItem() = default;
constexpr ResearchItem(uint32_t _rawValue, int32_t _category)
: rawValue(_rawValue)
, category(_category)
{
}
};
enum
@ -112,9 +119,10 @@ void research_populate_list_random();
void research_populate_list_researched();
void research_finish_item(ResearchItem* researchItem);
void research_insert(int32_t researched, int32_t rawValue, uint8_t category);
void research_insert(ResearchItem item, bool researched);
void research_remove(ResearchItem* researchItem);
bool research_insert_ride_entry(uint8_t rideType, uint8_t entryIndex, uint8_t category, bool researched);
void research_insert_ride_entry(uint8_t entryIndex, bool researched);
void research_insert_scenery_group_entry(uint8_t entryIndex, bool researched);