271 if (!CheckTrackCombination(tile, trackbit, flags) || |
271 if (!CheckTrackCombination(tile, trackbit, flags) || |
272 !EnsureNoVehicle(tile)) { |
272 !EnsureNoVehicle(tile)) { |
273 return CMD_ERROR; |
273 return CMD_ERROR; |
274 } |
274 } |
275 if (!IsTileOwner(tile, _current_player) || |
275 if (!IsTileOwner(tile, _current_player) || |
276 GetRailType(tile) != p1) { |
276 !IsCompatibleRail(GetRailType(tile), p1)) { |
277 // Get detailed error message |
277 // Get detailed error message |
278 return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
278 return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
279 } |
279 } |
280 |
280 |
281 ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile); |
281 ret = CheckRailSlope(tileh, trackbit, GetTrackBits(tile), tile); |
282 if (CmdFailed(ret)) return ret; |
282 if (CmdFailed(ret)) return ret; |
283 cost += ret; |
283 cost += ret; |
|
284 |
|
285 /* XXX Assume a 'higher' railtype has preference. This means we |
|
286 * will convert from normal rail to electrified rail, but not |
|
287 * the other way around. */ |
|
288 if (GetRailType(tile) < p1) { |
|
289 ret = DoCommand(tile, tile, p1, flags, CMD_CONVERT_RAIL); |
|
290 if (CmdFailed(ret)) return ret; |
|
291 cost += ret; |
|
292 } |
284 |
293 |
285 if (flags & DC_EXEC) { |
294 if (flags & DC_EXEC) { |
286 SetRailGroundType(tile, RAIL_GROUND_BARREN); |
295 SetRailGroundType(tile, RAIL_GROUND_BARREN); |
287 _m[tile].m5 |= trackbit; |
296 _m[tile].m5 |= trackbit; |
288 } |
297 } |