diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index f5044b05de..528d4ff3c5 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -84,7 +84,7 @@ struct PersistentStorageArray : BaseStorageArray { if (this->storage[pos] == value) return; /* We do not have made a backup; lets do so */ - if (this->prev_storage != NULL) { + if (this->prev_storage == NULL) { this->prev_storage = MallocT(SIZE); memcpy(this->prev_storage, this->storage, sizeof(this->storage)); @@ -121,6 +121,7 @@ struct PersistentStorageArray : BaseStorageArray { memcpy(this->storage, this->prev_storage, sizeof(this->storage)); } free(this->prev_storage); + this->prev_storage = NULL; } }; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 91ba3a5e89..34c148b0f7 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1196,11 +1196,15 @@ bool AfterLoadGame() switch (GetTileType(t)) { case MP_RAILWAY: if (HasSignals(t)) { + /* Original signal type/variant was stored in m4 but since saveload + * version 48 they are in m2. The bits has been already moved to m2 + * (see the code somewhere above) so don't use m4, use m2 instead. */ + /* convert PBS signals to combo-signals */ - if (HasBit(_m[t].m2, 2)) SetSignalType(t, TRACK_X, SIGTYPE_COMBO); + if (HasBit(_m[t].m2, 2)) SB(_m[t].m2, 0, 2, SIGTYPE_COMBO); /* move the signal variant back */ - SetSignalVariant(t, TRACK_X, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC); + SB(_m[t].m2, 2, 1, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC); ClrBit(_m[t].m2, 3); } @@ -1480,13 +1484,15 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(64)) { - /* copy the signal type/variant and move signal states bits */ + /* Since now we allow different signal types and variants on a single tile. + * Move signal states to m4 to make room and clone the signal type/variant. */ for (TileIndex t = 0; t < map_size; t++) { if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) { + /* move signal states */ SetSignalStates(t, GB(_m[t].m2, 4, 4)); - SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X)); - SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X)); - ClrBit(_m[t].m2, 7); + SB(_m[t].m2, 4, 4, 0); + /* clone signal type and variant */ + SB(_m[t].m2, 4, 3, GB(_m[t].m2, 0, 3)); } } } diff --git a/src/string.cpp b/src/string.cpp index ada9f9022a..301f150f89 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -608,7 +608,7 @@ char *strcasestr(const char *haystack, const char *needle) */ static const char *SkipGarbage(const char *str) { - while (*str != '\0' && (*str < 'A' || IsInsideMM(*str, '[', '`' + 1) || IsInsideMM(*str, '{', '~' + 1))) str++; + while (*str != '\0' && (*str < '0' || IsInsideMM(*str, ';', '@' + 1) || IsInsideMM(*str, '[', '`' + 1) || IsInsideMM(*str, '{', '~' + 1))) str++; return str; } diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 3daea33a22..bd2deb2611 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -3139,8 +3139,9 @@ bool TrainController(Train *v, Vehicle *nomove, bool reverse) * this to one, then if we reach the next signal it is * decreased to zero and we won't pass that new signal. */ Trackdir dir = FindFirstTrackdir(trackdirbits); - if (GetSignalType(gp.new_tile, TrackdirToTrack(dir)) != SIGTYPE_PBS || - !HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(dir))) { + if (HasSignalOnTrackdir(gp.new_tile, dir) || + (HasSignalOnTrackdir(gp.new_tile, ReverseTrackdir(dir)) && + GetSignalType(gp.new_tile, TrackdirToTrack(dir)) != SIGTYPE_PBS)) { /* However, we do not want to be stopped by PBS signals * entered via the back. */ v->force_proceed = (v->force_proceed == TFP_SIGNAL) ? TFP_STUCK : TFP_NONE;