* 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. */
| 238 | * @return A succeeded (the requested bridge is available) or failed (it cannot be built) command. |
| 239 | */ |
| 240 | CommandCost 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. |
no test coverage detected