The next patch should start to use http://www.flight-manuals-on-cd.com/B314.html
[fg:toms-fgdata.git] / Aircraft / Boeing314 / Nasal / Boeing314.nas
1 # EXPORT : functions ending by export are called from xml
2 # CRON : functions ending by cron are called from timer
3 # SCHEDULE : functions ending by schedule are called from cron
4
5
6
7 # ==============
8 # Initialization
9 # ==============
10
11 BoeingMain = {};
12
13 BoeingMain.new = func {
14    var obj = { parents : [BoeingMain]
15          };
16
17    obj.init();
18
19    return obj;
20 }
21
22 BoeingMain.putinrelation = func {
23    copilotcrew.set_relation( autopilotsystem, crewscreen, voicecrew );
24
25    mooringsystem.set_relation( copilotcrew );
26 }
27
28 # 1 s cron
29 BoeingMain.sec1cron = func {
30    daytimeinstrument.schedule();
31
32    # schedule the next call
33    settimer(func{ me.sec1cron(); },daytimeinstrument.SPEEDUPSEC);
34 }
35
36 # 2 s cron
37 BoeingMain.sec2cron = func {
38    copilotcrew.fastschedule();
39
40    # schedule the next call
41    settimer(func{ me.sec2cron(); },copilotcrew.COPILOTSEC);
42 }
43
44 # 3 s cron
45 BoeingMain.sec3cron = func {
46    crewscreen.schedule();
47
48    # schedule the next call
49    settimer(func{ me.sec3cron(); },crewscreen.MENUSEC);
50 }
51
52 # 5 s cron
53 BoeingMain.sec5cron = func {
54    mooringsystem.schedule();
55
56    # schedule the next call
57    settimer(func{ me.sec5cron(); },mooringsystem.MOORINGSEC);
58 }
59
60 BoeingMain.savedata = func {
61    var saved_props = [ "/controls/copilot/gyro",
62                        "/controls/crew/timeout",
63                        "/controls/crew/timeout-s",
64                        "/controls/doors/celestial/opened",
65                        "/controls/mooring/automatic",
66                        "/controls/mooring/heading-deg",
67                        "/controls/mooring/tower-adf",
68                        "/controls/mooring/wind",
69                        "/controls/seat/recover",
70                        "/controls/voice/sound",
71                        "/controls/voice/text",
72                        "/sim/model/immat",
73                        "/systems/crew/immat[0]",
74                        "/systems/crew/immat[1]",
75                        "/systems/fuel/presets",
76                        "/systems/seat/position/celestial/x-m",
77                        "/systems/seat/position/celestial/y-m",
78                        "/systems/seat/position/celestial/z-m",
79                        "/systems/seat/position/navigator/x-m",
80                        "/systems/seat/position/navigator/y-m",
81                        "/systems/seat/position/navigator/z-m",
82                        "/systems/seat/position/observer/x-m",
83                        "/systems/seat/position/observer/y-m",
84                        "/systems/seat/position/observer/z-m" ];
85
86    for( var i = 0; i < size(saved_props); i = i + 1 ) {
87         aircraft.data.add(saved_props[i]);
88    }
89 }
90
91 # global variables in Boeing314 namespace, for call by XML
92 BoeingMain.instantiate = func {
93    globals.Boeing314.constant = Constant.new();
94    globals.Boeing314.constantaero = ConstantAero.new();
95    globals.Boeing314.fuelsystem = Fuel.new();
96    globals.Boeing314.autopilotsystem = Autopilot.new();
97
98    globals.Boeing314.daytimeinstrument = DayTime.new();
99
100    globals.Boeing314.mooringsystem = Mooring.new();
101
102    globals.Boeing314.doorsystem = Doors.new();
103    globals.Boeing314.seatsystem = Seats.new();
104
105    globals.Boeing314.menusystem = Menu.new();
106    globals.Boeing314.crewscreen = Crewbox.new();
107
108    globals.Boeing314.copilotcrew = VirtualCopilot.new();
109    globals.Boeing314.voicecrew = Voice.new();
110    globals.Boeing314.GDFcrew = GDF.new();
111 }
112
113 BoeingMain.init = func {
114    aircraft.livery.init( "Aircraft/Boeing314/Models/Liveries",
115                          "sim/model/livery/name",
116                          "sim/model/livery/index" );
117
118    me.instantiate();
119    me.putinrelation();
120
121    # schedule the 1st call
122    settimer(func { me.sec1cron(); },0);
123    settimer(func { me.sec2cron(); },0);
124    settimer(func { me.sec3cron(); },0);
125    settimer(func { me.sec5cron(); },0);
126
127    # saved on exit, restored at launch
128    me.savedata();
129 }
130
131
132 boeing314L = setlistener("/sim/signals/fdm-initialized", func { theclipper = BoeingMain.new(); removelistener(boeing314L); } );