From 44ddf033ed4915d533420be8cadadeec91ed323c Mon Sep 17 00:00:00 2001 From: rubidium Date: Thu, 17 May 2007 20:19:55 +0000 Subject: (svn r9866) -Codechange: remove the technical one-input-cargo-creates-one-output-cargo limit in the factories, sawmills, steelmills and the ones I'm forgetting to mention right now. Use of this functionality will come later. --- src/economy.cpp | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'src/economy.cpp') diff --git a/src/economy.cpp b/src/economy.cpp index 55136c28d..25b99892b 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1178,34 +1178,47 @@ int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, C static void DeliverGoodsToIndustry(TileIndex xy, CargoID cargo_type, int num_pieces) { - Industry* best = NULL; - Industry* ind; - uint u; + Industry *best = NULL; + Industry *ind; + const IndustrySpec *indspec; + uint best_dist; + uint accepted_cargo_index; /* Check if there's an industry close to the station that accepts the cargo * XXX - Think of something better to * 1) Only deliver to industries which are withing the catchment radius * 2) Distribute between industries if more then one is present */ - u = (_patches.station_spread + 8) * 2; + best_dist = (_patches.station_spread + 8) * 2; FOR_ALL_INDUSTRIES(ind) { - uint t; - - if (( cargo_type == ind->accepts_cargo[0] || - cargo_type == ind->accepts_cargo[1] || - cargo_type == ind->accepts_cargo[2] - ) && - ind->produced_cargo[0] != CT_INVALID && - ind->produced_cargo[0] != cargo_type && - (t = DistanceManhattan(ind->xy, xy)) < u) { - u = t; + indspec = GetIndustrySpec(ind->type); + + if (indspec->produced_cargo[0] == CT_INVALID) continue; + + uint i; + for (i = 0; i < lengthof(indspec->accepts_cargo); i++) { + if (cargo_type == indspec->accepts_cargo[i] && + (indspec->input_cargo_multiplier[i][0] != 0 || indspec->input_cargo_multiplier[i][1] != 0)) { + break; + } + } + + if (i == lengthof(indspec->accepts_cargo)) continue; + + uint dist = DistanceManhattan(ind->xy, xy); + + if (dist < best_dist) { best = ind; + best_dist = dist; + accepted_cargo_index = i; } } /* Found one? */ if (best != NULL) { + indspec = GetIndustrySpec(best->type); best->was_cargo_delivered = true; - best->cargo_waiting[0] = min(best->cargo_waiting[0] + num_pieces, 0xFFFF); + best->cargo_waiting[0] = min(best->cargo_waiting[0] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][0] / 256), 0xFFFF); + best->cargo_waiting[1] = min(best->cargo_waiting[1] + (num_pieces * indspec->input_cargo_multiplier[accepted_cargo_index][1] / 256), 0xFFFF); } } -- cgit v1.2.3-54-g00ecf