summaryrefslogtreecommitdiff
path: root/town_gui.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2005-02-01 18:32:01 +0000
committertruelight <truelight@openttd.org>2005-02-01 18:32:01 +0000
commit59ac6e8c4b2e564a864260d6715d2128a291b1d0 (patch)
treeb7d40aab99c9bff1a5304e4659c8cc7748b8a881 /town_gui.c
parent567224e94089f26e0c64aa37c7c40937285fb8fa (diff)
downloadopenttd-59ac6e8c4b2e564a864260d6715d2128a291b1d0.tar.xz
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
you have that amount of towns in a map ;))
Diffstat (limited to 'town_gui.c')
-rw-r--r--town_gui.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/town_gui.c b/town_gui.c
index 96922d357..cd08386b1 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -367,14 +367,18 @@ static int CDECL TownNameSorter(const void *a, const void *b)
{
char buf1[64];
const Town *t;
- byte val;
+ uint16 val;
int r;
t = GetTown(*(const uint16*)a);
SetDParam(0, t->townnameparts);
GetString(buf1, t->townnametype);
- if ( (val=*(const uint16*)b) != _last_town_idx) {
+ /* If 'b' is the same town as in the last round, use the cached value
+ * We do this to speed stuff up ('b' is called with the same value a lot of
+ * times after eachother) */
+ val = *(const uint16*)b;
+ if (val != _last_town_idx) {
_last_town_idx = val;
t = GetTown(val);
SetDParam(0, t->townnameparts);
@@ -401,12 +405,12 @@ static void MakeSortedTownList(void)
int n = 0;
/* Create array for sorting */
- _town_sort = realloc(_town_sort, _towns_size * sizeof(_town_sort[0]));
+ _town_sort = realloc(_town_sort, GetTownPoolSize() * 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)
+ if (t->xy)
_town_sort[n++] = t->index;
_num_town_sort = n;