File diff r221:56c7ed3a0581 → r222:4409829eb08f
industry_gui.c
Show inline comments
 
@@ -383,26 +383,26 @@ static const Widget _industry_directory_
 
static byte _industry_sort[lengthof(_industries)];
 
static uint _num_industry_sort;
 

	
 
static char _bufcache[96];
 
static byte _last_industry_idx;
 

	
 
static byte _industry_sort_order;
 

	
 
static int CDECL GeneralIndustrySorter(const void *a, const void *b)
 
{
 
	char buf1[96];
 
	byte val;
 
	Industry *i = DEREF_INDUSTRY(*(byte*)a);
 
	Industry *j = DEREF_INDUSTRY(*(byte*)b);
 
	Industry *i = DEREF_INDUSTRY(*(const byte*)a);
 
	Industry *j = DEREF_INDUSTRY(*(const byte*)b);
 
	int r = 0;
 

	
 
	switch (_industry_sort_order >> 1) {
 
	/* case 0: Sort by Name (handled later) */
 
	case 1: /* Sort by Type */
 
		r = i->type - j->type;
 
		break;
 
	// 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?
 
@@ -428,25 +428,25 @@ static int CDECL GeneralIndustrySorter(c
 
		else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
 
			r = 1;
 
		else
 
			r = -1;
 
		break;
 
	}
 

	
 
	// default to string sorting if they are otherwise equal
 
	if (r == 0) {
 
		SET_DPARAM32(0, i->town->townnameparts);
 
		GetString(buf1, i->town->townnametype);
 

	
 
		if ( (val=*(byte*)b) != _last_industry_idx) {
 
		if ( (val=*(const byte*)b) != _last_industry_idx) {
 
			_last_industry_idx = val;
 
			SET_DPARAM32(0, j->town->townnameparts);
 
			GetString(_bufcache, j->town->townnametype);
 
		}
 
		r = strcmp(buf1, _bufcache);
 
	}
 

	
 
	if (_industry_sort_order & 1) r = -r;
 
	return r;
 
}
 

	
 
static void MakeSortedIndustryList()