1
0
Fork 0

(svn r2089) - Codechange: Simplify slopes check in CmdBuildBridge(). Inspired by st3wis' patch 1144746.

release/0.4.5
pasky 2005-03-27 15:56:54 +00:00
parent 04dc6441aa
commit aafb136cd0
1 changed files with 19 additions and 15 deletions

View File

@ -177,6 +177,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
uint direction; uint direction;
int i; int i;
int32 cost, terraformcost, ret; int32 cost, terraformcost, ret;
bool allow_on_slopes;
SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@ -240,34 +241,37 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_error_message = STR_500C; _error_message = STR_500C;
/* try and clear the start landscape */
if ((ret=DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) // Towns are not allowed to use bridges on slopes.
allow_on_slopes = ((!_is_ai_player || _patches.ainew_active)
&& _current_player != OWNER_TOWN
&& _patches.build_on_slopes);
/* Try and clear the start landscape */
if ((ret = DoCommandByTile(ti_start.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR)
return CMD_ERROR; return CMD_ERROR;
cost = ret; cost = ret;
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true); // true - bridge-start-tile, false - bridge-end-tile // true - bridge-start-tile, false - bridge-end-tile
terraformcost = CheckBridgeSlope(direction, ti_start.tileh, true);
// towns are not allowed to use bridges on slopes. if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes))
if (terraformcost == CMD_ERROR ||
(terraformcost && ((!_patches.ainew_active && _is_ai_player) || _current_player == OWNER_TOWN || !_patches.build_on_slopes)))
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
cost += terraformcost; cost += terraformcost;
/* try and clear the end landscape */ /* Try and clear the end landscape */
if ((ret=DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR) if ((ret=DoCommandByTile(ti_end.tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR)) == CMD_ERROR)
return CMD_ERROR; return CMD_ERROR;
cost += ret; cost += ret;
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false); // false - end tile slope check // false - end tile slope check
terraformcost = CheckBridgeSlope(direction, ti_end.tileh, false);
// towns are not allowed to use bridges on slopes. if (terraformcost == CMD_ERROR || (terraformcost && !allow_on_slopes))
if (terraformcost == CMD_ERROR ||
(terraformcost && ((!_patches.ainew_active && _is_ai_player) || _current_player == OWNER_TOWN || !_patches.build_on_slopes)))
return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION); return_cmd_error(STR_1000_LAND_SLOPED_IN_WRONG_DIRECTION);
cost += terraformcost; cost += terraformcost;
/* do the drill? */ /* do the drill? */
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
/* build the start tile */ /* build the start tile */