src/industry_cmd.cpp
branchNewGRF_ports
changeset 6878 7d1ff2f621c7
parent 6877 889301acc299
child 10184 fcf5fb2548eb
--- a/src/industry_cmd.cpp	Sun Feb 03 20:34:26 2008 +0000
+++ b/src/industry_cmd.cpp	Mon Mar 10 15:26:39 2008 +0000
@@ -815,7 +815,7 @@
 	ShowIndustryViewWindow(GetIndustryIndex(tile));
 }
 
-static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode)
+static TrackStatus GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
 {
 	return 0;
 }
@@ -1415,6 +1415,16 @@
 	return true;
 }
 
+/** Production level maximum, minimum and default values.
+ * It is not a value been really used in order to change, but rather an indicator
+ * of how the industry is behaving. */
+enum ProductionLevels {
+	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
+	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
+	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
+	PRODLEVEL_MAXIMUM = 0x80,  ///< the industry is running at full speed
+};
+
 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner)
 {
 	const IndustrySpec *indspec = GetIndustrySpec(type);
@@ -1503,7 +1513,7 @@
 
 	if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
 
-	i->prod_level = 0x10;
+	i->prod_level = PRODLEVEL_DEFAULT;
 
 	do {
 		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
@@ -2009,7 +2019,6 @@
  */
 static void ChangeIndustryProduction(Industry *i, bool monthly)
 {
-	extern StringID MapGRFStringID(uint32 grfid, StringID str);
 	StringID str = STR_NULL;
 	bool closeit = false;
 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
@@ -2126,8 +2135,8 @@
 	}
 
 	/* Increase if needed */
-	while (mul-- != 0 && i->prod_level < 0x80) {
-		i->prod_level <<= 1;
+	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
+		i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
 		i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
 		i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
 		if (str == STR_NULL) str = indspec->production_up_text;
@@ -2135,28 +2144,28 @@
 
 	/* Decrease if needed */
 	while (div-- != 0 && !closeit) {
-		if (i->prod_level == 4) {
+		if (i->prod_level == PRODLEVEL_MINIMUM) {
 			closeit = true;
 		} else {
-			i->prod_level >>= 1;
-			i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
-			i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
+			i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC
+			i->production_rate[0] = (i->production_rate[0] + 1) / 2;
+			i->production_rate[1] = (i->production_rate[1] + 1) / 2;
 			if (str == STR_NULL) str = indspec->production_down_text;
 		}
 	}
 
 	/* Increase or Decreasing the production level if needed */
 	if (increment != 0) {
-		if (increment < 0 && i->prod_level == 4) {
+		if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) {
 			closeit = true;
 		} else {
-			i->prod_level = ClampU(i->prod_level + increment, 4, 0x80);
+			i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM);
 		}
 	}
 
 	/* Close if needed and allowed */
 	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
-		i->prod_level = 0;
+		i->prod_level = PRODLEVEL_CLOSURE;
 		str = indspec->closure_text;
 	}
 
@@ -2200,7 +2209,7 @@
 
 	FOR_ALL_INDUSTRIES(i) {
 		UpdateIndustryStatistics(i);
-		if (i->prod_level == 0) {
+		if (i->prod_level == PRODLEVEL_CLOSURE) {
 			delete i;
 		} else {
 			ChangeIndustryProduction(i, true);