summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-03-13 15:53:44 +0000
committeralberth <alberth@openttd.org>2010-03-13 15:53:44 +0000
commit7e1a91db21e554b1518944b5523ce997b96eb622 (patch)
treeadea3561ea55aa1f5da06c6a3e47b6cf46cc9343
parent9e27194651152a3bbc1cb96cb327564767c56bca (diff)
downloadopenttd-7e1a91db21e554b1518944b5523ce997b96eb622.tar.xz
(svn r19402) -Codechange: CheckAllowRemoveRoad() returns a CommandCost.
-rw-r--r--src/road_cmd.cpp30
-rw-r--r--src/road_internal.h12
-rw-r--r--src/station_cmd.cpp2
3 files changed, 19 insertions, 25 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 5d83abeef..b58c552f8 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -115,34 +115,37 @@ static Foundation GetRoadFoundation(Slope tileh, RoadBits bits);
* @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
+ * @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.
* Towns are not be allowed to remove non "normal" road pieces, like tram
* tracks as that would result in trams that cannot turn. */
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
* 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);
- if (t == NULL) return true;
+ if (t == NULL) return CommandCost();
/* check if you're allowed to remove the street owned by a town
* removal allowance depends on difficulty setting */
CommandCost ret = CheckforTownRating(flags, t, ROAD_REMOVE);
ret.SetGlobalErrorMessage();
- if (ret.Failed()) return false;
+ if (ret.Failed()) return ret;
/* Get a bitmask of which neighbouring roads has a tile */
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 */
if (!_settings_game.construction.extra_dynamite) {
SetDParam(0, t->index);
- _error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS;
- return false;
+ return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
}
rating_decrease = RATING_ROAD_DOWN_STEP_INNER;
}
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;
}
- 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 it's the last roadtype, just clear the whole tile */
diff --git a/src/road_internal.h b/src/road_internal.h
index 6b0d8c8d4..0a6c02202 100644
--- a/src/road_internal.h
+++ b/src/road_internal.h
@@ -23,17 +23,7 @@
*/
RoadBits CleanUpRoadBits(const TileIndex tile, RoadBits org_rb);
-/**
- * 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);
+CommandCost CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType rt, DoCommandFlag flags, bool town_check = true);
/**
* Draw the catenary for tram road bits
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 57c533bcb..3747ae5e1 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -3443,7 +3443,7 @@ static bool CanRemoveRoadWithStop(TileIndex tile, DoCommandFlag flags)
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)