From 71be17729ea5a31ff755c3c09cebe2646d9c5ecc Mon Sep 17 00:00:00 2001 From: patch-import Date: Fri, 1 Jan 2016 13:35:26 +0000 Subject: [PATCH 1/4] Import vehicle lifetime profit patch v3 http://www.tt-forums.net/viewtopic.php?p=1161735#p1161735 --- src/lang/english.txt | 3 ++- src/saveload/afterload.cpp | 6 ++++++ src/saveload/saveload.cpp | 2 +- src/saveload/vehicle_sl.cpp | 1 + src/vehicle.cpp | 1 + src/vehicle_base.h | 7 +++++++ src/vehicle_gui.cpp | 11 +++++++++++ 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 0bd430bad0..62a7efa0f5 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -286,6 +286,7 @@ STR_SORT_BY_TRANSPORTED :Transported STR_SORT_BY_NUMBER :Number STR_SORT_BY_PROFIT_LAST_YEAR :Profit last year STR_SORT_BY_PROFIT_THIS_YEAR :Profit this year +STR_SORT_BY_PROFIT_LIFETIME :Lifetime profit STR_SORT_BY_AGE :Age STR_SORT_BY_RELIABILITY :Reliability STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE :Total capacity per cargo type @@ -3657,7 +3658,7 @@ STR_VEHICLE_INFO_MAX_SPEED_RANGE :{BLACK}Max. spe STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} {BLACK}Max. T.E.: {LTBLUE}{FORCE} -STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG}) +STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG}) (lifetime: {CURRENCY_LONG}) STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Reliability: {LTBLUE}{COMMA}% {BLACK}Breakdowns since last service: {LTBLUE}{COMMA} STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG} diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 9690481154..318400c80c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2975,6 +2975,12 @@ bool AfterLoadGame() FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false); } + /* Set lifetime vehicle profit to 0 if save game before 195 */ + if (IsSavegameVersionBefore(195)) { + Vehicle *v; + FOR_ALL_VEHICLES(v) v->profit_lifetime = 0; + } + /* Road stops is 'only' updating some caches */ AfterLoadRoadStops(); AfterLoadLabelMaps(); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index bd3c83d139..bcbe0f0c7f 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -263,7 +263,7 @@ * 193 26802 * 194 26881 1.5.x */ -extern const uint16 SAVEGAME_VERSION = 194; ///< Current savegame version of OpenTTD. +extern const uint16 SAVEGAME_VERSION = 195; ///< Current savegame version of OpenTTD. SavegameType _savegame_type; ///< type of savegame we are loading diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index ebc5fc4215..2cbb96d0b0 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -683,6 +683,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt) SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, 65, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, 65, SL_MAX_VERSION), + SLE_CONDVAR(Vehicle, profit_lifetime, SLE_INT64, 195, SL_MAX_VERSION), SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, 51, 64), SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, 51, 67), diff --git a/src/vehicle.cpp b/src/vehicle.cpp index a482520f25..15da4cc856 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2657,6 +2657,7 @@ void VehiclesYearlyLoop() } v->profit_last_year = v->profit_this_year; + v->profit_lifetime += v->profit_this_year; v->profit_this_year = 0; SetWindowDirty(WC_VEHICLE_DETAILS, v->index); } diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 59584da788..d55fa76f2d 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -180,6 +180,7 @@ public: Money profit_this_year; ///< Profit this year << 8, low 8 bits are fract Money profit_last_year; ///< Profit last year << 8, low 8 bits are fract + Money profit_lifetime; ///< Profit lifetime << 8, low 8 bits are fract Money value; ///< Value of the vehicle CargoPayment *cargo_payment; ///< The cargo payment we're currently in @@ -513,6 +514,12 @@ public: */ Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); } + /** + * Gets the lifetime profit of vehicle. It can be sent into SetDParam for string processing. + * @return the vehicle's lifetime profit + */ + Money GetDisplayProfitLifetime() const { return (this->profit_lifetime >> 8); } + void SetNext(Vehicle *next); /** diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 10f1d952da..b9a9a4c131 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -48,6 +48,7 @@ static GUIVehicleList::SortFunction VehicleNumberSorter; static GUIVehicleList::SortFunction VehicleNameSorter; static GUIVehicleList::SortFunction VehicleAgeSorter; static GUIVehicleList::SortFunction VehicleProfitThisYearSorter; +static GUIVehicleList::SortFunction VehicleProfitLifetimeSorter; static GUIVehicleList::SortFunction VehicleProfitLastYearSorter; static GUIVehicleList::SortFunction VehicleCargoSorter; static GUIVehicleList::SortFunction VehicleReliabilitySorter; @@ -64,6 +65,7 @@ GUIVehicleList::SortFunction * const BaseVehicleListWindow::vehicle_sorter_funcs &VehicleAgeSorter, &VehicleProfitThisYearSorter, &VehicleProfitLastYearSorter, + &VehicleProfitLifetimeSorter, &VehicleCargoSorter, &VehicleReliabilitySorter, &VehicleMaxSpeedSorter, @@ -80,6 +82,7 @@ const StringID BaseVehicleListWindow::vehicle_sorter_names[] = { STR_SORT_BY_AGE, STR_SORT_BY_PROFIT_THIS_YEAR, STR_SORT_BY_PROFIT_LAST_YEAR, + STR_SORT_BY_PROFIT_LIFETIME, STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE, STR_SORT_BY_RELIABILITY, STR_SORT_BY_MAX_SPEED, @@ -1132,6 +1135,13 @@ static int CDECL VehicleProfitLastYearSorter(const Vehicle * const *a, const Veh return (r != 0) ? r : VehicleNumberSorter(a, b); } +/** Sort vehicles by lifetime profit */ +static int CDECL VehicleProfitLifetimeSorter(const Vehicle * const *a, const Vehicle * const *b) +{ + int r = ClampToI32((*a)->GetDisplayProfitLifetime() - (*b)->GetDisplayProfitLifetime()); + return (r != 0) ? r : VehicleNumberSorter(a, b); +} + /** Sort vehicles by their cargo */ static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * const *b) { @@ -2082,6 +2092,7 @@ struct VehicleDetailsWindow : Window { /* Draw profit */ SetDParam(0, v->GetDisplayProfitThisYear()); SetDParam(1, v->GetDisplayProfitLastYear()); + SetDParam(2, v->GetDisplayProfitLifetime()); DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); y += FONT_HEIGHT_NORMAL; From e6afc6f0489e4865172fe92e7b3ce685b3cc6e41 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 1 Jan 2016 13:37:43 +0000 Subject: [PATCH 2/4] Display current lifetime profit, instead of the yearly-updated value. --- src/vehicle_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vehicle_base.h b/src/vehicle_base.h index d55fa76f2d..55966e49c3 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -518,7 +518,7 @@ public: * Gets the lifetime profit of vehicle. It can be sent into SetDParam for string processing. * @return the vehicle's lifetime profit */ - Money GetDisplayProfitLifetime() const { return (this->profit_lifetime >> 8); } + Money GetDisplayProfitLifetime() const { return ((this->profit_lifetime + this->profit_this_year) >> 8); } void SetNext(Vehicle *next); From 179e6df8001186cf8986a4c2504f00bd8636b44f Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 1 Jan 2016 14:46:21 +0000 Subject: [PATCH 3/4] Change lifetime profit display string to avoid breaking translations. --- src/lang/english.txt | 3 ++- src/vehicle_gui.cpp | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 62a7efa0f5..538e6cf600 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3658,7 +3658,8 @@ STR_VEHICLE_INFO_MAX_SPEED_RANGE :{BLACK}Max. spe STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE :{BLACK}Weight: {LTBLUE}{WEIGHT_SHORT} {BLACK}Power: {LTBLUE}{POWER}{BLACK} Max. speed: {LTBLUE}{VELOCITY} {BLACK}Max. T.E.: {LTBLUE}{FORCE} -STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG}) (lifetime: {CURRENCY_LONG}) +STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG}) +STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME :{STRING2} (lifetime: {CURRENCY_LONG}) STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS :{BLACK}Reliability: {LTBLUE}{COMMA}% {BLACK}Breakdowns since last service: {LTBLUE}{COMMA} STR_VEHICLE_INFO_BUILT_VALUE :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG} diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index b9a9a4c131..9b163899ef 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1949,12 +1949,14 @@ struct VehicleDetailsWindow : Window { STR_VEHICLE_INFO_MAX_SPEED, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE, - STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR, STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS }; for (uint i = 0; i < lengthof(info_strings); i++) { dim = maxdim(dim, GetStringBoundingBox(info_strings[i])); } + SetDParam(0, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + for (uint i = 1; i < 4; i++) SetDParamMaxValue(i, 1 << 24); + dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME)); SetDParam(0, STR_VEHICLE_INFO_AGE); dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_AGE_RUNNING_COST_YR)); size->width = dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT; @@ -2090,10 +2092,11 @@ struct VehicleDetailsWindow : Window { y += FONT_HEIGHT_NORMAL; /* Draw profit */ - SetDParam(0, v->GetDisplayProfitThisYear()); - SetDParam(1, v->GetDisplayProfitLastYear()); - SetDParam(2, v->GetDisplayProfitLifetime()); - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + SetDParam(0, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR); + SetDParam(1, v->GetDisplayProfitThisYear()); + SetDParam(2, v->GetDisplayProfitLastYear()); + SetDParam(3, v->GetDisplayProfitLifetime()); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME); y += FONT_HEIGHT_NORMAL; /* Draw breakdown & reliability */ From 07d24962cd02a618ff8bee6315654cc08d487da3 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Fri, 1 Jan 2016 14:35:27 +0000 Subject: [PATCH 4/4] Save/load changes for veh lifetime profit patch. --- src/saveload/afterload.cpp | 4 ++-- src/saveload/extended_ver_sl.cpp | 1 + src/saveload/extended_ver_sl.h | 1 + src/saveload/vehicle_sl.cpp | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 318400c80c..3d880f9e5b 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2975,8 +2975,8 @@ bool AfterLoadGame() FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false); } - /* Set lifetime vehicle profit to 0 if save game before 195 */ - if (IsSavegameVersionBefore(195)) { + /* Set lifetime vehicle profit to 0 if lifetime profit feature is missing */ + if (SlXvIsFeatureMissing(XSLFI_VEH_LIFETIME_PROFIT)) { Vehicle *v; FOR_ALL_VEHICLES(v) v->profit_lifetime = 0; } diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 6e13994e67..32407431d8 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -45,6 +45,7 @@ std::vector _sl_xv_discardable_chunk_ids; ///< list of chunks static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { + { XSLFI_VEH_LIFETIME_PROFIT, XSCF_NULL, 1, 1, "veh_lifetime_profit", 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 39a03478c2..c4f114a6df 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -21,6 +21,7 @@ */ enum SlXvFeatureIndex { XSLFI_NULL = 0, ///< Unused value, to indicate that no extended feature test is in use + XSLFI_VEH_LIFETIME_PROFIT, ///< Vehicle lifetime profit patch XSLFI_SIZE, ///< Total count of features, including null feature }; diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 2cbb96d0b0..407af970d9 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -683,7 +683,7 @@ const SaveLoad *GetVehicleDescription(VehicleType vt) SLE_CONDVAR(Vehicle, profit_this_year, SLE_INT64, 65, SL_MAX_VERSION), SLE_CONDVAR(Vehicle, profit_last_year, SLE_FILE_I32 | SLE_VAR_I64, 0, 64), SLE_CONDVAR(Vehicle, profit_last_year, SLE_INT64, 65, SL_MAX_VERSION), - SLE_CONDVAR(Vehicle, profit_lifetime, SLE_INT64, 195, SL_MAX_VERSION), + SLE_CONDVAR_X(Vehicle,profit_lifetime, SLE_INT64, 0, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_VEH_LIFETIME_PROFIT)), SLEG_CONDVAR( _cargo_feeder_share, SLE_FILE_I32 | SLE_VAR_I64, 51, 64), SLEG_CONDVAR( _cargo_feeder_share, SLE_INT64, 65, 67), SLEG_CONDVAR( _cargo_loaded_at_xy, SLE_UINT32, 51, 67),