Add: Overlay cargo icon in vehicle/depot list when holding shift+ctrl. (#12938)
[openttd-github.git] / src / saveload / animated_tile_sl.cpp
blob950cc9c20c6a659cb8142bf3cb828dfd46fed237
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file animated_tile_sl.cpp Code handling saving and loading of animated tiles */
10 #include "../stdafx.h"
12 #include "saveload.h"
13 #include "compat/animated_tile_sl_compat.h"
15 #include "../tile_type.h"
17 #include "../safeguards.h"
19 extern std::vector<TileIndex> _animated_tiles;
21 static const SaveLoad _animated_tile_desc[] = {
22 SLEG_VECTOR("tiles", _animated_tiles, SLE_UINT32),
25 struct ANITChunkHandler : ChunkHandler {
26 ANITChunkHandler() : ChunkHandler('ANIT', CH_TABLE) {}
28 void Save() const override
30 SlTableHeader(_animated_tile_desc);
32 SlSetArrayIndex(0);
33 SlGlobList(_animated_tile_desc);
36 void Load() const override
38 /* Before version 80 we did NOT have a variable length animated tile table */
39 if (IsSavegameVersionBefore(SLV_80)) {
40 /* In pre version 6, we has 16bit per tile, now we have 32bit per tile, convert it ;) */
41 TileIndex anim_list[256];
42 SlCopy(anim_list, 256, IsSavegameVersionBefore(SLV_6) ? (SLE_FILE_U16 | SLE_VAR_U32) : SLE_UINT32);
44 for (int i = 0; i < 256; i++) {
45 if (anim_list[i] == 0) break;
46 _animated_tiles.push_back(anim_list[i]);
48 return;
51 if (IsSavegameVersionBefore(SLV_RIFF_TO_ARRAY)) {
52 size_t count = SlGetFieldLength() / sizeof(_animated_tiles.front());
53 _animated_tiles.clear();
54 _animated_tiles.resize(_animated_tiles.size() + count);
55 SlCopy(_animated_tiles.data(), count, SLE_UINT32);
56 return;
59 const std::vector<SaveLoad> slt = SlCompatTableHeader(_animated_tile_desc, _animated_tile_sl_compat);
61 if (SlIterateArray() == -1) return;
62 SlGlobList(slt);
63 if (SlIterateArray() != -1) SlErrorCorrupt("Too many ANIT entries");
68 static const ANITChunkHandler ANIT;
69 static const ChunkHandlerRef animated_tile_chunk_handlers[] = {
70 ANIT,
73 extern const ChunkHandlerTable _animated_tile_chunk_handlers(animated_tile_chunk_handlers);