Changeset - r14774:6075f6397e6f
[Not reviewed]
master
0 7 0
alberth - 15 years ago 2010-03-07 20:44:05
alberth@openttd.org
(svn r19372) -Codechange: CheckTileOwnership() returns a CommandCost.
7 files changed with 74 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/company_cmd.cpp
Show inline comments
 
@@ -266,20 +266,19 @@ bool CheckOwnership(Owner owner, TileInd
 
 * the given tile.  If that isn't the case an
 
 * appropriate error will be given.
 
 * @param tile the tile to check.
 
 * @return true iff it's owned by the current company.
 
 * @return A succeeded command iff it's owned by the current company, else a failed command.
 
 */
 
bool CheckTileOwnership(TileIndex tile)
 
CommandCost CheckTileOwnership(TileIndex tile)
 
{
 
	Owner owner = GetTileOwner(tile);
 

	
 
	assert(owner < OWNER_END);
 

	
 
	if (owner == _current_company) return true;
 
	_error_message = STR_ERROR_OWNED_BY;
 
	if (owner == _current_company) return CommandCost();
 

	
 
	/* no need to get the name of the owner unless we're the local company (saves some time) */
 
	if (IsLocalCompany()) GetNameOfOwner(owner, tile);
 
	return false;
 
	return_cmd_error(STR_ERROR_OWNED_BY);
 
}
 

	
 
static void GenerateCompanyName(Company *c)
src/functions.h
Show inline comments
 
@@ -25,7 +25,7 @@ bool CheckCompanyHasMoney(CommandCost &c
 
void SubtractMoneyFromCompany(CommandCost cost);
 
void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost);
 
bool CheckOwnership(Owner owner, TileIndex tile = 0);
 
bool CheckTileOwnership(TileIndex tile);
 
CommandCost CheckTileOwnership(TileIndex tile);
 

	
 
/* misc functions */
 
/**
src/rail_cmd.cpp
Show inline comments
 
@@ -366,13 +366,15 @@ CommandCost CmdBuildSingleRail(TileIndex
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_RAILWAY: {
 
			if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
			CommandCost ret = CheckTileOwnership(tile);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (!IsPlainRail(tile)) return CMD_ERROR;
 

	
 
			if (!IsCompatibleRail(GetRailType(tile), railtype)) return_cmd_error(STR_ERROR_IMPOSSIBLE_TRACK_COMBINATION);
 

	
 
			CommandCost ret = CheckTrackCombination(tile, trackbit, flags);
 
			ret = CheckTrackCombination(tile, trackbit, flags);
 
			if (ret.Succeeded()) ret = EnsureNoTrainOnTrack(tile, track);
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 
@@ -514,11 +516,14 @@ CommandCost CmdRemoveSingleRail(TileInde
 

	
 
	switch (GetTileType(tile)) {
 
		case MP_ROAD: {
 
			if (!IsLevelCrossing(tile) ||
 
					GetCrossingRailBits(tile) != trackbit ||
 
					(_current_company != OWNER_WATER && !CheckTileOwnership(tile))) {
 
				return CMD_ERROR;
 
			if (!IsLevelCrossing(tile) || GetCrossingRailBits(tile) != trackbit) return CMD_ERROR;
 

	
 
			if (_current_company != OWNER_WATER) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				ret.SetGlobalErrorMessage();
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (!(flags & DC_BANKRUPT)) {
 
				CommandCost ret = EnsureNoVehicleOnGround(tile);
 
				ret.SetGlobalErrorMessage();
 
@@ -539,7 +544,13 @@ CommandCost CmdRemoveSingleRail(TileInde
 
		case MP_RAILWAY: {
 
			TrackBits present;
 

	
 
			if (!IsPlainRail(tile) || (_current_company != OWNER_WATER && !CheckTileOwnership(tile))) return CMD_ERROR;
 
			if (!IsPlainRail(tile)) return CMD_ERROR;
 

	
 
			if (_current_company != OWNER_WATER) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				ret.SetGlobalErrorMessage();
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			CommandCost ret = EnsureNoTrainOnTrack(tile, track);
 
			ret.SetGlobalErrorMessage();
 
@@ -906,7 +917,9 @@ CommandCost CmdBuildSingleSignal(TileInd
 
	/* Protect against invalid signal copying */
 
	if (p2 != 0 && (p2 & SignalOnTrack(track)) == 0) return CMD_ERROR;
 

	
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 
	ret = CheckTileOwnership(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	{
 
		/* See if this is a valid track combination for signals, (ie, no overlap) */
 
@@ -1265,7 +1278,11 @@ CommandCost CmdRemoveSingleSignal(TileIn
 
	if (ret.Failed()) return ret;
 

	
 
	/* Only water can remove signals from anyone */
 
	if (_current_company != OWNER_WATER && !CheckTileOwnership(tile)) return CMD_ERROR;
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* Do it? */
 
	if (flags & DC_EXEC) {
 
@@ -1398,7 +1415,11 @@ CommandCost CmdConvertRail(TileIndex til
 
			if (type == totype || (_settings_game.vehicle.disable_elrails && totype == RAILTYPE_RAIL && type == RAILTYPE_ELECTRIC)) continue;
 

	
 
			/* Trying to convert other's rail */
 
			if (!CheckTileOwnership(tile)) continue;
 
			CommandCost ret = CheckTileOwnership(tile);
 
			if (ret.Failed()) {
 
				ret.SetGlobalErrorMessage();
 
				continue;
 
			}
 

	
 
			SmallVector<Train *, 2> vehicles_affected;
 

	
 
@@ -1527,8 +1548,11 @@ CommandCost CmdConvertRail(TileIndex til
 

	
 
static CommandCost RemoveTrainDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER)
 
		return CMD_ERROR;
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
src/road_cmd.cpp
Show inline comments
 
@@ -911,7 +911,11 @@ CommandCost CmdBuildRoadDepot(TileIndex 
 

	
 
static CommandCost RemoveRoadDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -587,7 +587,9 @@ static inline bool CheckAllowRemoveTunne
 
			if (HasBit(rts, ROADTYPE_TRAM)) tram_owner = GetRoadOwner(tile, ROADTYPE_TRAM);
 

	
 
			/* We can remove unowned road and if the town allows it */
 
			if (road_owner == OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) return CheckTileOwnership(tile);
 
			if (road_owner == OWNER_TOWN && !(_settings_game.construction.extra_dynamite || _cheats.magic_bulldozer.value)) {
 
				return CheckTileOwnership(tile).Succeeded();
 
			}
 
			if (road_owner == OWNER_NONE || road_owner == OWNER_TOWN) road_owner = _current_company;
 
			if (tram_owner == OWNER_NONE) tram_owner = _current_company;
 

	
src/unmovable_cmd.cpp
Show inline comments
 
@@ -175,7 +175,11 @@ CommandCost CmdPurchaseLandArea(TileInde
 
CommandCost CmdSellLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 
{
 
	if (!IsOwnedLandTile(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR;
 
	if (_current_company != OWNER_WATER) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret.SetGlobalErrorMessage();
 
@@ -500,7 +504,11 @@ static void ChangeTileOwner_Unmovable(Ti
 
static CommandCost TerraformTile_Unmovable(TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
 
{
 
	/* Owned land remains unsold */
 
	if (IsOwnedLand(tile) && CheckTileOwnership(tile)) return CommandCost();
 
	if (IsOwnedLand(tile)) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Succeeded()) return CommandCost();
 
	}
 

	
 
	if (AutoslopeEnabled() && (IsStatue(tile) || IsCompanyHQ(tile))) {
 
		if (!IsSteepSlope(tileh_new) && (z_new + GetSlopeMaxZ(tileh_new) == GetTileMaxZ(tile))) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
src/water_cmd.cpp
Show inline comments
 
@@ -168,7 +168,10 @@ void MakeWaterKeepingClass(TileIndex til
 
static CommandCost RemoveShipDepot(TileIndex tile, DoCommandFlag flags)
 
{
 
	if (!IsShipDepot(tile)) return CMD_ERROR;
 
	if (!CheckTileOwnership(tile)) return CMD_ERROR;
 

	
 
	CommandCost ret = CheckTileOwnership(tile);
 
	ret.SetGlobalErrorMessage();
 
	if (ret.Failed()) return ret;
 

	
 
	TileIndex tile2 = GetOtherShipDepotTile(tile);
 

	
 
@@ -244,10 +247,14 @@ static CommandCost RemoveShiplift(TileIn
 
{
 
	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
 

	
 
	if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
 
	if (GetTileOwner(tile) != OWNER_NONE) {
 
		CommandCost ret = CheckTileOwnership(tile);
 
		ret.SetGlobalErrorMessage();
 
		if (ret.Failed()) return ret;
 
	}
 

	
 
	/* make sure no vehicle is on the tile. */
 
	CommandCost ret = EnsureNoVehicleOnGround(tile);
 
	ret = EnsureNoVehicleOnGround(tile);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile + delta);
 
	if (ret.Succeeded()) ret = EnsureNoVehicleOnGround(tile - delta);
 
	ret.SetGlobalErrorMessage();
 
@@ -361,7 +368,11 @@ static CommandCost ClearTile_Water(TileI
 
			ret.SetGlobalErrorMessage();
 
			if (ret.Failed()) return ret;
 

	
 
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
 
			if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE) {
 
				CommandCost ret = CheckTileOwnership(tile);
 
				ret.SetGlobalErrorMessage();
 
				if (ret.Failed()) return ret;
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				DoClearSquare(tile);
0 comments (0 inline, 0 general)