Skip to content

Commit

Permalink
Merge pull request #209 from n8rzz/feature/ATC-134
Browse files Browse the repository at this point in the history
feature/ATC-134
  • Loading branch information
n8rzz authored Dec 19, 2016
2 parents 1d8e2ab + 13a69c8 commit 02c6844
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 45 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
- Updates `PositionModel` to run all calculations through the static `.calculatePosition()` method and vastly simplifies internal logic.
- Refactors the the function names in `FixCollection` to better fit their function. `init()` to `addItems()` and `destroy()` to `removeItems()` [#186] (https://github.com/n8rzz/atc/issues/186)
- Adds gulp-cli and adds [tools readme](tools/README.md) link to gulp issues with Windows [#194](https://github.com/n8rzz/atc/issues/194)
- Prevents collision detection for aircraft that are outside of our airspace [#134](https://github.com/n8rzz/atc/issues/134)
- Originally reported under [#736](https://github.com/zlsa/atc/issues/736)
- Changes `routeString` to `routeCode` in `routeModel` [#188] (https://github.com/n8rzz/atc/issues/188)
-`.toUpperCase()` is now called on initialization and removed from the getter
- Escape clears commands but not callsign if commands are present [#211] (https://github.com/n8rzz/atc/issues/211)
Expand All @@ -39,8 +41,6 @@





### Bugfixes
- Moves `_comment` blocks in airport json file to be within object the are describing [#145](https://github.com/n8rzz/atc/issues/145)
- Streamlines flight number generation and adds new method to add new callsigns to the existing list [#151](https://github.com/n8rzz/atc/issues/151)
Expand Down Expand Up @@ -80,4 +80,4 @@
- Updates `FixCollection.findFixByName()` to accept upper, mixed, or lower case fix name [#109](https://github.com/n8rzz/atc/issues/109)
- Switching to a previously loaded airport does not clear previous airport fixes [#115](https://github.com/n8rzz/atc/issues/115)
- Fixes `parseElevation()` so that it does not return NaN when it is given the string `'Infinity'` [#191] (https://github.com/n8rzz/atc/issues/191)
- Originally reported under [#756](https://github.com/zlsa/atc/issues/756)
- Originally reported under [#756](https://github.com/zlsa/atc/issues/756)
6 changes: 4 additions & 2 deletions src/assets/scripts/aircraft/AircraftConflict.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,16 @@ export default class AircraftConflict {
* Check for collision
*/
checkCollision() {
if (this.aircraft[0].wow() || this.aircraft[1].wow()) {
if (this.aircraft[0].isOnGround() || this.aircraft[1].isOnGround()) {
return; // TEMPORARY FIX FOR CRASHES BTWN ARRIVALS AND TAXIIED A/C
}

// TODO: enumerate the magic numbers.
// Collide within 160 feet
const airport = window.airportController.airport_get();

if (((this.distance < 0.05) && (this.altitude < 160)) &&
(this.aircraft[0].isVisible() && this.aircraft[1].isVisible())
(this.aircraft[0].isInsideAirspace(airport) && this.aircraft[1].isInsideAirspace(airport))
) {
this.collided = true;
const isWarning = true;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/scripts/aircraft/AircraftController.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class AircraftController {
remove = true;
}

if (aircraft.hit && aircraft.wow()) {
if (aircraft.hit && aircraft.isOnGround()) {
window.uiController.ui_log(`Lost radar contact with ${aircraft.getCallsign()}`);
speech_say([
{ type: 'callsign', content: aircraft },
Expand Down
86 changes: 48 additions & 38 deletions src/assets/scripts/aircraft/AircraftInstanceModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ export default class Aircraft {
* @param data
*/
runReroute(data) {
// capitalize everything
// TODO: capitalize everything?
data = data[0].toUpperCase();
let worked = true;
const route = this.fms.formatRoute(data);
Expand Down Expand Up @@ -1473,7 +1473,7 @@ export default class Aircraft {
return ['fail', 'inbound'];
}

if (!this.wow()) {
if (!this.isOnGround()) {
return ['fail', 'already airborne'];
}
if (this.mode === FLIGHT_MODES.APRON) {
Expand Down Expand Up @@ -1704,6 +1704,41 @@ export default class Aircraft {
return this.approachOffset <= 0.048;
}

/**
* Checks if the aircraft is inside the airspace of a specified airport
*
* @for AircraftInstanceModel
* @method isInsideAirspace
* @param {airport} airport the airport whose airspace we are checking
* @return {Boolean}
* @private
*/
isInsideAirspace(airport) {
let withinAirspaceLateralBoundaries = this.distance <= airport.ctr_radius;
const withinAirspaceAltitudeRange = this.altitude <= airport.ctr_ceiling;

if (!_isNil(airport.perimeter)) { // polygonal airspace boundary
withinAirspaceLateralBoundaries = point_in_area(this.position, airport.perimeter);
}

return withinAirspaceAltitudeRange && withinAirspaceLateralBoundaries;
}

/**
* Aircraft has "weight-on-wheels" (on the ground)
* @for AircraftInstanceModel
* @method isOnGround
*/
isOnGround() {
const error_allowance_ft = 5;
const airport = window.airportController.airport_get();
const runway = airport.getRunway(this.rwy_dep || this.rwy_arr);
const nearRunwayAltitude = abs(this.altitude - runway.elevation) < error_allowance_ft;
const nearAirportAltitude = abs(this.altitude - airport.position.elevation) < error_allowance_ft;

return nearRunwayAltitude || nearAirportAltitude;
}

/**
* Aircraft is actively following an instrument approach and is elegible for reduced separation
*
Expand All @@ -1725,7 +1760,7 @@ export default class Aircraft {
*/
isStopped() {
// TODO: enumerate the magic number.
return this.wow() && this.speed < 5;
return this.isOnGround() && this.speed < 5;
}

/**
Expand Down Expand Up @@ -1980,7 +2015,7 @@ export default class Aircraft {
this.fms.setCurrent({ start_speed: this.fms.currentWaypoint.speed });
}

if (this.wow()) {
if (this.isOnGround()) {
this.target.altitude = runway.elevation;
this.target.speed = 0;
} else {
Expand Down Expand Up @@ -2136,7 +2171,7 @@ export default class Aircraft {
}

// If stalling, make like a meteorite and fall to the earth!
if (this.speed < this.model.speed.min && !this.wow()) {
if (this.speed < this.model.speed.min && !this.isOnGround()) {
this.target.altitude = Math.min(0, this.target.altitude);
}

Expand Down Expand Up @@ -2235,7 +2270,7 @@ export default class Aircraft {

// TURNING
// this.target.heading = radians_normalize(this.target.heading);
if (!this.wow() && this.heading !== this.target.heading) {
if (!this.isOnGround() && this.heading !== this.target.heading) {
// Perform standard turns 3 deg/s or 25 deg bank, whichever
// requires less bank angle.
// Formula based on http://aviation.stackexchange.com/a/8013
Expand Down Expand Up @@ -2290,7 +2325,7 @@ export default class Aircraft {
}
}

if (this.wow()) {
if (this.isOnGround()) {
this.trend = 0;
}

Expand All @@ -2300,7 +2335,7 @@ export default class Aircraft {
if (this.target.speed < this.speed - 0.01) {
difference = -this.model.rate.decelerate * window.gameController.game_delta() / 2;

if (this.wow()) {
if (this.isOnGround()) {
difference *= 3.5;
}
} else if (this.target.speed > this.speed + 0.01) {
Expand Down Expand Up @@ -2348,7 +2383,7 @@ export default class Aircraft {
const wind = window.airportController.airport_get().wind;
let vector;

if (this.wow()) {
if (this.isOnGround()) {
vector = vscale([sin(angle), cos(angle)], scaleSpeed);
} else {
let crab_angle = 0;
Expand Down Expand Up @@ -2387,22 +2422,10 @@ export default class Aircraft {
this.radial += tau();
}

// polygonal airspace boundary
if (window.airportController.airport_get().perimeter) {
let inside = point_in_area(this.position, window.airportController.airport_get().perimeter);
const isInsideAirspace = this.isInsideAirspace(window.airportController.airport_get());

// TODO: this logic is duplicated below. abstract to new method
if (inside !== this.inside_ctr) {
this.crossBoundary(inside);
}
} else {
// simple circular airspace boundary
let inside = this.distance <= window.airportController.airport_get().ctr_radius &&
this.altitude <= window.airportController.airport_get().ctr_ceiling;

if (inside !== this.inside_ctr) {
this.crossBoundary(inside);
}
if (isInsideAirspace !== this.inside_ctr) {
this.crossBoundary(isInsideAirspace);
}
}

Expand Down Expand Up @@ -2481,7 +2504,7 @@ export default class Aircraft {
});
}

if (this.terrain_ranges && !this.wow()) {
if (this.terrain_ranges && !this.isOnGround()) {
const terrain = prop.airport.current.terrain;
const prev_level = this.terrain_ranges[this.terrain_level];
const ele = Math.ceil(this.altitude, 1000);
Expand Down Expand Up @@ -2664,17 +2687,4 @@ export default class Aircraft {
removeConflict(other) {
delete this.conflicts[other.getCallsign()];
}

/**
* Aircraft has "weight-on-wheels" (on the ground)
* @for AircraftInstanceModel
* @method wow
*/
wow() {
const error_allowance = 5;
const apt = window.airportController.airport_get();
const rwy_elev = apt.getRunway(this.rwy_dep || this.rwy_arr).elevation;
const apt_elev = apt.position.elevation;
return this.altitude - (rwy_elev || apt_elev) < error_allowance;
}
}
2 changes: 1 addition & 1 deletion src/assets/scripts/aircraft/FlightManagementSystem/Leg.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class Leg {

// TODO: refactor/abstract this boolean logic
// Remove the placeholder leg (if present)
if (fms.my_aircraft.wow() &&
if (fms.my_aircraft.isOnGround() &&
fms.legs.length > 0 &&
fms.legs[0].route === airport.icao &&
pairs.length > 0
Expand Down

0 comments on commit 02c6844

Please sign in to comment.