Index: src/aircraft.h
===================================================================
--- src/aircraft.h (revision 27795)
+++ src/aircraft.h (working copy)
@@ -73,6 +73,7 @@
*/
struct Aircraft FINAL : public SpecializedVehicle<Aircraft, VEH_AIRCRAFT> {
uint16 crashed_counter; ///< Timer for handling crash animations.
+ uint16 flight_counter; ///< Handler for flight distance since last takeoff.
byte pos; ///< Next desired position of the aircraft.
byte previous_pos; ///< Previous desired position of the aircraft.
StationID targetairport; ///< Airport to go to next.
@@ -134,6 +135,15 @@
{
return this->acache.cached_max_range;
}
+
+ /** Increase flight_counter everytime the aircraft coordinates don't match. */
+ void UpdateFlightDistance(Aircraft *v, TileIndex old_pos, TileIndex new_pos)
+ {
+ if (old_pos == new_pos) return;
+ if (v->flight_counter == UINT16_MAX || (v->vehstatus & VS_AIRCRAFT_BROKEN)) return;
+
+ v->flight_counter = ClampU(v->flight_counter + 1, 0, UINT16_MAX);
+ }
};
/**
Index: src/aircraft_cmd.cpp
===================================================================
--- src/aircraft_cmd.cpp (revision 27795)
+++ src/aircraft_cmd.cpp (working copy)
@@ -1101,6 +1101,7 @@
}
+ if (v->state == FLYING) v->UpdateFlightDistance(v, TileVirtXY(v->x_pos, v->y_pos), TileVirtXY(gp.x, gp.y));
SetAircraftPosition(v, gp.x, gp.y, z);
} while (--count != 0);
return false;
@@ -1619,6 +1620,7 @@
static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc)
{
v->state = ENDLANDING;
+ v->flight_counter = 0;
AircraftLandAirplane(v); // maybe crash airplane
/* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */
@@ -1632,6 +1634,7 @@
static void AircraftEventHandler_HeliLanding(Aircraft *v, const AirportFTAClass *apc)
{
v->state = HELIENDLANDING;
+ v->flight_counter = 0;
v->UpdateDeltaXY(INVALID_DIR);
}
Index: src/lang/english.txt
===================================================================
--- src/lang/english.txt (revision 27795)
+++ src/lang/english.txt (working copy)
@@ -1241,6 +1241,10 @@
STR_CONFIG_SETTING_PLANE_SPEED :Plane speed factor: {STRING2}
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
STR_CONFIG_SETTING_PLANE_SPEED_VALUE :1 / {COMMA}
+STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST :Flight distance before increased breakdown rate: {STRING2}
+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
+STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE :{COMMA}{NBSP}tile{P "" s}
+STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE_DISABLED :Disabled
STR_CONFIG_SETTING_PLANE_CRASHES :Number of plane crashes: {STRING2}
STR_CONFIG_SETTING_PLANE_CRASHES_HELPTEXT :Set the chance of an aircraft crash happening
STR_CONFIG_SETTING_PLANE_CRASHES_NONE :None
Index: src/saveload/afterload.cpp
===================================================================
--- src/saveload/afterload.cpp (revision 27795)
+++ src/saveload/afterload.cpp (working copy)
@@ -2970,6 +2970,13 @@
#endif
}
+ if (IsSavegameVersionBefore(197)) {
+ Aircraft *a;
+ FOR_ALL_AIRCRAFT(a) {
+ a->flight_counter = 0;
+ }
+ _settings_game.vehicle.plane_breakdown_dist = 0;
+ }
/* Station acceptance is some kind of cache */
if (IsSavegameVersionBefore(127)) {
Index: src/saveload/saveload.cpp
===================================================================
--- src/saveload/saveload.cpp (revision 27795)
+++ src/saveload/saveload.cpp (working copy)
@@ -264,8 +264,9 @@
* 194 26881 1.5.x, 1.6.0
* 195 27572 1.6.x
* 196 27778 1.7.x
+ * 197 27795
*/
-extern const uint16 SAVEGAME_VERSION = 196; ///< Current savegame version of OpenTTD.
+extern const uint16 SAVEGAME_VERSION = 197; ///< Current savegame version of OpenTTD.
SavegameType _savegame_type; ///< type of savegame we are loading
FileToSaveLoad _file_to_saveload; ///< File to save or load in the openttd loop.
Index: src/saveload/vehicle_sl.cpp
===================================================================
--- src/saveload/vehicle_sl.cpp (revision 27795)
+++ src/saveload/vehicle_sl.cpp (working copy)
@@ -762,6 +762,7 @@
SLE_WRITEBYTE(Vehicle, type, VEH_AIRCRAFT),
SLE_VEH_INCLUDE(),
SLE_VAR(Aircraft, crashed_counter, SLE_UINT16),
+ SLE_CONDVAR(Aircraft, flight_counter, SLE_UINT16, 197, SL_MAX_VERSION),
SLE_VAR(Aircraft, pos, SLE_UINT8),
SLE_CONDVAR(Aircraft, targetairport, SLE_FILE_U8 | SLE_VAR_U16, 0, 4),
Index: src/settings_gui.cpp
===================================================================
--- src/settings_gui.cpp (revision 27795)
+++ src/settings_gui.cpp (working copy)
@@ -1656,6 +1656,7 @@
disasters->Add(new SettingEntry("difficulty.disasters"));
disasters->Add(new SettingEntry("difficulty.economy"));
disasters->Add(new SettingEntry("difficulty.vehicle_breakdowns"));
+ disasters->Add(new SettingEntry("vehicle.plane_breakdown_dist"));
disasters->Add(new SettingEntry("vehicle.plane_crashes"));
}
Index: src/settings_type.h
===================================================================
--- src/settings_type.h (revision 27795)
+++ src/settings_type.h (working copy)
@@ -461,6 +461,7 @@
bool never_expire_vehicles; ///< never expire vehicles
byte extend_vehicle_life; ///< extend vehicle life by this many years
byte road_side; ///< the side of the road vehicles drive on
+ uint16 plane_breakdown_dist; ///< distance before increasing breakdown chance during a flight
uint8 plane_crashes; ///< number of plane crashes, 0 = none, 1 = reduced, 2 = normal
};
Index: src/table/settings.ini
===================================================================
--- src/table/settings.ini (revision 27795)
+++ src/table/settings.ini (working copy)
@@ -1136,6 +1136,21 @@
strval = STR_CONFIG_SETTING_PLANE_CRASHES_NONE
cat = SC_BASIC
+[SDT_VAR]
+base = GameSettings
+var = vehicle.plane_breakdown_dist
+type = SLE_UINT16
+from = 197
+guiflags = SGF_0ISDISABLED
+def = 100
+min = 0
+max = 5461
+interval = 5
+str = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST
+strhelp = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_HELPTEXT
+strval = STR_CONFIG_SETTING_PLANE_BREAKDOWN_DIST_VALUE
+cat = SC_EXPERT
+
; station.join_stations
[SDT_NULL]
length = 1
Index: src/vehicle.cpp
===================================================================
--- src/vehicle.cpp (revision 27795)
+++ src/vehicle.cpp (working copy)
@@ -52,6 +52,7 @@
#include "gamelog.h"
#include "linkgraph/linkgraph.h"
#include "linkgraph/refresh.h"
+#include "settings_internal.h"
#include "table/strings.h"
@@ -1204,7 +1205,11 @@
/* increase chance of failure */
int chance = v->breakdown_chance + 1;
- if (Chance16I(1, 25, r)) chance += 25;
+ if (Chance16I(1, 25, r) || _settings_game.vehicle.plane_breakdown_dist &&
+ v->type == VEH_AIRCRAFT && !(v->vehstatus & VS_AIRCRAFT_BROKEN) &&
+ Aircraft::From(v)->flight_counter >= _settings_game.vehicle.plane_breakdown_dist) {
+ chance += 25;
+ }
v->breakdown_chance = min(255, chance);
/* calculate reliability value to use in comparison */