OpenTTD Source: src/saveload/station_sl.cpp Source File

OpenTTD Source 15.0-RC2

station_sl.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "../stdafx.h"
11
12#include "saveload.h"
13#include "compat/station_sl_compat.h"
14
15#include "../station_base.h"
16#include "../waypoint_base.h"
17#include "../roadstop_base.h"
18#include "../vehicle_base.h"
19#include "../newgrf_station.h"
20#include "../newgrf_roadstop.h"
21#include "../timer/timer_game_calendar.h"
22
23#include "table/strings.h"
24
25#include "../safeguards.h"
26
31 static void UpdateWaypointOrder(Order &o)
32{
33 if (!o.IsType(OT_GOTO_STATION)) return;
34
35 const Station *st = Station::Get(o.GetDestination().ToStationID());
36 if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) return;
37
38 o.MakeGoToWaypoint(o.GetDestination().ToStationID());
39}
40
45 void MoveBuoysToWaypoints()
46{
47 /* Buoy orders become waypoint orders */
48 for (OrderList *ol : OrderList::Iterate()) {
49 VehicleType vt = ol->GetFirstSharedVehicle()->type;
50 if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
51
52 for (Order &o : ol->GetOrders()) UpdateWaypointOrder(o);
53 }
54
55 for (Vehicle *v : Vehicle::Iterate()) {
56 VehicleType vt = v->type;
57 if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
58
59 UpdateWaypointOrder(v->current_order);
60 }
61
62 /* Now make the stations waypoints */
63 for (Station *st : Station::Iterate()) {
64 if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue;
65
66 StationID index = st->index;
67 TileIndex xy = st->xy;
68 Town *town = st->town;
69 StringID string_id = st->string_id;
70 std::string name = st->name;
71 TimerGameCalendar::Date build_date = st->build_date;
72 /* TTDPatch could use "buoys with rail station" for rail waypoints */
73 bool train = st->train_station.tile != INVALID_TILE;
74 TileArea train_st = st->train_station;
75
76 /* Delete the station, so we can make it a real waypoint. */
77 delete st;
78
79 /* Stations and waypoints are in the same pool, so if a station
80 * is deleted there must be place for a Waypoint. */
81 assert(Waypoint::CanAllocateItem());
82 Waypoint *wp = new (index) Waypoint(xy);
83 wp->town = town;
84 wp->string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
85 wp->name = std::move(name);
86 wp->delete_ctr = 0; // Just reset delete counter for once.
87 wp->build_date = build_date;
88 wp->owner = train ? GetTileOwner(xy) : OWNER_NONE;
89
90 if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;
91
92 if (train) {
93 /* When we make a rail waypoint of the station, convert the map as well. */
94 for (TileIndex t : train_st) {
95 Tile tile(t);
96 if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != index) continue;
97
98 SB(tile.m6(), 3, 3, to_underlying(StationType::RailWaypoint));
99 wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
100 }
101
102 wp->train_station = train_st;
103 wp->facilities.Set(StationFacility::Train);
104 } else if (IsBuoyTile(xy) && GetStationIndex(xy) == index) {
105 wp->rect.BeforeAddTile(xy, StationRect::ADD_FORCE);
106 wp->facilities.Set(StationFacility::Dock);
107 }
108 }
109}
110
111void AfterLoadStations()
112{
113 /* Update the speclists of all stations to point to the currently loaded custom stations. */
114 for (BaseStation *st : BaseStation::Iterate()) {
115 for (auto &sm : GetStationSpecList<StationSpec>(st)) {
116 if (sm.grfid == 0) continue;
117 sm.spec = StationClass::GetByGrf(sm.grfid, sm.localidx);
118 }
119 for (auto &sm : GetStationSpecList<RoadStopSpec>(st)) {
120 if (sm.grfid == 0) continue;
121 sm.spec = RoadStopClass::GetByGrf(sm.grfid, sm.localidx);
122 }
123
124 if (Station::IsExpected(st)) {
125 Station *sta = Station::From(st);
126 for (const RoadStop *rs = sta->bus_stops; rs != nullptr; rs = rs->next) sta->bus_station.Add(rs->xy);
127 for (const RoadStop *rs = sta->truck_stops; rs != nullptr; rs = rs->next) sta->truck_station.Add(rs->xy);
128 }
129
130 StationUpdateCachedTriggers(st);
131 RoadStopUpdateCachedTriggers(st);
132 }
133
134 /* Station blocked, wires and pylon flags need to be stored in the map. This is effectively cached data, so no
135 * version check is necessary. */
136 for (const auto t : Map::Iterate()) {
137 if (HasStationTileRail(t)) SetRailStationTileFlags(t, GetStationSpec(t));
138 }
139}
140
144 void AfterLoadRoadStops()
145{
146 /* First construct the drive through entries */
147 for (RoadStop *rs : RoadStop::Iterate()) {
148 if (IsDriveThroughStopTile(rs->xy)) rs->MakeDriveThrough();
149 }
150 /* And then rebuild the data in those entries */
151 for (RoadStop *rs : RoadStop::Iterate()) {
152 if (!rs->status.Test(RoadStop::RoadStopStatusFlag::BaseEntry)) continue;
153
154 rs->GetEntry(DIAGDIR_NE).Rebuild(rs);
155 rs->GetEntry(DIAGDIR_NW).Rebuild(rs);
156 }
157}
158
159static const SaveLoad _roadstop_desc[] = {
160 SLE_VAR(RoadStop, xy, SLE_UINT32),
161 SLE_VAR(RoadStop, status, SLE_UINT8),
162 SLE_REF(RoadStop, next, REF_ROADSTOPS),
163};
164
165static uint16_t _waiting_acceptance;
166static uint32_t _old_num_flows;
167static uint16_t _cargo_source;
168static uint32_t _cargo_source_xy;
169static uint8_t _cargo_periods;
170static Money _cargo_feeder_share;
171
172std::list<CargoPacket *> _packets;
173uint32_t _old_num_dests;
174
175 struct FlowSaveLoad {
176 StationID source;
177 StationID via;
178 uint32_t share;
179 bool restricted;
180};
181
182typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
183
184static OldPersistentStorage _old_st_persistent_storage;
185
191 static void SwapPackets(GoodsEntry *ge)
192{
193 StationCargoPacketMap &ge_packets = const_cast<StationCargoPacketMap &>(*ge->GetOrCreateData().cargo.Packets());
194
195 if (_packets.empty()) {
196 std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(StationID::Invalid()));
197 if (it == ge_packets.end()) {
198 return;
199 } else {
200 it->second.swap(_packets);
201 }
202 } else {
203 assert(ge_packets[StationID::Invalid()].empty());
204 ge_packets[StationID::Invalid()].swap(_packets);
205 }
206}
207
208template <typename T>
209 class SlStationSpecList : public VectorSaveLoadHandler<SlStationSpecList<T>, BaseStation, SpecMapping<T>> {
210public:
211 static inline const SaveLoad description[] = {
212 SLE_CONDVAR(SpecMapping<T>, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION),
213 SLE_CONDVAR(SpecMapping<T>, localidx, SLE_FILE_U8 | SLE_VAR_U16, SLV_27, SLV_EXTEND_ENTITY_MAPPING),
214 SLE_CONDVAR(SpecMapping<T>, localidx, SLE_UINT16, SLV_EXTEND_ENTITY_MAPPING, SL_MAX_VERSION),
215 };
216 static inline const SaveLoadCompatTable compat_description = _station_spec_list_sl_compat;
217
218 static inline uint8_t last_num_specs;
219
220 std::vector<SpecMapping<T>> &GetVector(BaseStation *bst) const override { return GetStationSpecList<T>(bst); }
221
222 size_t GetLength() const override
223 {
224 return IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? last_num_specs : SlGetStructListLength(UINT8_MAX);
225 }
226};
227
228/* Instantiate SlStationSpecList classes. */
229template class SlStationSpecList<StationSpec>;
230template class SlStationSpecList<RoadStopSpec>;
231
232 class SlStationCargo : public DefaultSaveLoadHandler<SlStationCargo, GoodsEntry> {
233public:
234 static inline const SaveLoad description[] = {
235 SLE_VAR(StationCargoPair, first, SLE_UINT16),
236 SLE_REFLIST(StationCargoPair, second, REF_CARGO_PACKET),
237 };
238 static inline const SaveLoadCompatTable compat_description = _station_cargo_sl_compat;
239
240 void Save(GoodsEntry *ge) const override
241 {
242 if (!ge->HasData()) {
243 SlSetStructListLength(0);
244 return;
245 }
246
247 const auto *packets = ge->GetData().cargo.Packets();
248 SlSetStructListLength(packets->MapSize());
249 for (StationCargoPacketMap::ConstMapIterator it(packets->begin()); it != packets->end(); ++it) {
250 SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), this->GetDescription());
251 }
252 }
253
254 void Load(GoodsEntry *ge) const override
255 {
256 size_t num_dests = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? _old_num_dests : SlGetStructListLength(UINT32_MAX);
257 if (num_dests == 0) return;
258
259 GoodsEntry::GoodsEntryData &data = ge->GetOrCreateData();
260 StationCargoPair pair;
261 for (uint j = 0; j < num_dests; ++j) {
262 SlObject(&pair, this->GetLoadDescription());
263 const_cast<StationCargoPacketMap &>(*(data.cargo.Packets()))[pair.first].swap(pair.second);
264 assert(pair.second.empty());
265 }
266 }
267
268 void FixPointers(GoodsEntry *ge) const override
269 {
270 if (!ge->HasData()) return;
271
272 for (StationCargoPacketMap::ConstMapIterator it = ge->GetData().cargo.Packets()->begin(); it != ge->GetData().cargo.Packets()->end(); ++it) {
273 SlObject(const_cast<StationCargoPair *>(&(*it)), this->GetDescription());
274 }
275 }
276};
277
278 class SlStationFlow : public DefaultSaveLoadHandler<SlStationFlow, GoodsEntry> {
279public:
280 static inline const SaveLoad description[] = {
281 SLE_VAR(FlowSaveLoad, source, SLE_UINT16),
282 SLE_VAR(FlowSaveLoad, via, SLE_UINT16),
283 SLE_VAR(FlowSaveLoad, share, SLE_UINT32),
284 SLE_CONDVAR(FlowSaveLoad, restricted, SLE_BOOL, SLV_187, SL_MAX_VERSION),
285 };
286 static inline const SaveLoadCompatTable compat_description = _station_flow_sl_compat;
287
288 void Save(GoodsEntry *ge) const override
289 {
290 if (!ge->HasData()) {
291 SlSetStructListLength(0);
292 return;
293 }
294
295 size_t num_flows = 0;
296 for (const auto &it : ge->GetData().flows) {
297 num_flows += it.second.GetShares()->size();
298 }
299 SlSetStructListLength(num_flows);
300
301 for (const auto &outer_it : ge->GetData().flows) {
302 const FlowStat::SharesMap *shares = outer_it.second.GetShares();
303 uint32_t sum_shares = 0;
304 FlowSaveLoad flow{};
305 flow.source = outer_it.first;
306 for (auto &inner_it : *shares) {
307 flow.via = inner_it.second;
308 flow.share = inner_it.first - sum_shares;
309 flow.restricted = inner_it.first > outer_it.second.GetUnrestricted();
310 sum_shares = inner_it.first;
311 assert(flow.share > 0);
312 SlObject(&flow, this->GetDescription());
313 }
314 }
315 }
316
317 void Load(GoodsEntry *ge) const override
318 {
319 size_t num_flows = IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH) ? _old_num_flows : SlGetStructListLength(UINT32_MAX);
320 if (num_flows == 0) return;
321
322 GoodsEntry::GoodsEntryData &data = ge->GetOrCreateData();
323 FlowSaveLoad flow{};
324 FlowStat *fs = nullptr;
325 StationID prev_source = StationID::Invalid();
326 for (uint32_t j = 0; j < num_flows; ++j) {
327 SlObject(&flow, this->GetLoadDescription());
328 if (fs == nullptr || prev_source != flow.source) {
329 fs = &(data.flows.emplace(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second;
330 } else {
331 fs->AppendShare(flow.via, flow.share, flow.restricted);
332 }
333 prev_source = flow.source;
334 }
335 }
336};
337
338 class SlStationGoods : public DefaultSaveLoadHandler<SlStationGoods, BaseStation> {
339public:
340 static inline uint cargo_reserved_count;
341
342 static inline const SaveLoad description[] = {
343 SLEG_CONDVAR("waiting_acceptance", _waiting_acceptance, SLE_UINT16, SL_MIN_VERSION, SLV_68),
344 SLE_CONDVAR(GoodsEntry, status, SLE_UINT8, SLV_68, SL_MAX_VERSION),
345 SLE_VAR(GoodsEntry, time_since_pickup, SLE_UINT8),
346 SLE_VAR(GoodsEntry, rating, SLE_UINT8),
347 SLEG_CONDVAR("cargo_source", _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
348 SLEG_CONDVAR("cargo_source", _cargo_source, SLE_UINT16, SLV_7, SLV_68),
349 SLEG_CONDVAR("cargo_source_xy", _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
350 SLEG_CONDVAR("cargo_days", _cargo_periods, SLE_UINT8, SL_MIN_VERSION, SLV_68),
351 SLE_VAR(GoodsEntry, last_speed, SLE_UINT8),
352 SLE_VAR(GoodsEntry, last_age, SLE_UINT8),
353 SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, SLV_14, SLV_65),
354 SLEG_CONDVAR("cargo_feeder_share", _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
355 SLE_CONDVAR(GoodsEntry, amount_fract, SLE_UINT8, SLV_150, SL_MAX_VERSION),
356 SLEG_CONDREFLIST("packets", _packets, REF_CARGO_PACKET, SLV_68, SLV_183),
357 SLEG_CONDVAR("old_num_dests", _old_num_dests, SLE_UINT32, SLV_183, SLV_SAVELOAD_LIST_LENGTH),
358 SLEG_CONDVAR("cargo.reserved_count", SlStationGoods::cargo_reserved_count, SLE_UINT, SLV_181, SL_MAX_VERSION),
359 SLE_CONDVAR(GoodsEntry, link_graph, SLE_UINT16, SLV_183, SL_MAX_VERSION),
360 SLE_CONDVAR(GoodsEntry, node, SLE_UINT16, SLV_183, SL_MAX_VERSION),
361 SLEG_CONDVAR("old_num_flows", _old_num_flows, SLE_UINT32, SLV_183, SLV_SAVELOAD_LIST_LENGTH),
362 SLE_CONDVAR(GoodsEntry, max_waiting_cargo, SLE_UINT32, SLV_183, SL_MAX_VERSION),
363 SLEG_CONDSTRUCTLIST("flow", SlStationFlow, SLV_183, SL_MAX_VERSION),
364 SLEG_CONDSTRUCTLIST("cargo", SlStationCargo, SLV_183, SL_MAX_VERSION),
365 };
366
367 static inline const SaveLoadCompatTable compat_description = _station_goods_sl_compat;
368
373 size_t GetNumCargo() const
374 {
375 if (IsSavegameVersionBefore(SLV_55)) return 12;
376 if (IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES)) return 32;
377 if (IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) return NUM_CARGO;
378 /* Read from the savegame how long the list is. */
379 return SlGetStructListLength(NUM_CARGO);
380 }
381
382 void Save(BaseStation *bst) const override
383 {
384 Station *st = Station::From(bst);
385
386 SlSetStructListLength(NUM_CARGO);
387
388 for (GoodsEntry &ge : st->goods) {
389 SlStationGoods::cargo_reserved_count = ge.HasData() ? ge.GetData().cargo.reserved_count : 0;
390 SlObject(&ge, this->GetDescription());
391 }
392 }
393
394 void Load(BaseStation *bst) const override
395 {
396 Station *st = Station::From(bst);
397
398 /* Before savegame version 161, persistent storages were not stored in a pool. */
399 if (IsSavegameVersionBefore(SLV_161) && !IsSavegameVersionBefore(SLV_145) && st->facilities.Test(StationFacility::Airport)) {
400 /* Store the old persistent storage. The GRFID will be added later. */
401 assert(PersistentStorage::CanAllocateItem());
402 st->airport.psa = new PersistentStorage(0, GSF_INVALID, TileIndex{});
403 std::copy(std::begin(_old_st_persistent_storage.storage), std::end(_old_st_persistent_storage.storage), std::begin(st->airport.psa->storage));
404 }
405
406 auto end = std::next(std::begin(st->goods), std::min(this->GetNumCargo(), std::size(st->goods)));
407 for (auto it = std::begin(st->goods); it != end; ++it) {
408 GoodsEntry &ge = *it;
409 SlObject(&ge, this->GetLoadDescription());
410 if (!IsSavegameVersionBefore(SLV_181) && SlStationGoods::cargo_reserved_count != 0) {
411 ge.GetOrCreateData().cargo.reserved_count = SlStationGoods::cargo_reserved_count;
412 }
413 if (IsSavegameVersionBefore(SLV_183)) {
414 SwapPackets(&ge);
415 }
416 if (IsSavegameVersionBefore(SLV_68)) {
417 ge.status.Set(GoodsEntry::State::Acceptance, HasBit(_waiting_acceptance, 15));
418 if (GB(_waiting_acceptance, 0, 12) != 0) {
419 /* In old versions, enroute_from used 0xFF as StationID::Invalid() */
420 StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? StationID::Invalid() : static_cast<StationID>(_cargo_source);
421
422 /* Make sure we can allocate the CargoPacket. This is safe
423 * as there can only be ~64k stations and 32 cargoes in these
424 * savegame versions. As the CargoPacketPool has more than
425 * 16 million entries; it fits by an order of magnitude. */
426 assert(CargoPacket::CanAllocateItem());
427
428 /* Don't construct the packet with station here, because that'll fail with old savegames */
429 CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_periods, source, TileIndex{_cargo_source_xy}, _cargo_feeder_share);
430 ge.GetOrCreateData().cargo.Append(cp, StationID::Invalid());
431 ge.status.Set(GoodsEntry::State::Rating);
432 }
433 }
434 }
435 }
436
437 void FixPointers(BaseStation *bst) const override
438 {
439 Station *st = Station::From(bst);
440
441 size_t num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
442 auto end = std::next(std::begin(st->goods), std::min(num_cargo, std::size(st->goods)));
443 for (auto it = std::begin(st->goods); it != end; ++it) {
444 GoodsEntry &ge = *it;
445 if (IsSavegameVersionBefore(SLV_183)) {
446 SwapPackets(&ge); // We have to swap back again to be in the format pre-183 expects.
447 SlObject(&ge, this->GetDescription());
448 SwapPackets(&ge);
449 } else {
450 SlObject(&ge, this->GetDescription());
451 }
452 }
453 }
454};
455
456static const SaveLoad _old_station_desc[] = {
457 SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
458 SLE_CONDVAR(Station, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION),
459 SLE_CONDVAR(Station, train_station.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
460 SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
461 SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
462 SLE_CONDVAR(Station, airport.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
463 SLE_REF(Station, town, REF_TOWN),
464 SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
465 SLE_CONDVAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SL_MAX_VERSION),
466
467 SLE_VAR(Station, string_id, SLE_STRINGID),
468 SLE_CONDSSTR(Station, name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
469 SLE_CONDVAR(Station, indtype, SLE_UINT8, SLV_103, SL_MAX_VERSION),
470 SLE_CONDVAR(Station, had_vehicle_of_type, SLE_FILE_U16 | SLE_VAR_U8, SL_MIN_VERSION, SLV_122),
471 SLE_CONDVAR(Station, had_vehicle_of_type, SLE_UINT8, SLV_122, SL_MAX_VERSION),
472
473 SLE_VAR(Station, time_since_load, SLE_UINT8),
474 SLE_VAR(Station, time_since_unload, SLE_UINT8),
475 SLE_VAR(Station, delete_ctr, SLE_UINT8),
476 SLE_VAR(Station, owner, SLE_UINT8),
477 SLE_VAR(Station, facilities, SLE_UINT8),
478 SLE_VAR(Station, airport.type, SLE_UINT8),
479 SLE_CONDVARNAME(Station, airport.blocks, "airport.flags", SLE_VAR_U64 | SLE_FILE_U16, SL_MIN_VERSION, SLV_3),
480 SLE_CONDVARNAME(Station, airport.blocks, "airport.flags", SLE_VAR_U64 | SLE_FILE_U32, SLV_3, SLV_46),
481 SLE_CONDVARNAME(Station, airport.blocks, "airport.flags", SLE_UINT64, SLV_46, SL_MAX_VERSION),
482
483 SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, SLV_26, SL_MAX_VERSION),
484
485 SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, SLV_3, SLV_31),
486 SLE_CONDVAR(Station, build_date, SLE_INT32, SLV_31, SL_MAX_VERSION),
487
488 SLE_CONDREF(Station, bus_stops, REF_ROADSTOPS, SLV_6, SL_MAX_VERSION),
489 SLE_CONDREF(Station, truck_stops, REF_ROADSTOPS, SLV_6, SL_MAX_VERSION),
490
491 /* Used by newstations for graphic variations */
492 SLE_CONDVAR(Station, random_bits, SLE_UINT16, SLV_27, SL_MAX_VERSION),
493 SLE_CONDVARNAME(Station, waiting_random_triggers, "waiting_triggers", SLE_UINT8, SLV_27, SL_MAX_VERSION),
494 SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SLV_27, SL_MAX_VERSION),
495
496 SLE_CONDREFLIST(Station, loading_vehicles, REF_VEHICLE, SLV_57, SL_MAX_VERSION),
497
498 SLEG_STRUCTLIST("goods", SlStationGoods),
499 SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList<StationSpec>, SLV_27, SL_MAX_VERSION),
500};
501
502 struct STNSChunkHandler : ChunkHandler {
503 STNSChunkHandler() : ChunkHandler('STNS', CH_READONLY) {}
504
505 void Load() const override
506 {
507 const std::vector<SaveLoad> slt = SlCompatTableHeader(_old_station_desc, _old_station_sl_compat);
508
509 _cargo_source_xy = 0;
510 _cargo_periods = 0;
511 _cargo_feeder_share = 0;
512
513 int index;
514 while ((index = SlIterateArray()) != -1) {
515 Station *st = new (StationID(index)) Station();
516
517 _waiting_acceptance = 0;
518 SlObject(st, slt);
519 }
520 }
521
522 void FixPointers() const override
523 {
524 /* From SLV_123 we store stations in STNN; before that in STNS. So do not
525 * fix pointers when the version is SLV_123 or up, as that would fix
526 * pointers twice: once in STNN chunk and once here. */
527 if (!IsSavegameVersionBefore(SLV_123)) return;
528
529 for (Station *st : Station::Iterate()) {
530 SlObject(st, _old_station_desc);
531 }
532 }
533};
534
535 class SlRoadStopTileData : public VectorSaveLoadHandler<SlRoadStopTileData, BaseStation, RoadStopTileData> {
536public:
537 static inline const SaveLoad description[] = {
538 SLE_VAR(RoadStopTileData, tile, SLE_UINT32),
539 SLE_VAR(RoadStopTileData, random_bits, SLE_UINT8),
540 SLE_VAR(RoadStopTileData, animation_frame, SLE_UINT8),
541 };
542 static inline const SaveLoadCompatTable compat_description = {};
543
544 std::vector<RoadStopTileData> &GetVector(BaseStation *bst) const override { return bst->custom_roadstop_tile_data; }
545};
546
551 class SlStationBase : public DefaultSaveLoadHandler<SlStationBase, BaseStation> {
552public:
553 static inline const SaveLoad description[] = {
554 SLE_VAR(BaseStation, xy, SLE_UINT32),
555 SLE_REF(BaseStation, town, REF_TOWN),
556 SLE_VAR(BaseStation, string_id, SLE_STRINGID),
557 SLE_SSTR(BaseStation, name, SLE_STR | SLF_ALLOW_CONTROL),
558 SLE_VAR(BaseStation, delete_ctr, SLE_UINT8),
559 SLE_VAR(BaseStation, owner, SLE_UINT8),
560 SLE_VAR(BaseStation, facilities, SLE_UINT8),
561 SLE_VAR(BaseStation, build_date, SLE_INT32),
562
563 /* Used by newstations for graphic variations */
564 SLE_VAR(BaseStation, random_bits, SLE_UINT16),
565 SLE_VARNAME(BaseStation, waiting_random_triggers, "waiting_triggers", SLE_UINT8),
566 SLEG_CONDVAR("num_specs", SlStationSpecList<StationSpec>::last_num_specs, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
567 };
568 static inline const SaveLoadCompatTable compat_description = _station_base_sl_compat;
569
570 void Save(BaseStation *bst) const override
571 {
572 SlObject(bst, this->GetDescription());
573 }
574
575 void Load(BaseStation *bst) const override
576 {
577 SlObject(bst, this->GetLoadDescription());
578 }
579
580 void FixPointers(BaseStation *bst) const override
581 {
582 SlObject(bst, this->GetDescription());
583 }
584};
585
589 class SlStationNormal : public DefaultSaveLoadHandler<SlStationNormal, BaseStation> {
590public:
591 static inline const SaveLoad description[] = {
592 SLEG_STRUCT("base", SlStationBase),
593 SLE_VAR(Station, train_station.tile, SLE_UINT32),
594 SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
595 SLE_VAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16),
596
597 SLE_REF(Station, bus_stops, REF_ROADSTOPS),
598 SLE_REF(Station, truck_stops, REF_ROADSTOPS),
599 SLE_CONDVAR(Station, ship_station.tile, SLE_UINT32, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
600 SLE_CONDVAR(Station, ship_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
601 SLE_CONDVAR(Station, ship_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
602 SLE_CONDVAR(Station, docking_station.tile, SLE_UINT32, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
603 SLE_CONDVAR(Station, docking_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
604 SLE_CONDVAR(Station, docking_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
605 SLE_VAR(Station, airport.tile, SLE_UINT32),
606 SLE_CONDVAR(Station, airport.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
607 SLE_CONDVAR(Station, airport.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
608 SLE_VAR(Station, airport.type, SLE_UINT8),
609 SLE_CONDVAR(Station, airport.layout, SLE_UINT8, SLV_145, SL_MAX_VERSION),
610 SLE_VARNAME(Station, airport.blocks, "airport.flags", SLE_UINT64),
611 SLE_CONDVAR(Station, airport.rotation, SLE_UINT8, SLV_145, SL_MAX_VERSION),
612 SLEG_CONDARR("storage", _old_st_persistent_storage.storage, SLE_UINT32, 16, SLV_145, SLV_161),
613 SLE_CONDREF(Station, airport.psa, REF_STORAGE, SLV_161, SL_MAX_VERSION),
614
615 SLE_VAR(Station, indtype, SLE_UINT8),
616
617 SLE_VAR(Station, time_since_load, SLE_UINT8),
618 SLE_VAR(Station, time_since_unload, SLE_UINT8),
619 SLE_VAR(Station, last_vehicle_type, SLE_UINT8),
620 SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8),
621 SLE_REFLIST(Station, loading_vehicles, REF_VEHICLE),
622 SLE_CONDVAR(Station, always_accepted, SLE_FILE_U32 | SLE_VAR_U64, SLV_127, SLV_EXTEND_CARGOTYPES),
623 SLE_CONDVAR(Station, always_accepted, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
624 SLEG_CONDSTRUCTLIST("speclist", SlRoadStopTileData, SLV_NEWGRF_ROAD_STOPS, SLV_ROAD_STOP_TILE_DATA),
625 SLEG_STRUCTLIST("goods", SlStationGoods),
626 };
627 static inline const SaveLoadCompatTable compat_description = _station_normal_sl_compat;
628
629 void Save(BaseStation *bst) const override
630 {
631 if (bst->facilities.Test(StationFacility::Waypoint)) return;
632 SlObject(bst, this->GetDescription());
633 }
634
635 void Load(BaseStation *bst) const override
636 {
637 if (bst->facilities.Test(StationFacility::Waypoint)) return;
638 SlObject(bst, this->GetLoadDescription());
639 }
640
641 void FixPointers(BaseStation *bst) const override
642 {
643 if (bst->facilities.Test(StationFacility::Waypoint)) return;
644 SlObject(bst, this->GetDescription());
645 }
646};
647
648 class SlStationWaypoint : public DefaultSaveLoadHandler<SlStationWaypoint, BaseStation> {
649public:
650 static inline const SaveLoad description[] = {
651 SLEG_STRUCT("base", SlStationBase),
652 SLE_VAR(Waypoint, town_cn, SLE_UINT16),
653
654 SLE_CONDVAR(Waypoint, train_station.tile, SLE_UINT32, SLV_124, SL_MAX_VERSION),
655 SLE_CONDVAR(Waypoint, train_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION),
656 SLE_CONDVAR(Waypoint, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION),
657 SLE_CONDVAR(Waypoint, waypoint_flags, SLE_UINT16, SLV_ROAD_WAYPOINTS, SL_MAX_VERSION),
658 SLE_CONDVAR(Waypoint, road_waypoint_area.tile, SLE_UINT32, SLV_ROAD_WAYPOINTS, SL_MAX_VERSION),
659 SLE_CONDVAR(Waypoint, road_waypoint_area.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_ROAD_WAYPOINTS, SL_MAX_VERSION),
660 SLE_CONDVAR(Waypoint, road_waypoint_area.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_ROAD_WAYPOINTS, SL_MAX_VERSION),
661 };
662 static inline const SaveLoadCompatTable compat_description = _station_waypoint_sl_compat;
663
664 void Save(BaseStation *bst) const override
665 {
666 if (!bst->facilities.Test(StationFacility::Waypoint)) return;
667 SlObject(bst, this->GetDescription());
668 }
669
670 void Load(BaseStation *bst) const override
671 {
672 if (!bst->facilities.Test(StationFacility::Waypoint)) return;
673 SlObject(bst, this->GetLoadDescription());
674 }
675
676 void FixPointers(BaseStation *bst) const override
677 {
678 if (!bst->facilities.Test(StationFacility::Waypoint)) return;
679 SlObject(bst, this->GetDescription());
680 }
681};
682
683static const SaveLoad _station_desc[] = {
684 SLE_SAVEBYTE(BaseStation, facilities),
685 SLEG_STRUCT("normal", SlStationNormal),
686 SLEG_STRUCT("waypoint", SlStationWaypoint),
687 SLEG_CONDSTRUCTLIST("speclist", SlStationSpecList<StationSpec>, SLV_27, SL_MAX_VERSION),
688 SLEG_CONDSTRUCTLIST("roadstopspeclist", SlStationSpecList<RoadStopSpec>, SLV_NEWGRF_ROAD_STOPS, SL_MAX_VERSION),
689 SLEG_CONDSTRUCTLIST("roadstoptiledata", SlRoadStopTileData, SLV_ROAD_STOP_TILE_DATA, SL_MAX_VERSION),
690};
691
692 struct STNNChunkHandler : ChunkHandler {
693 STNNChunkHandler() : ChunkHandler('STNN', CH_TABLE) {}
694
695 void Save() const override
696 {
697 SlTableHeader(_station_desc);
698
699 /* Write the stations */
700 for (BaseStation *st : BaseStation::Iterate()) {
701 SlSetArrayIndex(st->index);
702 SlObject(st, _station_desc);
703 }
704 }
705
706
707 void Load() const override
708 {
709 const std::vector<SaveLoad> slt = SlCompatTableHeader(_station_desc, _station_sl_compat);
710
711 _old_num_flows = 0;
712
713 int index;
714 while ((index = SlIterateArray()) != -1) {
715 bool waypoint = static_cast<StationFacilities>(SlReadByte()).Test(StationFacility::Waypoint);
716
717 BaseStation *bst = waypoint ? (BaseStation *)new (StationID(index)) Waypoint() : new (StationID(index)) Station();
718 SlObject(bst, slt);
719 }
720 }
721
722 void FixPointers() const override
723 {
724 /* From SLV_123 we store stations in STNN; before that in STNS. So do not
725 * fix pointers when the version is below SLV_123, as that would fix
726 * pointers twice: once in STNS chunk and once here. */
727 if (IsSavegameVersionBefore(SLV_123)) return;
728
729 for (BaseStation *bst : BaseStation::Iterate()) {
730 SlObject(bst, _station_desc);
731 }
732 }
733};
734
735 struct ROADChunkHandler : ChunkHandler {
736 ROADChunkHandler() : ChunkHandler('ROAD', CH_TABLE) {}
737
738 void Save() const override
739 {
740 SlTableHeader(_roadstop_desc);
741
742 for (RoadStop *rs : RoadStop::Iterate()) {
743 SlSetArrayIndex(rs->index);
744 SlObject(rs, _roadstop_desc);
745 }
746 }
747
748 void Load() const override
749 {
750 const std::vector<SaveLoad> slt = SlCompatTableHeader(_roadstop_desc, _roadstop_sl_compat);
751
752 int index;
753
754 while ((index = SlIterateArray()) != -1) {
755 RoadStop *rs = new (RoadStopID(index)) RoadStop(INVALID_TILE);
756
757 SlObject(rs, slt);
758 }
759 }
760
761 void FixPointers() const override
762 {
763 for (RoadStop *rs : RoadStop::Iterate()) {
764 SlObject(rs, _roadstop_desc);
765 }
766 }
767};
768
769static const STNSChunkHandler STNS;
770static const STNNChunkHandler STNN;
771static const ROADChunkHandler ROAD;
772static const ChunkHandlerRef station_chunk_handlers[] = {
773 STNS,
774 STNN,
775 ROAD,
776};
777
778extern const ChunkHandlerTable _station_chunk_handlers(station_chunk_handlers);
GetStationSpecList
std::vector< SpecMapping< T > > & GetStationSpecList(BaseStation *bst)
Get spec mapping list for each supported custom spec type.
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
NUM_CARGO
static const CargoType NUM_CARGO
Maximum number of cargo types in a game.
Definition cargo_type.h:73
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
CargoList::Packets
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition cargopacket.h:320
DefaultSaveLoadHandler
Default handler for saving/loading an object to/from disk.
Definition saveload.h:596
DefaultSaveLoadHandler< SlStationGoods, BaseStation >::GetDescription
SaveLoadTable GetDescription() const override
Definition saveload.h:598
EnumBitSet< StationFacility, uint8_t >
FlowStat
Flow statistics telling how much flow should be sent along a link.
Definition station_base.h:33
FlowStat::AppendShare
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
Definition station_base.h:67
MultiMap
Hand-rolled multimap as map of lists.
Definition multimap.hpp:225
NewGRFClass::GetByGrf
static const Tspec * GetByGrf(uint32_t grfid, uint16_t local_id)
Retrieve a spec by GRF location.
Definition newgrf_class_func.h:128
OverflowSafeInt< int64_t >
SaveLoadHandler::GetLoadDescription
SaveLoadTable GetLoadDescription() const
Get the description for how to load the chunk.
Definition saveload.cpp:3444
SlRoadStopTileData
Definition station_sl.cpp:535
SlRoadStopTileData::GetVector
std::vector< RoadStopTileData > & GetVector(BaseStation *bst) const override
Get instance of vector to load/save.
Definition station_sl.cpp:544
SlStationBase
SaveLoad handler for the BaseStation, which all other stations / waypoints make use of.
Definition station_sl.cpp:551
SlStationCargo
Definition station_sl.cpp:232
SlStationFlow
Definition station_sl.cpp:278
SlStationGoods
Definition station_sl.cpp:338
SlStationGoods::GetNumCargo
size_t GetNumCargo() const
Get the number of cargoes used by this savegame version.
Definition station_sl.cpp:373
SlStationNormal
SaveLoad handler for a normal station (read: not a waypoint).
Definition station_sl.cpp:589
SlStationSpecList
Definition station_sl.cpp:209
SlStationSpecList::GetLength
size_t GetLength() const override
Get number of elements to load into vector.
Definition station_sl.cpp:222
SlStationSpecList::last_num_specs
static uint8_t last_num_specs
Number of specs of the last loaded station.
Definition station_sl.cpp:218
SlStationSpecList::GetVector
std::vector< SpecMapping< T > > & GetVector(BaseStation *bst) const override
Get instance of vector to load/save.
Definition station_sl.cpp:220
SlStationWaypoint
Definition station_sl.cpp:648
StationCargoList::Append
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Definition cargopacket.cpp:684
StationCargoList::reserved_count
uint reserved_count
Amount of cargo being reserved for loading.
Definition cargopacket.h:524
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
Tile::m6
uint8_t & m6()
General purpose.
Definition map_func.h:173
VectorSaveLoadHandler
Default handler for saving/loading a vector to/from disk.
Definition saveload.h:1382
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
IsInsideBS
constexpr bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition math_func.hpp:252
GSF_INVALID
@ GSF_INVALID
An invalid spec feature.
Definition newgrf.h:99
StationUpdateCachedTriggers
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
Definition newgrf_station.cpp:1026
SlCompatTableHeader
std::vector< SaveLoad > SlCompatTableHeader(const SaveLoadTable &slt, const SaveLoadCompatTable &slct)
Load a table header in a savegame compatible way.
Definition saveload.cpp:2037
SlGetStructListLength
size_t SlGetStructListLength(size_t limit)
Get the length of this list; if it exceeds the limit, error out.
Definition saveload.cpp:1833
SlIterateArray
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition saveload.cpp:677
SlReadByte
uint8_t SlReadByte()
Wrapper for reading a byte from the buffer.
Definition saveload.cpp:410
SlObject
void SlObject(void *object, const SaveLoadTable &slt)
Main SaveLoad function.
Definition saveload.cpp:1846
SlTableHeader
std::vector< SaveLoad > SlTableHeader(const SaveLoadTable &slt)
Save or Load a table header.
Definition saveload.cpp:1899
SlSetStructListLength
void SlSetStructListLength(size_t length)
Set the length of this list.
Definition saveload.cpp:1817
saveload.h
Functions/types related to saving and loading games.
SLEG_CONDARR
#define SLEG_CONDARR(name, variable, type, length, from, to)
Storage of a global fixed-size array of SL_VAR elements in some savegame versions.
Definition saveload.h:1145
SLEG_STRUCTLIST
#define SLEG_STRUCTLIST(name, handler)
Storage of a list of structs in every savegame version.
Definition saveload.h:1256
SLEG_CONDVAR
#define SLEG_CONDVAR(name, variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition saveload.h:1124
SLF_ALLOW_CONTROL
@ SLF_ALLOW_CONTROL
Allow control codes in the strings.
Definition saveload.h:702
SLE_VARNAME
#define SLE_VARNAME(base, variable, name, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1026
ChunkHandlerRef
std::reference_wrapper< const ChunkHandler > ChunkHandlerRef
A reference to ChunkHandler.
Definition saveload.h:524
REF_TOWN
@ REF_TOWN
Load/save a reference to a town.
Definition saveload.h:618
REF_CARGO_PACKET
@ REF_CARGO_PACKET
Load/save a reference to a cargo packet.
Definition saveload.h:622
REF_STORAGE
@ REF_STORAGE
Load/save a reference to a persistent storage.
Definition saveload.h:624
REF_VEHICLE
@ REF_VEHICLE
Load/save a reference to a vehicle.
Definition saveload.h:616
REF_ROADSTOPS
@ REF_ROADSTOPS
Load/save a reference to a bus/truck stop.
Definition saveload.h:620
SLEG_CONDREFLIST
#define SLEG_CONDREFLIST(name, variable, type, from, to)
Storage of a global reference list in some savegame versions.
Definition saveload.h:1174
ChunkHandlerTable
std::span< const ChunkHandlerRef > ChunkHandlerTable
A table of ChunkHandler entries.
Definition saveload.h:527
SLE_SAVEBYTE
#define SLE_SAVEBYTE(base, variable)
Only write byte during saving; never read it during loading.
Definition saveload.h:1098
SLE_REF
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition saveload.h:1034
SLE_CONDREFLIST
#define SLE_CONDREFLIST(base, variable, type, from, to)
Storage of a list of SL_REF elements in some savegame versions.
Definition saveload.h:969
SLE_REFLIST
#define SLE_REFLIST(base, variable, type)
Storage of a list of SL_REF elements in every savegame version.
Definition saveload.h:1078
SaveLoadCompatTable
std::span< const struct SaveLoadCompat > SaveLoadCompatTable
A table of SaveLoadCompat entries.
Definition saveload.h:533
SLEG_STRUCT
#define SLEG_STRUCT(name, handler)
Storage of a structs in every savegame version.
Definition saveload.h:1233
SLE_CONDSSTR
#define SLE_CONDSSTR(base, variable, type, from, to)
Storage of a std::string in some savegame versions.
Definition saveload.h:948
SLE_CONDVAR
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:883
IsSavegameVersionBefore
bool IsSavegameVersionBefore(SaveLoadVersion major, uint8_t minor=0)
Checks whether the savegame is below major.
Definition saveload.h:1278
SLE_SSTR
#define SLE_SSTR(base, variable, type)
Storage of a std::string in every savegame version.
Definition saveload.h:1061
SLV_150
@ SLV_150
150 20857
Definition saveload.h:223
SLV_84
@ SLV_84
84 11822
Definition saveload.h:143
SLV_26
@ SLV_26
26 4466
Definition saveload.h:74
SLV_ROAD_WAYPOINTS
@ SLV_ROAD_WAYPOINTS
338 PR#12572 Road waypoints
Definition saveload.h:385
SLV_103
@ SLV_103
103 14598
Definition saveload.h:166
SLV_44
@ SLV_44
44 8144
Definition saveload.h:95
SLV_6
@ SLV_6
6.0 1721 6.1 1768
Definition saveload.h:46
SLV_181
@ SLV_181
181 25012
Definition saveload.h:260
SLV_EXTEND_CARGOTYPES
@ SLV_EXTEND_CARGOTYPES
199 PR#6802 Extend cargotypes to 64
Definition saveload.h:282
SLV_SAVELOAD_LIST_LENGTH
@ SLV_SAVELOAD_LIST_LENGTH
293 PR#9374 Consistency in list length with SL_STRUCT / SL_STRUCTLIST / SL_DEQUE / SL_REFLIST.
Definition saveload.h:331
SLV_65
@ SLV_65
65 10210
Definition saveload.h:121
SLV_123
@ SLV_123
123 16909
Definition saveload.h:190
SLV_46
@ SLV_46
46 8705
Definition saveload.h:98
SLV_122
@ SLV_122
122 16855
Definition saveload.h:189
SLV_140
@ SLV_140
140 19382
Definition saveload.h:211
SLV_MULTITILE_DOCKS
@ SLV_MULTITILE_DOCKS
216 PR#7380 Multiple docks per station.
Definition saveload.h:303
SL_MAX_VERSION
@ SL_MAX_VERSION
Highest possible saveload version.
Definition saveload.h:416
SL_MIN_VERSION
@ SL_MIN_VERSION
First savegame version.
Definition saveload.h:31
SLV_3
@ SLV_3
3.x lost
Definition saveload.h:36
SLV_145
@ SLV_145
145 20376
Definition saveload.h:217
SLV_57
@ SLV_57
57 9691
Definition saveload.h:111
SLV_68
@ SLV_68
68 10266
Definition saveload.h:124
SLV_NEWGRF_ROAD_STOPS
@ SLV_NEWGRF_ROAD_STOPS
303 PR#10144 NewGRF road stops.
Definition saveload.h:343
SLV_2
@ SLV_2
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition saveload.h:34
SLV_187
@ SLV_187
187 25899 Linkgraph - restricted flows
Definition saveload.h:267
SLV_27
@ SLV_27
27 4757
Definition saveload.h:75
SLV_127
@ SLV_127
127 17439
Definition saveload.h:195
SLV_14
@ SLV_14
14.0 2441
Definition saveload.h:57
SLV_55
@ SLV_55
55 9638
Definition saveload.h:109
SLV_161
@ SLV_161
161 22567
Definition saveload.h:236
SLV_7
@ SLV_7
7.0 1770
Definition saveload.h:48
SLV_124
@ SLV_124
124 16993
Definition saveload.h:191
SLV_183
@ SLV_183
183 25363 Cargodist
Definition saveload.h:262
SLV_31
@ SLV_31
31 5999
Definition saveload.h:80
SLV_EXTEND_ENTITY_MAPPING
@ SLV_EXTEND_ENTITY_MAPPING
311 PR#10672 Extend entity mapping range.
Definition saveload.h:353
SLV_ROAD_STOP_TILE_DATA
@ SLV_ROAD_STOP_TILE_DATA
340 PR#12883 Move storage of road stop tile data, also save for road waypoints.
Definition saveload.h:388
SLE_CONDREF
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition saveload.h:904
SLEG_CONDSTRUCTLIST
#define SLEG_CONDSTRUCTLIST(name, handler, from, to)
Storage of a list of structs in some savegame versions.
Definition saveload.h:1193
CH_READONLY
@ CH_READONLY
Chunk is never saved.
Definition saveload.h:474
SLE_VAR
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition saveload.h:1017
SLE_CONDVARNAME
#define SLE_CONDVARNAME(base, variable, name, type, from, to)
Storage of a variable in some savegame versions.
Definition saveload.h:894
SetRailStationTileFlags
void SetRailStationTileFlags(TileIndex tile, const StationSpec *statspec)
Set rail station tile flags for the given tile.
Definition station_cmd.cpp:1402
IsDriveThroughStopTile
bool IsDriveThroughStopTile(Tile t)
Is tile t a drive through road stop station or waypoint?
Definition station_map.h:276
GetStationIndex
StationID GetStationIndex(Tile t)
Get StationID from a tile.
Definition station_map.h:28
HasStationTileRail
bool HasStationTileRail(Tile t)
Has this station tile a rail? In other words, is this station tile a rail station or rail waypoint?
Definition station_map.h:146
IsBuoyTile
bool IsBuoyTile(Tile t)
Is tile t a buoy tile?
Definition station_map.h:410
MoveBuoysToWaypoints
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints.
Definition station_sl.cpp:45
UpdateWaypointOrder
static void UpdateWaypointOrder(Order &o)
Update the buoy orders to be waypoint orders.
Definition station_sl.cpp:31
AfterLoadRoadStops
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
Definition station_sl.cpp:144
SwapPackets
static void SwapPackets(GoodsEntry *ge)
Swap the temporary packets with the packets without specific destination in the given goods entry.
Definition station_sl.cpp:191
station_sl_compat.h
Loading of station chunks before table headers were added.
_station_base_sl_compat
const SaveLoadCompat _station_base_sl_compat[]
Original field order for SlStationBase.
Definition station_sl_compat.h:75
_roadstop_sl_compat
const SaveLoadCompat _roadstop_sl_compat[]
Original field order for _roadstop_desc.
Definition station_sl_compat.h:16
_station_sl_compat
const SaveLoadCompat _station_sl_compat[]
Original field order for _station_desc.
Definition station_sl_compat.h:133
_station_cargo_sl_compat
const SaveLoadCompat _station_cargo_sl_compat[]
Original field order for SlStationCargo.
Definition station_sl_compat.h:36
_station_goods_sl_compat
const SaveLoadCompat _station_goods_sl_compat[]
Original field order for SlStationGoods.
Definition station_sl_compat.h:50
_station_flow_sl_compat
const SaveLoadCompat _station_flow_sl_compat[]
Original field order for SlStationFlow.
Definition station_sl_compat.h:42
_station_waypoint_sl_compat
const SaveLoadCompat _station_waypoint_sl_compat[]
Original field order for SlStationWaypoint.
Definition station_sl_compat.h:124
_station_normal_sl_compat
const SaveLoadCompat _station_normal_sl_compat[]
Original field order for SlStationNormal.
Definition station_sl_compat.h:90
_old_station_sl_compat
const SaveLoadCompat _old_station_sl_compat[]
Original field order for _old_station_desc.
Definition station_sl_compat.h:141
_station_spec_list_sl_compat
const SaveLoadCompat _station_spec_list_sl_compat[]
Original field order for SlStationSpecList.
Definition station_sl_compat.h:30
HVOT_WAYPOINT
@ HVOT_WAYPOINT
Station is a waypoint (NewGRF only!)
Definition station_type.h:72
StationFacility::Dock
@ Dock
Station with a dock.
StationFacility::Waypoint
@ Waypoint
Station is a waypoint.
StationFacility::Train
@ Train
Station with train station.
StationFacility::Airport
@ Airport
Station with an airport.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
Airport::psa
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition station_base.h:359
BaseStation
Base class for all station-ish types.
Definition base_station_base.h:58
BaseStation::string_id
StringID string_id
Default name (town area) of station.
Definition base_station_base.h:64
BaseStation::facilities
StationFacilities facilities
The facilities that this station has.
Definition base_station_base.h:69
BaseStation::train_station
TileArea train_station
Tile area the train 'station' part covers.
Definition base_station_base.h:83
BaseStation::owner
Owner owner
The owner of this station.
Definition base_station_base.h:68
BaseStation::delete_ctr
uint8_t delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Definition base_station_base.h:61
BaseStation::rect
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Definition base_station_base.h:84
BaseStation::town
Town * town
The town this station is associated with.
Definition base_station_base.h:67
BaseStation::custom_roadstop_tile_data
std::vector< RoadStopTileData > custom_roadstop_tile_data
List of custom road stop tile data.
Definition base_station_base.h:86
BaseStation::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition base_station_base.h:74
BaseStation::name
std::string name
Custom name.
Definition base_station_base.h:63
CargoPacket
Container for cargo from the same location and time.
Definition cargopacket.h:41
ChunkHandler
Handlers and description of chunk.
Definition saveload.h:478
FlowSaveLoad
Definition station_sl.cpp:175
GoodsEntry::GoodsEntryData
Definition station_base.h:212
GoodsEntry::GoodsEntryData::flows
FlowStatMap flows
Planned flows through this station.
Definition station_base.h:214
GoodsEntry::GoodsEntryData::cargo
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition station_base.h:213
GoodsEntry
Stores station stats for a single cargo.
Definition station_base.h:167
GoodsEntry::status
States status
Status of this cargo, see State.
Definition station_base.h:226
GoodsEntry::State::Acceptance
@ Acceptance
Set when the station accepts the cargo currently for final deliveries.
GoodsEntry::State::Rating
@ Rating
This indicates whether a cargo has a rating at the station.
GoodsEntry::GetData
const GoodsEntryData & GetData() const
Get optional cargo packet/flow data.
Definition station_base.h:317
GoodsEntry::HasData
bool HasData() const
Test if this goods entry has optional cargo packet/flow data.
Definition station_base.h:305
GoodsEntry::GetOrCreateData
GoodsEntryData & GetOrCreateData()
Get optional cargo packet/flow data.
Definition station_base.h:338
Map
Size related data of the map.
Definition map_func.h:206
OrderList
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition order_base.h:274
Order
Definition order_base.h:33
Order::GetDestination
DestinationID GetDestination() const
Gets the destination of this order.
Definition order_base.h:99
Order::IsType
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition order_base.h:66
Order::MakeGoToWaypoint
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition order_cmd.cpp:87
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::Add
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition tilearea.cpp:43
PersistentStorageArray
Class for persistent storage of data.
Definition newgrf_storage.h:67
PersistentStorageArray::storage
StorageType storage
Memory for the storage array.
Definition newgrf_storage.h:70
PersistentStorage
Class for pooled persistent storage of data.
Definition newgrf_storage.h:199
PoolID< uint16_t, struct StationIDTag, 64000, 0xFFFF >
Pool::PoolItem<&_orderlist_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_station_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition pool_type.hpp:357
ROADChunkHandler
Definition station_sl.cpp:735
ROADChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition station_sl.cpp:761
ROADChunkHandler::Load
void Load() const override
Load the chunk.
Definition station_sl.cpp:748
ROADChunkHandler::Save
void Save() const override
Save the chunk.
Definition station_sl.cpp:738
RoadStopSpec
Road stop specification.
Definition newgrf_roadstop.h:129
RoadStopTileData
Definition base_station_base.h:29
RoadStop
A Stop for a Road Vehicle.
Definition roadstop_base.h:21
RoadStop::RoadStopStatusFlag::BaseEntry
@ BaseEntry
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
STNNChunkHandler
Definition station_sl.cpp:692
STNNChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition station_sl.cpp:722
STNNChunkHandler::Save
void Save() const override
Save the chunk.
Definition station_sl.cpp:695
STNNChunkHandler::Load
void Load() const override
Load the chunk.
Definition station_sl.cpp:707
STNSChunkHandler
Definition station_sl.cpp:502
STNSChunkHandler::Load
void Load() const override
Load the chunk.
Definition station_sl.cpp:505
STNSChunkHandler::FixPointers
void FixPointers() const override
Fix the pointers.
Definition station_sl.cpp:522
SaveLoad
SaveLoad type struct.
Definition saveload.h:732
SpecMapping
Definition base_station_base.h:23
SpecializedStation< Station, false >::IsExpected
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
Definition base_station_base.h:229
SpecializedStation< Station, false >::Iterate
static Pool::IterateWrapper< Station > Iterate(size_t from=0)
Returns an iterable ensemble of all valid stations of type T.
Definition base_station_base.h:299
SpecializedStation< Station, false >::Get
static Station * Get(auto index)
Gets station with given index.
Definition base_station_base.h:248
SpecializedStation< Station, false >::From
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
Definition base_station_base.h:277
StationSpec
Station specification.
Definition newgrf_station.h:123
Station
Station data structure.
Definition station_base.h:500
Station::bus_stops
RoadStop * bus_stops
All the road stops.
Definition station_base.h:509
Station::goods
std::array< GoodsEntry, NUM_CARGO > goods
Goods at this station.
Definition station_base.h:529
Station::bus_station
TileArea bus_station
Tile area the bus 'station' part covers.
Definition station_base.h:510
Station::airport
Airport airport
Tile area the airport covers.
Definition station_base.h:514
Station::truck_station
TileArea truck_station
Tile area the truck 'station' part covers.
Definition station_base.h:512
Station::truck_stops
RoadStop * truck_stops
All the truck stops.
Definition station_base.h:511
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Town
Town data structure.
Definition town.h:63
Town::name
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Definition town.h:72
Vehicle
Vehicle data structure.
Definition vehicle_base.h:205
Waypoint
Representation of a waypoint.
Definition waypoint_base.h:23
Waypoint::town_cn
uint16_t town_cn
The N-1th waypoint for this town (consecutive number)
Definition waypoint_base.h:24
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_STATION
@ MP_STATION
A tile of a station.
Definition tile_type.h:53
VehicleType
VehicleType
Available vehicle types.
Definition vehicle_type.h:22
VEH_SHIP
@ VEH_SHIP
Ship vehicle type.
Definition vehicle_type.h:27
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition vehicle_type.h:25