(svn r3198) Rewrite the company league drawing routine for better readability

This commit is contained in:
tron 2005-11-16 12:10:45 +00:00
parent 67dcf1ffd8
commit 839cb586a7

View File

@ -813,37 +813,33 @@ static inline StringID GetPerformanceTitleFromValue(uint value)
return _performance_titles[minu(value, 1000) >> 6];
}
static int CDECL _perf_hist_comp(const void *elem1, const void *elem2 ) {
static int CDECL PerfHistComp(const void* elem1, const void* elem2)
{
const Player* p1 = *(const Player* const*)elem1;
const Player* p2 = *(const Player* const*)elem2;
int32 v = p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
return (v!=0) | (v >> (sizeof(int32)*8-1));
return p2->old_economy[1].performance_history - p1->old_economy[1].performance_history;
}
static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
const Player* plist[MAX_PLAYERS];
const Player* p;
Player const *plist[MAX_PLAYERS];
uint pl_num;
uint i;
DrawWindowWidgets(w);
pl_num = 0;
FOR_ALL_PLAYERS(p) {
if (p->is_active)
plist[pl_num++] = p;
}
assert(pl_num > 0);
FOR_ALL_PLAYERS(p) if (p->is_active) plist[pl_num++] = p;
qsort((void*)plist, pl_num, sizeof(Player*), _perf_hist_comp);
qsort(plist, pl_num, sizeof(*plist), PerfHistComp);
i = 0;
do {
SetDParam(0, i + STR_01AC_1ST);
for (i = 0; i != pl_num; i++) {
p = plist[i];
SetDParam(0, i + STR_01AC_1ST);
SetDParam(1, p->name_1);
SetDParam(2, p->name_2);
SetDParam(3, GetPlayerNameString(p->index, 4));
@ -851,7 +847,7 @@ static void CompanyLeagueWndProc(Window *w, WindowEvent *e)
DrawString(2, 15 + i * 10, i == 0 ? STR_7054 : STR_7055, 0);
DrawPlayerIcon(p->index, 27, 16 + i * 10);
} while (++i != pl_num);
}
break;
}