Skip to content

Commit 3823b2e

Browse files
committed
Merge pull request zlsa#289 from tedrek/t-wind-blows-aircraft
Include wind in aircraft movement
2 parents 7a8dc33 + b015b9e commit 3823b2e

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

assets/scripts/aircraft.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var Aircraft=Fiber.extend(function() {
8181
this.heading = 0;
8282
this.altitude = 0;
8383
this.speed = 0;
84+
this.groundSpeed = 0;
8485
this.ds = 0;
8586

8687
this.radial = 0;
@@ -1317,9 +1318,28 @@ var Aircraft=Fiber.extend(function() {
13171318
if (prop.game.option.get('simplifySpeeds') == 'no') {
13181319
// Calculate the true air speed as indicated airspeed * 1.6% per 1000'
13191320
scaleSpeed *= 1 + (this.altitude * 0.000016);
1321+
1322+
// Calculate movement including wind assuming wind speed
1323+
// increases 2% per 1000'
1324+
var wind = airport_get().wind;
1325+
var vector;
1326+
if (this.isLanded()) {
1327+
vector = vscale([sin(angle), cos(angle)], scaleSpeed);
1328+
}
1329+
else {
1330+
vector = vsum(vscale([sin(wind.angle + Math.PI), cos(wind.angle + Math.PI)],
1331+
wind.speed * 0.000514444 * game_delta()),
1332+
vscale([sin(angle), cos(angle)], scaleSpeed));
1333+
}
1334+
this.ds = vlen(vector);
1335+
this.groundSpeed = this.ds / 0.000514444 / game_delta();
1336+
this.position = vsum(this.position, vector);
1337+
}
1338+
else {
1339+
this.ds = scaleSpeed;
1340+
this.groundSpeed = this.speed;
1341+
this.position = vsum(this.position, vscale([sin(angle), cos(angle)], scaleSpeed));
13201342
}
1321-
this.ds = scaleSpeed;
1322-
this.position = vsum(this.position, vscale([sin(angle), cos(angle)], scaleSpeed));
13231343

13241344
this.distance = vlen(this.position);
13251345
this.radial = vradial(this.position);

assets/scripts/canvas.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,9 @@ function canvas_draw_info(cc, aircraft) {
764764
cc.fillText(lpad(round(aircraft.altitude * 0.01), 2), -separation, line_height);
765765

766766
cc.textAlign = "left";
767-
var speed = aircraft.speed;
768-
if (prop.game.option.get('simplifySpeeds') == 'no') {
769-
speed *= 1 + (aircraft.altitude * 0.000016);
770-
}
771-
cc.fillText(lpad(round(speed * 0.1), 2), separation, line_height);
767+
cc.fillText(lpad(round(aircraft.groundSpeed * 0.1), 2),
768+
separation,
769+
line_height);
772770

773771
cc.textAlign = "center";
774772
cc.fillText(aircraft.getCallsign(), 0, -line_height);

0 commit comments

Comments
 (0)