Changeset - r16448:b343c742a7ba
[Not reviewed]
master
0 1 0
alberth - 14 years ago 2010-11-13 15:20:57
alberth@openttd.org
(svn r21174) -Add: Use a progressive back-off mechanism to reduce wasting build attempts at unbuildable industries.
1 file changed with 14 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/industry_cmd.cpp
Show inline comments
 
@@ -1972,6 +1972,8 @@ void IndustryTypeBuildData::Reset()
 
{
 
	this->probability  = 0;
 
	this->target_count = 0;
 
	this->max_wait     = 1;
 
	this->wait_count   = 0;
 
}
 

	
 
/** Completely reset the industry build data. */
 
@@ -2150,6 +2152,7 @@ void IndustryBuildData::TryBuildNewIndus
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		int difference = this->builddata[it].target_count - Industry::GetIndustryTypeCount(it);
 
		missing += difference;
 
		if (this->builddata[it].wait_count > 0) continue; // This type may not be built now.
 
		if (difference > 0) {
 
			total_prob += difference;
 
			count++;
 
@@ -2166,6 +2169,7 @@ void IndustryBuildData::TryBuildNewIndus
 
		uint32 r = 0; // Initialized to silence the compiler.
 
		if (count > 1) r = RandomRange(total_prob);
 
		for (it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
			if (this->builddata[it].wait_count > 0) continue; // Type may not be built now.
 
			int difference = this->builddata[it].target_count - Industry::GetIndustryTypeCount(it);
 
			if (difference <= 0) continue; // Too many of this kind.
 
			if (count == 1) break;
 
@@ -2176,10 +2180,19 @@ void IndustryBuildData::TryBuildNewIndus
 

	
 
		/* Try to create the industry. */
 
		const Industry *ind = PlaceIndustry(it, IACT_RANDOMCREATION, false);
 
		if (ind != NULL) {
 
		if (ind == NULL) {
 
			this->builddata[it].wait_count = this->builddata[it].max_wait + 1; // Compensate for decrementing below.
 
			this->builddata[it].max_wait = min(1000, this->builddata[it].max_wait + 2);
 
		} else {
 
			AdvertiseIndustryOpening(ind);
 
			this->builddata[it].max_wait = max(this->builddata[it].max_wait / 2, 1); // Reduce waiting time of the industry type.
 
		}
 
	}
 

	
 
	/* Decrement wait counters. */
 
	for (IndustryType it = 0; it < NUM_INDUSTRYTYPES; it++) {
 
		if (this->builddata[it].wait_count > 0) this->builddata[it].wait_count--;
 
	}
 
}
 

	
 
/**
0 comments (0 inline, 0 general)