src/station_gui.cpp
changeset 7506 e52d89f5c7c1
parent 7486 d130c10f4dab
child 7554 076c42f44a83
equal deleted inserted replaced
7505:94a7391e0377 7506:e52d89f5c7c1
   132 	const Station* st1 = *(const Station**)a;
   132 	const Station* st1 = *(const Station**)a;
   133 	const Station* st2 = *(const Station**)b;
   133 	const Station* st2 = *(const Station**)b;
   134 	Money sum1 = 0, sum2 = 0;
   134 	Money sum1 = 0, sum2 = 0;
   135 
   135 
   136 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   136 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   137 		if (st1->goods[j].waiting_acceptance & 0xfff) sum1 += GetTransportedGoodsIncome(st1->goods[j].waiting_acceptance & 0xfff, 20, 50, j);
   137 		if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
   138 		if (st2->goods[j].waiting_acceptance & 0xfff) sum2 += GetTransportedGoodsIncome(st2->goods[j].waiting_acceptance & 0xfff, 20, 50, j);
   138 		if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
   139 	}
   139 	}
   140 
   140 
   141 	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
   141 	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
   142 }
   142 }
   143 
   143 
   155 	const Station* st2 = *(const Station**)b;
   155 	const Station* st2 = *(const Station**)b;
   156 	byte maxr1 = 0;
   156 	byte maxr1 = 0;
   157 	byte maxr2 = 0;
   157 	byte maxr2 = 0;
   158 
   158 
   159 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   159 	for (CargoID j = 0; j < NUM_CARGO; j++) {
   160 		if (st1->goods[j].enroute_from != INVALID_STATION) maxr1 = max(maxr1, st1->goods[j].rating);
   160 		if (st1->goods[j].days_since_pickup != 255) maxr1 = max(maxr1, st1->goods[j].rating);
   161 		if (st2->goods[j].enroute_from != INVALID_STATION) maxr2 = max(maxr2, st2->goods[j].rating);
   161 		if (st2->goods[j].days_since_pickup != 255) maxr2 = max(maxr2, st2->goods[j].rating);
   162 	}
   162 	}
   163 
   163 
   164 	return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
   164 	return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
   165 }
   165 }
   166 
   166 
   223 	FOR_ALL_STATIONS(st) {
   223 	FOR_ALL_STATIONS(st) {
   224 		if (st->owner == owner) {
   224 		if (st->owner == owner) {
   225 			if (facilities & st->facilities) { //only stations with selected facilities
   225 			if (facilities & st->facilities) { //only stations with selected facilities
   226 				int num_waiting_cargo = 0;
   226 				int num_waiting_cargo = 0;
   227 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   227 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   228 					if (st->goods[j].waiting_acceptance & 0xFFF) {
   228 					if (!st->goods[j].cargo.Empty()) {
   229 						num_waiting_cargo++; //count number of waiting cargo
   229 						num_waiting_cargo++; //count number of waiting cargo
   230 						if (HASBIT(cargo_filter, j)) {
   230 						if (HASBIT(cargo_filter, j)) {
   231 							station_sort[n++] = st;
   231 							station_sort[n++] = st;
   232 							break;
   232 							break;
   233 						}
   233 						}
   366 				SetDParam(1, st->facilities);
   366 				SetDParam(1, st->facilities);
   367 				x = DrawString(xb, y, STR_3049_0, 0) + 5;
   367 				x = DrawString(xb, y, STR_3049_0, 0) + 5;
   368 
   368 
   369 				/* show cargo waiting and station ratings */
   369 				/* show cargo waiting and station ratings */
   370 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   370 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   371 					uint amount = GB(st->goods[j].waiting_acceptance, 0, 12);
   371 					if (!st->goods[j].cargo.Empty()) {
   372 					if (amount != 0) {
   372 						StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
   373 						StationsWndShowStationRating(x, y, j, amount, st->goods[j].rating);
       
   374 						x += 20;
   373 						x += 20;
   375 					}
   374 					}
   376 				}
   375 				}
   377 				y += 10;
   376 				y += 10;
   378 			}
   377 			}
   703 	int pos;
   702 	int pos;
   704 	StringID str;
   703 	StringID str;
   705 
   704 
   706 	num = 1;
   705 	num = 1;
   707 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   706 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   708 		if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) {
   707 		if (!st->goods[i].cargo.Empty()) {
   709 			num++;
   708 			num++;
   710 			if (st->goods[i].enroute_from != station_id) num++;
   709 			if (st->goods[i].cargo.Source() != station_id) num++;
   711 		}
   710 		}
   712 	}
   711 	}
   713 	SetVScrollCount(w, num);
   712 	SetVScrollCount(w, num);
   714 
   713 
   715 	SetWindowWidgetDisabledState(w,  9, st->owner != _local_player);
   714 	SetWindowWidgetDisabledState(w,  9, st->owner != _local_player);
   727 	pos = w->vscroll.pos;
   726 	pos = w->vscroll.pos;
   728 
   727 
   729 	if (--pos < 0) {
   728 	if (--pos < 0) {
   730 		str = STR_00D0_NOTHING;
   729 		str = STR_00D0_NOTHING;
   731 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   730 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   732 			if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY;
   731 			if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
   733 		}
   732 		}
   734 		SetDParam(0, str);
   733 		SetDParam(0, str);
   735 		DrawString(x, y, STR_0008_WAITING, 0);
   734 		DrawString(x, y, STR_0008_WAITING, 0);
   736 		y += 10;
   735 		y += 10;
   737 	}
   736 	}
   738 
   737 
   739 	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
   738 	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
   740 		uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12);
   739 		uint waiting = st->goods[i].cargo.Count();
   741 		if (waiting == 0) continue;
   740 		if (waiting == 0) continue;
   742 
   741 
   743 		if (st->goods[i].enroute_from == station_id) {
   742 		if (st->goods[i].cargo.Source() == station_id) {
   744 			if (--pos < 0) {
   743 			if (--pos < 0) {
   745 				DrawCargoIcons(i, waiting, x, y);
   744 				DrawCargoIcons(i, waiting, x, y);
   746 				SetDParam(1, waiting);
   745 				SetDParam(1, waiting);
   747 				SetDParam(0, i);
   746 				SetDParam(0, i);
   748 				DrawStringRightAligned(x + 234, y, STR_0009, 0);
   747 				DrawStringRightAligned(x + 234, y, STR_0009, 0);
   757 				DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
   756 				DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
   758 				y += 10;
   757 				y += 10;
   759 			}
   758 			}
   760 
   759 
   761 			if (pos > -5 && --pos < 0) {
   760 			if (pos > -5 && --pos < 0) {
   762 				SetDParam(0, st->goods[i].enroute_from);
   761 				SetDParam(0, st->goods[i].cargo.Source());
   763 				DrawStringRightAligned(x + 234, y, STR_000B, 0);
   762 				DrawStringRightAligned(x + 234, y, STR_000B, 0);
   764 				y += 10;
   763 				y += 10;
   765 			}
   764 			}
   766 		}
   765 		}
   767 	}
   766 	}
   772 
   771 
   773 		b = InlineString(b, STR_000C_ACCEPTS);
   772 		b = InlineString(b, STR_000C_ACCEPTS);
   774 
   773 
   775 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   774 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   776 			if (b >= endof(_userstring) - 5 - 1) break;
   775 			if (b >= endof(_userstring) - 5 - 1) break;
   777 			if (st->goods[i].waiting_acceptance & 0x8000) {
   776 			if (st->goods[i].acceptance) {
   778 				if (first) {
   777 				if (first) {
   779 					first = false;
   778 					first = false;
   780 				} else {
   779 				} else {
   781 					/* Add a comma if this is not the first item */
   780 					/* Add a comma if this is not the first item */
   782 					*b++ = ',';
   781 					*b++ = ',';
   798 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   797 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   799 			const CargoSpec *cs = GetCargo(i);
   798 			const CargoSpec *cs = GetCargo(i);
   800 			if (!cs->IsValid()) continue;
   799 			if (!cs->IsValid()) continue;
   801 
   800 
   802 			const GoodsEntry *ge = &st->goods[i];
   801 			const GoodsEntry *ge = &st->goods[i];
   803 			if (ge->enroute_from == INVALID_STATION) continue;
   802 			if (ge->days_since_pickup == 255) continue;
   804 
   803 
   805 			SetDParam(0, cs->name);
   804 			SetDParam(0, cs->name);
   806 			SetDParam(2, ge->rating * 101 >> 8);
   805 			SetDParam(2, ge->rating * 101 >> 8);
   807 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   806 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   808 			DrawString(8, y, STR_303D, 0);
   807 			DrawString(8, y, STR_303D, 0);