175 TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ |
175 TileInfo ti_start, ti_end, ti; /* OPT: only 2 of those are ever used */ |
176 int bridge_len, odd_middle_part; |
176 int bridge_len, odd_middle_part; |
177 uint direction; |
177 uint direction; |
178 int i; |
178 int i; |
179 int32 cost, terraformcost, ret; |
179 int32 cost, terraformcost, ret; |
|
180 bool allow_on_slopes; |
180 |
181 |
181 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
182 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
182 |
183 |
183 /* unpack parameters */ |
184 /* unpack parameters */ |
184 bridge_type = p2 & 0xFF; |
185 bridge_type = p2 & 0xFF; |
238 if (ti_start.z != ti_end.z) |
239 if (ti_start.z != ti_end.z) |
239 return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
240 return_cmd_error(STR_5009_LEVEL_LAND_OR_WATER_REQUIRED); |
240 |
241 |
241 _error_message = STR_500C; |
242 _error_message = STR_500C; |
242 |
243 |
243 /* try and clear the start landscape */ |
244 |
244 if ((ret=DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) |
245 // Towns are not allowed to use bridges on slopes. |
|
246 allow_on_slopes = ((!_is_ai_player || _patches.ainew_active) |
|
247 && _current_player != OWNER_TOWN |
|
248 && _patches.build_on_slopes); |
|
249 |
|
250 /* Try and clear the start landscape */ |
|
251 |
|
252 if ((ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) |
245 return CMD_ERROR; |
253 return CMD_ERROR; |
246 cost = ret; |
254 cost = ret; |
247 |
255 |
248 terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); // true - bridge-start-tile, false - bridge-end-tile |
256 // true - bridge-start-tile, false - bridge-end-tile |
249 |
257 terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); |
250 // towns are not allowed to use bridges on slopes. |
258 if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
251 if (terraformcost == CMD_ERROR || |
|
252 (terraformcost && ((!_patches.ainew_active && _is_ai_player) || _current_player == OWNER_TOWN || !_patches.build_on_slopes))) |
|
253 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
259 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
254 |
|
255 cost += terraformcost; |
260 cost += terraformcost; |
256 |
261 |
257 /* try and clear the end landscape */ |
262 /* Try and clear the end landscape */ |
|
263 |
258 if ((ret=DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) |
264 if ((ret=DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) |
259 return CMD_ERROR; |
265 return CMD_ERROR; |
260 cost += ret; |
266 cost += ret; |
261 |
267 |
262 terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); // false - end tile slope check |
268 // false - end tile slope check |
263 |
269 terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); |
264 // towns are not allowed to use bridges on slopes. |
270 if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes)) |
265 if (terraformcost == CMD_ERROR || |
|
266 (terraformcost && ((!_patches.ainew_active && _is_ai_player) || _current_player == OWNER_TOWN || !_patches.build_on_slopes))) |
|
267 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
271 return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); |
268 |
|
269 cost += terraformcost; |
272 cost += terraformcost; |
|
273 |
270 |
274 |
271 /* do the drill? */ |
275 /* do the drill? */ |
272 if (flags & DC_EXEC) { |
276 if (flags & DC_EXEC) { |
273 /* build the start tile */ |
277 /* build the start tile */ |
274 ModifyTile(ti_start.tile, |
278 ModifyTile(ti_start.tile, |