(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
authorpeter1138
Wed, 21 Mar 2007 13:19:01 +0000
changeset 6350 04b19f551aec
parent 6349 908a23fd464f
child 6351 8d0b6cce8d6d
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
src/aircraft_cmd.cpp
src/economy.cpp
src/economy.h
src/graph_gui.cpp
src/misc.cpp
src/misc_gui.cpp
src/newgrf.cpp
src/station_cmd.cpp
src/station_gui.cpp
src/town_cmd.cpp
src/train_gui.cpp
src/vehicle.cpp
src/vehicle_gui.cpp
--- a/src/aircraft_cmd.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/aircraft_cmd.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -1408,7 +1408,7 @@
 	if (GB(Random(), 0, 16) > prob) return;
 
 	/* Crash the airplane. Remove all goods stored at the station. */
-	for (uint i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		st->goods[i].rating = 1;
 		SB(st->goods[i].waiting_acceptance, 0, 12, 0);
 	}
--- a/src/economy.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/economy.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -652,7 +652,7 @@
 		_economy.max_loan += 50000;
 
 	inf = _economy.infl_amount_pr * 54;
-	for (uint i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		AddSingleInflation(
 			(int32*)_cargo_payment_rates + i,
 			_cargo_payment_rates_frac + i,
--- a/src/economy.h	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/economy.h	Wed Mar 21 13:19:01 2007 +0000
@@ -66,6 +66,6 @@
 void DeleteSubsidyWithStation(StationID index);
 
 int32 GetTransportedGoodsIncome(uint num_pieces, uint dist, byte transit_days, CargoID cargo_type);
-uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount);
+uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount);
 
 #endif /* ECONOMY_H */
--- a/src/graph_gui.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/graph_gui.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -721,7 +721,7 @@
 			gd.x_values_increment = 10;
 
 			uint i = 0;
-			for (CargoID c = 0; c != NUM_CARGO; c++) {
+			for (CargoID c = 0; c < NUM_CARGO; c++) {
 				const CargoSpec *cs = GetCargo(c);
 				if (!cs->IsValid()) continue;
 
@@ -791,7 +791,7 @@
 
 	/* Count the number of active cargo types */
 	uint num_active = 0;
-	for (CargoID c = 0; c != NUM_CARGO; c++) {
+	for (CargoID c = 0; c < NUM_CARGO; c++) {
 		if (GetCargo(c)->IsValid()) num_active++;
 	}
 
--- a/src/misc.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/misc.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -243,7 +243,7 @@
 {
 	if (only_constants) return;
 
-	for (CargoID i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		_cargo_payment_rates[i] = GetCargo(i)->initial_payment;
 		_cargo_payment_rates_frac[i] = 0;
 	}
--- a/src/misc_gui.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/misc_gui.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -141,11 +141,10 @@
 	GetString(_landinfo_data[4], STR_01A8_LOCAL_AUTHORITY, lastof(_landinfo_data[4]));
 
 	{
-		int i;
 		char *p = GetString(_landinfo_data[5], STR_01CE_CARGO_ACCEPTED, lastof(_landinfo_data[5]));
 		bool found = false;
 
-		for (i = 0; i < NUM_CARGO; ++i) {
+		for (CargoID i = 0; i < NUM_CARGO; ++i) {
 			if (ac[i] > 0) {
 				/* Add a comma between each item. */
 				if (found) {
@@ -732,11 +731,10 @@
 {
 	char *b = _userstring;
 	bool first = true;
-	int i;
 
 	b = InlineString(b, STR_000D_ACCEPTS);
 
-	for (i = 0; i != NUM_CARGO; i++, mask >>= 1) {
+	for (CargoID i = 0; i < NUM_CARGO; i++, mask >>= 1) {
 		if (b >= lastof(_userstring) - 5) break;
 		if (accepts[i] >= 8 && mask & 1) {
 			if (first) {
--- a/src/newgrf.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/newgrf.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -4006,7 +4006,7 @@
 
 	/* Generate default cargo translation table */
 	memset(_default_cargo_list, 0, sizeof(_default_cargo_list));
-	for (CargoID c = 0; c != NUM_CARGO; c++) {
+	for (CargoID c = 0; c < NUM_CARGO; c++) {
 		const CargoSpec *cs = GetCargo(c);
 		if (cs->IsValid()) _default_cargo_list[cs->bitnum] = cs->label;
 	}
--- a/src/station_cmd.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/station_cmd.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -352,7 +352,7 @@
 {
 	uint mask = 0;
 
-	for (uint i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		if (st->goods[i].waiting_acceptance & 0x8000) mask |= 1 << i;
 	}
 	return mask;
@@ -525,7 +525,7 @@
 	}
 
 	// Adjust in case our station only accepts fewer kinds of goods
-	for (uint i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		uint amt = min(accepts[i], 15);
 
 		// Make sure the station can accept the goods type.
@@ -2336,7 +2336,7 @@
 	FOR_ALL_STATIONS(st) {
 		if (st->owner == owner &&
 				DistanceManhattan(tile, st->xy) <= radius) {
-			for (uint i = 0; i != NUM_CARGO; i++) {
+			for (CargoID i = 0; i < NUM_CARGO; i++) {
 				GoodsEntry* ge = &st->goods[i];
 
 				if (ge->enroute_from != INVALID_STATION) {
@@ -2347,7 +2347,7 @@
 	}
 }
 
-static void UpdateStationWaiting(Station *st, int type, uint amount)
+static void UpdateStationWaiting(Station *st, CargoID type, uint amount)
 {
 	SB(st->goods[type].waiting_acceptance, 0, 12,
 		min(0xFFF, GB(st->goods[type].waiting_acceptance, 0, 12) + amount)
@@ -2391,7 +2391,7 @@
 }
 
 
-uint MoveGoodsToStation(TileIndex tile, int w, int h, int type, uint amount)
+uint MoveGoodsToStation(TileIndex tile, int w, int h, CargoID type, uint amount)
 {
 	Station* around[8];
 
@@ -2553,7 +2553,7 @@
 	st->facilities = FACIL_AIRPORT | FACIL_DOCK;
 	st->build_date = _date;
 
-	for (uint j = 0; j != NUM_CARGO; j++) {
+	for (CargoID j = 0; j < NUM_CARGO; j++) {
 		st->goods[j].waiting_acceptance = 0;
 		st->goods[j].days_since_pickup = 0;
 		st->goods[j].enroute_from = INVALID_STATION;
@@ -2801,7 +2801,7 @@
 static void SaveLoad_STNS(Station *st)
 {
 	SlObject(st, _station_desc);
-	for (uint i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		SlObject(&st->goods[i], _goods_desc);
 	}
 
--- a/src/station_gui.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/station_gui.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -364,7 +364,7 @@
 				x = DrawString(xb, y, STR_3049_0, 0) + 5;
 
 				// show cargo waiting and station ratings
-				for (CargoID j = 0; j != NUM_CARGO; j++) {
+				for (CargoID j = 0; j < NUM_CARGO; j++) {
 					uint amount = GB(st->goods[j].waiting_acceptance, 0, 12);
 					if (amount != 0) {
 						StationsWndShowStationRating(x, y, j, amount, st->goods[j].rating);
@@ -677,7 +677,7 @@
 	StringID str;
 
 	num = 1;
-	for (CargoID i = 0; i != NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) {
 			num++;
 			if (st->goods[i].enroute_from != station_id) num++;
@@ -701,7 +701,7 @@
 
 	if (--pos < 0) {
 		str = STR_00D0_NOTHING;
-		for (CargoID i = 0; i != NUM_CARGO; i++) {
+		for (CargoID i = 0; i < NUM_CARGO; i++) {
 			if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY;
 		}
 		SetDParam(0, str);
@@ -709,7 +709,7 @@
 		y += 10;
 	}
 
-	for (CargoID i = 0; i != NUM_CARGO && pos > -5; i++) {
+	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
 		uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12);
 		if (waiting == 0) continue;
 
@@ -753,7 +753,7 @@
 
 		b = InlineString(b, STR_000C_ACCEPTS);
 
-		for (CargoID i = 0; i != NUM_CARGO; i++) {
+		for (CargoID i = 0; i < NUM_CARGO; i++) {
 			if (b >= endof(_userstring) - 5 - 1) break;
 			if (st->goods[i].waiting_acceptance & 0x8000) {
 				if (first) {
@@ -776,7 +776,7 @@
 		DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0);
 
 		y = 77;
-		for (CargoID i = 0; i != NUM_CARGO; i++) {
+		for (CargoID i = 0; i < NUM_CARGO; i++) {
 			const CargoSpec *cs = GetCargo(i);
 			if (!cs->IsValid()) continue;
 
--- a/src/town_cmd.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/town_cmd.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -1587,9 +1587,7 @@
 		// set all close by station ratings to 0
 		FOR_ALL_STATIONS(st) {
 			if (st->town == t && st->owner == _current_player) {
-				uint i;
-
-				for (i = 0; i != NUM_CARGO; i++) st->goods[i].rating = 0;
+				for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0;
 			}
 		}
 
--- a/src/train_gui.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/train_gui.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -371,7 +371,6 @@
 	const Vehicle *u;
 	AcceptedCargo act_cargo;
 	AcceptedCargo max_cargo;
-	uint i;
 	int num;
 	int x;
 	int y;
@@ -380,7 +379,7 @@
 	num = 0;
 	u = v = GetVehicle(w->window_number);
 	if (det_tab == 3) { // Total cargo tab
-		for (i = 0; i < lengthof(act_cargo); i++) {
+		for (CargoID i = 0; i < lengthof(act_cargo); i++) {
 			act_cargo[i] = 0;
 			max_cargo[i] = 0;
 		}
@@ -393,7 +392,7 @@
 		/* Set scroll-amount seperately from counting, as to not compute num double
 		 * for more carriages of the same type
 		 */
-		for (i = 0; i != NUM_CARGO; i++) {
+		for (CargoID i = 0; i < NUM_CARGO; i++) {
 			if (max_cargo[i] > 0) num++; // only count carriages that the train has
 		}
 		num++; // needs one more because first line is description string
@@ -492,7 +491,7 @@
 	} else {
 		// draw total cargo tab
 		DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
-		for (i = 0; i != NUM_CARGO; i++) {
+		for (CargoID i = 0; i < NUM_CARGO; i++) {
 			if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) {
 				y += 14;
 				SetDParam(0, i);            // {CARGO} #1
--- a/src/vehicle.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/vehicle.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -772,7 +772,7 @@
 	uint32 refit_mask = EngInfo(engine_type)->refit_mask;
 
 	if (refit_mask != 0) {
-		for (CargoID cid = CT_PASSENGERS; cid < NUM_CARGO; cid++) {
+		for (CargoID cid = 0; cid < NUM_CARGO; cid++) {
 			if (HASBIT(refit_mask, cid)) return cid;
 		}
 	}
--- a/src/vehicle_gui.cpp	Wed Mar 21 11:50:34 2007 +0000
+++ b/src/vehicle_gui.cpp	Wed Mar 21 13:19:01 2007 +0000
@@ -209,7 +209,7 @@
 		if (u->cargo_cap == 0) continue;
 
 		/* Loop through all cargos in the refit mask */
-		for (CargoID cid = 0; cid != NUM_CARGO && num_lines < max_lines; cid++) {
+		for (CargoID cid = 0; cid < NUM_CARGO && num_lines < max_lines; cid++) {
 			/* Skip cargo type if it's not listed */
 			if (!HASBIT(cmask, cid)) continue;
 
@@ -616,14 +616,13 @@
 	AcceptedCargo cargoa;
 	AcceptedCargo cargob;
 	int r = 0;
-	int i;
 
 	memset(cargoa, 0, sizeof(cargoa));
 	memset(cargob, 0, sizeof(cargob));
 	for (v = va; v != NULL; v = v->next) cargoa[v->cargo_type] += v->cargo_cap;
 	for (v = vb; v != NULL; v = v->next) cargob[v->cargo_type] += v->cargo_cap;
 
-	for (i = 0; i < NUM_CARGO; i++) {
+	for (CargoID i = 0; i < NUM_CARGO; i++) {
 		r = cargoa[i] - cargob[i];
 		if (r != 0) break;
 	}