summaryrefslogtreecommitdiff
path: root/town.h
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
commit777dd99585ca5a775cd189eedd81e27d3ca395ed (patch)
treeb7d40aab99c9bff1a5304e4659c8cc7748b8a881 /town.h
parent6d5fdc2b6883f3522ccd0d4fa49e5855c5c70f79 (diff)
downloadopenttd-777dd99585ca5a775cd189eedd81e27d3ca395ed.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.h')
-rw-r--r--town.h25
1 files changed, 18 insertions, 7 deletions
diff --git a/town.h b/town.h
index a8757d596..c5c3b574f 100644
--- a/town.h
+++ b/town.h
@@ -1,6 +1,7 @@
#ifndef TOWN_H
#define TOWN_H
+#include "pool.h"
#include "player.h"
struct Town {
@@ -128,20 +129,30 @@ enum {
bool CheckforTownRating(uint tile, uint32 flags, Town *t, byte type);
-VARDEF Town _towns[250];
-VARDEF uint _towns_size;
-
VARDEF uint16 *_town_sort;
+extern MemoryPool _town_pool;
+
+/**
+ * Get the pointer to the town with index 'index'
+ */
static inline Town *GetTown(uint index)
{
- assert(index < _towns_size);
- return &_towns[index];
+ return (Town*)GetItemFromPool(&_town_pool, index);
+}
+
+/**
+ * Get the current size of the TownPool
+ */
+static inline uint16 GetTownPoolSize(void)
+{
+ return _town_pool.total_items;
}
-#define FOR_ALL_TOWNS(t) for(t = _towns; t != &_towns[_towns_size]; t++)
+#define FOR_ALL_TOWNS_FROM(t, start) for (t = GetTown(start); t != NULL; t = (t->index + 1 < GetTownPoolSize()) ? GetTown(t->index + 1) : NULL)
+#define FOR_ALL_TOWNS(t) FOR_ALL_TOWNS_FROM(t, 0)
-VARDEF int _total_towns; // For the AI: the amount of towns active
+VARDEF uint _total_towns; // For the AI: the amount of towns active
VARDEF bool _town_sort_dirty;
VARDEF byte _town_sort_order;