changeset 12267:fe4287ad4243 draft

(svn r16682) -Codechange: make (static) industry list used to trigger the industries' production compile unit static instead of passing it around as pointer
author rubidium <rubidium@openttd.org>
date Sun, 28 Jun 2009 14:36:25 +0000
parents c9e7d3ec5c1a
children 3a97d4e6f918
files src/economy.cpp
diffstat 1 files changed, 12 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -963,7 +963,6 @@
  * @param st The station that accepted the cargo
  * @param cargo_type Type of cargo delivered
  * @param nun_pieces Amount of cargo delivered
- * @param industry_set The destination industry will be inserted into this set
  * @note THIS FUNCTION WILL BE REMOVED SOON!
  */
 static Industry *DeliverGoodsToIndustryCheckOldStyle(const Station *st, CargoID cargo_type, int num_pieces)
@@ -1004,6 +1003,8 @@
 	return NULL;
 }
 
+/** The industries we've currently brought cargo to. */
+static SmallIndustryList _cargo_delivery_destinations;
 
 /**
  * Transfer goods from station to industry.
@@ -1011,9 +1012,8 @@
  * @param st The station that accepted the cargo
  * @param cargo_type Type of cargo delivered
  * @param nun_pieces Amount of cargo delivered
- * @param industry_set The destination industry will be inserted into this set
  */
-static void DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, int num_pieces, SmallIndustryList *industry_set)
+static void DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, int num_pieces)
 {
 	/* Find the nearest industrytile to the station sign inside the catchment area, whose industry accepts the cargo.
 	 * This fails in three cases:
@@ -1039,8 +1039,8 @@
 			if (res == 0) continue;
 		}
 
-		/* Insert the industry into industry_set, if not yet contained */
-		if (industry_set != NULL) industry_set->Include(ind);
+		/* Insert the industry into _cargo_delivery_destinations, if not yet contained */
+		_cargo_delivery_destinations.Include(ind);
 
 		assert(DeliverGoodsToIndustryCheckOldStyle(st, cargo_type, num_pieces) == ind); // safety check, will be removed soon
 
@@ -1059,11 +1059,10 @@
  * @param dest Station the cargo has been unloaded
  * @param source_tile The origin of the cargo for distance calculation
  * @param days_in_transit Travel time
- * @param industry_set The delivered industry will be inserted into this set, if not yet contained
  * @param company The company delivering the cargo
  * The cargo is just added to the stockpile of the industry. It is due to the caller to trigger the industry's production machinery
  */
-static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit, SmallIndustryList *industry_set, Company *company)
+static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit, Company *company)
 {
 	bool subsidised = false;
 
@@ -1088,7 +1087,7 @@
 	if (cs->town_effect == TE_WATER) s_to->town->new_act_water += num_pieces;
 
 	/* Give the goods to the industry. */
-	DeliverGoodsToIndustry(s_to, cargo_type, num_pieces, industry_set);
+	DeliverGoodsToIndustry(s_to, cargo_type, num_pieces);
 
 	/* Determine profit */
 	Money profit = GetTransportedGoodsIncome(num_pieces, DistanceManhattan(source_tile, s_to->xy), days_in_transit, cargo_type);
@@ -1167,10 +1166,6 @@
 	/* Start unloading in at the first possible moment */
 	front_v->load_unload_time_rem = 1;
 
-	/* Collect delivered industries */
-	static SmallIndustryList industry_set;
-	industry_set.Clear();
-
 	for (Vehicle *v = front_v; v != NULL; v = v->Next()) {
 		/* No cargo to unload */
 		if (v->cargo_cap == 0 || v->cargo.Empty() || (front_v->current_order.GetUnloadType() & OUFB_NO_UNLOAD)) continue;
@@ -1194,7 +1189,7 @@
 				st->time_since_unload = 0;
 
 				/* handle end of route payment */
-				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit, &industry_set, company);
+				Money profit = DeliverGoods(cp->count, v->cargo_type, cp->source, last_visited, cp->source_xy, cp->days_in_transit, company);
 				cp->paid_for = true;
 				route_profit   += profit; // display amount paid for final route delivery, A-D of a chain A-B-C-D
 				vehicle_profit += profit - cp->feeder_share;                    // whole vehicle is not payed for transfers picked up earlier
@@ -1224,11 +1219,12 @@
 		v->cargo.InvalidateCache();
 	}
 
-	/* Call the production machinery of industries only once for every vehicle chain */
-	const Industry * const *isend = industry_set.End();
-	for (Industry **iid = industry_set.Begin(); iid != isend; iid++) {
+	/* Call the production machinery of industries */
+	const Industry * const *isend = _cargo_delivery_destinations.End();
+	for (Industry **iid = _cargo_delivery_destinations.Begin(); iid != isend; iid++) {
 		TriggerIndustryProduction(*iid);
 	}
+	_cargo_delivery_destinations.Clear();
 
 	if (virtual_profit > 0) {
 		ShowFeederIncomeAnimation(front_v->x_pos, front_v->y_pos, front_v->z_pos, virtual_profit);