diff options
author | alberth <alberth@openttd.org> | 2010-03-14 19:59:45 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2010-03-14 19:59:45 +0000 |
commit | db1c6b7a811fc10e4d598ede421b4ce4cee3c848 (patch) | |
tree | b60db8f79b7c2a393eb826dfa2338a1519af4482 /src/industry_gui.cpp | |
parent | 6ef68f5d42ebe8551a45f650ef37198167628937 (diff) | |
download | openttd-db1c6b7a811fc10e4d598ede421b4ce4cee3c848.tar.xz |
(svn r19423) -Codechange: Move error message reporting of industry build in SE to a callback.
Diffstat (limited to 'src/industry_gui.cpp')
-rw-r--r-- | src/industry_gui.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 0380ebb20..a0bebce8a 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -96,6 +96,26 @@ static inline void GetAllCargoSuffixes(uint cb_offset, CargoSuffixType cst, cons } } +/** Command callback. In case of failure to build an industry, show an error message. + * @param result Result of the command. + * @param tile Tile where the industry is placed. + * @param p1 Additional data of the #CMD_BUILD_INDUSTRY command. + * @param p2 Additional data of the #CMD_BUILD_INDUSTRY command. + */ +void CcBuildIndustry(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2) +{ + if (result.Succeeded()) return; + + uint8 indtype = GB(p1, 0, 8); + if (indtype < NUM_INDUSTRYTYPES) { + const IndustrySpec *indsp = GetIndustrySpec(indtype); + if (indsp->enabled) { + SetDParam(0, indsp->name); + ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, result.GetErrorMessage(), WL_INFO, TileX(tile) * TILE_SIZE, TileY(tile) * TILE_SIZE); + } + } +} + /** Names of the widgets of the dynamic place industries gui */ enum DynamicPlaceIndustriesWidgets { DPIW_MATRIX_WIDGET, @@ -465,11 +485,8 @@ public: _current_company = OWNER_NONE; _generating_world = true; _ignore_restrictions = true; - success = DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY)); - if (!success) { - SetDParam(0, indsp->name); - ShowErrorMessage(STR_ERROR_CAN_T_BUILD_HERE, _error_message, WL_INFO, pt.x, pt.y); - } + DoCommandP(tile, (InteractiveRandomRange(indsp->num_table) << 8) | this->selected_type, seed, + CMD_BUILD_INDUSTRY | CMD_MSG(STR_ERROR_CAN_T_CONSTRUCT_THIS_INDUSTRY), &CcBuildIndustry); _ignore_restrictions = false; _generating_world = false; |