Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "../vehicle_base.h"
00014 #include "../station_base.h"
00015
00016 #include "saveload.h"
00017
00021 void CargoPacket::AfterLoad()
00022 {
00023 if (IsSavegameVersionBefore(44)) {
00024 Vehicle *v;
00025
00026
00027
00028
00029
00030
00031 FOR_ALL_VEHICLES(v) {
00032 const VehicleCargoList::List *packets = v->cargo.Packets();
00033 for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
00034 CargoPacket *cp = *it;
00035 cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
00036 cp->loaded_at_xy = cp->source_xy;
00037 }
00038 }
00039
00040
00041
00042
00043
00044
00045 Station *st;
00046 FOR_ALL_STATIONS(st) {
00047 for (CargoID c = 0; c < NUM_CARGO; c++) {
00048 GoodsEntry *ge = &st->goods[c];
00049
00050 const StationCargoList::List *packets = ge->cargo.Packets();
00051 for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
00052 CargoPacket *cp = *it;
00053 cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
00054 cp->loaded_at_xy = cp->source_xy;
00055 }
00056 }
00057 }
00058 }
00059
00060 if (IsSavegameVersionBefore(120)) {
00061
00062 CargoPacket *cp;
00063 FOR_ALL_CARGOPACKETS(cp) {
00064 if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
00065 }
00066 }
00067
00068 if (!IsSavegameVersionBefore(68)) {
00069
00070
00071
00072 Vehicle *v;
00073 FOR_ALL_VEHICLES(v) v->cargo.InvalidateCache();
00074
00075 Station *st;
00076 FOR_ALL_STATIONS(st) {
00077 for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
00078 }
00079 }
00080 }
00081
00087 const SaveLoad *GetCargoPacketDesc()
00088 {
00089 static const SaveLoad _cargopacket_desc[] = {
00090 SLE_VAR(CargoPacket, source, SLE_UINT16),
00091 SLE_VAR(CargoPacket, source_xy, SLE_UINT32),
00092 SLE_VAR(CargoPacket, loaded_at_xy, SLE_UINT32),
00093 SLE_VAR(CargoPacket, count, SLE_UINT16),
00094 SLE_VAR(CargoPacket, days_in_transit, SLE_UINT8),
00095 SLE_VAR(CargoPacket, feeder_share, SLE_INT64),
00096 SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, 125, SL_MAX_VERSION),
00097 SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, 125, SL_MAX_VERSION),
00098
00099
00100 SLE_CONDNULL(1, 0, 120),
00101
00102 SLE_END()
00103 };
00104 return _cargopacket_desc;
00105 }
00106
00110 static void Save_CAPA()
00111 {
00112 CargoPacket *cp;
00113
00114 FOR_ALL_CARGOPACKETS(cp) {
00115 SlSetArrayIndex(cp->index);
00116 SlObject(cp, GetCargoPacketDesc());
00117 }
00118 }
00119
00123 static void Load_CAPA()
00124 {
00125 int index;
00126
00127 while ((index = SlIterateArray()) != -1) {
00128 CargoPacket *cp = new (index) CargoPacket();
00129 SlObject(cp, GetCargoPacketDesc());
00130 }
00131 }
00132
00134 extern const ChunkHandler _cargopacket_chunk_handlers[] = {
00135 { 'CAPA', Save_CAPA, Load_CAPA, NULL, NULL, CH_ARRAY | CH_LAST},
00136 };