1 /*****************************************************************************
2 * Copyright (c) 2014-2020 OpenRCT2 developers
3 *
4 * For a complete list of all authors, please refer to contributors.md
5 * Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
6 *
7 * OpenRCT2 is licensed under the GNU General Public License version 3.
8 *****************************************************************************/
9
10 #include "StaffSetCostumeAction.h"
11
12 #include "../Context.h"
13 #include "../interface/Window.h"
14 #include "../localisation/Localisation.h"
15 #include "../localisation/StringIds.h"
16 #include "../windows/Intent.h"
17 #include "../world/Entity.h"
18
19 /** rct2: 0x00982134 */
20 constexpr const bool peep_slow_walking_types[] = {
21 false, // PeepSpriteType::Normal
22 false, // PeepSpriteType::Handyman
23 false, // PeepSpriteType::Mechanic
24 false, // PeepSpriteType::Security
25 false, // PeepSpriteType::EntertainerPanda
26 false, // PeepSpriteType::EntertainerTiger
27 false, // PeepSpriteType::EntertainerElephant
28 false, // PeepSpriteType::EntertainerRoman
29 false, // PeepSpriteType::EntertainerGorilla
30 false, // PeepSpriteType::EntertainerSnowman
31 false, // PeepSpriteType::EntertainerKnight
32 true, // PeepSpriteType::EntertainerAstronaut
33 false, // PeepSpriteType::EntertainerBandit
34 false, // PeepSpriteType::EntertainerSheriff
35 true, // PeepSpriteType::EntertainerPirate
36 true, // PeepSpriteType::Balloon
37 };
38
StaffSetCostumeAction(uint16_t spriteIndex,EntertainerCostume costume)39 StaffSetCostumeAction::StaffSetCostumeAction(uint16_t spriteIndex, EntertainerCostume costume)
40 : _spriteIndex(spriteIndex)
41 , _costume(costume)
42 {
43 }
44
GetActionFlags() const45 uint16_t StaffSetCostumeAction::GetActionFlags() const
46 {
47 return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
48 }
49
Serialise(DataSerialiser & stream)50 void StaffSetCostumeAction::Serialise(DataSerialiser& stream)
51 {
52 GameAction::Serialise(stream);
53
54 stream << DS_TAG(_spriteIndex) << DS_TAG(_costume);
55 }
56
Query() const57 GameActions::Result::Ptr StaffSetCostumeAction::Query() const
58 {
59 if (_spriteIndex >= MAX_ENTITIES)
60 {
61 return std::make_unique<GameActions::Result>(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
62 }
63
64 auto* staff = TryGetEntity<Staff>(_spriteIndex);
65 if (staff == nullptr)
66 {
67 log_warning("Invalid game command for sprite %u", _spriteIndex);
68 return std::make_unique<GameActions::Result>(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
69 }
70
71 auto spriteType = EntertainerCostumeToSprite(_costume);
72 if (EnumValue(spriteType) > std::size(peep_slow_walking_types))
73 {
74 log_warning("Invalid game command for sprite %u", _spriteIndex);
75 return std::make_unique<GameActions::Result>(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
76 }
77 return std::make_unique<GameActions::Result>();
78 }
79
Execute() const80 GameActions::Result::Ptr StaffSetCostumeAction::Execute() const
81 {
82 auto* staff = TryGetEntity<Staff>(_spriteIndex);
83 if (staff == nullptr)
84 {
85 log_warning("Invalid game command for sprite %u", _spriteIndex);
86 return std::make_unique<GameActions::Result>(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
87 }
88
89 auto spriteType = EntertainerCostumeToSprite(_costume);
90 staff->SpriteType = spriteType;
91 staff->PeepFlags &= ~PEEP_FLAGS_SLOW_WALK;
92 if (peep_slow_walking_types[EnumValue(spriteType)])
93 {
94 staff->PeepFlags |= PEEP_FLAGS_SLOW_WALK;
95 }
96 staff->ActionFrame = 0;
97 staff->UpdateCurrentActionSpriteType();
98 staff->Invalidate();
99
100 window_invalidate_by_number(WC_PEEP, _spriteIndex);
101 auto intent = Intent(INTENT_ACTION_REFRESH_STAFF_LIST);
102 context_broadcast_intent(&intent);
103
104 auto res = std::make_unique<GameActions::Result>();
105 res->Position = staff->GetLocation();
106
107 return res;
108 }
109