diff --git a/src/openrct2/peep/Guest.cpp b/src/openrct2/peep/Guest.cpp index 6c4fa6d309..bfdd9e3599 100644 --- a/src/openrct2/peep/Guest.cpp +++ b/src/openrct2/peep/Guest.cpp @@ -891,11 +891,6 @@ void rct_peep::TryGetUpFromSitting() UpdateCurrentActionSpriteType(); } -/** rct2: 0x00981F2C, 0x00981F2E */ -static constexpr const LocationXY16 _981F2C[] = { - { 7, 12 }, { 12, 25 }, { 25, 20 }, { 20, 7 }, { 7, 20 }, { 20, 25 }, { 25, 12 }, { 12, 7 }, -}; - /** * * rct2: 0x0069152B @@ -916,8 +911,8 @@ void rct_peep::UpdateSitting() sint32 ebx = var_37 & 0x7; LocationXYZ16 loc = { - (sint16)((x & 0xFFE0) + _981F2C[ebx].x), - (sint16)((y & 0xFFE0) + _981F2C[ebx].y), + (sint16)((x & 0xFFE0) + BenchUseOffsets[ebx].x), + (sint16)((y & 0xFFE0) + BenchUseOffsets[ebx].y), z }; @@ -5125,8 +5120,6 @@ void rct_peep::UpdateRide() } } -static sint32 peep_update_walking_find_bench(rct_peep * peep); -static sint32 peep_update_walking_find_bin(rct_peep * peep); static void peep_update_walking_break_scenery(rct_peep * peep); static bool peep_find_ride_to_look_at(rct_peep * peep, uint8 edge, uint8 * rideToView, uint8 * rideSeatToView); @@ -5279,10 +5272,10 @@ void rct_peep::UpdateWalking() CheckCantFindRide(); CheckCantFindExit(); - if (peep_update_walking_find_bench(this)) + if (UpdateWalkingFindBench()) return; - if (peep_update_walking_find_bin(this)) + if (UpdateWalkingFindBin()) return; peep_update_walking_break_scenery(this); @@ -5867,27 +5860,27 @@ void rct_peep::UpdateUsingBin() } } -/* Simplifies 0x690582. Returns 1 if should find bench*/ -static bool peep_should_find_bench(rct_peep * peep) +/* Simplifies 0x690582. Returns true if should find bench*/ +bool rct_peep::ShouldFindBench() { - if (!(peep->peep_flags & PEEP_FLAGS_LEAVING_PARK)) + if (!(peep_flags & PEEP_FLAGS_LEAVING_PARK)) { - if (peep->HasFood()) + if (HasFood()) { - if (peep->hunger < 128 || peep->happiness < 128) + if (hunger < 128 || happiness < 128) { - if (!peep->GetNextIsSurface() && !peep->GetNextIsSloped()) + if (!GetNextIsSurface() && !GetNextIsSloped()) { return true; } } } - if (peep->nausea <= 170 && peep->energy > 50) + if (nausea <= 170 && energy > 50) { return false; } - if (!peep->GetNextIsSurface() && !peep->GetNextIsSloped()) + if (!GetNextIsSurface() && !GetNextIsSloped()) { return true; } @@ -5898,50 +5891,51 @@ static bool peep_should_find_bench(rct_peep * peep) /** * * rct2: 0x00690582 + * Returns true when the guest wants to sit down and has found a bench to sit on */ -static sint32 peep_update_walking_find_bench(rct_peep * peep) +bool rct_peep::UpdateWalkingFindBench() { - if (!peep_should_find_bench(peep)) - return 0; + if (!ShouldFindBench()) + return false; - rct_tile_element * tile_element = map_get_first_element_at(peep->next_x / 32, peep->next_y / 32); + rct_tile_element * tile_element = map_get_first_element_at(next_x / 32, next_y / 32); for (;; tile_element++) { if (tile_element->GetType() == TILE_ELEMENT_TYPE_PATH) { - if (peep->next_z == tile_element->base_height) + if (next_z == tile_element->base_height) break; } if (tile_element_is_last_for_tile(tile_element)) { - return 0; + return false; } } if (!footpath_element_has_path_scenery(tile_element)) - return 0; + return false; rct_scenery_entry * sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); if (sceneryEntry == nullptr || !(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BENCH)) - return 0; + return false; if (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) - return 0; + return false; if (footpath_element_path_scenery_is_ghost(tile_element)) - return 0; + return false; sint32 edges = (tile_element->properties.path.edges & 0xF) ^ 0xF; if (edges == 0) - return 0; + return false; uint8 chosen_edge = scenario_rand() & 0x3; for (; !(edges & (1 << chosen_edge));) chosen_edge = (chosen_edge + 1) & 0x3; - uint16 sprite_id = sprite_get_first_in_quadrant(peep->x, peep->y); + uint16 sprite_id = sprite_get_first_in_quadrant(x, y); uint8 free_edge = 3; // Check if there is no peep sitting in chosen_edge @@ -5955,7 +5949,7 @@ static sint32 peep_update_walking_find_bench(rct_peep * peep) if (sprite->peep.state != PEEP_STATE_SITTING) continue; - if (peep->z != sprite->peep.z) + if (z != sprite->peep.z) continue; if ((sprite->peep.var_37 & 0x3) != chosen_edge) @@ -5965,7 +5959,7 @@ static sint32 peep_update_walking_find_bench(rct_peep * peep) } if (!free_edge) - return 0; + return false; free_edge ^= 0x3; if (!free_edge) @@ -5974,30 +5968,31 @@ static sint32 peep_update_walking_find_bench(rct_peep * peep) free_edge = 1; } - peep->var_37 = ((free_edge & 1) << 2) | chosen_edge; + var_37 = ((free_edge & 1) << 2) | chosen_edge; - peep->SetState(PEEP_STATE_SITTING); + SetState(PEEP_STATE_SITTING); - peep->sub_state = PEEP_SITTING_TRYING_TO_SIT; + sub_state = PEEP_SITTING_TRYING_TO_SIT; - sint32 ebx = peep->var_37 & 0x7; - sint32 x = (peep->x & 0xFFE0) + _981F2C[ebx].x; - sint32 y = (peep->y & 0xFFE0) + _981F2C[ebx].y; + sint32 ebx = var_37 & 0x7; + sint32 benchX = (x & 0xFFE0) + BenchUseOffsets[ebx].x; + sint32 benchY = (y & 0xFFE0) + BenchUseOffsets[ebx].y; - peep->destination_x = x; - peep->destination_y = y; - peep->destination_tolerance = 3; + destination_x = benchX; + destination_y = benchY; + destination_tolerance = 3; - return 1; + return true; } -static sint32 peep_update_walking_find_bin(rct_peep * peep) +bool rct_peep::UpdateWalkingFindBin() { + auto peep = this; if (!peep->HasEmptyContainer()) - return 0; + return false; if (peep->GetNextIsSurface()) - return 0; + return false; rct_tile_element * tile_element = map_get_first_element_at(peep->next_x / 32, peep->next_y / 32); @@ -6010,30 +6005,30 @@ static sint32 peep_update_walking_find_bin(rct_peep * peep) } if (tile_element_is_last_for_tile(tile_element)) { - return 0; + return false; } } if (!footpath_element_has_path_scenery(tile_element)) - return 0; + return false; rct_scenery_entry * sceneryEntry = get_footpath_item_entry(footpath_element_get_path_scenery_index(tile_element)); if (sceneryEntry == nullptr) { - return 0; + return false; } if (!(sceneryEntry->path_bit.flags & PATH_BIT_FLAG_IS_BIN)) - return 0; + return false; if (tile_element->flags & TILE_ELEMENT_FLAG_BROKEN) - return 0; + return false; if (footpath_element_path_scenery_is_ghost(tile_element)) - return 0; + return false; sint32 edges = (tile_element->properties.path.edges & 0xF) ^ 0xF; if (edges == 0) - return 0; + return false; uint8 chosen_edge = scenario_rand() & 0x3; @@ -6062,15 +6057,15 @@ static sint32 peep_update_walking_find_bin(rct_peep * peep) peep->SetState(PEEP_STATE_USING_BIN); peep->sub_state = 0; - sint32 ebx = peep->var_37 & 0x3; - sint32 x = (peep->x & 0xFFE0) + BinUseOffsets[ebx].x; - sint32 y = (peep->y & 0xFFE0) + BinUseOffsets[ebx].y; + sint32 ebx = peep->var_37 & 0x3; + sint32 binX = (peep->x & 0xFFE0) + BinUseOffsets[ebx].x; + sint32 binY = (peep->y & 0xFFE0) + BinUseOffsets[ebx].y; - peep->destination_x = x; - peep->destination_y = y; + peep->destination_x = binX; + peep->destination_y = binY; peep->destination_tolerance = 3; - return 1; + return true; } /** diff --git a/src/openrct2/peep/Peep.cpp b/src/openrct2/peep/Peep.cpp index 07d39d06b4..1b3d9d8558 100644 --- a/src/openrct2/peep/Peep.cpp +++ b/src/openrct2/peep/Peep.cpp @@ -304,11 +304,6 @@ static struct { PEEP_ACTION_NONE_2, 1 }, }; -/** rct2: 0x00981F2C, 0x00981F2E */ -static constexpr const LocationXY16 _981F2C[] = { - { 7, 12 }, { 12, 25 }, { 25, 20 }, { 20, 7 }, { 7, 20 }, { 20, 25 }, { 25, 12 }, { 12, 7 }, -}; - static uint8 PeepSpecialSpriteToSpriteTypeMap[] = { PEEP_ACTION_SPRITE_TYPE_NONE, PEEP_ACTION_SPRITE_TYPE_HOLD_MAT, diff --git a/src/openrct2/peep/Peep.h b/src/openrct2/peep/Peep.h index eaacd83774..d647ce0771 100644 --- a/src/openrct2/peep/Peep.h +++ b/src/openrct2/peep/Peep.h @@ -784,6 +784,9 @@ public: // Guest void ReadMap(); bool ShouldGoOnRide(sint32 rideIndex, sint32 entranceNum, bool atQueue, bool thinking); bool ShouldGoToShop(sint32 rideIndex, bool peepAtShop); + bool ShouldFindBench(); + bool UpdateWalkingFindBench(); + bool UpdateWalkingFindBin(); void SpendMoney(money16 & peep_expend_type, money32 amount); void SpendMoney(money32 amount); void SetHasRidden(sint32 rideIndex); diff --git a/src/openrct2/world/Footpath.cpp b/src/openrct2/world/Footpath.cpp index 110fbaeef7..a20836fcc4 100644 --- a/src/openrct2/world/Footpath.cpp +++ b/src/openrct2/world/Footpath.cpp @@ -66,6 +66,18 @@ const LocationXY16 BinUseOffsets[4] = { { 16, 11 }, }; +// These are the offsets for bench positions on footpaths, 2 for each edge +// rct2: 0x00981F2C, 0x00981F2E +const LocationXY16 BenchUseOffsets[8] = { + { 7, 12 }, + { 12, 25 }, + { 25, 20 }, + { 20, 7 }, + { 7, 20 }, + { 20, 25 }, + { 25, 12 }, + { 12, 7 }, +}; /** rct2: 0x00981D6C, 0x00981D6E */ const LocationXY16 word_981D6C[4] = { diff --git a/src/openrct2/world/Footpath.h b/src/openrct2/world/Footpath.h index 038ffc67b3..d5ef69266a 100644 --- a/src/openrct2/world/Footpath.h +++ b/src/openrct2/world/Footpath.h @@ -128,6 +128,7 @@ extern uint8 gFootpathGroundFlags; extern const LocationXY16 word_981D6C[4]; extern const LocationXY16 BinUseOffsets[4]; +extern const LocationXY16 BenchUseOffsets[8]; rct_tile_element *map_get_footpath_element(sint32 x, sint32 y, sint32 z); money32 footpath_remove_real(sint32 x, sint32 y, sint32 z, sint32 flags);