Loading

Paste #pri7bzd6e

  1. Index: src/aircraft.h
  2. ===================================================================
  3. --- src/aircraft.h  (revision 27794)
  4. +++ src/aircraft.h  (working copy)
  5. @@ -73,6 +73,7 @@
  6.   */
  7.  struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
  8.     uint16 crashed_counter;        ///< Timer for handling crash animations.
  9. +   uint64 flight_counter;         ///< Timer for handling flight duration since last takeoff.
  10.     byte pos;                      ///< Next desired position of the aircraft.
  11.     byte previous_pos;             ///< Previous desired position of the aircraft.
  12.     StationID targetairport;       ///< Airport to go to next.
  13. Index: src/aircraft_cmd.cpp
  14. ===================================================================
  15. --- src/aircraft_cmd.cpp    (revision 27794)
  16. +++ src/aircraft_cmd.cpp    (working copy)
  17. @@ -37,6 +37,7 @@
  18.  #include "core/backup_type.hpp"
  19.  #include "zoom_func.h"
  20.  #include "disaster_vehicle.h"
  21. +#include "settings_internal.h"
  22.  
  23.  #include "table/strings.h"
  24.  
  25. @@ -1619,6 +1620,7 @@
  26.  static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
  27.  {
  28.     v->state = ENDLANDING;
  29. +   v->flight_counter = 0;
  30.     AircraftLandAirplane(v);  // maybe crash airplane
  31.  
  32.     /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
  33. @@ -1632,6 +1634,7 @@
  34.  static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
  35.  {
  36.     v->state = HELIENDLANDING;
  37. +   v->flight_counter = 0;
  38.     v->UpdateDeltaXY(INVALID_DIR);
  39.  }
  40.  
  41. @@ -2034,6 +2037,20 @@
  42.     return true;
  43.  }
  44.  
  45. +static uint FlightTimeDelta()
  46. +{
  47. +   uint speed_factor_max = GetSettingFromName("vehicle.plane_speed", &speed_factor_max)->desc.max;
  48. +   uint speed_factor_min = GetSettingFromName("vehicle.plane_speed", &speed_factor_min)->desc.min;
  49. +
  50. +   uint m = 1;
  51. +   for (uint i = speed_factor_min; i <= speed_factor_max; i++) {
  52. +       uint l = LeastCommonMultiple(i, speed_factor_max);
  53. +       m = l > m ? l : m;
  54. +   }
  55. +
  56. +   return m / _settings_game.vehicle.plane_speed;
  57. +}
  58. +
  59.  bool Aircraft::Tick()
  60.  {
  61.     if (!this->IsNormalAircraft()) return true;
  62. @@ -2046,6 +2063,8 @@
  63.  
  64.     this->current_order_time++;
  65.  
  66. +   if (this->state == FLYING) this->flight_counter += FlightTimeDelta();
  67. +
  68.     for (uint i = 0; i != 2; i++) {
  69.         /* stop if the aircraft was deleted */
  70.         if (!AircraftEventHandler(this, i)) return false;
  71. Index: src/lang/english.txt
  72. ===================================================================
  73. --- src/lang/english.txt    (revision 27794)
  74. +++ src/lang/english.txt    (working copy)
  75. @@ -286,6 +286,7 @@
  76.  STR_SORT_BY_NUMBER                                              :Number
  77.  STR_SORT_BY_PROFIT_LAST_YEAR                                    :Profit last year
  78.  STR_SORT_BY_PROFIT_THIS_YEAR                                    :Profit this year
  79. +STR_SORT_BY_PROFIT_LIFETIME                                     :Lifetime profit
  80.  STR_SORT_BY_AGE                                                 :Age
  81.  STR_SORT_BY_RELIABILITY                                         :Reliability
  82.  STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE                        :Total capacity per cargo type
  83. @@ -3662,6 +3663,7 @@
  84.  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}
  85.  
  86.  STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR                     :{BLACK}Profit this year: {LTBLUE}{CURRENCY_LONG} (last year: {CURRENCY_LONG})
  87. +STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME            :{STRING2} (lifetime: {CURRENCY_LONG})
  88.  STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS                         :{BLACK}Reliability: {LTBLUE}{COMMA}%  {BLACK}Breakdowns since last service: {LTBLUE}{COMMA}
  89.  
  90.  STR_VEHICLE_INFO_BUILT_VALUE                                    :{LTBLUE}{ENGINE} {BLACK}Built: {LTBLUE}{NUM}{BLACK} Value: {LTBLUE}{CURRENCY_LONG}
  91. Index: src/saveload/afterload.cpp
  92. ===================================================================
  93. --- src/saveload/afterload.cpp  (revision 27794)
  94. +++ src/saveload/afterload.cpp  (working copy)
  95. @@ -2977,6 +2977,12 @@
  96.         FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
  97.     }
  98.  
  99. +   /* Set lifetime vehicle profit to 0 if save game before 197 */
  100. +   if (IsSavegameVersionBefore(197)) {
  101. +       Vehicle *v;
  102. +       FOR_ALL_VEHICLES(v) v->profit_lifetime = 0;
  103. +   }
  104. +
  105.     /* Road stops is 'only' updating some caches */
  106.     AfterLoadRoadStops();
  107.     AfterLoadLabelMaps();
  108. Index: src/saveload/saveload.cpp
  109. ===================================================================
  110. --- src/saveload/saveload.cpp   (revision 27794)
  111. +++ src/saveload/saveload.cpp   (working copy)
  112. @@ -264,8 +264,9 @@
  113.   *  194   26881   1.5.x, 1.6.0
  114.   *  195   27572   1.6.x
  115.   *  196   27778   1.7.x
  116. + *  197
  117.   */
  118. -extern const uint16 SAVEGAME_VERSION = 196; ///< Current savegame version of OpenTTD.
  119. +extern const uint16 SAVEGAME_VERSION = 197; ///< Current savegame version of OpenTTD.
  120.  
  121.  SavegameType _savegame_type; ///< type of savegame we are loading
  122.  FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
  123. Index: src/saveload/vehicle_sl.cpp
  124. ===================================================================
  125. --- src/saveload/vehicle_sl.cpp (revision 27794)
  126. +++ src/saveload/vehicle_sl.cpp (working copy)
  127. @@ -683,6 +683,7 @@
  128.          SLE_CONDVAR(Vehicle, profit_this_year,      SLE_INT64,                   65, SL_MAX_VERSION),
  129.          SLE_CONDVAR(Vehicle, profit_last_year,      SLE_FILE_I32 | SLE_VAR_I64,   0,  64),
  130.          SLE_CONDVAR(Vehicle, profit_last_year,      SLE_INT64,                   65, SL_MAX_VERSION),
  131. +        SLE_CONDVAR(Vehicle, profit_lifetime,       SLE_INT64,                   197, SL_MAX_VERSION),
  132.         SLEG_CONDVAR(         _cargo_feeder_share,   SLE_FILE_I32 | SLE_VAR_I64,  51,  64),
  133.         SLEG_CONDVAR(         _cargo_feeder_share,   SLE_INT64,                   65,  67),
  134.         SLEG_CONDVAR(         _cargo_loaded_at_xy,   SLE_UINT32,                  51,  67),
  135. Index: src/vehicle.cpp
  136. ===================================================================
  137. --- src/vehicle.cpp (revision 27794)
  138. +++ src/vehicle.cpp (working copy)
  139. @@ -1237,6 +1237,10 @@
  140.      * >2 - vehicle is counting down to the actual breakdown event */
  141.     switch (this->breakdown_ctr) {
  142.         case 0:
  143. +           if (this->type == VEH_AIRCRAFT) {
  144. +               Aircraft *a = Aircraft::From(this);
  145. +               if (false && a->flight_counter < 74 * 20 * 4 && !(this->vehstatus & VS_AIRCRAFT_BROKEN)) this->breakdown_ctr = 2;
  146. +           }
  147.             return false;
  148.  
  149.         case 2:
  150. @@ -2704,6 +2708,7 @@
  151.             }
  152.  
  153.             v->profit_last_year = v->profit_this_year;
  154. +           v->profit_lifetime += v->profit_this_year;
  155.             v->profit_this_year = 0;
  156.             SetWindowDirty(WC_VEHICLE_DETAILS, v->index);
  157.         }
  158. Index: src/vehicle_base.h
  159. ===================================================================
  160. --- src/vehicle_base.h  (revision 27794)
  161. +++ src/vehicle_base.h  (working copy)
  162. @@ -238,6 +238,7 @@
  163.  
  164.     Money profit_this_year;             ///< Profit this year << 8, low 8 bits are fract
  165.     Money profit_last_year;             ///< Profit last year << 8, low 8 bits are fract
  166. +   Money profit_lifetime;              ///< Profit lifetime << 8, low 8 bits are fract
  167.     Money value;                        ///< Value of the vehicle
  168.  
  169.     CargoPayment *cargo_payment;        ///< The cargo payment we're currently in
  170. @@ -571,6 +572,12 @@
  171.      */
  172.     Money GetDisplayProfitLastYear() const { return (this->profit_last_year >> 8); }
  173.  
  174. +   /**
  175. +    * Gets the lifetime profit of vehicle. It can be sent into SetDParam for string processing.
  176. +    * @return the vehicle's lifetime profit
  177. +    */
  178. +   Money GetDisplayProfitLifetime() const { return ((this->profit_lifetime + this->profit_this_year) >> 8); }
  179. +
  180.     void SetNext(Vehicle *next);
  181.  
  182.     /**
  183. Index: src/vehicle_gui.cpp
  184. ===================================================================
  185. --- src/vehicle_gui.cpp (revision 27794)
  186. +++ src/vehicle_gui.cpp (working copy)
  187. @@ -48,6 +48,7 @@
  188.  static GUIVehicleList::SortFunction VehicleNameSorter;
  189.  static GUIVehicleList::SortFunction VehicleAgeSorter;
  190.  static GUIVehicleList::SortFunction VehicleProfitThisYearSorter;
  191. +static GUIVehicleList::SortFunction VehicleProfitLifetimeSorter;
  192.  static GUIVehicleList::SortFunction VehicleProfitLastYearSorter;
  193.  static GUIVehicleList::SortFunction VehicleCargoSorter;
  194.  static GUIVehicleList::SortFunction VehicleReliabilitySorter;
  195. @@ -64,6 +65,7 @@
  196.     &VehicleAgeSorter,
  197.     &VehicleProfitThisYearSorter,
  198.     &VehicleProfitLastYearSorter,
  199. +   &VehicleProfitLifetimeSorter,
  200.     &VehicleCargoSorter,
  201.     &VehicleReliabilitySorter,
  202.     &VehicleMaxSpeedSorter,
  203. @@ -80,6 +82,7 @@
  204.     STR_SORT_BY_AGE,
  205.     STR_SORT_BY_PROFIT_THIS_YEAR,
  206.     STR_SORT_BY_PROFIT_LAST_YEAR,
  207. +   STR_SORT_BY_PROFIT_LIFETIME,
  208.     STR_SORT_BY_TOTAL_CAPACITY_PER_CARGOTYPE,
  209.     STR_SORT_BY_RELIABILITY,
  210.     STR_SORT_BY_MAX_SPEED,
  211. @@ -1132,6 +1135,13 @@
  212.     return (r != 0) ? r : VehicleNumberSorter(a, b);
  213.  }
  214.  
  215. +/** Sort vehicles by lifetime profit */
  216. +static int CDECL VehicleProfitLifetimeSorter(const Vehicle * const *a, const Vehicle * const *b)
  217. +{
  218. +   int r = ClampToI32((*a)->GetDisplayProfitLifetime() - (*b)->GetDisplayProfitLifetime());
  219. +   return (r != 0) ? r : VehicleNumberSorter(a, b);
  220. +}
  221. +
  222.  /** Sort vehicles by their cargo */
  223.  static int CDECL VehicleCargoSorter(const Vehicle * const *a, const Vehicle * const *b)
  224.  {
  225. @@ -1939,12 +1949,14 @@
  226.                     STR_VEHICLE_INFO_MAX_SPEED,
  227.                     STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED,
  228.                     STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED_MAX_TE,
  229. -                   STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR,
  230.                     STR_VEHICLE_INFO_RELIABILITY_BREAKDOWNS
  231.                 };
  232.                 for (uint i = 0; i < lengthof(info_strings); i++) {
  233.                     dim = maxdim(dim, GetStringBoundingBox(info_strings[i]));
  234.                 }
  235. +               SetDParam(0, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
  236. +               for (uint i = 1; i < 4; i++) SetDParamMaxValue(i, 1 << 24);
  237. +               dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME));
  238.                 SetDParam(0, STR_VEHICLE_INFO_AGE);
  239.                 dim = maxdim(dim, GetStringBoundingBox(STR_VEHICLE_INFO_AGE_RUNNING_COST_YR));
  240.                 size->width = dim.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
  241. @@ -2080,9 +2092,11 @@
  242.                 y += FONT_HEIGHT_NORMAL;
  243.  
  244.                 /* Draw profit */
  245. -               SetDParam(0, v->GetDisplayProfitThisYear());
  246. -               SetDParam(1, v->GetDisplayProfitLastYear());
  247. -               DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
  248. +               SetDParam(0, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR);
  249. +               SetDParam(1, v->GetDisplayProfitThisYear());
  250. +               SetDParam(2, v->GetDisplayProfitLastYear());
  251. +               SetDParam(3, v->GetDisplayProfitLifetime());
  252. +               DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_PROFIT_THIS_YEAR_LAST_YEAR_LIFETIME);
  253.                 y += FONT_HEIGHT_NORMAL;
  254.  
  255.                 /* Draw breakdown & reliability */

Comments