Changeset - r7608:77bc663268b5
[Not reviewed]
master
0 2 0
belugas - 17 years ago 2007-09-22 00:59:27
belugas@openttd.org
(svn r11137) -Feature: [NewGRF] Add support for bit 17 of property 1A for Industries. This bit enables the protection of the last instance of an industry type once raise.
2 files changed with 27 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
@@ -78,12 +78,13 @@ enum IndustyBehaviour {
 
	INDUSTRYBEH_BEFORE_1950           = 1 << 8,  ///< can only be built before 1950 (oil wells)
 
	INDUSTRYBEH_AFTER_1960            = 1 << 9,  ///< can only be built after 1960 (oil rigs)
 
	INDUSTRYBEH_AI_AIRSHIP_ROUTES     = 1 << 10, ///< ai will attempt to establish air/ship routes to this industry (oil rig)
 
	INDUSTRYBEH_AIRPLANE_ATTACKS      = 1 << 11, ///< can be exploded by a military airplane (oil refinery)
 
	INDUSTRYBEH_CHOPPER_ATTACKS       = 1 << 12, ///< can be exploded by a military helicopter (factory)
 
	INDUSTRYBEH_CAN_SUBSIDENCE        = 1 << 13, ///< can cause a subsidence (coal mine, shaft that collapses)
 
	INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type
 
};
 

	
 

	
 
DECLARE_ENUM_AS_BIT_SET(IndustyBehaviour);
 

	
 
struct Industry;
src/industry_cmd.cpp
Show inline comments
 
@@ -1691,12 +1691,30 @@ void GenerateIndustries()
 
				if (chance > 0) PlaceInitialIndustry(it, chance);
 
			}
 
		}
 
	}
 
}
 

	
 
/**
 
 * Protects an industry from closure if the appropriate flags and conditions are met
 
 * INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the
 
 * count of industries of this type must one (or lower) in order to be protected
 
 * against closure.
 
 * @param type IndustryType been queried
 
 * @result true if protection is on, false otherwise (except for oil wells)
 
 */
 
static bool CheckIndustryCloseDownProtection(IndustryType type)
 
{
 
	const IndustrySpec *indspec = GetIndustrySpec(type);
 

	
 
	/* oil wells (or the industries with that flag set) are always allowed to closedown */
 
	if (indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD && _opt.landscape == LT_TEMPERATE) return false;
 
	return (indspec->behaviour & INDUSTRYBEH_CANCLOSE_LASTINSTANCE && GetIndustryTypeCount(type) <= 1);
 
}
 

	
 

	
 
/** Change industry production or do closure
 
 * @param i Industry for which changes are performed
 
 */
 
static void ExtChangeIndustryProduction(Industry *i)
 
{
 
	bool closeit = true;
 
@@ -1749,13 +1767,13 @@ static void ExtChangeIndustryProduction(
 

	
 
	if ((indspec->life_type & INDUSTRYLIFE_PROCESSING) != 0) {
 
		if ((byte)(_cur_year - i->last_prod_year) < 5 || !CHANCE16(1, 180)) closeit = false;
 
	}
 

	
 
	/* If industry will be closed down, show this */
 
	if (closeit) {
 
	if (closeit && !CheckIndustryCloseDownProtection(i->type)) {
 
		i->prod_level = 0;
 
		SetDParam(0, i->index);
 
		AddNewsItem(
 
			indspec->closure_text,
 
			NEWS_FLAGS(NM_THIN, NF_VIEWPORT | NF_TILE, NT_OPENCLOSE, 0),
 
			i->xy + TileDiffXY(1, 1), 0
 
@@ -1892,27 +1910,31 @@ static void ChangeIndustryProduction(Ind
 

	
 
					str = indspec->production_up_text;
 
				}
 
			} else {
 
				/* Decrease production */
 
				if (i->prod_level == 4) {
 
					i->prod_level = 0;
 
					str = indspec->closure_text;
 
					/* Really set the production to 0 when the industrytype allows it,
 
					 * since it is equivalent to closing it. */
 
					if (!CheckIndustryCloseDownProtection(i->type)) {
 
						i->prod_level = 0;
 
						str = indspec->closure_text;
 
					}
 
				} else {
 
					i->prod_level >>= 1;
 
					i->production_rate[0] = (i->production_rate[0] + 1) >> 1;
 
					i->production_rate[1] = (i->production_rate[1] + 1) >> 1;
 

	
 
					str = indspec->production_down_text;
 
				}
 
			}
 
		}
 
	}
 
	if (indspec->life_type & INDUSTRYLIFE_PROCESSING) {
 
		/* maybe close */
 
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2)) {
 
		if ( (byte)(_cur_year - i->last_prod_year) >= 5 && CHANCE16(1, 2) && !CheckIndustryCloseDownProtection(i->type)) {
 
			i->prod_level = 0;
 
			str = indspec->closure_text;
 
		}
 
	}
 

	
 
	if (str != STR_NULL) {
0 comments (0 inline, 0 general)