summaryrefslogtreecommitdiff
path: root/ai
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-22 15:33:35 +0000
committertruelight <truelight@openttd.org>2006-08-22 15:33:35 +0000
commit0461d896123b918b492a3d16439bb46b041528cd (patch)
tree618708068f10739a382af83313db9c96b4744ef5 /ai
parent4c2abf1de53e28a5c3c6c6920efabc4653693c4c (diff)
downloadopenttd-0461d896123b918b492a3d16439bb46b041528cd.tar.xz
(svn r6047) -Codechange: FOR_ALL now _only_ loops valid items, and skips invalid ones
-Codechange: use IsValidXXX where ever possible Note: both changes to prepare for new pool system, which needs those changes. For every pool there are 2 ugly lines, which will be removed when done implementing new pool system. Based on FS#13 by blathijs, partly implemented.
Diffstat (limited to 'ai')
-rw-r--r--ai/default/default.c17
-rw-r--r--ai/trolly/trolly.c30
2 files changed, 18 insertions, 29 deletions
diff --git a/ai/default/default.c b/ai/default/default.c
index cd04bae21..c57ba0c51 100644
--- a/ai/default/default.c
+++ b/ai/default/default.c
@@ -90,7 +90,7 @@ static void AiStateVehLoop(Player *p)
index = (p->ai.cur_veh == NULL) ? 0 : p->ai.cur_veh->index + 1;
FOR_ALL_VEHICLES_FROM(v, index) {
- if (v->type == 0 || v->owner != _current_player) continue;
+ if (v->owner != _current_player) continue;
if ((v->type == VEH_Train && v->subtype == 0) ||
v->type == VEH_Road ||
@@ -411,7 +411,7 @@ static void AiStateCheckReplaceVehicle(Player *p)
{
const Vehicle* v = p->ai.cur_veh;
- if (v->type == 0 ||
+ if (!IsValidVehicle(v) ||
v->owner != _current_player ||
v->type > VEH_Ship ||
_veh_check_replace_proc[v->type - VEH_Train](p, v) == INVALID_ENGINE) {
@@ -428,7 +428,7 @@ static void AiStateDoReplaceVehicle(Player *p)
p->ai.state = AIS_VEH_LOOP;
// vehicle is not owned by the player anymore, something went very wrong.
- if (v->type == 0 || v->owner != _current_player) return;
+ if (!IsValidVehicle(v) || v->owner != _current_player) return;
_veh_do_replace_proc[v->type - VEH_Train](p);
}
@@ -442,13 +442,13 @@ typedef struct FoundRoute {
static Town *AiFindRandomTown(void)
{
Town *t = GetTown(RandomRange(_total_towns));
- return (t->xy != 0) ? t : NULL;
+ return IsValidTown(t) ? t : NULL;
}
static Industry *AiFindRandomIndustry(void)
{
Industry *i = GetIndustry(RandomRange(_total_industries));
- return (i->xy != 0) ? i : NULL;
+ return IsValidIndustry(i) ? i : NULL;
}
static void AiFindSubsidyIndustryRoute(FoundRoute *fr)
@@ -608,7 +608,7 @@ static bool AiCheckIfRouteIsGood(Player *p, FoundRoute *fr, byte bitmask)
FOR_ALL_STATIONS(st) {
int cur;
- if (st->xy == 0 || st->owner != _current_player) continue;
+ if (st->owner != _current_player) continue;
cur = DistanceMax(from_tile, st->xy);
if (cur < dist) dist = cur;
cur = DistanceMax(to_tile, st->xy);
@@ -3243,9 +3243,6 @@ static void AiStateAirportStuff(Player *p)
aib = &p->ai.src + i;
FOR_ALL_STATIONS(st) {
- // Dismiss ghost stations.
- if (st->xy == 0) continue;
-
// Is this an airport?
if (!(st->facilities & FACIL_AIRPORT)) continue;
@@ -3578,7 +3575,7 @@ static void AiStateRemoveStation(Player *p)
// Go through all stations and delete those that aren't in use
used = in_use;
FOR_ALL_STATIONS(st) {
- if (st->xy != 0 && st->owner == _current_player && !*used &&
+ if (st->owner == _current_player && !*used &&
( (st->bus_stops != NULL && (tile = st->bus_stops->xy) != 0) ||
(st->truck_stops != NULL && (tile = st->truck_stops->xy)) != 0 ||
(tile = st->train_tile) != 0 ||
diff --git a/ai/trolly/trolly.c b/ai/trolly/trolly.c
index aec49c9b8..ea41cdac3 100644
--- a/ai/trolly/trolly.c
+++ b/ai/trolly/trolly.c
@@ -231,8 +231,6 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
// and sometimes it takes up to 4 months before the stats are corectly.
// This way we don't get 12 busstations in one city of 100 population ;)
FOR_ALL_STATIONS(st) {
- // Is it an active station
- if (st->xy == 0) continue;
// Do we own it?
if (st->owner == _current_player) {
// Are we talking busses?
@@ -291,9 +289,6 @@ static bool AiNew_Check_City_or_Industry(Player *p, int ic, byte type)
// else we don't do it. This is done, because stat updates can be slow
// and sometimes it takes up to 4 months before the stats are corectly.
FOR_ALL_STATIONS(st) {
- // Is it an active station
- if (st->xy == 0) continue;
-
// Do we own it?
if (st->owner == _current_player) {
// Are we talking trucks?
@@ -620,21 +615,19 @@ static void AiNew_State_FindStation(Player *p)
}
FOR_ALL_STATIONS(st) {
- if (st->xy != 0) {
- if (st->owner == _current_player) {
- if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) {
- if (st->town == town) {
- // Check how much cargo there is left in the station
- if ((st->goods[p->ainew.cargo].waiting_acceptance & 0xFFF) > RoadVehInfo(i)->capacity * AI_STATION_REUSE_MULTIPLER) {
- if (AiNew_CheckVehicleStation(p, st)) {
- // We did found a station that was good enough!
- new_tile = st->xy;
- direction = GetRoadStopDir(st->xy);
- break;
- }
+ if (st->owner == _current_player) {
+ if (p->ainew.tbt == AI_BUS && (FACIL_BUS_STOP & st->facilities) == FACIL_BUS_STOP) {
+ if (st->town == town) {
+ // Check how much cargo there is left in the station
+ if ((st->goods[p->ainew.cargo].waiting_acceptance & 0xFFF) > RoadVehInfo(i)->capacity * AI_STATION_REUSE_MULTIPLER) {
+ if (AiNew_CheckVehicleStation(p, st)) {
+ // We did found a station that was good enough!
+ new_tile = st->xy;
+ direction = GetRoadStopDir(st->xy);
+ break;
}
- count++;
}
+ count++;
}
}
}
@@ -1302,7 +1295,6 @@ static void AiNew_State_CheckAllVehicles(Player *p)
Vehicle *v;
FOR_ALL_VEHICLES(v) {
- if (v->type == 0) continue;
if (v->owner != p->index) continue;
// Currently, we only know how to handle road-vehicles
if (v->type != VEH_Road) continue;