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.
(cherry picked from commit df400ef84a)
This commit is contained in:
committed by
Jonathan G Rennison
parent
05c35c8e31
commit
4280c413a6
@@ -81,6 +81,45 @@ extern btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
|
||||
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) && SlXvIsFeatureMissing(XSLFI_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];
|
||||
if (ge.data == nullptr) continue;
|
||||
auto *packets = ge.data->cargo.Packets();
|
||||
for (auto it = packets->begin(); it != 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()) {
|
||||
auto *packets = v->cargo.Packets();
|
||||
for (auto it = packets->begin(); it != packets->end(); it++) {
|
||||
if ((*it)->source_xy != INVALID_TILE) {
|
||||
(*it)->UpdateLoadingTile((*it)->source_xy);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_FULL_ASSERTS
|
||||
/* CPF_IN_VEHICLE in flags 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)->flags |= CPF_IN_VEHICLE;
|
||||
}
|
||||
}
|
||||
#endif /* WITH_FULL_ASSERTS */
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,6 +160,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_X(CargoPacket, travelled.x, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED)),
|
||||
SLE_CONDVAR_X(CargoPacket, travelled.y, SLE_INT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_CARGO_TRAVELLED)),
|
||||
|
||||
/* Used to be paid_for, but that got changed. */
|
||||
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_121),
|
||||
|
||||
@@ -206,6 +206,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
|
||||
{ XSLFI_DISASTER_VEH_STATE, XSCF_NULL, 1, 1, "slv_disaster_veh_state", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_SAVEGAME_ID, XSCF_NULL, 1, 1, "slv_savegame_id", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_NEWGRF_LAST_SERVICE, XSCF_NULL, 1, 1, "slv_newgrf_last_service", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_CARGO_TRAVELLED, XSCF_NULL, 1, 1, "slv_cargo_travelled", nullptr, nullptr, nullptr },
|
||||
{ XSLFI_NULL, XSCF_NULL, 0, 0, nullptr, nullptr, nullptr, nullptr },// This is the end marker
|
||||
};
|
||||
|
||||
|
||||
@@ -156,6 +156,7 @@ enum SlXvFeatureIndex {
|
||||
XSLFI_DISASTER_VEH_STATE, ///< See: SLV_DISASTER_VEH_STATE (PR #10798)
|
||||
XSLFI_SAVEGAME_ID, ///< See: SLV_SAVEGAME_ID (PR #10719)
|
||||
XSLFI_NEWGRF_LAST_SERVICE, ///< See: SLV_NEWGRF_LAST_SERVICE (PR #11124)
|
||||
XSLFI_CARGO_TRAVELLED, ///< See: SLV_CARGO_TRAVELLED (PR #11283)
|
||||
|
||||
XSLFI_RIFF_HEADER_60_BIT, ///< Size field in RIFF chunk header is 60 bit
|
||||
XSLFI_HEIGHT_8_BIT, ///< Map tile height is 8 bit instead of 4 bit, but savegame version may be before this became true in trunk
|
||||
|
||||
@@ -372,6 +372,7 @@ enum SaveLoadVersion : uint16 {
|
||||
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