summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-11-13 15:20:57 +0000
committeralberth <alberth@openttd.org>2010-11-13 15:20:57 +0000
commit0c775e575059a25d1c0df1b059e27818e98c47c4 (patch)
tree0748c5775af6089ba1bd9d01e58a01e5901f4095 /src
parenta245db636006c506b5e11ac51d0287a15a1c24b2 (diff)
downloadopenttd-0c775e575059a25d1c0df1b059e27818e98c47c4.tar.xz
(svn r21174) -Add: Use a progressive back-off mechanism to reduce wasting build attempts at unbuildable industries.
Diffstat (limited to 'src')
-rw-r--r--src/industry_cmd.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 5cedd4e3a..f549334ff 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -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::TryBuildNewIndustry()
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::TryBuildNewIndustry()
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::TryBuildNewIndustry()
/* 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--;
+ }
}
/**