-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathG422_SCENARIO_RW.cpp
More file actions
255 lines (180 loc) · 7.14 KB
/
Copy pathG422_SCENARIO_RW.cpp
File metadata and controls
255 lines (180 loc) · 7.14 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#include "G422.h"
#include "G422_DVC.h"
#include "G422_MDL_DVC.h"
//
//
// this helps make things less ugly
//
inline bool CFGCheckTag(char* line, const char* tag, int *cfgData)
{
int len = strlen(tag);
if (strnicmp (line, tag, len)) return false;
sscanf (line+len, "%d", cfgData);
return true;
}
//
void G422::clbkLoadStateEx (FILEHANDLE scn, void *status)
{
char *lineChars;
int cfgLoadInt;
while (oapiReadScenario_nextline (scn, lineChars)) {
if (CFGCheckTag(lineChars, "GEARS", &cfgLoadInt)) landingGears->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "CNRDS", &cfgLoadInt)) canards->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "VISOR", &cfgLoadInt)) visor->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "INLET_MAIN", &cfgLoadInt)) inltDoors->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "INLET_RAMX", &cfgLoadInt)) ramxDoors->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "WING_WVRD", &cfgLoadInt)) wingTipWvrd->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "WING_FTHR", &cfgLoadInt)) wingTipFthr->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "CGO_BAY", &cfgLoadInt)) bayDoors->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "RCSDOORS", &cfgLoadInt)) rcs->loadCfgState(cfgLoadInt);
else if (CFGCheckTag(lineChars, "MAIN_ENG_MD", &cfgLoadInt)) main_eng_mode = cfgLoadInt;
else if (CFGCheckTag(lineChars, "BURNER_TGGL", &cfgLoadInt)) burner_toggle = cfgLoadInt;
else if (CFGCheckTag(lineChars, "RAMX_ENG_MD", &cfgLoadInt)) ramcaster_mode = cfgLoadInt;
else if (CFGCheckTag(lineChars, "THR_AUTH_MD", &cfgLoadInt)) thr_authority = cfgLoadInt;
else if (!strnicmp (lineChars, "VC_SWS", 6))
{
for (int i =0; i< VC_SWITCH_COUNT; ++i)
{
VCSwitches[i].setLoadState(lineChars[i+7], this);
}
}
else if (!strnicmp (lineChars, "ENG_MAIN_", 9))
{
if (lineChars[9] == 'L') // load state for left main engine
{
sscanf(lineChars+10, "%d%d%lf%lf%lf%lf%lf",
&engMain_L.state, &engMain_L.feed, &engMain_L.thr, &engMain_L.genPct,
&engMain_L.epr, &engMain_L.fuelPrs, &engMain_L.oxyPrs);
} else // load state for right main engine
{
sscanf(lineChars+10, "%d%d%lf%lf%lf%lf%lf",
&engMain_R.state, &engMain_R.feed, &engMain_R.thr, &engMain_R.genPct,
&engMain_R.epr, &engMain_R.fuelPrs, &engMain_R.oxyPrs);
}
}
else if (!strnicmp (lineChars, "ENG_RAMX", 8))
{
sscanf(lineChars+8, "%d%d%lf%lf%lf",
&engRamx.state, &engRamx.feed, &engRamx.thr, &engRamx.epr, &engRamx.fuelPrs);
//cueEngines(engRamx, (RAMCASTER::SIMSTATE) engRamx.state);
}
else if (!strnicmp (lineChars, "ENG_APU",7))
{
sscanf(lineChars+7, "%d%d%lf%lf%lf",
&apu.state, &apu.feed, &apu.pwrPct, &apu.fuelPrs, &apu.fuelFlow);
}
else if (!strnicmp (lineChars, "VC_EICAS",8))
{
sscanf(lineChars+8, "%d%d%d%d%d%d",
VC_eicas_screens+5, VC_eicas_screens+4, VC_eicas_screens, VC_eicas_screens+1, VC_eicas_screens+2, VC_eicas_screens+3);
}
else
ParseScenarioLineEx (lineChars, status);
}
//oapiVCTriggerRedrawArea(-1, VC_AREA_MFDKEYS);
}
void G422::clbkSaveState (FILEHANDLE scn)
{
VESSEL2::clbkSaveState(scn);
//
//
// alright, first the moving parts... those should be mostly readable...
//
oapiWriteScenario_int(scn, "GEARS", landingGears->getCfgState());
oapiWriteScenario_int(scn, "CNRDS", canards->getCfgState());
oapiWriteScenario_int(scn, "VISOR", visor->getCfgState());
oapiWriteScenario_int(scn, "RCSDOORS", rcs->getCfgState());
oapiWriteScenario_int(scn, "INLET_MAIN", inltDoors->getCfgState());
oapiWriteScenario_int(scn, "INLET_RAMX", ramxDoors->getCfgState());
oapiWriteScenario_int(scn, "WING_WVRD", wingTipWvrd->getCfgState());
oapiWriteScenario_int(scn, "WING_FTHR", wingTipFthr->getCfgState());
oapiWriteScenario_int(scn, "CGO_BAY", bayDoors->getCfgState());
// now, simulation things....
oapiWriteScenario_int(scn, "MAIN_ENG_MD", main_eng_mode);
oapiWriteScenario_int(scn, "BURNER_TGGL", burner_toggle);
oapiWriteScenario_int(scn, "RAMX_ENG_MD", ramcaster_mode);
oapiWriteScenario_int(scn, "THR_AUTH_MD", thr_authority);
// engines crap...
char scnData[256];
sprintf(scnData, "%d %d %0.4f %0.4f %0.4f %0.4f %0.4f",
engMain_L.state, engMain_L.feed, engMain_L.thr, engMain_L.genPct, engMain_L.epr, engMain_L.fuelPrs, engMain_L.oxyPrs);
oapiWriteScenario_string(scn, "ENG_MAIN_L", scnData); // left main engine
sprintf(scnData, "%d %d %0.4f %0.4f %0.4f %0.4f %0.4f",
engMain_R.state, engMain_R.feed, engMain_R.thr, engMain_R.genPct, engMain_R.epr, engMain_R.fuelPrs, engMain_R.oxyPrs);
oapiWriteScenario_string(scn, "ENG_MAIN_R", scnData); // right main engine
sprintf(scnData, "%d %d %0.4f %0.4f %0.4f",
engRamx.state, engRamx.feed, engRamx.thr, engRamx.epr, engRamx.fuelPrs);
oapiWriteScenario_string(scn, "ENG_RAMX", scnData); // ramcaster
sprintf(scnData, "%d %d %0.4f %0.4f %0.4f", apu.state, apu.feed, apu.pwrPct, apu.fuelPrs, apu.fuelFlow);
oapiWriteScenario_string(scn, "ENG_APU", scnData); // APU
// ok... now onto VC stuff
//
sprintf(scnData, "%d %d %d %d %d %d",
VC_eicas_screens[5], VC_eicas_screens[4], VC_eicas_screens[0], VC_eicas_screens[1], VC_eicas_screens[2], VC_eicas_screens[3]);
oapiWriteScenario_string(scn, "VC_EICAS", scnData); // EICAS SCREENS
// seat position
//oapiWriteScenario_int(scn, "VC_SEAT", VC_PoV_station);
// this might come out a little unreadable now... but we gotta save the state for ALL those switches
//
char vcSwsState[VC_SWITCH_COUNT+1];
for (int i = 0; i< VC_SWITCH_COUNT; ++i)
{
vcSwsState[i] = VCSwitches[i].getSaveState();
}
vcSwsState[VC_SWITCH_COUNT] = '\x00'; // set null terminator
//
oapiWriteScenario_string(scn, "VC_SWS", vcSwsState);
// ok, i think that's it for now...
}
int MovingPart::getCfgState()
{
if ((mp_status == MP_REVERSING || mp_status == MP_LOW_DETENT))
{
return 1;
}
if((mp_status == MP_MOVING || mp_status == MP_HI_DETENT))
{
return 2;
}
}
void MovingPart::loadCfgState(int state)
{
if (state == 2)
{
mp_status = MP_HI_DETENT;
pos = 1.0;
vsl->SetAnimation (anim_idx, pos);
return;
}
if (state == 1)
{
mp_status = MP_LOW_DETENT;
pos = 0.0;
vsl->SetAnimation (anim_idx, pos);
return;
}
sysReset = false;
vsl->clbkGeneric(VMSG_MPSTOP, sysID, this);
}
char VCSwitch::getSaveState()
{
switch (pos)
{
case SW3_DOWN: return '-';
case SW3_MID: return '=';
case SW3_UP: return '+';
case SW2_UP: return '^';
case SW2_DOWN: return 'v';
}
}
void VCSwitch::setLoadState(char &cs, VESSEL3* vsl)
{
switch (cs)
{
case '-': return setPos(SW3_DOWN, vsl);
case '=': return setPos(SW3_MID, vsl);
case '+': return setPos(SW3_UP, vsl);
case '^': return setPos(SW2_UP, vsl);
case 'v': return setPos(SW2_DOWN, vsl);
}
}