(svn r19402) -Codechange: CheckAllowRemoveRoad() returns a CommandCost.

This commit is contained in:
alberth 2010-03-13 15:53:44 +00:00
parent 9e27194651
commit 7e1a91db21
3 changed files with 19 additions and 25 deletions

View File

@ -115,34 +115,37 @@ static Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
* @param rt the road type to remove the bits from * @param rt the road type to remove the bits from
* @param flags command flags * @param flags command flags
* @param town_check Shall the town rating checked/affected * @param town_check Shall the town rating checked/affected
* @return true when it is allowed to remove the road bits * @return A succeeded command when it is allowed to remove the road bits, a failed command otherwise.
*/ */
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check) CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check)
{ {
if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return true; if (_game_mode == GM_EDITOR || remove == ROAD_NONE) return CommandCost();
/* Water can always flood and towns can always remove "normal" road pieces. /* Water can always flood and towns can always remove "normal" road pieces.
* Towns are not be allowed to remove non "normal" road pieces, like tram * Towns are not be allowed to remove non "normal" road pieces, like tram
* tracks as that would result in trams that cannot turn. */ * tracks as that would result in trams that cannot turn. */
if (_current_company == OWNER_WATER || if (_current_company == OWNER_WATER ||
(rt == ROADTYPE_ROAD && !Company::IsValidID(_current_company))) return true; (rt == ROADTYPE_ROAD && !Company::IsValidID(_current_company))) return CommandCost();
/* Only do the special processing if the road is owned /* Only do the special processing if the road is owned
* by a town */ * by a town */
if (owner != OWNER_TOWN) return (owner == OWNER_NONE) || CheckOwnership(owner); if (owner != OWNER_TOWN) {
if (owner == OWNER_NONE) return CommandCost();
return CheckOwnership(owner) ? CommandCost() : CMD_ERROR;
}
if (!town_check) return true; if (!town_check) return CommandCost();
if (_cheats.magic_bulldozer.value) return true; if (_cheats.magic_bulldozer.value) return CommandCost();
Town *t = ClosestTownFromTile(tile, UINT_MAX); Town *t = ClosestTownFromTile(tile, UINT_MAX);
if (t == NULL) return true; if (t == NULL) return CommandCost();
/* check if you're allowed to remove the street owned by a town /* check if you're allowed to remove the street owned by a town
* removal allowance depends on difficulty setting */ * removal allowance depends on difficulty setting */
CommandCost ret = CheckforTownRating(flags, t, ROAD_REMOVE); CommandCost ret = CheckforTownRating(flags, t, ROAD_REMOVE);
ret.SetGlobalErrorMessage(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return false; if (ret.Failed()) return ret;
/* Get a bitmask of which neighbouring roads has a tile */ /* Get a bitmask of which neighbouring roads has a tile */
RoadBits n = ROAD_NONE; RoadBits n = ROAD_NONE;
@ -159,14 +162,13 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType
/* you can remove all kind of roads with extra dynamite */ /* you can remove all kind of roads with extra dynamite */
if (!_settings_game.construction.extra_dynamite) { if (!_settings_game.construction.extra_dynamite) {
SetDParam(0, t->index); SetDParam(0, t->index);
_error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS; return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
return false;
} }
rating_decrease = RATING_ROAD_DOWN_STEP_INNER; rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
} }
ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags); ChangeTownRating(t, rating_decrease, RATING_ROAD_MINIMUM, flags);
return true; return CommandCost();
} }
@ -210,7 +212,9 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
return CMD_ERROR; return CMD_ERROR;
} }
if (!CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rt), rt, flags, town_check)) return CMD_ERROR; CommandCost ret = CheckAllowRemoveRoad(tile, pieces, GetRoadOwner(tile, rt), rt, flags, town_check);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
if (!IsTileType(tile, MP_ROAD)) { if (!IsTileType(tile, MP_ROAD)) {
/* If it's the last roadtype, just clear the whole tile */ /* If it's the last roadtype, just clear the whole tile */

View File

@ -23,17 +23,7 @@
*/ */
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb); RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb);
/** CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check = true);
* Is it allowed to remove the given road bits from the given tile?
* @param tile the tile to remove the road from
* @param remove the roadbits that are going to be removed
* @param owner the actual owner of the roadbits of the tile
* @param rt the road type to remove the bits from
* @param flags command flags
* @param town_check Shall the town rating checked/affected
* @return true when it is allowed to remove the road bits
*/
bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check = true);
/** /**
* Draw the catenary for tram road bits * Draw the catenary for tram road bits

View File

@ -3443,7 +3443,7 @@ static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
if ((road_owner != OWNER_TOWN && !CheckOwnership(road_owner)) || !CheckOwnership(tram_owner)) return false; if ((road_owner != OWNER_TOWN && !CheckOwnership(road_owner)) || !CheckOwnership(tram_owner)) return false;
return road_owner != OWNER_TOWN || CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags); return road_owner != OWNER_TOWN || CheckAllowRemoveRoad(tile, GetAnyRoadBits(tile, ROADTYPE_ROAD), OWNER_TOWN, ROADTYPE_ROAD, flags).Succeeded();
} }
CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags) CommandCost ClearTile_Station(TileIndex tile, DoCommandFlag flags)