(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
authortron
Wed, 28 Sep 2005 19:35:36 +0000
changeset 2469 1bfbb0dc0b75
parent 2468 15753a8438ba
child 2470 a3b2f1f8ab3d
(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate
economy.c
engine.c
industry_cmd.c
industry_gui.c
main_gui.c
openttd.c
players.c
road_cmd.c
station_cmd.c
subsidy_gui.c
town_cmd.c
vehicle.c
--- a/economy.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/economy.c	Wed Sep 28 19:35:36 2005 +0000
@@ -259,7 +259,7 @@
 	return score;
 }
 
-// use 255 as new_player to delete the player.
+// use OWNER_SPECTATOR as new_player to delete the player.
 void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
 {
 	PlayerID old = _current_player;
@@ -269,9 +269,9 @@
 		Subsidy *s;
 
 		for (s = _subsidies; s != endof(_subsidies); s++) {
-			if (s->cargo_type != 0xff && s->age >= 12) {
+			if (s->cargo_type != CT_INVALID && s->age >= 12) {
 				if (GetStation(s->to)->owner == old_player)
-					s->cargo_type = 0xff;
+					s->cargo_type = CT_INVALID;
 			}
 		}
 	}
@@ -376,13 +376,13 @@
 			for (i = 0; i < 4; i++) {
 				/* 'Sell' the share if this player has any */
 				if (p->share_owners[i] == _current_player)
-					p->share_owners[i] = 0xFF;
+					p->share_owners[i] = OWNER_SPECTATOR;
 			}
 		}
 		p = GetPlayer(_current_player);
 		/* Sell all the shares that people have on this company */
 		for (i = 0; i < 4; i++)
-			p->share_owners[i] = 0xFF;
+			p->share_owners[i] = OWNER_SPECTATOR;
 	}
 
 	_current_player = old;
@@ -471,7 +471,7 @@
 
 				// Convert everything the player owns to NO_OWNER
 				p->money64 = p->player_money = 100000000;
-				ChangeOwnershipOfPlayerItems(owner, 0xFF); // 255 is no owner
+				ChangeOwnershipOfPlayerItems(owner, OWNER_SPECTATOR);
 				// Register the player as not-active
 				p->is_active = false;
 
@@ -846,10 +846,10 @@
 	Subsidy *s;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age < 12 &&
+		if (s->cargo_type != CT_INVALID && s->age < 12 &&
 				s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
 				(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
-			s->cargo_type = 0xFF;
+			s->cargo_type = CT_INVALID;
 		}
 	}
 }
@@ -860,9 +860,9 @@
 	bool dirty = false;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age >= 12 &&
+		if (s->cargo_type != CT_INVALID && s->age >= 12 &&
 				(s->from == index || s->to == index)) {
-			s->cargo_type = 0xFF;
+			s->cargo_type = CT_INVALID;
 			dirty = true;
 		}
 	}
@@ -908,7 +908,7 @@
 		return;
 
 	// Randomize cargo type
-	if (Random()&1 && i->produced_cargo[1] != 0xFF) {
+	if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
 		cargo = i->produced_cargo[1];
 		trans = i->pct_transported[1];
 		total = i->total_production[1];
@@ -921,7 +921,7 @@
 	// Quit if no production in this industry
 	//  or if the cargo type is passengers
 	//  or if the pct transported is already large enough
-	if (total == 0  || trans > 42 || cargo == 0xFF || cargo == CT_PASSENGERS)
+	if (total == 0 || trans > 42 || cargo == CT_INVALID || cargo == CT_PASSENGERS)
 		return;
 
 	fr->cargo = cargo;
@@ -960,7 +960,7 @@
 				ss->from == s->from &&
 				ss->to == s->to &&
 				ss->cargo_type == s->cargo_type) {
-			s->cargo_type = 0xFF;
+			s->cargo_type = CT_INVALID;
 			return true;
 		}
 	}
@@ -974,7 +974,7 @@
 
 	// search the first free subsidy
 	for(s=_subsidies; s != endof(_subsidies); s++)
-		if (s->cargo_type == 0xFF)
+		if (s->cargo_type == CT_INVALID)
 			break;
 
 	memcpy(s,s_new,sizeof(Subsidy));
@@ -995,13 +995,13 @@
 	bool modified = false;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type == 0xFF)
+		if (s->cargo_type == CT_INVALID)
 			continue;
 
 		if (s->age == 12-1) {
 			pair = SetupSubsidyDecodeParam(s, 1);
 			AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
-			s->cargo_type = 0xFF;
+			s->cargo_type = CT_INVALID;
 			modified = true;
 		} else if (s->age == 2*12-1) {
 			st = GetStation(s->to);
@@ -1009,7 +1009,7 @@
 				pair = SetupSubsidyDecodeParam(s, 1);
 				AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
 			}
-			s->cargo_type = 0xFF;
+			s->cargo_type = CT_INVALID;
 			modified = true;
 		} else {
 			s->age++;
@@ -1020,7 +1020,7 @@
 	if (CHANCE16(1,4)) {
 		// Find a free slot
 		s = _subsidies;
-		while (s->cargo_type != 0xFF) {
+		while (s->cargo_type != CT_INVALID) {
 			if (++s == endof(_subsidies))
 				goto no_add;
 		}
@@ -1072,7 +1072,7 @@
 
 	for(i=0; i!=lengthof(_subsidies); i++) {
 		s = &_subsidies[i];
-		if (s->cargo_type != 0xFF) {
+		if (s->cargo_type != CT_INVALID) {
 			SlSetArrayIndex(i);
 			SlObject(s, _subsidies_desc);
 		}
@@ -1126,7 +1126,7 @@
 	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 &&
+				 ind->produced_cargo[0] != CT_INVALID &&
 				 ind->produced_cargo[0] != cargo_type &&
 				 (t = DistanceManhattan(ind->xy, xy)) < 2 * u) {
 			u = t;
@@ -1516,7 +1516,7 @@
 
 	value = CalculateCompanyValue(p) >> 2;
 	for(i=0; i!=4; i++) {
-		if (p->share_owners[i] != 0xFF) {
+		if (p->share_owners[i] != OWNER_SPECTATOR) {
 			owner = GetPlayer(p->share_owners[i]);
 			owner->money64 += value;
 			owner->yearly_expenses[0][EXPENSES_OTHER] += value;
@@ -1562,7 +1562,7 @@
 		int i;
 		byte *b = p->share_owners;
 
-		while (*b != 0xFF) b++; /* share owners is guaranteed to contain at least one 0xFF */
+		while (*b != OWNER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one OWNER_SPECTATOR */
 		*b = _current_player;
 
 		for (i = 0; p->share_owners[i] == _current_player;) {
@@ -1603,7 +1603,7 @@
 	if (flags & DC_EXEC) {
 		byte *b = p->share_owners;
 		while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
-		*b = 0xFF;
+		*b = OWNER_SPECTATOR;
 		InvalidateWindow(WC_COMPANY, (int)p1);
 	}
 	return cost;
--- a/engine.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/engine.c	Wed Sep 28 19:35:36 2005 +0000
@@ -761,7 +761,7 @@
 
 	do {
 		best_hist = -1;
-		best_player = -1;
+		best_player = OWNER_SPECTATOR;
 		FOR_ALL_PLAYERS(p) {
 			if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
 					p->old_economy[0].performance_history > best_hist) {
@@ -770,7 +770,7 @@
 			}
 		}
 
-		if (best_player == (PlayerID)-1) return -1;
+		if (best_player == OWNER_SPECTATOR) return OWNER_SPECTATOR;
 
 		SETBIT(mask, best_player);
 	} while (--pp != 0);
@@ -797,7 +797,7 @@
  			} else if (e->preview_player != 0xFF) {
 				PlayerID best_player = GetBestPlayer(e->preview_player);
 
-				if (best_player == (PlayerID)-1) {
+				if (best_player == OWNER_SPECTATOR) {
 					e->preview_player = 0xFF;
 					continue;
 				}
--- a/industry_cmd.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/industry_cmd.c	Wed Sep 28 19:35:36 2005 +0000
@@ -1406,14 +1406,14 @@
 	spec = &_industry_spec[type];
 
 	// accepting industries won't be close, not even with patch
-	if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) )
+	if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID)
 		return true;
 
 	FOR_ALL_INDUSTRIES(i) {
 		// check if an industry that accepts the same goods is nearby
 		if (i->xy != 0 &&
 				(DistanceMax(tile, i->xy) <= 14) &&
-				spec->accepts_cargo[0] != 0xFF &&
+				spec->accepts_cargo[0] != CT_INVALID &&
 				spec->accepts_cargo[0] == i->accepts_cargo[0] &&
 				!(_game_mode == GM_EDITOR &&
 					_patches.same_industry_close &&
@@ -1754,7 +1754,7 @@
 {
 	byte pct;
 
-	if (i->produced_cargo[0] != 0xFF) {
+	if (i->produced_cargo[0] != CT_INVALID) {
 		pct = 0;
 		if (i->last_mo_production[0] != 0) {
 			i->last_prod_year = _cur_year;
@@ -1769,7 +1769,7 @@
 		i->last_mo_transported[0] = 0;
 	}
 
-	if (i->produced_cargo[1] != 0xFF) {
+	if (i->produced_cargo[1] != CT_INVALID) {
 		pct = 0;
 		if (i->last_mo_production[1] != 0) {
 			i->last_prod_year = _cur_year;
@@ -1785,7 +1785,7 @@
 	}
 
 
-	if ( i->produced_cargo[0] != 0xFF || i->produced_cargo[1] != 0xFF )
+	if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
 		InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
 
 	if (i->prod_level == 0)
--- a/industry_gui.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/industry_gui.c	Wed Sep 28 19:35:36 2005 +0000
@@ -496,28 +496,28 @@
 	// FIXME - Production & Transported sort need to be inversed...but, WTF it does not wanna!
 	// FIXME - And no simple --> "if (!(_industry_sort_order & 1)) r = -r;" hack at the bottom!!
 	case 2: { /* Sort by Production */
-		if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
-				if (i->produced_cargo[1] == 0xFF) // producing one or two things?
+		if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
+				if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
 					r = j->total_production[0] - i->total_production[0];
 				else
 					r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2;
-		} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
+		} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
 			r = 0;
-		else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
+		else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
 			r = 1;
 		else
 			r = -1;
 		break;
 	}
 	case 3: /* Sort by Transported amount */
-		if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
-				if (i->produced_cargo[1] == 0xFF) // producing one or two things?
+		if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
+				if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
 					r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8);
 				else
 					r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2;
-		} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
+		} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
 			r = 0;
-		else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
+		else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
 			r = 1;
 		else
 			r = -1;
@@ -589,11 +589,11 @@
 		while (p < _num_industry_sort) {
 			i = GetIndustry(_industry_sort[p]);
 			SetDParam(0, i->index);
-			if (i->produced_cargo[0] != 0xFF) {
+			if (i->produced_cargo[0] != CT_INVALID) {
 				SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
 				SetDParam(2, i->total_production[0]);
 
-				if (i->produced_cargo[1] != 0xFF) {
+				if (i->produced_cargo[1] != CT_INVALID) {
 					SetDParam(3, _cargoc.names_long[i->produced_cargo[1]]);
 					SetDParam(4, i->total_production[1]);
 					SetDParam(5, i->pct_transported[0] * 100 >> 8);
--- a/main_gui.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/main_gui.c	Wed Sep 28 19:35:36 2005 +0000
@@ -1889,8 +1889,7 @@
 	} break;
 
 	case WE_KEYPRESS: {
-		int local = _local_player;
-		if (local == 0xff) local = 0; // spectator
+		PlayerID local = (_local_player != OWNER_SPECTATOR) ? _local_player : 0;
 
 		switch(e->keypress.keycode) {
 		case WKC_F1: case WKC_PAUSE:
--- a/openttd.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/openttd.c	Wed Sep 28 19:35:36 2005 +0000
@@ -799,7 +799,7 @@
 			_generating_world = true;
 			// delete all players.
 			for (i = 0; i != MAX_PLAYERS; i++) {
-				ChangeOwnershipOfPlayerItems(i, 0xff);
+				ChangeOwnershipOfPlayerItems(i, OWNER_SPECTATOR);
 				_players[i].is_active = false;
 			}
 			_generating_world = false;
--- a/players.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/players.c	Wed Sep 28 19:35:36 2005 +0000
@@ -487,7 +487,7 @@
 
 	p->is_ai = is_ai;
 	p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */
-	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = 0xFF;
+	p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = OWNER_SPECTATOR;
 
 	p->avail_railtypes = GetPlayerRailtypes(p->index);
 	p->inaugurated_year = _cur_year;
--- a/road_cmd.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/road_cmd.c	Wed Sep 28 19:35:36 2005 +0000
@@ -1172,7 +1172,7 @@
 
 	// road/rail crossing where the road is owned by the current player?
 	if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
-		_m[tile].m3 = (new_player == 0xFF) ? OWNER_NONE : new_player;
+		_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
 	}
 
 	if (!IsTileOwner(tile, old_player)) return;
--- a/station_cmd.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/station_cmd.c	Wed Sep 28 19:35:36 2005 +0000
@@ -3131,7 +3131,7 @@
 
 		/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
 		if (_sl_full_version < 0x700 && st->goods[i].enroute_from == 0xFF)
-			st->goods[i].enroute_from = 0xFFFF;
+			st->goods[i].enroute_from = INVALID_STATION;
 	}
 }
 
--- a/subsidy_gui.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/subsidy_gui.c	Wed Sep 28 19:35:36 2005 +0000
@@ -25,7 +25,7 @@
 
 	num = 0;
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age < 12) {
+		if (s->cargo_type != CT_INVALID && s->age < 12) {
 			y -= 10;
 			if (y < 0) goto handle_click;
 			num++;
@@ -41,7 +41,7 @@
 	if (y < 0) return;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age >= 12) {
+		if (s->cargo_type != CT_INVALID && s->age >= 12) {
 			y -= 10;
 			if (y < 0) goto handle_click;
 		}
@@ -92,7 +92,7 @@
 	num = 0;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age < 12) {
+		if (s->cargo_type != CT_INVALID && s->age < 12) {
 			SetupSubsidyDecodeParam(s, 1);
 			x2 = DrawString(x+2, y, STR_2027_FROM_TO, 0);
 
@@ -113,7 +113,7 @@
 	num = 0;
 
 	for(s=_subsidies; s != endof(_subsidies); s++) {
-		if (s->cargo_type != 0xFF && s->age >= 12) {
+		if (s->cargo_type != CT_INVALID && s->age >= 12) {
 			SetupSubsidyDecodeParam(s, 1);
 
 			p = GetPlayer(GetStation(s->to)->owner);
--- a/town_cmd.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/town_cmd.c	Wed Sep 28 19:35:36 2005 +0000
@@ -1953,7 +1953,7 @@
 
 	memset(_subsidies, 0, sizeof(_subsidies));
 	for (s=_subsidies; s != endof(_subsidies); s++)
-		s->cargo_type = 0xFF;
+		s->cargo_type = CT_INVALID;
 
 	_cur_town_ctr = 0;
 	_cur_town_iter = 0;
--- a/vehicle.c	Tue Sep 27 20:55:42 2005 +0000
+++ b/vehicle.c	Wed Sep 28 19:35:36 2005 +0000
@@ -2233,7 +2233,7 @@
 
 		/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
 		if (_sl_version < 5 && v->last_station_visited == 0xFF)
-			v->last_station_visited = 0xFFFF;
+			v->last_station_visited = INVALID_STATION;
 
 		if (_sl_version < 5) {
 			/* Convert the current_order.type (which is a mix of type and flags, because