(svn r1292) -Codechange: also updated the town/industry sort-list to be uint16 compatible

This commit is contained in:
truelight 2004-12-28 17:50:17 +00:00
parent e6a59be8c0
commit 6735bffd39
2 changed files with 21 additions and 16 deletions

View File

@ -384,11 +384,11 @@ static const Widget _industry_directory_widgets[] = {
{ WIDGETS_END},
};
static byte _industry_sort[lengthof(_industries)];
static uint16 _industry_sort[lengthof(_industries)];
static uint _num_industry_sort;
static char _bufcache[96];
static byte _last_industry_idx;
static uint16 _last_industry_idx;
static byte _industry_sort_order;
@ -396,8 +396,8 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{
char buf1[96];
byte val;
Industry *i = DEREF_INDUSTRY(*(const byte*)a);
Industry *j = DEREF_INDUSTRY(*(const byte*)b);
Industry *i = DEREF_INDUSTRY(*(const uint16*)a);
Industry *j = DEREF_INDUSTRY(*(const uint16*)b);
int r = 0;
switch (_industry_sort_order >> 1) {
@ -441,7 +441,7 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
SetDParam(0, i->town->townnameparts);
GetString(buf1, i->town->townnametype);
if ( (val=*(const byte*)b) != _last_industry_idx) {
if ( (val=*(const uint16*)b) != _last_industry_idx) {
_last_industry_idx = val;
SetDParam(0, j->town->townnameparts);
GetString(_bufcache, j->town->townnametype);
@ -459,13 +459,15 @@ static void MakeSortedIndustryList()
int n = 0, index = 0;
for(i=_industries; i != endof(_industries); i++) {
if(i->xy) _industry_sort[n++] = index;
if(i->xy)
_industry_sort[n++] = index;
index++;
}
_num_industry_sort = n;
_last_industry_idx = 255; // used for "cache"
_last_industry_idx = 0xFFFF; // used for "cache"
qsort(_industry_sort, n, 1, GeneralIndustrySorter);
qsort(_industry_sort, n, sizeof(_industry_sort[0]), GeneralIndustrySorter);
DEBUG(misc, 1) ("Resorting Industries list...");
}
@ -548,7 +550,7 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
case 8: {
int y = (e->click.pt.y - 28) / 10;
byte p;
uint16 p;
Industry *c;
if (!IS_INT_INSIDE(y, 0, 16))

View File

@ -352,11 +352,11 @@ static const Widget _town_directory_widgets[] = {
// used to get a sorted list of the towns
static byte _town_sort[lengthof(_towns)];
static uint16 _town_sort[lengthof(_towns)];
static uint _num_town_sort;
static char _bufcache[64];
static byte _last_town_idx;
static uint16 _last_town_idx;
static int CDECL TownNameSorter(const void *a, const void *b)
{
@ -365,11 +365,11 @@ static int CDECL TownNameSorter(const void *a, const void *b)
byte val;
int r;
t = DEREF_TOWN(*(const byte*)a);
t = DEREF_TOWN(*(const uint16*)a);
SetDParam(0, t->townnameparts);
GetString(buf1, t->townnametype);
if ( (val=*(const byte*)b) != _last_town_idx) {
if ( (val=*(const uint16*)b) != _last_town_idx) {
_last_town_idx = val;
t = DEREF_TOWN(val);
SetDParam(0, t->townnameparts);
@ -383,8 +383,8 @@ static int CDECL TownNameSorter(const void *a, const void *b)
static int CDECL TownPopSorter(const void *a, const void *b)
{
const Town *ta = DEREF_TOWN(*(const byte*)a);
const Town *tb = DEREF_TOWN(*(const byte*)b);
const Town *ta = DEREF_TOWN(*(const uint16*)a);
const Town *tb = DEREF_TOWN(*(const uint16*)b);
int r = ta->population - tb->population;
if (_town_sort_order & 1) r = -r;
return r;
@ -394,7 +394,10 @@ static void MakeSortedTownList()
{
Town *t;
int n = 0;
FOR_ALL_TOWNS(t) if(t->xy) _town_sort[n++] = t->index;
FOR_ALL_TOWNS(t)
if(t->xy)
_town_sort[n++] = t->index;
_num_town_sort = n;
_last_town_idx = 0; // used for "cache"