From 380d18fb69b0318f9c442526572ebf589b8e5d54 Mon Sep 17 00:00:00 2001 From: belugas Date: Fri, 18 May 2007 00:33:47 +0000 Subject: (svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead. --- src/economy.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/economy.cpp') diff --git a/src/economy.cpp b/src/economy.cpp index 25b99892b..c68fe5672 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -957,6 +957,7 @@ static void FindSubsidyPassengerRoute(FoundRoute *fr) static void FindSubsidyCargoRoute(FoundRoute *fr) { Industry *i; + const IndustrySpec *ind; int trans, total; CargoID cargo; @@ -964,14 +965,15 @@ static void FindSubsidyCargoRoute(FoundRoute *fr) fr->from = i = GetRandomIndustry(); if (i == NULL) return; + ind = GetIndustrySpec(i->type); /* Randomize cargo type */ - if (Random()&1 && i->produced_cargo[1] != CT_INVALID) { - cargo = i->produced_cargo[1]; + if (HASBIT(Random(), 0) && ind->produced_cargo[1] != CT_INVALID) { + cargo = ind->produced_cargo[1]; trans = i->pct_transported[1]; total = i->total_production[1]; } else { - cargo = i->produced_cargo[0]; + cargo = ind->produced_cargo[0]; trans = i->pct_transported[0]; total = i->total_production[0]; } @@ -998,13 +1000,19 @@ static void FindSubsidyCargoRoute(FoundRoute *fr) } else { /* The destination is an industry */ Industry *i2 = GetRandomIndustry(); + if (i2 == NULL) { + return; + } + + ind = GetIndustrySpec(i2->type); /* The industry must accept the cargo */ - if (i == i2 || i == NULL || - (cargo != i2->accepts_cargo[0] && - cargo != i2->accepts_cargo[1] && - cargo != i2->accepts_cargo[2])) + if (i == i2 || + (cargo != ind->accepts_cargo[0] && + cargo != ind->accepts_cargo[1] && + cargo != ind->accepts_cargo[2])) { return; + } fr->distance = DistanceManhattan(i->xy, i2->xy); fr->to = i2; } -- cgit v1.2.3-54-g00ecf