summaryrefslogtreecommitdiff
path: root/town_gui.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-01-06 22:31:58 +0000
committertruelight <truelight@openttd.org>2005-01-06 22:31:58 +0000
commit63e97754fbf907cfefd277087bfbac5e0d4434e8 (patch)
tree254702245ba43d006f4823111d0c2c592fb701ca /town_gui.c
parenta4111363c0def2ccec66ef28b5e8169e8a2df2f0 (diff)
downloadopenttd-63e97754fbf907cfefd277087bfbac5e0d4434e8.tar.xz
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
(in prepare of dynamic arrays): - DEREF_XXX is changed into GetXXX - All direct call are directed via GetXXX - struct Industry has now an index-field - ENUM'd some stuff - Replaced home built loops with FOR_ALL_XXX - Added _stations_size, _vehicles_size, ... which gives the length of the array (which will be dynamic in the near future) - Changed lengtof(XXX) to _XXX_size (e.g. _stations_size) - Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX) - Made the sort-functions of all 4 dynamic - Made all 4 Initialize functions more of the same - Some minor tab-fixing and stuff (tnx to Tron for proof-reading my 100kb patch ;)) Note for all: please do NOT directly call _stations, _vehicles, _towns and _industries, but use the right wrapper to access them. Thank you. Ps: please also do not use 'v++', where v is of type Vehicle *.
Diffstat (limited to 'town_gui.c')
-rw-r--r--town_gui.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/town_gui.c b/town_gui.c
index a263c2087..171294732 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -85,7 +85,7 @@ static void TownAuthorityWndProc(Window *w, WindowEvent *e)
{
uint buttons;
int numact;
- Town *t = DEREF_TOWN(w->window_number);
+ Town *t = GetTown(w->window_number);
switch(e->event) {
case WE_PAINT:
@@ -224,7 +224,7 @@ static void ShowTownAuthorityWindow(uint town)
static void TownViewWndProc(Window *w, WindowEvent *e)
{
- Town *t = DEREF_TOWN(w->window_number);
+ Town *t = GetTown(w->window_number);
switch(e->event) {
case WE_PAINT:
@@ -338,7 +338,7 @@ void ShowTownViewWindow(uint town)
if (w) {
w->flags4 |= WF_DISABLE_VP_SCROLL;
- t = DEREF_TOWN(w->window_number);
+ t = GetTown(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, t->xy, 1);
}
}
@@ -357,7 +357,6 @@ static const Widget _town_directory_widgets[] = {
// used to get a sorted list of the towns
-static uint16 _town_sort[lengthof(_towns)];
static uint _num_town_sort;
static char _bufcache[64];
@@ -370,13 +369,13 @@ static int CDECL TownNameSorter(const void *a, const void *b)
byte val;
int r;
- t = DEREF_TOWN(*(const uint16*)a);
+ t = GetTown(*(const uint16*)a);
SetDParam(0, t->townnameparts);
GetString(buf1, t->townnametype);
if ( (val=*(const uint16*)b) != _last_town_idx) {
_last_town_idx = val;
- t = DEREF_TOWN(val);
+ t = GetTown(val);
SetDParam(0, t->townnameparts);
GetString(_bufcache, t->townnametype);
}
@@ -388,8 +387,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 uint16*)a);
- const Town *tb = DEREF_TOWN(*(const uint16*)b);
+ const Town *ta = GetTown(*(const uint16*)a);
+ const Town *tb = GetTown(*(const uint16*)b);
int r = ta->population - tb->population;
if (_town_sort_order & 1) r = -r;
return r;
@@ -399,6 +398,12 @@ static void MakeSortedTownList()
{
Town *t;
int n = 0;
+
+ /* Create array for sorting */
+ _town_sort = realloc(_town_sort, _towns_size * sizeof(_town_sort[0]));
+ if (_town_sort == NULL)
+ error("Could not allocate memory for the town-sorting-list");
+
FOR_ALL_TOWNS(t)
if(t->xy)
_town_sort[n++] = t->index;
@@ -434,7 +439,7 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
int y = 28;
while (i < _num_town_sort) {
- t = DEREF_TOWN(_town_sort[i]);
+ t = GetTown(_town_sort[i]);
assert(t->xy);
@@ -473,7 +478,7 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
if (id_v >= _num_town_sort) { return;} // click out of town bounds
{
- Town *t = DEREF_TOWN(_town_sort[id_v]);
+ Town *t = GetTown(_town_sort[id_v]);
assert(t->xy);
ScrollMainWindowToTile(t->xy);