summaryrefslogtreecommitdiff
path: root/src/ai
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
commit380d18fb69b0318f9c442526572ebf589b8e5d54 (patch)
tree0f4edac96e152260deb0ea541ace05ad039c8170 /src/ai
parent44ddf033ed4915d533420be8cadadeec91ed323c (diff)
downloadopenttd-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')
-rw-r--r--src/ai/default/default.cpp25
-rw-r--r--src/ai/trolly/trolly.cpp31
2 files changed, 33 insertions, 23 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;
}
}
diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp
index 7e888f629..f509afa7e 100644
--- a/src/ai/trolly/trolly.cpp
+++ b/src/ai/trolly/trolly.cpp
@@ -271,6 +271,7 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
}
if (type == AI_INDUSTRY) {
const Industry* i = GetIndustry(ic);
+ const IndustrySpec *indsp = GetIndustrySpec(i->type);
const Station* st;
int count = 0;
int j = 0;
@@ -279,7 +280,7 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
// No limits on delevering stations!
// Or for industry that does not give anything yet
- if (i->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
+ if (indsp->produced_cargo[0] == CT_INVALID || i->total_production[0] == 0) return true;
if (i->total_production[0] - i->total_transported[0] < AI_CHECKCITY_NEEDED_CARGO) return false;
@@ -302,13 +303,13 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
// we want to know if this station gets the same good. If so,
// we want to know its rating. If it is too high, we are not going
// to build there
- if (i->produced_cargo[0] == CT_INVALID) continue;
+ if (indsp->produced_cargo[0] == CT_INVALID) continue;
// It does not take this cargo
- if (!st->goods[i->produced_cargo[0]].last_speed) continue;
+ if (!st->goods[indsp->produced_cargo[0]].last_speed) continue;
// Is it around our industry
if (DistanceManhattan(st->xy, i->xy) > 5) continue;
// It does take this cargo.. what is his rating?
- if (st->goods[i->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
+ if (st->goods[indsp->produced_cargo[0]].rating < AI_CHECKCITY_CARGO_RATING) continue;
j++;
// The rating is high.. a little chance that we still continue
// But if there are 2 stations of this size, we never go on...
@@ -458,17 +459,19 @@ static void AiNew_State_LocateRoute(Player *p)
}
} else if (p->ainew.tbt == AI_TRUCK) {
const Industry* ind_from = GetIndustry(p->ainew.from_ic);
+ const IndustrySpec *indsp_from = GetIndustrySpec(ind_from->type);
const Industry* ind_temp = GetIndustry(p->ainew.temp);
+ const IndustrySpec *indsp_temp = GetIndustrySpec(ind_temp->type);
bool found = false;
int max_cargo = 0;
uint i;
// TODO: in max_cargo, also check other cargo (beside [0])
// First we check if the from_ic produces cargo that this ic accepts
- if (ind_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
- for (i = 0; i < lengthof(ind_temp->accepts_cargo); i++) {
- if (ind_temp->accepts_cargo[i] == CT_INVALID) break;
- if (ind_from->produced_cargo[0] == ind_temp->accepts_cargo[i]) {
+ if (indsp_from->produced_cargo[0] != CT_INVALID && ind_from->total_production[0] != 0) {
+ for (i = 0; i < lengthof(indsp_temp->accepts_cargo); i++) {
+ if (indsp_temp->accepts_cargo[i] == CT_INVALID) break;
+ if (indsp_from->produced_cargo[0] == indsp_temp->accepts_cargo[i]) {
// Found a compatible industry
max_cargo = ind_from->total_production[0] - ind_from->total_transported[0];
found = true;
@@ -478,11 +481,11 @@ static void AiNew_State_LocateRoute(Player *p)
}
}
}
- if (!found && ind_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
+ if (!found && indsp_temp->produced_cargo[0] != CT_INVALID && ind_temp->total_production[0] != 0) {
// If not check if the current ic produces cargo that the from_ic accepts
- for (i = 0; i < lengthof(ind_from->accepts_cargo); i++) {
- if (ind_from->accepts_cargo[i] == CT_INVALID) break;
- if (ind_temp->produced_cargo[0] == ind_from->accepts_cargo[i]) {
+ for (i = 0; i < lengthof(indsp_from->accepts_cargo); i++) {
+ if (indsp_from->accepts_cargo[i] == CT_INVALID) break;
+ if (indsp_from->produced_cargo[0] == indsp_from->accepts_cargo[i]) {
// Found a compatbiel industry
found = true;
max_cargo = ind_temp->total_production[0] - ind_temp->total_transported[0];
@@ -501,9 +504,9 @@ static void AiNew_State_LocateRoute(Player *p)
distance <= max_cargo * AI_LOCATEROUTE_TRUCK_CARGO_DISTANCE) {
p->ainew.to_ic = p->ainew.temp;
if (p->ainew.from_deliver) {
- p->ainew.cargo = ind_from->produced_cargo[0];
+ p->ainew.cargo = indsp_from->produced_cargo[0];
} else {
- p->ainew.cargo = ind_temp->produced_cargo[0];
+ p->ainew.cargo = indsp_temp->produced_cargo[0];
}
p->ainew.state = AI_STATE_FIND_STATION;