2014-04-29 02:26:32 +00:00
|
|
|
# See: http://wiki.flightgear.org/MapStructure
|
2014-01-27 02:18:30 +00:00
|
|
|
# Class things:
|
|
|
|
var name = 'TFC';
|
|
|
|
var parents = [SymbolLayer.Controller];
|
|
|
|
var __self__ = caller(0)[0];
|
|
|
|
SymbolLayer.Controller.add(name, __self__);
|
|
|
|
SymbolLayer.add(name, {
|
|
|
|
parents: [SymbolLayer],
|
|
|
|
type: name, # Symbol type
|
|
|
|
df_controller: __self__, # controller to use by default -- this one
|
2014-04-29 02:26:32 +00:00
|
|
|
df_style: { debug: 0 }, # style to use by default
|
2014-01-27 02:18:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
var model_root = props.globals.getNode("/ai/models/");
|
|
|
|
|
|
|
|
var new = func(layer) {
|
|
|
|
var m = {
|
|
|
|
parents: [__self__],
|
|
|
|
layer: layer,
|
2014-04-29 02:26:32 +00:00
|
|
|
map: layer.map,
|
2014-01-27 02:18:30 +00:00
|
|
|
listeners: [],
|
2014-04-29 02:26:32 +00:00
|
|
|
searchCmd: searchCmd_default,
|
2014-01-27 02:18:30 +00:00
|
|
|
};
|
|
|
|
layer.searcher._equals = func(l,r) l.equals(r);
|
|
|
|
return m;
|
|
|
|
};
|
|
|
|
var del = func() {
|
|
|
|
#print(name~".lcontroller.del()");
|
|
|
|
foreach (var l; me.listeners)
|
|
|
|
removelistener(l);
|
|
|
|
};
|
|
|
|
|
|
|
|
var TrafficModel = {
|
|
|
|
new: func(node, id=nil, layer=nil) {
|
|
|
|
if (id == nil) id = node.getValue("id");
|
|
|
|
var m = {
|
|
|
|
# Note: because this inherits from props.Node, Symbol.Controller.equals
|
|
|
|
# will call l.equals(r) -- the one defined below
|
2014-01-28 02:48:29 +00:00
|
|
|
parents: [TrafficModel, geo.Coord, node], # note we don't implement a full geo.Coord API
|
2014-01-27 02:18:30 +00:00
|
|
|
id: id,
|
|
|
|
node: node,
|
2014-01-28 02:48:29 +00:00
|
|
|
pos: node.getNode("position",1),
|
2014-01-27 02:18:30 +00:00
|
|
|
};
|
|
|
|
return m;
|
|
|
|
},
|
|
|
|
equals: func(other) other.id == me.id,
|
2014-04-29 02:26:32 +00:00
|
|
|
latlon: func() { # this makes sure to look like a geo.Coord to MapStructure, but will internally use the AI/MP traffic properties instead
|
2014-01-27 02:18:30 +00:00
|
|
|
return [
|
|
|
|
me.pos.getValue("latitude-deg"),
|
|
|
|
me.pos.getValue("longitude-deg"),
|
|
|
|
me.pos.getValue("altitude-ft")
|
|
|
|
];
|
|
|
|
},
|
2014-04-29 02:26:32 +00:00
|
|
|
# these are helper methods related to TCAS handling (TAs/RAs)
|
|
|
|
get_threat_lvl: func() me.getValue("tcas/threat-level"),
|
|
|
|
get_vspd: func() (me.getValue("velocities/vertical-speed-fps") or 0)*60,
|
|
|
|
get_alt: func() (me.getValue("position/altitude-ft") or 0),
|
2014-01-27 02:18:30 +00:00
|
|
|
};
|
|
|
|
|
2014-04-29 02:26:32 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# dummy/placeholder (will be overridden in ctor and set to the default callback)
|
|
|
|
var searchCmd = func;
|
|
|
|
|
|
|
|
var searchCmd_default = func {
|
2014-01-27 02:18:30 +00:00
|
|
|
# TODO: this would be a good candidate for splitting across frames
|
2014-04-29 02:26:32 +00:00
|
|
|
printlog(_MP_dbg_lvl, "Doing query: "~name);
|
2014-01-27 02:18:30 +00:00
|
|
|
|
|
|
|
var result = [];
|
2014-04-29 02:26:32 +00:00
|
|
|
var models = 0;
|
2014-01-27 02:18:30 +00:00
|
|
|
|
|
|
|
# AI and Multiplayer traffic
|
2014-04-29 02:26:32 +00:00
|
|
|
foreach (var t; model_root.getChildren()) {
|
|
|
|
if (!t.getValue("valid")) continue;
|
|
|
|
var t_id = t.getNode("id");
|
|
|
|
if (t_id == nil or t_id.getValue() == -1) continue;
|
|
|
|
models += 1;
|
|
|
|
var (lat,lon) = (t.getValue("position/latitude-deg"),
|
|
|
|
t.getValue("position/longitude-deg"));
|
|
|
|
if (lat == nil or lon == nil) {
|
|
|
|
printlog("alert", "lat/lon was nil for AI node "~t.getPath());
|
|
|
|
continue;
|
2014-01-27 02:18:30 +00:00
|
|
|
}
|
2014-04-29 02:26:32 +00:00
|
|
|
if (me.map.controller.in_range(lat, lon))
|
|
|
|
append(result, TrafficModel.new(t, nil, me.layer));
|
2014-01-28 02:48:29 +00:00
|
|
|
}
|
2014-01-27 02:18:30 +00:00
|
|
|
|
2014-04-29 02:26:32 +00:00
|
|
|
#print("Found "~size(result)~" TrafficModel's in range out of "~models~" total.");
|
2014-01-27 02:18:30 +00:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|