Refactor variable names in window_guest_stats_bars_paint (#13214)

* Refactor variable names in window_guest_stats_bars_paint

Change the variables eax/ebp to timeInPark and barColor, respectively.

* Refactor guest stat UI calculations

Simplify guest stat calculations and move them to a new function NormalizeGuestStatValue.
This commit is contained in:
aw20368 2020-10-21 02:38:44 -04:00 committed by GitHub
parent 1f245b8288
commit c81bf7b501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 91 deletions

View File

@ -1256,10 +1256,9 @@ void window_guest_stats_update(rct_window* w)
*
* rct2: 0x0066ECC1
*
* ebp: colour, contains flag BAR_BLINK for blinking
*/
static void window_guest_stats_bars_paint(
int32_t value, int32_t x, int32_t y, rct_window* w, rct_drawpixelinfo* dpi, int32_t colour)
int32_t value, int32_t x, int32_t y, rct_window* w, rct_drawpixelinfo* dpi, int32_t colour, bool blinkFlag)
{
if (font_get_line_height(gCurrentFontSpriteBase) > 10)
{
@ -1268,10 +1267,7 @@ static void window_guest_stats_bars_paint(
gfx_fill_rect_inset(dpi, x + 61, y + 1, x + 61 + 121, y + 9, w->colours[1], INSET_RECT_F_30);
int32_t blink_flag = colour & BAR_BLINK;
colour &= ~BAR_BLINK;
if (!blink_flag || game_is_paused() || (gCurrentRealTimeTicks & 8) == 0)
if (!blinkFlag || game_is_paused() || (gCurrentRealTimeTicks & 8) == 0)
{
value *= 118;
value >>= 8;
@ -1283,6 +1279,16 @@ static void window_guest_stats_bars_paint(
}
}
/**
* Takes a guest stat value (scaled to currMax) and adjusts it to be scaled out of 255.
* Then clamp the value to between newMin and 255.
*/
static int32_t NormalizeGuestStatValue(int32_t value, int32_t currMax, int32_t newMin)
{
int32_t newValue = (value * 255) / currMax;
return std::clamp(newValue, newMin, 255);
}
/**
*
* rct2: 0x0069711D
@ -1314,123 +1320,66 @@ void window_guest_stats_paint(rct_window* w, rct_drawpixelinfo* dpi)
// Happiness
gfx_draw_string_left(dpi, STR_GUEST_STAT_HAPPINESS_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t happiness = peep->Happiness;
if (happiness < 10)
happiness = 10;
int32_t ebp = COLOUR_BRIGHT_GREEN;
if (happiness < 50)
{
ebp |= BAR_BLINK;
}
window_guest_stats_bars_paint(happiness, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t happiness = NormalizeGuestStatValue(peep->Happiness, PEEP_MAX_HAPPINESS, 10);
int32_t barColour = COLOUR_BRIGHT_GREEN;
bool barBlink = happiness < 50;
window_guest_stats_bars_paint(happiness, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Energy
screenCoords.y += LIST_ROW_HEIGHT;
gfx_draw_string_left(dpi, STR_GUEST_STAT_ENERGY_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t energy = ((peep->Energy - PEEP_MIN_ENERGY) * 255) / (PEEP_MAX_ENERGY - PEEP_MIN_ENERGY);
ebp = COLOUR_BRIGHT_GREEN;
if (energy < 50)
{
ebp |= BAR_BLINK;
}
if (energy < 10)
energy = 10;
window_guest_stats_bars_paint(energy, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t energy = NormalizeGuestStatValue(peep->Energy - PEEP_MIN_ENERGY, PEEP_MAX_ENERGY - PEEP_MIN_ENERGY, 10);
barColour = COLOUR_BRIGHT_GREEN;
barBlink = energy < 50;
window_guest_stats_bars_paint(energy, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Hunger
screenCoords.y += LIST_ROW_HEIGHT;
gfx_draw_string_left(dpi, STR_GUEST_STAT_HUNGER_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t hunger = peep->Hunger;
if (hunger > 190)
hunger = 190;
hunger -= 32;
if (hunger < 0)
hunger = 0;
hunger *= 51;
hunger /= 32;
hunger = 0xFF & ~hunger;
ebp = COLOUR_BRIGHT_RED;
if (hunger > 170)
{
ebp |= BAR_BLINK;
}
window_guest_stats_bars_paint(hunger, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t hunger = NormalizeGuestStatValue(peep->Hunger - 32, 158, 0);
hunger = 255 - hunger; // the bar should be longer when peep->Hunger is low
barColour = COLOUR_BRIGHT_RED;
barBlink = hunger > 170;
window_guest_stats_bars_paint(hunger, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Thirst
screenCoords.y += LIST_ROW_HEIGHT;
gfx_draw_string_left(dpi, STR_GUEST_STAT_THIRST_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t thirst = peep->Thirst;
if (thirst > 190)
thirst = 190;
thirst -= 32;
if (thirst < 0)
thirst = 0;
thirst *= 51;
thirst /= 32;
thirst = 0xFF & ~thirst;
ebp = COLOUR_BRIGHT_RED;
if (thirst > 170)
{
ebp |= BAR_BLINK;
}
window_guest_stats_bars_paint(thirst, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t thirst = NormalizeGuestStatValue(peep->Thirst - 32, 158, 0);
thirst = 255 - thirst; // the bar should be longer when peep->Thirst is low
barColour = COLOUR_BRIGHT_RED;
barBlink = thirst > 170;
window_guest_stats_bars_paint(thirst, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Nausea
screenCoords.y += LIST_ROW_HEIGHT;
gfx_draw_string_left(dpi, STR_GUEST_STAT_NAUSEA_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t nausea = peep->Nausea - 32;
if (nausea < 0)
nausea = 0;
nausea *= 36;
nausea /= 32;
ebp = COLOUR_BRIGHT_RED;
if (nausea > 120)
{
ebp |= BAR_BLINK;
}
window_guest_stats_bars_paint(nausea, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t nausea = NormalizeGuestStatValue(peep->Nausea - 32, 223, 0);
barColour = COLOUR_BRIGHT_RED;
barBlink = nausea > 120;
window_guest_stats_bars_paint(nausea, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Toilet
screenCoords.y += LIST_ROW_HEIGHT;
gfx_draw_string_left(dpi, STR_GUEST_STAT_TOILET_LABEL, nullptr, COLOUR_BLACK, screenCoords);
int32_t toilet = peep->Toilet - 32;
if (toilet > 210)
toilet = 210;
toilet -= 32;
if (toilet < 0)
toilet = 0;
toilet *= 45;
toilet /= 32;
ebp = COLOUR_BRIGHT_RED;
if (toilet > 160)
{
ebp |= BAR_BLINK;
}
window_guest_stats_bars_paint(toilet, screenCoords.x, screenCoords.y, w, dpi, ebp);
int32_t toilet = NormalizeGuestStatValue(peep->Toilet - 64, 178, 0);
barColour = COLOUR_BRIGHT_RED;
barBlink = toilet > 160;
window_guest_stats_bars_paint(toilet, screenCoords.x, screenCoords.y, w, dpi, barColour, barBlink);
// Time in park
screenCoords.y += LIST_ROW_HEIGHT + 1;
int32_t guestEntryTime = peep->GetParkEntryTime();
if (guestEntryTime != -1)
{
int32_t eax = gScenarioTicks;
eax -= guestEntryTime;
eax >>= 11;
int32_t timeInPark = (gScenarioTicks - guestEntryTime) >> 11;
auto ft = Formatter();
ft.Add<uint16_t>(eax & 0xFFFF);
ft.Add<uint16_t>(timeInPark & 0xFFFF);
gfx_draw_string_left(dpi, STR_GUEST_STAT_TIME_IN_PARK, ft.Data(), COLOUR_BLACK, screenCoords);
}