(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.

pull/155/head
frosch 16 years ago
parent 0c23420998
commit b58cdfc294

@ -921,7 +921,7 @@ static void GetStationLayout(byte *layout, int numtracks, int plat_len, const St
CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint32 p2, const char *text)
{
/* Does the authority allow this? */
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile_org)) return CMD_ERROR;
if (!CheckIfAuthorityAllowsNewStation(tile_org, flags)) return CMD_ERROR;
if (!ValParamRailtype((RailType)(p1 & 0xF))) return CMD_ERROR;
/* unpack parameters */
@ -1437,7 +1437,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2,
/* Road bits in the wrong direction */
if (build_over_road && (GetAllRoadBits(tile) & ((Axis)p1 == AXIS_X ? ROAD_Y : ROAD_X)) != 0) return_cmd_error(STR_DRIVE_THROUGH_ERROR_DIRECTION);
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
RoadTypes cur_rts = IsNormalRoadTile(tile) ? GetRoadTypes(tile) : ROADTYPES_NONE;
uint num_roadbits = 0;
@ -1856,7 +1856,7 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2,
/* Check if a valid, buildable airport was chosen for construction */
if (p1 > lengthof(_airport_sections) || !HasBit(GetValidAirports(), p1)) return CMD_ERROR;
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) {
if (!CheckIfAuthorityAllowsNewStation(tile, flags)) {
return CMD_ERROR;
}
@ -2174,7 +2174,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, con
/* Docks cannot be placed on rapids */
if (IsWaterTile(tile)) return_cmd_error(STR_304B_SITE_UNSUITABLE);
if (!(flags & DC_NO_TOWN_RATING) && !CheckIfAuthorityAllows(tile)) return CMD_ERROR;
if (!CheckIfAuthorityAllowsNewStation(tile, flags)) return CMD_ERROR;
if (MayHaveBridgeAbove(tile) && IsBridgeAbove(tile)) return_cmd_error(STR_5007_MUST_DEMOLISH_BRIDGE_FIRST);

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

@ -2445,9 +2445,14 @@ static void UpdateTownUnwanted(Town *t)
}
}
bool CheckIfAuthorityAllows(TileIndex 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 flags Command flags. DC_NO_TOWN_RATING is tested.
*/
bool CheckIfAuthorityAllowsNewStation(TileIndex tile, uint32 flags)
{
if (!IsValidCompanyID(_current_company)) return true;
if (!IsValidCompanyID(_current_company) || (flags & DC_NO_TOWN_RATING)) return true;
Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
if (t == NULL) return true;

Loading…
Cancel
Save