00001
00002 #include "ReadInit.h"
00003 #include "Geom.h"
00004 #include "main.h"
00005 #include "texture.h"
00006
00007 int *CarList;
00008 int CarListSize = 0;
00009
00010 int WheelList[CAR_NWHEELS];
00011 int WheelListSize = 0;
00012
00013 int SpringList[CAR_NWHEELS];
00014 int SpringListSize = 0;
00015
00016 int AxleList[CAR_NWHEELS];
00017 int AxleListSize = 0;
00018
00019 int PinList[CAR_NWHEELS];
00020 int PinListSize = 0;
00021
00022 int ModelList[MAX_CAR_MODEL_TYPES];
00023 int ModelListSize = 0;
00024
00025 static char ErrorMessage[READ_MAX_WORDLEN];
00026
00028
00029
00030
00032
00033 bool ReadWord(char *buf, FILE *fp)
00034 {
00035 char *pChar = buf;
00036
00037
00038 while (isspace(*pChar = fgetc(fp)) || (*pChar == ',')) {
00039 }
00040
00041
00042 while (*pChar == READ_COMMENT_CHAR) {
00043
00044 while ((*pChar = fgetc(fp)) != '\n' && (*pChar != EOF)) {
00045 NULL;
00046 }
00047
00048
00049 if (*pChar != EOF) {
00050 while (isspace(*pChar = fgetc(fp))) {
00051 }
00052 }
00053 }
00054
00055
00056 if (*pChar == EOF) {
00057 buf[0] = NULL;
00058 return FALSE;
00059 }
00060
00061
00062 while (!isspace(*++pChar = fgetc(fp)) &&
00063 (*pChar != EOF) &&
00064 (*pChar != '{') &&
00065 (*pChar != '}') &&
00066 (*pChar != ','))
00067 {
00068 NULL;
00069 }
00070 ungetc(*pChar, fp);
00071 *pChar = '\0';
00072
00073 return TRUE;
00074 }
00075
00076
00078
00079
00080
00082
00083 bool ReadFileName(char *name, FILE *fp)
00084 {
00085 int iCh, nameLen;
00086 char delimiter;
00087 char *endOfName;
00088
00089
00090 if (!ReadWord(name, fp)) {
00091 ShowErrorMessage("Could not find file name");
00092 return FALSE;
00093 }
00094
00095
00096
00097 delimiter = name[0];
00098 endOfName = name + strlen(name);
00099 while (((delimiter == '\"') || (delimiter == '\'')) && (*(endOfName-1) != delimiter)) {
00100 while (isspace(*endOfName = fgetc(fp))) {
00101 endOfName++;
00102 }
00103 ungetc(*endOfName, fp);
00104 if (!ReadWord(endOfName, fp)) {
00105 ShowErrorMessage("Could not find file name");
00106 return FALSE;
00107 }
00108 endOfName = name + strlen(name);
00109 }
00110
00111
00112 if (delimiter == '\'' || delimiter == '\"') {
00113 nameLen = strlen(name);
00114 for (iCh = 0; iCh < nameLen - 2; iCh++) {
00115 name[iCh] = name[iCh+1];
00116 }
00117 name[nameLen - 2] = '\0';
00118 }
00119
00120
00121 if (Compare(name, "NULL") || Compare(name, "NONE") || Compare(name, "0")) {
00122 name[0] = '\0';
00123 }
00124
00125 return TRUE;
00126 }
00127
00128
00130
00131
00132
00134
00135 bool ReadInt(int *n, FILE *fp)
00136 {
00137 if (fscanf(fp, "%d", n) == EOF) {
00138 ShowErrorMessage("Could not read integer");
00139 return FALSE;
00140 } else {
00141 return TRUE;
00142 }
00143 }
00144
00145
00147
00148
00149
00151
00152 bool ReadBool(bool *b, FILE *fp)
00153 {
00154 char word[READ_MAX_WORDLEN];
00155
00156 *b = FALSE;
00157
00158 if (!ReadWord(word, fp)) {
00159 return FALSE;
00160 }
00161
00162 if (Compare(word, "TRUE") || Compare(word, "1") || Compare(word, "YES")) {
00163 *b = TRUE;
00164 }
00165 else if (Compare(word, "FALSE") || Compare(word, "0") || Compare(word, "NO")) {
00166 *b = FALSE;
00167 }
00168 else {
00169 return FALSE;
00170 }
00171
00172 return TRUE;
00173 }
00174
00175
00177
00178
00179
00181
00182 #if (defined(_PC) || defined(_N64))
00183 bool ReadReal(REAL *r, FILE *fp)
00184 {
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 char word[READ_MAX_WORDLEN];
00196
00197 if (!ReadWord(word, fp)) {
00198 return FALSE;
00199 } else {
00200 *r = (REAL)atof(word);
00201 return TRUE;
00202 }
00203 }
00204 #else
00205 bool ReadReal(REAL *r, FILE *fp)
00206 {
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217 char word[READ_MAX_WORDLEN];
00218
00219 if (!ReadWord(word, fp)) {
00220 return FALSE;
00221 } else {
00222 *r = ONE * atol(word);
00223 return TRUE;
00224 }
00225
00226 }
00227 #endif
00228
00229
00231
00232
00233
00235
00236 bool ReadVec(VEC *vec, FILE *fp)
00237 {
00238 int iR;
00239
00240 for (iR = 0; iR < 3; iR++) {
00241 if (!ReadReal(&vec->v[iR], fp)) {
00242 ShowErrorMessage("Could not read vector");
00243 return FALSE;
00244 }
00245 }
00246 return TRUE;
00247 }
00248
00249
00251
00252
00253
00255
00256 bool ReadMat(MAT *mat, FILE *fp)
00257 {
00258 int iV;
00259
00260 for (iV = 0; iV < 3; iV++) {
00261 if (!ReadVec(&mat->mv[iV], fp)) {
00262 ShowErrorMessage("Could not read Matrix");
00263 return FALSE;
00264 }
00265 }
00266 return TRUE;
00267 }
00268
00270
00271
00272
00274
00275 bool StringToUpper(char *string)
00276 {
00277 int iChar;
00278 int sLen = strlen(string);
00279
00280 if (sLen > READ_MAX_WORDLEN) return FALSE;
00281
00282 for (iChar = 0; iChar < sLen; ++iChar) {
00283 string[iChar] = toupper(string[iChar]);
00284 }
00285 return TRUE;
00286 }
00287
00289
00290
00291
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 bool Compare (char *word, char *token)
00310 {
00311 unsigned int wordLen;
00312 unsigned int iChar;
00313
00314 wordLen = strlen(word);
00315
00316 if (wordLen != strlen(token)) return FALSE;
00317
00318 for (iChar = 0; iChar < wordLen; iChar++) {
00319 if (toupper(word[iChar]) != toupper(token[iChar])) {
00320 return FALSE;
00321 }
00322 }
00323
00324 return TRUE;
00325 }
00326
00328
00329
00330
00332
00333 int ReadNumberList(int *numList, int maxNum, FILE *fp)
00334 {
00335 int iN = 0;
00336 int startNum, endNum, tmpNum;
00337 bool doneList;
00338 char ch;
00339
00340
00341 while (isspace(ch = fgetc(fp))) {
00342 NULL;
00343 }
00344 ungetc(ch, fp);
00345
00346
00347 if ((!ReadInt(&numList[iN++], fp))) {
00348 return 0;
00349 }
00350
00351 if (numList[0] < 0) {
00352 return -1;
00353 }
00354
00355
00356 doneList = FALSE;
00357 while (!doneList) {
00358
00359
00360 if (iN > maxNum) {
00361 return -1;
00362 }
00363
00364
00365 while (isspace(ch = fgetc(fp))){
00366 NULL;
00367 }
00368
00369
00370 switch (ch) {
00371
00372
00373 case ',':
00374 if (!ReadInt(&numList[iN++], fp)) {
00375 return iN - 1;
00376 }
00377 break;
00378
00379
00380 case '-':
00381 if (!ReadInt(&endNum, fp)) {
00382 return -1;
00383 } else {
00384 if (endNum < 0 || endNum >= maxNum) return -1;
00385 startNum = numList[--iN];
00386 if (endNum < startNum) {
00387 tmpNum = startNum;
00388 startNum = endNum;
00389 endNum = tmpNum;
00390 }
00391 while(startNum <= endNum) {
00392 numList[iN++] = startNum++;
00393 }
00394 }
00395 break;
00396
00397
00398 default:
00399 ungetc(ch, fp);
00400 doneList = TRUE;
00401 break;
00402
00403 }
00404 }
00405 return iN;
00406 }
00407
00408
00410
00411
00412
00414
00415 bool ReadAllCarInfo(char *fileName)
00416 {
00417 char word[READ_MAX_WORDLEN];
00418 FILE *fp;
00419
00420 int tInt;
00421
00422
00423 if ((fp = fopen(fileName, "r")) == NULL) {
00424 ShowErrorMessage("Could not open CarInit file");
00425 return FALSE;
00426 }
00427
00428
00429 while (ReadWord(word, fp)) {
00430
00431
00432 if (Compare(word, "NUMCARS")) {
00433
00434 ReadInt(&tInt, fp);
00435 NCarTypes = tInt;
00436 if (CarInfo == NULL) {
00437 CarInfo = CreateCarInfo(NCarTypes);
00438 }
00439 CarList = (int *)malloc(sizeof(int) * NCarTypes);
00440 }
00441
00442
00443 else if (Compare(word, "CAR")) {
00444 if ((CarListSize = ReadNumberList(CarList, NCarTypes, fp)) < 0) {
00445 InvalidNumberList("Car");
00446 fclose(fp);
00447 return FALSE;
00448 }
00449 if (!ReadCarInfo(fp)) {
00450 ShowErrorMessage("Error in CarInit file");
00451 fclose(fp);
00452 return FALSE;
00453 }
00454 }
00455
00456
00457 else {
00458 if (UnknownWordMessage(word) == IDNO) {
00459 fclose(fp);
00460 return FALSE;
00461 }
00462 }
00463 }
00464
00465 free(CarList);
00466 fclose(fp);
00467
00468 return TRUE;
00469 }
00470
00471
00473
00474
00475
00477
00478 bool ReadCarInfo(FILE *fp)
00479 {
00480 char ch;
00481 char word[READ_MAX_WORDLEN];
00482 int iCar, iModel;
00483 bool tBool;
00484
00485
00486 REAL tReal;
00487 int tInt, tInt2, tInt3;
00488 VEC tVec;
00489
00490
00491 while (isspace(ch = fgetc(fp)) && ch != EOF) {
00492 if (ch == EOF || ch != '{') {
00493 return FALSE;
00494 }
00495 }
00496
00497
00498 while (ReadWord(word, fp) && !Compare(word, "}")) {
00499
00500
00501 if (Compare(word, "MODEL")) {
00502 if ((ModelListSize = ReadNumberList(ModelList, MAX_CAR_MODEL_TYPES, fp)) < 0) {
00503 InvalidNumberList("Model");
00504 return FALSE;
00505 }
00506 ReadFileName(word, fp);
00507 for (iCar = 0; iCar < CarListSize; iCar++) {
00508 for (iModel = 0; iModel < ModelListSize; iModel++) {
00509 if (ModelList[iModel] >= MAX_CAR_MODEL_TYPES) {
00510 return FALSE;
00511 }
00512 strncpy(CarInfo[CarList[iCar]].ModelFile[ModelList[iModel]], word, MAX_CAR_FILENAME);
00513 }
00514 }
00515 }
00516
00517
00518 else if (Compare(word, "TPAGE")) {
00519 ReadFileName(word, fp);
00520 for (iCar = 0; iCar < CarListSize; iCar++) {
00521 strncpy(CarInfo[CarList[iCar]].TPageFile, word, MAX_CAR_FILENAME);
00522 }
00523 }
00524
00525
00526 else if (Compare(word, "ENVRGB")) {
00527 ReadInt(&tInt, fp);
00528 ReadInt(&tInt2, fp);
00529 ReadInt(&tInt3, fp);
00530 for (iCar = 0; iCar < CarListSize; iCar++) {
00531 CarInfo[CarList[iCar]].EnvRGB = (tInt << 16) | (tInt2 << 8) | tInt3;
00532 }
00533 }
00534
00535
00536 else if (Compare(word, "COLL")) {
00537 ReadFileName(word, fp);
00538 for (iCar = 0; iCar < CarListSize; iCar++) {
00539 strncpy(CarInfo[CarList[iCar]].CollFile, word, MAX_CAR_FILENAME);
00540 }
00541 }
00542
00543
00544 else if (Compare(word, "COM")) {
00545 ReadVec(&tVec, fp);
00546
00547 for (iCar = 0; iCar < CarListSize; iCar++) {
00548 CopyVec(&tVec, &CarInfo[CarList[iCar]].CoMOffset);
00549 }
00550 }
00551
00552
00553 else if (Compare(word, "WEAPON")) {
00554 ReadVec(&tVec, fp);
00555
00556 for (iCar = 0; iCar < CarListSize; iCar++) {
00557 CopyVec(&tVec, &CarInfo[CarList[iCar]].WeaponOffset);
00558 }
00559 }
00560
00561
00562 else if (Compare(word, "BODY")) {
00563 ReadBodyInfo(fp);
00564 }
00565
00566
00567 else if (Compare(word, "WHEEL")) {
00568 if ((WheelListSize = ReadNumberList(WheelList, CAR_NWHEELS, fp)) < 1) {
00569 InvalidNumberList("Wheel");
00570 return FALSE;
00571 }
00572 ReadWheelInfo(fp);
00573 }
00574
00575
00576 else if (Compare(word, "AERIAL")) {
00577 ReadAerialInfo(fp);
00578 }
00579
00580
00581 else if (Compare(word, "SPRING")) {
00582 if ((SpringListSize = ReadNumberList(SpringList, CAR_NWHEELS, fp)) < 1) {
00583 InvalidNumberList("Spring");
00584 return FALSE;
00585 }
00586 ReadSpringInfo(fp);
00587 }
00588
00589
00590 else if (Compare(word, "AXLE")) {
00591 if ((AxleListSize = ReadNumberList(AxleList, CAR_NWHEELS, fp)) < 1) {
00592 InvalidNumberList("Axle");
00593 return FALSE;
00594 }
00595 ReadAxleInfo(fp);
00596 }
00597
00598
00599 else if (Compare(word, "PIN")) {
00600 if ((PinListSize = ReadNumberList(PinList, CAR_NWHEELS, fp)) < 1) {
00601 InvalidNumberList("Pin");
00602 return FALSE;
00603 }
00604 ReadPinInfo(fp);
00605 }
00606
00607
00608 else if (Compare(word, "SPINNER")) {
00609 ReadSpinnerInfo(fp);
00610 }
00611
00612
00613 else if (Compare(word, "STEERRATE")) {
00614 ReadReal(&tReal, fp);
00615
00616 for (iCar = 0; iCar < CarListSize; iCar++) {
00617 CarInfo[CarList[iCar]].SteerRate = tReal;
00618 }
00619 }
00620
00621
00622 else if (Compare(word, "STEERMOD")) {
00623 ReadReal(&tReal, fp);
00624 for (iCar = 0; iCar < CarListSize; iCar++) {
00625 CarInfo[CarList[iCar]].SteerModifier = tReal;
00626 }
00627 }
00628
00629
00630 else if (Compare(word, "ENGINERATE")) {
00631 ReadReal(&tReal, fp);
00632
00633 for (iCar = 0; iCar < CarListSize; iCar++) {
00634 CarInfo[CarList[iCar]].EngineRate = tReal;
00635 }
00636 }
00637
00638
00639 else if (Compare(word, "TOPSPEED")) {
00640 ReadReal(&tReal, fp);
00641 tReal *= MPH2OGU_SPEED;
00642 for (iCar = 0; iCar < CarListSize; iCar++) {
00643 CarInfo[CarList[iCar]].TopSpeed = tReal;
00644 }
00645 }
00646
00647
00648 else if (Compare(word, "MAXREVS")) {
00649 ReadReal(&tReal, fp);
00650 tReal *= MPH2OGU_SPEED;
00651 for (iCar = 0; iCar < CarListSize; iCar++) {
00652 CarInfo[CarList[iCar]].MaxRevs = tReal;
00653 }
00654 }
00655
00656
00657 else if (Compare(word, "DOWNFORCEMOD")) {
00658 ReadReal(&tReal, fp);
00659 for (iCar = 0; iCar < CarListSize; iCar++) {
00660 CarInfo[CarList[iCar]].DownForceMod = tReal;
00661 }
00662 }
00663
00664
00665 else if (Compare(word, "NAME")) {
00666 ReadFileName(word, fp);
00667 for (iCar = 0; iCar < CarListSize; iCar++) {
00668 strncpy(CarInfo[CarList[iCar]].Name, word, CAR_NAMELEN - 1);
00669 }
00670 }
00671
00672
00673 else if (Compare(word, "BESTTIME")) {
00674 ReadBool(&tBool, fp);
00675 for (iCar = 0; iCar < CarListSize; iCar++) {
00676 CarInfo[CarList[iCar]].AllowedBestTime = tBool;
00677 }
00678 }
00679
00680
00681 else if (Compare(word, "SELECTABLE")) {
00682 ReadBool(&tBool, fp);
00683 for (iCar = 0; iCar < CarListSize; iCar++) {
00684 CarInfo[CarList[iCar]].Selectable = tBool;
00685 }
00686 }
00687
00688
00689 else {
00690 if (UnknownWordMessage(word) == IDNO) {
00691 fclose(fp);
00692 return FALSE;
00693 }
00694 }
00695 }
00696
00697 return TRUE;
00698 }
00699
00700
00702
00703
00704
00706
00707 bool ReadBodyInfo(FILE *fp)
00708 {
00709 char ch;
00710 char word[READ_MAX_WORDLEN];
00711 int iCar;
00712
00713 int tInt;
00714 REAL tReal;
00715 VEC tVec;
00716 MAT tMat;
00717
00718
00719 while (isspace(ch = fgetc(fp)) && ch != EOF) {
00720 }
00721 if (ch == EOF || ch != '{') {
00722 return FALSE;
00723 }
00724
00725
00726 while (ReadWord(word, fp) && !Compare(word, "}")) {
00727
00728
00729 if (Compare(word, "MODELNUM")) {
00730 ReadInt(&tInt, fp);
00731 for (iCar = 0; iCar < CarListSize; iCar++) {
00732 CarInfo[CarList[iCar]].Body.ModelNum = tInt;
00733 }
00734 }
00735
00736
00737 else if (Compare(word, "OFFSET")) {
00738 ReadVec(&tVec, fp);
00739
00740 for (iCar = 0; iCar < CarListSize; iCar++) {
00741 CopyVec(&tVec, &CarInfo[CarList[iCar]].Body.Offset);
00742 }
00743 }
00744
00745
00746 else if (Compare(word, "MASS")) {
00747 ReadReal(&tReal, fp);
00748
00749 for (iCar = 0; iCar < CarListSize; iCar++) {
00750 CarInfo[CarList[iCar]].Body.Mass = tReal;
00751 }
00752 }
00753
00754
00755 else if (Compare(word, "INERTIA")) {
00756 ReadMat(&tMat, fp);
00757
00758 for (iCar = 0; iCar < CarListSize; iCar++) {
00759 CopyMat(&tMat, &CarInfo[CarList[iCar]].Body.Inertia);
00760 }
00761 }
00762
00763
00764 else if (Compare(word, "GRAVITY")) {
00765 ReadReal(&tReal, fp);
00766
00767 for (iCar = 0; iCar < CarListSize; iCar++) {
00768 CarInfo[CarList[iCar]].Body.Gravity = tReal;
00769 }
00770 }
00771
00772
00773 else if (Compare(word, "HARDNESS")) {
00774 ReadReal(&tReal, fp);
00775 for (iCar = 0; iCar < CarListSize; iCar++) {
00776 CarInfo[CarList[iCar]].Body.Hardness = tReal;
00777 }
00778 }
00779
00780
00781 else if (Compare(word, "RESISTANCE")) {
00782 ReadReal(&tReal, fp);
00783 for (iCar = 0; iCar < CarListSize; iCar++) {
00784 CarInfo[CarList[iCar]].Body.Resistance = tReal;
00785 }
00786 }
00787
00788
00789 else if (Compare(word, "ANGRES")) {
00790 ReadReal(&tReal, fp);
00791 for (iCar = 0; iCar < CarListSize; iCar++) {
00792 CarInfo[CarList[iCar]].Body.AngResistance = tReal;
00793 }
00794 }
00795
00796
00797 else if (Compare(word, "RESMOD")) {
00798 ReadReal(&tReal, fp);
00799 for (iCar = 0; iCar < CarListSize; iCar++) {
00800 CarInfo[CarList[iCar]].Body.ResModifier = tReal;
00801 }
00802 }
00803
00804
00805 else if (Compare(word, "STATICFRICTION")) {
00806 ReadReal(&tReal, fp);
00807 for (iCar = 0; iCar < CarListSize; iCar++) {
00808 CarInfo[CarList[iCar]].Body.StaticFriction = tReal;
00809 }
00810 }
00811
00812
00813 else if (Compare(word, "KINETICFRICTION")) {
00814 ReadReal(&tReal, fp);
00815 for (iCar = 0; iCar < CarListSize; iCar++) {
00816 CarInfo[CarList[iCar]].Body.KineticFriction = tReal;
00817 }
00818 }
00819
00820
00821 else if (Compare(word, "GRIP")) {
00822 ReadReal(&tReal, fp);
00823 for (iCar = 0; iCar < CarListSize; iCar++) {
00824 CarInfo[CarList[iCar]].Body.Grip = tReal;
00825 }
00826 }
00827
00828
00829 else {
00830 if (UnknownWordMessage(word) == IDNO) {
00831 fclose(fp);
00832 return FALSE;
00833 }
00834 }
00835 }
00836
00837 return TRUE;
00838 }
00839
00840
00841
00843
00844
00845
00847
00848 bool ReadWheelInfo(FILE *fp)
00849 {
00850 char ch;
00851 char word[READ_MAX_WORDLEN];
00852 int iCar, iWheel;
00853
00854 int tInt;
00855 bool tBool;
00856 REAL tReal;
00857 VEC tVec;
00858
00859
00860 while (isspace(ch = fgetc(fp)) && ch != EOF) {
00861 }
00862 if (ch == EOF || ch != '{') {
00863 return FALSE;
00864 }
00865
00866
00867 while (ReadWord(word, fp) && !Compare(word, "}")) {
00868
00869
00870 if (Compare(word, "MODELNUM")) {
00871 ReadInt(&tInt, fp);
00872 for (iCar = 0; iCar < CarListSize; iCar++) {
00873 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00874 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].ModelNum = tInt;
00875 if (tInt == CAR_MODEL_NONE) {
00876 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].IsPresent = FALSE;
00877 } else {
00878 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].IsPresent = TRUE;
00879 }
00880 }
00881 }
00882 }
00883
00884
00885 else if (Compare(word, "OFFSET1")) {
00886 ReadVec(&tVec, fp);
00887
00888 for (iCar = 0; iCar < CarListSize; iCar++) {
00889 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00890 CopyVec(&tVec, &CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Offset1);
00891 }
00892 }
00893 }
00894 else if (Compare(word, "OFFSET2")) {
00895 ReadVec(&tVec, fp);
00896
00897 for (iCar = 0; iCar < CarListSize; iCar++) {
00898 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00899 CopyVec(&tVec, &CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Offset2);
00900 }
00901 }
00902 }
00903
00904
00905 else if (Compare(word, "RADIUS")) {
00906 ReadReal(&tReal, fp);
00907
00908 for (iCar = 0; iCar < CarListSize; iCar++) {
00909 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00910 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Radius = tReal;
00911 }
00912 }
00913 }
00914
00915
00916 else if (Compare(word, "MASS")) {
00917 ReadReal(&tReal, fp);
00918
00919 for (iCar = 0; iCar < CarListSize; iCar++) {
00920 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00921 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Mass = tReal;
00922 }
00923 }
00924 }
00925
00926
00927 else if (Compare(word, "GRAVITY")) {
00928 ReadReal(&tReal, fp);
00929
00930 for (iCar = 0; iCar < CarListSize; iCar++) {
00931 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00932 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Gravity = tReal;
00933 }
00934 }
00935 }
00936
00937
00938 else if (Compare(word, "MAXPOS")) {
00939 ReadReal(&tReal, fp);
00940
00941 for (iCar = 0; iCar < CarListSize; iCar++) {
00942 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00943 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].MaxPos = tReal;
00944 }
00945 }
00946 }
00947
00948
00949 else if (Compare(word, "GRIP")) {
00950 ReadReal(&tReal, fp);
00951
00952 for (iCar = 0; iCar < CarListSize; iCar++) {
00953 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00954 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].Grip = tReal;
00955 }
00956 }
00957 }
00958
00959
00960 else if (Compare(word, "STATICFRICTION")) {
00961 ReadReal(&tReal, fp);
00962 for (iCar = 0; iCar < CarListSize; iCar++) {
00963 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00964 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].StaticFriction = tReal;
00965 }
00966 }
00967 }
00968
00969
00970 else if (Compare(word, "KINETICFRICTION")) {
00971 ReadReal(&tReal, fp);
00972 for (iCar = 0; iCar < CarListSize; iCar++) {
00973 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00974 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].KineticFriction = tReal;
00975 }
00976 }
00977 }
00978
00979
00980 else if (Compare(word, "AXLEFRICTION")) {
00981 ReadReal(&tReal, fp);
00982 for (iCar = 0; iCar < CarListSize; iCar++) {
00983 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00984 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].AxleFriction = tReal;
00985 }
00986 }
00987 }
00988
00989
00990 else if (Compare(word, "STEERRATIO")) {
00991 ReadReal(&tReal, fp);
00992
00993 for (iCar = 0; iCar < CarListSize; iCar++) {
00994 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
00995 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].SteerRatio = tReal;
00996 }
00997 }
00998 }
00999
01000
01001 else if (Compare(word, "ENGINERATIO")) {
01002 ReadReal(&tReal, fp);
01003
01004 for (iCar = 0; iCar < CarListSize; iCar++) {
01005 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
01006 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].EngineRatio = tReal;
01007 }
01008 }
01009 }
01010
01011
01012 else if (Compare(word, "ISTURNABLE")) {
01013 ReadBool(&tBool, fp);
01014 for (iCar = 0; iCar < CarListSize; iCar++) {
01015 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
01016 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].IsTurnable = tBool;
01017 }
01018 }
01019 }
01020 else if (Compare(word, "ISPOWERED")) {
01021 ReadBool(&tBool, fp);
01022 for (iCar = 0; iCar < CarListSize; iCar++) {
01023 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
01024 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].IsPowered = tBool;
01025 }
01026 }
01027 }
01028 else if (Compare(word, "ISPRESENT")) {
01029 ReadBool(&tBool, fp);
01030 for (iCar = 0; iCar < CarListSize; iCar++) {
01031 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
01032 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].IsPresent = tBool;
01033 }
01034 }
01035 }
01036
01037
01038 else if (Compare(word, "SKIDWIDTH")) {
01039 ReadReal(&tReal, fp);
01040
01041 for (iCar = 0; iCar < CarListSize; iCar++) {
01042 for (iWheel = 0; iWheel < WheelListSize; iWheel++) {
01043 CarInfo[CarList[iCar]].Wheel[WheelList[iWheel]].SkidWidth = tReal;
01044 }
01045 }
01046 }
01047
01048
01049
01050 else {
01051 if (UnknownWordMessage(word) == IDNO) {
01052 fclose(fp);
01053 return FALSE;
01054 }
01055 }
01056
01057 }
01058
01059 return TRUE;
01060 }
01061
01062
01063
01065
01066
01067
01069
01070 bool ReadSpringInfo(FILE *fp)
01071 {
01072 char ch;
01073 char word[READ_MAX_WORDLEN];
01074 int iCar, iSpring;
01075
01076 int tInt;
01077 REAL tReal;
01078 VEC tVec;
01079
01080
01081 while (isspace(ch = fgetc(fp)) && ch != EOF) {
01082 }
01083 if (ch == EOF || ch != '{') {
01084 return FALSE;
01085 }
01086
01087
01088 while (ReadWord(word, fp) && !Compare(word, "}")) {
01089
01090
01091 if (Compare(word, "MODELNUM")) {
01092 ReadInt(&tInt, fp);
01093 for (iCar = 0; iCar < CarListSize; iCar++) {
01094 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01095 CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].ModelNum = tInt;
01096 }
01097 }
01098 }
01099
01100
01101 else if (Compare(word, "OFFSET")) {
01102 ReadVec(&tVec, fp);
01103
01104 for (iCar = 0; iCar < CarListSize; iCar++) {
01105 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01106 CopyVec(&tVec, &CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].Offset);
01107 }
01108 }
01109 }
01110
01111
01112 else if (Compare(word, "LENGTH")) {
01113 ReadReal(&tReal, fp);
01114
01115 for (iCar = 0; iCar < CarListSize; iCar++) {
01116 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01117 CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].Length = tReal;
01118 }
01119 }
01120 }
01121
01122
01123 else if (Compare(word, "STIFFNESS")) {
01124 ReadReal(&tReal, fp);
01125
01126 for (iCar = 0; iCar < CarListSize; iCar++) {
01127 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01128 CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].Stiffness = tReal;
01129 }
01130 }
01131 }
01132
01133
01134 else if (Compare(word, "DAMPING")) {
01135 ReadReal(&tReal, fp);
01136
01137 for (iCar = 0; iCar < CarListSize; iCar++) {
01138 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01139 CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].Damping = tReal;
01140 }
01141 }
01142 }
01143
01144
01145 else if (Compare(word, "RESTITUTION")) {
01146 ReadReal(&tReal, fp);
01147 for (iCar = 0; iCar < CarListSize; iCar++) {
01148 for (iSpring = 0; iSpring < SpringListSize; iSpring++) {
01149 CarInfo[CarList[iCar]].Spring[SpringList[iSpring]].Restitution = tReal;
01150 }
01151 }
01152 }
01153
01154
01155 else {
01156 if (UnknownWordMessage(word) == IDNO) {
01157 fclose(fp);
01158 return FALSE;
01159 }
01160 }
01161 }
01162
01163 return TRUE;
01164 }
01165
01166
01168
01169
01170
01172
01173 bool ReadAxleInfo(FILE *fp)
01174 {
01175 char ch;
01176 char word[READ_MAX_WORDLEN];
01177 int iCar, iAxle;
01178
01179 int tInt;
01180 REAL tReal;
01181 VEC tVec;
01182
01183
01184 while (isspace(ch = fgetc(fp)) && ch != EOF) {
01185 }
01186 if (ch == EOF || ch != '{') {
01187 return FALSE;
01188 }
01189
01190
01191 while (ReadWord(word, fp) && !Compare(word, "}")) {
01192
01193
01194 if (Compare(word, "MODELNUM")) {
01195 ReadInt(&tInt, fp);
01196 for (iCar = 0; iCar < CarListSize; iCar++) {
01197 for (iAxle = 0; iAxle < AxleListSize; iAxle++) {
01198 CarInfo[CarList[iCar]].Axle[AxleList[iAxle]].ModelNum = tInt;
01199 }
01200 }
01201 }
01202
01203
01204 else if (Compare(word, "OFFSET")) {
01205 ReadVec(&tVec, fp);
01206
01207 for (iCar = 0; iCar < CarListSize; iCar++) {
01208 for (iAxle = 0; iAxle < AxleListSize; iAxle++) {
01209 CopyVec(&tVec, &CarInfo[CarList[iCar]].Axle[AxleList[iAxle]].Offset);
01210 }
01211 }
01212 }
01213
01214
01215 else if (Compare(word, "LENGTH")) {
01216 ReadReal(&tReal, fp);
01217
01218 for (iCar = 0; iCar < CarListSize; iCar++) {
01219 for (iAxle = 0; iAxle < AxleListSize; iAxle++) {
01220 CarInfo[CarList[iCar]].Axle[AxleList[iAxle]].Length = tReal;
01221 }
01222 }
01223 }
01224
01225
01226 else {
01227 if (UnknownWordMessage(word) == IDNO) {
01228 fclose(fp);
01229 return FALSE;
01230 }
01231 }
01232 }
01233
01234 return TRUE;
01235 }
01236
01237
01239
01240
01241
01243
01244 bool ReadPinInfo(FILE *fp)
01245 {
01246 char ch;
01247 char word[READ_MAX_WORDLEN];
01248 int iCar, iPin;
01249
01250 int tInt;
01251 REAL tReal;
01252 VEC tVec;
01253
01254
01255 while (isspace(ch = fgetc(fp)) && ch != EOF) {
01256 }
01257 if (ch == EOF || ch != '{') {
01258 return FALSE;
01259 }
01260
01261
01262 while (ReadWord(word, fp) && !Compare(word, "}")) {
01263
01264
01265 if (Compare(word, "MODELNUM")) {
01266 ReadInt(&tInt, fp);
01267 for (iCar = 0; iCar < CarListSize; iCar++) {
01268 for (iPin = 0; iPin < PinListSize; iPin++) {
01269 CarInfo[CarList[iCar]].Pin[PinList[iPin]].ModelNum = tInt;
01270 }
01271 }
01272 }
01273
01274
01275 else if (Compare(word, "OFFSET")) {
01276 ReadVec(&tVec, fp);
01277
01278 for (iCar = 0; iCar < CarListSize; iCar++) {
01279 for (iPin = 0; iPin < PinListSize; iPin++) {
01280 CopyVec(&tVec, &CarInfo[CarList[iCar]].Pin[PinList[iPin]].Offset);
01281 }
01282 }
01283 }
01284
01285
01286 else if (Compare(word, "LENGTH")) {
01287 ReadReal(&tReal, fp);
01288
01289 for (iCar = 0; iCar < CarListSize; iCar++) {
01290 for (iPin = 0; iPin < PinListSize; iPin++) {
01291 CarInfo[CarList[iCar]].Pin[PinList[iPin]].Length = tReal;
01292 }
01293 }
01294 }
01295
01296
01297 else {
01298 if (UnknownWordMessage(word) == IDNO) {
01299 fclose(fp);
01300 return FALSE;
01301 }
01302 }
01303 }
01304
01305 return TRUE;
01306 }
01307
01309
01310
01311
01313
01314 bool ReadSpinnerInfo(FILE *fp)
01315 {
01316 char ch;
01317 char word[READ_MAX_WORDLEN];
01318 int iCar;
01319
01320 int tInt;
01321 REAL tReal;
01322 VEC tVec;
01323
01324
01325 while (isspace(ch = fgetc(fp)) && ch != EOF) {
01326 }
01327 if (ch == EOF || ch != '{') {
01328 return FALSE;
01329 }
01330
01331
01332 while (ReadWord(word, fp) && !Compare(word, "}")) {
01333
01334
01335 if (Compare(word, "MODELNUM")) {
01336 ReadInt(&tInt, fp);
01337 for (iCar = 0; iCar < CarListSize; iCar++) {
01338 CarInfo[CarList[iCar]].Spinner.ModelNum = tInt;
01339 }
01340 }
01341
01342
01343 else if (Compare(word, "OFFSET")) {
01344 ReadVec(&tVec, fp);
01345 for (iCar = 0; iCar < CarListSize; iCar++) {
01346 CopyVec(&tVec, &CarInfo[CarList[iCar]].Spinner.Offset);
01347 }
01348 }
01349
01350
01351 else if (Compare(word, "AXIS")) {
01352 ReadVec(&tVec, fp);
01353 for (iCar = 0; iCar < CarListSize; iCar++) {
01354 CopyVec(&tVec, &CarInfo[CarList[iCar]].Spinner.Axis);
01355 }
01356 }
01357
01358
01359 else if (Compare(word, "ANGVEL")) {
01360 ReadReal(&tReal, fp);
01361 for (iCar = 0; iCar < CarListSize; iCar++) {
01362 CarInfo[CarList[iCar]].Spinner.AngVel = tReal;
01363 }
01364 }
01365
01366
01367 else {
01368 if (UnknownWordMessage(word) == IDNO) {
01369 fclose(fp);
01370 return FALSE;
01371 }
01372 }
01373
01374 }
01375 return TRUE;
01376 }
01377
01378
01380
01381
01382
01384
01385 bool ReadAerialInfo(FILE *fp)
01386 {
01387 char ch;
01388 char word[READ_MAX_WORDLEN];
01389 int iCar;
01390
01391 int tInt;
01392 REAL tReal;
01393 VEC tVec;
01394
01395
01396 while (isspace(ch = fgetc(fp)) && ch != EOF) {
01397 }
01398 if (ch == EOF || ch != '{') {
01399 return FALSE;
01400 }
01401
01402
01403 while (ReadWord(word, fp) && !Compare(word, "}")) {
01404
01405
01406 if (Compare(word, "SECMODELNUM")) {
01407 ReadInt(&tInt, fp);
01408 for (iCar = 0; iCar < CarListSize; iCar++) {
01409 CarInfo[CarList[iCar]].Aerial.SecModelNum = tInt;
01410 }
01411 }
01412 else if (Compare(word, "TOPMODELNUM")) {
01413 ReadInt(&tInt, fp);
01414 for (iCar = 0; iCar < CarListSize; iCar++) {
01415 CarInfo[CarList[iCar]].Aerial.TopModelNum = tInt;
01416 }
01417 }
01418
01419
01420 else if (Compare(word, "OFFSET")) {
01421 ReadVec(&tVec, fp);
01422
01423 for (iCar = 0; iCar < CarListSize; iCar++) {
01424 CopyVec(&tVec, &CarInfo[CarList[iCar]].Aerial.Offset);
01425 }
01426 }
01427
01428
01429 else if (Compare(word, "LENGTH")) {
01430 ReadReal(&tReal, fp);
01431
01432 for (iCar = 0; iCar < CarListSize; iCar++) {
01433 CarInfo[CarList[iCar]].Aerial.SecLen = tReal;
01434 }
01435 }
01436
01437
01438 else if (Compare(word, "DIRECTION")) {
01439 ReadVec(&tVec, fp);
01440 for (iCar = 0; iCar < CarListSize; iCar++) {
01441 CopyVec(&tVec, &CarInfo[CarList[iCar]].Aerial.Direction);
01442 }
01443 }
01444
01445
01446 else if (Compare(word, "STIFFNESS")) {
01447 ReadReal(&tReal, fp);
01448
01449 for (iCar = 0; iCar < CarListSize; iCar++) {
01450 CarInfo[CarList[iCar]].Aerial.Stiffness = tReal;
01451 }
01452 }
01453
01454
01455 else if (Compare(word, "DAMPING")) {
01456 ReadReal(&tReal, fp);
01457
01458 for (iCar = 0; iCar < CarListSize; iCar++) {
01459 CarInfo[CarList[iCar]].Aerial.Damping = tReal;
01460 }
01461 }
01462
01463
01464 else {
01465 if (UnknownWordMessage(word) == IDNO) {
01466 fclose(fp);
01467 return FALSE;
01468 }
01469 }
01470 }
01471
01472 return TRUE;
01473 }
01474
01475
01477
01478
01479
01481
01482 int UnknownWordMessage(char *word)
01483 {
01484
01485 wsprintf(ErrorMessage, "\"%s\"\n\nContinue?", word);
01486 return Box("Unrecognised word:", ErrorMessage, MB_YESNO | MB_DEFBUTTON1 | MB_ICONQUESTION);
01487
01488 }
01489
01490 void ShowErrorMessage(char *word)
01491 {
01492
01493 wsprintf(ErrorMessage, "%s", word);
01494 Box("Initialisation Error", ErrorMessage, MB_OK);
01495
01496 }
01497
01498 void InvalidVariable(char *object)
01499 {
01500
01501 wsprintf(ErrorMessage, "Invalid variable for%s", object);
01502 Box("Initialisation Error", ErrorMessage, MB_OK);
01503
01504 }
01505
01506 void InvalidNumberList(char *object)
01507 {
01508
01509 wsprintf(ErrorMessage, "Invalid number list for\n%s", object);
01510 Box("Initialisation Error", ErrorMessage, MB_OK);
01511
01512 }