Skip to content

Commit

Permalink
Refactor PARK_AWARD to use strong enum (#13017)
Browse files Browse the repository at this point in the history
* Refactor PARK_AWARD to use strong enum
  • Loading branch information
gsckoco committed Sep 29, 2020
1 parent 3c8adb1 commit 147daa8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
66 changes: 33 additions & 33 deletions src/openrct2/management/Award.cpp
Expand Up @@ -26,23 +26,23 @@ constexpr uint8_t NEGATIVE = 0;
constexpr uint8_t POSITIVE = 1;

static constexpr const uint8_t AwardPositiveMap[] = {
NEGATIVE, // PARK_AWARD_MOST_UNTIDY
POSITIVE, // PARK_AWARD_MOST_TIDY
POSITIVE, // PARK_AWARD_BEST_ROLLERCOASTERS
POSITIVE, // PARK_AWARD_BEST_VALUE
POSITIVE, // PARK_AWARD_MOST_BEAUTIFUL
NEGATIVE, // PARK_AWARD_WORST_VALUE
POSITIVE, // PARK_AWARD_SAFEST
POSITIVE, // PARK_AWARD_BEST_STAFF
POSITIVE, // PARK_AWARD_BEST_FOOD
NEGATIVE, // PARK_AWARD_WORST_FOOD
POSITIVE, // PARK_AWARD_BEST_RESTROOMS
NEGATIVE, // PARK_AWARD_MOST_DISAPPOINTING
POSITIVE, // PARK_AWARD_BEST_WATER_RIDES
POSITIVE, // PARK_AWARD_BEST_CUSTOM_DESIGNED_RIDES
POSITIVE, // PARK_AWARD_MOST_DAZZLING_RIDE_COLOURS
NEGATIVE, // PARK_AWARD_MOST_CONFUSING_LAYOUT
POSITIVE, // PARK_AWARD_BEST_GENTLE_RIDES
NEGATIVE, // ParkAward::MostUntidy
POSITIVE, // ParkAward::MostTidy
POSITIVE, // ParkAward::BestRollerCoasters
POSITIVE, // ParkAward::BestValue
POSITIVE, // ParkAward::MostBeautiful
NEGATIVE, // ParkAward::WorstValue
POSITIVE, // ParkAward::Safest
POSITIVE, // ParkAward::BestStaff
POSITIVE, // ParkAward::BestFood
NEGATIVE, // ParkAward::WorstFood
POSITIVE, // ParkAward::BestRestrooms
NEGATIVE, // ParkAward::MostDisappointing
POSITIVE, // ParkAward::BestWaterRides
POSITIVE, // ParkAward::BestCustomDesignedRides
POSITIVE, // ParkAward::MostDazzlingRideColours
NEGATIVE, // ParkAward::MostConfusingLayout
POSITIVE, // ParkAward::BestGentleRides
};

static constexpr const rct_string_id AwardNewsStrings[] = {
Expand Down Expand Up @@ -77,11 +77,11 @@ bool award_is_positive(int32_t type)
/** More than 1/16 of the total guests must be thinking untidy thoughts. */
static bool award_is_deserved_most_untidy(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_MOST_BEAUTIFUL))
if (activeAwardTypes & EnumToFlag(ParkAward::MostBeautiful))
return false;
if (activeAwardTypes & (1 << PARK_AWARD_BEST_STAFF))
if (activeAwardTypes & EnumToFlag(ParkAward::BestStaff))
return false;
if (activeAwardTypes & (1 << PARK_AWARD_MOST_TIDY))
if (activeAwardTypes & EnumToFlag(ParkAward::MostTidy))
return false;

uint32_t negativeCount = 0;
Expand All @@ -107,9 +107,9 @@ static bool award_is_deserved_most_untidy(int32_t activeAwardTypes)
/** More than 1/64 of the total guests must be thinking tidy thoughts and less than 6 guests thinking untidy thoughts. */
static bool award_is_deserved_most_tidy(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_MOST_UNTIDY))
if (activeAwardTypes & EnumToFlag(ParkAward::MostUntidy))
return false;
if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
if (activeAwardTypes & EnumToFlag(ParkAward::MostDisappointing))
return false;

uint32_t positiveCount = 0;
Expand Down Expand Up @@ -166,10 +166,10 @@ static bool award_is_deserved_best_rollercoasters([[maybe_unused]] int32_t activ
/** Entrance fee is 0.10 less than half of the total ride value. */
static bool award_is_deserved_best_value(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_WORST_VALUE))
if (activeAwardTypes & EnumToFlag(ParkAward::WorstValue))
return false;

if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
if (activeAwardTypes & EnumToFlag(ParkAward::MostDisappointing))
return false;

if ((gParkFlags & PARK_FLAGS_NO_MONEY) || !park_entry_price_unlocked())
Expand All @@ -187,9 +187,9 @@ static bool award_is_deserved_best_value(int32_t activeAwardTypes)
/** More than 1/128 of the total guests must be thinking scenic thoughts and fewer than 16 untidy thoughts. */
static bool award_is_deserved_most_beautiful(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_MOST_UNTIDY))
if (activeAwardTypes & EnumToFlag(ParkAward::MostUntidy))
return false;
if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
if (activeAwardTypes & EnumToFlag(ParkAward::MostDisappointing))
return false;

uint32_t positiveCount = 0;
Expand Down Expand Up @@ -220,7 +220,7 @@ static bool award_is_deserved_most_beautiful(int32_t activeAwardTypes)
/** Entrance fee is more than total ride value. */
static bool award_is_deserved_worst_value(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_BEST_VALUE))
if (activeAwardTypes & EnumToFlag(ParkAward::BestValue))
return false;
if (gParkFlags & PARK_FLAGS_NO_MONEY)
return false;
Expand Down Expand Up @@ -263,7 +263,7 @@ static bool award_is_deserved_safest([[maybe_unused]] int32_t activeAwardTypes)
/** All staff types, at least 20 staff, one staff per 32 peeps. */
static bool award_is_deserved_best_staff(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_MOST_UNTIDY))
if (activeAwardTypes & EnumToFlag(ParkAward::MostUntidy))
return false;

auto peepCount = 0;
Expand All @@ -288,7 +288,7 @@ static bool award_is_deserved_best_staff(int32_t activeAwardTypes)
/** At least 7 shops, 4 unique, one shop per 128 guests and no more than 12 hungry guests. */
static bool award_is_deserved_best_food(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_WORST_FOOD))
if (activeAwardTypes & EnumToFlag(ParkAward::WorstFood))
return false;

uint32_t shops = 0;
Expand Down Expand Up @@ -332,7 +332,7 @@ static bool award_is_deserved_best_food(int32_t activeAwardTypes)
/** No more than 2 unique shops, less than one shop per 256 guests and more than 15 hungry guests. */
static bool award_is_deserved_worst_food(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_BEST_FOOD))
if (activeAwardTypes & EnumToFlag(ParkAward::BestFood))
return false;

uint32_t shops = 0;
Expand Down Expand Up @@ -406,7 +406,7 @@ static bool award_is_deserved_best_restrooms([[maybe_unused]] int32_t activeAwar
/** More than half of the rides have satisfaction <= 6 and park rating <= 650. */
static bool award_is_deserved_most_disappointing(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_BEST_VALUE))
if (activeAwardTypes & EnumToFlag(ParkAward::BestValue))
return false;
if (gParkRating > 650)
return false;
Expand Down Expand Up @@ -461,7 +461,7 @@ static bool award_is_deserved_best_water_rides([[maybe_unused]] int32_t activeAw
/** At least 6 custom designed rides. */
static bool award_is_deserved_best_custom_designed_rides(int32_t activeAwardTypes)
{
if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
if (activeAwardTypes & EnumToFlag(ParkAward::MostDisappointing))
return false;

auto customDesignedRides = 0;
Expand All @@ -488,7 +488,7 @@ static bool award_is_deserved_most_dazzling_ride_colours(int32_t activeAwardType
static constexpr const colour_t dazzling_ride_colours[] = { COLOUR_BRIGHT_PURPLE, COLOUR_BRIGHT_GREEN, COLOUR_LIGHT_ORANGE,
COLOUR_BRIGHT_PINK };

if (activeAwardTypes & (1 << PARK_AWARD_MOST_DISAPPOINTING))
if (activeAwardTypes & EnumToFlag(ParkAward::MostDisappointing))
return false;

auto countedRides = 0;
Expand Down
38 changes: 19 additions & 19 deletions src/openrct2/management/Award.h
Expand Up @@ -17,26 +17,26 @@ struct Award
uint16_t Type;
};

enum PARK_AWARD
enum class ParkAward : uint8_t
{
PARK_AWARD_MOST_UNTIDY,
PARK_AWARD_MOST_TIDY,
PARK_AWARD_BEST_ROLLERCOASTERS,
PARK_AWARD_BEST_VALUE,
PARK_AWARD_MOST_BEAUTIFUL,
PARK_AWARD_WORST_VALUE,
PARK_AWARD_SAFEST,
PARK_AWARD_BEST_STAFF,
PARK_AWARD_BEST_FOOD,
PARK_AWARD_WORST_FOOD,
PARK_AWARD_BEST_RESTROOMS,
PARK_AWARD_MOST_DISAPPOINTING,
PARK_AWARD_BEST_WATER_RIDES,
PARK_AWARD_BEST_CUSTOM_DESIGNED_RIDES,
PARK_AWARD_MOST_DAZZLING_RIDE_COLOURS,
PARK_AWARD_MOST_CONFUSING_LAYOUT,
PARK_AWARD_BEST_GENTLE_RIDES,
PARK_AWARD_COUNT
MostUntidy,
MostTidy,
BestRollerCoasters,
BestValue,
MostBeautiful,
WorstValue,
Safest,
BestStaff,
BestFood,
WorstFood,
BestRestrooms,
MostDisappointing,
BestWaterRides,
BestCustomDesignedRides,
MostDazzlingRideColours,
MostConfusingLayout,
BestGentleRides,
Count
};

#define MAX_AWARDS 4
Expand Down

0 comments on commit 147daa8

Please sign in to comment.