Make peep_has_food, has_item and has_drink member functions

This commit is contained in:
Hielke Morsink 2018-04-03 17:12:53 +02:00 committed by duncanspumpkin
parent a70301c114
commit 6e02d6af4c
4 changed files with 41 additions and 38 deletions

View File

@ -2107,7 +2107,7 @@ void window_guest_inventory_paint(rct_window *w, rct_drawpixelinfo *dpi)
for (sint32 item = 0; item < SHOP_ITEM_COUNT; item++) {
if (y >= maxY) break;
if (!peep_has_item(peep, item)) continue;
if (!peep->HasItem(item)) continue;
rct_string_id stringId = window_guest_inventory_format_item(peep, item);
y += gfx_draw_string_left_wrapped(dpi, gCommonFormatArgs, x, y, itemNameWidth, stringId, COLOUR_BLACK);

View File

@ -124,7 +124,7 @@ static void peep_tried_to_enter_full_queue(rct_peep * peep, sint32 rideIndex);
void rct_peep::TryGetUpFromSitting()
{
// Eats all food first
if (peep_has_food(this))
if (HasFood())
return;
time_to_sitdown--;
@ -215,7 +215,7 @@ void rct_peep::UpdateSitting()
return;
}
if (peep_has_food(this))
if (HasFood())
{
if ((scenario_rand() & 0xFFFF) > 1310)
{
@ -309,7 +309,7 @@ void rct_peep::PickRideToGoOn()
return;
if (this->peep_flags & PEEP_FLAGS_LEAVING_PARK)
return;
if (peep_has_food(this))
if (HasFood())
return;
if (this->x == LOCATION_NULL)
return;

View File

@ -118,9 +118,6 @@ static void * _crowdSoundChannel = nullptr;
static void peep_128_tick_update(rct_peep * peep, sint32 index);
static bool peep_has_empty_container(rct_peep * peep);
static bool peep_has_drink(rct_peep * peep);
static sint32 peep_has_food_standard_flag(rct_peep * peep);
static sint32 peep_has_food_extra_flag(rct_peep * peep);
static sint32 peep_empty_container_standard_flag(rct_peep * peep);
static sint32 peep_empty_container_extra_flag(rct_peep * peep);
static bool peep_should_find_bench(rct_peep * peep);
@ -1056,12 +1053,12 @@ static void peep_128_tick_update(rct_peep * peep, sint32 index)
possible_thoughts[num_thoughts++] = PEEP_THOUGHT_TYPE_TIRED;
}
if (peep->hunger <= 10 && !peep_has_food(peep))
if (peep->hunger <= 10 && !peep->HasFood())
{
possible_thoughts[num_thoughts++] = PEEP_THOUGHT_TYPE_HUNGRY;
}
if (peep->thirst <= 25 && !peep_has_food(peep))
if (peep->thirst <= 25 && !peep->HasFood())
{
possible_thoughts[num_thoughts++] = PEEP_THOUGHT_TYPE_THIRSTY;
}
@ -1261,7 +1258,7 @@ static void peep_128_tick_update(rct_peep * peep, sint32 index)
// Remaining content is executed every call.
// 68FA89
if (peep->time_to_consume == 0 && peep_has_food(peep))
if (peep->time_to_consume == 0 && peep->HasFood())
{
peep->time_to_consume += 3;
}
@ -1271,7 +1268,7 @@ static void peep_128_tick_update(rct_peep * peep, sint32 index)
peep->time_to_consume = Math::Max(peep->time_to_consume - 3, 0);
if (peep_has_drink(peep))
if (peep->HasDrink())
{
peep->thirst = Math::Min(peep->thirst + 7, 255);
}
@ -1284,7 +1281,7 @@ static void peep_128_tick_update(rct_peep * peep, sint32 index)
if (peep->time_to_consume == 0)
{
sint32 chosen_food = bitscanforward(peep_has_food_standard_flag(peep));
sint32 chosen_food = bitscanforward(peep->HasFoodStandardFlag());
if (chosen_food != -1)
{
peep->item_standard_flags &= ~(1 << chosen_food);
@ -1300,7 +1297,7 @@ static void peep_128_tick_update(rct_peep * peep, sint32 index)
}
else
{
chosen_food = bitscanforward(peep_has_food_extra_flag(peep));
chosen_food = bitscanforward(peep->HasFoodExtraFlag());
if (chosen_food != -1)
{
peep->item_extra_flags &= ~(1 << chosen_food);
@ -3363,7 +3360,7 @@ void rct_peep::UpdateWatching()
}
else
{
if (peep_has_food(this))
if (HasFood())
{
if ((scenario_rand() & 0xFFFF) <= 1310)
{
@ -4154,7 +4151,7 @@ void rct_peep::UpdateWalking()
if (toilet > 140)
return;
uint16 chance = peep_has_food(this) ? 13107 : 2849;
uint16 chance = HasFoodExtraFlag() ? 13107 : 2849;
if ((scenario_rand() & 0xFFFF) > chance)
return;
@ -5354,29 +5351,29 @@ sint32 peep_is_mechanic(rct_peep * peep)
peep->staff_type == STAFF_TYPE_MECHANIC);
}
bool peep_has_item(rct_peep * peep, sint32 peepItem)
bool rct_peep::HasItem(sint32 peepItem) const
{
if (peepItem < 32)
{
return peep->item_standard_flags & (1u << peepItem);
return item_standard_flags & (1u << peepItem);
}
else
{
return peep->item_extra_flags & (1u << (peepItem - 32));
return item_extra_flags & (1u << (peepItem - 32));
}
}
static sint32 peep_has_food_standard_flag(rct_peep * peep)
sint32 rct_peep::HasFoodStandardFlag() const
{
return peep->item_standard_flags &
return item_standard_flags &
(PEEP_ITEM_DRINK | PEEP_ITEM_BURGER | PEEP_ITEM_CHIPS | PEEP_ITEM_ICE_CREAM | PEEP_ITEM_CANDYFLOSS |
PEEP_ITEM_PIZZA | PEEP_ITEM_POPCORN | PEEP_ITEM_HOT_DOG | PEEP_ITEM_TENTACLE | PEEP_ITEM_TOFFEE_APPLE |
PEEP_ITEM_DOUGHNUT | PEEP_ITEM_COFFEE | PEEP_ITEM_CHICKEN | PEEP_ITEM_LEMONADE);
}
static sint32 peep_has_food_extra_flag(rct_peep * peep)
sint32 rct_peep::HasFoodExtraFlag() const
{
return peep->item_extra_flags &
return item_extra_flags &
(PEEP_ITEM_PRETZEL | PEEP_ITEM_CHOCOLATE | PEEP_ITEM_ICED_TEA | PEEP_ITEM_FUNNEL_CAKE | PEEP_ITEM_BEEF_NOODLES |
PEEP_ITEM_FRIED_RICE_NOODLES | PEEP_ITEM_WONTON_SOUP | PEEP_ITEM_MEATBALL_SOUP | PEEP_ITEM_FRUIT_JUICE |
PEEP_ITEM_SOYBEAN_MILK | PEEP_ITEM_SU_JONGKWA | PEEP_ITEM_SUB_SANDWICH | PEEP_ITEM_COOKIE |
@ -5387,19 +5384,19 @@ static sint32 peep_has_food_extra_flag(rct_peep * peep)
* To simplify check of 0x36BA3E0 and 0x11FF78
* returns false on no food.
*/
bool peep_has_food(rct_peep * peep)
bool rct_peep::HasFood() const
{
return peep_has_food_standard_flag(peep) || peep_has_food_extra_flag(peep);
return HasFoodStandardFlag() || HasFoodExtraFlag();
}
static bool peep_has_drink_standard_flag(rct_peep * peep)
bool rct_peep::HasDrinkStandardFlag() const
{
return peep->item_standard_flags & (PEEP_ITEM_DRINK | PEEP_ITEM_COFFEE | PEEP_ITEM_LEMONADE);
return item_standard_flags & (PEEP_ITEM_DRINK | PEEP_ITEM_COFFEE | PEEP_ITEM_LEMONADE);
}
static bool peep_has_drink_extra_flag(rct_peep * peep)
bool rct_peep::HasDrinkExtraFlag() const
{
return peep->item_extra_flags &
return item_extra_flags &
(PEEP_ITEM_CHOCOLATE | PEEP_ITEM_ICED_TEA | PEEP_ITEM_FRUIT_JUICE | PEEP_ITEM_SOYBEAN_MILK | PEEP_ITEM_SU_JONGKWA);
}
@ -5407,9 +5404,9 @@ static bool peep_has_drink_extra_flag(rct_peep * peep)
* To simplify check of NOT(0x12BA3C0 and 0x118F48)
* returns 0 on no food.
*/
static bool peep_has_drink(rct_peep * peep)
bool rct_peep::HasDrink() const
{
return peep_has_drink_standard_flag(peep) || peep_has_drink_extra_flag(peep);
return HasDrinkStandardFlag() || HasDrinkExtraFlag();
}
static sint32 peep_empty_container_standard_flag(rct_peep * peep)
@ -5434,7 +5431,7 @@ static bool peep_should_find_bench(rct_peep * peep)
{
if (!(peep->peep_flags & PEEP_FLAGS_LEAVING_PARK))
{
if (peep_has_food(peep))
if (peep->HasFood())
{
if (peep->hunger < 128 || peep->happiness < 128)
{
@ -8219,7 +8216,7 @@ static sint32 guest_path_finding(rct_peep * peep)
* In principle, peeps with food are not paying as much attention to
* where they are going and are consequently more like to walk up
* dead end paths, paths to ride exits, etc. */
if (!peep_has_food(peep) && (scenario_rand() & 0xFFFF) >= 2184)
if (!peep->HasFood() && (scenario_rand() & 0xFFFF) >= 2184)
{
uint8 adjustedEdges = edges;
for (sint32 chosenDirection = 0; chosenDirection < 4; chosenDirection++)
@ -8997,7 +8994,7 @@ bool rct_peep::DecideAndBuyItem(uint8 rideIndex, sint32 shopItem, money32 price)
hasVoucher = true;
}
if (peep_has_item(this, shopItem))
if (HasItem(shopItem))
{
peep_insert_new_thought(this, PEEP_THOUGHT_TYPE_ALREADY_GOT, shopItem);
return false;
@ -9006,12 +9003,12 @@ bool rct_peep::DecideAndBuyItem(uint8 rideIndex, sint32 shopItem, money32 price)
if (shop_item_is_food_or_drink(shopItem))
{
sint32 food = -1;
if ((food = peep_has_food_standard_flag(this)) != 0)
if ((food = HasFoodStandardFlag()) != 0)
{
peep_insert_new_thought(this, PEEP_THOUGHT_TYPE_HAVENT_FINISHED, bitscanforward(food));
return false;
}
else if ((food = peep_has_food_extra_flag(this)) != 0)
else if ((food = HasFoodExtraFlag()) != 0)
{
peep_insert_new_thought(this, PEEP_THOUGHT_TYPE_HAVENT_FINISHED, bitscanforward(food) + 32);
return false;
@ -10025,7 +10022,7 @@ static void peep_head_for_nearest_ride_with_flags(rct_peep * peep, sint32 rideTy
}
}
if ((rideTypeFlags & RIDE_TYPE_FLAG_IS_BATHROOM) && peep_has_food(peep))
if ((rideTypeFlags & RIDE_TYPE_FLAG_IS_BATHROOM) && peep->HasFood())
{
return;
}

View File

@ -684,6 +684,7 @@ struct rct_peep
uint8 favourite_ride_rating; // 0xFA
uint8 pad_FB;
uint32 item_standard_flags; // 0xFC
void Update();
void SetState(uint8 new_state);
void Remove();
@ -695,6 +696,9 @@ struct rct_peep
void OnEnterRide(uint8 rideIndex);
void OnExitRide(uint8 rideIndex);
void StateReset();
bool HasItem(sint32 peepItem) const;
bool HasFood() const;
bool HasDrink() const;
private:
void UpdateFalling();
@ -763,6 +767,10 @@ public: // TODO: Make these private again when done refactoring - they need to b
bool HasRidden(sint32 rideIndex) const;
void SetHasRiddenRideType(sint32 rideType);
bool HasRiddenRideType(sint32 rideType) const;
sint32 HasFoodStandardFlag() const;
sint32 HasFoodExtraFlag() const;
bool HasDrinkStandardFlag() const;
bool HasDrinkExtraFlag() const;
private:
bool DecideAndBuyItem(uint8 rideIndex, sint32 shopItem, money32 price);
};
@ -882,8 +890,6 @@ sint32 get_peep_face_sprite_large(rct_peep * peep);
sint32 peep_check_easteregg_name(sint32 index, rct_peep * peep);
sint32 peep_get_easteregg_name_id(rct_peep * peep);
sint32 peep_is_mechanic(rct_peep * peep);
bool peep_has_item(rct_peep * peep, sint32 peepItem);
bool peep_has_food(rct_peep * peep);
void peep_pickup(rct_peep * peep);
void peep_pickup_abort(rct_peep * peep, sint32 old_x);
bool peep_pickup_place(rct_peep * peep, sint32 x, sint32 y, sint32 z, bool apply);