summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcelestar <celestar@openttd.org>2007-02-02 15:04:59 +0000
committercelestar <celestar@openttd.org>2007-02-02 15:04:59 +0000
commit8be271f9b02c9ddd634d7d9ca7f752ea22b7937d (patch)
tree7651c6f5f9c30eac3ef69510a23d31d9ea039230
parent6d50c66d67ae772ca4d642943279528b00158ed2 (diff)
downloadopenttd-8be271f9b02c9ddd634d7d9ca7f752ea22b7937d.tar.xz
(svn r8534) -Feature/Codechange: Provide aircraft with vertical separation depending on their altitude and velocity
-rw-r--r--src/aircraft_cmd.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index c4e63eed5..8e45e9001 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -898,14 +898,32 @@ static bool UpdateAircraftSpeed(Vehicle *v)
return t < v->progress;
}
-// get Aircraft running altitude
+/**
+ * Gets the cruise altitude of an aircraft.
+ * The cruise altitude is determined by the velocity of the vehicle
+ * and the direction it is moving
+ * @param v The vehicle. Should be an aircraft
+ * @returns Altitude in pixel units
+ */
static byte GetAircraftFlyingAltitude(const Vehicle *v)
{
- switch (v->max_speed) {
- case 37: return 162;
- case 74: return 171;
- default: return 180;
+ /* Make sure Aircraft fly no lower so that they don't conduct
+ * CFITs (controlled flight into terrain)
+ */
+ byte base_altitude = 150;
+
+ /* Make sure eastbound and westbound planes do not "crash" into each
+ * other by providing them with vertical seperation
+ */
+ switch (v->direction) {
+ case DIR_N: case DIR_NE: case DIR_E: case DIR_SE: base_altitude += 15; break;
+ default: break;
}
+
+ /* Make faster planes fly higher so that they can overtake slower ones */
+ base_altitude += min(30 * (v->max_speed / 37), 90);
+
+ return base_altitude;
}
static bool AircraftController(Vehicle *v)