Changeset - r14686:c8f1a9222c1c
[Not reviewed]
master
0 3 0
alberth - 15 years ago 2010-02-27 17:42:55
alberth@openttd.org
(svn r19279) -Codechange: CheckIfAuthorityAllowsNewStation() returns CommandCost.
3 files changed with 26 insertions and 20 deletions:
0 comments (0 inline, 0 general)
src/station_cmd.cpp
Show inline comments
 
@@ -1092,13 +1092,16 @@ CommandCost CmdBuildRailStation(TileInde
 

	
 
	StationClassID spec_class = (StationClassID)GB(p2, 0, 8);
 
	byte spec_index           = GB(p2, 8, 8);
 
	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 */
 
	if ((uint)spec_class >= GetNumStationClasses()) return CMD_ERROR;
 
	if (spec_index >= GetNumCustomStations(spec_class)) return CMD_ERROR;
 
	if (plat_len == 0 || numtracks == 0) return CMD_ERROR;
 
@@ -1129,13 +1132,13 @@ CommandCost CmdBuildRailStation(TileInde
 
	CommandCost cost = CheckFlatLandRailStation(TileArea(tile_org, w_org, h_org), flags, 5 << axis, _settings_game.station.nonuniform_stations ? &est : NULL, rt);
 
	if (cost.Failed()) return cost;
 
	/* Add construction expenses. */
 
	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;
 

	
 
	/* See if there is a deleted station close to us. */
 
	if (st == NULL && reuse) st = GetClosestDeletedStation(tile_org);
 

	
 
@@ -1685,18 +1688,20 @@ CommandCost CmdBuildRoadStop(TileIndex t
 

	
 
	/* Safeguard the parameters. */
 
	if (!IsValidDiagDirection(ddir)) return CMD_ERROR;
 
	/* 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);
 

	
 
	Station *st = NULL;
 
	ret = FindJoiningRoadStop(est, station_to_join, HasBit(p2, 5), roadstop_area, &st);
 
	ret.SetGlobalErrorMessage();
 
@@ -2056,15 +2061,15 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	bool distant_join = (station_to_join != INVALID_STATION);
 

	
 
	if (distant_join && (!_settings_game.station.distant_join_stations || !Station::IsValidID(station_to_join))) return CMD_ERROR;
 

	
 
	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);
 
	if (!as->IsAvailable()) return CMD_ERROR;
 

	
 
	Town *t = ClosestTownFromTile(tile, UINT_MAX);
 
@@ -2104,13 +2109,13 @@ CommandCost CmdBuildAirport(TileIndex ti
 
	if (authority_refuse_message != STR_NULL) {
 
		SetDParam(0, t->index);
 
		return_cmd_error(authority_refuse_message);
 
	}
 

	
 
	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;
 

	
 
	/* Distant join */
 
	if (st == NULL && distant_join) st = Station::GetIfValid(station_to_join);
 

	
 
@@ -2323,13 +2328,15 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	if (direction == INVALID_DIAGDIR) return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	direction = ReverseDiagDir(direction);
 

	
 
	/* 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);
 

	
 
	if (DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR).Failed()) return CMD_ERROR;
 

	
 
	TileIndex tile_cur = tile + TileOffsByDiagDir(direction);
 
@@ -2349,13 +2356,13 @@ CommandCost CmdBuildDock(TileIndex tile,
 
	if (!IsTileType(tile_cur, MP_WATER) || GetTileSlope(tile_cur, NULL) != SLOPE_FLAT) {
 
		return_cmd_error(STR_ERROR_SITE_UNSUITABLE);
 
	}
 

	
 
	/* 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();
 
	if (ret.Failed()) return ret;
 

	
 
	/* Distant join */
src/town.h
Show inline comments
 
@@ -188,13 +188,13 @@ Town *CalcClosestTownFromTile(TileIndex 
 

	
 
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);
 
void SetTownRatingTestMode(bool mode);
 
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
 
bool GenerateTowns(TownLayout layout);
src/town_cmd.cpp
Show inline comments
 
@@ -2659,26 +2659,25 @@ 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->ratings[_current_company] > RATING_VERYPOOR) return true;
 

	
 
	_error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS;
 
	if (t == NULL) return CommandCost();
 

	
 
	if (t->ratings[_current_company] > RATING_VERYPOOR) return CommandCost();
 

	
 
	SetDParam(0, t->index);
 

	
 
	return false;
 
	return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS);
 
}
 

	
 

	
 
Town *CalcClosestTownFromTile(TileIndex tile, uint threshold)
 
{
 
	Town *t;
0 comments (0 inline, 0 general)