-
Notifications
You must be signed in to change notification settings - Fork 2
/
aar.nas
120 lines (87 loc) · 3.65 KB
/
aar.nas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Properties under /consumables/fuel/tank[n]:
# + level-gal_us - Current fuel load. Can be set by user code.
# + level-lbs - OUTPUT ONLY property, do not try to set
# + selected - boolean indicating tank selection.
# + density-ppg - Fuel density, in lbs/gallon.
# + capacity-gal_us - Tank capacity
#
# Properties under /engines/engine[n]:
# + fuel-consumed-lbs - Output from the FDM, zeroed by this script
# + out-of-fuel - boolean, set by this code.
# ==================================== timer stuff ===========================================
# set the update period
UPDATE_PERIOD = 0.3;
# set the timer for the selected function
registerTimer = func {
settimer(arg[0], UPDATE_PERIOD);
} # end function
# =============================== end timer stuff ===========================================
initialized = 0;
enabled = 0;
print ("running aar");
# print (" enabled " , enabled, " initialized ", initialized);
updateTanker = func {
# print ("tanker update running ");
#if (!initialized ) {
#print("calling initialize");
#initialize();}
Refueling = props.globals.getNode("/systems/refuel/contact");
AllAircraft = props.globals.getNode("ai/models").getChildren("aircraft");
AllMultiplayer = props.globals.getNode("ai/models").getChildren("multiplayer");
Aircraft = props.globals.getNode("ai/models/aircraft");
# select all tankers which are in contact. For now we assume that it must be in
# contact with us.
selectedTankers = [];
if ( enabled ) { # check that AI Models are enabled, otherwise don't bother
foreach(a; AllAircraft) {
contact_node = a.getNode("refuel/contact");
id_node = a.getNode("id");
tanker_node = a.getNode("tanker");
contact = contact_node.getValue();
id = id_node.getValue();
tanker = tanker_node.getValue();
# print ("contact ", contact , " tanker " , tanker );
if (tanker and contact) {
append(selectedTankers, a);
}
}
foreach(m; AllMultiplayer) {
contact_node = m.getNode("refuel/contact");
id_node = m.getNode("id");
tanker_node = m.getNode("tanker");
contact = contact_node.getValue();
id = id_node.getValue();
tanker = tanker_node.getValue();
# print (" mp contact ", contact , " tanker " , tanker );
if (tanker and contact) {
append(selectedTankers, m);
}
}
}
# print ("tankers ", size(selectedTankers) );
if ( size(selectedTankers) >= 1 ){
Refueling.setBoolValue(1);
} else {
Refueling.setBoolValue(0);
}
registerTimer(updateTanker);
}
# Initalize: Make sure all needed properties are present and accounted
# for, and that they have sane default values.
initialize = func {
AI_Enabled = props.globals.getNode("sim/ai/enabled");
Refueling = props.globals.getNode("/systems/refuel/contact",1);
Refueling.setBoolValue(0);
enabled = AI_Enabled.getValue();
initialized = 1;
}
initDoubleProp = func {
node = arg[0]; prop = arg[1]; val = arg[2];
if(node.getNode(prop) != nil) {
val = num(node.getNode(prop).getValue());
}
node.getNode(prop, 1).setDoubleValue(val);
}
# Fire it up
if (!initialized) {initialize();}
registerTimer(updateTanker);