# HG changeset patch # User celestar # Date 1174046629 0 # Node ID 7d3a5979a7338f748a49b4172485e26d13ea6404 # Parent 37b56728c4716b46787ef1eaf41283831f707e16 (svn r9253) [gamebalance] -Feature: The economic activity is now displayed in the town directory. It is also possible to sort by it (and the total economic output of a town). diff -r 37b56728c471 -r 7d3a5979a733 src/lang/english.txt --- a/src/lang/english.txt Wed Mar 14 11:15:58 2007 +0000 +++ b/src/lang/english.txt Fri Mar 16 12:03:49 2007 +0000 @@ -368,6 +368,8 @@ STR_SORT_BY :{BLACK}Sort by STR_SORT_BY_POPULATION :{BLACK}Population +STR_SORT_BY_GDP_CAPITA :{BLACK}Wealth +STR_SORT_BY_GDP_TOTAL :{BLACK}Output STR_SORT_BY_PRODUCTION :{BLACK}Production STR_SORT_BY_TYPE :{BLACK}Type STR_SORT_BY_TRANSPORTED :{BLACK}Transported @@ -1679,7 +1681,7 @@ STR_TOWN_BRIBE_THE_LOCAL_AUTHORITY_DESC :{WHITE}{STRING}{}{YELLOW} Bribe the local authority to increase your rating, at the risk of a severe penalty if caught.{} Cost: {CURRENCY} STR_2055_TRAFFIC_CHAOS_IN_ROAD_REBUILDING :{BIGFONT}{BLACK}Traffic chaos in {TOWN}!{}{}Road rebuilding programme funded by {COMPANY} brings 6 months of misery to motorists! STR_2056 :{TINYFONT}{WHITE}{TOWN} -STR_2057 :{ORANGE}{TOWN}{BLACK} ({COMMA}) +STR_2057 :{ORANGE}{TOWN}{BLACK} (Pop: {COMMA}, GDP: {COMMA}%) STR_2058_UNDER_CONSTRUCTION :{STRING} (under construction) STR_2059_IGLOO :Igloo STR_205A_TEPEES :Tepees diff -r 37b56728c471 -r 7d3a5979a733 src/town_gui.cpp --- a/src/town_gui.cpp Wed Mar 14 11:15:58 2007 +0000 +++ b/src/town_gui.cpp Fri Mar 16 12:03:49 2007 +0000 @@ -361,14 +361,16 @@ static const Widget _town_directory_widgets[] = { { WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, -{ WWT_CAPTION, RESIZE_NONE, 13, 11, 195, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS}, -{ WWT_STICKYBOX, RESIZE_NONE, 13, 196, 207, 0, 13, 0x0, STR_STICKY_BUTTON}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, -{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 99, 195, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP}, -{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 195, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, -{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 196, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, -{ WWT_PANEL, RESIZE_TB, 13, 0, 195, 190, 201, 0x0, STR_NULL}, -{ WWT_RESIZEBOX, RESIZE_TB, 13, 196, 207, 190, 201, 0x0, STR_RESIZE_BUTTON}, +{ WWT_CAPTION, RESIZE_NONE, 13, 11, 300, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS}, +{ WWT_STICKYBOX, RESIZE_NONE, 13, 301, 312, 0, 13, 0x0, STR_STICKY_BUTTON}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 74, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 75, 149, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 150, 224, 14, 25, STR_SORT_BY_GDP_CAPITA, STR_SORT_ORDER_TIP}, +{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 225, 300, 14, 25, STR_SORT_BY_GDP_TOTAL, STR_SORT_ORDER_TIP}, +{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 300, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME}, +{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 301, 312, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, +{ WWT_PANEL, RESIZE_TB, 13, 0, 312, 190, 201, 0x0, STR_NULL}, +{ WWT_RESIZEBOX, RESIZE_TB, 13, 301, 312, 190, 201, 0x0, STR_RESIZE_BUTTON}, { WIDGETS_END}, }; @@ -412,9 +414,30 @@ return r; } +static int CDECL TownGDPSorter(const void *a, const void *b) +{ + const Town* ta = *(const Town**)a; + const Town* tb = *(const Town**)b; + int r = (ta->GetActivity() * 100) - (tb->GetActivity() * 100); + if (_town_sort_order & 1) r = -r; + return r; +} + +static int CDECL TownOutputSorter(const void *a, const void *b) +{ + const Town* ta = *(const Town**)a; + const Town* tb = *(const Town**)b; + int r = (ta->GetActivity() * 100 * ta->population) - (tb->GetActivity() * 100 * tb->population); + if (_town_sort_order & 1) r = -r; + return r; +} + static void MakeSortedTownList(void) { const Town* t; + int (*townsortproc[])(const void *a, const void *b) = { + TownNameSorter, TownPopSorter, TownGDPSorter, TownOutputSorter + }; uint n = 0; /* Create array for sorting */ @@ -426,7 +449,7 @@ _num_town_sort = n; _last_town = NULL; // used for "cache" - qsort((void*)_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter); + qsort((void*)_town_sort, n, sizeof(_town_sort[0]), townsortproc[_town_sort_order / 2]); DEBUG(misc, 3, "Resorting towns list"); } @@ -444,7 +467,7 @@ SetVScrollCount(w, _num_town_sort); DrawWindowWidgets(w); - DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, 0x10); + DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, 66 + (_town_sort_order / 2) * 75, 15, 0x10); { int n = 0; @@ -458,6 +481,7 @@ SetDParam(0, t->index); SetDParam(1, t->population); + SetDParam(2, t->GetActivity() * 100); DrawString(2, y, STR_2057, 0); y += 10; @@ -471,19 +495,17 @@ case WE_CLICK: switch (e->we.click.widget) { - case 3: { /* Sort by Name ascending/descending */ - _town_sort_order = (_town_sort_order == 0) ? 1 : 0; + case 3: /* Sort by Name ascending/descending */ + case 4: /* Sort by Population ascending/descending */ + case 5: /* Sort by GDP per capita */ + case 6: { /* Sort by economic output */ + int sorter = e->we.click.widget - 3; + _town_sort_order = (_town_sort_order == 2 * sorter) ? 2 * sorter + 1 : 2 * sorter; _town_sort_dirty = true; SetWindowDirty(w); } break; - case 4: { /* Sort by Population ascending/descending */ - _town_sort_order = (_town_sort_order == 2) ? 3 : 2; - _town_sort_dirty = true; - SetWindowDirty(w); - } break; - - case 5: { /* Click on Town Matrix */ + case 7: { /* Click on Town Matrix */ const Town* t; uint16 id_v = (e->we.click.pt.y - 28) / 10; @@ -513,7 +535,7 @@ } static const WindowDesc _town_directory_desc = { - WDP_AUTO, WDP_AUTO, 208, 202, + WDP_AUTO, WDP_AUTO, 313, 202, WC_TOWN_DIRECTORY, WC_NONE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _town_directory_widgets, @@ -531,3 +553,5 @@ w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high } } + +