Files
@ r28035:f86971abe639
Branch filter:
Location: cpp/openttd-patchpack/source/src/saveload/cargopacket_sl.cpp - annotation
r28035:f86971abe639
6.7 KiB
text/x-c
Update: Translations from eints
english (au): 3 changes by krysclarke
russian: 3 changes by Ln-Wolf
finnish: 3 changes by hpiirai
turkish: 4 changes by BeratSJ
french: 3 changes by ottdfevr
portuguese: 3 changes by azulcosta
portuguese (brazilian): 3 changes by pasantoro
english (au): 3 changes by krysclarke
russian: 3 changes by Ln-Wolf
finnish: 3 changes by hpiirai
turkish: 4 changes by BeratSJ
french: 3 changes by ottdfevr
portuguese: 3 changes by azulcosta
portuguese (brazilian): 3 changes by pasantoro
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r10571:99cb9a95b4cf r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25752:2d6c2238f03d r25752:2d6c2238f03d r25752:2d6c2238f03d r25752:2d6c2238f03d r13287:52547c48c3ba r13287:52547c48c3ba r10571:99cb9a95b4cf r21383:942c32fb8b0e r21383:942c32fb8b0e r17625:366001a31c88 r17625:366001a31c88 r17625:366001a31c88 r13287:52547c48c3ba r13287:52547c48c3ba r23264:b36243874b4a r19944:25a78576fb5e r13444:93a257b9ec0b r13444:93a257b9ec0b r13444:93a257b9ec0b r13444:93a257b9ec0b r13444:93a257b9ec0b r23966:9de0a0960701 r20348:d6fd0cf0c673 r13294:1c7a8cd8e77d r13287:52547c48c3ba r27882:e0b47acdb939 r13287:52547c48c3ba r13287:52547c48c3ba r13287:52547c48c3ba r13287:52547c48c3ba r13444:93a257b9ec0b r13444:93a257b9ec0b r13444:93a257b9ec0b r13444:93a257b9ec0b r23954:8e43140b9a66 r28001:3cbf0e1a68f8 r28001:3cbf0e1a68f8 r13294:1c7a8cd8e77d r13287:52547c48c3ba r27882:e0b47acdb939 r13287:52547c48c3ba r13287:52547c48c3ba r13287:52547c48c3ba r13287:52547c48c3ba r13287:52547c48c3ba r23264:b36243874b4a r13287:52547c48c3ba r23956:102d2d7daf23 r27882:e0b47acdb939 r13287:52547c48c3ba r13287:52547c48c3ba r13297:221c8d555eb9 r23264:b36243874b4a r13297:221c8d555eb9 r13297:221c8d555eb9 r13297:221c8d555eb9 r23966:9de0a0960701 r13297:221c8d555eb9 r23954:8e43140b9a66 r28001:3cbf0e1a68f8 r13297:221c8d555eb9 r13297:221c8d555eb9 r20054:152d076eb07b r23264:b36243874b4a r23966:9de0a0960701 r20054:152d076eb07b r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r28001:3cbf0e1a68f8 r28001:3cbf0e1a68f8 r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r27941:fbe336fa8b4e r13287:52547c48c3ba r13287:52547c48c3ba r13203:2e49af5aeba4 r13203:2e49af5aeba4 r13203:2e49af5aeba4 r13203:2e49af5aeba4 r13203:2e49af5aeba4 r25585:53810459092f r13203:2e49af5aeba4 r13203:2e49af5aeba4 r27882:e0b47acdb939 r27064:9235bbc2bec8 r27893:8c85dc228529 r27893:8c85dc228529 r27064:9235bbc2bec8 r27717:8f7c1d75f921 r27717:8f7c1d75f921 r27717:8f7c1d75f921 r27064:9235bbc2bec8 r27064:9235bbc2bec8 r27064:9235bbc2bec8 r27941:fbe336fa8b4e r27941:fbe336fa8b4e r13203:2e49af5aeba4 r13203:2e49af5aeba4 r13203:2e49af5aeba4 r10571:99cb9a95b4cf r25773:457e167f3c9e r25773:457e167f3c9e r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r10571:99cb9a95b4cf r10571:99cb9a95b4cf r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25752:2d6c2238f03d r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r25773:457e167f3c9e r10571:99cb9a95b4cf r25773:457e167f3c9e r25772:5ba83ce3a853 r25772:5ba83ce3a853 r10571:99cb9a95b4cf r25596:7bf7822e5659 r25596:7bf7822e5659 | /*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file cargopacket_sl.cpp Code handling saving and loading of cargo packets */
#include "../stdafx.h"
#include "saveload.h"
#include "compat/cargopacket_sl_compat.h"
#include "../vehicle_base.h"
#include "../station_base.h"
#include "../safeguards.h"
/**
* Savegame conversion for cargopackets.
*/
/* static */ void CargoPacket::AfterLoad()
{
if (IsSavegameVersionBefore(SLV_44)) {
/* If we remove a station while cargo from it is still en route, payment calculation will assume
* 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
* stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
* where this situation exists, the cargo-source information is lost. in this case, we set the source
* to the current tile of the vehicle to prevent excessive profits
*/
for (const Vehicle *v : Vehicle::Iterate()) {
const CargoPacketList *packets = v->cargo.Packets();
for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
CargoPacket *cp = *it;
cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : v->tile;
}
}
/* Store position of the station where the goods come from, so there
* are no very high payments when stations get removed. However, if the
* station where the goods came from is already removed, the source
* information is lost. In that case we set it to the position of this
* station */
for (Station *st : Station::Iterate()) {
for (GoodsEntry &ge : st->goods) {
const StationCargoPacketMap *packets = ge.cargo.Packets();
for (StationCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) {
CargoPacket *cp = *it;
cp->source_xy = Station::IsValidID(cp->first_station) ? Station::Get(cp->first_station)->xy : st->xy;
}
}
}
}
if (IsSavegameVersionBefore(SLV_120)) {
/* CargoPacket's source should be either INVALID_STATION or a valid station */
for (CargoPacket *cp : CargoPacket::Iterate()) {
if (!Station::IsValidID(cp->first_station)) cp->first_station = INVALID_STATION;
}
}
if (!IsSavegameVersionBefore(SLV_68)) {
/* Only since version 68 we have cargo packets. Savegames from before used
* 'new CargoPacket' + cargolist.Append so their caches are already
* correct and do not need rebuilding. */
for (Vehicle *v : Vehicle::Iterate()) v->cargo.InvalidateCache();
for (Station *st : Station::Iterate()) {
for (GoodsEntry &ge : st->goods) ge.cargo.InvalidateCache();
}
}
if (IsSavegameVersionBefore(SLV_181)) {
for (Vehicle *v : Vehicle::Iterate()) v->cargo.KeepAll();
}
/* Before this version, we didn't track how far cargo actually traveled in vehicles. Make best-effort estimates of this. */
if (IsSavegameVersionBefore(SLV_CARGO_TRAVELLED)) {
/* Update the cargo-traveled in stations as if they arrived from the source tile. */
for (Station *st : Station::Iterate()) {
for (GoodsEntry &ge : st->goods) {
for (auto it = ge.cargo.Packets()->begin(); it != ge.cargo.Packets()->end(); ++it) {
for (CargoPacket *cp : it->second) {
if (cp->source_xy != INVALID_TILE && cp->source_xy != st->xy) {
cp->travelled.x = TileX(cp->source_xy) - TileX(st->xy);
cp->travelled.y = TileY(cp->source_xy) - TileY(st->xy);
}
}
}
}
}
/* Update the cargo-traveled in vehicles as if they were loaded at the source tile. */
for (Vehicle *v : Vehicle::Iterate()) {
for (auto it = v->cargo.Packets()->begin(); it != v->cargo.Packets()->end(); it++) {
if ((*it)->source_xy != INVALID_TILE) {
(*it)->UpdateLoadingTile((*it)->source_xy);
}
}
}
}
#ifdef WITH_ASSERT
/* in_vehicle is a NOSAVE; it tells if cargo is in a vehicle or not. Restore the value in here. */
for (Vehicle *v : Vehicle::Iterate()) {
for (auto it = v->cargo.Packets()->begin(); it != v->cargo.Packets()->end(); it++) {
(*it)->in_vehicle = true;
}
}
#endif /* WITH_ASSERT */
}
/**
* Wrapper function to get the CargoPacket's internal structure while
* some of the variables itself are private.
* @return the saveload description for CargoPackets.
*/
SaveLoadTable GetCargoPacketDesc()
{
static const SaveLoad _cargopacket_desc[] = {
SLE_VARNAME(CargoPacket, first_station, "source", SLE_UINT16),
SLE_VAR(CargoPacket, source_xy, SLE_UINT32),
SLE_CONDVARNAME(CargoPacket, next_hop, "loaded_at_xy", SLE_FILE_U32 | SLE_VAR_U16, SL_MIN_VERSION, SLV_REMOVE_LOADED_AT_XY),
SLE_CONDVARNAME(CargoPacket, next_hop, "loaded_at_xy", SLE_UINT16, SLV_REMOVE_LOADED_AT_XY, SL_MAX_VERSION),
SLE_VAR(CargoPacket, count, SLE_UINT16),
SLE_CONDVARNAME(CargoPacket, periods_in_transit, "days_in_transit", SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_MORE_CARGO_AGE),
SLE_CONDVARNAME(CargoPacket, periods_in_transit, "days_in_transit", SLE_UINT16, SLV_MORE_CARGO_AGE, SLV_PERIODS_IN_TRANSIT_RENAME),
SLE_CONDVAR(CargoPacket, periods_in_transit, SLE_UINT16, SLV_PERIODS_IN_TRANSIT_RENAME, SL_MAX_VERSION),
SLE_VAR(CargoPacket, feeder_share, SLE_INT64),
SLE_CONDVAR(CargoPacket, source_type, SLE_UINT8, SLV_125, SL_MAX_VERSION),
SLE_CONDVAR(CargoPacket, source_id, SLE_UINT16, SLV_125, SL_MAX_VERSION),
SLE_CONDVAR(CargoPacket, travelled.x, SLE_INT16, SLV_CARGO_TRAVELLED, SL_MAX_VERSION),
SLE_CONDVAR(CargoPacket, travelled.y, SLE_INT16, SLV_CARGO_TRAVELLED, SL_MAX_VERSION),
};
return _cargopacket_desc;
}
struct CAPAChunkHandler : ChunkHandler {
CAPAChunkHandler() : ChunkHandler('CAPA', CH_TABLE) {}
void Save() const override
{
SlTableHeader(GetCargoPacketDesc());
for (CargoPacket *cp : CargoPacket::Iterate()) {
SlSetArrayIndex(cp->index);
SlObject(cp, GetCargoPacketDesc());
}
}
void Load() const override
{
const std::vector<SaveLoad> slt = SlCompatTableHeader(GetCargoPacketDesc(), _cargopacket_sl_compat);
int index;
while ((index = SlIterateArray()) != -1) {
CargoPacket *cp = new (index) CargoPacket();
SlObject(cp, slt);
}
}
};
static const CAPAChunkHandler CAPA;
static const ChunkHandlerRef cargopacket_chunk_handlers[] = {
CAPA,
};
extern const ChunkHandlerTable _cargopacket_chunk_handlers(cargopacket_chunk_handlers);
|