From c699c9134882697158e49eab0b131fd6317da066 Mon Sep 17 00:00:00 2001 From: Ted John Date: Tue, 24 Jan 2017 13:05:02 +0000 Subject: [PATCH] Pick random entertainer costume --- src/openrct2/peep/staff.c | 45 ++++++++++++++++++++++++++++--- src/openrct2/peep/staff.h | 2 ++ src/openrct2/windows/staff.c | 23 ++-------------- src/openrct2/windows/staff_list.c | 12 +++++++-- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/openrct2/peep/staff.c b/src/openrct2/peep/staff.c index d7122ea225..2ba5ef536c 100644 --- a/src/openrct2/peep/staff.c +++ b/src/openrct2/peep/staff.c @@ -16,16 +16,17 @@ #include "../config.h" #include "../game.h" -#include "../scenario/scenario.h" #include "../interface/viewport.h" #include "../localisation/date.h" -#include "../localisation/string_ids.h" #include "../localisation/localisation.h" +#include "../localisation/string_ids.h" #include "../management/finance.h" #include "../network/network.h" +#include "../scenario/scenario.h" #include "../util/util.h" -#include "../world/sprite.h" #include "../world/footpath.h" +#include "../world/scenery.h" +#include "../world/sprite.h" #include "peep.h" #include "staff.h" @@ -174,6 +175,14 @@ static money32 staff_hire_new_staff_member(uint8 staff_type, uint8 flags, sint16 // Invalid entertainer costume return MONEY32_UNDEFINED; } + + uint32 availableCostumes = staff_get_available_entertainer_costumes(); + if (!(availableCostumes & (1 << entertainerType))) + { + // Entertainer costume unavailable + return MONEY32_UNDEFINED; + } + staff_type = STAFF_TYPE_ENTERTAINER; } @@ -1414,3 +1423,33 @@ bool staff_set_colour(uint8 staffType, colour_t value) } return true; } + +uint32 staff_get_available_entertainer_costumes() +{ + init_scenery(); + + uint32 entertainerCostumes = 0; + for (sint32 i = 0; i < 19; i++) { + if (window_scenery_tab_entries[i][0] != -1) { + rct_scenery_set_entry* scenery_entry = get_scenery_group_entry(i); + entertainerCostumes |= scenery_entry->entertainer_costumes; + } + } + + // For some reason the flags are +4 from the actual costume IDs + entertainerCostumes <<= 4; + + return entertainerCostumes; +} + +sint32 staff_get_available_entertainer_costume_list(uint8 * costumeList) +{ + uint32 availableCostumes = staff_get_available_entertainer_costumes(); + sint32 numCostumes = 0; + for (uint8 i = 0; i < ENTERTAINER_COSTUME_COUNT; i++) { + if (availableCostumes & (1 << i)) { + costumeList[numCostumes++] = i; + } + } + return numCostumes; +} diff --git a/src/openrct2/peep/staff.h b/src/openrct2/peep/staff.h index e72a3830d3..c5d4e198ea 100644 --- a/src/openrct2/peep/staff.h +++ b/src/openrct2/peep/staff.h @@ -88,5 +88,7 @@ void staff_set_patrol_area(sint32 staffIndex, sint32 x, sint32 y, bool value); void staff_toggle_patrol_area(sint32 staffIndex, sint32 x, sint32 y); colour_t staff_get_colour(uint8 staffType); bool staff_set_colour(uint8 staffType, colour_t value); +uint32 staff_get_available_entertainer_costumes(); +sint32 staff_get_available_entertainer_costume_list(uint8 * costumeList); #endif diff --git a/src/openrct2/windows/staff.c b/src/openrct2/windows/staff.c index 4f8a3313c1..4790b4b38f 100644 --- a/src/openrct2/windows/staff.c +++ b/src/openrct2/windows/staff.c @@ -1296,32 +1296,13 @@ void window_staff_options_mousedown(sint32 widgetIndex, rct_window* w, rct_widge return; } - init_scenery(); - - uint32 entertainerCostumes = 0; - for (sint32 i = 0; i < 19; i++) { - if (window_scenery_tab_entries[i][0] != -1) { - rct_scenery_set_entry* scenery_entry = get_scenery_group_entry(i); - entertainerCostumes |= scenery_entry->entertainer_costumes; - } - } - - uint8 *costumep = _availableCostumes; - uint16 numCostumes = 0; - for (uint8 i = 0; i < ENTERTAINER_COSTUME_COUNT; i++) { - if (entertainerCostumes & (1 << i)) { - // For some reason the flags are +4 from the actual costume IDs - *costumep++ = (i - 4); - numCostumes++; - } - } - rct_peep* peep = GET_PEEP(w->number); sint32 itemsChecked = 0; //This will be moved below where Items Checked is when all //of dropdown related functions are finished. This prevents //the dropdown from not working on first click. - for (sint32 i = 0; i < numCostumes; ++i){ + sint32 numCostumes = staff_get_available_entertainer_costume_list(_availableCostumes); + for (sint32 i = 0; i < numCostumes; i++) { uint8 costume = _availableCostumes[i]; if (costume == peep->sprite_type) { itemsChecked = 1 << i; diff --git a/src/openrct2/windows/staff_list.c b/src/openrct2/windows/staff_list.c index 95af821314..218acd98d7 100644 --- a/src/openrct2/windows/staff_list.c +++ b/src/openrct2/windows/staff_list.c @@ -15,8 +15,8 @@ #pragma endregion #include "../config.h" -#include "../game.h" #include "../drawing/drawing.h" +#include "../game.h" #include "../input.h" #include "../interface/themes.h" #include "../interface/viewport.h" @@ -27,6 +27,7 @@ #include "../peep/staff.h" #include "../rct2.h" #include "../sprites.h" +#include "../util/util.h" #include "../world/footpath.h" #include "../world/sprite.h" #include "dropdown.h" @@ -706,5 +707,12 @@ void window_staff_list_scrollpaint(rct_window *w, rct_drawpixelinfo *dpi, sint32 static uint8 window_staff_list_get_random_entertainer_costume() { - return ENTERTAINER_COSTUME_PANDA; + uint8 result = ENTERTAINER_COSTUME_PANDA; + uint8 costumeList[ENTERTAINER_COSTUME_COUNT]; + sint32 numCostumes = staff_get_available_entertainer_costume_list(costumeList); + if (numCostumes > 0) + { + result = util_rand() % numCostumes; + } + return result; }