From 777151c34dedca854794727b61de92a774cd6948 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 1 Jun 2018 19:12:53 +0100 Subject: [PATCH] Station rating: Track last visited vehicle type separately per-cargo --- src/economy.cpp | 2 +- src/saveload/afterload.cpp | 4 +++- src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/saveload/station_sl.cpp | 9 +++++++-- src/station.cpp | 3 +-- src/station_base.h | 4 +++- src/station_cmd.cpp | 4 ++-- 8 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/economy.cpp b/src/economy.cpp index 7030ab81ba..046e21c4a2 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1928,7 +1928,7 @@ static void LoadUnloadVehicle(Vehicle *front) anything_loaded = true; st->time_since_load = 0; - st->last_vehicle_type = v->type; + ge->last_vehicle_type = v->type; if (ge->cargo.TotalCount() == 0) { TriggerStationRandomisation(st, st->xy, SRT_CARGO_TAKEN, v->cargo_type); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 0ab9a5bfac..ceefd9ad36 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1480,7 +1480,9 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(26)) { Station *st; FOR_ALL_STATIONS(st) { - st->last_vehicle_type = VEH_INVALID; + for (CargoID c = 0; c < NUM_CARGO; c++) { + st->goods[c].last_vehicle_type = VEH_INVALID; + } } } diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 0cd5885ed8..f80736119e 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -85,6 +85,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_TRAIN_THROUGH_LOAD, XSCF_NULL, 1, 1, "train_through_load", NULL, NULL, NULL }, { XSLFI_ORDER_EXTRA_DATA, XSCF_NULL, 1, 1, "order_extra_data", NULL, NULL, NULL }, { XSLFI_WHOLE_MAP_CHUNK, XSCF_NULL, 1, 1, "whole_map_chunk", NULL, NULL, "WMAP" }, + { XSLFI_ST_LAST_VEH_TYPE, XSCF_NULL, 1, 1, "station_last_veh_type", NULL, NULL, NULL }, { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker }; diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index cf5afa2b5a..f0304442c2 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -59,6 +59,7 @@ enum SlXvFeatureIndex { XSLFI_TRAIN_THROUGH_LOAD, ///< Train through load/unload XSLFI_ORDER_EXTRA_DATA, ///< Order extra data field(s) XSLFI_WHOLE_MAP_CHUNK, ///< Whole map chunk + XSLFI_ST_LAST_VEH_TYPE, ///< Per-cargo station last vehicle type 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 diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 1cee1f26ab..6fee7d5809 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -23,6 +23,8 @@ #include "../safeguards.h" +static byte _old_last_vehicle_type; + /** * Update the buoy orders to be waypoint orders. * @param o the order 'list' to check. @@ -219,7 +221,7 @@ static const SaveLoad _old_station_desc[] = { SLE_CONDVAR(Station, airport.flags, SLE_UINT64, 46, SL_MAX_VERSION), SLE_CONDNULL(2, 0, 25), ///< last-vehicle - SLE_CONDVAR(Station, last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION), + SLEG_CONDVAR_X(_old_last_vehicle_type, SLE_UINT8, 26, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ST_LAST_VEH_TYPE, 0, 0)), SLE_CONDNULL(2, 3, 25), ///< custom station class and id SLE_CONDVAR(Station, build_date, SLE_FILE_U16 | SLE_VAR_I32, 3, 30), @@ -306,6 +308,7 @@ const SaveLoad *GetGoodsDesc() SLE_CONDVAR(GoodsEntry, node, SLE_UINT16, 183, SL_MAX_VERSION), SLEG_CONDVAR( _num_flows, SLE_UINT32, 183, SL_MAX_VERSION), SLE_CONDVAR(GoodsEntry, max_waiting_cargo, SLE_UINT32, 183, SL_MAX_VERSION), + SLE_CONDVAR_X(GoodsEntry, last_vehicle_type, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ST_LAST_VEH_TYPE, 1)), SLE_END() }; @@ -379,6 +382,7 @@ static void Load_STNS() SB(ge->status, GoodsEntry::GES_RATING, 1, 1); } } + if (SlXvIsFeatureMissing(XSLFI_ST_LAST_VEH_TYPE)) ge->last_vehicle_type = _old_last_vehicle_type; } if (st->num_specs != 0) { @@ -460,7 +464,7 @@ static const SaveLoad _station_desc[] = { SLE_VAR(Station, time_since_load, SLE_UINT8), SLE_VAR(Station, time_since_unload, SLE_UINT8), - SLE_VAR(Station, last_vehicle_type, SLE_UINT8), + SLEG_CONDVAR_X(_old_last_vehicle_type, SLE_UINT8, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ST_LAST_VEH_TYPE, 0, 0)), SLE_VAR(Station, had_vehicle_of_type, SLE_UINT8), SLE_VEC(Station, loading_vehicles, REF_VEHICLE), SLE_CONDVAR(Station, always_accepted, SLE_UINT32, 127, SL_MAX_VERSION), @@ -601,6 +605,7 @@ static void Load_STNN() assert(pair.second.empty()); } } + if (SlXvIsFeatureMissing(XSLFI_ST_LAST_VEH_TYPE)) st->goods[i].last_vehicle_type = _old_last_vehicle_type; } } diff --git a/src/station.cpp b/src/station.cpp index 9b1a2e0004..bf04764f17 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -60,8 +60,7 @@ Station::Station(TileIndex tile) : dock_station(INVALID_TILE, 0, 0), indtype(IT_INVALID), time_since_load(255), - time_since_unload(255), - last_vehicle_type(VEH_INVALID) + time_since_unload(255) { /* this->random_bits is set in Station::AddFacility() */ } diff --git a/src/station_base.h b/src/station_base.h index 9602e8b3bd..4eef69dea2 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -216,6 +216,7 @@ struct GoodsEntry { GoodsEntry() : status(0), time_since_pickup(255), + last_vehicle_type(VEH_INVALID), rating(INITIAL_STATION_RATING), last_speed(0), last_age(255), @@ -234,6 +235,8 @@ struct GoodsEntry { */ byte time_since_pickup; + byte last_vehicle_type; + byte rating; ///< %Station rating for this cargo. /** @@ -470,7 +473,6 @@ public: byte time_since_load; byte time_since_unload; - byte last_vehicle_type; std::vector loading_vehicles; GoodsEntry goods[NUM_CARGO]; ///< Goods at this station CargoTypes always_accepted; ///< Bitmask of always accepted cargo types (by houses, HQs, industry tiles when industry doesn't accept cargo) diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 951806c0c3..83198031e9 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3485,7 +3485,7 @@ static void UpdateStationRating(Station *st) uint32 var18 = min(ge->time_since_pickup, 0xFF) | (min(ge->max_waiting_cargo, 0xFFFF) << 8) | (min(last_speed, 0xFF) << 24); /* Convert to the 'old' vehicle types */ - uint32 var10 = (st->last_vehicle_type == VEH_INVALID) ? 0x0 : (st->last_vehicle_type + 0x10); + uint32 var10 = (ge->last_vehicle_type == VEH_INVALID) ? 0x0 : (ge->last_vehicle_type + 0x10); uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, cs); if (callback != CALLBACK_FAILED) { skip = true; @@ -3501,7 +3501,7 @@ static void UpdateStationRating(Station *st) if (b >= 0) rating += b >> 2; byte waittime = ge->time_since_pickup; - if (st->last_vehicle_type == VEH_SHIP) waittime >>= 2; + if (ge->last_vehicle_type == VEH_SHIP) waittime >>= 2; (waittime > 21) || (rating += 25, waittime > 12) || (rating += 25, waittime > 6) ||