diff options
author | belugas <belugas@openttd.org> | 2007-05-18 00:33:47 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2007-05-18 00:33:47 +0000 |
commit | 380d18fb69b0318f9c442526572ebf589b8e5d54 (patch) | |
tree | 0f4edac96e152260deb0ea541ace05ad039c8170 /src/ai/default | |
parent | 44ddf033ed4915d533420be8cadadeec91ed323c (diff) | |
download | openttd-380d18fb69b0318f9c442526572ebf589b8e5d54.tar.xz |
(svn r9867) -Codechange: Remove data duplication. The exact same values can be found in the industry spec, so take it from there instead.
Diffstat (limited to 'src/ai/default')
-rw-r--r-- | src/ai/default/default.cpp | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index e61f3a635..8533e6eba 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -543,6 +543,7 @@ static void AiFindSubsidyPassengerRoute(FoundRoute *fr) static void AiFindRandomIndustryRoute(FoundRoute *fr) { Industry* i; + const IndustrySpec *indsp; uint32 r; CargoID cargo; @@ -556,8 +557,9 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) if (i == NULL) return; // pick a random produced cargo - cargo = i->produced_cargo[0]; - if (r & 1 && i->produced_cargo[1] != CT_INVALID) cargo = i->produced_cargo[1]; + indsp = GetIndustrySpec(i->type); + cargo = indsp->produced_cargo[0]; + if (r & 1 && indsp->produced_cargo[1] != CT_INVALID) cargo = indsp->produced_cargo[1]; fr->cargo = cargo; @@ -567,12 +569,16 @@ static void AiFindRandomIndustryRoute(FoundRoute *fr) if (cargo != CT_GOODS && cargo != CT_FOOD) { // pick a dest, and see if it can receive Industry* i2 = AiFindRandomIndustry(); + if (i2 == NULL) { + return; + } + + indsp = GetIndustrySpec(i2->type); - if (i2 == NULL || i == i2 || ( - i2->accepts_cargo[0] != cargo && - i2->accepts_cargo[1] != cargo && - i2->accepts_cargo[2] != cargo) - ) { + if (i == i2 || + (indsp->accepts_cargo[0] != cargo && + indsp->accepts_cargo[1] != cargo && + indsp->accepts_cargo[2] != cargo)) { return; } @@ -664,9 +670,10 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask) } } else { const Industry* i = (const Industry*)fr->from; + const IndustrySpec *indsp = GetIndustrySpec(i->type); - if (i->pct_transported[fr->cargo != i->produced_cargo[0]] > 0x99 || - i->total_production[fr->cargo != i->produced_cargo[0]] == 0) { + if (i->pct_transported[fr->cargo != indsp->produced_cargo[0]] > 0x99 || + i->total_production[fr->cargo != indsp->produced_cargo[0]] == 0) { return false; } } |