summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2009-01-11 14:26:11 +0000
committerfrosch <frosch@openttd.org>2009-01-11 14:26:11 +0000
commitb58cdfc2942f07f231c1ee175b4a114ac6bf35ed (patch)
tree249698a6ee162bfe2dd153377c44d153495e1d6d
parent0c234209985458a8d3233dbf42d0a0e49457bf18 (diff)
downloadopenttd-b58cdfc2942f07f231c1ee175b4a114ac6bf35ed.tar.xz
(svn r14992) -Codechange: Rename 'CheckIfAuthorityAllows' to 'CheckIfAuthorityAllowsNewStation' and unduplicate a tiny bit of code.
-rw-r--r--src/station_cmd.cpp8
-rw-r--r--src/town.h2
-rw-r--r--src/town_cmd.cpp9
3 files changed, 12 insertions, 7 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index f9d8d2bdd..e7a792c9a 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 e3c7d6f8e..91d83271c 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 1546f8cb3..429aeec50 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;