summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/industry_gui.cpp36
-rw-r--r--src/newgrf_callbacks.h2
2 files changed, 37 insertions, 1 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 751a8fc92..51a8c694a 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -24,6 +24,7 @@
#include "newgrf_callbacks.h"
#include "newgrf_industries.h"
#include "newgrf_text.h"
+#include "date.h"
extern Industry *CreateNewIndustry(TileIndex tile, IndustryType type);
@@ -62,6 +63,8 @@ enum {
struct fnd_d {
int index; ///< index of the element in the matrix
IndustryType select; ///< industry corresponding to the above index
+ uint16 callback_timer; ///< timer counter for callback eventual verification
+ bool timer_enabled; ///< timer can be used
};
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(fnd_d));
@@ -70,6 +73,7 @@ static struct IndustryData {
uint16 count; ///< How many industries are loaded
IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded
StringID text[NUM_INDUSTRYTYPES + 1]; ///< Text coming from CBM_IND_FUND_MORE_TEXT (if ever)
+ bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_AVAILABLE (if ever)
} _fund_gui;
static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
@@ -91,9 +95,12 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
w->resize.height = w->height -= 44;
}
+ WP(w, fnd_d).timer_enabled = _loaded_newgrf_features.has_newindustries;
+
/* Initilialize structures */
memset(&_fund_gui.index, 0xFF, NUM_INDUSTRYTYPES);
memset(&_fund_gui.text, STR_NULL, NUM_INDUSTRYTYPES);
+ memset(&_fund_gui.enabled, false, NUM_INDUSTRYTYPES);
_fund_gui.count = 0;
w->vscroll.cap = 8; // rows in grid, same in scroller
@@ -102,6 +109,7 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
if (_game_mode == GM_EDITOR) { // give room for the Many Random "button"
_fund_gui.index[_fund_gui.count] = INVALID_INDUSTRYTYPE;
_fund_gui.count++;
+ WP(w, fnd_d).timer_enabled = false;
}
/* We'll perform two distinct loops, one for secondary industries, and the other one for
@@ -110,6 +118,7 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
indsp = GetIndustrySpec(ind);
if (indsp->enabled && (!indsp->IsRawIndustry() || _game_mode == GM_EDITOR)) {
_fund_gui.index[_fund_gui.count] = ind;
+ _fund_gui.enabled[_fund_gui.count] = CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
_fund_gui.count++;
}
}
@@ -119,14 +128,17 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
indsp = GetIndustrySpec(ind);
if (indsp->enabled && indsp->IsRawIndustry()) {
_fund_gui.index[_fund_gui.count] = ind;
+ _fund_gui.enabled[_fund_gui.count] = CheckIfCallBackAllowsAvailability(ind, IACT_USERCREATION);
_fund_gui.count++;
}
}
}
+
/* first indutry type is selected.
* I'll be damned if there are none available ;) */
WP(w, fnd_d).index = 0;
WP(w, fnd_d).select = _fund_gui.index[0];
+ WP(w, fnd_d).callback_timer = DAY_TICKS;
} break;
case WE_PAINT: {
@@ -140,10 +152,15 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
/* Raw industries might be prospected. Show this fact by changing the string
* In Editor, you just build, while ingame, or you fund or you prospect */
if (_game_mode == GM_EDITOR) {
+ /* We've chosen many random industries but no industries have been specified */
+ if (indsp == NULL && _patches.raw_industry_construction == 0) {
+ _fund_gui.enabled[WP(w, fnd_d).index] = false;
+ }
w->widget[DYNA_INDU_FUND_WIDGET].data = STR_BUILD_NEW_INDUSTRY;
} else {
w->widget[DYNA_INDU_FUND_WIDGET].data = (_patches.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_PROSPECT_NEW_INDUSTRY : STR_FUND_NEW_INDUSTRY;
}
+ SetWindowWidgetDisabledState(w, DYNA_INDU_FUND_WIDGET, !_fund_gui.enabled[WP(w, fnd_d).index]);
SetVScrollCount(w, _fund_gui.count);
@@ -308,6 +325,25 @@ static void BuildDynamicIndustryWndProc(Window *w, WindowEvent *e)
ResetObjectToPlace();
} break;
+ case WE_TICK:
+ if (!WP(w, fnd_d).timer_enabled) break;
+ if (--WP(w, fnd_d).callback_timer == 0) {
+ /* We have just passed another day.
+ * See if we need to update availability of currently selected industry */
+ WP(w, fnd_d).callback_timer = DAY_TICKS; //restart counter
+
+ const IndustrySpec *indsp = GetIndustrySpec(WP(w, fnd_d).select);
+
+ if (indsp->enabled) {
+ bool call_back_result = CheckIfCallBackAllowsAvailability(WP(w, fnd_d).select, IACT_USERCREATION);
+
+ /* Only if result does match the previous state would it require a redraw. */
+ if (call_back_result != _fund_gui.enabled[WP(w, fnd_d).index]) {
+ _fund_gui.enabled[WP(w, fnd_d).index] = call_back_result;
+ SetWindowDirty(w);
+ }
+ }
+ }
break;
case WE_TIMEOUT:
diff --git a/src/newgrf_callbacks.h b/src/newgrf_callbacks.h
index d255c9a51..33f005c2b 100644
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -75,7 +75,7 @@ enum CallbackID {
CBID_HOUSE_DESTRUCTION = 0x21,
/** Called to determine if the given industry type is available */
- CBID_INDUSTRY_AVAILABLE = 0x22, // not implemented
+ CBID_INDUSTRY_AVAILABLE = 0x22,
/** This callback is called from vehicle purchase lists. It returns a value to be
* used as a custom string ID in the 0xD000 range. */