00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00028 #include "../Include/FlyLegacy.h"
00029 #include "../Include/Database.h"
00030 #include "../Include/Globals.h"
00031 #include "../Include/Endian.h"
00032
00033
00034 static void DecodeAirportRecord (char* rec, SAirport *airport)
00035 {
00036
00037 unsigned long i;
00038 double d;
00039 char c;
00040
00041 strncpy (airport->airportKey, rec+4, 10);
00042 strncpy (airport->faaID, rec+14, 4);
00043 strncpy (airport->icaoID, rec+18, 5);
00044
00045 i = *(unsigned long*)(rec+89);
00046 i = LittleEndian (i);
00047 airport->type = i;
00048
00049 strncpy (airport->name, rec+23, 40);
00050 strncpy (airport->country, rec+63, 3);
00051 strncpy (airport->state, rec+66, 3);
00052 strncpy (airport->county, rec+69, 20);
00053 strcpy (airport->city, "");
00054
00055 i = *(unsigned long*)(rec+109);
00056 i = LittleEndian (i);
00057 airport->elevation = i;
00058
00059 i = *(unsigned long*)(rec+113);
00060 i = LittleEndian (i);
00061 airport->ownership = i;
00062
00063 i = *(unsigned long*)(rec+117);
00064 i = LittleEndian (i);
00065 airport->usage = i;
00066
00067 d = *(double*)(rec+166);
00068 d = LittleEndian (d);
00069
00070 airport->magneticVariation = d;
00071
00072 d = *(double*)(rec+174);
00073 d = LittleEndian (d);
00074
00075 airport->trafficAltitude = d;
00076
00077 c = *(rec+178);
00078 airport->fssAvailable = c;
00079
00080 c = *(rec+179);
00081 airport->notamAvailable = c;
00082
00083 c = *(rec+180);
00084 airport->atcAvailable = c;
00085
00086 c = *(rec+181);
00087 airport->segmentedCircle = c;
00088
00089 c = *(rec+182);
00090 airport->landingFeesCharged = c;
00091
00092 c = *(rec+183);
00093 airport->jointUseAirport = c;
00094
00095 c = *(rec+184);
00096 airport->militaryLandingRights = c;
00097
00098 c = *(rec+185);
00099 airport->customsEntryPoint = c;
00100
00101 i = *(unsigned long*)(rec+186);
00102 i = LittleEndian (i);
00103
00104 airport->fuelTypes = i;
00105
00106 i = *(unsigned long*)(rec+190);
00107 i = LittleEndian (i);
00108
00109 airport->frameService = i;
00110
00111 i = *(unsigned long*)(rec+194);
00112 i = LittleEndian (i);
00113
00114 airport->engineService = i;
00115
00116 i = *(unsigned long*)(rec+198);
00117 i = LittleEndian (i);
00118
00119 airport->bottledOxygen = i;
00120
00121 i = *(unsigned long*)(rec+202);
00122 i = LittleEndian (i);
00123
00124 airport->bulkOxygen = i;
00125
00126 i = *(unsigned long*)(rec+206);
00127 i = LittleEndian (i);
00128
00129 airport->beaconLensColor = i;
00130
00131 i = *(unsigned long*)(rec+210);
00132 i = LittleEndian (i);
00133
00134 airport->basedAircraft = i;
00135
00136 i = *(unsigned long*)(rec+214);
00137 i = LittleEndian (i);
00138
00139 airport->annualCommercialOps = i;
00140
00141 i = *(unsigned long*)(rec+218);
00142 i = LittleEndian (i);
00143
00144 airport->annualGeneralAvOps = i;
00145
00146 i = *(unsigned long*)(rec+222);
00147 i = LittleEndian (i);
00148
00149 airport->annualMilitaryOps = i;
00150
00151 i = *(unsigned long*)(rec+226);
00152 i = LittleEndian (i);
00153
00154 airport->attendanceFlags = i;
00155
00156 i = *(unsigned long*)(rec+238);
00157 i = LittleEndian (i);
00158
00159 airport->lightingFlags = i;
00160
00161 d = *(double*)(rec+93);
00162 d = LittleEndian (d);
00163
00164 airport->pos.lat = d;
00165
00166 d = *(double*)(rec+101);
00167 d = LittleEndian (d);
00168
00169 airport->pos.lon = d;
00170
00171 airport->pos.alt = airport->elevation;
00172
00174 airport->runways = NULL;
00175 airport->comms = NULL;
00176
00177 airport->prev = NULL;
00178 airport->next = NULL;
00179 }
00180
00181
00182 static void DecodeNavaidRecord (char* rec, SNavaid *navaid)
00183 {
00184 strncpy (navaid->name, rec+19, 40);
00185 strncpy (navaid->id, rec+14, 5);
00186
00187
00188 unsigned long i;
00189 double d;
00190
00191 i = *(unsigned long*)(rec+89);
00192 i = LittleEndian (i);
00193
00194 navaid->type = i;
00195
00196 i = *(unsigned long*)(rec+93);
00197 i = LittleEndian (i);
00198
00199 navaid->classification = i;
00200
00201 i = *(unsigned long*)(rec+97);
00202 i = LittleEndian (i);
00203
00204 navaid->usage = i;
00205
00206 d = *(double*)(rec+101);
00207 d = LittleEndian (d);
00208
00209 navaid->pos.lat = d;
00210
00211 d = *(double*)(rec+109);
00212 d = LittleEndian (d);
00213
00214 navaid->pos.lon = d;
00215
00216 i = *(unsigned long*)(rec+117);
00217 i = LittleEndian (i);
00218
00219 navaid->pos.alt = i;
00220
00221 d = *(double*)(rec+59);
00222 d = LittleEndian (d);
00223
00224 navaid->freq = d;
00225
00226 i = *(unsigned long*)(rec+125);
00227 i = LittleEndian (i);
00228
00229 navaid->range = i;
00230
00231 d = *(double*)(rec+67);
00232 d = LittleEndian (d);
00233
00234 navaid->magneticVariation = d;
00235
00236 d = *(double*)(rec+75);
00237 d = LittleEndian (d);
00238
00239 navaid->slavedVariation = d;
00240
00241 navaid->prev = NULL;
00242 navaid->next = NULL;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251 int GetLocalNavaids(SNavaid **navaids)
00252 {
00253 int rc = 0;
00254
00255 *navaids = NULL;
00256 SNavaid *last = NULL;
00257
00258
00259 SPosition pos = globals->sit->GetUserVehicle()->GetPosition();
00260 int gtx, gtz;
00261 lat_lon_to_globe_tile (pos.lat/3600, pos.lon/3600, gtx, gtz);
00262
00264 int range = 3;
00265 for (int i=-range; i<=range; i++) {
00266 for (int j=-range; j<=range; j++) {
00267 int x = (gtx + j) % 256;
00268 int z = (gtz + i) % 256;
00269 SNavaid *temp = NULL;
00270 rc += SearchNavaidsByGlobeTile (x, z, &temp);
00271 if (temp != NULL) {
00272
00273 if (*navaids == NULL) {
00274
00275 *navaids = temp;
00276 } else {
00277
00278 temp->prev = last;
00279 last->next = temp;
00280 }
00281
00282 last = temp;
00283 while (last->next != NULL) last = last->next;
00284 }
00285 }
00286 }
00287
00288 return rc;
00289 }
00290
00291
00292
00293
00294
00295 int GetLocalILS(SILS **ils)
00296 {
00297 int rc = 0;
00298 return rc;
00299 }
00300
00301
00302
00303
00304
00305 int GetLocalComms(SComm **comms)
00306 {
00307 int rc = 0;
00308 return rc;
00309 }
00310
00311
00312
00313
00314
00315 int GetLocalCenters(SComm **comms)
00316 {
00317 int rc = 0;
00318 return rc;
00319 }
00320
00321
00322
00323
00324
00325 int GetLocalAirports(SAirport **airports)
00326 {
00327 int rc = 0;
00328 return rc;
00329 }
00330
00331
00332
00333
00334
00335 int GetLocalWaypoints(SWaypoint **waypoints)
00336 {
00337 int rc = 0;
00338 return rc;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356 int GetNearestNavaid(SPosition *pos, int navType, SNavaid *navaid, float *distanceInFeet)
00357 {
00358 int rc = 0;
00359
00360 return rc;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380 int GetNearestNavaidByFreq(SPosition *pos, int navType, float freq,
00381 SNavaid *navaid, float *distanceInFeet)
00382 {
00383 int rc = 0;
00384
00385 return rc;
00386 }
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403 int GetNearestILS(SPosition *pos, float freq, SILS *ils, float *distanceInFeet)
00404 {
00405 int rc = 0;
00406
00407 return rc;
00408 }
00409
00410
00411
00412
00413
00414 int GetNearestComm(SPosition *pos, float freq, SComm *comm, float *distanceInFeet)
00415 {
00416 int rc = 0;
00417
00418 return rc;
00419 }
00420
00421
00422
00423
00424
00425 int GetNearestAirportComm(SPosition *pos, float freq, SComm *comm, float *distanceInFeet)
00426 {
00427 int rc = 0;
00428
00429 return rc;
00430 }
00431
00432
00433
00434
00435
00436 int GetNearestCenterComm(SPosition *pos, float freq, SComm *comm, float *distanceInFeet)
00437 {
00438 int rc = 0;
00439
00440 return rc;
00441 }
00442
00443
00444
00445
00446
00447 int GetNearestAirport(SPosition *pos, SAirport *airport, float *distanceInFeet)
00448 {
00449 int rc = 0;
00450
00451 return rc;
00452 }
00453
00454
00455
00456
00457
00458 int InAirportRegion(SPosition *pos, float *distanceInFeet)
00459 {
00460 int rc = 0;
00461
00462 return rc;
00463 }
00464
00465
00466
00467
00468
00469 int GetAirport(char *airportKey, SAirport *airport)
00470 {
00471 int rc = 0;
00472
00473 return rc;
00474 }
00475
00476
00477
00478
00479
00480
00481 int SearchNavaidsByID(char *id, int navType, SNavaid **navaids)
00482 {
00483 int rc = 0;
00484
00485 return rc;
00486 }
00487
00488
00489
00490
00491
00492
00493 int SearchNavaidsByName(char *name, int navType, SNavaid **navaids)
00494 {
00495 int rc = 0;
00496
00497 return rc;
00498 }
00499
00500
00501
00502
00503
00504 int SearchNavaidsByGlobeTile (int x, int z, SNavaid **navaids)
00505 {
00506 int rc = 0;
00507 *navaids = NULL;
00508
00509 char key[16];
00510 sprintf (key, "%03d%03d", x, z);
00511 unsigned long offset = dbNavaid->Search ('nltl', key);
00512 if (offset != 0) {
00513
00514 int recLength = dbNavaid->GetRawRecordLength ();
00515 char *rec = new char[recLength];
00516 dbNavaid->GetRawRecord (offset, rec);
00517
00518
00519 SNavaid *first = new SNavaid;
00520 DecodeNavaidRecord (rec, first);
00521
00522
00523 *navaids = first;
00524 rc++;
00525
00526
00527 SNavaid *prev = first;
00528 while ((offset = dbNavaid->SearchNext ()) != 0) {
00529
00530 dbNavaid->GetRawRecord (offset, rec);
00531
00532
00533 SNavaid *next = new SNavaid;
00534 DecodeNavaidRecord (rec, next);
00535
00536
00537 next->prev = prev;
00538 prev->next = next;
00539 prev = next;
00540 }
00541
00542
00543 delete rec;
00544 }
00545
00546 return rc;
00547 }
00548
00549
00550
00551
00552
00553 int SearchWaypointsByName(char *name, SWaypoint **waypoints)
00554 {
00555 int rc = 0;
00556
00557 return rc;
00558 }
00559
00560
00561
00562
00563
00564 int SearchAirportsByFAA(char *faaID, SAirport **airports)
00565 {
00566 int rc = 0;
00567 *airports = NULL;
00568
00569
00570 unsigned long offset = dbAirport->Search ('aafa', faaID);
00571 if (offset != 0) {
00572
00573 int recLength = dbAirport->GetRawRecordLength ();
00574 char *rec = new char[recLength];
00575 dbAirport->GetRawRecord (offset, rec);
00576
00577
00578 SAirport *first = new SAirport;
00579 DecodeAirportRecord (rec, first);
00580
00581
00582 *airports = first;
00583 rc++;
00584
00586
00587
00588 delete rec;
00589 }
00590
00591 return rc;
00592 }
00593
00594
00595
00596
00597
00598 int SearchAirportsByICAO(char *icaoID, SAirport **airports)
00599 {
00600 int rc = 0;
00601 *airports = NULL;
00602
00603
00604 unsigned long offset = dbAirport->Search ('acia', icaoID);
00605 if (offset != 0) {
00606
00607 int recLength = dbAirport->GetRawRecordLength ();
00608 char *rec = new char[recLength];
00609 dbAirport->GetRawRecord (offset, rec);
00610
00611
00612 SAirport *first = new SAirport;
00613 DecodeAirportRecord (rec, first);
00614
00615
00616 *airports = first;
00617 rc++;
00618
00620
00621
00622 delete rec;
00623 }
00624
00625 return rc;
00626 }
00627
00628
00629
00630
00631
00632 int SearchAirportsByName(char *name, SAirport **airports)
00633 {
00634 int rc = 0;
00635
00637
00638 return rc;
00639 }
00640
00641
00642
00643
00644
00645
00646
00647 int SearchILS(char *airportKey, char *runwayEndID, SILS **ils)
00648 {
00649 int rc = 0;
00650
00652
00653 return rc;
00654 }
00655
00656
00657
00658
00659
00660
00661
00662
00663 int SearchDatabase(char *db, char *index, char *key, SGeneric **list)
00664 {
00665 int rc = 0;
00666
00668
00669 return rc;
00670 }
00671
00672
00673
00674
00675
00676 void FreeNavaid(SNavaid *navaids)
00677 {
00678 SNavaid *next = navaids;
00679
00680 while (next != NULL) {
00681 SNavaid *prev = next;
00682 next = next->next;
00683 delete prev;
00684 }
00685 }
00686
00687
00688
00689
00690
00691 void FreeILS(SILS *ils)
00692 {
00693 SILS *next = ils;
00694
00695 while (next != NULL) {
00696 SILS *prev = next;
00697 next = next->next;
00698 delete prev;
00699 }
00700 }
00701
00702
00703
00704
00705
00706 void FreeWaypoint(SWaypoint *waypoint)
00707 {
00708 SWaypoint *next = waypoint;
00709
00710 while (next != NULL) {
00711 SWaypoint *prev = next;
00712 next = next->next;
00713 delete prev;
00714 }
00715 }
00716
00717
00718
00719
00720
00721 void FreeComm(SComm *comm)
00722 {
00723 SComm *next = comm;
00724
00725 while (next != NULL) {
00726 SComm *prev = next;
00727 next = next->next;
00728 delete prev;
00729 }
00730 }
00731
00732
00733
00734
00735
00736 void FreeAirport(SAirport *airport)
00737 {
00738 SAirport *next = airport;
00739
00740 while (next != NULL) {
00741 SAirport *prev = next;
00742 next = next->next;
00743 delete prev;
00744 }
00745 }
00746
00747
00748
00749
00750
00751 void FreeGeneric(SGeneric *list)
00752 {
00753 SGeneric *next = list;
00754
00755 while (next != NULL) {
00756 SGeneric *prev = next;
00757 next = next->next;
00758 delete prev;
00759 }
00760 }
00761