summaryrefslogtreecommitdiff
path: root/src/newgrf_station.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-10 14:30:01 +0000
committerrubidium <rubidium@openttd.org>2009-01-10 14:30:01 +0000
commitdb546e607f72c70fb89fe05f5baa7b425bb92123 (patch)
treeef237d224d69edabc827ec3232e4d484491a57d9 /src/newgrf_station.cpp
parent1b546505d29c69f1d25bfb3fe45fa2f617554b69 (diff)
downloadopenttd-db546e607f72c70fb89fe05f5baa7b425bb92123.tar.xz
(svn r14956) -Fix [FS#1832]: building new station parts didn't allocate a new station spec effectively breaking variable 41. This was due to the limited number of station specs that we can have per station. This fix makes newly build station parts create a new spec until one cannot allocate new station specs anymore and it'll revert to the old behaviour (sharing station specs).
Diffstat (limited to 'src/newgrf_station.cpp')
-rw-r--r--src/newgrf_station.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index be0253f95..a2ad21ec6 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -693,16 +693,22 @@ int AllocateSpecToStation(const StationSpec *statspec, Station *st, bool exec)
if (statspec == NULL || st == NULL) return 0;
- /* Check if this spec has already been allocated */
- for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
- if (st->speclist[i].spec == statspec) return i;
- }
-
for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
if (st->speclist[i].spec == NULL && st->speclist[i].grfid == 0) break;
}
- if (i == MAX_SPECLIST) return -1;
+ if (i == MAX_SPECLIST) {
+ /* As final effort when the spec list is already full...
+ * try to find the same spec and return that one. This might
+ * result in slighty "wrong" (as per specs) looking stations,
+ * but it's fairly unlikely that one reaches the limit anyways.
+ */
+ for (i = 1; i < st->num_specs && i < MAX_SPECLIST; i++) {
+ if (st->speclist[i].spec == statspec) return i;
+ }
+
+ return -1;
+ }
if (exec) {
if (i >= st->num_specs) {