(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.

This commit is contained in:
alberth 2010-02-27 17:42:55 +00:00
parent e338c26504
commit 566f87b2de
3 changed files with 24 additions and 18 deletions

View File

@ -1095,7 +1095,10 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
StationID station_to_join = GB(p2, 16, 16); StationID station_to_join = GB(p2, 16, 16);
/* Does the authority allow this? */ /* 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; if (!ValParamRailtype(rt)) return CMD_ERROR;
/* Check if the given station class is valid */ /* 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); cost.AddCost((numtracks * _price[PR_BUILD_STATION_RAIL] + _price[PR_BUILD_STATION_RAIL_LENGTH]) * plat_len);
Station *st = NULL; 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(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret; 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 it is a drive-through stop, check for valid axis. */
if (is_drive_through && !IsValidAxis((Axis)ddir)) return CMD_ERROR; 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. */ /* Total road stop cost. */
CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]); CommandCost cost(EXPENSES_CONSTRUCTION, roadstop_area.w * roadstop_area.h * _price[type ? PR_BUILD_STATION_TRUCK : PR_BUILD_STATION_BUS]);
StationID est = INVALID_STATION; 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; if (ret.Failed()) return ret;
cost.AddCost(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 (p1 >= NUM_AIRPORTS) return CMD_ERROR;
if (!CheckIfAuthorityAllowsNewStation(tile, flags)) { CommandCost ret = CheckIfAuthorityAllowsNewStation(tile, flags);
return CMD_ERROR; ret.SetGlobalErrorMessage();
} if (ret.Failed()) return ret;
/* Check if a valid, buildable airport was chosen for construction */ /* Check if a valid, buildable airport was chosen for construction */
const AirportSpec *as = AirportSpec::Get(p1); const AirportSpec *as = AirportSpec::Get(p1);
@ -2107,7 +2112,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} }
Station *st = NULL; 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(); ret.SetGlobalErrorMessage();
if (ret.Failed()) return ret; if (ret.Failed()) return ret;
@ -2326,7 +2331,9 @@ CommandCost CmdBuildDock(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
/* Docks cannot be placed on rapids */ /* Docks cannot be placed on rapids */
if (IsWaterTile(tile)) return_cmd_error(STR_ERROR_SITE_UNSUITABLE); 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); 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 */ /* middle */
Station *st = NULL; 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]), TileArea(tile + ToTileIndexDiff(_dock_tileoffs_chkaround[direction]),
_dock_w_chk[direction], _dock_h_chk[direction]), &st); _dock_w_chk[direction], _dock_h_chk[direction]), &st);
ret.SetGlobalErrorMessage(); ret.SetGlobalErrorMessage();

View File

@ -191,7 +191,7 @@ void ResetHouses();
void ClearTownHouse(Town *t, TileIndex tile); void ClearTownHouse(Town *t, TileIndex tile);
void UpdateTownMaxPass(Town *t); void UpdateTownMaxPass(Town *t);
void UpdateTownRadius(Town *t); void UpdateTownRadius(Town *t);
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags); CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags);
Town *ClosestTownFromTile(TileIndex tile, uint threshold); Town *ClosestTownFromTile(TileIndex tile, uint threshold);
void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags); void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags);
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile); HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);

View File

@ -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 * 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 tile The tile where the station shall be constructed.
* @param flags Command flags. DC_NO_TEST_TOWN_RATING is tested. * @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); 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); SetDParam(0, t->index);
return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
return false;
} }