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

Function ShowBuildBridgeWindow

src/bridge_gui.cpp:357–439  ·  view source on GitHub ↗

* Prepare the data for the build a bridge window. * If we can't build a bridge under the given conditions * show an error message. * * @param start The start tile of the bridge * @param end The end tile of the bridge * @param transport_type The transport type * @param road_rail_type The road/rail type */

Source from the content-addressed store, hash-verified

355 * @param road_rail_type The road/rail type
356 */
357void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transport_type, uint8_t road_rail_type)
358{
359 CloseWindowByClass(WC_BUILD_BRIDGE);
360
361 /* The bridge length without ramps. */
362 const uint bridge_len = GetTunnelBridgeLength(start, end);
363
364 /* If Ctrl is being pressed, check whether the last bridge built is available
365 * If so, return this bridge type. Otherwise continue normally.
366 * We store bridge types for each transport type, so we have to check for
367 * the transport type beforehand.
368 */
369 BridgeType last_bridge_type = 0;
370 switch (transport_type) {
371 case TRANSPORT_ROAD: last_bridge_type = _last_roadbridge_type; break;
372 case TRANSPORT_RAIL: last_bridge_type = _last_railbridge_type; break;
373 default: break; // water ways and air routes don't have bridge types
374 }
375 if (_ctrl_pressed && CheckBridgeAvailability(last_bridge_type, bridge_len).Succeeded()) {
376 Command<CMD_BUILD_BRIDGE>::Post(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE, CcBuildBridge, end, start, transport_type, last_bridge_type, road_rail_type);
377 return;
378 }
379
380 /* only query bridge building possibility once, result is the same for all bridges!
381 * returns CMD_ERROR on failure, and price on success */
382 CommandCost ret = Command<CMD_BUILD_BRIDGE>::Do(CommandFlagsToDCFlags(GetCommandFlags<CMD_BUILD_BRIDGE>()) | DoCommandFlag::QueryCost, end, start, transport_type, 0, road_rail_type);
383
384 GUIBridgeList bl;
385 if (!ret.Failed()) {
386 /* check which bridges can be built */
387 const uint tot_bridgedata_len = CalcBridgeLenCostFactor(bridge_len + 2);
388
389 Money infra_cost = 0;
390 switch (transport_type) {
391 case TRANSPORT_ROAD: {
392 /* In case we add a new road type as well, we must be aware of those costs. */
393 RoadType road_rt = INVALID_ROADTYPE;
394 RoadType tram_rt = INVALID_ROADTYPE;
395 if (IsBridgeTile(start)) {
396 road_rt = GetRoadTypeRoad(start);
397 tram_rt = GetRoadTypeTram(start);
398 }
399 if (RoadTypeIsRoad((RoadType)road_rail_type)) {
400 road_rt = (RoadType)road_rail_type;
401 } else {
402 tram_rt = (RoadType)road_rail_type;
403 }
404
405 if (road_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(road_rt);
406 if (tram_rt != INVALID_ROADTYPE) infra_cost += (bridge_len + 2) * 2 * RoadBuildCost(tram_rt);
407
408 break;
409 }
410 case TRANSPORT_RAIL: infra_cost = (bridge_len + 2) * RailBuildCost((RailType)road_rail_type); break;
411 default: break;
412 }
413
414 bool any_available = false;

Callers 2

OnPlaceMouseUpMethod · 0.85
OnPlaceMouseUpMethod · 0.85

Calls 15

CloseWindowByClassFunction · 0.85
GetTunnelBridgeLengthFunction · 0.85
CheckBridgeAvailabilityFunction · 0.85
CommandFlagsToDCFlagsFunction · 0.85
CalcBridgeLenCostFactorFunction · 0.85
IsBridgeTileFunction · 0.85
GetRoadTypeRoadFunction · 0.85
GetRoadTypeTramFunction · 0.85
RoadTypeIsRoadFunction · 0.85
RoadBuildCostFunction · 0.85
RailBuildCostFunction · 0.85
GetBridgeSpecFunction · 0.85

Tested by

no test coverage detected