changeset 14606:7e0b0b3c275b draft

(svn r19183) -Codechange: Return CommandCost from FindTownForIndustry().
author alberth <alberth@openttd.org>
date Sun, 21 Feb 2010 14:57:27 +0000
parents ca545476755b
children 473d68383c30
files src/industry_cmd.cpp
diffstat 1 files changed, 18 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1270,27 +1270,27 @@
 /** Find a town for the industry, while checking for multiple industries in the same town.
  * @param tile Position of the industry to build.
  * @param type Industry type.
- * @param [out] err_mesg Error message, if any.
- * @return Town for the new industry, \c NULL if no good town can be found.
+ * @param [out] town Pointer to return town for the new industry, \c NULL is written if no good town can be found.
+ * @return Succeeded or failed command.
+ *
+ * @precond \c *t != NULL
+ * @postcon \c *t points to a town on success, and \c NULL on failure.
  */
-static const Town *FindTownForIndustry(TileIndex tile, int type)
+static CommandCost FindTownForIndustry(TileIndex tile, int type, const Town **t)
 {
-	const Town *t;
-	const Industry *i;
+	*t = ClosestTownFromTile(tile, UINT_MAX);
 
-	t = ClosestTownFromTile(tile, UINT_MAX);
+	if (_settings_game.economy.multiple_industry_per_town) return CommandCost();
 
-	if (_settings_game.economy.multiple_industry_per_town) return t;
-
+	const Industry *i;
 	FOR_ALL_INDUSTRIES(i) {
-		if (i->type == (byte)type &&
-				i->town == t) {
-			_error_message = STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN;
-			return NULL;
+		if (i->type == (byte)type && i->town == *t) {
+			*t = NULL;
+			return_cmd_error(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN);
 		}
 	}
 
-	return t;
+	return CommandCost();
 }
 
 bool IsSlopeRefused(Slope current, Slope refused)
@@ -1708,8 +1708,11 @@
 	ret.SetGlobalErrorMessage();
 	if (ret.Failed()) return NULL;
 
-	const Town *t = FindTownForIndustry(tile, type);
-	if (t == NULL) return NULL;
+	const Town *t = NULL;
+	ret = FindTownForIndustry(tile, type, &t);
+	ret.SetGlobalErrorMessage();
+	if (ret.Failed()) return NULL;
+	assert(t != NULL);
 
 	ret = CheckIfIndustryIsAllowed(tile, type, t);
 	ret.SetGlobalErrorMessage();