OpenTTD
station_sl.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "../stdafx.h"
13 #include "../station_base.h"
14 #include "../waypoint_base.h"
15 #include "../roadstop_base.h"
16 #include "../vehicle_base.h"
17 #include "../newgrf_station.h"
18 
19 #include "saveload.h"
20 #include "table/strings.h"
21 
22 #include "../safeguards.h"
23 
28 static void UpdateWaypointOrder(Order *o)
29 {
30  if (!o->IsType(OT_GOTO_STATION)) return;
31 
32  const Station *st = Station::Get(o->GetDestination());
33  if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) return;
34 
36 }
37 
43 {
44  /* Buoy orders become waypoint orders */
45  OrderList *ol;
46  FOR_ALL_ORDER_LISTS(ol) {
48  if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
49 
50  for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
51  }
52 
53  Vehicle *v;
54  FOR_ALL_VEHICLES(v) {
55  VehicleType vt = v->type;
56  if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
57 
59  }
60 
61  /* Now make the stations waypoints */
62  Station *st;
63  FOR_ALL_STATIONS(st) {
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  char *name = st->name;
71  st->name = NULL;
72  Date build_date = st->build_date;
73  /* TTDPatch could use "buoys with rail station" for rail waypoints */
74  bool train = st->train_station.tile != INVALID_TILE;
75  TileArea train_st = st->train_station;
76 
77  /* Delete the station, so we can make it a real waypoint. */
78  delete st;
79 
80  /* Stations and waypoints are in the same pool, so if a station
81  * is deleted there must be place for a Waypoint. */
82  assert(Waypoint::CanAllocateItem());
83  Waypoint *wp = new (index) Waypoint(xy);
84  wp->town = town;
85  wp->string_id = train ? STR_SV_STNAME_WAYPOINT : STR_SV_STNAME_BUOY;
86  wp->name = name;
87  wp->delete_ctr = 0; // Just reset delete counter for once.
88  wp->build_date = build_date;
89  wp->owner = train ? GetTileOwner(xy) : OWNER_NONE;
90 
91  if (IsInsideBS(string_id, STR_SV_STNAME_BUOY, 9)) wp->town_cn = string_id - STR_SV_STNAME_BUOY;
92 
93  if (train) {
94  /* When we make a rail waypoint of the station, convert the map as well. */
95  TILE_AREA_LOOP(t, train_st) {
96  if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;
97 
98  SB(_me[t].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  BaseStation *st;
115  FOR_ALL_BASE_STATIONS(st) {
116  for (uint i = 0; i < st->num_specs; i++) {
117  if (st->speclist[i].grfid == 0) continue;
118 
119  st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
120  }
121 
122  if (Station::IsExpected(st)) {
123  Station *sta = Station::From(st);
124  for (const RoadStop *rs = sta->bus_stops; rs != NULL; rs = rs->next) sta->bus_station.Add(rs->xy);
125  for (const RoadStop *rs = sta->truck_stops; rs != NULL; rs = rs->next) sta->truck_station.Add(rs->xy);
126  }
127 
129  }
130 }
131 
136 {
137  /* First construct the drive through entries */
138  RoadStop *rs;
139  FOR_ALL_ROADSTOPS(rs) {
141  }
142  /* And then rebuild the data in those entries */
143  FOR_ALL_ROADSTOPS(rs) {
144  if (!HasBit(rs->status, RoadStop::RSSFB_BASE_ENTRY)) continue;
145 
146  rs->GetEntry(DIAGDIR_NE)->Rebuild(rs);
147  rs->GetEntry(DIAGDIR_NW)->Rebuild(rs);
148  }
149 }
150 
151 static const SaveLoad _roadstop_desc[] = {
152  SLE_VAR(RoadStop, xy, SLE_UINT32),
154  SLE_VAR(RoadStop, status, SLE_UINT8),
155  /* Index was saved in some versions, but this is not needed */
159 
162 
165 
166  SLE_END()
167 };
168 
169 static const SaveLoad _old_station_desc[] = {
170  SLE_CONDVAR(Station, xy, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
171  SLE_CONDVAR(Station, xy, SLE_UINT32, SLV_6, SL_MAX_VERSION),
173  SLE_CONDVAR(Station, train_station.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
174  SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
175  SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
176  SLE_CONDVAR(Station, airport.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
177  SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
178  SLE_CONDVAR(Station, dock_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
179  SLE_REF(Station, town, REF_TOWN),
180  SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
181  SLE_CONDVAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SL_MAX_VERSION),
182 
184 
185  SLE_VAR(Station, string_id, SLE_STRINGID),
187  SLE_CONDVAR(Station, indtype, SLE_UINT8, SLV_103, SL_MAX_VERSION),
188  SLE_CONDVAR(Station, had_vehicle_of_type, SLE_FILE_U16 | SLE_VAR_U8, SL_MIN_VERSION, SLV_122),
189  SLE_CONDVAR(Station, had_vehicle_of_type, SLE_UINT8, SLV_122, SL_MAX_VERSION),
190 
191  SLE_VAR(Station, time_since_load, SLE_UINT8),
192  SLE_VAR(Station, time_since_unload, SLE_UINT8),
193  SLE_VAR(Station, delete_ctr, SLE_UINT8),
194  SLE_VAR(Station, owner, SLE_UINT8),
195  SLE_VAR(Station, facilities, SLE_UINT8),
196  SLE_VAR(Station, airport.type, SLE_UINT8),
197 
200 
201  SLE_CONDVAR(Station, airport.flags, SLE_VAR_U64 | SLE_FILE_U16, SL_MIN_VERSION, SLV_3),
202  SLE_CONDVAR(Station, airport.flags, SLE_VAR_U64 | SLE_FILE_U32, SLV_3, SLV_46),
203  SLE_CONDVAR(Station, airport.flags, SLE_UINT64, SLV_46, SL_MAX_VERSION),
204 
206  SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, SLV_26, SL_MAX_VERSION),
207 
208  SLE_CONDNULL(2, SLV_3, SLV_26),
209  SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, SLV_3, SLV_31),
210  SLE_CONDVAR(Station, build_date, SLE_INT32, SLV_31, SL_MAX_VERSION),
211 
214 
215  /* Used by newstations for graphic variations */
216  SLE_CONDVAR(Station, random_bits, SLE_UINT16, SLV_27, SL_MAX_VERSION),
217  SLE_CONDVAR(Station, waiting_triggers, SLE_UINT8, SLV_27, SL_MAX_VERSION),
218  SLE_CONDVAR(Station, num_specs, SLE_UINT8, SLV_27, SL_MAX_VERSION),
219 
220  SLE_CONDLST(Station, loading_vehicles, REF_VEHICLE, SLV_57, SL_MAX_VERSION),
221 
222  /* reserve extra space in savegame here. (currently 32 bytes) */
224 
225  SLE_END()
226 };
227 
228 static uint16 _waiting_acceptance;
229 static uint32 _num_flows;
230 static uint16 _cargo_source;
231 static uint32 _cargo_source_xy;
232 static uint8 _cargo_days;
233 static Money _cargo_feeder_share;
234 
235 static const SaveLoad _station_speclist_desc[] = {
236  SLE_CONDVAR(StationSpecList, grfid, SLE_UINT32, SLV_27, SL_MAX_VERSION),
237  SLE_CONDVAR(StationSpecList, localidx, SLE_UINT8, SLV_27, SL_MAX_VERSION),
238 
239  SLE_END()
240 };
241 
242 std::list<CargoPacket *> _packets;
243 uint32 _num_dests;
244 
245 struct FlowSaveLoad {
246  FlowSaveLoad() : source(0), via(0), share(0), restricted(false) {}
247  StationID source;
248  StationID via;
249  uint32 share;
250  bool restricted;
251 };
252 
253 static const SaveLoad _flow_desc[] = {
254  SLE_VAR(FlowSaveLoad, source, SLE_UINT16),
255  SLE_VAR(FlowSaveLoad, via, SLE_UINT16),
256  SLE_VAR(FlowSaveLoad, share, SLE_UINT32),
257  SLE_CONDVAR(FlowSaveLoad, restricted, SLE_BOOL, SLV_187, SL_MAX_VERSION),
258  SLE_END()
259 };
260 
267 {
268  static const SaveLoad goods_desc[] = {
269  SLEG_CONDVAR( _waiting_acceptance, SLE_UINT16, SL_MIN_VERSION, SLV_68),
270  SLE_CONDVAR(GoodsEntry, status, SLE_UINT8, SLV_68, SL_MAX_VERSION),
272  SLE_VAR(GoodsEntry, time_since_pickup, SLE_UINT8),
273  SLE_VAR(GoodsEntry, rating, SLE_UINT8),
274  SLEG_CONDVAR( _cargo_source, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_7),
275  SLEG_CONDVAR( _cargo_source, SLE_UINT16, SLV_7, SLV_68),
276  SLEG_CONDVAR( _cargo_source_xy, SLE_UINT32, SLV_44, SLV_68),
277  SLEG_CONDVAR( _cargo_days, SLE_UINT8, SL_MIN_VERSION, SLV_68),
278  SLE_VAR(GoodsEntry, last_speed, SLE_UINT8),
279  SLE_VAR(GoodsEntry, last_age, SLE_UINT8),
280  SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_U32 | SLE_VAR_I64, SLV_14, SLV_65),
281  SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, SLV_65, SLV_68),
282  SLE_CONDVAR(GoodsEntry, amount_fract, SLE_UINT8, SLV_150, SL_MAX_VERSION),
284  SLEG_CONDVAR( _num_dests, SLE_UINT32, SLV_183, SL_MAX_VERSION),
285  SLE_CONDVAR(GoodsEntry, cargo.reserved_count, SLE_UINT, SLV_181, SL_MAX_VERSION),
286  SLE_CONDVAR(GoodsEntry, link_graph, SLE_UINT16, SLV_183, SL_MAX_VERSION),
287  SLE_CONDVAR(GoodsEntry, node, SLE_UINT16, SLV_183, SL_MAX_VERSION),
288  SLEG_CONDVAR( _num_flows, SLE_UINT32, SLV_183, SL_MAX_VERSION),
289  SLE_CONDVAR(GoodsEntry, max_waiting_cargo, SLE_UINT32, SLV_183, SL_MAX_VERSION),
290  SLE_END()
291  };
292 
293  return goods_desc;
294 }
295 
296 typedef std::pair<const StationID, std::list<CargoPacket *> > StationCargoPair;
297 
298 static const SaveLoad _cargo_list_desc[] = {
299  SLE_VAR(StationCargoPair, first, SLE_UINT16),
300  SLE_LST(StationCargoPair, second, REF_CARGO_PACKET),
301  SLE_END()
302 };
303 
309 static void SwapPackets(GoodsEntry *ge)
310 {
311  StationCargoPacketMap &ge_packets = const_cast<StationCargoPacketMap &>(*ge->cargo.Packets());
312 
313  if (_packets.empty()) {
314  std::map<StationID, std::list<CargoPacket *> >::iterator it(ge_packets.find(INVALID_STATION));
315  if (it == ge_packets.end()) {
316  return;
317  } else {
318  it->second.swap(_packets);
319  }
320  } else {
321  assert(ge_packets[INVALID_STATION].empty());
322  ge_packets[INVALID_STATION].swap(_packets);
323  }
324 }
325 
326 static void Load_STNS()
327 {
328  _cargo_source_xy = 0;
329  _cargo_days = 0;
330  _cargo_feeder_share = 0;
331 
333  int index;
334  while ((index = SlIterateArray()) != -1) {
335  Station *st = new (index) Station();
336 
337  SlObject(st, _old_station_desc);
338 
339  _waiting_acceptance = 0;
340 
341  for (CargoID i = 0; i < num_cargo; i++) {
342  GoodsEntry *ge = &st->goods[i];
343  SlObject(ge, GetGoodsDesc());
344  SwapPackets(ge);
346  SB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1, HasBit(_waiting_acceptance, 15));
347  if (GB(_waiting_acceptance, 0, 12) != 0) {
348  /* In old versions, enroute_from used 0xFF as INVALID_STATION */
349  StationID source = (IsSavegameVersionBefore(SLV_7) && _cargo_source == 0xFF) ? INVALID_STATION : _cargo_source;
350 
351  /* Make sure we can allocate the CargoPacket. This is safe
352  * as there can only be ~64k stations and 32 cargoes in these
353  * savegame versions. As the CargoPacketPool has more than
354  * 16 million entries; it fits by an order of magnitude. */
356 
357  /* Don't construct the packet with station here, because that'll fail with old savegames */
358  CargoPacket *cp = new CargoPacket(GB(_waiting_acceptance, 0, 12), _cargo_days, source, _cargo_source_xy, _cargo_source_xy, _cargo_feeder_share);
359  ge->cargo.Append(cp, INVALID_STATION);
360  SB(ge->status, GoodsEntry::GES_RATING, 1, 1);
361  }
362  }
363  }
364 
365  if (st->num_specs != 0) {
366  /* Allocate speclist memory when loading a game */
367  st->speclist = CallocT<StationSpecList>(st->num_specs);
368  for (uint i = 0; i < st->num_specs; i++) {
369  SlObject(&st->speclist[i], _station_speclist_desc);
370  }
371  }
372  }
373 }
374 
375 static void Ptrs_STNS()
376 {
377  /* Don't run when savegame version is higher than or equal to 123. */
378  if (!IsSavegameVersionBefore(SLV_123)) return;
379 
381  Station *st;
382  FOR_ALL_STATIONS(st) {
384  for (CargoID i = 0; i < num_cargo; i++) {
385  GoodsEntry *ge = &st->goods[i];
386  SwapPackets(ge);
387  SlObject(ge, GetGoodsDesc());
388  SwapPackets(ge);
389  }
390  }
391  SlObject(st, _old_station_desc);
392  }
393 }
394 
395 
396 static const SaveLoad _base_station_desc[] = {
397  SLE_VAR(BaseStation, xy, SLE_UINT32),
398  SLE_REF(BaseStation, town, REF_TOWN),
399  SLE_VAR(BaseStation, string_id, SLE_STRINGID),
401  SLE_VAR(BaseStation, delete_ctr, SLE_UINT8),
402  SLE_VAR(BaseStation, owner, SLE_UINT8),
403  SLE_VAR(BaseStation, facilities, SLE_UINT8),
404  SLE_VAR(BaseStation, build_date, SLE_INT32),
405 
406  /* Used by newstations for graphic variations */
407  SLE_VAR(BaseStation, random_bits, SLE_UINT16),
408  SLE_VAR(BaseStation, waiting_triggers, SLE_UINT8),
409  SLE_VAR(BaseStation, num_specs, SLE_UINT8),
410 
411  SLE_END()
412 };
413 
414 static OldPersistentStorage _old_st_persistent_storage;
415 
416 static const SaveLoad _station_desc[] = {
417  SLE_WRITEBYTE(Station, facilities),
418  SLE_ST_INCLUDE(),
419 
420  SLE_VAR(Station, train_station.tile, SLE_UINT32),
421  SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
422  SLE_VAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16),
423 
424  SLE_REF(Station, bus_stops, REF_ROADSTOPS),
425  SLE_REF(Station, truck_stops, REF_ROADSTOPS),
426  SLE_VAR(Station, dock_tile, SLE_UINT32),
427  SLE_VAR(Station, airport.tile, SLE_UINT32),
428  SLE_CONDVAR(Station, airport.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
429  SLE_CONDVAR(Station, airport.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
430  SLE_VAR(Station, airport.type, SLE_UINT8),
431  SLE_CONDVAR(Station, airport.layout, SLE_UINT8, SLV_145, SL_MAX_VERSION),
432  SLE_VAR(Station, airport.flags, SLE_UINT64),
433  SLE_CONDVAR(Station, airport.rotation, SLE_UINT8, SLV_145, SL_MAX_VERSION),
434  SLEG_CONDARR(_old_st_persistent_storage.storage, SLE_UINT32, 16, SLV_145, SLV_161),
436 
437  SLE_VAR(Station, indtype, SLE_UINT8),
438 
439  SLE_VAR(Station, time_since_load, SLE_UINT8),
440  SLE_VAR(Station, time_since_unload, SLE_UINT8),
441  SLE_VAR(Station, last_vehicle_type, SLE_UINT8),
442  SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8),
443  SLE_LST(Station, loading_vehicles, REF_VEHICLE),
444  SLE_CONDVAR(Station, always_accepted, SLE_FILE_U32 | SLE_VAR_U64, SLV_127, SLV_EXTEND_CARGOTYPES),
445  SLE_CONDVAR(Station, always_accepted, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
446 
447  SLE_END()
448 };
449 
450 static const SaveLoad _waypoint_desc[] = {
451  SLE_WRITEBYTE(Waypoint, facilities),
452  SLE_ST_INCLUDE(),
453 
454  SLE_VAR(Waypoint, town_cn, SLE_UINT16),
455 
456  SLE_CONDVAR(Waypoint, train_station.tile, SLE_UINT32, SLV_124, SL_MAX_VERSION),
457  SLE_CONDVAR(Waypoint, train_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION),
458  SLE_CONDVAR(Waypoint, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_124, SL_MAX_VERSION),
459 
460  SLE_END()
461 };
462 
468 {
469  return _base_station_desc;
470 }
471 
472 static void RealSave_STNN(BaseStation *bst)
473 {
474  bool waypoint = (bst->facilities & FACIL_WAYPOINT) != 0;
475  SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
476 
477  if (!waypoint) {
478  Station *st = Station::From(bst);
479  for (CargoID i = 0; i < NUM_CARGO; i++) {
480  _num_dests = (uint32)st->goods[i].cargo.Packets()->MapSize();
481  _num_flows = 0;
482  for (FlowStatMap::const_iterator it(st->goods[i].flows.begin()); it != st->goods[i].flows.end(); ++it) {
483  _num_flows += (uint32)it->second.GetShares()->size();
484  }
485  SlObject(&st->goods[i], GetGoodsDesc());
486  for (FlowStatMap::const_iterator outer_it(st->goods[i].flows.begin()); outer_it != st->goods[i].flows.end(); ++outer_it) {
487  const FlowStat::SharesMap *shares = outer_it->second.GetShares();
488  uint32 sum_shares = 0;
489  FlowSaveLoad flow;
490  flow.source = outer_it->first;
491  for (FlowStat::SharesMap::const_iterator inner_it(shares->begin()); inner_it != shares->end(); ++inner_it) {
492  flow.via = inner_it->second;
493  flow.share = inner_it->first - sum_shares;
494  flow.restricted = inner_it->first > outer_it->second.GetUnrestricted();
495  sum_shares = inner_it->first;
496  assert(flow.share > 0);
497  SlObject(&flow, _flow_desc);
498  }
499  }
500  for (StationCargoPacketMap::ConstMapIterator it(st->goods[i].cargo.Packets()->begin()); it != st->goods[i].cargo.Packets()->end(); ++it) {
501  SlObject(const_cast<StationCargoPacketMap::value_type *>(&(*it)), _cargo_list_desc);
502  }
503  }
504  }
505 
506  for (uint i = 0; i < bst->num_specs; i++) {
507  SlObject(&bst->speclist[i], _station_speclist_desc);
508  }
509 }
510 
511 static void Save_STNN()
512 {
513  BaseStation *st;
514  /* Write the stations */
515  FOR_ALL_BASE_STATIONS(st) {
516  SlSetArrayIndex(st->index);
517  SlAutolength((AutolengthProc*)RealSave_STNN, st);
518  }
519 }
520 
521 static void Load_STNN()
522 {
523  _num_flows = 0;
524 
526  int index;
527  while ((index = SlIterateArray()) != -1) {
528  bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0;
529 
530  BaseStation *bst = waypoint ? (BaseStation *)new (index) Waypoint() : new (index) Station();
531  SlObject(bst, waypoint ? _waypoint_desc : _station_desc);
532 
533  if (!waypoint) {
534  Station *st = Station::From(bst);
535 
536  /* Before savegame version 161, persistent storages were not stored in a pool. */
538  /* Store the old persistent storage. The GRFID will be added later. */
540  st->airport.psa = new PersistentStorage(0, 0, 0);
541  memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(_old_st_persistent_storage.storage));
542  }
543 
544  for (CargoID i = 0; i < num_cargo; i++) {
545  SlObject(&st->goods[i], GetGoodsDesc());
546  FlowSaveLoad flow;
547  FlowStat *fs = NULL;
548  StationID prev_source = INVALID_STATION;
549  for (uint32 j = 0; j < _num_flows; ++j) {
550  SlObject(&flow, _flow_desc);
551  if (fs == NULL || prev_source != flow.source) {
552  fs = &(st->goods[i].flows.insert(std::make_pair(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second);
553  } else {
554  fs->AppendShare(flow.via, flow.share, flow.restricted);
555  }
556  prev_source = flow.source;
557  }
559  SwapPackets(&st->goods[i]);
560  } else {
561  StationCargoPair pair;
562  for (uint j = 0; j < _num_dests; ++j) {
563  SlObject(&pair, _cargo_list_desc);
564  const_cast<StationCargoPacketMap &>(*(st->goods[i].cargo.Packets()))[pair.first].swap(pair.second);
565  assert(pair.second.empty());
566  }
567  }
568  }
569  }
570 
571  if (bst->num_specs != 0) {
572  /* Allocate speclist memory when loading a game */
573  bst->speclist = CallocT<StationSpecList>(bst->num_specs);
574  for (uint i = 0; i < bst->num_specs; i++) {
575  SlObject(&bst->speclist[i], _station_speclist_desc);
576  }
577  }
578  }
579 }
580 
581 static void Ptrs_STNN()
582 {
583  /* Don't run when savegame version lower than 123. */
584  if (IsSavegameVersionBefore(SLV_123)) return;
585 
587  Station *st;
588  FOR_ALL_STATIONS(st) {
589  for (CargoID i = 0; i < num_cargo; i++) {
590  GoodsEntry *ge = &st->goods[i];
592  SwapPackets(ge);
593  SlObject(ge, GetGoodsDesc());
594  SwapPackets(ge);
595  } else {
596  SlObject(ge, GetGoodsDesc());
597  for (StationCargoPacketMap::ConstMapIterator it = ge->cargo.Packets()->begin(); it != ge->cargo.Packets()->end(); ++it) {
598  SlObject(const_cast<StationCargoPair *>(&(*it)), _cargo_list_desc);
599  }
600  }
601  }
602  SlObject(st, _station_desc);
603  }
604 
605  Waypoint *wp;
606  FOR_ALL_WAYPOINTS(wp) {
607  SlObject(wp, _waypoint_desc);
608  }
609 }
610 
611 static void Save_ROADSTOP()
612 {
613  RoadStop *rs;
614 
615  FOR_ALL_ROADSTOPS(rs) {
616  SlSetArrayIndex(rs->index);
617  SlObject(rs, _roadstop_desc);
618  }
619 }
620 
621 static void Load_ROADSTOP()
622 {
623  int index;
624 
625  while ((index = SlIterateArray()) != -1) {
626  RoadStop *rs = new (index) RoadStop(INVALID_TILE);
627 
628  SlObject(rs, _roadstop_desc);
629  }
630 }
631 
632 static void Ptrs_ROADSTOP()
633 {
634  RoadStop *rs;
635  FOR_ALL_ROADSTOPS(rs) {
636  SlObject(rs, _roadstop_desc);
637  }
638 }
639 
640 extern const ChunkHandler _station_chunk_handlers[] = {
641  { 'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
642  { 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
643  { 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY | CH_LAST},
644 };
#define SLE_CONDNULL(length, from, to)
Empty space in some savegame versions.
Definition: saveload.h:632
127 17439
Definition: saveload.h:196
44 8144
Definition: saveload.h:96
uint16 town_cn
The N-1th waypoint for this town (consecutive number)
Definition: waypoint_base.h:19
byte status
Current status of the Stop,.
Definition: roadstop_base.h:70
static bool IsSavegameVersionBefore(SaveLoadVersion major, byte minor=0)
Checks whether the savegame is below major.
Definition: saveload.h:753
TileArea bus_station
Tile area the bus &#39;station&#39; part covers.
Definition: station_base.h:456
2.0 0.3.0 2.1 0.3.1, 0.3.2
Definition: saveload.h:35
#define SLE_CONDSTR(base, variable, type, length, from, to)
Storage of a string in some savegame versions.
Definition: saveload.h:556
#define SLE_CONDREF(base, variable, type, from, to)
Storage of a reference in some savegame versions.
Definition: saveload.h:534
uint8 num_specs
Number of specs in the speclist.
#define SLE_LST(base, variable, type)
Storage of a list in every savegame version.
Definition: saveload.h:618
51 8978
Definition: saveload.h:105
26 4466
Definition: saveload.h:75
#define SLE_REF(base, variable, type)
Storage of a reference in every version of a savegame.
Definition: saveload.h:592
Maximal number of cargo types in a game.
Definition: cargo_type.h:66
TileIndex xy
Position on the map.
Definition: roadstop_base.h:69
103 14598
Definition: saveload.h:167
void MakeDriveThrough()
Join this road stop to another &#39;base&#39; road stop if possible; fill all necessary data to become an act...
Definition: roadstop.cpp:64
145 20376
Definition: saveload.h:218
static void UpdateWaypointOrder(Order *o)
Update the buoy orders to be waypoint orders.
Definition: station_sl.cpp:28
25 4259
Definition: saveload.h:74
TileArea train_station
Tile area the train &#39;station&#39; part covers.
Vehicle data structure.
Definition: vehicle_base.h:212
static bool IsExpected(const BaseStation *st)
Helper for checking whether the given station is of this type.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:250
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
Stores station stats for a single cargo.
Definition: station_base.h:170
Tindex index
Index of this pool item.
Definition: pool_type.hpp:147
Northeast, upper right on your monitor.
Load/save a reference to a town.
Definition: saveload.h:364
Representation of a waypoint.
Definition: waypoint_base.h:18
const SaveLoad * GetBaseStationDescription()
Get the base station description to be used for SL_ST_INCLUDE.
Definition: station_sl.cpp:467
StationCargoList cargo
The cargo packets of cargo waiting in this station.
Definition: station_base.h:255
static bool IsDriveThroughStopTile(TileIndex t)
Is tile t a drive through road stop station?
Definition: station_map.h:234
Town * town
The town this station is associated with.
Vehicle * GetFirstSharedVehicle() const
Get the first vehicle of this vehicle chain.
Definition: order_base.h:337
void MoveBuoysToWaypoints()
Perform all steps to upgrade from the old station buoys to the new version that uses waypoints...
Definition: station_sl.cpp:42
#define SLE_CONDLST(base, variable, type, from, to)
Storage of a list in some savegame versions.
Definition: saveload.h:566
void StationUpdateCachedTriggers(BaseStation *st)
Update the cached animation trigger bitmask for a station.
#define SLEG_CONDARR(variable, type, length, from, to)
Storage of a global array in some savegame versions.
Definition: saveload.h:680
GoodsEntry goods[NUM_CARGO]
Goods at this station.
Definition: station_base.h:472
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Station is a waypoint (NewGRF only!)
Definition: station_type.h:73
static Station * From(BaseStation *st)
Converts a BaseStation to SpecializedStation with type checking.
57 9691
Definition: saveload.h:112
byte delete_ctr
Delete counter. If greater than 0 then it is decremented until it reaches 0; the waypoint is then is ...
Order * next
Pointer to next order. If NULL, end of list.
Definition: order_base.h:51
Class for persistent storage of data.
150 20857
Definition: saveload.h:224
Load/save a reference to a bus/truck stop.
Definition: saveload.h:366
122 16855
Definition: saveload.h:190
Station is a waypoint.
Definition: station_type.h:59
Shared order list linking together the linked list of orders and the list of vehicles sharing this or...
Definition: order_base.h:252
Hand-rolled multimap as map of lists.
Definition: multimap.hpp:19
Functions/types related to saving and loading games.
#define SLE_CONDVAR(base, variable, type, from, to)
Storage of a variable in some savegame versions.
Definition: saveload.h:524
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
68 10266
Definition: saveload.h:125
RoadStop * truck_stops
All the truck stops.
Definition: station_base.h:457
This indicates whether a cargo has a rating at the station.
Definition: station_base.h:187
void Add(TileIndex to_add)
Add a single tile to a tile area; enlarge if needed.
Definition: tilearea.cpp:45
const SaveLoad * GetGoodsDesc()
Wrapper function to get the GoodsEntry&#39;s internal structure while some of the variables itself are pr...
Definition: station_sl.cpp:266
Highest possible saveload version.
Definition: saveload.h:295
allow control codes in the strings
Definition: saveload.h:461
5.0 1429 5.1 1440 5.2 1525 0.3.6
Definition: saveload.h:44
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
First savegame version.
Definition: saveload.h:32
bool IsType(OrderType type) const
Check whether this order is of the given type.
Definition: order_base.h:63
TileArea truck_station
Tile area the truck &#39;station&#39; part covers.
Definition: station_base.h:458
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
byte status
Status of this cargo, see GoodsEntryStatus.
Definition: station_base.h:226
Container for cargo from the same location and time.
Definition: cargopacket.h:44
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
#define SLE_WRITEBYTE(base, variable)
Translate values ingame to different values in the savegame and vv.
Definition: saveload.h:635
TileExtended * _me
Extended Tiles of the map.
Definition: map.cpp:33
struct RoadStop * next
Next stop of the given type at this station.
Definition: roadstop_base.h:71
TYPE storage[SIZE]
Memory to for the storage array.
static bool IsBuoyTile(TileIndex t)
Is tile t a buoy tile?
Definition: station_map.h:317
Represents the covered area of e.g.
Definition: tilearea_type.h:18
Class for pooled persistent storage of data.
Order * GetFirstOrder() const
Get the first order of the order chain.
Definition: order_base.h:290
StationSpecList * speclist
List of station specs of this station.
55 9638
Definition: saveload.h:110
The tile has no ownership.
Definition: company_type.h:27
Northwest.
PersistentStorage * psa
Persistent storage for NewGRF airports.
Definition: station_base.h:313
StationFacilityByte facilities
The facilities that this station has.
84 11822
Definition: saveload.h:144
183 25363 Cargodist
Definition: saveload.h:263
Station with a dock.
Definition: station_type.h:58
byte SlReadByte()
Wrapper for reading a byte from the buffer.
Definition: saveload.cpp:411
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
6.0 1721 6.1 1768
Definition: saveload.h:47
123 16909
Definition: saveload.h:191
int SlIterateArray()
Iterate through the elements of an array and read the whole thing.
Definition: saveload.cpp:634
Load/save a reference to a vehicle.
Definition: saveload.h:362
124 16993
Definition: saveload.h:192
RoadStop * bus_stops
All the road stops.
Definition: station_base.h:455
Handlers and description of chunk.
Definition: saveload.h:346
static void SwapPackets(GoodsEntry *ge)
Swap the temporary packets with the packets without specific destination in the given goods entry...
Definition: station_sl.cpp:309
Ship vehicle type.
Definition: vehicle_type.h:28
FlowStatMap flows
Planned flows through this station.
Definition: station_base.h:259
#define SLEG_CONDVAR(variable, type, from, to)
Storage of a global variable in some savegame versions.
Definition: saveload.h:661
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
OwnerByte owner
The owner of this station.
#define SLE_END()
End marker of a struct/class save or load.
Definition: saveload.h:641
9.0 1909
Definition: saveload.h:51
static StationID GetStationIndex(TileIndex t)
Get StationID from a tile.
Definition: station_map.h:29
3.x lost
Definition: saveload.h:37
7.0 1770
Definition: saveload.h:49
Load/save a reference to a cargo packet.
Definition: saveload.h:368
DestinationID GetDestination() const
Gets the destination of this order.
Definition: order_base.h:96
181 25012
Definition: saveload.h:261
size_t MapSize() const
Count the number of ranges with equal keys in this MultiMap.
Definition: multimap.hpp:352
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
14.0 2441
Definition: saveload.h:58
TileIndex xy
Base tile of the station.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
void AppendShare(StationID st, uint flow, bool restricted=false)
Add some flow to the end of the shares map.
Definition: station_base.h:70
A tile of a station.
Definition: tile_type.h:48
void SlObject(void *object, const SaveLoad *sld)
Main SaveLoad function.
Definition: saveload.cpp:1543
Town data structure.
Definition: town.h:55
Station with train station.
Definition: station_type.h:54
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:216
Flow statistics telling how much flow should be sent along a link.
Definition: station_base.h:36
const Entry * GetEntry(DiagDirection dir) const
Get the drive through road stop entry struct for the given direction.
A Stop for a Road Vehicle.
Definition: roadstop_base.h:24
65 10210
Definition: saveload.h:122
uint8 localidx
Station ID within GRF of station.
void SlAutolength(AutolengthProc *proc, void *arg)
Do something of which I have no idea what it is :P.
Definition: saveload.cpp:1571
int32 Date
The type to store our dates in.
Definition: date_type.h:16
Airport airport
Tile area the airport covers.
Definition: station_base.h:460
140 19382
Definition: saveload.h:212
void MakeGoToWaypoint(StationID destination)
Makes this order a Go To Waypoint order.
Definition: order_cmd.cpp:106
SaveLoad type struct.
Definition: saveload.h:486
#define SLE_VAR(base, variable, type)
Storage of a variable in every version of a savegame.
Definition: saveload.h:584
45 8501
Definition: saveload.h:98
const Tcont * Packets() const
Returns a pointer to the cargo packet list (so you can iterate over it etc).
Definition: cargopacket.h:261
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
#define SLE_STR(base, variable, type, length)
Storage of a string in every savegame version.
Definition: saveload.h:610
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
161 22567
Definition: saveload.h:237
Non-zero when the entries on this road stop are the primary, i.e. the ones to delete.
Definition: roadstop_base.h:29
199 PR#6802 Extend cargotypes to 64
Definition: saveload.h:283
187 25899 Linkgraph - restricted flows
Definition: saveload.h:268
void Rebuild(const RoadStop *rs, int side=-1)
Rebuild, from scratch, the vehicles and other metadata on this stop.
Definition: roadstop.cpp:354
31 5999
Definition: saveload.h:81
static Station * Get(size_t index)
Gets station with given index.
char * name
Custom name.
46 8705
Definition: saveload.h:99
StringID string_id
Default name (town area) of station.
27 4757
Definition: saveload.h:76
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
void Append(CargoPacket *cp, StationID next)
Appends the given cargo packet to the range of packets with the same next station.
Base class for all station-ish types.
Station data structure.
Definition: station_base.h:446
Set when the station accepts the cargo currently for final deliveries.
Definition: station_base.h:177
Station with an airport.
Definition: station_type.h:57
Order current_order
The current order (+ status, like: loading)
Definition: vehicle_base.h:318
#define SLEG_CONDLST(variable, type, from, to)
Storage of a global list in some savegame versions.
Definition: saveload.h:699
uint32 grfid
GRF ID of this custom station.
#define FOR_ALL_WAYPOINTS(var)
Iterate over all waypoints.
Definition: waypoint_base.h:74
Date build_date
Date of construction.
void AfterLoadRoadStops()
(Re)building of road stop caches after loading a savegame.
Definition: station_sl.cpp:135
Last chunk in this array.
Definition: saveload.h:381
4.0 1 4.1 122 0.3.3, 0.3.4 4.2 1222 0.3.5 4.3 1417 4.4 1426
Definition: saveload.h:38
Load/save a reference to a persistent storage.
Definition: saveload.h:370
Train vehicle type.
Definition: vehicle_type.h:26