Changeset - r7886:d1aa6534d262
[Not reviewed]
master
0 1 0
rubidium - 17 years ago 2007-11-15 17:54:46
rubidium@openttd.org
(svn r11437) -Change: when sorting stations by cargo sum, only sum the cargos that are selected in the filter. Patch by divide.
1 file changed with 4 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/station_gui.cpp
Show inline comments
 
@@ -118,31 +118,35 @@ static int CDECL StationNameSorter(const
 

	
 
	r = strcmp(buf1, _bufcache); // sort by name
 
	return (_internal_sort_order & 1) ? -r : r;
 
}
 

	
 
static int CDECL StationTypeSorter(const void *a, const void *b)
 
{
 
	const Station* st1 = *(const Station**)a;
 
	const Station* st2 = *(const Station**)b;
 
	return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
 
}
 

	
 
static const uint32 _cargo_filter_max = ~0;
 
static uint32 _cargo_filter = _cargo_filter_max;
 

	
 
static int CDECL StationWaitingSorter(const void *a, const void *b)
 
{
 
	const Station* st1 = *(const Station**)a;
 
	const Station* st2 = *(const Station**)b;
 
	Money sum1 = 0, sum2 = 0;
 

	
 
	for (CargoID j = 0; j < NUM_CARGO; j++) {
 
		if (!HASBIT(_cargo_filter, j)) continue;
 
		if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
 
		if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
 
	}
 

	
 
	return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
 
}
 

	
 
/**
 
 * qsort-compatible version of sorting two stations by maximum rating
 
 * @param a   First object to be sorted, must be of type (const Station *)
 
 * @param b   Second object to be sorted, must be of type (const Station *)
 
 * @return    The sort order
 
@@ -263,27 +267,24 @@ static void SortStationsList(plstations_
 
	};
 

	
 
	if (!(sl->flags & SL_RESORT)) return;
 

	
 
	_internal_sort_order = sl->flags & SL_ORDER;
 
	_last_station = NULL; // used for "cache" in namesorting
 
	qsort((void*)sl->sort_list, sl->list_length, sizeof(sl->sort_list[0]), _station_sorter[sl->sort_type]);
 

	
 
	sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
 
	sl->flags &= ~SL_RESORT;
 
}
 

	
 
static const uint32 _cargo_filter_max = ~0;
 
static uint32 _cargo_filter = _cargo_filter_max;
 

	
 
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
 
{
 
	const PlayerID owner = (PlayerID)w->window_number;
 
	static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
 
	static Listing station_sort = {0, 0};
 
	static bool include_empty = true;
 

	
 
	plstations_d *sl = &WP(w, plstations_d);
 

	
 
	switch (e->event) {
 
		case WE_CREATE: /* set up resort timer */
 
			if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
0 comments (0 inline, 0 general)