summaryrefslogtreecommitdiff
path: root/src/ai/default
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2007-05-18 00:33:47 +0000
committerbelugas <belugas@openttd.org>2007-05-18 00:33:47 +0000
commitc4b90f31372b9a88dea80afa01b920a4f3f4d3db (patch)
tree0f4edac96e152260deb0ea541ace05ad039c8170 /src/ai/default
parentb007a3419cd8827e6a88e2c9e245d3c24746e4d5 (diff)
downloadopenttd-c4b90f31372b9a88dea80afa01b920a4f3f4d3db.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.cpp25
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;
}
}