=== modified file 'src/industry_cmd.cpp' --- src/industry_cmd.cpp 2008-06-29 09:09:21 +0000 +++ src/industry_cmd.cpp 2008-06-29 09:10:32 +0000 @@ -58,6 +58,8 @@ IndustrySpec _industry_specs[NUM_INDUSTRYTYPES]; IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES]; +static const int MAX_MONTHS_RECENTLY_NEW_STATION = 12; ///< Number of months considered 'recently built' for a station in range of an industry + /** This function initialize the spec arrays of both * industry and industry tiles. * It adjusts the enabling of the industry too, based on climate availability. @@ -2032,6 +2034,25 @@ PERCENT_TRANSPORTED_80 = 204, }; +/** + * Check whether a station has been built recently within range of the industry. + * @param i Industry to perform the check for + * @return \c true if a station has been built near the industry less than MAX_MONTHS_RECENTLY_NEW_STATION months ago, + * \c false otherwise. + */ +static bool StationRecentlyBuiltNearby(Industry *i) +{ + StationSet stations = FindStationsAroundIndustryTile(i->xy, i->width, i->height); + for (StationSet::iterator st_iter = stations.begin(); st_iter != stations.end(); ++st_iter) { + Station *st = *st_iter; + if (_date - st->build_date < 30 * MAX_MONTHS_RECENTLY_NEW_STATION) { + return true; + } + } + return false; +} + + /** Change industry production or do closure * @param i Industry for which changes are performed * @param monthly true if it's the monthly call, false if it's the random call @@ -2184,7 +2205,8 @@ } /* Close if needed and allowed */ - if (closeit && !CheckIndustryCloseDownProtection(i->type)) { + if (closeit && !CheckIndustryCloseDownProtection(i->type) + && !StationRecentlyBuiltNearby(i)) { i->prod_level = PRODLEVEL_CLOSURE; str = indspec->closure_text; }