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

Function CheckBridgeAvailability

src/tunnelbridge_cmd.cpp:240–257  ·  view source on GitHub ↗

* Is a bridge of the specified type and length available? * @param bridge_type Wanted type of bridge. * @param bridge_len Wanted length of the bridge. * @param flags Type of operation. * @return A succeeded (the requested bridge is available) or failed (it cannot be built) command. */

Source from the content-addressed store, hash-verified

238 * @return A succeeded (the requested bridge is available) or failed (it cannot be built) command.
239 */
240CommandCost CheckBridgeAvailability(BridgeType bridge_type, uint bridge_len, DoCommandFlags flags)
241{
242 if (flags.Test(DoCommandFlag::QueryCost)) {
243 if (bridge_len <= _settings_game.construction.max_bridge_length) return CommandCost();
244 return CommandCost(STR_ERROR_BRIDGE_TOO_LONG);
245 }
246
247 if (bridge_type >= MAX_BRIDGES) return CMD_ERROR;
248
249 const BridgeSpec *b = GetBridgeSpec(bridge_type);
250 if (b->avail_year > TimerGameCalendar::year) return CMD_ERROR;
251
252 uint max = std::min(b->max_length, _settings_game.construction.max_bridge_length);
253
254 if (b->min_length > bridge_len) return CMD_ERROR;
255 if (bridge_len <= max) return CommandCost();
256 return CommandCost(STR_ERROR_BRIDGE_TOO_LONG);
257}
258
259/**
260 * Calculate the base cost of clearing a tunnel/bridge per tile.

Callers 2

CmdBuildBridgeFunction · 0.85
ShowBuildBridgeWindowFunction · 0.85

Calls 3

CommandCostClass · 0.85
GetBridgeSpecFunction · 0.85
TestMethod · 0.80

Tested by

no test coverage detected