10 #include "../stdafx.h"
15 #include "../map_func.h"
16 #include "../core/bitmath_func.hpp"
19 #include "../safeguards.h"
21 static uint32_t _map_dim_x;
22 static uint32_t _map_dim_y;
24 static const SaveLoad _map_desc[] = {
67 static const uint MAP_SL_BUF_SIZE = 4096;
74 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
78 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
79 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
type() = buf[j];
85 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
90 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
type();
91 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
101 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
105 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
106 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
height() = buf[j];
112 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
117 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
height();
118 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
128 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
132 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
133 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m1() = buf[j];
139 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
144 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m1();
145 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
155 std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
159 SlCopy(buf.data(), MAP_SL_BUF_SIZE,
163 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m2() = buf[j];
169 std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
172 SlSetLength(
static_cast<uint32_t
>(size) *
sizeof(uint16_t));
174 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m2();
175 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
185 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
189 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
190 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m3() = buf[j];
196 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
201 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m3();
202 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
212 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
216 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
217 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m4() = buf[j];
223 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
228 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m4();
229 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
239 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
243 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
244 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m5() = buf[j];
250 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
255 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m5();
256 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
266 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
272 SlCopy(buf.data(), 1024, SLE_UINT8);
273 for (uint j = 0; j != 1024; j++) {
282 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
283 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m6() = buf[j];
290 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
295 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m6();
296 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
306 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
310 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
311 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m7() = buf[j];
317 std::array<uint8_t, MAP_SL_BUF_SIZE> buf;
322 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m7();
323 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
333 std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
337 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
338 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++)
Tile(i++).
m8() = buf[j];
344 std::array<uint16_t, MAP_SL_BUF_SIZE> buf;
347 SlSetLength(
static_cast<uint32_t
>(size) *
sizeof(uint16_t));
349 for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] =
Tile(i++).
m8();
350 SlCopy(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Wrapper class to abstract away the way the tiles are stored.
debug_inline uint16_t & m8()
General purpose.
debug_inline uint8_t & m7()
Primarily used for newgrf support.
debug_inline uint8_t & type()
The type (bits 4..7), bridges (2..3), rainforest/desert (0..1)
debug_inline uint8_t & m5()
General purpose.
debug_inline uint8_t & m1()
Primarily used for ownership information.
debug_inline uint8_t & m4()
General purpose.
debug_inline uint8_t & height()
The height of the northern corner.
debug_inline uint16_t & m2()
Primarily used for indices to towns, industries and stations.
debug_inline uint8_t & m6()
General purpose.
debug_inline uint8_t & m3()
General purpose.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Loading for map chunks before table headers were added.
const SaveLoadCompat _map_sl_compat[]
Original field order for _map_desc.
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
void SlCopy(void *object, size_t length, VarType conv)
Copy a list of SL_VARs to/from a savegame.
void SlErrorCorrupt(const std::string &msg)
Error handler for corrupt savegames.
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
void SlSetLength(size_t length)
Sets the length of either a RIFF object or the number of items in an array.
void SlGlobList(const SaveLoadTable &slt)
Save or Load (a list of) global variables.
Functions/types related to saving and loading games.
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
@ SLV_RIFF_TO_ARRAY
294 PR#9375 Changed many CH_RIFF chunks to CH_ARRAY chunks.
@ SL_MAX_VERSION
Highest possible saveload version.
@ SLV_5
5.0 1429 5.1 1440 5.2 1525 0.3.6
Handlers and description of chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void Save() const override
Save the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
void LoadCheck(size_t) const override
Load the chunk for game preview.
void Load() const override
Load the chunk.
void Load() const override
Load the chunk.
void Save() const override
Save the chunk.
static uint SizeY()
Get the size of the map along the Y.
static debug_inline uint SizeX()
Get the size of the map along the X.
static void Allocate(uint size_x, uint size_y)
(Re)allocates a map with the given dimension
static debug_inline uint Size()
Get the size of the map.