summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-02-27 17:42:55 +0000
committeralberth <alberth@openttd.org>2010-02-27 17:42:55 +0000
commit566f87b2deca7c08582e0ed59d173b9c71304e0b (patch)
tree4af48cec0b1bdd5694716d30717a78415caf1163 /src
parente338c26504680156df196c10279c05342a2b76f6 (diff)
downloadopenttd-566f87b2deca7c08582e0ed59d173b9c71304e0b.tar.xz
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
Diffstat (limited to 'src')
-rw-r--r--src/station_cmd.cpp27
-rw-r--r--src/town.h2
-rw-r--r--src/town_cmd.cpp13
3 files changed, 24 insertions, 18 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index 90b443661..337c7bad8 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -1095,7 +1095,10 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
StationID station_to_join = GB(p2, 16, 16);
/* Does the authority allow this? */
- if (!CheckIfAuthorityAllowsNewStation(tile_org, flags)) return CMD_ERROR;
+ CommandCost ret = CheckIfAuthorityAllowsNewStation(tile_org, flags);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
+
if (!ValParamRailtype(rt)) return CMD_ERROR;
/* Check if the given station class is valid */
@@ -1132,7 +1135,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
Station *st = NULL;
- CommandCost ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
+ ret = FindJoiningStation(est, station_to_join, adjacent, new_location, &st);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
@@ -1688,12 +1691,14 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
/* If it is a drive-through stop, check for valid axis. */
if (is_drive_through && !IsValidAxis((Axis)ddir)) return CMD_ERROR;
- if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
+ CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
/* Total road stop cost. */
CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
StationID est = INVALID_STATION;
- CommandCost ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << ddir : 1 << ddir, is_drive_through, type, DiagDirToAxis(ddir), &est, rts);
+ ret = CheckFlatLandRoadStop(roadstop_area, flags, is_drive_through ? 5 << ddir : 1 << ddir, is_drive_through, type, DiagDirToAxis(ddir), &est, rts);
if (ret.Failed()) return ret;
cost.AddCost(ret);
@@ -2059,9 +2064,9 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
if (p1 >= NUM_AIRPORTS) return CMD_ERROR;
- if (!CheckIfAuthorityAllowsNewStation(tile, flags)) {
- return CMD_ERROR;
- }
+ CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
/* Check if a valid, buildable airport was chosen for construction */
const AirportSpec *as = AirportSpec::Get(p1);
@@ -2107,7 +2112,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
}
Station *st = NULL;
- CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), TileArea(tile, w, h), &st);
+ ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p2, 0), TileArea(tile, w, h), &st);
ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret;
@@ -2326,7 +2331,9 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Docks cannot be placed on rapids */
if (IsWaterTile(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
- if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
+ CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
+ ret.SetGlobalErrorMessage();
+ if (ret.Failed()) return ret;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
@@ -2352,7 +2359,7 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* middle */
Station *st = NULL;
- CommandCost ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0),
+ ret = FindJoiningStation(INVALID_STATION, station_to_join, HasBit(p1, 0),
TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
_dock_w_chk[direction], _dock_h_chk[direction]), &st);
ret.SetGlobalErrorMessage();
diff --git a/src/town.h b/src/town.h
index 284026fd6..cbd95cbe1 100644
--- a/src/town.h
+++ b/src/town.h
@@ -191,7 +191,7 @@ void ResetHouses();
void ClearTownHouse(Town *t, TileIndex tile);
void UpdateTownMaxPass(Town *t);
void UpdateTownRadius(Town *t);
-bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
+CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 7543c63e0..28c2fe032 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2662,20 +2662,19 @@ static void UpdateTownUnwanted(Town *t)
* Checks whether the local authority allows construction of a new station (rail, road, airport, dock) on the given tile
* @param tile The tile where the station shall be constructed.
* @param flags Command flags. DC_NO_TEST_TOWN_RATING is tested.
+ * @return Succeeded or failed command.
*/
-bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
+CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags)
{
- if (!Company::IsValidID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) return true;
+ if (!Company::IsValidID(_current_company) || (flags & DC_NO_TEST_TOWN_RATING)) return CommandCost();
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
- if (t == NULL) return true;
+ if (t == NULL) return CommandCost();
- if (t->ratings[_current_company] > RATING_VERYPOOR) return true;
+ if (t->ratings[_current_company] > RATING_VERYPOOR) return CommandCost();
- _error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS;
SetDParam(0, t->index);
-
- return false;
+ return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
}