diff options
author | frosch <frosch@openttd.org> | 2011-11-08 17:26:13 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2011-11-08 17:26:13 +0000 |
commit | b98c7763de42eda4b3d19604bc3f33452b9b05e4 (patch) | |
tree | 3a0092e76fa25fd7d025cefe8e105875b99c5c8f /src/newgrf_industries.cpp | |
parent | b374b92bfb06745d21701d398bb0c78a395498b4 (diff) | |
download | openttd-b98c7763de42eda4b3d19604bc3f33452b9b05e4.tar.xz |
(svn r23146) -Change: [NewGRF v8] Make callback 22 return a probability to use instead of property 18.
Diffstat (limited to 'src/newgrf_industries.cpp')
-rw-r--r-- | src/newgrf_industries.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 389bcebfb..2f469dc71 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -550,22 +550,32 @@ CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, uin } /** - * Check with callback #CBM_IND_AVAILABLE whether the industry can be built. + * Check with callback #CBID_INDUSTRY_PROBABILITY whether the industry can be built. * @param type Industry type to check. * @param creation_type Reason to construct a new industry. * @return If the industry has no callback or allows building, \c true is returned. Otherwise, \c false is returned. */ -bool CheckIfCallBackAllowsAvailability(IndustryType type, IndustryAvailabilityCallType creation_type) +uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob) { const IndustrySpec *indspec = GetIndustrySpec(type); - if (HasBit(indspec->callback_mask, CBM_IND_AVAILABLE)) { - uint16 res = GetIndustryCallback(CBID_INDUSTRY_AVAILABLE, 0, creation_type, NULL, type, INVALID_TILE); + if (HasBit(indspec->callback_mask, CBM_IND_PROBABILITY)) { + uint16 res = GetIndustryCallback(CBID_INDUSTRY_PROBABILITY, 0, creation_type, NULL, type, INVALID_TILE); if (res != CALLBACK_FAILED) { - return (res == 0); + if (indspec->grf_prop.grffile->grf_version < 8) { + /* Disallow if result != 0 */ + if (res != 0) default_prob = 0; + } else { + /* Use returned probability. 0x100 to use default */ + if (res < 0x100) { + default_prob = res; + } else if (res > 0x100) { + ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROBABILITY, res); + } + } } } - return true; + return default_prob; } static int32 DerefIndProd(int field, bool use_register) |