2014-04-29 02:26:32 +00:00
|
|
|
# WARNING: *.model files will be deprecated, see: http://wiki.flightgear.org/MapStructure
|
2013-12-01 12:29:22 +00:00
|
|
|
var MPTrafficModel = {};
|
|
|
|
MPTrafficModel.new = func make(LayerModel, MPTrafficModel);
|
|
|
|
|
|
|
|
MPTrafficModel.init = func {
|
|
|
|
var pos = geo.Coord.new(); # FIXME: all of these should be instance variables
|
|
|
|
var myPosition = geo.Coord.new();
|
|
|
|
var myPositionVec = me._controller['get_position']();
|
|
|
|
myPosition.set_latlon( myPositionVec[0], myPositionVec[1]);
|
|
|
|
var max_dist_nm = me._controller['query_range']();
|
|
|
|
|
|
|
|
me._view.reset(); # hides: removeAllChildren()
|
2013-12-28 15:18:35 +00:00
|
|
|
|
|
|
|
# AI traffic
|
|
|
|
var traffic = props.globals.initNode("/ai/models/").getChildren( "aircraft" );
|
2013-12-01 12:29:22 +00:00
|
|
|
foreach(var t; traffic) {
|
|
|
|
pos.set_latlon( t.getNode("position/latitude-deg").getValue(),
|
|
|
|
t.getNode("position/longitude-deg").getValue()
|
|
|
|
);
|
|
|
|
|
2013-12-28 15:18:35 +00:00
|
|
|
if (pos.distance_to( myPosition ) <= max_dist_nm*NM2M )
|
|
|
|
me.push(t);
|
|
|
|
}
|
|
|
|
# Multiplayer traffic
|
|
|
|
var traffic = props.globals.initNode("/ai/models/").getChildren( "multiplayer" );
|
|
|
|
foreach(var t; traffic) {
|
|
|
|
pos.set_latlon( t.getNode("position/latitude-deg").getValue(),
|
|
|
|
t.getNode("position/longitude-deg").getValue()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (pos.distance_to( myPosition ) <= max_dist_nm*NM2M )
|
2013-12-01 12:29:22 +00:00
|
|
|
me.push(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
me.notifyView();
|
|
|
|
|
|
|
|
# update itself FIXME: this needs to be killed by the controller (e.g. when tcas layer is disabled)
|
|
|
|
# and the interval needs to be configurable via the controller
|
|
|
|
# so better use maketimer() here
|
|
|
|
settimer(func me.init(), 2);
|
2013-12-28 15:18:35 +00:00
|
|
|
}
|