(svn r16709) -Fix [FS#2994]: the list of animated tiles could have duplicates (only for old savegames) and tiles that weren't animated

This commit is contained in:
rubidium 2009-07-01 14:51:05 +00:00
parent 8db99f57f8
commit 927c4a0fe8
5 changed files with 37 additions and 1 deletions

View File

@ -141,6 +141,10 @@ Industry::~Industry()
if (GetIndustryIndex(tile_cur) == this->index) { if (GetIndustryIndex(tile_cur) == this->index) {
/* MakeWaterKeepingClass() can also handle 'land' */ /* MakeWaterKeepingClass() can also handle 'land' */
MakeWaterKeepingClass(tile_cur, OWNER_NONE); 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)) { } else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
DeleteOilRig(tile_cur); DeleteOilRig(tile_cur);

View File

@ -22,6 +22,7 @@
#include "effectvehicle_func.h" #include "effectvehicle_func.h"
#include "landscape_type.h" #include "landscape_type.h"
#include "settings_type.h" #include "settings_type.h"
#include "animated_tile_func.h"
#include "table/sprites.h" #include "table/sprites.h"
@ -471,6 +472,9 @@ void DrawFoundation(TileInfo *ti, Foundation f)
void DoClearSquare(TileIndex tile) 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); MakeClear(tile, CLEAR_GRASS, _generating_world ? 3 : 0);
MarkTileDirtyByTile(tile); MarkTileDirtyByTile(tile);
} }

View File

@ -30,6 +30,7 @@
#include "../ai/ai.hpp" #include "../ai/ai.hpp"
#include "../town.h" #include "../town.h"
#include "../economy_base.h" #include "../economy_base.h"
#include "../animated_tile_func.h"
#include "table/strings.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(); AfterLoadLabelMaps();
GamelogPrintDebug(1); GamelogPrintDebug(1);

View File

@ -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; byte old_specindex = IsTileType(tile, MP_STATION) ? GetCustomStationSpecIndex(tile) : 0;
MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p1, 0, 4)); MakeRailStation(tile, st->owner, st->index, axis, layout & ~1, (RailType)GB(p1, 0, 4));
/* Free the spec if we overbuild something */ /* Free the spec if we overbuild something */
@ -2948,6 +2950,7 @@ void BuildOilRig(TileIndex tile)
st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG); st->string_id = GenerateStationName(st, tile, STATIONNAMING_OILRIG);
assert(IsTileType(tile, MP_INDUSTRY)); assert(IsTileType(tile, MP_INDUSTRY));
DeleteAnimatedTile(tile);
MakeOilrig(tile, st->index, GetWaterClass(tile)); MakeOilrig(tile, st->index, GetWaterClass(tile));
st->owner = OWNER_NONE; st->owner = OWNER_NONE;

View File

@ -174,7 +174,7 @@ static inline void AddProducedCargo(TileIndex tile, CargoArray &produced)
static inline void AnimateTile(TileIndex tile) static inline void AnimateTile(TileIndex tile)
{ {
AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc; AnimateTileProc *proc = _tile_type_procs[GetTileType(tile)]->animate_tile_proc;
if (proc == NULL) return; assert(proc != NULL);
proc(tile); proc(tile);
} }