summaryrefslogtreecommitdiff
path: root/town.h
diff options
context:
space:
mode:
Diffstat (limited to 'town.h')
-rw-r--r--town.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/town.h b/town.h
index 122a373dc..1ad4a7f04 100644
--- a/town.h
+++ b/town.h
@@ -191,6 +191,28 @@ static inline TownID GetTownArraySize(void)
return _total_towns + 1;
}
+/**
+ * Return a random valid town.
+ */
+static inline Town *GetRandomTown(void)
+{
+ uint num = RandomRange(GetTownArraySize());
+ uint index = 0;
+
+ while (num > 0) {
+ num--;
+
+ index++;
+ /* Make sure we have a valid industry */
+ while (GetTown(index) == NULL) {
+ index++;
+ if (index == GetTownArraySize()) index = 0;
+ }
+ }
+
+ return GetTown(index);
+}
+
static inline bool IsValidTownID(uint index)
{
return index < GetTownPoolSize() && IsValidTown(GetTown(index));