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 "RideSetColourSchemeAction.h"
11
12 #include "../Cheats.h"
13 #include "../common.h"
14 #include "../core/MemoryStream.h"
15 #include "../interface/Window.h"
16 #include "../localisation/Localisation.h"
17 #include "../localisation/StringIds.h"
18 #include "../management/Finance.h"
19 #include "../ride/Ride.h"
20 #include "../world/Park.h"
21
RideSetColourSchemeAction(const CoordsXYZD & location,track_type_t trackType,uint16_t newColourScheme)22 RideSetColourSchemeAction::RideSetColourSchemeAction(
23 const CoordsXYZD& location, track_type_t trackType, uint16_t newColourScheme)
24 : _loc(location)
25 , _trackType(trackType)
26 , _newColourScheme(newColourScheme)
27 {
28 }
29
AcceptParameters(GameActionParameterVisitor & visitor)30 void RideSetColourSchemeAction::AcceptParameters(GameActionParameterVisitor& visitor)
31 {
32 visitor.Visit(_loc);
33 visitor.Visit("trackType", _trackType);
34 visitor.Visit("colourScheme", _newColourScheme);
35 }
36
GetActionFlags() const37 uint16_t RideSetColourSchemeAction::GetActionFlags() const
38 {
39 return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
40 }
41
Serialise(DataSerialiser & stream)42 void RideSetColourSchemeAction::Serialise(DataSerialiser& stream)
43 {
44 GameAction::Serialise(stream);
45
46 stream << DS_TAG(_loc) << DS_TAG(_trackType) << DS_TAG(_newColourScheme);
47 }
48
Query() const49 GameActions::Result::Ptr RideSetColourSchemeAction::Query() const
50 {
51 if (!LocationValid(_loc))
52 {
53 return MakeResult(GameActions::Status::InvalidParameters, STR_CANT_SET_COLOUR_SCHEME, STR_LAND_NOT_OWNED_BY_PARK);
54 }
55 return std::make_unique<GameActions::Result>();
56 }
57
Execute() const58 GameActions::Result::Ptr RideSetColourSchemeAction::Execute() const
59 {
60 GameActions::Result::Ptr res = std::make_unique<GameActions::Result>();
61 res->Expenditure = ExpenditureType::RideConstruction;
62 res->ErrorTitle = STR_CANT_SET_COLOUR_SCHEME;
63
64 GetTrackElementOriginAndApplyChanges(_loc, _trackType, _newColourScheme, nullptr, TRACK_ELEMENT_SET_COLOUR_SCHEME);
65
66 return res;
67 }
68