summaryrefslogtreecommitdiff
path: root/src/industry_gui.cpp
diff options
context:
space:
mode:
authorYexo <yexo@openttd.org>2020-06-01 00:43:47 +0200
committerYexo <t.marinussen@gmail.com>2020-06-01 22:46:06 +0200
commitce618bf7e96ddc92b1ceb7c82c821af822b3796d (patch)
tree064b05053a3d219cea28868db9bd540d0ebbf362 /src/industry_gui.cpp
parenta82572d0f5a55a33df4163b429f891ea76ed92a7 (diff)
downloadopenttd-ce618bf7e96ddc92b1ceb7c82c821af822b3796d.tar.xz
Codechange: replace custom timer and OnGameTick() with OnHundrethTick()
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r--src/industry_gui.cpp33
1 files changed, 10 insertions, 23 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index a5f03a2b9..c7ba3345c 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -270,8 +270,6 @@ static WindowDesc _build_industry_desc(
class BuildIndustryWindow : public Window {
int selected_index; ///< index of the element in the matrix
IndustryType selected_type; ///< industry corresponding to the above index
- uint16 callback_timer; ///< timer counter for callback eventual verification
- bool timer_enabled; ///< timer can be used
uint16 count; ///< How many industries are loaded
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever)
@@ -295,7 +293,6 @@ class BuildIndustryWindow : public Window {
this->index[this->count] = INVALID_INDUSTRYTYPE;
this->enabled[this->count] = true;
this->count++;
- this->timer_enabled = false;
}
/* Fill the arrays with industries.
* The tests performed after the enabled allow to load the industries
@@ -387,13 +384,9 @@ class BuildIndustryWindow : public Window {
public:
BuildIndustryWindow() : Window(&_build_industry_desc)
{
- this->timer_enabled = _loaded_newgrf_features.has_newindustries;
-
this->selected_index = -1;
this->selected_type = INVALID_INDUSTRYTYPE;
- this->callback_timer = DAY_TICKS;
-
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_DPI_SCROLLBAR);
this->FinishInitNested(0);
@@ -673,25 +666,19 @@ public:
if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
}
- void OnGameTick() override
+ void OnHundredthTick() override
{
- if (!this->timer_enabled) return;
- if (--this->callback_timer == 0) {
- /* We have just passed another day.
- * See if we need to update availability of currently selected industry */
- this->callback_timer = DAY_TICKS; // restart counter
-
- const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
+ if (_game_mode == GM_EDITOR) return;
+ const IndustrySpec *indsp = GetIndustrySpec(this->selected_type);
- if (indsp->enabled) {
- bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
+ if (indsp->enabled) {
+ bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0;
- /* Only if result does match the previous state would it require a redraw. */
- if (call_back_result != this->enabled[this->selected_index]) {
- this->enabled[this->selected_index] = call_back_result;
- this->SetButtons();
- this->SetDirty();
- }
+ /* Only if result does match the previous state would it require a redraw. */
+ if (call_back_result != this->enabled[this->selected_index]) {
+ this->enabled[this->selected_index] = call_back_result;
+ this->SetButtons();
+ this->SetDirty();
}
}
}