From f5cff712844a1fe853b750cba242f04b4e960c0e Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 11 Jan 2009 14:26:11 +0000 Subject: [PATCH] (svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code. --- src/station_cmd.cpp | 8 ++++---- src/town.h | 2 +- src/town_cmd.cpp | 9 +++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f9d8d2bddf..e7a792c9af 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -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); diff --git a/src/town.h b/src/town.h index e3c7d6f8ed..91d83271c8 100644 --- a/src/town.h +++ b/src/town.h @@ -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); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 1546f8cb3c..429aeec50d 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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;