Changeset - r27154:32c425976634
[Not reviewed]
master
0 2 0
Tyler Trahan - 14 months ago 2023-04-24 19:58:48
tyler@tylertrahan.com
Cleanup: Don't use a magic number when closing processing industries (#10710)
2 files changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/industry.h
Show inline comments
 
/*
 
 * This file is part of OpenTTD.
 
 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
 
 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
/** @file industry.h Base of all industries. */
 

	
 
#ifndef INDUSTRY_H
 
#define INDUSTRY_H
 

	
 
#include "newgrf_storage.h"
 
#include "subsidy_type.h"
 
#include "industry_map.h"
 
#include "industrytype.h"
 
#include "tilearea_type.h"
 
#include "station_base.h"
 

	
 

	
 
typedef Pool<Industry, IndustryID, 64, 64000> IndustryPool;
 
extern IndustryPool _industry_pool;
 

	
 
static const Year PROCESSING_INDUSTRY_ABANDONMENT_YEARS = 5; ///< If a processing industry doesn't produce for this many consecutive years, it may close.
 

	
 
/**
 
 * Production level maximum, minimum and default values.
 
 * It is not a value been really used in order to change, but rather an indicator
 
 * of how the industry is behaving.
 
 */
 
enum ProductionLevels {
 
	PRODLEVEL_CLOSURE = 0x00,  ///< signal set to actually close the industry
 
	PRODLEVEL_MINIMUM = 0x04,  ///< below this level, the industry is set to be closing
 
	PRODLEVEL_DEFAULT = 0x10,  ///< default level set when the industry is created
 
	PRODLEVEL_MAXIMUM = 0x80,  ///< the industry is running at full speed
 
};
 

	
 
/**
 
 * Flags to control/override the behaviour of an industry.
 
 * These flags are controlled by game scripts.
 
 */
 
enum IndustryControlFlags : byte {
 
	/** No flags in effect */
 
	INDCTL_NONE                   = 0,
 
	/** When industry production change is evaluated, rolls to decrease are ignored. */
 
	INDCTL_NO_PRODUCTION_DECREASE = 1 << 0,
 
	/** When industry production change is evaluated, rolls to increase are ignored. */
 
	INDCTL_NO_PRODUCTION_INCREASE = 1 << 1,
 
	/**
src/industry_cmd.cpp
Show inline comments
 
@@ -2836,49 +2836,49 @@ static void ChangeIndustryProduction(Ind
 
				/* Do not stop closing the industry when it has the lowest possible production rate */
 
				if (new_prod == old_prod && old_prod > 1) {
 
					closeit = false;
 
					continue;
 
				}
 

	
 
				percent = (old_prod == 0) ? 100 : (new_prod * 100 / old_prod - 100);
 
				i->production_rate[j] = new_prod;
 

	
 
				/* Close the industry when it has the lowest possible production rate */
 
				if (new_prod > 1) closeit = false;
 

	
 
				if (abs(percent) >= 10) {
 
					ReportNewsProductionChangeIndustry(i, i->produced_cargo[j], percent);
 
				}
 
			}
 
		}
 
	}
 

	
 
	/* If override flags are set, prevent actually changing production if any was decided on */
 
	if ((i->ctlflags & INDCTL_NO_PRODUCTION_DECREASE) && (div > 0 || increment < 0)) return;
 
	if ((i->ctlflags & INDCTL_NO_PRODUCTION_INCREASE) && (mul > 0 || increment > 0)) return;
 

	
 
	if (!callback_enabled && (indspec->life_type & INDUSTRYLIFE_PROCESSING)) {
 
		if ( (byte)(TimerGameCalendar::year - i->last_prod_year) >= 5 && Chance16(1, original_economy ? 2 : 180)) {
 
		if (TimerGameCalendar::year - i->last_prod_year >= PROCESSING_INDUSTRY_ABANDONMENT_YEARS && Chance16(1, original_economy ? 2 : 180)) {
 
			closeit = true;
 
		}
 
	}
 

	
 
	/* Increase if needed */
 
	while (mul-- != 0 && i->prod_level < PRODLEVEL_MAXIMUM) {
 
		i->prod_level = std::min<int>(i->prod_level * 2, PRODLEVEL_MAXIMUM);
 
		recalculate_multipliers = true;
 
		if (str == STR_NULL) str = indspec->production_up_text;
 
	}
 

	
 
	/* Decrease if needed */
 
	while (div-- != 0 && !closeit) {
 
		if (i->prod_level == PRODLEVEL_MINIMUM) {
 
			closeit = true;
 
			break;
 
		} else {
 
			i->prod_level = std::max<int>(i->prod_level / 2, PRODLEVEL_MINIMUM);
 
			recalculate_multipliers = true;
 
			if (str == STR_NULL) str = indspec->production_down_text;
 
		}
 
	}
 

	
 
	/* Increase or Decreasing the production level if needed */
0 comments (0 inline, 0 general)