diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index a6cd054bb6..617b8d6ad4 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -23,6 +23,7 @@ #include "currency.h" #include "zoom_func.h" #include "unit_conversion.h" +#include "core/math_func.hpp" #include "widgets/graph_widget.h" @@ -1847,7 +1848,7 @@ struct StationCargoGraphWindow final : BaseGraphWindow { uint offset = station->station_cargo_history_offset; for (uint j = 0; j < MAX_STATION_CARGO_HISTORY_DAYS; j++) { - this->cost[i][j] = history[offset]; + this->cost[i][j] = RXDecompressUint(history[offset]); offset++; if (offset == MAX_STATION_CARGO_HISTORY_DAYS) offset = 0; } diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index b501e5cb2e..294e222c4a 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -156,7 +156,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_WATER_FLOODING, XSCF_NULL, 2, 2, "water_flooding", nullptr, nullptr, nullptr }, { XSLFI_MORE_HOUSES, XSCF_NULL, 2, 2, "more_houses", nullptr, nullptr, nullptr }, { XSLFI_CUSTOM_TOWN_ZONE, XSCF_IGNORABLE_UNKNOWN, 1, 1, "custom_town_zone", nullptr, nullptr, nullptr }, - { XSLFI_STATION_CARGO_HISTORY, XSCF_NULL, 1, 1, "station_cargo_history", nullptr, nullptr, nullptr }, + { XSLFI_STATION_CARGO_HISTORY, XSCF_NULL, 2, 2, "station_cargo_history", nullptr, nullptr, nullptr }, { XSLFI_TRAIN_SPEED_ADAPTATION, XSCF_NULL, 2, 2, "train_speed_adaptation", nullptr, nullptr, "TSAS" }, { XSLFI_EXTRA_STATION_NAMES, XSCF_NULL, 1, 1, "extra_station_names", nullptr, nullptr, nullptr }, { XSLFI_DEPOT_ORDER_EXTRA_FLAGS,XSCF_IGNORABLE_UNKNOWN, 1, 1, "depot_order_extra_flags", nullptr, nullptr, nullptr }, diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 12d74da133..dbbdf70ba8 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -14,6 +14,7 @@ #include "../vehicle_base.h" #include "../newgrf_station.h" #include "../newgrf_roadstop.h" +#include "../core/math_func.hpp" #include "saveload.h" #include "saveload_buffer.h" @@ -680,6 +681,13 @@ static void Load_STNN() amount = buffer->RawReadUint16(); } } + if (SlXvIsFeaturePresent(XSLFI_STATION_CARGO_HISTORY, 1, 1)) { + for (auto &history : st->station_cargo_history) { + for (uint16 &amount : history) { + amount = RXCompressUint(amount); + } + } + } st->station_cargo_history_offset = 0; } diff --git a/src/station_base.h b/src/station_base.h index b1c5412713..8725913818 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -839,7 +839,7 @@ public: CargoTypes station_cargo_history_cargoes; ///< Bitmask of cargoes in station_cargo_history uint8 station_cargo_history_offset; ///< Start offset in station_cargo_history cargo ring buffer - std::vector> station_cargo_history; ///< Station history of waiting cargo. + std::vector> station_cargo_history; ///< Station history of waiting cargo, dynamic range compressed (see RXCompressUint) Station(TileIndex tile = INVALID_TILE); ~Station(); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index fc4ce1ee04..de9c192c9a 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -59,6 +59,7 @@ #include "tunnelbridge_map.h" #include "cheat_type.h" #include "newgrf_roadstop.h" +#include "core/math_func.hpp" #include "table/strings.h" @@ -475,7 +476,7 @@ void Station::UpdateCargoHistory() this->station_cargo_history.emplace(this->station_cargo_history.begin() + storage_offset); } } - this->station_cargo_history[storage_offset][this->station_cargo_history_offset] = static_cast(std::clamp(amount, (uint)0, (uint)UINT16_MAX)); + this->station_cargo_history[storage_offset][this->station_cargo_history_offset] = RXCompressUint(amount); storage_offset++; } this->station_cargo_history_offset++;