-
Notifications
You must be signed in to change notification settings - Fork 1
/
NewBGLs.c
3341 lines (2764 loc) · 97.3 KB
/
NewBGLs.c
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* NewBGLs.c
*******************************************************************************/
#include "MakeRwys.h"
extern char chRwyT[6];
extern char szParkNames[12][5];
extern char *pszParkType[];
extern char szCurrentFilePath[MAX_PATH];
__int32 nOffsetBase = 0;
__int64 *pLastSetGateList = 0;
__int32 fDeletionsPass = 0, nMinRunwayLen = 1500;
BOOL fIncludeWater = FALSE, fMarkJetways = FALSE, fDebugThisEntry = FALSE;;
BOOL fNoDrawHoldConvert = TRUE; // ### 4900
RWYLIST *prwyPrevious = 0;
/******************************************************************************
Data
******************************************************************************/
char *pszParkType[] =
{ "", "Parking", "N Park", "NE Park", "E Park", "SE Park",
"S Park", "SW Park", "W Park", "NW Park", "Gate", "Dock" };
char *pszGateType[] =
{ "?", "GA Ramp", "GA Ramp Small", "GA Ramp Medium", "GA Ramp Large",
"Cargo Ramp", "Mil Cargo Ramp", "Mil Combat Ramp",
"Small Gate", "Medium Gate", "Heavy Gate", "GA Dock",
"?", "Vehicles", "?", "?" };
// runway surfaces
const char *szNRwySurf[] =
{
"Concrete", // 0
"Grass", // 1
"Water", // 2
"Unknown3", // 3
"Asphalt", // 4
"Unknown5", // 5
"Unknown6", // 6
"Clay", // 7
"Snow", // 8
"Ice", // 9
"Unknown10",// 10
"Unknown11",// 11
"Dirt", // 12
"Coral", // 13
"Gravel", // 14
"Oil-treated",// 15
"Mats", // 16
"Bituminous",// 17
"Brick", // 18
"Macadam", // 19
"Planks", // 20
"Sand", // 21
"Shale", // 22
"Tarmac", // 23
"Concrete", // 24 ###added 230719 (fiddle?)
};
char *pszComms[] = {
"", "ATIS", "MULTICOM", "UNICOM", "CTAF", "GROUND", "TOWER",
"CLEARANCE", "APPROACH", "DEPARTURE", "CENTRE", "FSS", "AWOS",
"ASOS", "CLR PRETAXI", "REM CLR DELIV", "???" };
// Conversion FS2004 to FS2002 surface codes
char chOldSurf[25] = {
2, 4, 10, 4, 3, 4, 4, 1, 8, 8, 2, 2,
1, 9, 5, 6, 7, 3, 11, 3, 12, 5, 5, 3, 0 }; // 11, 12 as 0 old, but okay for XML
/******************************************************************************
Assorted conversions
******************************************************************************/
static __int64 fslat2lat(__int32 ndblat, float *pf, double *pd)
{ double f = (((double)ndblat)*180)/MAXSOUTH;
if (f>90.0) f = -((f-180)+90);
else f = 90-f;
if (pd) *pd = f;
if (pf) *pf = (float) f;
return (__int64) ((f * 10001750.0) / 90.0);
}
static __int64 fslon2lon(__int32 ndblon, float *pf, double *pd)
{ double f = (((double)ndblon)*360)/MAXEAST;
f -= 180;
if (pd) *pd = f;
if (pf) *pf = (float) f;
return (__int64) ((f * 65536.0 * 65536.0) / 360.0);
}
static void str_rev(char *string)
{ DWORD i, j;
DWORD length = strlen(string); /* Number of characters in string */
char temp;
for (i = 0, j = length-1; /* Counting from front and rear */
i < length / 2; i++, j--)
{ /* until we reach the middle */
temp = string[i]; /* Save front character */
string[i] = string[j]; /* Switch with rear character */
string[j] = temp; /* Copy new rear character */
}
}
static void DecodeID(DWORD number, char *p, BOOL fShift)
{ char r, c;
char *p1 = p;
DWORD q = fShift ? (number >> 5) : number;
for (; q>0; q/=38)
{ r = (char)(q % 38);
c = (r<12) ? r+46 : r+53;
*p++ = c;
}
*p = 0;
if (!*p1)
{ *p1='0';
*++p1= 0;
}
else
str_rev(p1);
}
/******************************************************************************
MakeHelipadsFile
******************************************************************************/
HELI helipads[10000];
__int32 nHelipadCtr = 0;
__int32 hcompare(const void *arg1, const void *arg2)
{ HELI *h1 = (HELI *) arg1;
HELI *h2 = (HELI *) arg2;
return _strnicmp(h1->chICAO, h2->chICAO, 4);
}
void MakeHelipadsFile(void)
{ FILE *phf = fopen("helipads.csv", "wb");
__int32 i = 0;
if (phf)
{ if (nHelipadCtr > 1)
// First sort array into ICAO order
qsort((void *) &helipads[0], (size_t) nHelipadCtr,
sizeof(HELI), hcompare);
while (i < nHelipadCtr)
{ if (helipads[i].fDelete == 0)
fprintf(phf, "%.4s,%.6f,%.6f,%.0f,%.1f,%d,%d,%d,%d\n",
helipads[i].chICAO, helipads[i].fLat, helipads[i].fLong,
helipads[i].fAlt, helipads[i].fHeading,
helipads[i].sLen, helipads[i].sWidth,
helipads[i].bSurface, helipads[i].bFlags);
i++;
}
fclose(phf);
}
}
void DeleteHelipads(char *pchICAO)
{ __int32 i = 0;
while (i < nHelipadCtr)
{ if (strncmp(helipads[i].chICAO, pchICAO, 4) == 0)
helipads[i].fDelete = 255;
i++;
}
}
/******************************************************************************
DoHelipadOnly
******************************************************************************/
void DoHelipadOnly(helipad_t* ph, char *pszICAO)
{ static char *pszFlags[5] = { "", "H", "Square", "Circle", "Medical" };
static char szPrevICAO[5];
char chWork[64];
double dLat, dLon;
HELI *phs = &helipads[nHelipadCtr++];
*((DWORD *) (&phs->chICAO[0])) = *((DWORD *) pszICAO);
phs->bFlags = ph->bFlags;
phs->bSurface = ph->bSurface;
phs->fAlt = ((float) ph->nAlt)*3.28084F/1000;
phs->fHeading = ph->fHeading;
phs->sLen = (unsigned short) ((ph->fLength * 3.28084) + 0.5);
phs->sWidth = (unsigned short) ((ph->fWidth * 3.28084) + 0.5);
fslat2lat(ph->nLat, &phs->fLat, &dLat);
fslon2lon(ph->nLon, &phs->fLong, &dLon);
phs->fDelete = 0;
sprintf(chWork, "UNKNOWN %d", ph->bSurface);
if (strncmp(pszICAO, szPrevICAO, 4) != 0)
fprintf(fpAFDS, "\n");
strncpy(szPrevICAO, pszICAO, 5);
fprintf(fpAFDS, " HELIPAD at %s: %s %s %s",
pszICAO, pszFlags[ph->bFlags & 0x0f],
ph->bFlags & 0x10 ? "transparent" : "",
ph->bFlags & 0x20 ? "closed" : "");
fprintf(fpAFDS, "\n Surface=%s, Lat=%.6f, Lon=%.6f, Alt=%.0fft",
ph->bSurface > 24 ? chWork : szNRwySurf[ph->bSurface],
dLat, dLon, (double) phs->fAlt);
fprintf(fpAFDS, "\n Length=%dft, Width=%dft, Heading=%.1fT\n\n",
phs->sLen, phs->sWidth, (double) ph->fHeading);
}
/******************************************************************************
PrintRWSLIST
******************************************************************************/
void PrintRWSLIST(RWYLIST *pL)
{ static char *pszDels[] = { "Runway", "DelRwy", "DelSta", "DelBth" };
if (memcmp(&pL->r.chICAO[4], "99", 2))
{ fprintf(fpAFDS, "\n *** %s *** %.8s Lat %.6f Long %.6f Alt %.2f Hdg %d Len %d Wid %d",
pszDels[-pL->fDelete],
pL->r.chICAO,
(double) pL->r.fLat,
(double) pL->r.fLong,
pL->r.fAlt,
pL->r.uHdg,
pL->r.uLen,
pL->r.uWid);
if (pL->r.chILS[1])
fprintf(fpAFDS, " ILS %.6s%s%s%s%s", pL->r.chILS,
(pL->fILSflags & 0x1C) ? ", Flags:" : "",
(pL->fILSflags & 0x08) ? " GS" : "",
(pL->fILSflags & 0x10) ? " DME" : "",
(pL->fILSflags & 0x04) ? " BC" : "");
}
}
/******************************************************************************
ProcessRunwayList
******************************************************************************/
void ProcessRunwayList(RWYLIST *pL, BOOL fAdd, BOOL fNoCtr)
{ BOOL fDelAll = (fAdd <= 0) && !pL->r.chRwy[0] && !pL->fAirport;
__int32 nCompLen = fDelAll ? 4 : 8;
// First, standardise chICAO 4 chars: ###4692
if (pL->r.chICAO[3] == ' ') pL->r.chICAO[3] = 0;
if ((fAdd > 0) && !pL->fAirport && !pL->pGateList && !pL->pTaxiwayList) PrintRWSLIST(pL);
if (fDebugThisEntry)
{ if (strncmp(pL->r.chRwy, "999", 3) == 0)
fprintf(fpAFDS,"\nAdded %.4s entry for Gates\n", pL->r.chICAO);
else if (strncmp(pL->r.chRwy, "998", 3) == 0)
fprintf(fpAFDS,"\nAdded %.4s entry for Taxiways\n", pL->r.chICAO);
}
// Now link it in at correct place: (or find it if deleting)
if (pRlast == NULL)
pRlast = pR;
if (pR == NULL)
{ if (fAdd <= 0) return; // deleting when no runways yet!
pR = pRlast = pL;
ulTotalRwys++;
}
else
{ __int32 fDir = 0;
if (fAdd <= 0) pRlast = pR; // deletes need search from start
while (pRlast)
{ __int32 comp = memcmp(&pRlast->r, &pL->r, nCompLen);
if (fUserAbort) return;
if (fNewAirport && (memcmp(&pRlast->r, &pL->r, 4) == 0))
{ ulTotalAPs--;
fNewAirport = FALSE;
}
if (comp == 0) // Duplicate (or found one to delete)
{ if (fAdd > 0)
{ // Copy in new data and then discard alloc!
// NB Except for gates and taxiways, when keep first ones if exist
// But keep ILS/ATIS if the new one hasn't got it or it is < 118.00!
if (pL->r.chILS[1] == 0)
{ memcpy(pL->r.chILS, pRlast->r.chILS, sizeof(pL->r.chILS));
memcpy(pL->r.chILSHdg, pRlast->r.chILSHdg, sizeof(pL->r.chILSHdg));
pL->fILSflags = pRlast->fILSflags;
}
if (pL->Atis < 0x1800)
pL->Atis = pRlast->Atis;
memcpy(&pRlast->r, &pL->r, sizeof(RWYDATA));
pRlast->fHdg = pL->fHdg;
pRlast->nOffThresh = pL->nOffThresh;
pRlast->fMagvar = pL->fMagvar;
pRlast->fLat = pL->fLat;
pRlast->fLong = pL->fLong;
if (pRlast->fDelete && !fNoCtr)
{ ulTotalRwys++;
}
pRlast->fDelete = 0;
pRlast->fCL = pL->fCL;
pRlast->fCTO = pL->fCTO;
if (!pRlast->pGateList)
pRlast->pGateList = pL->pGateList;
if (!pRlast->pTaxiwayList)
pRlast->pTaxiwayList = pL->pTaxiwayList;
pRlast->fILSflags = pL->fILSflags;
if (!fMSFS || !(pRlast->pPathName && (strstr(pL->pPathName, "fs-base-nav"))))
// Retain previous pathname if new one only MSFS NAV additions
pRlast->pPathName = pL->pPathName;
if (!fMSFS || !(pRlast->pSceneryName && (strstr(pL->pSceneryName, "fs-base-nav"))))
// Retain previous title if new one only MSFS NAV additions
pRlast->pSceneryName = pL->pSceneryName;
if (strncmp(pL->r.chRwy, "999", 3) == 0)
prwyPrevious = pRlast;
free(pL);
break;
}
// Deletion:
// Just mark it for omission
if (!fDelAll || ((pRlast->pGateList == 0) && (pRlast->pTaxiwayList == 0)))
{ if (!pRlast->fDelete)
{ if (!pRlast->fAirport && (pRlast->pGateList == 0) && (pRlast->pTaxiwayList == 0))
{ ulTotalRwys--;
}
pRlast->fDelete = fAdd-1;
}
else if (pRlast->fDelete != fAdd-1)
pRlast->fDelete = -3;
}
if (pRlast->pGateList) free(pRlast->pGateList);
if (pRlast->pTaxiwayList) free(pRlast->pTaxiwayList);
pRlast->pGateList = 0;
pRlast->pTaxiwayList = 0;
if (!pRlast->fAirport)
{ PrintRWSLIST(pRlast);
fprintf(fpAFDS, "\n");
}
fDir = 1;
pRlast = pRlast->pTo;
}
if (comp < 0)
{ // Goes later
if ((fDir < 0) || !pRlast->pTo)
{ // Insert after last
if (fAdd <= 0) break;
pL->pFrom = pRlast;
pL->pTo = pRlast->pTo;
if (pL->pTo) pL->pTo->pFrom = pL;
pRlast->pTo = pL;
pRlast = pL;
if (!pL->fAirport && (pL->pGateList == 0) && (pL->pTaxiwayList == 0))
{ ulTotalRwys++;
}
if (strncmp(pL->r.chRwy, "999", 3) == 0)
prwyPrevious = pRlast;
break;
}
fDir = 1;
pRlast = pRlast->pTo;
}
else if (comp > 0)
{ // Goes earlier
if ((fDir > 0) || !pRlast->pFrom)
{ // Insert before last
if (fAdd <= 0) break;
pL->pFrom = pRlast->pFrom;
pL->pTo = pRlast;
pRlast->pFrom = pL;
if (pL->pFrom) pL->pFrom->pTo = pL;
else pR = pL;
pRlast = pL;
if (!pL->fAirport && (pL->pGateList == 0) && (pL->pTaxiwayList == 0))
{ ulTotalRwys++;
}
if (strncmp(pL->r.chRwy, "999", 3) == 0)
prwyPrevious = pRlast;
break;
}
fDir = -1;
pRlast = pRlast->pFrom;
}
}
}
fNewAirport = FALSE;
}
/******************************************************************************
AddRunway
******************************************************************************/
void AddRunway(RWYLIST *prwy)
{ RWYLIST *pL = (RWYLIST *) malloc(sizeof(RWYLIST)), *pRes = 0;
if (pL)
{ memcpy(pL, prwy, sizeof(RWYLIST));
ProcessRunwayList(pL, TRUE, 0);
if (!pL->fAirport) fFS9 = 1; // Stay in >=FS9 mode
}
}
/******************************************************************************
SetLocPos
******************************************************************************/
void SetLocPos(LOCATION *pLoc, __int32 alt, __int32 lat, __int32 lon, float *pflat, float *pflon, double *pdLat, double *pdLon)
{ DWORD wk;
pLoc->elev = (__int32) ((alt * 65536.0) / 1000.0);
*((__int64 *) &pLoc->lat.f) = fslat2lat(lat, pflat, pdLat);
wk = (DWORD) pLoc->lat.f;
pLoc->lat.i = (__int32) pLoc->lat.f;
pLoc->lat.f = wk;
*((__int64 *) &pLoc->lon.f) = fslon2lon(lon, pflon, pdLon);
wk = (DWORD) pLoc->lon.f;
pLoc->lon.i = (__int32) pLoc->lon.f;
pLoc->lon.f = wk;
}
/******************************************************************************
StoreName
******************************************************************************/
void StoreName(char *psz, NNAM *pName)
{ psz[0] = 0;
if (pName->nLen > 6)
{ __int32 nlen = min(pName->nLen-6, 255);
memcpy(psz, pName->chName, nlen);
while (nlen && !isalnum((unsigned char) psz[nlen - 1])) nlen--;
psz[nlen] = 0;
}
}
/******************************************************************************
HdgDiff
******************************************************************************/
float HdgDiff(float f1, float f2)
{ float fres = (float) fabs(f1 - f2);
if (fres > 180.0F) fres = 360.0F - fres;
return fres;
}
/******************************************************************************
NewILSs
******************************************************************************/
BOOL fMatchedILS = FALSE, fFoundSome = FALSE;
__int32 nOffsetILS, nSizeILS;
char chNameILS[256];
float fILSheading, fILSslope, fRange2;
// Mode 0 = Match ID & Dir
// 1 = Match Name & Dir & Range
// -1 = List all by Range
__int32 NewILSs(NILS *pi, DWORD size, char *psz, RWYLIST *prwy, __int32 nMode)
{ char chId[16], chRwy[6], *pch;
NILS *pi2;
DWORD size2;
BOOL fInRange = FALSE;
fMatchedILS = FALSE;
chNameILS[0] = 0;
while ((size > 6) && (size >= pi->nLen))
{ __int32 nThisLen = sizeof(NILS);
if (fUserAbort) return 0;
if ((pi->wId == OBJTYPE_VOR) && (pi->bType == 4))
{ // ILS record found
BOOL fMatchID;
nThisLen = pi->nLen;
fILSheading = pi->loc.fHeading;
fILSslope = (pi->loc.nRec0014 == 0x0015) ? ((NILSGS *) &pi->loc.nRec0014)->fGSpitch :
*((WORD *) ((BYTE *) &pi->loc.fWidth + 4)) == 0x0015 ?
((NILSGS *) ((BYTE *) &pi->loc.fWidth + 4))->fGSpitch : 0.00F;
nOffsetILS = (__int32) &pi->wId - nOffsetBase;
nSizeILS = pi->nLen;
DecodeID(pi->nId, chId, 1);
fMatchID = _stricmp(chId, psz) == 0;
if (fMatchID && (HdgDiff(pi->loc.fHeading, prwy->fHdg) < 40.0))
{ prwy->fILSflags = pi->bFlags;
fMatchedILS = TRUE;
fInRange = TRUE;
}
if (nMode && prwy)
{ // Check range
LOCATION loc;
float fLat, fLon, fWk1, fWk2;
SetLocPos(&loc, pi->nAlt, pi->nLat, pi->nLon, &fLat, &fLon, 0 ,0);
fWk1 = fLat - prwy->fLat;
fWk2 = (float) ((fLon - prwy->fLong) * cos((fLat + prwy->fLat)* PI / 360.0));
fRange2 = (fWk1*fWk1) + (fWk2*fWk2);
fInRange = fRange2 < 0.0025F; // 3.0nm = 1/20th degree = ^2
}
fFoundSome |= fInRange;
if (fInRange && (nMode < 2))
{ // look for the name
size2 = size - sizeof(NILS);
pi2 = (NILS *) ((BYTE *) pi + sizeof(NILS));
// Set up proper runway name for comparison
pch = &prwy->r.chRwy[0];
if (*pch == '0') pch++;
chRwy[0] = pch[0];
chRwy[1] = pch[1];
chRwy[2] = chRwyT[pch[2] & 3];
chNameILS[0] = 0;
while ((size2 > 6) && (size2 >= pi2->nLen))
{ if (pi2->wId == OBJTYPE_NAME)
{ StoreName(chNameILS, (NNAM *) pi2);
if ((nMode == 0) && fMatchedILS)
{ prwy->r.fILSslope = fILSslope;
return pi->nFreq;
}
if (nMode == 1)
{ //pch = strrchr(chNameILS, ' ');
//if ((pch && strncmp(&pch[1], chRwy, strlen(pch+1)) == 0)
// && (HdgDiff(pi->loc.fHeading, prwy->fHdg) < 80.0))
if (HdgDiff(pi->loc.fHeading, prwy->fHdg) < 80.0)
{ prwy->fILSflags = pi->bFlags;
strcpy(psz, chId);
fMatchedILS = fMatchID;
return pi->nFreq;
}
}
break;
}
if ((pi2->wId != OBJTYPE_ILSADD) &&
(pi2->wId != OBJTYPE_GS) &&
(pi2->wId != OBJTYPE_DME))
break;
size2 -= pi2->nLen;
pi2 = (NILS *) ((BYTE *) pi2 + pi2->nLen);
}
}
/*if (fInRange) // && (nMode < 0))
{ fprintf(fpAFDS, "\n ");
fprintf(fpAFDS, "ILS ID=%s: Freq %.2f Heading %.1f (%s), Range %.2f, Slope %.2f \x22%s\x22",
chId, (double) (pi->nFreq / 1000000.0),
(double) pi->loc.fHeading,
(pi->loc.bEnd & 16) ? "Secondary" : "Primary",
60.0 * sqrt((double) fRange2),
(double) fILSslope,
chNameILS);
}*/
}
else
nThisLen = pi->nLen;
size -= nThisLen;
pi = (NILS *) ((BYTE *) pi + nThisLen);
}
if (prwy && (nMode >= 0)) prwy->fILSflags = 0;
return 0;
}
/******************************************************************************
MatchILS
******************************************************************************/
__int32 MatchILS(DWORD nObjs, NSECTS *ps, BYTE *p, char *psz, RWYLIST *prwy, __int32 nMode)
{ // Look for VORs (ILSs)
DWORD i, j;
for (i = 0; i < nObjs; i++)
{ DWORD offs = ps[i].nGroupOffset;
if (fUserAbort) return 0;
for (j = 0; j < ps[i].nGroupsCount; j++)
{ if (ps[i].nObjType == OBJTYPE_VOR)
{ NOBJ *po = (NOBJ *) &p[offs];
__int32 nFreq = NewILSs((NILS *) &p[po->chunkoff], po->chunksize, psz, prwy, nMode);
if (nFreq)
return (nFreq + 5000) / 10000;
}
offs += sizeof(NOBJ);
}
}
return 0;
}
/******************************************************************************
FindStart
******************************************************************************/
BOOL FindStart(RWYLIST *prwy, NAPT *pa, DWORD size, char *psz)
{ LOCATION loc;
char chWk[16];
RWYLIST *pL;
while ((size > 6) && (size >= pa->nLen))
{ __int32 nThisLen = pa->nLen;
if (fUserAbort) return 0;
if (pa->wId == OBJTYPE_START)
{ // Start record found
NSTART *ps = (NSTART *) pa;
nThisLen = ps->nLen;
if ((ps->des >> 4) == 1)
{ // Runway start
DecodeRwy(ps->num, ps->des & 15, chWk, 0, sizeof(chWk));
if (strcmp(chWk, psz) == 0)
{ fprintf(fpAFDS, " Start %s: ", chWk);
SetLocPos(&loc, ps->nAlt, ps->nLat, ps->nLon, &prwy->r.fLat, &prwy->r.fLong, 0, 0);
WritePosition(&loc, 1);
fprintf(fpAFDS, " Hdg: %.1fT, Length %dft \n", (double) ps->fHeading, prwy->r.uLen);
return TRUE;
}
}
}
size -= nThisLen;
pa = (NAPT *) ((BYTE *) pa + nThisLen);
}
// See if there's an undeleted start from a previous scenery file
pL = pR;
while (pL)
{ if (fUserAbort) return FALSE;
if ((memcmp(&prwy->r, &pL->r, 8) == 0) && (pL->fDelete == -1))
{ // Found one without start deleted!
fprintf(fpAFDS, " Start %s re-used from previous deleted runway\n", psz);
prwy->r.fLat = pL->r.fLat;
prwy->r.fLong = pL->r.fLong;
prwy->nOffThresh = pL->nOffThresh;
return TRUE;
}
pL = pL->pTo;
}
return FALSE;
}
/******************************************************************************
DebugRwyAdditions
******************************************************************************/
// Type = 5 for primary, 6 for secondary
void DebugRwyAdditions(NAPT * pa, DWORD size)
{ while ((size > 6) && (size >= pa->nLen))
{ __int32 nThisLen = pa->nLen, i = 0, x, j;
char wk[256];
BYTE* pb = (BYTE *) pa;
if (fUserAbort) return;
fprintf(fpAFDS, "### AFTER RWY: at OFFSET %08X ID=%04X LEN=%d\n",
(__int32) ((BYTE *) &pa->wId - nOffsetBase), pa->wId, nThisLen);
j = nThisLen;
while (j--)
{ if ((i & 15) == 0)
x = sprintf(wk, " %04X:", i);
x += sprintf(&wk[x], " %02X", *pb++);
if (((++i & 15) == 0) || (j == 0))
{ fprintf(fpAFDS, "%s\n", wk);
x = 0;
}
}
if (nThisLen == 0) break; // Safety precaution (why needed?)
size -= nThisLen;
pa = (NAPT*)((BYTE*)pa + nThisLen);
}
}
/******************************************************************************
FindOffThresh
******************************************************************************/
// Type = 5 for primary, 6 for secondary: negative for MSFS (my conventio)
BOOL FindOffThresh(RWYLIST* prwy, NAPT* pa, DWORD size, short int nType)
{
while ((size > 6) && (size >= pa->nLen))
{ __int32 nThisLen = pa->nLen;
if (fUserAbort) return 0;
prwy->nOffThresh = 0;
if ((pa->wId == nType) || (pa->wId == -nType))
{ // Threshold record found
NOFFTHR *ps = (NOFFTHR *) ((BYTE *) pa + ((nType < 0) ? 16 : 0));
nThisLen = pa->nLen;
prwy->nOffThresh = (unsigned __int32) ((ps->fLength * 3.28084F) + .5F);
fprintf(fpAFDS, " Offset Threshold %s: %d feet\n",
(abs(nType) == 5) ? "primary" : "secondary", prwy->nOffThresh);
return TRUE;
}
if (nThisLen == 0) break; // Safety precaution (why needed?)
size -= nThisLen;
pa = (NAPT *) ((BYTE *) pa + nThisLen);
}
return FALSE;
}
/******************************************************************************
FindVASI
******************************************************************************/
// Type = 11 for primary left, 12 for primary right, 13 sec left, 14 sec right
BOOL FindVASI(RWYLIST *prwy, NAPT *pa, DWORD size, WORD nType)
{ while (pa->nLen && (size > 6) && (size >= pa->nLen))
{ __int32 nThisLen = pa->nLen;
if (fUserAbort) return 0;
// ########## ??? prwy->nOffThresh = 0;
if (pa->wId == nType)
{ // Start record found
vasi_t *ps = (vasi_t *) pa;
nThisLen = ps->nLen;
if (nType & 1)
{ prwy->r.bVASIleft = (BYTE) ps->wType;
prwy->r.fLeftBiasX = ps->fBiasX;
prwy->r.fLeftBiasZ = ps->fBiasZ;
prwy->r.fLeftSpacing = ps->fSpacing;
prwy->r.fLeftPitch = ps->fPitch;
}
else
{ prwy->r.bVASIright = (BYTE) ps->wType;
prwy->r.fRightBiasX = ps->fBiasX;
prwy->r.fRightBiasZ = ps->fBiasZ;
prwy->r.fRightSpacing = ps->fSpacing;
prwy->r.fRightPitch = ps->fPitch;
}
return TRUE;
}
size -= nThisLen;
pa = (NAPT *) ((BYTE *) pa + nThisLen);
}
return FALSE;
}
/******************************************************************************
FindAppLights
******************************************************************************/
// Type = 15 primary, 16 secondary, or 0xDF, 0xE0 for MSFS
BOOL FindAppLights(RWYLIST *prwy, NAPT *pa, DWORD size, WORD nType)
{ while ((size > 6) && (size >= pa->nLen))
{ __int32 nThisLen = pa->nLen;
if (fUserAbort) return 0;
// ########## ??? prwy->nOffThresh = 0;
if (pa->wId == nType)
{ // Applights record found
approachlights_t *ps = (approachlights_t *) pa;
nThisLen = ps->nLen;
prwy->r.bAppLights = ps->bFlags;
prwy->r.nStrobes = ps->bStrobes;
return TRUE;
}
size -= nThisLen;
pa = (NAPT *) ((BYTE *) pa + nThisLen);
}
return FALSE;
}
/******************************************************************************
WriteFSM
******************************************************************************/
void WriteFSM(RWYLIST *pAp)
{ RWYLIST *pL = (RWYLIST *) malloc(sizeof(RWYLIST));
if (pL)
{ memcpy(pL, pAp, sizeof(RWYLIST));
pAp->fAirport = 0;
pAp->Atis = 0;
fprintf(fpAFDS, " FSM A/P %4s, lat=%.6f, long=%.6f, alt=%.2f\n",
pAp->r.chICAO, (double) pAp->r.fLat, (double) pAp->r.fLong, pAp->r.fAlt);
ProcessRunwayList(pL, TRUE, TRUE);
}
}
/******************************************************************************
MakeTaxiwayList
******************************************************************************/
TWHDR *MakeTaxiwayList(NTAXIPT *pT, NTAXINM *pN, NTAXI *pP, WORD wT, WORD wN, WORD wP)
{ WORD wo = wN, w2;
__int32 wp1, wp2;
__int32 nAllocSize = (40*wP) + (32*wT*wP);
TWHDR *twh = (TWHDR *) malloc(nAllocSize);
TWHDR *twh0 = twh;
WORD wGateCtr = 0;
NGATE **ppg;
NGATE2 **ppg2;
LOCATION locg;
if (pLastSetGateList)
{ wGateCtr = (WORD) (*pLastSetGateList & 0xffff);
ppg = (NGATE **) &pLastSetGateList[1];
ppg2 = (NGATE2 **) (
(((*pLastSetGateList >> 16) == OBJTYPE_NEWTAXIPARK) ||
((*pLastSetGateList >> 16) == OBJTYPE_MSFSTAXIPARK)) ? ppg : 0); // ############### MSFSTAXIPARK ?? #########
}
if (!twh)
{ fprintf(fpAFDS, " ##### Error making Taxiway list: Need %d bytes memory block, not available!\n (%d Points, %d Paths, %d Names)\n",
nAllocSize, wT, wP, wN);
return 0;
}
while (wo)
{ WORD wMin = 0, wF = 0xffff;
WORD w = 0, wPts = 0;
BOOL fDone = FALSE;
TW *tw = (TW *) &twh[1];
while (w < wN)
{ // Find next lowest taxiway name
if (pN[w].szName[0] != 0xFF)
{ if (w && (strncmp(pN[wMin].szName, pN[w].szName, 8) >= 0))
wMin = w;
fDone = TRUE;
}
w++;
}
if (!fDone) break; // All done now
memcpy(twh->chName, pN[wMin].szName, 8);
twh->fMaxWid = 0.0F;
twh->fMinWid = 3000000.0F;
twh->wPoints = wPts;
// Search for 1st point in chained path fragment
for (w = 0; w < wP; w++)
{ if ((pP[w].bNumber == wMin) &&
( (((pP[w].bDrawFlags == 1) || (pP[w].bDrawFlags == 4)) && // #T# TAXIWAY TYPE #T#
(pP[w].wEnd < wT) && (pP[w].wStart < wT)) ||
((pP[w].bDrawFlags == 3) &&
(pP[w].wEnd < wGateCtr) && (pP[w].wStart < wT))
))
{ BOOL f1seen = FALSE;
BOOL f2seen = FALSE;
wp2 = (pP[w].bDrawFlags == 3) ? -(pP[w].wEnd + 1) : pP[w].wEnd;
wp1 = pP[w].wStart;
// See if this has a lone end
for (w2 = 0; w2 < wP; w2++)
{ if ((pP[w2].bNumber == wMin) && (w2 != w) &&
( (((pP[w].bDrawFlags == 1) || (pP[w].bDrawFlags == 4)) && // #T# TAXIWAY TYPE #T#
(pP[w].wEnd < wT) && (pP[w].wStart < wT)) ||
((pP[w].bDrawFlags == 3) &&
(pP[w].wEnd < wGateCtr) && (pP[w].wStart < wT))
))
{ if ((pP[w2].wStart == wp1) || (pP[w2].wEnd == wp1))
f1seen = TRUE;
if ((pP[w2].wStart == wp2) || (pP[w2].wEnd == wp2))
f2seen = TRUE;
if (f1seen && f2seen)
break;
}
}
wF = w;
if (!f1seen || !f2seen)
{ if (f1seen)
{ __int32 wrk = wp1;
wp1 = wp2;
wp2 = wrk;
}
break;
}
}
}
if (wF != 0xffff)
{ // Start found, maybe (else circular or multiple)
WORD wStart = wp1;
char szTaxiway[9];
szTaxiway[8] = 0;
w = wF;
if (wp1 >= 0)
{ tw[wPts].bOrientation = pT[wp1].bOrientation;
tw[wPts].bType = pT[wp1].bType;
if (fNoDrawHoldConvert && (pT[wp1].bType == 5))
// Convert "no draw" holds to normal types ### 4880
tw[wPts].bType = 7;
tw[wPts].fLat = pT[wp1].fLat;
tw[wPts].fLon = pT[wp1].fLon;
}
else
{ __int32 wp1x = (-wp1) - 1;
SetLocPos(&locg, 0,
ppg2 ? (*(ppg2[wp1x])).nLat : (*(ppg[wp1x])).nLat,
ppg2 ? (*(ppg2[wp1x])).nLon : (*(ppg[wp1x])).nLon,
&tw[wPts].fLat, &tw[wPts].fLon, 0, 0);
tw[wPts].bOrientation = 0;
tw[wPts].bType = 5;
}
tw[wPts].fWid = pP[wF].fWidth;
tw[wPts].bPtype = pP[w].bDrawFlags; // Path type
twh->fMaxWid = twh->fMinWid = pP[w].fWidth;
// if (pP[w].bDrawFlags != 1) twh->chName[0] = 0;// No names for non-taxi. #T#
wPts++;
strncpy(szTaxiway, twh->chName, 8);
if (wp1 >= 0)
fprintf(fpAFDS, " TaxiWay %s: %d", szTaxiway, wp1);
else
fprintf(fpAFDS, " TaxiWay %s: G%d", szTaxiway, (-wp1)-1);
// Set next point and find further reference
while (1)
{ if (wp2 >= 0)
{ tw[wPts].bOrientation = pT[wp2].bOrientation;
tw[wPts].bType = pT[wp2].bType;
if (fNoDrawHoldConvert && (pT[wp2].bType == 5))
// Convert "no draw" holds to normal types ### 4880
tw[wPts].bType = 7;
tw[wPts].fLat = pT[wp2].fLat;
tw[wPts].fLon = pT[wp2].fLon;
}
else
{ __int32 wp2x = (-wp2)-1;
SetLocPos(&locg, 0,
ppg2 ? (*(ppg2[wp2x])).nLat : (*(ppg[wp2x])).nLat,