mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Replace separate Station/RoadStopSpecList with template struct.
Reduces duplication and simplifies reuse. Additionally naming an item that is used in a list as a ...List was pretty weird.pull/12212/head
parent
278c3a7db1
commit
41b3314d76
|
@ -19,16 +19,11 @@
|
||||||
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
typedef Pool<BaseStation, StationID, 32, 64000> StationPool;
|
||||||
extern StationPool _station_pool;
|
extern StationPool _station_pool;
|
||||||
|
|
||||||
struct StationSpecList {
|
template <typename T>
|
||||||
const StationSpec *spec;
|
struct SpecMapping {
|
||||||
uint32_t grfid; ///< GRF ID of this custom station
|
const T *spec; ///< Custom spec.
|
||||||
uint16_t localidx; ///< Station ID within GRF of station
|
uint32_t grfid; ///< GRF ID of this custom spec.
|
||||||
};
|
uint16_t localidx; ///< Local ID within GRF of this custom spec.
|
||||||
|
|
||||||
struct RoadStopSpecList {
|
|
||||||
const RoadStopSpec *spec;
|
|
||||||
uint32_t grfid; ///< GRF ID of this custom road stop
|
|
||||||
uint16_t localidx; ///< Station ID within GRF of road stop
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RoadStopTileData {
|
struct RoadStopTileData {
|
||||||
|
@ -74,8 +69,8 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
|
||||||
Owner owner; ///< The owner of this station
|
Owner owner; ///< The owner of this station
|
||||||
StationFacility facilities; ///< The facilities that this station has
|
StationFacility facilities; ///< The facilities that this station has
|
||||||
|
|
||||||
std::vector<StationSpecList> speclist; ///< List of rail station specs of this station.
|
std::vector<SpecMapping<StationSpec>> speclist; ///< List of rail station specs of this station.
|
||||||
std::vector<RoadStopSpecList> roadstop_speclist; ///< List of road stop specs of this station
|
std::vector<SpecMapping<RoadStopSpec>> roadstop_speclist; ///< List of road stop specs of this station
|
||||||
|
|
||||||
TimerGameCalendar::Date build_date; ///< Date of construction
|
TimerGameCalendar::Date build_date; ///< Date of construction
|
||||||
|
|
||||||
|
|
|
@ -205,9 +205,9 @@ static void SwapPackets(GoodsEntry *ge)
|
||||||
class SlStationSpecList : public DefaultSaveLoadHandler<SlStationSpecList, BaseStation> {
|
class SlStationSpecList : public DefaultSaveLoadHandler<SlStationSpecList, BaseStation> {
|
||||||
public:
|
public:
|
||||||
inline static const SaveLoad description[] = {
|
inline static const SaveLoad description[] = {
|
||||||
SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION),
|
SLE_CONDVAR(SpecMapping<StationSpec>, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION),
|
||||||
SLE_CONDVAR(StationSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING),
|
SLE_CONDVAR(SpecMapping<StationSpec>, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING),
|
||||||
SLE_CONDVAR(StationSpecList, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
|
SLE_CONDVAR(SpecMapping<StationSpec>, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
|
||||||
};
|
};
|
||||||
inline const static SaveLoadCompatTable compat_description = _station_spec_list_sl_compat;
|
inline const static SaveLoadCompatTable compat_description = _station_spec_list_sl_compat;
|
||||||
|
|
||||||
|
@ -237,9 +237,9 @@ uint8_t SlStationSpecList::last_num_specs;
|
||||||
class SlRoadStopSpecList : public DefaultSaveLoadHandler<SlRoadStopSpecList, BaseStation> {
|
class SlRoadStopSpecList : public DefaultSaveLoadHandler<SlRoadStopSpecList, BaseStation> {
|
||||||
public:
|
public:
|
||||||
inline static const SaveLoad description[] = {
|
inline static const SaveLoad description[] = {
|
||||||
SLE_VAR(RoadStopSpecList, grfid, SLE_UINT32),
|
SLE_VAR(SpecMapping<RoadStopSpec>, grfid, SLE_UINT32),
|
||||||
SLE_CONDVAR(RoadStopSpecList, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING),
|
SLE_CONDVAR(SpecMapping<RoadStopSpec>, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING),
|
||||||
SLE_CONDVAR(RoadStopSpecList, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
|
SLE_CONDVAR(SpecMapping<RoadStopSpec>, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
|
||||||
};
|
};
|
||||||
inline const static SaveLoadCompatTable compat_description = _station_road_stop_spec_list_sl_compat;
|
inline const static SaveLoadCompatTable compat_description = _station_road_stop_spec_list_sl_compat;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue