src/industry_cmd.cpp
branchnoai
changeset 9718 f82a4facea8b
parent 9704 197cb8c6ae17
child 9722 ebf0ece7d8f6
--- a/src/industry_cmd.cpp	Sat Oct 20 10:14:05 2007 +0000
+++ b/src/industry_cmd.cpp	Sat Oct 20 10:42:28 2007 +0000
@@ -1007,7 +1007,7 @@
 	if ((i->counter & 0xFF) == 0) {
 		if (HASBIT(indsp->callback_flags, CBM_IND_PRODUCTION_256_TICKS)) IndustryProductionCallback(i, 1);
 
-		IndustyBehaviour indbehav = indsp->behaviour;
+		IndustryBehaviour indbehav = indsp->behaviour;
 		i->produced_cargo_waiting[0] = min(0xffff, i->produced_cargo_waiting[0] + i->production_rate[0]);
 		i->produced_cargo_waiting[1] = min(0xffff, i->produced_cargo_waiting[1] + i->production_rate[1]);
 
@@ -1185,6 +1185,7 @@
 
 bool IsSlopeRefused(Slope current, Slope refused)
 {
+	if (IsSteepSlope(current)) return true;
 	if (current != SLOPE_FLAT) {
 		if (refused & SLOPE_STEEP) return true;
 
@@ -1220,32 +1221,22 @@
 				return false;
 			}
 		} else {
-			if (!EnsureNoVehicle(cur_tile)) return false;
+			if (!EnsureNoVehicleOnGround(cur_tile)) return false;
 			if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
 
 			const IndustryTileSpec *its = GetIndustryTileSpec(gfx);
 
-			IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
+			IndustryBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
+
+			/* Perform land/water check if not disabled */
+			if (!HASBIT(its->slopes_refused, 5) && (IsWaterTile(cur_tile) == !(ind_behav & INDUSTRYBEH_BUILT_ONWATER))) return false;
 
 			if (HASBIT(its->callback_flags, CBM_INDT_SHAPE_CHECK)) {
 				custom_shape = true;
 				if (!PerformIndustryTileSlopeCheck(tile, cur_tile, its, type, gfx, itspec_index)) return false;
 			} else {
-				if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
-					/* As soon as the tile is not water, bail out.
-					* But that does not mean the search is over.  You have
-					* to make sure every tile of the industry will be only water*/
-					if (!IsClearWaterTile(cur_tile)) return false;
-				} else {
-					Slope tileh;
-
-					if (IsClearWaterTile(cur_tile)) return false;
-
-					tileh = GetTileSlope(cur_tile, NULL);
-					if (IsSteepSlope(tileh)) return false;
-
-					refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
-				}
+				Slope tileh = GetTileSlope(cur_tile, NULL);
+				refused_slope |= IsSlopeRefused(tileh, its->slopes_refused);
 			}
 
 			if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
@@ -1591,8 +1582,6 @@
  */
 CommandCost CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	int num;
-	const IndustryTileTable * const *itt;
 	const IndustrySpec *indspec;
 
 	SET_EXPENSES_TYPE(EXPENSES_OTHER);
@@ -1617,11 +1606,15 @@
 			 * is nothing we can really do about that. */
 			if (Random() <= indspec->prospecting_chance) {
 				for (int i = 0; i < 5000; i++) {
-					uint tilespec_index = RandomRange(indspec->num_table);
-					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, tilespec_index);
+					const Industry *ind = CreateNewIndustryHelper(RandomTile(), p1, flags, indspec, RandomRange(indspec->num_table));
 					if (ind != NULL) {
 						SetDParam(0, indspec->name);
-						SetDParam(1, ind->town->index);
+						if (indspec->new_industry_text > STR_LAST_STRINGID) {
+							SetDParam(1, STR_TOWN);
+							SetDParam(2, ind->town->index);
+						} else {
+							SetDParam(1, ind->town->index);
+						}
 						AddNewsItem(indspec->new_industry_text,
 								NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
 						break;
@@ -1630,12 +1623,14 @@
 			}
 		}
 	} else {
-		num = indspec->num_table;
-		itt = indspec->table;
+		int count = indspec->num_table;
+		const IndustryTileTable * const *itt = indspec->table;
+		int num = RandomRange(count);
 
-
+		_error_message = STR_0239_SITE_UNSUITABLE;
 		do {
-			if (--num < 0) return_cmd_error(STR_0239_SITE_UNSUITABLE);
+			if (--count < 0) return CMD_ERROR;
+			if (--num < 0) num = indspec->num_table - 1;
 		} while (!CheckIfIndustryTilesAreFree(tile, itt[num], num, p1));
 
 		if (CreateNewIndustryHelper(tile, p1, flags, indspec, num) == NULL) return CMD_ERROR;
@@ -1829,7 +1824,12 @@
 	}
 
 	SetDParam(0, ind_spc->name);
-	SetDParam(1, ind->town->index);
+	if (ind_spc->new_industry_text > STR_LAST_STRINGID) {
+		SetDParam(1, STR_TOWN);
+		SetDParam(2, ind->town->index);
+	} else {
+		SetDParam(1, ind->town->index);
+	}
 	AddNewsItem(ind_spc->new_industry_text,
 		NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0), ind->xy, 0);
 }
@@ -1984,7 +1984,13 @@
 	}
 
 	if (!suppress_message && str != STR_NULL) {
-		SetDParam(0, i->index);
+		if (str > STR_LAST_STRINGID) {
+			SetDParam(0, STR_TOWN);
+			SetDParam(1, i->town->index);
+			SetDParam(2, indspec->name);
+		} else {
+			SetDParam(0, i->index);
+		}
 		AddNewsItem(str,
 			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, closeit ? NT_OPENCLOSE : NT_ECONOMY, 0),
 			i->xy + TileDiffXY(1, 1), 0);