summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ai.c12
-rw-r--r--disaster_cmd.c10
-rw-r--r--economy.c2
-rw-r--r--industry.h1
-rw-r--r--industry_cmd.c15
-rw-r--r--industry_gui.c2
-rw-r--r--town_cmd.c2
7 files changed, 25 insertions, 19 deletions
diff --git a/ai.c b/ai.c
index 855c39c22..2be8243c1 100644
--- a/ai.c
+++ b/ai.c
@@ -1416,7 +1416,7 @@ static void AiWantOilRigAircraftRoute(Player *p)
t = AiFindRandomTown();
if (t != NULL) {
// Find a random oil rig industry
- in = DEREF_INDUSTRY(RandomRange(lengthof(_industries)));
+ in = DEREF_INDUSTRY(RandomRange(_total_industries));
if (in != NULL && in->type == IT_OIL_RIG) {
if (GetTileDist(t->xy, in->xy) < 60)
break;
@@ -2482,13 +2482,13 @@ static bool AiCheckRoadResources(TileIndex tile, const AiDefaultBlockData *p, by
{
uint values[NUM_CARGO];
int rad;
-
+
if (_patches.modified_catchment) {
- rad = CA_TRUCK; //Same as CA_BUS at the moment?
+ rad = CA_TRUCK; //Same as CA_BUS at the moment?
} else { //change that at some point?
rad = 4;
}
-
+
for(;;p++) {
if (p->mode == 4) {
return true;
@@ -3354,9 +3354,9 @@ static bool AiCheckAirportResources(TileIndex tile, const AiDefaultBlockData *p,
int w,h;
uint tile2;
int rad;
-
+
if (_patches.modified_catchment) {
- rad = CA_AIR_LARGE; //I Have NFI what airport the
+ rad = CA_AIR_LARGE; //I Have NFI what airport the
} else { //AI is going to build here
rad = 4;
}
diff --git a/disaster_cmd.c b/disaster_cmd.c
index a1bf71644..7ea7f747c 100644
--- a/disaster_cmd.c
+++ b/disaster_cmd.c
@@ -755,7 +755,9 @@ static void Disaster2_Init()
Vehicle *v,*u;
int x,y;
- for(found=NULL,i=_industries; i != endof(_industries); i++) {
+ found = NULL;
+
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 &&
i->type == IT_OIL_REFINERY &&
(found==NULL || CHANCE16(1,2))) {
@@ -789,7 +791,9 @@ static void Disaster3_Init()
Vehicle *v,*u,*w;
int x,y;
- for(found=NULL,i=_industries; i != endof(_industries); i++) {
+ found = NULL;
+
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 &&
i->type == IT_FACTORY &&
(found==NULL || CHANCE16(1,2))) {
@@ -896,7 +900,7 @@ static void Disaster7_Init()
int index = Random() & 0xF;
do {
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
SetDParam(0, i->town->index);
diff --git a/economy.c b/economy.c
index 04bd4d7c1..67992d55c 100644
--- a/economy.c
+++ b/economy.c
@@ -1127,7 +1127,7 @@ static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces
* the cargo */
best = NULL;
u = _patches.station_spread + 8;
- for(ind = _industries; ind != endof(_industries); ind++) {
+ FOR_ALL_INDUSTRIES(ind) {
if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
== ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
ind->produced_cargo[0] != 0xFF &&
diff --git a/industry.h b/industry.h
index d0f7e43db..852f23bbd 100644
--- a/industry.h
+++ b/industry.h
@@ -28,6 +28,7 @@ struct Industry {
VARDEF int _total_industries; // For the AI: the amount of industries active
VARDEF Industry _industries[90];
#define DEREF_INDUSTRY(i) (&_industries[i])
+#define FOR_ALL_INDUSTRIES(i) for(i = _industries; i != endof(_industries); i++)
VARDEF bool _industry_sort_dirty;
void DeleteIndustry(Industry *is);
diff --git a/industry_cmd.c b/industry_cmd.c
index 1cf301282..2e57b59fc 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1105,7 +1105,7 @@ void OnTick_Industry()
if (_game_mode == GM_EDITOR)
return;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0)
ProduceIndustryGoods(i);
}
@@ -1233,7 +1233,7 @@ static Town *CheckMultipleIndustryInTown(uint tile, int type)
if (_patches.multiple_industry_per_town)
return t;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 &&
i->type == (byte)type &&
i->town == t) {
@@ -1366,7 +1366,7 @@ static bool CheckIfTooCloseToIndustry(uint tile, int type)
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) )
return true;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
// check if an industry that accepts the same goods is nearby
if (i->xy != 0 &&
(GetTileDist1D(tile, i->xy) <= 14) &&
@@ -1391,7 +1391,7 @@ static Industry *AllocateIndustry()
{
Industry *i;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy == 0) {
int index = i - _industries;
if (index > _total_industries) _total_industries = index;
@@ -1807,7 +1807,7 @@ void IndustryMonthlyLoop()
byte old_player = _current_player;
_current_player = OWNER_NONE;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0)
UpdateIndustryStatistics(i);
}
@@ -1887,9 +1887,10 @@ static const byte _industry_desc[] = {
static void Save_INDY()
{
Industry *ind;
- int i;
+ int i = 0;
// Write the vehicles
- for(ind=_industries,i=0; i!=lengthof(_industries); ind++,i++) {
+ FOR_ALL_INDUSTRIES(ind) {
+ i++;
if (ind->xy != 0) {
SlSetArrayIndex(i);
SlObject(ind, _industry_desc);
diff --git a/industry_gui.c b/industry_gui.c
index a3de1511a..76b92a7ed 100644
--- a/industry_gui.c
+++ b/industry_gui.c
@@ -458,7 +458,7 @@ static void MakeSortedIndustryList()
Industry *i;
int n = 0, index = 0;
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if(i->xy)
_industry_sort[n++] = index;
diff --git a/town_cmd.c b/town_cmd.c
index 2830ea23b..bb72d2bf1 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1375,7 +1375,7 @@ void DeleteTown(Town *t)
_town_sort_dirty = true;
// Delete all industries belonging to the town
- for(i=_industries; i != endof(_industries); i++) {
+ FOR_ALL_INDUSTRIES(i) {
if (i->xy && i->town == t)
DeleteIndustry(i);
}