Fix: only count distance traveled in vehicles for cargo payment (#11283)
No longer you can utilize the free (and instant) labour of station workers, transporting your cargo from one part of the station to the other. No more! Based on patch by dP.
This commit is contained in:
@@ -76,6 +76,42 @@
|
||||
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 (size_t i = 0; i < NUM_CARGO; i++) {
|
||||
GoodsEntry *ge = &st->goods[i];
|
||||
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 */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +133,8 @@ SaveLoadTable GetCargoPacketDesc()
|
||||
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;
|
||||
}
|
||||
|
@@ -360,6 +360,7 @@ enum SaveLoadVersion : uint16_t {
|
||||
SLV_PERIODS_IN_TRANSIT_RENAME, ///< 316 PR#11112 Rename days in transit to (cargo) periods in transit.
|
||||
SLV_NEWGRF_LAST_SERVICE, ///< 317 PR#11124 Added stable date_of_last_service to avoid NewGRF trouble.
|
||||
SLV_REMOVE_LOADED_AT_XY, ///< 318 PR#11276 Remove loaded_at_xy variable from CargoPacket.
|
||||
SLV_CARGO_TRAVELLED, ///< 319 PR#11283 CargoPacket now tracks how far it travelled inside a vehicle.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
|
Reference in New Issue
Block a user