MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / OnPlaceObject

Method OnPlaceObject

src/dock_gui.cpp:195–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193 }
194
195 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
196 {
197 switch (this->last_clicked_widget) {
198 case WID_DT_CANAL: // Build canal button
199 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_WATER);
200 break;
201
202 case WID_DT_LOCK: // Build lock button
203 Command<CMD_BUILD_LOCK>::Post(STR_ERROR_CAN_T_BUILD_LOCKS, CcBuildDocks, tile);
204 break;
205
206 case WID_DT_DEMOLISH: // Demolish aka dynamite button
207 PlaceProc_DemolishArea(tile);
208 break;
209
210 case WID_DT_DEPOT: // Build depot button
211 Command<CMD_BUILD_SHIP_DEPOT>::Post(STR_ERROR_CAN_T_BUILD_SHIP_DEPOT, CcBuildDocks, tile, _ship_depot_direction);
212 break;
213
214 case WID_DT_STATION: { // Build station button
215 /* Determine the watery part of the dock. */
216 DiagDirection dir = GetInclinedSlopeDirection(GetTileSlope(tile));
217 TileIndex tile_to = (dir != INVALID_DIAGDIR ? TileAddByDiagDir(tile, ReverseDiagDir(dir)) : tile);
218
219 bool adjacent = _ctrl_pressed;
220 auto proc = [=](bool test, StationID to_join) -> bool {
221 if (test) {
222 return Command<CMD_BUILD_DOCK>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_DOCK>()), tile, StationID::Invalid(), adjacent).Succeeded();
223 } else {
224 return Command<CMD_BUILD_DOCK>::Post(STR_ERROR_CAN_T_BUILD_DOCK_HERE, CcBuildDocks, tile, to_join, adjacent);
225 }
226 };
227
228 ShowSelectStationIfNeeded(TileArea(tile, tile_to), proc);
229 break;
230 }
231
232 case WID_DT_BUOY: // Build buoy button
233 Command<CMD_BUILD_BUOY>::Post(STR_ERROR_CAN_T_POSITION_BUOY_HERE, CcBuildDocks, tile);
234 break;
235
236 case WID_DT_RIVER: // Build river button (in scenario editor)
237 VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_RIVER);
238 break;
239
240 case WID_DT_BUILD_AQUEDUCT: // Build aqueduct button
241 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_AQUEDUCT_HERE, CcBuildBridge, tile, GetOtherAqueductEnd(tile), TRANSPORT_WATER, 0, 0);
242 break;
243
244 default: NOT_REACHED();
245 }
246 }
247
248 void OnPlaceDrag(ViewportPlaceMethod select_method, [[maybe_unused]] ViewportDragDropSelectionProcess select_proc, [[maybe_unused]] Point pt) override
249 {

Callers

nothing calls this directly

Calls 12

VpStartPlaceSizingFunction · 0.85
PlaceProc_DemolishAreaFunction · 0.85
GetTileSlopeFunction · 0.85
TileAddByDiagDirFunction · 0.85
ReverseDiagDirFunction · 0.85
CommandFlagsToDCFlagsFunction · 0.85
InvalidFunction · 0.85
GetOtherAqueductEndFunction · 0.85
NOT_REACHEDFunction · 0.85
SucceededMethod · 0.80

Tested by

no test coverage detected