summaryrefslogtreecommitdiff
path: root/ai/default
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
commit505566da5ca515428eed3b618f2f67aac2077f32 (patch)
tree618708068f10739a382af83313db9c96b4744ef5 /ai/default
parent650b9be724863bb91a2bd0b25d4e26858bc8b3fa (diff)
downloadopenttd-505566da5ca515428eed3b618f2f67aac2077f32.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/default')
-rw-r--r--ai/default/default.c17
1 files changed, 7 insertions, 10 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 ||