src/industry_cmd.cpp
branchnoai
changeset 9732 f8eb3e208514
parent 9724 b39bc69bb2f2
child 9826 9707ad4c9b60
equal deleted inserted replaced
9731:9b1552d0fd9b 9732:f8eb3e208514
   813 static void ClickTile_Industry(TileIndex tile)
   813 static void ClickTile_Industry(TileIndex tile)
   814 {
   814 {
   815 	ShowIndustryViewWindow(GetIndustryIndex(tile));
   815 	ShowIndustryViewWindow(GetIndustryIndex(tile));
   816 }
   816 }
   817 
   817 
   818 static uint32 GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode)
   818 static TrackStatus GetTileTrackStatus_Industry(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
   819 {
   819 {
   820 	return 0;
   820 	return 0;
   821 }
   821 }
   822 
   822 
   823 static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
   823 static void GetProducedCargo_Industry(TileIndex tile, CargoID *b)
  1412 			return false;
  1412 			return false;
  1413 		}
  1413 		}
  1414 	}
  1414 	}
  1415 	return true;
  1415 	return true;
  1416 }
  1416 }
       
  1417 
       
  1418 /** Production level maximum, minimum and default values.
       
  1419  * It is not a value been really used in order to change, but rather an indicator
       
  1420  * of how the industry is behaving. */
       
  1421 enum ProductionLevels {
       
  1422 	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
       
  1423 	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
       
  1424 	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
       
  1425 	PRODLEVEL_MAXIMUM = 0x80,  ///< the industry is running at full speed
       
  1426 };
  1417 
  1427 
  1418 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner)
  1428 static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner)
  1419 {
  1429 {
  1420 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1430 	const IndustrySpec *indspec = GetIndustrySpec(type);
  1421 	uint32 r;
  1431 	uint32 r;
  1501 	 * else, chosen layout + 1 */
  1511 	 * else, chosen layout + 1 */
  1502 	i->selected_layout = layout + 1;
  1512 	i->selected_layout = layout + 1;
  1503 
  1513 
  1504 	if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
  1514 	if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
  1505 
  1515 
  1506 	i->prod_level = 0x10;
  1516 	i->prod_level = PRODLEVEL_DEFAULT;
  1507 
  1517 
  1508 	do {
  1518 	do {
  1509 		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
  1519 		TileIndex cur_tile = tile + ToTileIndexDiff(it->ti);
  1510 
  1520 
  1511 		if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
  1521 		if (it->gfx != GFX_WATERTILE_SPECIALCHECK) {
  2124 			closeit = true;
  2134 			closeit = true;
  2125 		}
  2135 		}
  2126 	}
  2136 	}
  2127 
  2137 
  2128 	/* Increase if needed */
  2138 	/* Increase if needed */
  2129 	while (mul-- != 0 && i->prod_level < 0x80) {
  2139 	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
  2130 		i->prod_level <<= 1;
  2140 		i->prod_level = min(i->prod_level * 2, PRODLEVEL_MAXIMUM);
  2131 		i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
  2141 		i->production_rate[0] = min(i->production_rate[0] * 2, 0xFF);
  2132 		i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
  2142 		i->production_rate[1] = min(i->production_rate[1] * 2, 0xFF);
  2133 		if (str == STR_NULL) str = indspec->production_up_text;
  2143 		if (str == STR_NULL) str = indspec->production_up_text;
  2134 	}
  2144 	}
  2135 
  2145 
  2136 	/* Decrease if needed */
  2146 	/* Decrease if needed */
  2137 	while (div-- != 0 && !closeit) {
  2147 	while (div-- != 0 && !closeit) {
  2138 		if (i->prod_level == 4) {
  2148 		if (i->prod_level == PRODLEVEL_MINIMUM) {
  2139 			closeit = true;
  2149 			closeit = true;
  2140 		} else {
  2150 		} else {
  2141 			i->prod_level >>= 1;
  2151 			i->prod_level = max(i->prod_level / 2, (int)PRODLEVEL_MINIMUM); // typecast to int required to please MSVC
  2142 			i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
  2152 			i->production_rate[0] = (i->production_rate[0] + 1) / 2;
  2143 			i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
  2153 			i->production_rate[1] = (i->production_rate[1] + 1) / 2;
  2144 			if (str == STR_NULL) str = indspec->production_down_text;
  2154 			if (str == STR_NULL) str = indspec->production_down_text;
  2145 		}
  2155 		}
  2146 	}
  2156 	}
  2147 
  2157 
  2148 	/* Increase or Decreasing the production level if needed */
  2158 	/* Increase or Decreasing the production level if needed */
  2149 	if (increment != 0) {
  2159 	if (increment != 0) {
  2150 		if (increment < 0 && i->prod_level == 4) {
  2160 		if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) {
  2151 			closeit = true;
  2161 			closeit = true;
  2152 		} else {
  2162 		} else {
  2153 			i->prod_level = ClampU(i->prod_level + increment, 4, 0x80);
  2163 			i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM);
  2154 		}
  2164 		}
  2155 	}
  2165 	}
  2156 
  2166 
  2157 	/* Close if needed and allowed */
  2167 	/* Close if needed and allowed */
  2158 	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
  2168 	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
  2159 		i->prod_level = 0;
  2169 		i->prod_level = PRODLEVEL_CLOSURE;
  2160 		str = indspec->closure_text;
  2170 		str = indspec->closure_text;
  2161 	}
  2171 	}
  2162 
  2172 
  2163 	if (!suppress_message && str != STR_NULL) {
  2173 	if (!suppress_message && str != STR_NULL) {
  2164 		NewsType nt;
  2174 		NewsType nt;
  2198 	PlayerID old_player = _current_player;
  2208 	PlayerID old_player = _current_player;
  2199 	_current_player = OWNER_NONE;
  2209 	_current_player = OWNER_NONE;
  2200 
  2210 
  2201 	FOR_ALL_INDUSTRIES(i) {
  2211 	FOR_ALL_INDUSTRIES(i) {
  2202 		UpdateIndustryStatistics(i);
  2212 		UpdateIndustryStatistics(i);
  2203 		if (i->prod_level == 0) {
  2213 		if (i->prod_level == PRODLEVEL_CLOSURE) {
  2204 			delete i;
  2214 			delete i;
  2205 		} else {
  2215 		} else {
  2206 			ChangeIndustryProduction(i, true);
  2216 			ChangeIndustryProduction(i, true);
  2207 		}
  2217 		}
  2208 	}
  2218 	}