diff options
-rw-r--r-- | src/company_cmd.cpp | 9 | ||||
-rw-r--r-- | src/functions.h | 2 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 48 | ||||
-rw-r--r-- | src/road_cmd.cpp | 6 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 4 | ||||
-rw-r--r-- | src/unmovable_cmd.cpp | 12 | ||||
-rw-r--r-- | src/water_cmd.cpp | 19 |
7 files changed, 74 insertions, 26 deletions
diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 29343a09b..e1b3e34f5 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -266,20 +266,19 @@ bool CheckOwnership(Owner owner, TileIndex tile) * 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) diff --git a/src/functions.h b/src/functions.h index 28c8f16bb..6acbb9af7 100644 --- a/src/functions.h +++ b/src/functions.h @@ -25,7 +25,7 @@ bool CheckCompanyHasMoney(CommandCost &cost); 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 */ /** diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 3475eb90e..bce6732da 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -366,13 +366,15 @@ CommandCost CmdBuildSingleRail(TileIndex tile, DoCommandFlag flags, uint32 p1, u 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(TileIndex tile, DoCommandFlag flags, uint32 p1, 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(TileIndex tile, DoCommandFlag flags, uint32 p1, 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(TileIndex tile, DoCommandFlag flags, uint32 p1, /* 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(TileIndex tile, DoCommandFlag flags, uint32 p1 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 tile, DoCommandFlag flags, uint32 p1, uint3 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 tile, DoCommandFlag flags, uint32 p1, uint3 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(); diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 0f6cc1581..366f6bd0c 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -911,7 +911,11 @@ CommandCost CmdBuildRoadDepot(TileIndex tile, DoCommandFlag flags, uint32 p1, ui 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(); diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index 612c49041..81688b6bc 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -587,7 +587,9 @@ static inline bool CheckAllowRemoveTunnelBridge(TileIndex tile) 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; diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp index 039a0162f..d3a97b5f3 100644 --- a/src/unmovable_cmd.cpp +++ b/src/unmovable_cmd.cpp @@ -175,7 +175,11 @@ CommandCost CmdPurchaseLandArea(TileIndex tile, DoCommandFlag flags, uint32 p1, 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(TileIndex tile, Owner old_owner, Owner new 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]); diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 01c25157f..6b881352e 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -168,7 +168,10 @@ void MakeWaterKeepingClass(TileIndex tile, Owner o) 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(TileIndex tile, DoCommandFlag flags) { 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(TileIndex tile, DoCommandFlag flags) 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); |