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 "TileModifyAction.h"
11 
12 #include "../world/TileInspector.h"
13 
14 using namespace OpenRCT2;
15 
TileModifyAction(CoordsXY loc,TileModifyType setting,uint32_t value1,uint32_t value2,TileElement pasteElement)16 TileModifyAction::TileModifyAction(
17     CoordsXY loc, TileModifyType setting, uint32_t value1, uint32_t value2, TileElement pasteElement)
18     : _loc(loc)
19     , _setting(setting)
20     , _value1(value1)
21     , _value2(value2)
22     , _pasteElement(pasteElement)
23 {
24 }
25 
GetActionFlags() const26 uint16_t TileModifyAction::GetActionFlags() const
27 {
28     return GameAction::GetActionFlags() | GameActions::Flags::AllowWhilePaused;
29 }
30 
Serialise(DataSerialiser & stream)31 void TileModifyAction::Serialise(DataSerialiser& stream)
32 {
33     GameAction::Serialise(stream);
34 
35     stream << DS_TAG(_loc) << DS_TAG(_setting) << DS_TAG(_value1) << DS_TAG(_value2) << DS_TAG(_pasteElement);
36 }
37 
Query() const38 GameActions::Result::Ptr TileModifyAction::Query() const
39 {
40     return QueryExecute(false);
41 }
42 
Execute() const43 GameActions::Result::Ptr TileModifyAction::Execute() const
44 {
45     return QueryExecute(true);
46 }
47 
QueryExecute(bool isExecuting) const48 GameActions::Result::Ptr TileModifyAction::QueryExecute(bool isExecuting) const
49 {
50     if (!LocationValid(_loc))
51     {
52         return MakeResult(GameActions::Status::InvalidParameters, STR_LAND_NOT_OWNED_BY_PARK, STR_NONE);
53     }
54     auto res = MakeResult();
55     switch (_setting)
56     {
57         case TileModifyType::AnyRemove:
58         {
59             const auto elementIndex = _value1;
60             res = TileInspector::RemoveElementAt(_loc, elementIndex, isExecuting);
61             break;
62         }
63         case TileModifyType::AnySwap:
64         {
65             const auto firstIndex = _value1;
66             const auto secondIndex = _value2;
67             res = TileInspector::SwapElementsAt(_loc, firstIndex, secondIndex, isExecuting);
68             break;
69         }
70         case TileModifyType::AnyInsertCorrupt:
71         {
72             const auto elementIndex = _value1;
73             res = TileInspector::InsertCorruptElementAt(_loc, elementIndex, isExecuting);
74             break;
75         }
76         case TileModifyType::AnyRotate:
77         {
78             const auto elementIndex = _value1;
79             res = TileInspector::RotateElementAt(_loc, elementIndex, isExecuting);
80             break;
81         }
82         case TileModifyType::AnyPaste:
83         {
84             res = TileInspector::PasteElementAt(_loc, _pasteElement, isExecuting);
85             break;
86         }
87         case TileModifyType::AnySort:
88         {
89             res = TileInspector::SortElementsAt(_loc, isExecuting);
90             break;
91         }
92         case TileModifyType::AnyBaseHeightOffset:
93         {
94             const auto elementIndex = _value1;
95             const auto heightOffset = _value2;
96             res = TileInspector::AnyBaseHeightOffset(_loc, elementIndex, heightOffset, isExecuting);
97             break;
98         }
99         case TileModifyType::SurfaceShowParkFences:
100         {
101             const bool showFences = _value1;
102             res = TileInspector::SurfaceShowParkFences(_loc, showFences, isExecuting);
103             break;
104         }
105         case TileModifyType::SurfaceToggleCorner:
106         {
107             const auto cornerIndex = _value1;
108             res = TileInspector::SurfaceToggleCorner(_loc, cornerIndex, isExecuting);
109             break;
110         }
111         case TileModifyType::SurfaceToggleDiagonal:
112         {
113             res = TileInspector::SurfaceToggleDiagonal(_loc, isExecuting);
114             break;
115         }
116         case TileModifyType::PathSetSlope:
117         {
118             const auto elementIndex = _value1;
119             const bool sloped = _value2;
120             res = TileInspector::PathSetSloped(_loc, elementIndex, sloped, isExecuting);
121             break;
122         }
123         case TileModifyType::PathSetBroken:
124         {
125             const auto elementIndex = _value1;
126             const bool broken = _value2;
127             res = TileInspector::PathSetBroken(_loc, elementIndex, broken, isExecuting);
128             break;
129         }
130         case TileModifyType::PathToggleEdge:
131         {
132             const auto elementIndex = _value1;
133             const auto edgeIndex = _value2;
134             res = TileInspector::PathToggleEdge(_loc, elementIndex, edgeIndex, isExecuting);
135             break;
136         }
137         case TileModifyType::EntranceMakeUsable:
138         {
139             const auto elementIndex = _value1;
140             res = TileInspector::EntranceMakeUsable(_loc, elementIndex, isExecuting);
141             break;
142         }
143         case TileModifyType::WallSetSlope:
144         {
145             const auto elementIndex = _value1;
146             const auto slopeValue = _value2;
147             res = TileInspector::WallSetSlope(_loc, elementIndex, slopeValue, isExecuting);
148             break;
149         }
150         case TileModifyType::WallSetAnimationFrame:
151         {
152             const auto elementIndex = _value1;
153             const auto animationFrameOffset = _value2;
154             res = TileInspector::WallAnimationFrameOffset(_loc, elementIndex, animationFrameOffset, isExecuting);
155             break;
156         }
157         case TileModifyType::TrackBaseHeightOffset:
158         {
159             const auto elementIndex = _value1;
160             const auto heightOffset = _value2;
161             res = TileInspector::TrackBaseHeightOffset(_loc, elementIndex, heightOffset, isExecuting);
162             break;
163         }
164         case TileModifyType::TrackSetChainBlock:
165         {
166             const auto elementIndex = _value1;
167             const bool setChain = _value2;
168             res = TileInspector::TrackSetChain(_loc, elementIndex, true, setChain, isExecuting);
169             break;
170         }
171         case TileModifyType::TrackSetChain:
172         {
173             const auto elementIndex = _value1;
174             const bool setChain = _value2;
175             res = TileInspector::TrackSetChain(_loc, elementIndex, false, setChain, isExecuting);
176             break;
177         }
178         case TileModifyType::TrackSetBlockBrake:
179         {
180             const auto elementIndex = _value1;
181             const bool blockBrake = _value2;
182             res = TileInspector::TrackSetBlockBrake(_loc, elementIndex, blockBrake, isExecuting);
183             break;
184         }
185         case TileModifyType::TrackSetIndestructible:
186         {
187             const auto elementIndex = _value1;
188             const bool isIndestructible = _value2;
189             res = TileInspector::TrackSetIndestructible(_loc, elementIndex, isIndestructible, isExecuting);
190             break;
191         }
192         case TileModifyType::ScenerySetQuarterLocation:
193         {
194             const auto elementIndex = _value1;
195             const auto quarterIndex = _value2;
196             res = TileInspector::ScenerySetQuarterLocation(_loc, elementIndex, quarterIndex, isExecuting);
197             break;
198         }
199         case TileModifyType::ScenerySetQuarterCollision:
200         {
201             const auto elementIndex = _value1;
202             const auto quarterIndex = _value2;
203             res = TileInspector::ScenerySetQuarterCollision(_loc, elementIndex, quarterIndex, isExecuting);
204             break;
205         }
206         case TileModifyType::BannerToggleBlockingEdge:
207         {
208             const auto elementIndex = _value1;
209             const auto edgeIndex = _value2;
210             res = TileInspector::BannerToggleBlockingEdge(_loc, elementIndex, edgeIndex, isExecuting);
211             break;
212         }
213         case TileModifyType::CorruptClamp:
214         {
215             const auto elementIndex = _value1;
216             res = TileInspector::CorruptClamp(_loc, elementIndex, isExecuting);
217             break;
218         }
219         default:
220             log_error("invalid instruction");
221             return MakeResult(GameActions::Status::InvalidParameters, STR_NONE, STR_NONE);
222     }
223 
224     res->Position.x = _loc.x;
225     res->Position.y = _loc.y;
226     res->Position.z = tile_element_height(_loc);
227 
228     return res;
229 }
230