diff options
author | alberth <alberth@openttd.org> | 2010-03-13 15:33:07 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-03-13 15:33:07 +0000 |
commit | 6b6ff9c52b04ec47de1281284fcc99f6775f2302 (patch) | |
tree | 303ab0e7deed7d7293218566146fa6b60387de73 /src | |
parent | 7134201524f61ce4234c476fe2d8c16eec4f391e (diff) | |
download | openttd-6b6ff9c52b04ec47de1281284fcc99f6775f2302.tar.xz |
(svn r19400) -Codechange: CheckforTownRating returns a CommandCost.
Diffstat (limited to 'src')
-rw-r--r-- | src/road_cmd.cpp | 4 | ||||
-rw-r--r-- | src/town.h | 2 | ||||
-rw-r--r-- | src/town_cmd.cpp | 16 | ||||
-rw-r--r-- | src/tunnelbridge_cmd.cpp | 14 |
4 files changed, 21 insertions, 15 deletions
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 366f6bd0c..5d83abeef 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -140,7 +140,9 @@ bool CheckAllowRemoveRoad(TileIndex tile, RoadBits remove, Owner owner, RoadType /* check if you're allowed to remove the street owned by a town * removal allowance depends on difficulty setting */ - if (!CheckforTownRating(flags, t, ROAD_REMOVE)) return false; + CommandCost ret = CheckforTownRating(flags, t, ROAD_REMOVE); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return false; /* Get a bitmask of which neighbouring roads has a tile */ RoadBits n = ROAD_NONE; diff --git a/src/town.h b/src/town.h index f1571d241..25794f084 100644 --- a/src/town.h +++ b/src/town.h @@ -179,7 +179,7 @@ enum { TOWN_HAS_STADIUM = 2 ///< There can be only one stadium by town. }; -bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type); +CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type); TileIndexDiff GetHouseNorthPart(HouseID &house); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 67d6c7546..2a4e3674d 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2795,12 +2795,19 @@ void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags) } } -bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type) +/** + * Does the town authority allow the (destructive) action of the current company? + * @param flags Checking flags of the command. + * @param t Town that must allow the company action. + * @param type Type of action that is wanted. + * @return A succeeded command if the action is allowed, a failed command if it is not allowed. + */ +CommandCost CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type) { /* if magic_bulldozer cheat is active, town doesn't restrict your destructive actions */ if (t == NULL || !Company::IsValidID(_current_company) || _cheats.magic_bulldozer.value || (flags & DC_NO_TEST_TOWN_RATING)) { - return true; + return CommandCost(); } /* minimum rating needed to be allowed to remove stuff */ @@ -2819,11 +2826,10 @@ bool CheckforTownRating(DoCommandFlag flags, Town *t, TownRatingCheckType type) if (GetRating(t) < needed) { SetDParam(0, t->index); - _error_message = STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS; - return false; + return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); } - return true; + return CommandCost(); } void TownsMonthlyLoop() diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index aefb074d3..a5d724108 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -638,10 +638,9 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags) /* Check if you are allowed to remove the tunnel owned by a town * Removal depends on difficulty settings */ - if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { - SetDParam(0, t->index); - return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); - } + CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until @@ -706,10 +705,9 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags) /* Check if you are allowed to remove the bridge owned by a town * Removal depends on difficulty settings */ - if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) { - SetDParam(0, t->index); - return_cmd_error(STR_ERROR_LOCAL_AUTHORITY_REFUSES_TO_ALLOW_THIS); - } + CommandCost ret = CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE); + ret.SetGlobalErrorMessage(); + if (ret.Failed()) return ret; } /* checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until |