Files
OpenRCT2-Web/src/openrct2/entity/Peep.cpp
T

2762 lines
81 KiB
C++
Raw Normal View History

2014-04-03 00:22:33 +01:00
/*****************************************************************************
* Copyright (c) 2014-2020 OpenRCT2 developers
*
2018-06-15 14:07:34 +02:00
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
2018-06-15 14:07:34 +02:00
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2014-04-03 00:22:33 +01:00
2018-06-22 23:04:19 +02:00
#include "Peep.h"
2017-11-26 21:24:57 +01:00
2018-06-22 23:04:19 +02:00
#include "../Cheats.h"
2017-10-13 10:06:36 +02:00
#include "../Context.h"
2018-06-22 23:04:19 +02:00
#include "../Game.h"
#include "../Input.h"
2017-10-13 10:06:36 +02:00
#include "../OpenRCT2.h"
2020-06-17 22:35:13 +01:00
#include "../actions/GameAction.h"
2017-01-03 20:15:02 +00:00
#include "../audio/AudioMixer.h"
2017-10-13 10:06:36 +02:00
#include "../audio/audio.h"
2017-02-18 15:45:10 +00:00
#include "../config/Config.h"
2018-03-13 13:14:02 +01:00
#include "../core/Guard.hpp"
2021-11-27 15:51:54 +02:00
#include "../drawing/LightFX.h"
2021-11-24 16:48:33 +02:00
#include "../entity/Balloon.h"
2021-11-24 16:58:01 +02:00
#include "../entity/EntityRegistry.h"
2021-11-24 16:48:33 +02:00
#include "../entity/EntityTweener.h"
2018-01-06 00:05:16 +00:00
#include "../interface/Window.h"
2018-01-06 18:32:25 +01:00
#include "../localisation/Localisation.h"
2017-10-06 22:37:06 +02:00
#include "../management/Finance.h"
2017-10-11 21:38:26 +02:00
#include "../management/Marketing.h"
#include "../management/NewsItem.h"
2016-10-17 14:26:19 -06:00
#include "../network/network.h"
2021-11-27 15:51:54 +02:00
#include "../paint/Paint.h"
2021-11-25 23:47:24 +02:00
#include "../peep/GuestPathfinding.h"
2017-12-31 13:21:34 +01:00
#include "../ride/Ride.h"
2018-01-10 00:00:09 +01:00
#include "../ride/RideData.h"
2018-05-14 19:21:43 +02:00
#include "../ride/ShopItem.h"
2018-06-22 23:04:19 +02:00
#include "../ride/Station.h"
#include "../ride/Track.h"
2018-01-02 17:58:43 +00:00
#include "../scenario/Scenario.h"
2014-10-06 17:36:58 +01:00
#include "../sprites.h"
2017-12-13 13:02:24 +01:00
#include "../util/Util.h"
2018-05-14 19:21:43 +02:00
#include "../windows/Intent.h"
2017-03-11 11:24:18 +00:00
#include "../world/Climate.h"
#include "../world/ConstructionClearance.h"
2017-12-14 10:34:12 +01:00
#include "../world/Entrance.h"
2018-01-11 10:59:26 +01:00
#include "../world/Footpath.h"
2017-11-20 11:13:55 +01:00
#include "../world/LargeScenery.h"
2018-06-22 23:04:19 +02:00
#include "../world/Map.h"
2018-03-19 23:28:40 +01:00
#include "../world/Park.h"
2018-01-11 10:59:26 +01:00
#include "../world/Scenery.h"
2017-12-04 20:09:38 +01:00
#include "../world/SmallScenery.h"
2018-05-01 16:33:16 +02:00
#include "../world/Surface.h"
2017-10-13 10:06:36 +02:00
#include "Staff.h"
2014-04-03 00:22:33 +01:00
2018-08-12 12:50:40 +01:00
#include <algorithm>
2018-11-21 23:16:04 +01:00
#include <iterator>
2018-06-22 23:04:19 +02:00
#include <limits>
uint8_t gGuestChangeModifier;
uint32_t gNumGuestsInPark;
uint32_t gNumGuestsInParkLastWeek;
uint32_t gNumGuestsHeadingForPark;
2016-08-14 15:50:52 +01:00
money16 gGuestInitialCash;
2018-06-22 23:04:19 +02:00
uint8_t gGuestInitialHappiness;
uint8_t gGuestInitialHunger;
uint8_t gGuestInitialThirst;
2016-08-14 15:50:52 +01:00
uint32_t gNextGuestNumber;
2016-08-14 15:50:52 +01:00
uint8_t gPeepWarningThrottle[16];
2016-05-11 21:15:43 +01:00
2018-06-22 23:04:19 +02:00
static uint8_t _unk_F1AEF0;
2018-11-01 13:53:50 +01:00
static TileElement* _peepRideEntranceExitElement;
2016-09-04 21:33:27 +01:00
2018-06-22 23:04:19 +02:00
static void* _crowdSoundChannel = nullptr;
2016-08-05 12:00:16 +02:00
2019-02-28 19:28:58 +00:00
static void peep_128_tick_update(Peep* peep, int32_t index);
static void peep_release_balloon(Guest* peep, int16_t spawn_height);
2014-09-21 15:38:55 +01:00
2019-01-02 14:10:05 +00:00
static PeepActionSpriteType PeepSpecialSpriteToSpriteTypeMap[] = {
PeepActionSpriteType::None,
PeepActionSpriteType::HoldMat,
2021-10-17 15:31:56 +02:00
PeepActionSpriteType::StaffMower,
};
2019-01-02 14:10:05 +00:00
static PeepActionSpriteType PeepActionToSpriteTypeMap[] = {
PeepActionSpriteType::CheckTime,
PeepActionSpriteType::EatFood,
PeepActionSpriteType::ShakeHead,
PeepActionSpriteType::EmptyPockets,
PeepActionSpriteType::SittingEatFood,
PeepActionSpriteType::SittingLookAroundLeft,
PeepActionSpriteType::SittingLookAroundRight,
PeepActionSpriteType::Wow,
PeepActionSpriteType::ThrowUp,
PeepActionSpriteType::Jump,
PeepActionSpriteType::StaffSweep,
PeepActionSpriteType::Drowning,
PeepActionSpriteType::StaffAnswerCall,
PeepActionSpriteType::StaffAnswerCall2,
PeepActionSpriteType::StaffCheckboard,
PeepActionSpriteType::StaffFix,
PeepActionSpriteType::StaffFix2,
PeepActionSpriteType::StaffFixGround,
PeepActionSpriteType::StaffFix3,
PeepActionSpriteType::StaffWatering,
PeepActionSpriteType::Joy,
PeepActionSpriteType::ReadMap,
PeepActionSpriteType::Wave,
PeepActionSpriteType::StaffEmptyBin,
PeepActionSpriteType::Wave2,
PeepActionSpriteType::TakePhoto,
PeepActionSpriteType::Clap,
PeepActionSpriteType::Disgust,
PeepActionSpriteType::DrawPicture,
PeepActionSpriteType::BeingWatched,
2021-10-17 15:31:56 +02:00
PeepActionSpriteType::WithdrawMoney,
2016-07-15 22:46:27 +01:00
};
2016-07-15 22:42:29 +01:00
const bool gSpriteTypeToSlowWalkMap[] = {
2021-10-17 15:31:56 +02:00
false, false, false, false, false, false, false, false, false, false, false, true, false, false, true, true,
true, true, true, false, true, false, true, true, true, false, false, true, true, false, false, true,
true, true, true, true, true, true, false, true, false, true, true, true, true, true, true, true,
2016-07-15 22:55:19 +01:00
};
2021-08-25 17:42:09 +03:00
template<> bool EntityBase::Is<Peep>() const
{
return Type == EntityType::Guest || Type == EntityType::Staff;
}
2019-02-28 19:28:58 +00:00
uint8_t Peep::GetNextDirection() const
2018-04-04 18:50:07 +01:00
{
return NextFlags & PEEP_NEXT_FLAG_DIRECTION_MASK;
2018-04-04 18:50:07 +01:00
}
2019-02-28 19:28:58 +00:00
bool Peep::GetNextIsSloped() const
2018-04-04 18:50:07 +01:00
{
return NextFlags & PEEP_NEXT_FLAG_IS_SLOPED;
2018-04-04 18:50:07 +01:00
}
2019-02-28 19:28:58 +00:00
bool Peep::GetNextIsSurface() const
2018-04-04 18:50:07 +01:00
{
return NextFlags & PEEP_NEXT_FLAG_IS_SURFACE;
2018-04-04 18:50:07 +01:00
}
2019-02-28 19:28:58 +00:00
void Peep::SetNextFlags(uint8_t next_direction, bool is_sloped, bool is_surface)
2018-04-04 18:50:07 +01:00
{
NextFlags = next_direction & PEEP_NEXT_FLAG_DIRECTION_MASK;
NextFlags |= is_sloped ? PEEP_NEXT_FLAG_IS_SLOPED : 0;
NextFlags |= is_surface ? PEEP_NEXT_FLAG_IS_SURFACE : 0;
2018-04-04 18:50:07 +01:00
}
bool Peep::CanBePickedUp() const
{
switch (State)
{
case PeepState::One:
case PeepState::QueuingFront:
case PeepState::OnRide:
case PeepState::EnteringRide:
case PeepState::LeavingRide:
case PeepState::EnteringPark:
case PeepState::LeavingPark:
case PeepState::Fixing:
case PeepState::Buying:
case PeepState::Inspecting:
return false;
case PeepState::Falling:
case PeepState::Walking:
case PeepState::Queuing:
case PeepState::Sitting:
case PeepState::Picked:
case PeepState::Patrolling:
case PeepState::Mowing:
case PeepState::Sweeping:
case PeepState::Answering:
case PeepState::Watching:
case PeepState::EmptyingBin:
case PeepState::UsingBin:
case PeepState::Watering:
case PeepState::HeadingToInspection:
return true;
}
return false;
}
int32_t peep_get_staff_count()
2014-04-16 02:05:49 +01:00
{
return GetEntityListCount(EntityType::Staff);
2014-04-16 02:05:49 +01:00
}
2014-04-03 00:22:33 +01:00
/**
*
* rct2: 0x0068F0A9
*/
2014-04-03 00:22:33 +01:00
void peep_update_all()
{
2019-03-20 20:58:08 +01:00
if (gScreenFlags & SCREEN_FLAGS_EDITOR)
2017-06-06 23:24:18 +02:00
return;
2020-04-18 11:41:05 +01:00
2020-06-09 20:45:17 +01:00
int32_t i = 0;
2020-06-10 17:54:34 +01:00
// Warning this loop can delete peeps
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<Guest>())
2017-10-13 10:06:36 +02:00
{
2020-04-22 17:09:29 +02:00
if (static_cast<uint32_t>(i & 0x7F) != (gCurrentTicks & 0x7F))
2017-10-13 10:06:36 +02:00
{
2018-04-01 15:34:05 +02:00
peep->Update();
2017-10-13 10:06:36 +02:00
}
else
{
2018-03-21 22:02:16 +00:00
peep_128_tick_update(peep, i);
// 128 tick can delete so double check its not deleted
if (peep->Type == EntityType::Guest)
2017-10-13 10:06:36 +02:00
{
2018-04-01 15:34:05 +02:00
peep->Update();
2017-06-06 23:24:18 +02:00
}
}
2014-04-03 00:22:33 +01:00
2017-06-06 23:24:18 +02:00
i++;
}
2021-03-16 11:18:06 +00:00
for (auto staff : EntityList<Staff>())
{
if (static_cast<uint32_t>(i & 0x7F) != (gCurrentTicks & 0x7F))
{
staff->Update();
}
else
{
peep_128_tick_update(staff, i);
// 128 tick can delete so double check its not deleted
if (staff->Type == EntityType::Staff)
{
staff->Update();
}
}
i++;
}
}
2014-05-07 16:24:36 +02:00
2015-06-30 13:42:06 +01:00
/**
*
* rct2: 0x0068F41A
2018-03-21 22:02:16 +00:00
* Called every 128 ticks
2015-06-30 13:42:06 +01:00
*/
2019-02-28 19:28:58 +00:00
static void peep_128_tick_update(Peep* peep, int32_t index)
2015-06-30 13:42:06 +01:00
{
auto* guest = peep->As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
2019-02-28 19:28:58 +00:00
guest->Tick128UpdateGuest(index);
2017-06-06 23:24:18 +02:00
}
else
{
auto* staff = peep->As<Staff>();
2019-02-28 19:28:58 +00:00
if (staff != nullptr)
{
staff->Tick128UpdateStaff();
}
2017-06-06 23:24:18 +02:00
}
2015-06-30 13:42:06 +01:00
}
2015-12-29 21:08:14 +01:00
/*
* rct2: 0x68F3AE
* Set peep state to falling if path below has gone missing, return true if current path is valid, false if peep starts falling.
2015-12-29 21:08:14 +01:00
*/
2019-02-28 19:28:58 +00:00
bool Peep::CheckForPath()
2017-10-13 10:06:36 +02:00
{
PathCheckOptimisation++;
if ((PathCheckOptimisation & 0xF) != (sprite_index & 0xF))
2017-10-13 10:06:36 +02:00
{
// This condition makes the check happen less often
2018-03-21 22:02:16 +00:00
// As a side effect peeps hover for a short,
2017-06-06 23:24:18 +02:00
// random time when a path below them has been deleted
return true;
2017-06-06 23:24:18 +02:00
}
2014-11-13 21:49:47 +00:00
TileElement* tile_element = map_get_first_element_at(NextLoc);
2014-11-13 21:49:47 +00:00
uint8_t map_type = TILE_ELEMENT_TYPE_PATH;
2018-04-04 18:50:07 +01:00
if (GetNextIsSurface())
2017-10-13 10:06:36 +02:00
{
2017-10-31 12:57:40 +01:00
map_type = TILE_ELEMENT_TYPE_SURFACE;
2017-06-06 23:24:18 +02:00
}
2014-11-13 21:49:47 +00:00
2017-10-13 10:06:36 +02:00
do
{
if (tile_element == nullptr)
break;
if (tile_element->GetType() == map_type)
2017-10-13 10:06:36 +02:00
{
if (NextLoc.z == tile_element->GetBaseZ())
2017-10-13 10:06:36 +02:00
{
2018-04-01 15:34:05 +02:00
// Found a suitable path or surface
return true;
2017-06-06 23:24:18 +02:00
}
}
} while (!(tile_element++)->IsLastForTile());
2015-09-12 00:16:05 +02:00
2017-06-06 23:24:18 +02:00
// Found no suitable path
SetState(PeepState::Falling);
return false;
2014-11-13 21:49:47 +00:00
}
2019-02-28 19:28:58 +00:00
PeepActionSpriteType Peep::GetActionSpriteType()
2017-02-17 09:35:53 +01:00
{
if (IsActionInterruptable())
{ // PeepActionType::None1 or PeepActionType::None2
return PeepSpecialSpriteToSpriteTypeMap[SpecialSprite];
2017-10-13 10:06:36 +02:00
}
2021-09-15 22:22:15 +02:00
if (EnumValue(Action) < std::size(PeepActionToSpriteTypeMap))
2017-10-13 10:06:36 +02:00
{
return PeepActionToSpriteTypeMap[EnumValue(Action)];
2017-10-13 10:06:36 +02:00
}
2021-09-15 22:22:15 +02:00
openrct2_assert(
EnumValue(Action) >= std::size(PeepActionToSpriteTypeMap) && Action < PeepActionType::Idle, "Invalid peep action %u",
EnumValue(Action));
return PeepActionSpriteType::None;
2017-02-17 09:35:53 +01:00
}
2017-06-06 13:48:06 +01:00
/*
2017-10-13 10:06:36 +02:00
* rct2: 0x00693B58
*/
2019-02-28 19:28:58 +00:00
void Peep::UpdateCurrentActionSpriteType()
2017-10-13 10:06:36 +02:00
{
2020-10-06 01:56:52 -03:00
if (EnumValue(SpriteType) >= std::size(g_peep_animation_entries))
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
return;
}
2019-01-02 14:10:05 +00:00
PeepActionSpriteType newActionSpriteType = GetActionSpriteType();
if (ActionSpriteType == newActionSpriteType)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
return;
}
2014-11-13 14:02:36 +00:00
2018-03-31 10:01:43 +01:00
Invalidate();
ActionSpriteType = newActionSpriteType;
2014-11-13 14:02:36 +00:00
2020-10-07 17:02:38 -03:00
const rct_sprite_bounds* spriteBounds = &GetSpriteBounds(SpriteType, ActionSpriteType);
sprite_width = spriteBounds->sprite_width;
sprite_height_negative = spriteBounds->sprite_height_negative;
sprite_height_positive = spriteBounds->sprite_height_positive;
2018-03-31 10:01:43 +01:00
Invalidate();
2014-11-13 14:02:36 +00:00
}
2018-04-01 15:34:05 +02:00
/* rct2: 0x00693BE5 */
2019-02-28 19:28:58 +00:00
void Peep::SwitchToSpecialSprite(uint8_t special_sprite_id)
2017-10-13 10:06:36 +02:00
{
if (special_sprite_id == SpecialSprite)
2017-10-13 10:06:36 +02:00
return;
2015-01-25 13:16:39 +00:00
SpecialSprite = special_sprite_id;
2015-01-25 13:16:39 +00:00
if (IsActionInterruptable())
2017-10-13 10:06:36 +02:00
{
ActionSpriteImageOffset = 0;
2017-06-06 23:24:18 +02:00
}
2018-03-31 10:01:43 +01:00
UpdateCurrentActionSpriteType();
2015-01-25 13:16:39 +00:00
}
2019-02-28 19:28:58 +00:00
void Peep::StateReset()
2017-10-13 10:06:36 +02:00
{
SetState(PeepState::One);
2018-04-02 18:18:15 +01:00
SwitchToSpecialSprite(0);
2014-11-16 12:52:52 +00:00
}
2016-08-14 00:38:14 +02:00
/** rct2: 0x00981D7C, 0x00981D7E */
2021-10-17 15:31:56 +02:00
static constexpr const CoordsXY word_981D7C[4] = {
{ -2, 0 },
{ 0, 2 },
{ 2, 0 },
{ 0, -2 },
};
2016-08-14 00:38:14 +02:00
2019-08-15 18:32:19 +01:00
std::optional<CoordsXY> Peep::UpdateAction()
2018-03-31 10:01:43 +01:00
{
2019-08-15 18:32:19 +01:00
int16_t xy_distance;
return UpdateAction(xy_distance);
2018-03-31 10:01:43 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x6939EB
2014-11-15 20:23:21 +00:00
* Also used to move peeps to the correct position to
2018-03-31 10:01:43 +01:00
* start an action. Returns true if the correct destination
* has not yet been reached. xy_distance is how close the
* peep is to the target.
2014-11-13 14:48:58 +00:00
*/
2019-08-15 18:32:19 +01:00
std::optional<CoordsXY> Peep::UpdateAction(int16_t& xy_distance)
2017-10-13 10:06:36 +02:00
{
_unk_F1AEF0 = ActionSpriteImageOffset;
2021-05-11 09:44:41 +03:00
if (Action == PeepActionType::Idle)
2017-10-13 10:06:36 +02:00
{
2021-05-11 09:44:41 +03:00
Action = PeepActionType::Walking;
2017-06-06 23:24:18 +02:00
}
2014-10-18 15:04:48 +01:00
2021-02-20 13:49:50 +02:00
CoordsXY differenceLoc = GetLocation();
differenceLoc -= GetDestination();
2014-11-15 20:23:21 +00:00
2021-02-20 13:49:50 +02:00
int32_t x_delta = abs(differenceLoc.x);
int32_t y_delta = abs(differenceLoc.y);
2015-09-12 00:16:05 +02:00
2019-08-15 18:32:19 +01:00
xy_distance = x_delta + y_delta;
2015-09-12 00:16:05 +02:00
if (IsActionWalking())
2017-10-13 10:06:36 +02:00
{
if (xy_distance <= DestinationTolerance)
2017-10-13 10:06:36 +02:00
{
return std::nullopt;
2017-06-06 23:24:18 +02:00
}
int32_t nextDirection = 0;
2017-10-13 10:06:36 +02:00
if (x_delta < y_delta)
{
2018-04-01 15:34:05 +02:00
nextDirection = 8;
2021-02-20 13:49:50 +02:00
if (differenceLoc.y >= 0)
2017-10-13 10:06:36 +02:00
{
2018-04-01 15:34:05 +02:00
nextDirection = 24;
2017-06-06 23:24:18 +02:00
}
}
2017-10-13 10:06:36 +02:00
else
{
2018-04-01 15:34:05 +02:00
nextDirection = 16;
2021-02-20 13:49:50 +02:00
if (differenceLoc.x >= 0)
2017-10-13 10:06:36 +02:00
{
2018-04-01 15:34:05 +02:00
nextDirection = 0;
2017-06-06 23:24:18 +02:00
}
}
2018-04-01 15:34:05 +02:00
sprite_direction = nextDirection;
2019-08-15 18:32:19 +01:00
CoordsXY loc = { x, y };
loc += word_981D7C[nextDirection / 8];
WalkingFrameNum++;
2020-10-07 12:01:43 -03:00
const rct_peep_animation* peepAnimation = &GetPeepAnimation(SpriteType);
const uint8_t* imageOffset = peepAnimation[EnumValue(ActionSpriteType)].frame_offsets;
if (WalkingFrameNum >= peepAnimation[EnumValue(ActionSpriteType)].num_frames)
2017-10-13 10:06:36 +02:00
{
WalkingFrameNum = 0;
2017-06-06 23:24:18 +02:00
}
ActionSpriteImageOffset = imageOffset[WalkingFrameNum];
2019-08-15 18:32:19 +01:00
return loc;
2017-06-06 23:24:18 +02:00
}
2015-09-12 00:16:05 +02:00
2020-10-07 12:01:43 -03:00
const rct_peep_animation* peepAnimation = &GetPeepAnimation(SpriteType);
2020-06-07 20:18:42 -03:00
ActionFrame++;
2014-10-18 15:04:48 +01:00
2017-06-06 23:24:18 +02:00
// If last frame of action
if (ActionFrame >= peepAnimation[EnumValue(ActionSpriteType)].num_frames)
2017-10-13 10:06:36 +02:00
{
ActionSpriteImageOffset = 0;
2021-05-11 09:44:41 +03:00
Action = PeepActionType::Walking;
2018-04-01 15:34:05 +02:00
UpdateCurrentActionSpriteType();
2019-08-15 18:32:19 +01:00
return { { x, y } };
2017-06-06 23:24:18 +02:00
}
ActionSpriteImageOffset = peepAnimation[EnumValue(ActionSpriteType)].frame_offsets[ActionFrame];
2014-11-13 14:02:36 +00:00
auto* guest = As<Guest>();
2017-06-06 23:24:18 +02:00
// If not throwing up and not at the frame where sick appears.
if (Action != PeepActionType::ThrowUp || ActionFrame != 15 || guest == nullptr)
2017-10-13 10:06:36 +02:00
{
2019-08-15 18:32:19 +01:00
return { { x, y } };
2017-06-06 23:24:18 +02:00
}
2014-10-18 15:04:48 +01:00
2017-06-06 23:24:18 +02:00
// We are throwing up
guest->Hunger /= 2;
guest->NauseaTarget /= 2;
2014-10-18 15:04:48 +01:00
if (guest->Nausea < 30)
guest->Nausea = 0;
2017-06-06 23:24:18 +02:00
else
guest->Nausea -= 30;
2014-10-18 15:04:48 +01:00
WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_2;
2014-10-18 15:04:48 +01:00
2021-09-28 03:16:04 +03:00
const auto curLoc = GetLocation();
Litter::Create({ curLoc, sprite_direction }, (sprite_index & 1) ? Litter::Type::VomitAlt : Litter::Type::Vomit);
2014-10-18 15:04:48 +01:00
2021-10-17 15:31:56 +02:00
static constexpr OpenRCT2::Audio::SoundId coughs[4] = {
OpenRCT2::Audio::SoundId::Cough1,
OpenRCT2::Audio::SoundId::Cough2,
OpenRCT2::Audio::SoundId::Cough3,
OpenRCT2::Audio::SoundId::Cough4,
};
2019-07-22 19:02:45 +01:00
auto soundId = coughs[scenario_rand() & 3];
2021-09-28 03:16:04 +03:00
OpenRCT2::Audio::Play3D(soundId, curLoc);
2014-10-18 15:04:48 +01:00
2019-08-15 18:32:19 +01:00
return { { x, y } };
2014-10-18 15:04:48 +01:00
}
2015-03-13 14:48:46 +00:00
2014-09-20 14:46:50 +01:00
/**
2017-10-13 10:06:36 +02:00
* rct2: 0x0069A409
* Decreases rider count if on/entering a ride.
*/
2019-02-28 19:28:58 +00:00
void peep_decrement_num_riders(Peep* peep)
2017-10-13 10:06:36 +02:00
{
if (peep->State == PeepState::OnRide || peep->State == PeepState::EnteringRide)
2017-10-13 10:06:36 +02:00
{
2020-06-07 22:21:53 -03:00
auto ride = get_ride(peep->CurrentRide);
if (ride != nullptr)
{
ride->num_riders = std::max(0, ride->num_riders - 1);
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST;
}
2017-06-06 23:24:18 +02:00
}
2014-09-20 14:46:50 +01:00
}
2014-09-20 14:35:11 +01:00
/**
2015-12-11 09:38:37 -06:00
* Call after changing a peeps state to insure that all relevant windows update.
* Note also increase ride count if on/entering a ride.
2014-09-20 14:35:11 +01:00
* rct2: 0x0069A42F
*/
2019-02-28 19:28:58 +00:00
void peep_window_state_update(Peep* peep)
2016-08-21 15:21:48 +01:00
{
2018-06-22 23:04:19 +02:00
rct_window* w = window_find_by_number(WC_PEEP, peep->sprite_index);
2018-01-04 06:58:44 +01:00
if (w != nullptr)
2017-06-06 23:24:18 +02:00
window_event_invalidate_call(w);
2014-09-20 14:35:11 +01:00
if (peep->Is<Guest>())
2017-10-13 10:06:36 +02:00
{
if (peep->State == PeepState::OnRide || peep->State == PeepState::EnteringRide)
2017-10-13 10:06:36 +02:00
{
2020-06-07 22:21:53 -03:00
auto ride = get_ride(peep->CurrentRide);
if (ride != nullptr)
{
ride->num_riders++;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_MAIN | RIDE_INVALIDATE_RIDE_LIST;
}
2017-06-06 23:24:18 +02:00
}
2014-09-20 14:35:11 +01:00
2017-06-06 23:24:18 +02:00
window_invalidate_by_number(WC_PEEP, peep->sprite_index);
window_invalidate_by_class(WC_GUEST_LIST);
2017-10-13 10:06:36 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
window_invalidate_by_number(WC_PEEP, peep->sprite_index);
window_invalidate_by_class(WC_STAFF_LIST);
}
2014-09-20 14:35:11 +01:00
}
2019-02-28 19:28:58 +00:00
void Peep::Pickup()
2016-10-17 14:26:19 -06:00
{
auto* guest = As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
{
guest->RemoveFromRide();
}
2020-05-11 12:36:45 +02:00
MoveTo({ LOCATION_NULL, y, z });
SetState(PeepState::Picked);
SubState = 0;
2016-10-17 14:26:19 -06:00
}
2019-02-28 19:28:58 +00:00
void Peep::PickupAbort(int32_t old_x)
2016-10-17 14:26:19 -06:00
{
if (State != PeepState::Picked)
2017-06-06 23:24:18 +02:00
return;
2016-10-17 14:26:19 -06:00
2020-05-11 12:36:45 +02:00
MoveTo({ old_x, y, z + 8 });
2016-10-17 14:26:19 -06:00
2020-04-22 17:09:29 +02:00
if (x != LOCATION_NULL)
2017-10-13 10:06:36 +02:00
{
SetState(PeepState::Falling);
2021-05-11 09:44:41 +03:00
Action = PeepActionType::Walking;
SpecialSprite = 0;
ActionSpriteImageOffset = 0;
ActionSpriteType = PeepActionSpriteType::None;
PathCheckOptimisation = 0;
2017-06-06 23:24:18 +02:00
}
2016-10-17 14:26:19 -06:00
2017-06-06 23:24:18 +02:00
gPickupPeepImage = UINT32_MAX;
2016-10-17 14:26:19 -06:00
}
// Returns GameActions::Status::OK when a peep can be dropped at the given location. When apply is set to true the peep gets
// dropped.
GameActions::Result Peep::Place(const TileCoordsXYZ& location, bool apply)
2016-10-17 14:26:19 -06:00
{
auto* pathElement = map_get_path_element_at(location);
TileElement* tileElement = reinterpret_cast<TileElement*>(pathElement);
2021-09-24 20:05:50 +02:00
if (pathElement == nullptr)
2017-10-13 10:06:36 +02:00
{
tileElement = reinterpret_cast<TileElement*>(map_get_surface_element_at(location.ToCoordsXYZ()));
2017-06-06 23:24:18 +02:00
}
2021-09-24 20:05:50 +02:00
if (tileElement == nullptr)
2021-10-20 00:50:34 +03:00
{
return GameActions::Result(GameActions::Status::InvalidParameters, STR_ERR_CANT_PLACE_PERSON_HERE, STR_NONE);
2021-10-20 00:50:34 +03:00
}
2016-10-18 13:33:43 -06:00
2017-06-06 23:24:18 +02:00
// Set the coordinate of destination to be exactly
// in the middle of a tile.
2020-03-13 12:03:43 +01:00
CoordsXYZ destination = { location.ToCoordsXY().ToTileCentre(), tileElement->GetBaseZ() + 16 };
2016-10-17 14:26:19 -06:00
if (!map_is_location_owned(destination))
2017-10-13 10:06:36 +02:00
{
return GameActions::Result(GameActions::Status::NotOwned, STR_ERR_CANT_PLACE_PERSON_HERE, STR_LAND_NOT_OWNED_BY_PARK);
2017-06-06 23:24:18 +02:00
}
2016-11-13 20:17:49 +01:00
2020-06-17 22:35:13 +01:00
if (auto res = MapCanConstructAt({ destination, destination.z, destination.z + (1 * 8) }, { 0b1111, 0 });
res.Error != GameActions::Status::Ok)
2017-10-13 10:06:36 +02:00
{
const auto stringId = std::get<rct_string_id>(res.ErrorMessage);
2021-10-20 16:37:32 +03:00
if (stringId != STR_RAISE_OR_LOWER_LAND_FIRST && stringId != STR_FOOTPATH_IN_THE_WAY)
2017-10-13 10:06:36 +02:00
{
return GameActions::Result(
GameActions::Status::NoClearance, STR_ERR_CANT_PLACE_PERSON_HERE, stringId, res.ErrorMessageArgs.data());
2017-06-06 23:24:18 +02:00
}
}
2016-10-17 14:26:19 -06:00
2017-10-13 10:06:36 +02:00
if (apply)
{
2020-05-11 12:36:45 +02:00
MoveTo(destination);
SetState(PeepState::Falling);
2021-05-11 09:44:41 +03:00
Action = PeepActionType::Walking;
SpecialSprite = 0;
ActionSpriteImageOffset = 0;
ActionSpriteType = PeepActionSpriteType::None;
PathCheckOptimisation = 0;
EntityTweener::Get().Reset();
auto* guest = As<Guest>();
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
ActionSpriteType = PeepActionSpriteType::Invalid;
guest->HappinessTarget = std::max(guest->HappinessTarget - 10, 0);
2018-04-26 17:15:29 +02:00
UpdateCurrentActionSpriteType();
2017-06-06 23:24:18 +02:00
}
}
2016-10-17 14:26:19 -06:00
return GameActions::Result();
2016-10-17 14:26:19 -06:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x0069A535
*/
2019-02-28 19:28:58 +00:00
void peep_sprite_remove(Peep* peep)
2017-10-13 10:06:36 +02:00
{
auto* guest = peep->As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
{
guest->RemoveFromRide();
}
2018-04-03 18:53:23 +01:00
peep->Invalidate();
2015-03-11 21:13:44 +00:00
2017-06-06 23:24:18 +02:00
window_close_by_number(WC_PEEP, peep->sprite_index);
2015-03-11 21:13:44 +00:00
window_close_by_number(WC_FIRE_PROMPT, EnumValue(peep->Type));
2015-03-11 21:13:44 +00:00
auto* staff = peep->As<Staff>();
// Needed for invalidations after sprite removal
bool wasGuest = staff == nullptr;
if (wasGuest)
2017-10-13 10:06:36 +02:00
{
News::DisableNewsItems(News::ItemType::PeepOnRide, peep->sprite_index);
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
2021-09-19 09:15:10 +01:00
staff->ClearPatrolArea();
2017-06-06 23:24:18 +02:00
staff_update_greyed_patrol_areas();
2015-03-11 21:13:44 +00:00
News::DisableNewsItems(News::ItemType::Peep, staff->sprite_index);
2017-06-06 23:24:18 +02:00
}
2021-11-24 15:37:47 +02:00
EntityRemove(peep);
auto intent = Intent(wasGuest ? INTENT_ACTION_REFRESH_GUEST_LIST : INTENT_ACTION_REFRESH_STAFF_LIST);
context_broadcast_intent(&intent);
2015-03-11 21:13:44 +00:00
}
2015-12-11 09:38:37 -06:00
/**
2016-05-26 02:49:19 -05:00
* New function removes peep from park existence. Works with staff.
2014-09-20 14:06:42 +01:00
*/
2019-02-28 19:28:58 +00:00
void Peep::Remove()
2017-10-13 10:06:36 +02:00
{
auto* guest = As<Guest>();
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
if (!guest->OutsideOfPark)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
decrement_guests_in_park();
2018-01-17 01:39:03 +01:00
auto intent = Intent(INTENT_ACTION_UPDATE_GUEST_COUNT);
context_broadcast_intent(&intent);
2017-06-06 23:24:18 +02:00
}
if (State == PeepState::EnteringPark)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
decrement_guests_heading_for_park();
}
}
2018-03-27 21:04:57 +01:00
peep_sprite_remove(this);
2014-09-20 11:56:11 +01:00
}
2014-09-17 21:59:40 +01:00
/**
2014-09-20 11:56:11 +01:00
* Falling and its subset drowning
2015-12-11 09:38:37 -06:00
* rct2: 0x690028
2014-09-17 21:59:40 +01:00
*/
2019-02-28 19:28:58 +00:00
void Peep::UpdateFalling()
2017-10-13 10:06:36 +02:00
{
if (Action == PeepActionType::Drowning)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Check to see if we are ready to drown.
2019-08-15 18:32:19 +01:00
UpdateAction();
2019-08-21 12:31:05 +02:00
Invalidate();
if (Action == PeepActionType::Drowning)
2017-10-13 10:06:36 +02:00
return;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_died)
{
auto ft = Formatter();
FormatNameTo(ft);
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Blank, STR_NEWS_ITEM_GUEST_DROWNED, x | (y << 16), ft);
2017-06-06 23:24:18 +02:00
}
2018-06-20 17:11:35 +02:00
gParkRatingCasualtyPenalty = std::min(gParkRatingCasualtyPenalty + 25, 1000);
2018-03-27 21:04:57 +01:00
Remove();
2017-06-06 23:24:18 +02:00
return;
}
2014-09-20 11:56:11 +01:00
2017-06-06 23:24:18 +02:00
// If not drowning then falling. Note: peeps 'fall' after leaving a ride/enter the park.
TileElement* tile_element = map_get_first_element_at(CoordsXY{ x, y });
2018-11-01 13:53:50 +01:00
TileElement* saved_map = nullptr;
2018-06-22 23:04:19 +02:00
int32_t saved_height = 0;
2014-09-17 21:59:40 +01:00
2018-01-04 06:58:44 +01:00
if (tile_element != nullptr)
2017-10-13 10:06:36 +02:00
{
do
{
2017-06-06 23:24:18 +02:00
// If a path check if we are on it
if (tile_element->GetType() == TILE_ELEMENT_TYPE_PATH)
2017-10-13 10:06:36 +02:00
{
2018-10-03 21:45:52 +02:00
int32_t height = map_height_from_slope(
{ x, y }, tile_element->AsPath()->GetSlopeDirection(), tile_element->AsPath()->IsSloped())
2019-12-22 22:14:02 +01:00
+ tile_element->GetBaseZ();
2014-09-20 14:06:42 +01:00
2018-03-27 21:04:57 +01:00
if (height < z - 1 || height > z + 4)
2017-10-13 10:06:36 +02:00
continue;
2014-09-20 14:06:42 +01:00
2017-06-06 23:24:18 +02:00
saved_height = height;
2018-06-22 23:04:19 +02:00
saved_map = tile_element;
2017-06-06 23:24:18 +02:00
break;
} // If a surface get the height and see if we are on it
else if (tile_element->GetType() == TILE_ELEMENT_TYPE_SURFACE)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// If the surface is water check to see if we could be drowning
2018-09-14 14:54:12 +02:00
if (tile_element->AsSurface()->GetWaterHeight() > 0)
2017-07-27 17:15:56 +02:00
{
2020-01-19 16:12:48 +01:00
int32_t height = tile_element->AsSurface()->GetWaterHeight();
2014-09-20 14:06:42 +01:00
2018-03-27 21:04:57 +01:00
if (height - 4 >= z && height < z + 20)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Looks like we are drowning!
2020-05-11 12:36:45 +02:00
MoveTo({ x, y, height });
2019-02-28 19:28:58 +00:00
auto* guest = As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
{
// Drop balloon if held
peep_release_balloon(guest, height);
guest->InsertNewThought(PeepThoughtType::Drowning);
2019-02-28 19:28:58 +00:00
}
Action = PeepActionType::Drowning;
2020-06-07 20:18:42 -03:00
ActionFrame = 0;
ActionSpriteImageOffset = 0;
2018-04-01 15:34:05 +02:00
UpdateCurrentActionSpriteType();
2018-03-27 21:04:57 +01:00
peep_window_state_update(this);
2017-06-06 23:24:18 +02:00
return;
}
}
int32_t map_height = tile_element_height({ x, y });
2018-03-27 21:04:57 +01:00
if (map_height < z || map_height - 4 > z)
2017-10-13 10:06:36 +02:00
continue;
2017-06-06 23:24:18 +02:00
saved_height = map_height;
2018-06-22 23:04:19 +02:00
saved_map = tile_element;
2017-06-06 23:24:18 +02:00
} // If not a path or surface go see next element
2017-10-13 10:06:36 +02:00
else
continue;
} while (!(tile_element++)->IsLastForTile());
2017-06-06 23:24:18 +02:00
}
2014-09-20 11:56:11 +01:00
2017-06-06 23:24:18 +02:00
// This will be null if peep is falling
2018-01-04 06:58:44 +01:00
if (saved_map == nullptr)
2017-10-13 10:06:36 +02:00
{
2018-03-27 21:04:57 +01:00
if (z <= 1)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Remove peep if it has gone to the void
2018-03-27 21:04:57 +01:00
Remove();
2017-06-06 23:24:18 +02:00
return;
}
2020-05-11 12:36:45 +02:00
MoveTo({ x, y, z - 2 });
2017-06-06 23:24:18 +02:00
return;
}
2015-09-12 00:16:05 +02:00
2020-05-11 12:36:45 +02:00
MoveTo({ x, y, saved_height });
2014-09-20 11:56:11 +01:00
NextLoc = { CoordsXY{ x, y }.ToTileStart(), saved_map->GetBaseZ() };
2014-09-20 11:56:11 +01:00
if (saved_map->GetType() != TILE_ELEMENT_TYPE_PATH)
2017-10-13 10:06:36 +02:00
{
2018-04-04 18:50:07 +01:00
SetNextFlags(0, false, true);
}
else
{
SetNextFlags(saved_map->AsPath()->GetSlopeDirection(), saved_map->AsPath()->IsSloped(), false);
2017-06-06 23:24:18 +02:00
}
SetState(PeepState::One);
2014-09-17 21:59:40 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x6902A2
*/
2019-02-28 19:28:58 +00:00
void Peep::Update1()
2017-10-13 10:06:36 +02:00
{
2018-03-27 21:04:57 +01:00
if (!CheckForPath())
2017-10-13 10:06:36 +02:00
return;
2014-11-13 20:38:12 +00:00
if (Is<Guest>())
2017-10-13 10:06:36 +02:00
{
SetState(PeepState::Walking);
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
SetState(PeepState::Patrolling);
2017-06-06 23:24:18 +02:00
}
2018-03-27 21:04:57 +01:00
SetDestination(GetLocation(), 10);
2020-06-06 11:12:11 -03:00
PeepDirection = sprite_direction >> 3;
2018-03-27 21:04:57 +01:00
}
2019-02-28 19:28:58 +00:00
void Peep::SetState(PeepState new_state)
2018-03-27 21:04:57 +01:00
{
peep_decrement_num_riders(this);
State = new_state;
2018-03-27 21:04:57 +01:00
peep_window_state_update(this);
2014-11-13 20:38:12 +00:00
}
/**
2015-12-11 09:38:37 -06:00
*
* rct2: 0x690009
*/
2019-02-28 19:28:58 +00:00
void Peep::UpdatePicked()
2017-10-13 10:06:36 +02:00
{
if (gCurrentTicks & 0x1F)
return;
SubState++;
auto* guest = As<Guest>();
if (SubState == 13 && guest != nullptr)
2017-10-13 10:06:36 +02:00
{
guest->InsertNewThought(PeepThoughtType::Help);
2017-06-06 23:24:18 +02:00
}
}
/* From peep_update */
static void peep_update_thoughts(Guest* peep)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Thoughts must always have a gap of at least
// 220 ticks in age between them. In order to
// allow this when a thought is new it enters
// a holding zone. Before it becomes fresh.
2018-06-22 23:04:19 +02:00
int32_t add_fresh = 1;
int32_t fresh_thought = -1;
for (int32_t i = 0; i < PEEP_MAX_THOUGHTS; i++)
2017-10-13 10:06:36 +02:00
{
if (peep->Thoughts[i].type == PeepThoughtType::None)
2017-06-06 23:24:18 +02:00
break;
2020-06-06 10:03:58 -03:00
if (peep->Thoughts[i].freshness == 1)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
add_fresh = 0;
// If thought is fresh we wait 220 ticks
// before allowing a new thought to become fresh.
2020-06-06 10:03:58 -03:00
if (++peep->Thoughts[i].fresh_timeout >= 220)
2017-10-13 10:06:36 +02:00
{
2020-06-06 10:03:58 -03:00
peep->Thoughts[i].fresh_timeout = 0;
2017-06-06 23:24:18 +02:00
// Thought is no longer fresh
2020-06-06 10:03:58 -03:00
peep->Thoughts[i].freshness++;
2017-06-06 23:24:18 +02:00
add_fresh = 1;
}
}
2020-06-06 10:03:58 -03:00
else if (peep->Thoughts[i].freshness > 1)
2017-10-13 10:06:36 +02:00
{
2020-06-06 10:03:58 -03:00
if (++peep->Thoughts[i].fresh_timeout == 0)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// When thought is older than ~6900 ticks remove it
2020-06-06 10:03:58 -03:00
if (++peep->Thoughts[i].freshness >= 28)
2017-10-13 10:06:36 +02:00
{
peep->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_THOUGHTS;
2017-06-06 23:24:18 +02:00
// Clear top thought, push others up
2017-10-13 10:06:36 +02:00
if (i < PEEP_MAX_THOUGHTS - 2)
{
2021-08-27 23:17:47 +03:00
memmove(&peep->Thoughts[i], &peep->Thoughts[i + 1], sizeof(PeepThought) * (PEEP_MAX_THOUGHTS - i - 1));
2017-06-06 23:24:18 +02:00
}
peep->Thoughts[PEEP_MAX_THOUGHTS - 1].type = PeepThoughtType::None;
2017-06-06 23:24:18 +02:00
}
}
}
2017-10-13 10:06:36 +02:00
else
{
2017-06-06 23:24:18 +02:00
fresh_thought = i;
}
}
// If there are no fresh thoughts
// a previously new thought can become
// fresh.
2017-10-13 10:06:36 +02:00
if (add_fresh && fresh_thought != -1)
{
2020-06-06 10:03:58 -03:00
peep->Thoughts[fresh_thought].freshness = 1;
peep->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_THOUGHTS;
2017-06-06 23:24:18 +02:00
}
}
2014-05-30 23:27:11 +01:00
/**
*
* rct2: 0x0068FC1E
*/
2019-02-28 19:28:58 +00:00
void Peep::Update()
2014-05-30 23:27:11 +01:00
{
auto* guest = As<Guest>();
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
if (guest->PreviousRide != RIDE_ID_NULL)
if (++guest->PreviousRideTimeOut >= 720)
guest->PreviousRide = RIDE_ID_NULL;
2014-05-30 23:27:11 +01:00
peep_update_thoughts(guest);
2017-06-06 23:24:18 +02:00
}
2014-05-30 23:27:11 +01:00
2017-06-06 23:24:18 +02:00
// Walking speed logic
2020-06-08 23:34:35 -03:00
uint32_t stepsToTake = Energy;
if (stepsToTake < 95 && State == PeepState::Queuing)
2017-06-06 23:24:18 +02:00
stepsToTake = 95;
if ((PeepFlags & PEEP_FLAGS_SLOW_WALK) && State != PeepState::Queuing)
2017-06-06 23:24:18 +02:00
stepsToTake /= 2;
if (IsActionWalking() && GetNextIsSloped())
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
stepsToTake /= 2;
if (State == PeepState::Queuing)
2017-06-06 23:24:18 +02:00
stepsToTake += stepsToTake / 2;
}
2014-05-30 23:27:11 +01:00
2020-06-07 20:00:07 -03:00
uint32_t carryCheck = StepProgress + stepsToTake;
StepProgress = carryCheck;
2017-10-13 10:06:36 +02:00
if (carryCheck <= 255)
{
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
{
guest->UpdateEasterEggInteractions();
2019-02-28 19:28:58 +00:00
}
2017-10-13 10:06:36 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
// loc_68FD2F
switch (State)
2017-10-13 10:06:36 +02:00
{
case PeepState::Falling:
2018-06-22 23:04:19 +02:00
UpdateFalling();
break;
case PeepState::One:
2018-06-22 23:04:19 +02:00
Update1();
break;
case PeepState::OnRide:
2018-06-22 23:04:19 +02:00
// No action
break;
case PeepState::Picked:
2018-06-22 23:04:19 +02:00
UpdatePicked();
break;
default:
2019-02-28 19:28:58 +00:00
{
if (guest != nullptr)
{
guest->UpdateGuest();
}
else
{
auto* staff = As<Staff>();
2019-02-28 19:28:58 +00:00
if (staff != nullptr)
{
staff->UpdateStaff(stepsToTake);
}
else
{
assert(false);
}
}
2018-06-22 23:04:19 +02:00
break;
2019-02-28 19:28:58 +00:00
}
2017-06-06 23:24:18 +02:00
}
}
2014-05-30 23:27:11 +01:00
}
2014-05-07 16:24:36 +02:00
/**
*
2015-12-11 09:38:37 -06:00
* rct2: 0x0069BF41
*/
2014-05-07 16:24:36 +02:00
void peep_problem_warnings_update()
{
2018-06-22 23:04:19 +02:00
Ride* ride;
uint32_t hunger_counter = 0, lost_counter = 0, noexit_counter = 0, thirst_counter = 0, litter_counter = 0,
2020-04-25 15:34:43 +02:00
disgust_counter = 0, toilet_counter = 0, vandalism_counter = 0;
2018-06-22 23:04:19 +02:00
uint8_t* warning_throttle = gPeepWarningThrottle;
2014-05-07 16:24:36 +02:00
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<Guest>())
2017-10-13 10:06:36 +02:00
{
if (peep->OutsideOfPark || peep->Thoughts[0].freshness > 5)
2017-06-06 23:24:18 +02:00
continue;
2014-05-07 16:24:36 +02:00
2020-06-06 10:03:58 -03:00
switch (peep->Thoughts[0].type)
2017-10-13 10:06:36 +02:00
{
case PeepThoughtType::Lost: // 0x10
2018-06-22 23:04:19 +02:00
lost_counter++;
2017-06-06 23:24:18 +02:00
break;
2014-05-07 16:24:36 +02:00
case PeepThoughtType::Hungry: // 0x14
2020-06-08 14:06:00 +02:00
if (peep->GuestHeadingToRideId == RIDE_ID_NULL)
2018-06-22 23:04:19 +02:00
{
hunger_counter++;
break;
}
ride = get_ride(peep->GuestHeadingToRideId);
2021-02-24 13:53:01 +01:00
if (ride != nullptr && !ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_FLAT_RIDE))
2018-06-22 23:04:19 +02:00
hunger_counter++;
2017-06-06 23:24:18 +02:00
break;
2014-05-07 16:24:36 +02:00
case PeepThoughtType::Thirsty:
2020-06-08 14:06:00 +02:00
if (peep->GuestHeadingToRideId == RIDE_ID_NULL)
2018-06-22 23:04:19 +02:00
{
thirst_counter++;
break;
}
ride = get_ride(peep->GuestHeadingToRideId);
2021-02-24 13:53:01 +01:00
if (ride != nullptr && !ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_SELLS_DRINKS))
2018-06-22 23:04:19 +02:00
thirst_counter++;
2017-06-06 23:24:18 +02:00
break;
2014-05-07 16:24:36 +02:00
case PeepThoughtType::Toilet:
2020-06-08 14:06:00 +02:00
if (peep->GuestHeadingToRideId == RIDE_ID_NULL)
2018-06-22 23:04:19 +02:00
{
2020-04-25 15:34:43 +02:00
toilet_counter++;
2018-06-22 23:04:19 +02:00
break;
}
ride = get_ride(peep->GuestHeadingToRideId);
2021-02-24 13:53:01 +01:00
if (ride != nullptr && !ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IS_TOILET))
2020-04-25 15:34:43 +02:00
toilet_counter++;
2018-06-22 23:04:19 +02:00
break;
case PeepThoughtType::BadLitter: // 0x1a
2018-06-22 23:04:19 +02:00
litter_counter++;
break;
case PeepThoughtType::CantFindExit: // 0x1b
2018-06-22 23:04:19 +02:00
noexit_counter++;
break;
case PeepThoughtType::PathDisgusting: // 0x1f
2018-06-22 23:04:19 +02:00
disgust_counter++;
break;
case PeepThoughtType::Vandalism: // 0x21
2018-06-22 23:04:19 +02:00
vandalism_counter++;
break;
default:
break;
2017-06-06 23:24:18 +02:00
}
}
// could maybe be packed into a loop, would lose a lot of clarity though
if (warning_throttle[0])
--warning_throttle[0];
else if (hunger_counter >= PEEP_HUNGER_WARNING_THRESHOLD && hunger_counter >= gNumGuestsInPark / 16)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[0] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_ARE_HUNGRY, 20, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[1])
--warning_throttle[1];
else if (thirst_counter >= PEEP_THIRST_WARNING_THRESHOLD && thirst_counter >= gNumGuestsInPark / 16)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[1] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_ARE_THIRSTY, 21, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[2])
--warning_throttle[2];
2020-04-25 15:34:43 +02:00
else if (toilet_counter >= PEEP_TOILET_WARNING_THRESHOLD && toilet_counter >= gNumGuestsInPark / 16)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[2] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_CANT_FIND_TOILET, 22, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[3])
--warning_throttle[3];
else if (litter_counter >= PEEP_LITTER_WARNING_THRESHOLD && litter_counter >= gNumGuestsInPark / 32)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[3] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISLIKE_LITTER, 26, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[4])
--warning_throttle[4];
else if (disgust_counter >= PEEP_DISGUST_WARNING_THRESHOLD && disgust_counter >= gNumGuestsInPark / 32)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[4] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISGUSTED_BY_PATHS, 31, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[5])
--warning_throttle[5];
else if (vandalism_counter >= PEEP_VANDALISM_WARNING_THRESHOLD && vandalism_counter >= gNumGuestsInPark / 32)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
warning_throttle[5] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_DISLIKE_VANDALISM, 33, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
2017-06-06 23:24:18 +02:00
if (warning_throttle[6])
--warning_throttle[6];
2017-10-13 10:06:36 +02:00
else if (noexit_counter >= PEEP_NOEXIT_WARNING_THRESHOLD)
{
2017-06-06 23:24:18 +02:00
warning_throttle[6] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, 27, {});
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
}
else if (lost_counter >= PEEP_LOST_WARNING_THRESHOLD)
{
2017-06-06 23:24:18 +02:00
warning_throttle[6] = 4;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_warnings)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(News::ItemType::Peeps, STR_PEEPS_GETTING_LOST_OR_STUCK, 16, {});
2017-06-06 23:24:18 +02:00
}
}
2014-05-07 16:24:36 +02:00
}
2014-05-25 01:08:08 +01:00
2017-03-28 19:58:15 +01:00
void peep_stop_crowd_noise()
{
2018-01-04 06:58:44 +01:00
if (_crowdSoundChannel != nullptr)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
Mixer_Stop_Channel(_crowdSoundChannel);
2018-01-04 06:58:44 +01:00
_crowdSoundChannel = nullptr;
2017-06-06 23:24:18 +02:00
}
2017-03-28 19:58:15 +01:00
}
2014-05-25 01:08:08 +01:00
/**
*
* rct2: 0x006BD18A
*/
void peep_update_crowd_noise()
{
2020-10-07 00:34:42 +03:00
if (OpenRCT2::Audio::gGameSoundsOff)
2017-06-06 23:24:18 +02:00
return;
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
if (!gConfigSound.sound_enabled)
return;
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
if (gScreenFlags & SCREEN_FLAGS_SCENARIO_EDITOR)
return;
2014-05-25 01:08:08 +01:00
2020-06-10 17:54:34 +01:00
auto viewport = g_music_tracking_viewport;
2018-01-04 06:58:44 +01:00
if (viewport == nullptr)
2017-06-06 23:24:18 +02:00
return;
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
// Count the number of peeps visible
2020-06-10 17:54:34 +01:00
auto visiblePeeps = 0;
2014-05-25 01:08:08 +01:00
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<Guest>())
2017-10-13 10:06:36 +02:00
{
if (peep->x == LOCATION_NULL)
2017-06-06 23:24:18 +02:00
continue;
if (viewport->viewPos.x > peep->SpriteRect.GetRight())
2017-06-06 23:24:18 +02:00
continue;
if (viewport->viewPos.x + viewport->view_width < peep->SpriteRect.GetLeft())
2017-06-06 23:24:18 +02:00
continue;
if (viewport->viewPos.y > peep->SpriteRect.GetBottom())
2017-06-06 23:24:18 +02:00
continue;
if (viewport->viewPos.y + viewport->view_height < peep->SpriteRect.GetTop())
2017-06-06 23:24:18 +02:00
continue;
2014-05-25 01:08:08 +01:00
visiblePeeps += peep->State == PeepState::Queuing ? 1 : 2;
2017-06-06 23:24:18 +02:00
}
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
// This function doesn't account for the fact that the screen might be so big that 100 peeps could potentially be very
// spread out and therefore not produce any crowd noise. Perhaps a more sophisticated solution would check how many peeps
// were in close proximity to each other.
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
// Allows queuing peeps to make half as much noise, and at least 6 peeps must be visible for any crowd noise
visiblePeeps = (visiblePeeps / 2) - 6;
2017-10-13 10:06:36 +02:00
if (visiblePeeps < 0)
{
2017-06-06 23:24:18 +02:00
// Mute crowd noise
2018-01-04 06:58:44 +01:00
if (_crowdSoundChannel != nullptr)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
Mixer_Stop_Channel(_crowdSoundChannel);
2018-01-04 06:58:44 +01:00
_crowdSoundChannel = nullptr;
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
}
else
{
int32_t volume;
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
// Formula to scale peeps to dB where peeps [0, 120] scales approximately logarithmically to [-3314, -150] dB/100
// 207360000 maybe related to DSBVOLUME_MIN which is -10,000 (dB/100)
2018-06-20 17:11:35 +02:00
volume = 120 - std::min(visiblePeeps, 120);
2017-06-06 23:24:18 +02:00
volume = volume * volume * volume * volume;
volume = (((207360000 - volume) / viewport->zoom) - 207360000) / 65536 - 150;
2014-05-25 01:08:08 +01:00
2017-06-06 23:24:18 +02:00
// Load and play crowd noise if needed and set volume
2018-01-04 06:58:44 +01:00
if (_crowdSoundChannel == nullptr)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
_crowdSoundChannel = Mixer_Play_Music(PATH_ID_CSS2, MIXER_LOOP_INFINITE, false);
2018-01-04 06:58:44 +01:00
if (_crowdSoundChannel != nullptr)
2017-10-13 10:06:36 +02:00
{
Mixer_Channel_SetGroup(_crowdSoundChannel, OpenRCT2::Audio::MixerGroup::Sound);
2017-06-06 23:24:18 +02:00
}
}
2018-01-04 06:58:44 +01:00
if (_crowdSoundChannel != nullptr)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
Mixer_Channel_Volume(_crowdSoundChannel, DStoMixerVolume(volume));
}
}
2014-05-25 13:59:31 +01:00
}
2014-05-25 19:47:11 +01:00
/**
*
* rct2: 0x0069BE9B
*/
void peep_applause()
{
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<Guest>())
2017-10-13 10:06:36 +02:00
{
if (peep->OutsideOfPark)
2017-06-06 23:24:18 +02:00
continue;
2014-05-25 19:47:11 +01:00
2017-06-06 23:24:18 +02:00
// Release balloon
peep_release_balloon(peep, peep->z + 9);
2014-05-25 19:47:11 +01:00
2017-06-06 23:24:18 +02:00
// Clap
if ((peep->State == PeepState::Walking || peep->State == PeepState::Queuing) && peep->IsActionInterruptable())
2017-10-13 10:06:36 +02:00
{
peep->Action = PeepActionType::Clap;
2020-06-07 20:18:42 -03:00
peep->ActionFrame = 0;
peep->ActionSpriteImageOffset = 0;
2018-04-01 20:35:41 +01:00
peep->UpdateCurrentActionSpriteType();
2017-06-06 23:24:18 +02:00
}
}
2014-05-25 19:47:11 +01:00
2017-06-06 23:24:18 +02:00
// Play applause noise
2020-10-07 00:34:42 +03:00
OpenRCT2::Audio::Play(OpenRCT2::Audio::SoundId::Applause, 0, context_get_width() / 2);
2014-05-25 19:47:11 +01:00
}
2015-03-08 18:04:39 +01:00
/**
2017-10-13 10:06:36 +02:00
*
* rct2: 0x0069C35E
*/
2015-03-08 18:04:39 +01:00
void peep_update_days_in_queue()
{
2021-03-16 11:18:06 +00:00
for (auto peep : EntityList<Guest>())
2017-10-13 10:06:36 +02:00
{
if (!peep->OutsideOfPark && peep->State == PeepState::Queuing)
2017-10-13 10:06:36 +02:00
{
2020-05-13 23:19:41 -03:00
if (peep->DaysInQueue < 255)
2017-10-13 10:06:36 +02:00
{
2020-05-13 23:19:41 -03:00
peep->DaysInQueue += 1;
2017-06-06 23:24:18 +02:00
}
}
}
2015-03-08 18:04:39 +01:00
}
void Peep::FormatActionTo(Formatter& ft) const
{
switch (State)
2017-10-13 10:06:36 +02:00
{
case PeepState::Falling:
ft.Add<rct_string_id>(Action == PeepActionType::Drowning ? STR_DROWNING : STR_WALKING);
2018-06-22 23:04:19 +02:00
break;
case PeepState::One:
ft.Add<rct_string_id>(STR_WALKING);
2018-06-22 23:04:19 +02:00
break;
case PeepState::OnRide:
case PeepState::LeavingRide:
case PeepState::EnteringRide:
2019-07-21 00:23:10 +01:00
{
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
2018-06-22 23:04:19 +02:00
{
2021-02-24 13:53:01 +01:00
ft.Add<rct_string_id>(
ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IN_RIDE) ? STR_IN_RIDE : STR_ON_RIDE);
ride->FormatNameTo(ft);
2018-06-22 23:04:19 +02:00
}
else
{
ft.Add<rct_string_id>(STR_ON_RIDE).Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
2019-07-21 12:09:23 +01:00
break;
2019-07-21 00:23:10 +01:00
}
case PeepState::Buying:
2019-07-21 00:23:10 +01:00
{
ft.Add<rct_string_id>(STR_AT_RIDE);
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
else
{
ft.Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
break;
}
case PeepState::Walking:
case PeepState::UsingBin:
{
auto* guest = As<Guest>();
if (guest != nullptr)
2019-07-21 00:23:10 +01:00
{
if (guest->GuestHeadingToRideId != RIDE_ID_NULL)
2019-07-21 00:23:10 +01:00
{
auto ride = get_ride(guest->GuestHeadingToRideId);
if (ride != nullptr)
{
ft.Add<rct_string_id>(STR_HEADING_FOR);
ride->FormatNameTo(ft);
}
}
else
{
ft.Add<rct_string_id>((PeepFlags & PEEP_FLAGS_LEAVING_PARK) ? STR_LEAVING_PARK : STR_WALKING);
2019-07-21 00:23:10 +01:00
}
}
2018-06-22 23:04:19 +02:00
break;
}
case PeepState::QueuingFront:
case PeepState::Queuing:
2019-07-21 00:23:10 +01:00
{
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ft.Add<rct_string_id>(STR_QUEUING_FOR);
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
break;
2019-07-21 00:23:10 +01:00
}
case PeepState::Sitting:
ft.Add<rct_string_id>(STR_SITTING);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Watching:
2020-06-07 22:21:53 -03:00
if (CurrentRide != RIDE_ID_NULL)
2018-06-22 23:04:19 +02:00
{
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ft.Add<rct_string_id>((StandingFlags & 0x1) ? STR_WATCHING_CONSTRUCTION_OF : STR_WATCHING_RIDE);
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
}
else
{
ft.Add<rct_string_id>((StandingFlags & 0x1) ? STR_WATCHING_NEW_RIDE_BEING_CONSTRUCTED : STR_LOOKING_AT_SCENERY);
2018-06-22 23:04:19 +02:00
}
break;
case PeepState::Picked:
ft.Add<rct_string_id>(STR_SELECT_LOCATION);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Patrolling:
case PeepState::EnteringPark:
case PeepState::LeavingPark:
ft.Add<rct_string_id>(STR_WALKING);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Mowing:
ft.Add<rct_string_id>(STR_MOWING_GRASS);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Sweeping:
ft.Add<rct_string_id>(STR_SWEEPING_FOOTPATH);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Watering:
ft.Add<rct_string_id>(STR_WATERING_GARDENS);
2018-06-22 23:04:19 +02:00
break;
case PeepState::EmptyingBin:
ft.Add<rct_string_id>(STR_EMPTYING_LITTER_BIN);
2018-06-22 23:04:19 +02:00
break;
case PeepState::Answering:
if (SubState == 0)
2018-06-22 23:04:19 +02:00
{
ft.Add<rct_string_id>(STR_WALKING);
2018-06-22 23:04:19 +02:00
}
else if (SubState == 1)
2018-06-22 23:04:19 +02:00
{
ft.Add<rct_string_id>(STR_ANSWERING_RADIO_CALL);
2018-06-22 23:04:19 +02:00
}
else
{
ft.Add<rct_string_id>(STR_RESPONDING_TO_RIDE_BREAKDOWN_CALL);
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
else
{
ft.Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
}
break;
case PeepState::Fixing:
2019-07-21 00:23:10 +01:00
{
ft.Add<rct_string_id>(STR_FIXING_RIDE);
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
else
{
ft.Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
break;
2019-07-21 00:23:10 +01:00
}
case PeepState::HeadingToInspection:
2019-07-21 00:23:10 +01:00
{
ft.Add<rct_string_id>(STR_HEADING_TO_RIDE_FOR_INSPECTION);
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
else
{
ft.Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
break;
2019-07-21 00:23:10 +01:00
}
case PeepState::Inspecting:
2019-07-21 00:23:10 +01:00
{
ft.Add<rct_string_id>(STR_INSPECTING_RIDE);
2020-06-07 22:21:53 -03:00
auto ride = get_ride(CurrentRide);
2019-07-21 00:23:10 +01:00
if (ride != nullptr)
{
ride->FormatNameTo(ft);
2019-07-21 00:23:10 +01:00
}
else
{
ft.Add<rct_string_id>(STR_NONE);
2019-07-21 00:23:10 +01:00
}
2018-06-22 23:04:19 +02:00
break;
2019-07-21 00:23:10 +01:00
}
2017-06-06 23:24:18 +02:00
}
2014-08-23 10:39:15 +01:00
}
static constexpr const rct_string_id _staffNames[] = {
STR_HANDYMAN_X,
STR_MECHANIC_X,
STR_SECURITY_GUARD_X,
STR_ENTERTAINER_X,
};
void Peep::FormatNameTo(Formatter& ft) const
{
if (Name == nullptr)
2019-07-21 20:44:19 +01:00
{
auto* staff = As<Staff>();
if (staff != nullptr)
2019-07-21 20:44:19 +01:00
{
auto staffNameIndex = static_cast<uint8_t>(staff->AssignedStaffType);
if (staffNameIndex >= std::size(_staffNames))
2019-07-21 20:44:19 +01:00
{
staffNameIndex = 0;
}
ft.Add<rct_string_id>(_staffNames[staffNameIndex]);
2020-06-06 10:31:19 -03:00
ft.Add<uint32_t>(Id);
2019-07-21 20:44:19 +01:00
}
else if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)
{
2020-06-06 10:31:19 -03:00
auto realNameStringId = get_real_name_string_id_from_id(Id);
ft.Add<rct_string_id>(realNameStringId);
2019-07-21 20:44:19 +01:00
}
else
{
ft.Add<rct_string_id>(STR_GUEST_X).Add<uint32_t>(Id);
2019-07-21 20:44:19 +01:00
}
}
else
{
ft.Add<rct_string_id>(STR_STRING).Add<const char*>(Name);
2019-07-21 20:44:19 +01:00
}
}
std::string Peep::GetName() const
{
Formatter ft;
FormatNameTo(ft);
return format_string(STR_STRINGID, ft.Data());
2019-07-21 20:44:19 +01:00
}
2021-01-07 01:22:22 +09:00
bool Peep::SetName(std::string_view value)
2019-07-21 20:44:19 +01:00
{
if (value.empty())
{
std::free(Name);
Name = nullptr;
2019-07-21 20:44:19 +01:00
return true;
}
2021-09-15 22:22:15 +02:00
auto newNameMemory = static_cast<char*>(std::malloc(value.size() + 1));
if (newNameMemory != nullptr)
2019-07-21 20:44:19 +01:00
{
2021-09-15 22:22:15 +02:00
std::memcpy(newNameMemory, value.data(), value.size());
newNameMemory[value.size()] = '\0';
std::free(Name);
Name = newNameMemory;
return true;
2019-07-21 20:44:19 +01:00
}
return false;
}
bool Peep::IsActionWalking() const
{
return Action == PeepActionType::Walking;
}
bool Peep::IsActionIdle() const
{
return Action == PeepActionType::Idle;
}
bool Peep::IsActionInterruptable() const
{
return IsActionIdle() || IsActionWalking();
}
2019-02-28 19:28:58 +00:00
void peep_set_map_tooltip(Peep* peep)
{
auto ft = Formatter();
auto* guest = peep->As<Guest>();
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
2020-05-31 17:45:52 -03:00
ft.Add<rct_string_id>((peep->PeepFlags & PEEP_FLAGS_TRACKING) ? STR_TRACKED_GUEST_MAP_TIP : STR_GUEST_MAP_TIP);
ft.Add<uint32_t>(get_peep_face_sprite_small(guest));
guest->FormatNameTo(ft);
guest->FormatActionTo(ft);
2017-10-13 10:06:36 +02:00
}
else
{
ft.Add<rct_string_id>(STR_STAFF_MAP_TIP);
peep->FormatNameTo(ft);
peep->FormatActionTo(ft);
2017-06-06 23:24:18 +02:00
}
auto intent = Intent(INTENT_ACTION_SET_MAP_TOOLTIP);
intent.putExtra(INTENT_EXTRA_FORMATTER, &ft);
context_broadcast_intent(&intent);
2015-01-14 12:56:49 +00:00
}
2015-04-10 00:21:51 -07:00
2017-06-06 13:55:23 +01:00
/**
2017-10-13 10:06:36 +02:00
* rct2: 0x00693BAB
*/
2019-02-28 19:28:58 +00:00
void Peep::SwitchNextActionSpriteType()
2017-10-13 10:06:36 +02:00
{
// TBD: Add nextActionSpriteType as function parameter and make peep->NextActionSpriteType obsolete?
if (NextActionSpriteType != ActionSpriteType)
2017-10-13 10:06:36 +02:00
{
2018-04-03 18:53:23 +01:00
Invalidate();
ActionSpriteType = NextActionSpriteType;
2020-10-07 17:02:38 -03:00
const rct_sprite_bounds* spriteBounds = &GetSpriteBounds(SpriteType, NextActionSpriteType);
sprite_width = spriteBounds->sprite_width;
sprite_height_negative = spriteBounds->sprite_height_negative;
sprite_height_positive = spriteBounds->sprite_height_positive;
2018-04-03 18:53:23 +01:00
Invalidate();
2017-06-06 23:24:18 +02:00
}
2015-04-10 00:21:51 -07:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x00693EF2
*/
2019-02-28 19:28:58 +00:00
static void peep_return_to_centre_of_tile(Peep* peep)
2017-10-13 10:06:36 +02:00
{
2020-06-06 11:12:11 -03:00
peep->PeepDirection = direction_reverse(peep->PeepDirection);
auto destination = peep->GetLocation().ToTileCentre();
peep->SetDestination(destination, 5);
2015-07-21 19:17:25 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x00693f2C
*/
static bool peep_interact_with_entrance(Peep* peep, const CoordsXYE& coords, uint8_t& pathing_result)
2017-10-13 10:06:36 +02:00
{
auto tile_element = coords.element;
2018-09-26 12:13:44 +02:00
uint8_t entranceType = tile_element->AsEntrance()->GetEntranceType();
auto rideIndex = tile_element->AsEntrance()->GetRideIndex();
2015-07-21 19:17:25 +01:00
if ((entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE) || (entranceType == ENTRANCE_TYPE_RIDE_EXIT))
{
// If an entrance or exit that doesn't belong to the ride we are queuing for ignore the entrance/exit
// This can happen when paths clip through entrance/exits
if (peep->State == PeepState::Queuing && peep->CurrentRide != rideIndex)
{
return false;
}
}
2017-06-06 23:24:18 +02:00
// Store some details to determine when to override the default
// behaviour (defined below) for when staff attempt to enter a ride
// to fix/inspect it.
2017-10-13 10:06:36 +02:00
if (entranceType == ENTRANCE_TYPE_RIDE_EXIT)
{
2018-03-27 21:04:57 +01:00
pathing_result |= PATHING_RIDE_EXIT;
2017-10-31 12:57:40 +01:00
_peepRideEntranceExitElement = tile_element;
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
2018-03-27 21:04:57 +01:00
pathing_result |= PATHING_RIDE_ENTRANCE;
2017-10-31 12:57:40 +01:00
_peepRideEntranceExitElement = tile_element;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-10-13 10:06:36 +02:00
if (entranceType == ENTRANCE_TYPE_RIDE_EXIT)
{
2017-06-06 23:24:18 +02:00
// Default guest/staff behaviour attempting to enter a
// ride exit is to turn around.
2020-10-27 22:24:39 +01:00
peep->InteractionRideIndex = RIDE_ID_NULL;
peep_return_to_centre_of_tile(peep);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-10-13 10:06:36 +02:00
if (entranceType == ENTRANCE_TYPE_RIDE_ENTRANCE)
{
2019-08-10 15:21:49 +01:00
auto ride = get_ride(rideIndex);
if (ride == nullptr)
return false;
2019-08-10 15:21:49 +01:00
auto* guest = peep->As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest == nullptr)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Default staff behaviour attempting to enter a
// ride entrance is to turn around.
2020-10-27 22:24:39 +01:00
peep->InteractionRideIndex = RIDE_ID_NULL;
peep_return_to_centre_of_tile(peep);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
if (guest->State == PeepState::Queuing)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Guest is in the ride queue.
guest->RideSubState = PeepRideSubState::AtQueueFront;
guest->ActionSpriteImageOffset = _unk_F1AEF0;
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
// Guest is on a normal path, i.e. ride has no queue.
if (guest->InteractionRideIndex == rideIndex)
{
2017-06-06 23:24:18 +02:00
// Peep is retrying the ride entrance without leaving
// the path tile and without trying any other ride
// attached to this path tile. i.e. stick with the
// peeps previous decision not to go on the ride.
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
guest->TimeLost = 0;
auto stationNum = tile_element->AsEntrance()->GetStationIndex();
2017-06-06 23:24:18 +02:00
// Guest walks up to the ride for the first time since entering
// the path tile or since considering another ride attached to
// the path tile.
2019-02-28 19:28:58 +00:00
if (!guest->ShouldGoOnRide(ride, stationNum, false, false))
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Peep remembers that this is the last ride they
// considered while on this path tile.
guest->InteractionRideIndex = rideIndex;
peep_return_to_centre_of_tile(guest);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
// Guest has decided to go on the ride.
guest->ActionSpriteImageOffset = _unk_F1AEF0;
guest->InteractionRideIndex = rideIndex;
2015-07-21 19:17:25 +01:00
2019-01-01 01:14:19 +00:00
uint16_t previous_last = ride->stations[stationNum].LastPeepInQueue;
ride->stations[stationNum].LastPeepInQueue = guest->sprite_index;
guest->GuestNextInQueue = previous_last;
2019-01-01 01:14:19 +00:00
ride->stations[stationNum].QueueLength++;
2015-09-12 00:16:05 +02:00
guest->CurrentRide = rideIndex;
guest->CurrentRideStation = stationNum;
guest->DaysInQueue = 0;
guest->SetState(PeepState::Queuing);
guest->RideSubState = PeepRideSubState::AtQueueFront;
guest->TimeInQueue = 0;
if (guest->PeepFlags & PEEP_FLAGS_TRACKING)
2017-10-13 10:06:36 +02:00
{
auto ft = Formatter();
guest->FormatNameTo(ft);
ride->FormatNameTo(ft);
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_queuing_for_ride)
{
2020-08-27 14:35:37 +02:00
News::AddItemToQueue(
News::ItemType::PeepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->sprite_index, ft);
2017-06-06 23:24:18 +02:00
}
}
}
2017-10-13 10:06:36 +02:00
else
{
2017-06-06 23:24:18 +02:00
// PARK_ENTRANCE
auto* guest = peep->As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest == nullptr)
{
2017-06-06 23:24:18 +02:00
// Staff cannot leave the park, so go back.
peep_return_to_centre_of_tile(peep);
return true;
}
2015-07-21 19:17:25 +01:00
2017-07-01 00:11:28 +02:00
// If not the centre of the entrance arch
if (tile_element->AsEntrance()->GetSequenceIndex() != 0)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
2018-09-14 11:14:19 +02:00
uint8_t entranceDirection = tile_element->GetDirection();
if (entranceDirection != guest->PeepDirection)
2017-10-13 10:06:36 +02:00
{
if (direction_reverse(entranceDirection) != guest->PeepDirection)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2017-06-06 23:24:18 +02:00
// Peep is leaving the park.
if (guest->State != PeepState::Walking)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
if (!(guest->PeepFlags & PEEP_FLAGS_LEAVING_PARK))
2017-10-13 10:06:36 +02:00
{
2017-07-01 00:11:28 +02:00
// If the park is open and leaving flag isn't set return to centre
2017-06-06 23:24:18 +02:00
if (gParkFlags & PARK_FLAGS_PARK_OPEN)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
auto destination = guest->GetDestination() + CoordsDirectionDelta[guest->PeepDirection];
guest->SetDestination(destination, 9);
guest->MoveTo({ coords, guest->z });
guest->SetState(PeepState::LeavingPark);
2015-07-21 19:17:25 +01:00
guest->Var37 = 0;
if (guest->PeepFlags & PEEP_FLAGS_TRACKING)
2017-10-13 10:06:36 +02:00
{
auto ft = Formatter();
guest->FormatNameTo(ft);
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_left_park)
{
News::AddItemToQueue(News::ItemType::PeepOnRide, STR_PEEP_TRACKING_LEFT_PARK, guest->sprite_index, ft);
2017-06-06 23:24:18 +02:00
}
}
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
// Peep is entering the park.
2015-07-21 19:17:25 +01:00
if (guest->State != PeepState::EnteringPark)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
2017-10-13 10:06:36 +02:00
if (!(gParkFlags & PARK_FLAGS_PARK_OPEN))
{
guest->State = PeepState::LeavingPark;
guest->Var37 = 1;
2017-06-06 23:24:18 +02:00
decrement_guests_heading_for_park();
peep_window_state_update(guest);
peep_return_to_centre_of_tile(guest);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2018-06-22 23:04:19 +02:00
bool found = false;
auto entrance = std::find_if(
gParkEntrances.begin(), gParkEntrances.end(), [coords](const auto& e) { return coords.ToTileStart() == e; });
if (entrance != gParkEntrances.end())
2017-10-13 10:06:36 +02:00
{
int16_t z = entrance->z / 8;
entranceDirection = entrance->direction;
auto nextLoc = coords.ToTileStart() + CoordsDirectionDelta[entranceDirection];
2015-07-21 19:17:25 +01:00
// Make sure there is a path right behind the entrance, otherwise turn around
TileElement* nextTileElement = map_get_first_element_at(nextLoc);
do
2017-10-13 10:06:36 +02:00
{
if (nextTileElement == nullptr)
break;
if (nextTileElement->GetType() != TILE_ELEMENT_TYPE_PATH)
continue;
if (nextTileElement->AsPath()->IsQueue())
continue;
if (nextTileElement->AsPath()->IsSloped())
{
uint8_t slopeDirection = nextTileElement->AsPath()->GetSlopeDirection();
if (slopeDirection == entranceDirection)
{
if (z != nextTileElement->base_height)
{
continue;
}
found = true;
break;
}
2019-01-05 15:41:19 +00:00
if (direction_reverse(slopeDirection) != entranceDirection)
continue;
if (z - 2 != nextTileElement->base_height)
continue;
found = true;
break;
}
2021-09-15 22:22:15 +02:00
if (z != nextTileElement->base_height)
2017-10-13 10:06:36 +02:00
{
2021-09-15 22:22:15 +02:00
continue;
2017-06-06 23:24:18 +02:00
}
2021-09-15 22:22:15 +02:00
found = true;
break;
} while (!(nextTileElement++)->IsLastForTile());
}
2015-07-21 19:17:25 +01:00
2017-10-13 10:06:36 +02:00
if (!found)
{
guest->State = PeepState::LeavingPark;
guest->Var37 = 1;
2017-06-06 23:24:18 +02:00
decrement_guests_heading_for_park();
peep_window_state_update(guest);
peep_return_to_centre_of_tile(guest);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
money16 entranceFee = park_get_entrance_fee();
2017-10-13 10:06:36 +02:00
if (entranceFee != 0)
{
if (guest->HasItem(ShopItem::Voucher))
2017-10-13 10:06:36 +02:00
{
if (guest->VoucherType == VOUCHER_TYPE_PARK_ENTRY_HALF_PRICE)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
entranceFee /= 2;
guest->RemoveItem(ShopItem::Voucher);
guest->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY;
2017-06-06 23:24:18 +02:00
}
else if (guest->VoucherType == VOUCHER_TYPE_PARK_ENTRY_FREE)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
entranceFee = 0;
guest->RemoveItem(ShopItem::Voucher);
guest->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY;
2017-06-06 23:24:18 +02:00
}
}
if (entranceFee > guest->CashInPocket)
2017-10-13 10:06:36 +02:00
{
guest->State = PeepState::LeavingPark;
guest->Var37 = 1;
2017-06-06 23:24:18 +02:00
decrement_guests_heading_for_park();
peep_window_state_update(guest);
peep_return_to_centre_of_tile(guest);
return true;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
gTotalIncomeFromAdmissions += entranceFee;
guest->SpendMoney(guest->PaidToEnter, entranceFee, ExpenditureType::ParkEntranceTickets);
guest->PeepFlags |= PEEP_FLAGS_HAS_PAID_FOR_PARK_ENTRY;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
gTotalAdmissions++;
window_invalidate_by_number(WC_PARK_INFORMATION, 0);
2015-07-21 19:17:25 +01:00
guest->Var37 = 1;
auto destination = guest->GetDestination();
destination += CoordsDirectionDelta[guest->PeepDirection];
guest->SetDestination(destination, 7);
guest->MoveTo({ coords, guest->z });
2017-06-06 23:24:18 +02:00
}
return true;
2015-07-21 19:17:25 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x006946D8
*/
static void peep_footpath_move_forward(Peep* peep, const CoordsXYE& coords, bool vandalism)
2017-10-13 10:06:36 +02:00
{
auto tile_element = coords.element;
peep->NextLoc = { coords.ToTileStart(), tile_element->GetBaseZ() };
peep->SetNextFlags(tile_element->AsPath()->GetSlopeDirection(), tile_element->AsPath()->IsSloped(), false);
2015-09-12 00:16:05 +02:00
int16_t z = peep->GetZOnSlope(coords.x, coords.y);
2015-07-23 21:22:58 +01:00
auto* guest = peep->As<Guest>();
if (guest == nullptr)
2017-10-13 10:06:36 +02:00
{
peep->MoveTo({ coords, z });
return;
2017-06-06 23:24:18 +02:00
}
uint8_t vandalThoughtTimeout = (guest->VandalismSeen & 0xC0) >> 6;
2018-03-21 22:02:16 +00:00
// Advance the vandalised tiles by 1
uint8_t vandalisedTiles = (guest->VandalismSeen * 2) & 0x3F;
2015-07-23 21:22:58 +01:00
if (vandalism)
2017-10-13 10:06:36 +02:00
{
2018-03-21 22:02:16 +00:00
// Add one more to the vandalised tiles
vandalisedTiles |= 1;
// If there has been 2 vandalised tiles in the last 6
if (vandalisedTiles & 0x3E && (vandalThoughtTimeout == 0))
2017-10-13 10:06:36 +02:00
{
2018-03-31 10:01:43 +01:00
if ((scenario_rand() & 0xFFFF) <= 10922)
2017-10-13 10:06:36 +02:00
{
guest->InsertNewThought(PeepThoughtType::Vandalism);
guest->HappinessTarget = std::max(0, guest->HappinessTarget - 17);
2017-06-06 23:24:18 +02:00
}
2018-03-21 22:02:16 +00:00
vandalThoughtTimeout = 3;
2017-06-06 23:24:18 +02:00
}
}
2015-07-23 21:22:58 +01:00
2018-03-31 10:01:43 +01:00
if (vandalThoughtTimeout && (scenario_rand() & 0xFFFF) <= 4369)
2017-10-13 10:06:36 +02:00
{
2018-03-21 22:02:16 +00:00
vandalThoughtTimeout--;
2017-06-06 23:24:18 +02:00
}
2015-09-12 00:16:05 +02:00
guest->VandalismSeen = (vandalThoughtTimeout << 6) | vandalisedTiles;
2018-06-22 23:04:19 +02:00
uint16_t crowded = 0;
uint8_t litter_count = 0;
uint8_t sick_count = 0;
auto quad = EntityTileList(coords);
2020-06-08 20:13:50 +01:00
for (auto entity : quad)
2017-10-13 10:06:36 +02:00
{
2020-06-08 20:13:50 +01:00
if (auto other_peep = entity->As<Peep>(); other_peep != nullptr)
2017-10-13 10:06:36 +02:00
{
if (other_peep->State != PeepState::Walking)
2017-06-06 23:24:18 +02:00
continue;
2015-07-23 21:22:58 +01:00
if (abs(other_peep->z - guest->NextLoc.z) > 16)
2017-06-06 23:24:18 +02:00
continue;
crowded++;
continue;
}
2021-09-15 22:22:15 +02:00
if (auto litter = entity->As<Litter>(); litter != nullptr)
2017-10-13 10:06:36 +02:00
{
if (abs(litter->z - guest->NextLoc.z) > 16)
2017-06-06 23:24:18 +02:00
continue;
2015-07-23 21:22:58 +01:00
2017-06-06 23:24:18 +02:00
litter_count++;
2021-05-13 16:20:25 +02:00
if (litter->SubType != Litter::Type::Vomit && litter->SubType != Litter::Type::VomitAlt)
2017-06-06 23:24:18 +02:00
continue;
2015-07-23 21:22:58 +01:00
2017-06-06 23:24:18 +02:00
litter_count--;
sick_count++;
}
}
2015-07-23 21:22:58 +01:00
if (crowded >= 10 && guest->State == PeepState::Walking && (scenario_rand() & 0xFFFF) <= 21845)
2017-10-13 10:06:36 +02:00
{
guest->InsertNewThought(PeepThoughtType::Crowded);
guest->HappinessTarget = std::max(0, guest->HappinessTarget - 14);
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
litter_count = std::min(static_cast<uint8_t>(3), litter_count);
2018-06-22 23:04:19 +02:00
sick_count = std::min(static_cast<uint8_t>(3), sick_count);
2015-07-23 21:22:58 +01:00
uint8_t disgusting_time = guest->DisgustingCount & 0xC0;
uint8_t disgusting_count = ((guest->DisgustingCount & 0xF) << 2) | sick_count;
guest->DisgustingCount = disgusting_count | disgusting_time;
2015-07-23 21:22:58 +01:00
2018-03-31 10:01:43 +01:00
if (disgusting_time & 0xC0 && (scenario_rand() & 0xFFFF) <= 4369)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Reduce the disgusting time
guest->DisgustingCount -= 0x40;
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
uint8_t total_sick = 0;
for (uint8_t time = 0; time < 3; time++)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
total_sick += (disgusting_count >> (2 * time)) & 0x3;
}
2015-09-12 00:16:05 +02:00
2018-03-31 10:01:43 +01:00
if (total_sick >= 3 && (scenario_rand() & 0xFFFF) <= 10922)
2017-10-13 10:06:36 +02:00
{
guest->InsertNewThought(PeepThoughtType::PathDisgusting);
guest->HappinessTarget = std::max(0, guest->HappinessTarget - 17);
2017-06-06 23:24:18 +02:00
// Reset disgusting time
guest->DisgustingCount |= 0xC0;
2017-06-06 23:24:18 +02:00
}
}
2015-07-23 21:22:58 +01:00
uint8_t litter_time = guest->LitterCount & 0xC0;
litter_count = ((guest->LitterCount & 0xF) << 2) | litter_count;
guest->LitterCount = litter_count | litter_time;
2015-07-23 21:22:58 +01:00
2018-03-31 10:01:43 +01:00
if (litter_time & 0xC0 && (scenario_rand() & 0xFFFF) <= 4369)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Reduce the litter time
guest->LitterCount -= 0x40;
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
uint8_t total_litter = 0;
for (uint8_t time = 0; time < 3; time++)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
total_litter += (litter_count >> (2 * time)) & 0x3;
}
2015-07-23 21:22:58 +01:00
2018-03-31 10:01:43 +01:00
if (total_litter >= 3 && (scenario_rand() & 0xFFFF) <= 10922)
2017-10-13 10:06:36 +02:00
{
guest->InsertNewThought(PeepThoughtType::BadLitter);
guest->HappinessTarget = std::max(0, guest->HappinessTarget - 17);
2017-06-06 23:24:18 +02:00
// Reset litter time
guest->LitterCount |= 0xC0;
2017-06-06 23:24:18 +02:00
}
}
2015-07-23 21:22:58 +01:00
guest->MoveTo({ coords, z });
2015-07-23 21:22:58 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x0069455E
*/
static void peep_interact_with_path(Peep* peep, const CoordsXYE& coords)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// 0x00F1AEE2
auto tile_element = coords.element;
2017-06-06 23:24:18 +02:00
bool vandalism_present = false;
2019-02-26 09:29:25 +00:00
if (tile_element->AsPath()->HasAddition() && (tile_element->AsPath()->IsBroken())
2018-10-05 13:11:44 +02:00
&& (tile_element->AsPath()->GetEdges()) != 0xF)
2017-10-13 10:06:36 +02:00
{
vandalism_present = true;
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
2019-12-22 22:14:02 +01:00
int16_t z = tile_element->GetBaseZ();
auto* guest = peep->As<Guest>();
if (map_is_location_owned({ coords, z }))
2017-10-13 10:06:36 +02:00
{
2021-09-24 20:05:50 +02:00
if (guest != nullptr && guest->OutsideOfPark)
{
peep_return_to_centre_of_tile(guest);
return;
}
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
if (guest == nullptr || !guest->OutsideOfPark)
{
peep_return_to_centre_of_tile(peep);
return;
}
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
2019-02-28 19:28:58 +00:00
if (guest != nullptr && tile_element->AsPath()->IsQueue())
2017-10-13 10:06:36 +02:00
{
auto rideIndex = tile_element->AsPath()->GetRideIndex();
if (guest->State == PeepState::Queuing)
2017-10-13 10:06:36 +02:00
{
2017-06-06 23:24:18 +02:00
// Check if this queue is connected to the ride the
// peep is queuing for, i.e. the player hasn't edited
// the queue, rebuilt the ride, etc.
if (guest->CurrentRide == rideIndex)
2017-10-13 10:06:36 +02:00
{
peep_footpath_move_forward(guest, { coords, tile_element }, vandalism_present);
2017-06-06 23:24:18 +02:00
}
else
2017-10-13 10:06:36 +02:00
{
// Queue got disconnected from the original ride.
guest->InteractionRideIndex = RIDE_ID_NULL;
2019-02-28 19:28:58 +00:00
guest->RemoveFromQueue();
guest->SetState(PeepState::One);
peep_footpath_move_forward(guest, { coords, tile_element }, vandalism_present);
}
}
2017-10-13 10:06:36 +02:00
else
{
// Peep is not queuing.
guest->TimeLost = 0;
auto stationNum = tile_element->AsPath()->GetStationIndex();
2015-07-23 21:22:58 +01:00
if ((tile_element->AsPath()->HasQueueBanner())
&& (tile_element->AsPath()->GetQueueBannerDirection()
== direction_reverse(guest->PeepDirection)) // Ride sign is facing the direction the peep is walking
)
2017-10-13 10:06:36 +02:00
{
/* Peep is approaching the entrance of a ride queue.
* Decide whether to go on the ride. */
auto ride = get_ride(rideIndex);
2019-02-28 19:28:58 +00:00
if (ride != nullptr && guest->ShouldGoOnRide(ride, stationNum, true, false))
{
// Peep has decided to go on the ride at the queue.
guest->InteractionRideIndex = rideIndex;
// Add the peep to the ride queue.
uint16_t old_last_peep = ride->stations[stationNum].LastPeepInQueue;
ride->stations[stationNum].LastPeepInQueue = guest->sprite_index;
guest->GuestNextInQueue = old_last_peep;
ride->stations[stationNum].QueueLength++;
peep_decrement_num_riders(guest);
guest->CurrentRide = rideIndex;
guest->CurrentRideStation = stationNum;
guest->State = PeepState::Queuing;
guest->DaysInQueue = 0;
peep_window_state_update(guest);
guest->RideSubState = PeepRideSubState::InQueue;
guest->DestinationTolerance = 2;
guest->TimeInQueue = 0;
if (guest->PeepFlags & PEEP_FLAGS_TRACKING)
{
auto ft = Formatter();
guest->FormatNameTo(ft);
ride->FormatNameTo(ft);
if (gConfigNotifications.guest_queuing_for_ride)
{
News::AddItemToQueue(
News::ItemType::PeepOnRide, STR_PEEP_TRACKING_PEEP_JOINED_QUEUE_FOR_X, guest->sprite_index, ft);
}
}
peep_footpath_move_forward(guest, { coords, tile_element }, vandalism_present);
}
else
{
// Peep has decided not to go on the ride.
peep_return_to_centre_of_tile(guest);
}
}
else
{
/* Peep is approaching a queue tile without a ride
* sign facing the peep. */
peep_footpath_move_forward(guest, { coords, tile_element }, vandalism_present);
2017-06-06 23:24:18 +02:00
}
}
}
2017-10-13 10:06:36 +02:00
else
{
2020-10-27 22:24:39 +01:00
peep->InteractionRideIndex = RIDE_ID_NULL;
if (guest != nullptr && peep->State == PeepState::Queuing)
2017-10-13 10:06:36 +02:00
{
guest->RemoveFromQueue();
guest->SetState(PeepState::One);
2017-06-06 23:24:18 +02:00
}
peep_footpath_move_forward(peep, { coords, tile_element }, vandalism_present);
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
}
2015-12-11 09:38:37 -06:00
/**
*
* rct2: 0x00693F70
*/
static bool peep_interact_with_shop(Peep* peep, const CoordsXYE& coords)
2017-10-13 10:06:36 +02:00
{
ride_id_t rideIndex = coords.element->AsTrack()->GetRideIndex();
auto ride = get_ride(rideIndex);
2021-02-24 13:53:01 +01:00
if (ride == nullptr || !ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IS_SHOP))
return false;
2015-07-21 19:17:25 +01:00
auto* guest = peep->As<Guest>();
2019-02-28 19:28:58 +00:00
if (guest == nullptr)
{
peep_return_to_centre_of_tile(peep);
return true;
}
2015-09-12 00:16:05 +02:00
// If we are queuing ignore the 'shop'
// This can happen when paths clip through track
if (guest->State == PeepState::Queuing)
{
return false;
}
guest->TimeLost = 0;
2015-09-12 00:16:05 +02:00
if (ride->status != RideStatus::Open)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
if (guest->InteractionRideIndex == rideIndex)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
if (guest->PeepFlags & PEEP_FLAGS_LEAVING_PARK)
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-07-21 19:17:25 +01:00
2021-02-24 13:53:01 +01:00
if (ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_PEEP_SHOULD_GO_INSIDE_FACILITY))
2017-10-13 10:06:36 +02:00
{
guest->TimeLost = 0;
2019-02-28 19:28:58 +00:00
if (!guest->ShouldGoOnRide(ride, 0, false, false))
{
peep_return_to_centre_of_tile(guest);
return true;
}
2015-09-12 00:16:05 +02:00
2020-05-11 17:50:30 +02:00
money16 cost = ride->price[0];
2017-10-13 10:06:36 +02:00
if (cost != 0 && !(gParkFlags & PARK_FLAGS_NO_MONEY))
{
2017-06-06 23:24:18 +02:00
ride->total_profit += cost;
ride->window_invalidate_flags |= RIDE_INVALIDATE_RIDE_INCOME;
2018-04-01 15:34:05 +02:00
// TODO: Refactor? SpendMoney previously accepted nullptr to not track money, passing a temporary variable as a
// workaround
money16 money = 0;
2019-12-22 09:20:40 +01:00
guest->SpendMoney(money, cost, ExpenditureType::ParkRideTickets);
2017-06-06 23:24:18 +02:00
}
auto coordsCentre = coords.ToTileCentre();
guest->SetDestination(coordsCentre, 3);
guest->CurrentRide = rideIndex;
guest->SetState(PeepState::EnteringRide);
guest->RideSubState = PeepRideSubState::ApproachShop;
2015-07-21 19:17:25 +01:00
guest->GuestTimeOnRide = 0;
2017-06-06 23:24:18 +02:00
ride->cur_num_customers++;
if (guest->PeepFlags & PEEP_FLAGS_TRACKING)
2017-10-13 10:06:36 +02:00
{
auto ft = Formatter();
guest->FormatNameTo(ft);
ride->FormatNameTo(ft);
2021-02-24 13:53:01 +01:00
rct_string_id string_id = ride->GetRideTypeDescriptor().HasFlag(RIDE_TYPE_FLAG_IN_RIDE)
? STR_PEEP_TRACKING_PEEP_IS_IN_X
: STR_PEEP_TRACKING_PEEP_IS_ON_X;
2017-10-13 10:06:36 +02:00
if (gConfigNotifications.guest_used_facility)
{
News::AddItemToQueue(News::ItemType::PeepOnRide, string_id, guest->sprite_index, ft);
2017-06-06 23:24:18 +02:00
}
}
}
2017-10-13 10:06:36 +02:00
else
{
if (guest->GuestHeadingToRideId == rideIndex)
guest->GuestHeadingToRideId = RIDE_ID_NULL;
guest->ActionSpriteImageOffset = _unk_F1AEF0;
guest->SetState(PeepState::Buying);
guest->CurrentRide = rideIndex;
guest->SubState = 0;
2017-06-06 23:24:18 +02:00
}
return true;
2015-07-21 19:17:25 +01:00
}
2019-02-28 19:28:58 +00:00
void Peep::PerformNextAction(uint8_t& pathing_result)
2018-04-02 18:18:15 +01:00
{
2018-11-01 13:53:50 +01:00
TileElement* tmpTile;
PerformNextAction(pathing_result, tmpTile);
2018-04-02 18:18:15 +01:00
}
2015-06-30 13:42:06 +01:00
/**
2015-09-12 00:16:05 +02:00
*
2015-06-30 13:42:06 +01:00
* rct2: 0x00693C9E
*/
2019-02-28 19:28:58 +00:00
void Peep::PerformNextAction(uint8_t& pathing_result, TileElement*& tile_result)
2015-06-30 13:42:06 +01:00
{
2018-03-27 21:04:57 +01:00
pathing_result = 0;
2020-06-07 20:18:42 -03:00
PeepActionType previousAction = Action;
2015-07-21 19:17:25 +01:00
2021-05-11 09:44:41 +03:00
if (Action == PeepActionType::Idle)
Action = PeepActionType::Walking;
2015-07-21 19:17:25 +01:00
auto* guest = As<Guest>();
if (State == PeepState::Queuing && guest != nullptr)
2017-10-13 10:06:36 +02:00
{
if (guest->UpdateQueuePosition(previousAction))
return;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2019-08-15 18:32:19 +01:00
std::optional<CoordsXY> loc;
2021-09-13 19:47:13 +03:00
if (loc = UpdateAction(); !loc.has_value())
2017-10-13 10:06:36 +02:00
{
2018-03-27 21:04:57 +01:00
pathing_result |= PATHING_DESTINATION_REACHED;
uint8_t result = 0;
2019-02-28 19:28:58 +00:00
if (guest != nullptr)
2017-10-13 10:06:36 +02:00
{
2019-02-28 19:28:58 +00:00
result = guest_path_finding(guest);
2017-06-06 23:24:18 +02:00
}
2017-10-13 10:06:36 +02:00
else
{
auto* staff = As<Staff>();
2020-03-07 23:07:47 +01:00
result = staff->DoPathFinding();
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2017-06-06 23:24:18 +02:00
if (result != 0)
return;
2015-07-21 19:17:25 +01:00
2021-09-13 19:47:13 +03:00
if (loc = UpdateAction(); !loc.has_value())
return;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2019-08-15 18:32:19 +01:00
auto newLoc = *loc;
CoordsXY truncatedNewLoc = newLoc.ToTileStart();
if (truncatedNewLoc == CoordsXY{ NextLoc })
2017-10-13 10:06:36 +02:00
{
2019-08-15 18:32:19 +01:00
int16_t height = GetZOnSlope(newLoc.x, newLoc.y);
2020-05-11 12:36:45 +02:00
MoveTo({ newLoc.x, newLoc.y, height });
return;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
2020-05-11 12:36:45 +02:00
if (map_is_edge(newLoc))
2017-10-13 10:06:36 +02:00
{
if (guest != nullptr && guest->OutsideOfPark)
2017-10-13 10:06:36 +02:00
{
2018-03-27 21:04:57 +01:00
pathing_result |= PATHING_OUTSIDE_PARK;
2017-06-06 23:24:18 +02:00
}
peep_return_to_centre_of_tile(this);
return;
2017-06-06 23:24:18 +02:00
}
2015-07-21 19:17:25 +01:00
TileElement* tileElement = map_get_first_element_at(newLoc);
if (tileElement == nullptr)
return;
2018-06-22 23:04:19 +02:00
int16_t base_z = std::max(0, (z / 8) - 2);
int16_t top_z = (z / 8) + 1;
2015-07-21 19:17:25 +01:00
2017-10-13 10:06:36 +02:00
do
{
2017-10-31 14:03:45 +01:00
if (base_z > tileElement->base_height)
2017-06-06 23:24:18 +02:00
continue;
2017-10-31 14:03:45 +01:00
if (top_z < tileElement->base_height)
2017-06-06 23:24:18 +02:00
continue;
2019-02-25 15:08:49 +00:00
if (tileElement->IsGhost())
2017-06-06 23:24:18 +02:00
continue;
2015-07-21 19:17:25 +01:00
if (tileElement->GetType() == TILE_ELEMENT_TYPE_PATH)
2017-10-13 10:06:36 +02:00
{
peep_interact_with_path(this, { newLoc, tileElement });
tile_result = tileElement;
return;
2017-06-06 23:24:18 +02:00
}
2021-09-15 22:22:15 +02:00
if (tileElement->GetType() == TILE_ELEMENT_TYPE_TRACK)
2017-10-13 10:06:36 +02:00
{
if (peep_interact_with_shop(this, { newLoc, tileElement }))
2018-04-02 18:18:15 +01:00
{
tile_result = tileElement;
return;
2018-04-02 18:18:15 +01:00
}
2017-06-06 23:24:18 +02:00
}
else if (tileElement->GetType() == TILE_ELEMENT_TYPE_ENTRANCE)
2017-10-13 10:06:36 +02:00
{
if (peep_interact_with_entrance(this, { newLoc, tileElement }, pathing_result))
{
tile_result = tileElement;
return;
}
2017-06-06 23:24:18 +02:00
}
} while (!(tileElement++)->IsLastForTile());
2015-07-21 19:17:25 +01:00
if (Is<Staff>() || (GetNextIsSurface()))
2017-10-13 10:06:36 +02:00
{
int16_t height = abs(tile_element_height(newLoc) - z);
if (height <= 3 || (Is<Staff>() && height <= 32))
2017-10-13 10:06:36 +02:00
{
2020-10-27 22:24:39 +01:00
InteractionRideIndex = RIDE_ID_NULL;
if (guest != nullptr && State == PeepState::Queuing)
2017-10-13 10:06:36 +02:00
{
guest->RemoveFromQueue();
SetState(PeepState::One);
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
2019-08-15 18:32:19 +01:00
if (!map_is_location_in_park(newLoc))
2017-10-13 10:06:36 +02:00
{
peep_return_to_centre_of_tile(this);
return;
2017-06-06 23:24:18 +02:00
}
2015-07-23 21:22:58 +01:00
auto surfaceElement = map_get_surface_element_at(newLoc);
if (surfaceElement == nullptr)
{
peep_return_to_centre_of_tile(this);
return;
}
2015-07-23 21:22:58 +01:00
int16_t water_height = surfaceElement->GetWaterHeight();
2020-01-19 16:12:48 +01:00
if (water_height > 0)
{
peep_return_to_centre_of_tile(this);
return;
}
2015-07-23 21:22:58 +01:00
auto* staff = As<Staff>();
if (staff != nullptr && !GetNextIsSurface())
{
// Prevent staff from leaving the path on their own unless they're allowed to mow.
if (!((staff->StaffOrders & STAFF_ORDERS_MOWING) && staff->StaffMowingTimeout >= 12))
{
peep_return_to_centre_of_tile(staff);
return;
}
}
// The peep is on a surface and not on a path
NextLoc = { truncatedNewLoc, surfaceElement->GetBaseZ() };
2018-04-04 18:50:07 +01:00
SetNextFlags(0, false, true);
2015-07-23 21:22:58 +01:00
2019-08-15 18:32:19 +01:00
height = GetZOnSlope(newLoc.x, newLoc.y);
2020-05-11 12:36:45 +02:00
MoveTo({ newLoc.x, newLoc.y, height });
return;
2017-06-06 23:24:18 +02:00
}
}
peep_return_to_centre_of_tile(this);
2015-06-30 13:42:06 +01:00
}
/**
2015-12-11 09:38:37 -06:00
* Gets the height including the bit depending on how far up the slope the peep
* is.
* rct2: 0x00694921
*/
2019-02-28 19:28:58 +00:00
int32_t Peep::GetZOnSlope(int32_t tile_x, int32_t tile_y)
{
2018-04-02 18:18:15 +01:00
if (tile_x == LOCATION_NULL)
2017-06-06 23:24:18 +02:00
return 0;
2015-07-19 10:22:49 +01:00
2018-04-04 18:50:07 +01:00
if (GetNextIsSurface())
2017-10-13 10:06:36 +02:00
{
return tile_element_height({ tile_x, tile_y });
2017-06-06 23:24:18 +02:00
}
2015-07-19 10:22:49 +01:00
uint8_t slope = GetNextDirection();
return NextLoc.z + map_height_from_slope({ tile_x, tile_y }, slope, GetNextIsSloped());
}
2019-07-21 20:44:19 +01:00
rct_string_id get_real_name_string_id_from_id(uint32_t id)
{
2020-06-06 10:31:19 -03:00
// Generate a name_string_idx from the peep Id using bit twiddling
2020-04-22 17:09:29 +02:00
uint16_t ax = static_cast<uint16_t>(id + 0xF0B);
uint16_t dx = 0;
2021-10-17 15:31:56 +02:00
static constexpr uint16_t twiddlingBitOrder[] = {
4, 9, 3, 7, 5, 8, 2, 1, 6, 0, 12, 11, 13, 10,
};
2018-11-21 23:16:04 +01:00
for (size_t i = 0; i < std::size(twiddlingBitOrder); i++)
2018-04-05 14:34:48 +02:00
{
dx |= (ax & (1 << twiddlingBitOrder[i]) ? 1 : 0) << i;
}
2017-06-06 23:24:18 +02:00
ax = dx & 0xF;
dx *= 4;
ax *= 4096;
dx += ax;
2017-10-13 10:06:36 +02:00
if (dx < ax)
{
2017-06-06 23:24:18 +02:00
dx += 0x1000;
}
dx /= 4;
2017-11-23 15:52:06 +01:00
dx += REAL_NAME_START;
2019-07-21 20:44:19 +01:00
return dx;
}
int32_t peep_compare(const uint16_t sprite_index_a, const uint16_t sprite_index_b)
2016-05-15 18:47:04 +02:00
{
Peep const* peep_a = GetEntity<Peep>(sprite_index_a);
Peep const* peep_b = GetEntity<Peep>(sprite_index_b);
if (peep_a == nullptr || peep_b == nullptr)
{
return 0;
}
2016-05-15 18:47:04 +02:00
2017-06-06 23:24:18 +02:00
// Compare types
if (peep_a->Type != peep_b->Type)
2017-10-13 10:06:36 +02:00
{
return static_cast<int32_t>(peep_a->Type) - static_cast<int32_t>(peep_b->Type);
2017-06-06 23:24:18 +02:00
}
2016-05-15 18:47:04 +02:00
if (peep_a->Name == nullptr && peep_b->Name == nullptr)
2017-10-13 10:06:36 +02:00
{
2019-07-21 20:44:19 +01:00
if (gParkFlags & PARK_FLAGS_SHOW_REAL_GUEST_NAMES)
2017-10-13 10:06:36 +02:00
{
2019-07-21 20:44:19 +01:00
// Potentially could find a more optional way of sorting dynamic real names
2017-10-13 10:06:36 +02:00
}
else
{
2019-07-21 20:44:19 +01:00
// Simple ID comparison for when both peeps use a number or a generated name
2020-06-06 10:31:19 -03:00
return peep_a->Id - peep_b->Id;
2017-06-06 23:24:18 +02:00
}
}
2016-05-15 18:47:04 +02:00
2017-06-06 23:24:18 +02:00
// Compare their names as strings
2019-07-21 20:44:19 +01:00
char nameA[256]{};
Formatter ft;
peep_a->FormatNameTo(ft);
format_string(nameA, sizeof(nameA), STR_STRINGID, ft.Data());
2019-07-21 20:44:19 +01:00
char nameB[256]{};
ft.Rewind();
peep_b->FormatNameTo(ft);
format_string(nameB, sizeof(nameB), STR_STRINGID, ft.Data());
2019-07-21 20:44:19 +01:00
return strlogicalcmp(nameA, nameB);
2016-05-15 18:47:04 +02:00
}
/**
2015-09-12 00:16:05 +02:00
*
* rct2: 0x0069926C
*/
void peep_update_names(bool realNames)
{
2017-10-13 10:06:36 +02:00
if (realNames)
{
2017-06-06 23:24:18 +02:00
gParkFlags |= PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
2019-07-21 20:44:19 +01:00
// Peep names are now dynamic
2017-10-13 10:06:36 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
gParkFlags &= ~PARK_FLAGS_SHOW_REAL_GUEST_NAMES;
2019-07-21 20:44:19 +01:00
// Peep names are now dynamic
2017-06-06 23:24:18 +02:00
}
2016-05-15 18:47:04 +02:00
2020-03-28 12:37:01 +00:00
auto intent = Intent(INTENT_ACTION_REFRESH_GUEST_LIST);
context_broadcast_intent(&intent);
2017-06-06 23:24:18 +02:00
gfx_invalidate_screen();
}
2015-08-04 15:21:12 +01:00
2017-10-10 15:16:30 +02:00
void increment_guests_in_park()
{
if (gNumGuestsInPark < UINT32_MAX)
2017-10-10 15:16:30 +02:00
{
2017-06-06 23:24:18 +02:00
gNumGuestsInPark++;
2017-10-10 15:16:30 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
openrct2_assert(false, "Attempt to increment guests in park above max value (65535).");
}
}
2017-10-10 15:16:30 +02:00
void increment_guests_heading_for_park()
{
if (gNumGuestsHeadingForPark < UINT32_MAX)
2017-10-10 15:16:30 +02:00
{
2017-06-06 23:24:18 +02:00
gNumGuestsHeadingForPark++;
2017-10-10 15:16:30 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
openrct2_assert(false, "Attempt to increment guests heading for park above max value (65535).");
}
}
2017-10-10 15:16:30 +02:00
void decrement_guests_in_park()
{
if (gNumGuestsInPark > 0)
{
2017-06-06 23:24:18 +02:00
gNumGuestsInPark--;
2017-10-10 15:16:30 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
log_error("Attempt to decrement guests in park below zero.");
}
}
2017-10-10 15:16:30 +02:00
void decrement_guests_heading_for_park()
{
if (gNumGuestsHeadingForPark > 0)
{
2017-06-06 23:24:18 +02:00
gNumGuestsHeadingForPark--;
2017-10-10 15:16:30 +02:00
}
else
{
2017-06-06 23:24:18 +02:00
log_error("Attempt to decrement guests heading for park below zero.");
}
}
2019-02-28 19:28:58 +00:00
static void peep_release_balloon(Guest* peep, int16_t spawn_height)
2017-10-10 15:16:30 +02:00
{
if (peep->HasItem(ShopItem::Balloon))
{
peep->RemoveItem(ShopItem::Balloon);
2020-10-06 01:56:52 -03:00
if (peep->SpriteType == PeepSpriteType::Balloon && peep->x != LOCATION_NULL)
{
2021-05-12 08:01:08 +01:00
Balloon::Create({ peep->x, peep->y, spawn_height }, peep->BalloonColour, false);
peep->WindowInvalidateFlags |= PEEP_INVALIDATE_PEEP_INVENTORY;
2018-04-04 19:18:49 +01:00
peep->UpdateSpriteType();
}
}
}
2019-02-28 19:28:58 +00:00
/**
*
* rct2: 0x0069A512
*/
void Peep::RemoveFromRide()
{
auto* guest = As<Guest>();
if (guest != nullptr && State == PeepState::Queuing)
2019-02-28 19:28:58 +00:00
{
guest->RemoveFromQueue();
2019-02-28 19:28:58 +00:00
}
StateReset();
}
void Peep::SetDestination(const CoordsXY& coords)
{
DestinationX = static_cast<uint16_t>(coords.x);
DestinationY = static_cast<uint16_t>(coords.y);
}
void Peep::SetDestination(const CoordsXY& coords, int32_t tolerance)
{
SetDestination(coords);
DestinationTolerance = tolerance;
}
CoordsXY Peep::GetDestination() const
{
2021-02-20 13:49:50 +02:00
return CoordsXY{ DestinationX, DestinationY };
}
void Peep::Serialise(DataSerialiser& stream)
{
EntityBase::Serialise(stream);
if (stream.IsLoading())
{
Name = nullptr;
}
stream << NextLoc;
stream << NextFlags;
stream << State;
stream << SubState;
stream << SpriteType;
stream << TshirtColour;
stream << TrousersColour;
stream << DestinationX;
stream << DestinationY;
stream << DestinationTolerance;
stream << Var37;
stream << Energy;
stream << EnergyTarget;
stream << Mass;
// stream << base.WindowInvalidateFlags;
stream << CurrentRide;
stream << CurrentRideStation;
stream << CurrentTrain;
stream << CurrentCar;
stream << CurrentSeat;
stream << SpecialSprite;
stream << ActionSpriteType;
stream << NextActionSpriteType;
stream << ActionSpriteImageOffset;
stream << Action;
stream << ActionFrame;
stream << StepProgress;
stream << PeepDirection;
stream << InteractionRideIndex;
stream << Id;
stream << PathCheckOptimisation;
stream << PathfindGoal;
stream << PathfindHistory;
stream << WalkingFrameNum;
stream << PeepFlags;
}
2021-11-27 15:20:17 +02:00
2021-11-27 15:51:54 +02:00
void Peep::Paint(paint_session* session, int32_t imageDirection) const
2021-11-27 15:20:17 +02:00
{
2021-11-27 15:51:54 +02:00
#ifdef __ENABLE_LIGHTFX__
if (lightfx_is_available())
{
if (Is<Staff>())
{
auto loc = GetLocation();
switch (sprite_direction)
{
case 0:
loc.x -= 10;
break;
case 8:
loc.y += 10;
break;
case 16:
loc.x += 10;
break;
case 24:
loc.y -= 10;
break;
default:
return;
}
LightfxAdd3DLight(*this, 0, loc, LightType::Spot1);
}
}
#endif
rct_drawpixelinfo* dpi = &session->DPI;
if (dpi->zoom_level > 2)
{
return;
}
if (session->ViewFlags & VIEWPORT_FLAG_INVISIBLE_PEEPS)
{
return;
}
PeepActionSpriteType actionSpriteType = ActionSpriteType;
uint8_t imageOffset = ActionSpriteImageOffset;
if (Action == PeepActionType::Idle)
{
actionSpriteType = NextActionSpriteType;
imageOffset = 0;
}
// In the following 4 calls to PaintAddImageAsParent/PaintAddImageAsChild, we add 5 (instead of 3) to the
// bound_box_offset_z to make sure peeps are drawn on top of railways
uint32_t baseImageId = (imageDirection >> 3) + GetPeepAnimation(SpriteType, actionSpriteType).base_image + imageOffset * 4;
uint32_t imageId = baseImageId | TshirtColour << 19 | TrousersColour << 24 | IMAGE_TYPE_REMAP | IMAGE_TYPE_REMAP_2_PLUS;
PaintAddImageAsParent(session, imageId, { 0, 0, z }, { 1, 1, 11 }, { 0, 0, z + 5 });
auto* guest = As<Guest>();
if (guest != nullptr)
{
if (baseImageId >= 10717 && baseImageId < 10749)
{
imageId = (baseImageId + 32) | guest->HatColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, { 0, 0, z }, { 1, 1, 11 }, { 0, 0, z + 5 });
return;
}
if (baseImageId >= 10781 && baseImageId < 10813)
{
imageId = (baseImageId + 32) | guest->BalloonColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, { 0, 0, z }, { 1, 1, 11 }, { 0, 0, z + 5 });
return;
}
if (baseImageId >= 11197 && baseImageId < 11229)
{
imageId = (baseImageId + 32) | guest->UmbrellaColour << 19 | IMAGE_TYPE_REMAP;
PaintAddImageAsChild(session, imageId, { 0, 0, z }, { 1, 1, 11 }, { 0, 0, z + 5 });
return;
}
}
2021-11-27 15:20:17 +02:00
}