(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
authortruelight
Thu, 30 Dec 2004 10:03:35 +0000
changeset 830 36c1366367e4
parent 829 e7b66723eba7
child 831 d706427d9e23
(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too
ai.c
disaster_cmd.c
economy.c
industry.h
industry_cmd.c
industry_gui.c
town_cmd.c
--- a/ai.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/ai.c	Thu Dec 30 10:03:35 2004 +0000
@@ -1416,7 +1416,7 @@
 		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 @@
 {
 	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 @@
 	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;
 	}
--- a/disaster_cmd.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/disaster_cmd.c	Thu Dec 30 10:03:35 2004 +0000
@@ -755,7 +755,9 @@
 	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 @@
 	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 @@
 	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);
--- a/economy.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/economy.c	Thu Dec 30 10:03:35 2004 +0000
@@ -1127,7 +1127,7 @@
 	 * 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 &&
--- a/industry.h	Thu Dec 30 09:46:40 2004 +0000
+++ b/industry.h	Thu Dec 30 10:03:35 2004 +0000
@@ -28,6 +28,7 @@
 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);
 
--- a/industry_cmd.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/industry_cmd.c	Thu Dec 30 10:03:35 2004 +0000
@@ -1105,7 +1105,7 @@
 	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 @@
 	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 @@
 	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 @@
 {
 	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 @@
 	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 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);
--- a/industry_gui.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/industry_gui.c	Thu Dec 30 10:03:35 2004 +0000
@@ -458,7 +458,7 @@
 	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;
 
--- a/town_cmd.c	Thu Dec 30 09:46:40 2004 +0000
+++ b/town_cmd.c	Thu Dec 30 10:03:35 2004 +0000
@@ -1375,7 +1375,7 @@
 	_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);
 	}