382 { WWT_IMGBTN, 13, 0, 496, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
382 { WWT_IMGBTN, 13, 0, 496, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, |
383 { WWT_SCROLLBAR, 13, 497, 507, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
383 { WWT_SCROLLBAR, 13, 497, 507, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, |
384 { WIDGETS_END}, |
384 { WIDGETS_END}, |
385 }; |
385 }; |
386 |
386 |
387 static byte _industry_sort[lengthof(_industries)]; |
387 static uint16 _industry_sort[lengthof(_industries)]; |
388 static uint _num_industry_sort; |
388 static uint _num_industry_sort; |
389 |
389 |
390 static char _bufcache[96]; |
390 static char _bufcache[96]; |
391 static byte _last_industry_idx; |
391 static uint16 _last_industry_idx; |
392 |
392 |
393 static byte _industry_sort_order; |
393 static byte _industry_sort_order; |
394 |
394 |
395 static int CDECL GeneralIndustrySorter(const void *a, const void *b) |
395 static int CDECL GeneralIndustrySorter(const void *a, const void *b) |
396 { |
396 { |
397 char buf1[96]; |
397 char buf1[96]; |
398 byte val; |
398 byte val; |
399 Industry *i = DEREF_INDUSTRY(*(const byte*)a); |
399 Industry *i = DEREF_INDUSTRY(*(const uint16*)a); |
400 Industry *j = DEREF_INDUSTRY(*(const byte*)b); |
400 Industry *j = DEREF_INDUSTRY(*(const uint16*)b); |
401 int r = 0; |
401 int r = 0; |
402 |
402 |
403 switch (_industry_sort_order >> 1) { |
403 switch (_industry_sort_order >> 1) { |
404 /* case 0: Sort by Name (handled later) */ |
404 /* case 0: Sort by Name (handled later) */ |
405 case 1: /* Sort by Type */ |
405 case 1: /* Sort by Type */ |
439 // default to string sorting if they are otherwise equal |
439 // default to string sorting if they are otherwise equal |
440 if (r == 0) { |
440 if (r == 0) { |
441 SetDParam(0, i->town->townnameparts); |
441 SetDParam(0, i->town->townnameparts); |
442 GetString(buf1, i->town->townnametype); |
442 GetString(buf1, i->town->townnametype); |
443 |
443 |
444 if ( (val=*(const byte*)b) != _last_industry_idx) { |
444 if ( (val=*(const uint16*)b) != _last_industry_idx) { |
445 _last_industry_idx = val; |
445 _last_industry_idx = val; |
446 SetDParam(0, j->town->townnameparts); |
446 SetDParam(0, j->town->townnameparts); |
447 GetString(_bufcache, j->town->townnametype); |
447 GetString(_bufcache, j->town->townnametype); |
448 } |
448 } |
449 r = strcmp(buf1, _bufcache); |
449 r = strcmp(buf1, _bufcache); |
457 { |
457 { |
458 Industry *i; |
458 Industry *i; |
459 int n = 0, index = 0; |
459 int n = 0, index = 0; |
460 |
460 |
461 for(i=_industries; i != endof(_industries); i++) { |
461 for(i=_industries; i != endof(_industries); i++) { |
462 if(i->xy) _industry_sort[n++] = index; |
462 if(i->xy) |
|
463 _industry_sort[n++] = index; |
|
464 |
463 index++; |
465 index++; |
464 } |
466 } |
465 _num_industry_sort = n; |
467 _num_industry_sort = n; |
466 _last_industry_idx = 255; // used for "cache" |
468 _last_industry_idx = 0xFFFF; // used for "cache" |
467 |
469 |
468 qsort(_industry_sort, n, 1, GeneralIndustrySorter); |
470 qsort(_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter); |
469 |
471 |
470 DEBUG(misc, 1) ("Resorting Industries list..."); |
472 DEBUG(misc, 1) ("Resorting Industries list..."); |
471 } |
473 } |
472 |
474 |
473 |
475 |