Changeset - r12934:d737369db59b
[Not reviewed]
master
0 1 0
smatz - 15 years ago 2009-09-06 22:05:53
smatz@openttd.org
(svn r17437) -Change: don't accept cargo produced in the same industry (generalise and improve the check used only for valuables)
1 file changed with 4 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -820,16 +820,12 @@ Money GetTransportedGoodsIncome(uint num
 
			 * by the amount of cargo moved and the price factor, then gets
 
			 * divided by 8192." */
 
			return result * num_pieces * cs->current_payment / 8192;
 
		}
 
	}
 

	
 
	/* zero the distance (thus income) if it's the bank and very short transport. */
 
	if (_settings_game.game_creation.landscape == LT_TEMPERATE && cs->label == 'VALU' && dist < 10) return 0;
 

	
 

	
 
	static const int MIN_TIME_FACTOR = 31;
 
	static const int MAX_TIME_FACTOR = 255;
 

	
 
	const int days1 = cs->transit_days[0];
 
	const int days2 = cs->transit_days[1];
 
	const int days_over_days1 = max(   transit_days - days1, 0);
 
@@ -858,25 +854,27 @@ static SmallIndustryList _cargo_delivery
 
 * All cargo is delivered to the nearest (Manhattan) industry to the station sign, which is inside the acceptance rectangle and actually accepts the cargo.
 
 * @param st The station that accepted the cargo
 
 * @param cargo_type Type of cargo delivered
 
 * @param nun_pieces Amount of cargo delivered
 
 * @return actually accepted pieces of cargo
 
 */
 
static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint num_pieces)
 
static uint DeliverGoodsToIndustry(const Station *st, CargoID cargo_type, uint num_pieces, IndustryID source)
 
{
 
	/* Find the nearest industrytile to the station sign inside the catchment area, whose industry accepts the cargo.
 
	 * This fails in three cases:
 
	 *  1) The station accepts the cargo because there are enough houses around it accepting the cargo.
 
	 *  2) The industries in the catchment area temporarily reject the cargo, and the daily station loop has not yet updated station acceptance.
 
	 *  3) The results of callbacks CBID_INDUSTRY_REFUSE_CARGO and CBID_INDTILE_CARGO_ACCEPTANCE are inconsistent. (documented behaviour)
 
	 */
 

	
 
	uint accepted = 0;
 

	
 
	for (uint i = 0; i < st->industries_near.Length() && num_pieces != 0; i++) {
 
		Industry *ind = st->industries_near[i];
 
		if (ind->index == source) continue;
 

	
 
		const IndustrySpec *indspec = GetIndustrySpec(ind->type);
 

	
 
		uint cargo_index;
 
		for (cargo_index = 0; cargo_index < lengthof(ind->accepts_cargo); cargo_index++) {
 
			if (cargo_type == ind->accepts_cargo[cargo_index]) break;
 
		}
 
@@ -926,13 +924,13 @@ static Money DeliverGoods(int num_pieces
 
	/* Increase town's counter for some special goods types */
 
	const CargoSpec *cs = CargoSpec::Get(cargo_type);
 
	if (cs->town_effect == TE_FOOD) st->town->new_act_food += num_pieces;
 
	if (cs->town_effect == TE_WATER) st->town->new_act_water += num_pieces;
 

	
 
	/* Give the goods to the industry. */
 
	uint accepted = DeliverGoodsToIndustry(st, cargo_type, num_pieces);
 
	uint accepted = DeliverGoodsToIndustry(st, cargo_type, num_pieces, src_type == ST_INDUSTRY ? src : INVALID_INDUSTRY);
 

	
 
	/* Determine profit */
 
	Money profit = GetTransportedGoodsIncome(accepted, DistanceManhattan(source_tile, st->xy), days_in_transit, cargo_type);
 

	
 
	/* Modify profit if a subsidy is in effect */
 
	if (CheckSubsidised(cargo_type, company->index, src_type, src, st))  {
0 comments (0 inline, 0 general)