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

OpenTTD Source 14.0-RC3

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