Changeset - r16186:88dee3f13edf
[Not reviewed]
master
0 2 0
frosch - 14 years ago 2010-10-04 19:23:50
frosch@openttd.org
(svn r20896) -Codechange: Split recompution of productionrates for non-smooth economy to separate function.
2 files changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -56,24 +56,26 @@ struct Industry : IndustryPool::PoolItem
 
	uint8 construction_type;            ///< Way the industry was constructed (@see IndustryConstructionType)
 
	Date last_cargo_accepted_at;        ///< Last day cargo was accepted by this industry
 
	byte selected_layout;               ///< Which tile layout was used when creating the industry
 

	
 
	byte random_triggers;               ///< Triggers for the random
 
	uint16 random;                      ///< Random value used for randomisation of all kinds of things
 

	
 
	PersistentStorage psa;              ///< Persistent storage for NewGRF industries.
 

	
 
	Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {}
 
	~Industry();
 

	
 
	void RecomputeProductionMultipliers();
 

	
 
	/**
 
	 * Get the industry of the given tile
 
	 * @param tile the tile to get the industry from
 
	 * @pre IsTileType(t, MP_INDUSTRY)
 
	 * @return the industry
 
	 */
 
	static FORCEINLINE Industry *GetByTile(TileIndex tile)
 
	{
 
		return Industry::Get(GetIndustryIndex(tile));
 
	}
 

	
 
	static Industry *GetRandom();
src/industry_cmd.cpp
Show inline comments
 
@@ -2021,24 +2021,38 @@ static void UpdateIndustryStatistics(Ind
 
			}
 
			i->last_month_pct_transported[j] = pct;
 

	
 
			i->last_month_production[j] = i->this_month_production[j];
 
			i->this_month_production[j] = 0;
 

	
 
			i->last_month_transported[j] = i->this_month_transported[j];
 
			i->this_month_transported[j] = 0;
 
		}
 
	}
 
}
 

	
 
/**
 
 * Recompute #production_rate for current #prod_level.
 
 * This function is only valid when not using smooth economy.
 
 */
 
void Industry::RecomputeProductionMultipliers()
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(this->type);
 
	assert(!indspec->UsesSmoothEconomy());
 

	
 
	/* Rates are rounded up, so e.g. oilrig always produces some passengers */
 
	this->production_rate[0] = min(CeilDiv(indspec->production_rate[0] * this->prod_level, PRODLEVEL_DEFAULT), 0xFF);
 
	this->production_rate[1] = min(CeilDiv(indspec->production_rate[1] * this->prod_level, PRODLEVEL_DEFAULT), 0xFF);
 
}
 

	
 
/** Simple helper that will collect data for the generation of industries */
 
struct ProbabilityHelper {
 
	uint16 prob;      ///< probability
 
	IndustryType ind; ///< Industry id.
 
};
 

	
 
/**
 
 * Try to create a random industry, during gameplay
 
 */
 
static void MaybeNewIndustry()
 
{
 
	uint num = 0;
 
@@ -2362,29 +2376,25 @@ static void ChangeIndustryProduction(Ind
 
	/* Increase or Decreasing the production level if needed */
 
	if (increment != 0) {
 
		if (increment < 0 && i->prod_level == PRODLEVEL_MINIMUM) {
 
			closeit = true;
 
		} else {
 
			i->prod_level = ClampU(i->prod_level + increment, PRODLEVEL_MINIMUM, PRODLEVEL_MAXIMUM);
 
			recalculate_multipliers = true;
 
		}
 
	}
 

	
 
	/* Recalculate production_rate
 
	 * For non-smooth economy these should always be synchronized with prod_level */
 
	if (recalculate_multipliers) {
 
		/* Rates are rounded up, so e.g. oilrig always produces some passengers */
 
		i->production_rate[0] = min(CeilDiv(indspec->production_rate[0] * i->prod_level, PRODLEVEL_DEFAULT), 0xFF);
 
		i->production_rate[1] = min(CeilDiv(indspec->production_rate[1] * i->prod_level, PRODLEVEL_DEFAULT), 0xFF);
 
	}
 
	if (recalculate_multipliers) i->RecomputeProductionMultipliers();
 

	
 
	/* Close if needed and allowed */
 
	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
 
		i->prod_level = PRODLEVEL_CLOSURE;
 
		str = indspec->closure_text;
 
	}
 

	
 
	if (!suppress_message && str != STR_NULL) {
 
		NewsSubtype ns;
 
		/* Compute news category */
 
		if (closeit) {
 
			ns = NS_INDUSTRY_CLOSE;
0 comments (0 inline, 0 general)