Changeset - r6350:7a0fb15b3676
[Not reviewed]
master
0 13 0
peter1138 - 18 years ago 2007-03-21 13:19:01
peter1138@openttd.org
(svn r9388) -Codechange: variable scope and type, and standardify all CargoID loops.
13 files changed with 29 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/aircraft_cmd.cpp
Show inline comments
 
@@ -1408,7 +1408,7 @@ static void MaybeCrashAirplane(Vehicle *
 
	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);
 
	}
src/economy.cpp
Show inline comments
 
@@ -652,7 +652,7 @@ static void AddInflation()
 
		_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,
src/economy.h
Show inline comments
 
@@ -66,6 +66,6 @@ void DeleteSubsidyWithIndustry(IndustryI
 
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 */
src/graph_gui.cpp
Show inline comments
 
@@ -721,7 +721,7 @@ static void CargoPaymentRatesWndProc(Win
 
			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 @@ void ShowCargoPaymentRates()
 

	
 
	/* 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++;
 
	}
 

	
src/misc.cpp
Show inline comments
 
@@ -243,7 +243,7 @@ void InitializeLandscapeVariables(bool o
 
{
 
	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;
 
	}
src/misc_gui.cpp
Show inline comments
 
@@ -141,11 +141,10 @@ static void Place_LandInfo(TileIndex til
 
	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 @@ static void DrawStationCoverageText(cons
 
{
 
	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) {
src/newgrf.cpp
Show inline comments
 
@@ -4006,7 +4006,7 @@ static void ResetNewGRFData()
 

	
 
	/* 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;
 
	}
src/station_cmd.cpp
Show inline comments
 
@@ -352,7 +352,7 @@ static uint GetAcceptanceMask(const Stat
 
{
 
	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 @@ static void UpdateStationAcceptance(Stat
 
	}
 

	
 
	// 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 @@ void ModifyStationRatingAround(TileIndex
 
	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 @@ void ModifyStationRatingAround(TileIndex
 
	}
 
}
 

	
 
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 @@ int32 CmdRenameStation(TileIndex tile, u
 
}
 

	
 

	
 
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 @@ void BuildOilRig(TileIndex tile)
 
	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 const SaveLoad _station_speclist_
 
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);
 
	}
 

	
src/station_gui.cpp
Show inline comments
 
@@ -364,7 +364,7 @@ static void PlayerStationsWndProc(Window
 
				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 @@ static void DrawStationViewWindow(Window
 
	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 @@ static void DrawStationViewWindow(Window
 

	
 
	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 @@ static void DrawStationViewWindow(Window
 
		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 @@ static void DrawStationViewWindow(Window
 

	
 
		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 @@ static void DrawStationViewWindow(Window
 
		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;
 

	
src/town_cmd.cpp
Show inline comments
 
@@ -1587,9 +1587,7 @@ static void TownActionBribe(Town* t)
 
		// 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;
 
			}
 
		}
 

	
src/train_gui.cpp
Show inline comments
 
@@ -371,7 +371,6 @@ static void DrawTrainDetailsWindow(Windo
 
	const Vehicle *u;
 
	AcceptedCargo act_cargo;
 
	AcceptedCargo max_cargo;
 
	uint i;
 
	int num;
 
	int x;
 
	int y;
 
@@ -380,7 +379,7 @@ static void DrawTrainDetailsWindow(Windo
 
	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 @@ static void DrawTrainDetailsWindow(Windo
 
		/* 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 @@ static void DrawTrainDetailsWindow(Windo
 
	} 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
src/vehicle.cpp
Show inline comments
 
@@ -772,7 +772,7 @@ CargoID FindFirstRefittableCargo(EngineI
 
	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;
 
		}
 
	}
src/vehicle_gui.cpp
Show inline comments
 
@@ -209,7 +209,7 @@ static RefitList *BuildRefitList(const V
 
		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 @@ static int CDECL VehicleCargoSorter(cons
 
	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;
 
	}
0 comments (0 inline, 0 general)