From 0c775e575059a25d1c0df1b059e27818e98c47c4 Mon Sep 17 00:00:00 2001 From: alberth Date: Sat, 13 Nov 2010 15:20:57 +0000 Subject: (svn r21174) -Add: Use a progressive back-off mechanism to reduce wasting build attempts at unbuildable industries. --- src/industry_cmd.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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--; + } } /** -- cgit v1.2.3-70-g09d2