Loading

Paste #pmcrgkitz

  1. Index: src/aircraft.h
  2. ===================================================================
  3. --- src/aircraft.h  (revision 27795)
  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. +   uint16 flight_counter;         ///< Handler for flight distance 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. @@ -134,6 +135,15 @@
  14.     {
  15.         return this->acache.cached_max_range;
  16.     }
  17. +
  18. +   /** Increase flight_counter everytime the aircraft coordinates don't match. */
  19. +   void UpdateFlightDistance(Aircraft *v, TileIndex old_pos, TileIndex new_pos)
  20. +   {
  21. +       if (old_pos == new_pos) return;
  22. +       if (v->flight_counter == UINT16_MAX || (v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
  23. +
  24. +       v->flight_counter = ClampU(v->flight_counter + 1, 0, UINT16_MAX);
  25. +   }
  26.  };
  27.  
  28.  /**
  29. Index: src/aircraft_cmd.cpp
  30. ===================================================================
  31. --- src/aircraft_cmd.cpp    (revision 27795)
  32. +++ src/aircraft_cmd.cpp    (working copy)
  33. @@ -1101,6 +1101,7 @@
  34.  
  35.         }
  36.  
  37. +       if (v->state == FLYING) v->UpdateFlightDistance(v, TileVirtXY(v->x_pos, v->y_pos), TileVirtXY(gp.x, gp.y));
  38.         SetAircraftPosition(v, gp.x, gp.y, z);
  39.     } while (--count != 0);
  40.     return false;
  41. @@ -1619,6 +1620,7 @@
  42.  static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
  43.  {
  44.     v->state = ENDLANDING;
  45. +   v->flight_counter = 0;
  46.     AircraftLandAirplane(v);  // maybe crash airplane
  47.  
  48.     /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
  49. @@ -1632,6 +1634,7 @@
  50.  static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
  51.  {
  52.     v->state = HELIENDLANDING;
  53. +   v->flight_counter = 0;
  54.     v->UpdateDeltaXY(INVALID_DIR);
  55.  }
  56.  
  57. Index: src/lang/english.txt
  58. ===================================================================
  59. --- src/lang/english.txt    (revision 27795)
  60. +++ src/lang/english.txt    (working copy)
  61. @@ -1241,6 +1241,10 @@
  62.  STR_CONFIG_SETTING_PLANE_SPEED                                  :Plane speed factor: {STRING2}
  63.  STR_CONFIG_SETTING_PLANE_SPEED_HELPTEXT                         :Set the relative speed of planes compared to other vehicle types, to reduce the amount of income of transport by aircraft
  64.  STR_CONFIG_SETTING_PLANE_SPEED_VALUE                            :1 / {COMMA}
  65. +STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST                         :Flight distance before increased breakdown rate: {STRING2}
  66. +STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_HELPTEXT                :If vehicle breakdowns are enabled, this sets how far it takes for an aircraft to forcedly have its breakdown rate increased during the current flight, if it has yet to breakdown. When set to 0, it becomes disabled and the breakdown rate won't increase
  67. +STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE                   :{COMMA}{NBSP}tile{P "" s}
  68. +STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE_DISABLED          :Disabled
  69.  STR_CONFIG_SETTING_PLANE_CRASHES                                :Number of plane crashes: {STRING2}
  70.  STR_CONFIG_SETTING_PLANE_CRASHES_HELPTEXT                       :Set the chance of an aircraft crash happening
  71.  STR_CONFIG_SETTING_PLANE_CRASHES_NONE                           :None
  72. Index: src/saveload/afterload.cpp
  73. ===================================================================
  74. --- src/saveload/afterload.cpp  (revision 27795)
  75. +++ src/saveload/afterload.cpp  (working copy)
  76. @@ -2970,6 +2970,13 @@
  77.  #endif
  78.     }
  79.  
  80. +   if (IsSavegameVersionBefore(197)) {
  81. +       Aircraft *a;
  82. +       FOR_ALL_AIRCRAFT(a) {
  83. +           a->flight_counter = 0;
  84. +       }
  85. +       _settings_game.vehicle.plane_breakdown_dist = 0;
  86. +   }
  87.  
  88.     /* Station acceptance is some kind of cache */
  89.     if (IsSavegameVersionBefore(127)) {
  90. Index: src/saveload/saveload.cpp
  91. ===================================================================
  92. --- src/saveload/saveload.cpp   (revision 27795)
  93. +++ src/saveload/saveload.cpp   (working copy)
  94. @@ -264,8 +264,9 @@
  95.   *  194   26881   1.5.x, 1.6.0
  96.   *  195   27572   1.6.x
  97.   *  196   27778   1.7.x
  98. + *  197   27795  
  99.   */
  100. -extern const uint16 SAVEGAME_VERSION = 196; ///< Current savegame version of OpenTTD.
  101. +extern const uint16 SAVEGAME_VERSION = 197; ///< Current savegame version of OpenTTD.
  102.  
  103.  SavegameType _savegame_type; ///< type of savegame we are loading
  104.  FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
  105. Index: src/saveload/vehicle_sl.cpp
  106. ===================================================================
  107. --- src/saveload/vehicle_sl.cpp (revision 27795)
  108. +++ src/saveload/vehicle_sl.cpp (working copy)
  109. @@ -762,6 +762,7 @@
  110.         SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT),
  111.         SLE_VEH_INCLUDE(),
  112.              SLE_VAR(Aircraft, crashed_counter,       SLE_UINT16),
  113. +        SLE_CONDVAR(Aircraft, flight_counter,        SLE_UINT16,                 197, SL_MAX_VERSION),
  114.              SLE_VAR(Aircraft, pos,                   SLE_UINT8),
  115.  
  116.          SLE_CONDVAR(Aircraft, targetairport,         SLE_FILE_U8  | SLE_VAR_U16,   0, 4),
  117. Index: src/settings_gui.cpp
  118. ===================================================================
  119. --- src/settings_gui.cpp    (revision 27795)
  120. +++ src/settings_gui.cpp    (working copy)
  121. @@ -1656,6 +1656,7 @@
  122.             disasters->Add(new SettingEntry("difficulty.disasters"));
  123.             disasters->Add(new SettingEntry("difficulty.economy"));
  124.             disasters->Add(new SettingEntry("difficulty.vehicle_breakdowns"));
  125. +           disasters->Add(new SettingEntry("vehicle.plane_breakdown_dist"));
  126.             disasters->Add(new SettingEntry("vehicle.plane_crashes"));
  127.         }
  128.  
  129. Index: src/settings_type.h
  130. ===================================================================
  131. --- src/settings_type.h (revision 27795)
  132. +++ src/settings_type.h (working copy)
  133. @@ -461,6 +461,7 @@
  134.     bool   never_expire_vehicles;            ///< never expire vehicles
  135.     byte   extend_vehicle_life;              ///< extend vehicle life by this many years
  136.     byte   road_side;                        ///< the side of the road vehicles drive on
  137. +   uint16 plane_breakdown_dist;             ///< distance before increasing breakdown chance during a flight
  138.     uint8  plane_crashes;                    ///< number of plane crashes, 0 = none, 1 = reduced, 2 = normal
  139.  };
  140.  
  141. Index: src/table/settings.ini
  142. ===================================================================
  143. --- src/table/settings.ini  (revision 27795)
  144. +++ src/table/settings.ini  (working copy)
  145. @@ -1136,6 +1136,21 @@
  146.  strval   = STR_CONFIG_SETTING_PLANE_CRASHES_NONE
  147.  cat      = SC_BASIC
  148.  
  149. +[SDT_VAR]
  150. +base     = GameSettings
  151. +var      = vehicle.plane_breakdown_dist
  152. +type     = SLE_UINT16
  153. +from     = 197
  154. +guiflags = SGF_0ISDISABLED
  155. +def      = 100
  156. +min      = 0
  157. +max      = 5461
  158. +interval = 5
  159. +str      = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST
  160. +strhelp  = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_HELPTEXT
  161. +strval   = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE
  162. +cat      = SC_EXPERT
  163. +
  164.  ; station.join_stations
  165.  [SDT_NULL]
  166.  length   = 1
  167. Index: src/vehicle.cpp
  168. ===================================================================
  169. --- src/vehicle.cpp (revision 27795)
  170. +++ src/vehicle.cpp (working copy)
  171. @@ -52,6 +52,7 @@
  172.  #include "gamelog.h"
  173.  #include "linkgraph/linkgraph.h"
  174.  #include "linkgraph/refresh.h"
  175. +#include "settings_internal.h"
  176.  
  177.  #include "table/strings.h"
  178.  
  179. @@ -1204,7 +1205,11 @@
  180.  
  181.     /* increase chance of failure */
  182.     int chance = v->breakdown_chance + 1;
  183. -   if (Chance16I(1, 25, r)) chance += 25;
  184. +   if (Chance16I(1, 25, r) || _settings_game.vehicle.plane_breakdown_dist &&
  185. +           v->type == VEH_AIRCRAFT && !(v->vehstatus & VS_AIRCRAFT_BROKEN) &&
  186. +           Aircraft::From(v)->flight_counter >= _settings_game.vehicle.plane_breakdown_dist) {
  187. +       chance += 25;
  188. +   }
  189.     v->breakdown_chance = min(255, chance);
  190.  
  191.     /* calculate reliability value to use in comparison */

Comments