src/station_gui.cpp
branchnoai
changeset 9629 66dde6412125
parent 9624 b71483f2330f
child 9694 e72987579514
equal deleted inserted replaced
9628:b5c2449616b5 9629:66dde6412125
   129 
   129 
   130 static int CDECL StationWaitingSorter(const void *a, const void *b)
   130 static int CDECL StationWaitingSorter(const void *a, const void *b)
   131 {
   131 {
   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 	int 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) ? sum2 - sum1 : sum1 - sum2;
   141 	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
   142 }
   142 }
   143 
   143 
   144 /**
   144 /**
   145  * qsort-compatible version of sorting two stations by maximum rating
   145  * qsort-compatible version of sorting two stations by maximum rating
   146  * @param a   First object to be sorted, must be of type (const Station *)
   146  * @param a   First object to be sorted, must be of type (const Station *)
   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 						}
   307 			SortStationsList(sl);
   307 			SortStationsList(sl);
   308 
   308 
   309 			SetVScrollCount(w, sl->list_length);
   309 			SetVScrollCount(w, sl->list_length);
   310 
   310 
   311 			/* draw widgets, with player's name in the caption */
   311 			/* draw widgets, with player's name in the caption */
   312 			const Player* p = GetPlayer(owner);
   312 			SetDParam(0, owner);
   313 			SetDParam(0, p->name_1);
   313 			SetDParam(1, w->vscroll.count);
   314 			SetDParam(1, p->name_2);
       
   315 			SetDParam(2, w->vscroll.count);
       
   316 			DrawWindowWidgets(w);
   314 			DrawWindowWidgets(w);
   317 
   315 
   318 			/* draw sorting criteria string */
   316 			/* draw sorting criteria string */
   319 			DrawString(85, 26, _station_sort_listing[sl->sort_type], 0x10);
   317 			DrawString(85, 26, _station_sort_listing[sl->sort_type], 0x10);
   320 			/* draw arrow pointing up/down for ascending/descending sorting */
   318 			/* draw arrow pointing up/down for ascending/descending sorting */
   366 				SetDParam(1, st->facilities);
   364 				SetDParam(1, st->facilities);
   367 				x = DrawString(xb, y, STR_3049_0, 0) + 5;
   365 				x = DrawString(xb, y, STR_3049_0, 0) + 5;
   368 
   366 
   369 				/* show cargo waiting and station ratings */
   367 				/* show cargo waiting and station ratings */
   370 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   368 				for (CargoID j = 0; j < NUM_CARGO; j++) {
   371 					uint amount = GB(st->goods[j].waiting_acceptance, 0, 12);
   369 					if (!st->goods[j].cargo.Empty()) {
   372 					if (amount != 0) {
   370 						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;
   371 						x += 20;
   375 					}
   372 					}
   376 				}
   373 				}
   377 				y += 10;
   374 				y += 10;
   378 			}
   375 			}
   703 	int pos;
   700 	int pos;
   704 	StringID str;
   701 	StringID str;
   705 
   702 
   706 	num = 1;
   703 	num = 1;
   707 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   704 	for (CargoID i = 0; i < NUM_CARGO; i++) {
   708 		if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) {
   705 		if (!st->goods[i].cargo.Empty()) {
   709 			num++;
   706 			num++;
   710 			if (st->goods[i].enroute_from != station_id) num++;
   707 			if (st->goods[i].cargo.Source() != station_id) num++;
   711 		}
   708 		}
   712 	}
   709 	}
   713 	SetVScrollCount(w, num);
   710 	SetVScrollCount(w, num);
   714 
   711 
   715 	SetWindowWidgetDisabledState(w,  9, st->owner != _local_player);
   712 	SetWindowWidgetDisabledState(w,  9, st->owner != _local_player);
   727 	pos = w->vscroll.pos;
   724 	pos = w->vscroll.pos;
   728 
   725 
   729 	if (--pos < 0) {
   726 	if (--pos < 0) {
   730 		str = STR_00D0_NOTHING;
   727 		str = STR_00D0_NOTHING;
   731 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   728 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   732 			if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY;
   729 			if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
   733 		}
   730 		}
   734 		SetDParam(0, str);
   731 		SetDParam(0, str);
   735 		DrawString(x, y, STR_0008_WAITING, 0);
   732 		DrawString(x, y, STR_0008_WAITING, 0);
   736 		y += 10;
   733 		y += 10;
   737 	}
   734 	}
   738 
   735 
   739 	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
   736 	for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
   740 		uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12);
   737 		uint waiting = st->goods[i].cargo.Count();
   741 		if (waiting == 0) continue;
   738 		if (waiting == 0) continue;
   742 
   739 
   743 		if (st->goods[i].enroute_from == station_id) {
   740 		if (st->goods[i].cargo.Source() == station_id) {
   744 			if (--pos < 0) {
   741 			if (--pos < 0) {
   745 				DrawCargoIcons(i, waiting, x, y);
   742 				DrawCargoIcons(i, waiting, x, y);
   746 				SetDParam(1, waiting);
   743 				SetDParam(1, waiting);
   747 				SetDParam(0, i);
   744 				SetDParam(0, i);
   748 				DrawStringRightAligned(x + 234, y, STR_0009, 0);
   745 				DrawStringRightAligned(x + 234, y, STR_0009, 0);
   757 				DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
   754 				DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
   758 				y += 10;
   755 				y += 10;
   759 			}
   756 			}
   760 
   757 
   761 			if (pos > -5 && --pos < 0) {
   758 			if (pos > -5 && --pos < 0) {
   762 				SetDParam(0, st->goods[i].enroute_from);
   759 				SetDParam(0, st->goods[i].cargo.Source());
   763 				DrawStringRightAligned(x + 234, y, STR_000B, 0);
   760 				DrawStringRightAligned(x + 234, y, STR_000B, 0);
   764 				y += 10;
   761 				y += 10;
   765 			}
   762 			}
   766 		}
   763 		}
   767 	}
   764 	}
   772 
   769 
   773 		b = InlineString(b, STR_000C_ACCEPTS);
   770 		b = InlineString(b, STR_000C_ACCEPTS);
   774 
   771 
   775 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   772 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   776 			if (b >= endof(_userstring) - 5 - 1) break;
   773 			if (b >= endof(_userstring) - 5 - 1) break;
   777 			if (st->goods[i].waiting_acceptance & 0x8000) {
   774 			if (st->goods[i].acceptance) {
   778 				if (first) {
   775 				if (first) {
   779 					first = false;
   776 					first = false;
   780 				} else {
   777 				} else {
   781 					/* Add a comma if this is not the first item */
   778 					/* Add a comma if this is not the first item */
   782 					*b++ = ',';
   779 					*b++ = ',';
   798 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   795 		for (CargoID i = 0; i < NUM_CARGO; i++) {
   799 			const CargoSpec *cs = GetCargo(i);
   796 			const CargoSpec *cs = GetCargo(i);
   800 			if (!cs->IsValid()) continue;
   797 			if (!cs->IsValid()) continue;
   801 
   798 
   802 			const GoodsEntry *ge = &st->goods[i];
   799 			const GoodsEntry *ge = &st->goods[i];
   803 			if (ge->enroute_from == INVALID_STATION) continue;
   800 			if (ge->days_since_pickup == 255) continue;
   804 
   801 
   805 			SetDParam(0, cs->name);
   802 			SetDParam(0, cs->name);
   806 			SetDParam(2, ge->rating * 101 >> 8);
   803 			SetDParam(2, ge->rating * 101 >> 8);
   807 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   804 			SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
   808 			DrawString(8, y, STR_303D, 0);
   805 			DrawString(8, y, STR_303D, 0);