Index: src/date_type.h =================================================================== --- src/date_type.h (revision 12375) +++ src/date_type.h (working copy) @@ -44,10 +44,14 @@ typedef uint8 Month; typedef uint8 Day; +/** + * Data structure to convert between Date and triplet (year, month, and day). + * @see ConvertDateToYMD(), ConvertYMDToDate() + */ struct YearMonthDay { - Year year; - Month month; - Day day; + Year year; ///< Year (0...) + Month month; ///< Month (0..11) + Day day; ///< Day (1..31) }; static const Year INVALID_YEAR = -1; Index: src/date.cpp =================================================================== --- src/date.cpp (revision 12375) +++ src/date.cpp (working copy) @@ -19,9 +19,9 @@ #include "saveload.h" #endif -Year _cur_year; -Month _cur_month; -Date _date; +Year _cur_year; ///< Current year, starting at 0 +Month _cur_month; ///< Current month (0..11) +Date _date; ///< Current date in days (day counter) DateFract _date_fract; Index: src/industry_cmd.cpp =================================================================== --- src/industry_cmd.cpp (revision 12375) +++ src/industry_cmd.cpp (working copy) @@ -57,6 +57,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. @@ -2013,6 +2015,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 @@ -2164,7 +2185,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; }