changeset 19297:2ba8abfee1f4 draft

(svn r24186) -Feature: [NewGRF] Callback to set industry production level on construction. (andythenorth)
author frosch <frosch@openttd.org>
date Sat, 28 Apr 2012 16:44:01 +0000
parents d34a985841b9
children b0976e095b98
files src/industry_cmd.cpp src/newgrf_callbacks.h src/table/newgrf_debug_data.h
diffstat 3 files changed, 25 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1655,8 +1655,6 @@
 	i->last_month_transported[1] = 0;
 	i->was_cargo_delivered = false;
 	i->last_prod_year = _cur_year;
-	i->last_month_production[0] = i->production_rate[0] * 8;
-	i->last_month_production[1] = i->production_rate[1] * 8;
 	i->founder = founder;
 
 	i->construction_date = _date;
@@ -1668,12 +1666,29 @@
 	 * else, chosen layout + 1 */
 	i->selected_layout = layout + 1;
 
-	if (!_generating_world) i->last_month_production[0] = i->last_month_production[1] = 0;
-
 	i->prod_level = PRODLEVEL_DEFAULT;
 
 	/* Call callbacks after the regular fields got initialised. */
 
+	if (HasBit(indspec->callback_mask, CBM_IND_PROD_CHANGE_BUILD)) {
+		uint16 res = GetIndustryCallback(CBID_INDUSTRY_PROD_CHANGE_BUILD, 0, Random(), i, type, INVALID_TILE);
+		if (res != CALLBACK_FAILED) {
+			if (res < PRODLEVEL_MINIMUM || res > PRODLEVEL_MAXIMUM) {
+				ErrorUnknownCallbackResult(indspec->grf_prop.grffile->grfid, CBID_INDUSTRY_PROD_CHANGE_BUILD, res);
+			} else {
+				i->prod_level = res;
+				i->RecomputeProductionMultipliers();
+			}
+		}
+	}
+
+	if (_generating_world) {
+		i->last_month_production[0] = i->production_rate[0] * 8;
+		i->last_month_production[1] = i->production_rate[1] * 8;
+	} else {
+		i->last_month_production[0] = i->last_month_production[1] = 0;
+	}
+
 	if (HasBit(indspec->callback_mask, CBM_IND_DECIDE_COLOUR)) {
 		uint16 res = GetIndustryCallback(CBID_INDUSTRY_DECIDE_COLOUR, 0, 0, i, type, INVALID_TILE);
 		if (res != CALLBACK_FAILED) {
@@ -2741,7 +2756,7 @@
 {
 	return _settings_game.economy.smooth_economy &&
 		!(HasBit(this->callback_mask, CBM_IND_PRODUCTION_256_TICKS) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL)) && // production callbacks
-		!(HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE));            // production change callbacks
+		!(HasBit(this->callback_mask, CBM_IND_MONTHLYPROD_CHANGE) || HasBit(this->callback_mask, CBM_IND_PRODUCTION_CHANGE) || HasBit(this->callback_mask, CBM_IND_PROD_CHANGE_BUILD)); // production change callbacks
 }
 
 static CommandCost TerraformTile_Industry(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
--- a/src/newgrf_callbacks.h
+++ b/src/newgrf_callbacks.h
@@ -275,6 +275,9 @@
 
 	/** Called to determine the cost factor for refitting a vehicle. */
 	CBID_VEHICLE_REFIT_COST              = 0x15E, // 15 bit callback
+
+	/** Called when industry is built to set initial production level. */
+	CBID_INDUSTRY_PROD_CHANGE_BUILD      = 0x15F, // 15 bit callback
 };
 
 /**
@@ -355,6 +358,7 @@
 	CBM_IND_DECIDE_COLOUR             = 11, ///< give a custom colour to newly build industries
 	CBM_IND_INPUT_CARGO_TYPES         = 12, ///< customize the cargoes the industry requires
 	CBM_IND_OUTPUT_CARGO_TYPES        = 13, ///< customize the cargoes the industry produces
+	CBM_IND_PROD_CHANGE_BUILD         = 14, ///< initialise production level on construction
 };
 
 /**
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -265,6 +265,7 @@
 	NICI(CBID_INDUSTRY_DECIDE_COLOUR,        CBM_IND_DECIDE_COLOUR),
 	NICI(CBID_INDUSTRY_INPUT_CARGO_TYPES,    CBM_IND_INPUT_CARGO_TYPES),
 	NICI(CBID_INDUSTRY_OUTPUT_CARGO_TYPES,   CBM_IND_OUTPUT_CARGO_TYPES),
+	NICI(CBID_INDUSTRY_PROD_CHANGE_BUILD,    CBM_IND_PROD_CHANGE_BUILD),
 	NIC_END()
 };