From 927c4a0fe8b836fe88ca0636d2249016501dc9c3 Mon Sep 17 00:00:00 2001 From: rubidium Date: Wed, 1 Jul 2009 14:51:05 +0000 Subject: (svn r16709) -Fix [FS#2994]: the list of animated tiles could have duplicates (only for old savegames) and tiles that weren't animated --- src/industry_cmd.cpp | 4 ++++ src/landscape.cpp | 4 ++++ src/saveload/afterload.cpp | 25 +++++++++++++++++++++++++ src/station_cmd.cpp | 3 +++ src/tile_cmd.h | 2 +- 5 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 0f7bf1a7c..92d510cd2 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -141,6 +141,10 @@ Industry::~Industry() if (GetIndustryIndex(tile_cur) == this->index) { /* MakeWaterKeepingClass() can also handle 'land' */ MakeWaterKeepingClass(tile_cur, OWNER_NONE); + + /* MakeWaterKeepingClass() doesn't remove animation if the tiles + * become watery, but be on the safe side an always remote it. */ + DeleteAnimatedTile(tile_cur); } } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { DeleteOilRig(tile_cur); diff --git a/src/landscape.cpp b/src/landscape.cpp index 372cf5d50..bf1d4414e 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -22,6 +22,7 @@ #include "effectvehicle_func.h" #include "landscape_type.h" #include "settings_type.h" +#include "animated_tile_func.h" #include "table/sprites.h" @@ -471,6 +472,9 @@ void DrawFoundation(TileInfo *ti, Foundation f) void DoClearSquare(TileIndex tile) { + /* If the tile can have animation and we clear it, delete it from the animated tile list. */ + if (_tile_type_procs[GetTileType(tile)]->animate_tile_proc != NULL) DeleteAnimatedTile(tile); + MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0); MarkTileDirtyByTile(tile); } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 26ca23b22..afe2060a7 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -30,6 +30,7 @@ #include "../ai/ai.hpp" #include "../town.h" #include "../economy_base.h" +#include "../animated_tile_func.h" #include "table/strings.h" @@ -1890,6 +1891,30 @@ bool AfterLoadGame() } } + if (CheckSavegameVersion(122)) { + /* Animated tiles would sometimes not be actually animated or + * in case of old savegames duplicate. */ + + extern TileIndex *_animated_tile_list; + extern uint _animated_tile_count; + + for (uint i = 0; i < _animated_tile_count; /* Nothing */) { + /* Remove if tile is not animated */ + bool remove = _tile_type_procs[GetTileType(_animated_tile_list[i])]->animate_tile_proc == NULL; + + /* and remove if duplicate */ + for (uint j = 0; !remove && j < i; j++) { + remove = _animated_tile_list[i] == _animated_tile_list[j]; + } + + if (remove) { + DeleteAnimatedTile(_animated_tile_list[i]); + } else { + i++; + } + } + } + AfterLoadLabelMaps(); GamelogPrintDebug(1); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index bd2c41dfe..7db3d6d6c 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1003,6 +1003,8 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, DoCommandFlag flags, uin } } + /* Remove animation if overbuilding */ + DeleteAnimatedTile(tile); byte old_specindex = IsTileType(tile, MP_STATION) ? GetCustomStationSpecIndex(tile) : 0; MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p1, 0, 4)); /* Free the spec if we overbuild something */ @@ -2948,6 +2950,7 @@ void BuildOilRig(TileIndex tile) st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG); assert(IsTileType(tile, MP_INDUSTRY)); + DeleteAnimatedTile(tile); MakeOilrig(tile, st->index, GetWaterClass(tile)); st->owner = OWNER_NONE; diff --git a/src/tile_cmd.h b/src/tile_cmd.h index 1b6c44128..59504ec1f 100644 --- a/src/tile_cmd.h +++ b/src/tile_cmd.h @@ -174,7 +174,7 @@ static inline void AddProducedCargo(TileIndex tile, CargoArray &produced) static inline void AnimateTile(TileIndex tile) { AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc; - if (proc == NULL) return; + assert(proc != NULL); proc(tile); } -- cgit v1.2.3-70-g09d2