Merge branch 'master' into jgrpp
# Conflicts: # .github/workflows/commit-checker.yml # src/industry_cmd.cpp # src/industry_gui.cpp # src/landscape.cpp # src/linkgraph/linkgraph_gui.cpp # src/order_base.h # src/order_cmd.cpp # src/order_gui.cpp # src/saveload/afterload.cpp # src/saveload/league_sl.cpp # src/saveload/saveload.h # src/script/api/script_object.hpp # src/script/squirrel_helper.hpp # src/settings_table.cpp # src/station_cmd.cpp # src/table/settings.h.preamble # src/tree_cmd.cpp # src/tree_map.h # src/vehicle.cpp # src/waypoint_cmd.cpp
This commit is contained in:
@@ -2697,8 +2697,7 @@ bool AfterLoadGame()
|
||||
if (IsTileType(t, MP_TREES)) {
|
||||
uint density = GB(_m[t].m2, 6, 2);
|
||||
uint ground = GB(_m[t].m2, 4, 2);
|
||||
uint counter = GB(_m[t].m2, 0, 4);
|
||||
_m[t].m2 = ground << 6 | density << 4 | counter;
|
||||
_m[t].m2 = ground << 6 | density << 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +352,8 @@ enum SaveLoadVersion : uint16 {
|
||||
SLV_U64_TICK_COUNTER, ///< 300 PR#10035 Make _tick_counter 64bit to avoid wrapping.
|
||||
SLV_LAST_LOADING_TICK, ///< 301 PR#9693 Store tick of last loading for vehicles.
|
||||
SLV_MULTITRACK_LEVEL_CROSSINGS, ///< 302 PR#9931 v13.0 Multi-track level crossings.
|
||||
SLV_NEWGRF_ROAD_STOPS, ///< 303 PR#10144 NewGRF road stops.
|
||||
SLV_LINKGRAPH_EDGES, ///< 304 PR#10314 Explicitly store link graph edges destination.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
|
||||
|
||||
@@ -34,6 +34,12 @@ const SaveLoadCompat _station_spec_list_sl_compat[] = {
|
||||
SLC_VAR("localidx"),
|
||||
};
|
||||
|
||||
/** Nominal field order for SlRoadStopSpecList. */
|
||||
const SaveLoadCompat _station_road_stop_spec_list_sl_compat[] = {
|
||||
SLC_VAR("grfid"),
|
||||
SLC_VAR("localidx"),
|
||||
};
|
||||
|
||||
/** Original field order for SlStationCargo. */
|
||||
const SaveLoadCompat _station_cargo_sl_compat[] = {
|
||||
SLC_VAR("first"),
|
||||
|
||||
@@ -18,13 +18,14 @@
|
||||
namespace upstream_sl {
|
||||
|
||||
static const SaveLoad _league_table_elements_desc[] = {
|
||||
SLE_VAR(LeagueTableElement, table, SLE_UINT8),
|
||||
SLE_VAR(LeagueTableElement, rating, SLE_UINT64),
|
||||
SLE_VAR(LeagueTableElement, company, SLE_UINT8),
|
||||
SLE_SSTR(LeagueTableElement, text, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
SLE_SSTR(LeagueTableElement, score, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
SLE_VAR(LeagueTableElement, link.type, SLE_UINT8),
|
||||
SLE_VAR(LeagueTableElement, link.target, SLE_UINT32),
|
||||
SLE_VAR(LeagueTableElement, table, SLE_UINT8),
|
||||
SLE_CONDVAR(LeagueTableElement, rating, SLE_FILE_U64 | SLE_VAR_I64, SL_MIN_VERSION, SLV_LINKGRAPH_EDGES),
|
||||
SLE_CONDVAR(LeagueTableElement, rating, SLE_INT64, SLV_LINKGRAPH_EDGES, SL_MAX_VERSION),
|
||||
SLE_VAR(LeagueTableElement, company, SLE_UINT8),
|
||||
SLE_SSTR(LeagueTableElement, text, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
SLE_SSTR(LeagueTableElement, score, SLE_STR | SLF_ALLOW_CONTROL),
|
||||
SLE_VAR(LeagueTableElement, link.type, SLE_UINT8),
|
||||
SLE_VAR(LeagueTableElement, link.target, SLE_UINT32),
|
||||
};
|
||||
|
||||
struct LEAEChunkHandler : ChunkHandler {
|
||||
|
||||
@@ -27,6 +27,7 @@ typedef LinkGraph::BaseEdge Edge;
|
||||
static uint16 _num_nodes;
|
||||
static LinkGraph *_linkgraph; ///< Contains the current linkgraph being saved/loaded.
|
||||
static NodeID _linkgraph_from; ///< Contains the current "from" node being saved/loaded.
|
||||
static NodeID _edge_dest_node;
|
||||
static NodeID _edge_next_edge;
|
||||
|
||||
class SlLinkgraphEdge : public DefaultSaveLoadHandler<SlLinkgraphEdge, Node> {
|
||||
@@ -37,7 +38,8 @@ public:
|
||||
SLE_CONDVAR(Edge, travel_time_sum, SLE_UINT64, SLV_LINKGRAPH_TRAVEL_TIME, SL_MAX_VERSION),
|
||||
SLE_VAR(Edge, last_unrestricted_update, SLE_INT32),
|
||||
SLE_CONDVAR(Edge, last_restricted_update, SLE_INT32, SLV_187, SL_MAX_VERSION),
|
||||
SLEG_VAR("next_edge", _edge_next_edge, SLE_UINT16),
|
||||
SLEG_VAR("dest_node", _edge_dest_node, SLE_UINT16),
|
||||
SLEG_CONDVAR("next_edge", _edge_next_edge, SLE_UINT16, SL_MIN_VERSION, SLV_LINKGRAPH_EDGES),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _linkgraph_edge_sl_compat;
|
||||
|
||||
@@ -54,18 +56,29 @@ public:
|
||||
NOT_REACHED();
|
||||
}
|
||||
|
||||
size_t used_size = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? max_size : SlGetStructListLength(UINT16_MAX);
|
||||
if (IsSavegameVersionBefore(SLV_LINKGRAPH_EDGES)) {
|
||||
size_t used_size = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? max_size : SlGetStructListLength(UINT16_MAX);
|
||||
|
||||
/* ... but as that wasted a lot of space we save a sparse matrix now. */
|
||||
for (NodeID to = _linkgraph_from; to != INVALID_NODE; to = _edge_next_edge) {
|
||||
if (used_size == 0) SlErrorCorrupt("Link graph structure overflow");
|
||||
used_size--;
|
||||
/* ... but as that wasted a lot of space we save a sparse matrix now. */
|
||||
for (NodeID to = _linkgraph_from; to != INVALID_NODE; to = _edge_next_edge) {
|
||||
if (used_size == 0) SlErrorCorrupt("Link graph structure overflow");
|
||||
used_size--;
|
||||
|
||||
if (to >= max_size) SlErrorCorrupt("Link graph structure overflow");
|
||||
SlObject(&_linkgraph->edges[std::make_pair(_linkgraph_from, to)], this->GetLoadDescription());
|
||||
if (to >= max_size) SlErrorCorrupt("Link graph structure overflow");
|
||||
SlObject(&_linkgraph->edges[std::make_pair(_linkgraph_from, to)], this->GetLoadDescription());
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) && used_size > 0) SlErrorCorrupt("Corrupted link graph");
|
||||
} else {
|
||||
/* Edge data is now a simple vector and not any kind of matrix. */
|
||||
size_t size = SlGetStructListLength(UINT16_MAX);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
Edge edge;
|
||||
SlObject(&edge, this->GetLoadDescription());
|
||||
if (_edge_dest_node >= max_size) SlErrorCorrupt("Link graph structure overflow");
|
||||
_linkgraph->edges[std::make_pair(_linkgraph_from, _edge_dest_node)] = edge;
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) && used_size > 0) SlErrorCorrupt("Corrupted link graph");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -319,6 +319,7 @@ struct SaveLoadCompat {
|
||||
/**
|
||||
* Storage of simple variables, references (pointers), and arrays.
|
||||
* @param cmd Load/save type. @see SaveLoadType
|
||||
* @param name Field name for table chunks.
|
||||
* @param base Name of the class or struct containing the variable.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
@@ -327,8 +328,20 @@ struct SaveLoadCompat {
|
||||
* @param extra Extra data to pass to the address callback function.
|
||||
* @note In general, it is better to use one of the SLE_* macros below.
|
||||
*/
|
||||
#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SaveLoad {#variable, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra, nullptr}
|
||||
#define SLE_GENERAL2(cmd, base, name, variable, type, length, from, to, extra) SaveLoad {name, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra, nullptr}
|
||||
#define SLE_GENERAL_NAME(cmd, name, base, variable, type, length, from, to, extra) SaveLoad {name, cmd, type, length, from, to, cpp_sizeof(base, variable), [] (void *b, size_t) -> void * { assert(b != nullptr); return const_cast<void *>(static_cast<const void *>(std::addressof(static_cast<base *>(b)->variable))); }, extra, nullptr}
|
||||
|
||||
/**
|
||||
* Storage of simple variables, references (pointers), and arrays with a custom name.
|
||||
* @param cmd Load/save type. @see SaveLoadType
|
||||
* @param base Name of the class or struct containing the variable.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
* @param from First savegame version that has the field.
|
||||
* @param to Last savegame version that has the field.
|
||||
* @param extra Extra data to pass to the address callback function.
|
||||
* @note In general, it is better to use one of the SLE_* macros below.
|
||||
*/
|
||||
#define SLE_GENERAL(cmd, base, variable, type, length, from, to, extra) SLE_GENERAL_NAME(cmd, #variable, base, variable, type, length, from, to, extra)
|
||||
|
||||
/**
|
||||
* Storage of a variable in some savegame versions.
|
||||
@@ -339,7 +352,17 @@ struct SaveLoadCompat {
|
||||
* @param to Last savegame version that has the field.
|
||||
*/
|
||||
#define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to, 0)
|
||||
#define SLE_CONDVAR2(base, name, variable, type, from, to) SLE_GENERAL2(SL_VAR, base, name, variable, type, 0, from, to, 0)
|
||||
|
||||
/**
|
||||
* Storage of a variable in some savegame versions.
|
||||
* @param base Name of the class or struct containing the variable.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param name Field name for table chunks.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
* @param from First savegame version that has the field.
|
||||
* @param to Last savegame version that has the field.
|
||||
*/
|
||||
#define SLE_CONDVARNAME(base, variable, name, type, from, to) SLE_GENERAL_NAME(SL_VAR, name, base, variable, type, 0, from, to, 0)
|
||||
|
||||
/**
|
||||
* Storage of a reference in some savegame versions.
|
||||
@@ -430,7 +453,7 @@ struct SaveLoadCompat {
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLE_VAR(base, variable, type) SLE_CONDVAR(base, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
|
||||
#define SLE_VAR2(base, name, variable, type) SLE_CONDVAR2(base, name, variable, type, SL_MIN_VERSION, SL_MAX_VERSION)
|
||||
#define SLE_VAR2(base, name, variable, type) SLE_CONDVARNAME(base, variable, name, type, SL_MIN_VERSION, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a reference in every version of a savegame.
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "../../roadstop_base.h"
|
||||
#include "../../vehicle_base.h"
|
||||
#include "../../newgrf_station.h"
|
||||
#include "../../newgrf_roadstop.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -102,6 +103,33 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SlRoadStopSpecList : public DefaultSaveLoadHandler<SlRoadStopSpecList, BaseStation> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_VAR(RoadStopSpecList, grfid, SLE_UINT32),
|
||||
SLE_VAR(RoadStopSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _station_road_stop_spec_list_sl_compat;
|
||||
|
||||
void Save(BaseStation *bst) const override
|
||||
{
|
||||
SlSetStructListLength(bst->roadstop_speclist.size());
|
||||
for (uint i = 0; i < bst->roadstop_speclist.size(); i++) {
|
||||
SlObject(&bst->roadstop_speclist[i], this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(BaseStation *bst) const override
|
||||
{
|
||||
uint8 num_specs = (uint8)SlGetStructListLength(UINT8_MAX);
|
||||
|
||||
bst->roadstop_speclist.resize(num_specs);
|
||||
for (uint i = 0; i < num_specs; i++) {
|
||||
SlObject(&bst->roadstop_speclist[i], this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class SlStationCargo : public DefaultSaveLoadHandler<SlStationCargo, GoodsEntry> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
@@ -295,6 +323,35 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SlRoadStopTileData : public DefaultSaveLoadHandler<SlRoadStopTileData, BaseStation> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_VAR(RoadStopTileData, tile, SLE_UINT32),
|
||||
SLE_VAR(RoadStopTileData, random_bits, SLE_UINT8),
|
||||
SLE_VAR(RoadStopTileData, animation_frame, SLE_UINT8),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = {};
|
||||
|
||||
static uint8 last_num_specs; ///< Number of specs of the last loaded station.
|
||||
|
||||
void Save(BaseStation *bst) const override
|
||||
{
|
||||
SlSetStructListLength(bst->custom_roadstop_tile_data.size());
|
||||
for (uint i = 0; i < bst->custom_roadstop_tile_data.size(); i++) {
|
||||
SlObject(&bst->custom_roadstop_tile_data[i], this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(BaseStation *bst) const override
|
||||
{
|
||||
uint32 num_tiles = (uint32)SlGetStructListLength(UINT32_MAX);
|
||||
bst->custom_roadstop_tile_data.resize(num_tiles);
|
||||
for (uint i = 0; i < num_tiles; i++) {
|
||||
SlObject(&bst->custom_roadstop_tile_data[i], this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* SaveLoad handler for the BaseStation, which all other stations / waypoints
|
||||
* make use of.
|
||||
@@ -371,6 +428,7 @@ public:
|
||||
SLE_REFVEC(Station, loading_vehicles, REF_VEHICLE),
|
||||
SLE_CONDVAR(Station, always_accepted, SLE_FILE_U32 | SLE_VAR_U64, SLV_127, SLV_EXTEND_CARGOTYPES),
|
||||
SLE_CONDVAR(Station, always_accepted, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
|
||||
SLEG_CONDSTRUCTLIST("speclist", SlRoadStopTileData, SLV_NEWGRF_ROAD_STOPS, SL_MAX_VERSION),
|
||||
SLEG_STRUCTLIST("goods", SlStationGoods),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _station_normal_sl_compat;
|
||||
@@ -434,6 +492,7 @@ static const SaveLoad _station_desc[] = {
|
||||
SLEG_STRUCT("normal", SlStationNormal),
|
||||
SLEG_STRUCT("waypoint", SlStationWaypoint),
|
||||
SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList, SLV_27, SL_MAX_VERSION),
|
||||
SLEG_CONDSTRUCTLIST("roadstopspeclist", SlRoadStopSpecList, SLV_NEWGRF_ROAD_STOPS, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
struct STNNChunkHandler : ChunkHandler {
|
||||
|
||||
Reference in New Issue
Block a user