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
00018 void CargoPacket::AfterLoad()
00019 {
00020 if (IsSavegameVersionBefore(44)) {
00021 Vehicle *v;
00022
00023
00024
00025
00026
00027
00028 FOR_ALL_VEHICLES(v) {
00029 const VehicleCargoList::List *packets = v->cargo.Packets();
00030 for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
00031 CargoPacket *cp = *it;
00032 cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : v->tile;
00033 cp->loaded_at_xy = cp->source_xy;
00034 }
00035 }
00036
00037
00038
00039
00040
00041
00042 Station *st;
00043 FOR_ALL_STATIONS(st) {
00044 for (CargoID c = 0; c < NUM_CARGO; c++) {
00045 GoodsEntry *ge = &st->goods[c];
00046
00047 const StationCargoList::List *packets = ge->cargo.Packets();
00048 for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
00049 CargoPacket *cp = *it;
00050 cp->source_xy = Station::IsValidID(cp->source) ? Station::Get(cp->source)->xy : st->xy;
00051 cp->loaded_at_xy = cp->source_xy;
00052 }
00053 }
00054 }
00055 }
00056
00057 if (IsSavegameVersionBefore(120)) {
00058
00059 CargoPacket *cp;
00060 FOR_ALL_CARGOPACKETS(cp) {
00061 if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
00062 }
00063 }
00064
00065 if (!IsSavegameVersionBefore(68)) {
00066
00067
00068
00069 Vehicle *v;
00070 FOR_ALL_VEHICLES(v) v->cargo.InvalidateCache();
00071
00072 Station *st;
00073 FOR_ALL_STATIONS(st) {
00074 for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
00075 }
00076 }
00077 }
00078
00084 const SaveLoad *GetCargoPacketDesc()
00085 {
00086 static const SaveLoad _cargopacket_desc[] = {
00087 SLE_VAR(CargoPacket, source, SLE_UINT16),
00088 SLE_VAR(CargoPacket, source_xy, SLE_UINT32),
00089 SLE_VAR(CargoPacket, loaded_at_xy, SLE_UINT32),
00090 SLE_VAR(CargoPacket, count, SLE_UINT16),
00091 SLE_VAR(CargoPacket, days_in_transit, SLE_UINT8),
00092 SLE_VAR(CargoPacket, feeder_share, SLE_INT64),
00093 SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, 125, SL_MAX_VERSION),
00094 SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, 125, SL_MAX_VERSION),
00095
00096
00097 SLE_CONDNULL(1, 0, 120),
00098
00099 SLE_END()
00100 };
00101 return _cargopacket_desc;
00102 }
00103
00104 static void Save_CAPA()
00105 {
00106 CargoPacket *cp;
00107
00108 FOR_ALL_CARGOPACKETS(cp) {
00109 SlSetArrayIndex(cp->index);
00110 SlObject(cp, GetCargoPacketDesc());
00111 }
00112 }
00113
00114 static void Load_CAPA()
00115 {
00116 int index;
00117
00118 while ((index = SlIterateArray()) != -1) {
00119 CargoPacket *cp = new (index) CargoPacket();
00120 SlObject(cp, GetCargoPacketDesc());
00121 }
00122 }
00123
00124 extern const ChunkHandler _cargopacket_chunk_handlers[] = {
00125 { 'CAPA', Save_CAPA, Load_CAPA, NULL, NULL, CH_ARRAY | CH_LAST},
00126 };