From 325a46e8ed8b93692ca8fb78e14b4d296511523b Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 26 Feb 2017 15:33:39 +0000 Subject: (svn r27750) -Codechange: Add cb37 result type to the cargo suffix. --- src/industry_gui.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 5eae0b4c8..8a8918333 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -56,9 +56,18 @@ enum CargoSuffixType { CST_DIR, ///< Industry-directory window }; +/** Ways of displaying the cargo. */ +enum CargoSuffixDisplay { + CSD_CARGO, ///< Display the cargo without sub-type (cb37 result 401). + CSD_CARGO_AMOUNT, ///< Display the cargo and amount (if useful), but no sub-type (cb37 result 400 or fail). + CSD_CARGO_TEXT, ///< Display then cargo and supplied string (cb37 result 800-BFF). + CSD_CARGO_AMOUNT_TEXT, ///< Display then cargo, amount, and string (cb37 result 000-3FF). +}; + /** Transfer storage of cargo suffix information. */ struct CargoSuffix { - char text[512]; ///< Storage of the cargo suffix to print. + CargoSuffixDisplay display; ///< How to display the cargo and text. + char text[512]; ///< Cargo suffix text. }; static void ShowIndustryCargoesWindow(IndustryType id); @@ -80,15 +89,47 @@ static void ShowIndustryCargoesWindow(IndustryType id); static void GetCargoSuffix(uint cargo, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, CargoSuffix &suffix) { suffix.text[0] = '\0'; + suffix.display = CSD_CARGO_AMOUNT; + if (HasBit(indspec->callback_mask, CBM_IND_CARGO_SUFFIX)) { - uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast(ind), ind_type, (cst != CST_FUND) ? ind->location.tile : INVALID_TILE); - if (callback == CALLBACK_FAILED || callback == 0x400) return; - if (callback > 0x400) { + TileIndex t = (cst != CST_FUND) ? ind->location.tile : INVALID_TILE; + uint16 callback = GetIndustryCallback(CBID_INDUSTRY_CARGO_SUFFIX, 0, (cst << 8) | cargo, const_cast(ind), ind_type, t); + if (callback == CALLBACK_FAILED) return; + + if (indspec->grf_prop.grffile->grf_version < 8) { + if (GB(callback, 0, 8) == 0xFF) return; + if (callback < 0x400) { + StartTextRefStackUsage(indspec->grf_prop.grffile, 6); + GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text)); + StopTextRefStackUsage(); + suffix.display = CSD_CARGO_AMOUNT_TEXT; + return; + } ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback); - } else if (indspec->grf_prop.grffile->grf_version >= 8 || GB(callback, 0, 8) != 0xFF) { - StartTextRefStackUsage(indspec->grf_prop.grffile, 6); - GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text)); - StopTextRefStackUsage(); + return; + + } else { // GRF version 8 or higher. + if (callback == 0x400) return; + if (callback == 0x401) { + suffix.display = CSD_CARGO; + return; + } + if (callback < 0x400) { + StartTextRefStackUsage(indspec->grf_prop.grffile, 6); + GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 + callback), lastof(suffix.text)); + StopTextRefStackUsage(); + suffix.display = CSD_CARGO_AMOUNT_TEXT; + return; + } + if (callback >= 0x800 && callback < 0xC00) { + StartTextRefStackUsage(indspec->grf_prop.grffile, 6); + GetString(suffix.text, GetGRFStringID(indspec->grf_prop.grffile->grfid, 0xD000 - 0x800 + callback), lastof(suffix.text)); + StopTextRefStackUsage(); + suffix.display = CSD_CARGO_TEXT; + return; + } + ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_CARGO_SUFFIX, callback); + return; } } } -- cgit v1.2.3-54-g00ecf