(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
authorbelugas
Sat, 09 Feb 2008 03:03:09 +0000
changeset 8516 4b3cba59c003
parent 8515 20b5c6e8415e
child 8517 a185893bcb61
(svn r12091) -Codechange : remove all production level magic numbers and replace them by enums
src/industry_cmd.cpp
--- a/src/industry_cmd.cpp	Sat Feb 09 02:49:33 2008 +0000
+++ b/src/industry_cmd.cpp	Sat Feb 09 03:03:09 2008 +0000
@@ -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);
@@ -2126,7 +2136,7 @@
 	}
 
 	/* Increase if needed */
-	while (mul-- != 0 && i->prod_level < 0x80) {
+	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
 		i->prod_level <<= 1;
 		i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
 		i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
@@ -2135,7 +2145,7 @@
 
 	/* 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;
@@ -2147,16 +2157,16 @@
 
 	/* 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 +2210,7 @@
 
 	FOR_ALL_INDUSTRIES(i) {
 		UpdateIndustryStatistics(i);
-		if (i->prod_level == 0) {
+		if (i->prod_level == PRODLEVEL_CLOSURE) {
 			delete i;
 		} else {
 			ChangeIndustryProduction(i, true);