1 /*
2 Copyright (C) 1994-1995 Apogee Software, Ltd.
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 
13 See the GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 */
20 //****************************************************************************
21 //
22 // RT_CFG.C
23 //
24 //****************************************************************************
25 
26 #define _ROTT_
27 
28 #ifdef DOS
29 #include <io.h>
30 #include <bios.h>
31 #include <conio.h>
32 #include <process.h>
33 #else
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <errno.h>
37 #endif
38 
39 #include <stdlib.h>
40 #include <fcntl.h>
41 #include <string.h>
42 #include <ctype.h>
43 
44 #ifdef _ROTT_
45 #include "rt_def.h"
46 #else
47 #include "st_def.h"
48 #endif
49 
50 #include "rt_cfg.h"
51 #include "version.h"
52 
53 #ifdef _ROTT_
54 
55 #include "scriplib.h"
56 #include "rt_playr.h"
57 #include "rt_menu.h"
58 #include "rt_game.h"
59 #include "rt_in.h"
60 #include "z_zone.h"
61 #include "w_wad.h"
62 #include "rt_crc.h"
63 #include "rt_sound.h"
64 #include "rt_util.h"
65 #include "rt_main.h"
66 #include "rt_view.h"
67 #include "rt_msg.h"
68 #include "rt_battl.h"
69 #include "rt_net.h"
70 #include "isr.h"
71 #include "fx_man.h"
72 #include "develop.h"
73 
74 #else
75 
76 #include "st_def.h"
77 #include "rt_cfg.h"
78 #include "scriplib.h"
79 #include "rt_sound.h"
80 #include "st_util.h"
81 
82 #endif
83 //MED
84 #include "memcheck.h"
85 
86 
87 //******************************************************************************
88 //
89 // GLOBALS
90 //
91 //******************************************************************************
92 
93 boolean WriteSoundFile   = true;
94 
95 int     FXMode           = 0;
96 int     MusicMode        = 0;
97 
98 int     MUvolume         = 196;
99 int     FXvolume         = 196;
100 
101 fx_blaster_config SBSettings =
102    {
103    0x220, fx_SB, 7, 1, 5, 0x330, 0x620
104    };
105 
106 boolean mouseenabled     = 1;
107 boolean joystickenabled  = 0;
108 boolean joypadenabled    = 0;
109 int     joystickport     = 0;
110 int     mouseadjustment  = 5;
111 int     threshold        = 1;
112 int     NumVoices        = 4;
113 int     NumChannels      = 1;
114 int     NumBits          = 8;
115 int     MidiAddress      = 0x330;
116 boolean cybermanenabled  = false;
117 boolean assassinenabled  = false;
118 boolean spaceballenabled = false;
119 boolean AutoDetailOn     = true;
120 int     DoubleClickSpeed = 20;
121 boolean BobbinOn         = true;
122 int     Menuflipspeed    = 15;
123 int     DetailLevel      = 2;         //HI DETAIL
124 int     fandc            = 1;
125 int     blanktime        = (2*60*VBLCOUNTER);
126 boolean ConfigLoaded     = false;
127 boolean stereoreversed   = false;
128 
129 int     DefaultDifficulty      = 2;
130 int     DefaultPlayerCharacter = 0;
131 int     DefaultPlayerColor     = 0;
132 byte    passwordstring[20];
133 
134 #ifndef _ROTT_
135 
136 int     fulllight        = 0;
137 int     viewsize         = 7;
138 
139 #endif
140 MacroList CommbatMacros[MAXMACROS];
141 
142 #ifdef DOS
143 char *ApogeePath = "APOGEECD";
144 #else
145 char ApogeePath[256];
146 #endif
147 
148 //******************************************************************************
149 //
150 // LOCALS
151 //
152 //******************************************************************************
153 
154 static char SoundName[13]  = "sound.rot";
155 
156 #ifdef _ROTT_
157 
158 static char *ConfigName = "config.rot";
159 static char *ScoresName = "scores.rot";
160 static char *ROTT       = "rott.rot";
161 static char *CONFIG     = "setup.rot";
162 static char *BattleName = "battle.rot";
163 
164 AlternateInformation RemoteSounds;
165 //AlternateInformation PlayerGraphics;
166 AlternateInformation GameLevels;
167 AlternateInformation BattleLevels;
168 char CodeName[MAXCODENAMELENGTH];
169 
170 #endif
171 
172 
173 #ifdef _ROTT_
174 
175 //******************************************************************************
176 //
177 // ReadScores ()
178 //
179 //******************************************************************************
180 
ReadScores(void)181 void ReadScores (void)
182 {
183    int file;
184    char filename[ 128 ];
185 
186    GetPathFromEnvironment( filename, ApogeePath, ScoresName );
187    if (access (filename, F_OK) == 0)
188       {
189       file = SafeOpenRead (filename);
190       SafeRead (file, &Scores, sizeof (Scores));
191       close(file);
192       }
193    else
194       gamestate.violence = 0;
195 }
196 
197 #endif
198 
199 //******************************************************************************
200 //
201 // ReadInt
202 //
203 //******************************************************************************
204 
ReadInt(const char * s1,int * val)205 void ReadInt (const char * s1, int * val)
206 {
207    GetToken (true);
208    if (!strcmpi (token,s1))
209       {
210       if (TokenAvailable()==true)
211          {
212          GetToken(false);
213          *val=ParseNum(token);
214          }
215       }
216 }
217 
218 //******************************************************************************
219 //
220 // ReadBoolean
221 //
222 //******************************************************************************
223 
ReadBoolean(const char * s1,boolean * val)224 void ReadBoolean (const char * s1, boolean * val)
225 {
226    int temp;
227 
228    temp = (int)(*val);
229    ReadInt (s1,&temp);
230    *val = (boolean) temp;
231 }
232 
233 //******************************************************************************
234 //
235 // ReadUnsigned
236 //
237 //******************************************************************************
238 
ReadUnsigned(const char * s1,unsigned long * val)239 void ReadUnsigned (const char * s1, unsigned long * val)
240 {
241    int temp;
242 
243    temp = (int)(*val);
244    ReadInt (s1,&temp);
245    *val = (unsigned) temp;
246 }
247 
248 //******************************************************************************
249 //
250 // ParseSoundFile ()
251 //
252 //******************************************************************************
253 
ParseSoundFile(void)254 boolean ParseSoundFile (void)
255 {
256    boolean retval = true;
257    int version    = 0;
258 
259    ReadInt("Version",&version);
260 
261    if (version == ROTTVERSION)
262    {
263       // Read in Music Mode
264 
265       ReadInt ("MusicMode",&MusicMode);
266 
267       // Read in FX Mode
268 
269       ReadInt ("FXMode",&FXMode);
270 
271       // Read in Music Volume
272 
273       ReadInt ("MusicVolume", &MUvolume);
274 
275       // Read in FX Volume
276 
277       ReadInt ("FXVolume", &FXvolume);
278 
279       // Read in numvoices
280 
281       ReadInt ("NumVoices",&NumVoices);
282 
283       // Read in numchannels
284 
285       ReadInt ("NumChannels",&NumChannels);
286 
287       // Read in numbits
288 
289       ReadInt ("NumBits",&NumBits);
290 
291       // Read in Midi Address
292 
293       ReadInt ("MidiAddress",&MidiAddress);
294 
295       // Read in stereo reversal
296 
297       ReadBoolean ("StereoReverse",&stereoreversed);
298 
299       // Read in Sound Blaster info
300       ReadUnsigned ("SBType",  &SBSettings.Type );
301       ReadUnsigned ("SBPort",  &SBSettings.Address );
302       ReadUnsigned ("SBIrq",   &SBSettings.Interrupt );
303       ReadUnsigned ("SBDma8",  &SBSettings.Dma8 );
304       ReadUnsigned ("SBDma16", &SBSettings.Dma16 );
305       ReadUnsigned ("SBMidi",  &SBSettings.Midi );
306       ReadUnsigned ("SBEmu",   &SBSettings.Emu );
307    }
308    else
309       retval = false;
310 
311    return (retval);
312 }
313 
314 
315 
316 //******************************************************************************
317 //
318 // SetSoundDefaultValues ()
319 //
320 //******************************************************************************
SetSoundDefaultValues(void)321 void SetSoundDefaultValues
322    (
323    void
324    )
325 
326    {
327    fx_blaster_config blaster;
328    int status;
329 
330    //
331    //  no config file, so select default values
332    //
333    #if !defined(PLATFORM_DOS)
334    // icculus' SDL_mixer driver looks like a soundscape to us
335    MusicMode   = 6;
336    FXMode      = 6;
337    NumVoices   = 8;
338    NumChannels = 2;
339    NumBits     = 16;
340    MidiAddress = 0x330;
341    stereoreversed = false;
342    #else
343    MusicMode   = 0;
344    FXMode      = 0;
345    NumVoices   = 4;
346    NumChannels = 1;
347    NumBits     = 8;
348    MidiAddress = 0x330;
349    stereoreversed = false;
350    #endif
351 
352    status = FX_GetBlasterSettings( &blaster );
353    if ( status == FX_Ok )
354       {
355       SBSettings.Type      = blaster.Type;
356       SBSettings.Address   = blaster.Address;
357       SBSettings.Interrupt = blaster.Interrupt;
358       SBSettings.Dma8      = blaster.Dma8;
359       SBSettings.Dma16     = blaster.Dma16;
360       SBSettings.Midi      = blaster.Midi;
361       SBSettings.Emu       = blaster.Emu;
362       }
363    }
364 
365 
366 #ifdef _ROTT_
367 
368 extern char    pword[ 13 ];
369 //******************************************************************************
370 //
371 // ConvertStringToPasswordString ()
372 //
373 //******************************************************************************
374 
375 #define PASSWORDENCRYPTER "7d7e4a2d3b6a0319554654231f6d2a"
376 
ConvertStringToPasswordString(char * string)377 void ConvertStringToPasswordString ( char * string )
378 {
379    int i;
380    char temp[3];
381 
382    memset(temp,0,sizeof(temp));
383 
384    for (i=0;i<13;i++)
385       {
386       memcpy(&temp[0],&string[i<<1],2);
387 //     sscanf(&temp[0],"%x",(unsigned int *)&passwordstring[i]); orig danger ! x86 onlu
388       { unsigned int x; sscanf(&temp[0],"%x",&x); passwordstring[i]=x;} // by bero
389       }
390 }
391 
392 //******************************************************************************
393 //
394 // ConvertPasswordStringToPassword ()
395 //
396 //******************************************************************************
397 
ConvertPasswordStringToPassword(void)398 void ConvertPasswordStringToPassword ( void )
399 {
400    int i;
401    int x;
402    char temp[3];
403    char key[40];
404 
405    memset(temp,0,sizeof(temp));
406    strcpy(&key[0],PASSWORDENCRYPTER);
407 
408    for (i=0;i<12;i++)
409       {
410       memcpy(&temp[0],&key[i<<1],2);
411       sscanf(&temp[0],"%x",&x);
412       pword[i]=passwordstring[i]^x;
413       }
414    memcpy(&temp[0],&key[i<<1],2);
415    sscanf(&temp[0],"%x",&x);
416    gamestate.violence=passwordstring[i]^x;
417    if (
418        (gamestate.violence<0) ||
419        (gamestate.violence>3)
420       )
421       gamestate.violence=0;
422 }
423 
424 //******************************************************************************
425 //
426 // ConvertPasswordStringToString ()
427 //
428 //******************************************************************************
429 
ConvertPasswordStringToString(char * string)430 void ConvertPasswordStringToString ( char * string )
431 {
432    int i;
433    char temp[8];
434 
435    memset(temp,0,sizeof(temp));
436 
437    for (i=0;i<13;i++)
438       {
439       itoa((passwordstring[i]>>4),&temp[0],16);
440       string[(i<<1)+0]=temp[0];
441       itoa((passwordstring[i]&0xf),&temp[0],16);
442       string[(i<<1)+1]=temp[0];
443       }
444 }
445 
446 //******************************************************************************
447 //
448 // ConvertPasswordToPasswordString ()
449 //
450 //******************************************************************************
451 
ConvertPasswordToPasswordString(void)452 void ConvertPasswordToPasswordString ( void )
453 {
454    int i;
455    int x;
456    char temp[3];
457    char key[40];
458 
459    memset(temp,0,sizeof(temp));
460    strcpy(&key[0],PASSWORDENCRYPTER);
461 
462    for (i=0;i<12;i++)
463       {
464       memcpy(&temp[0],&key[i<<1],2);
465       sscanf(&temp[0],"%x",&x);
466       passwordstring[i]=pword[i]^x;
467       }
468    memcpy(&temp[0],&key[i<<1],2);
469    sscanf(&temp[0],"%x",&x);
470    passwordstring[i]=gamestate.violence^x;
471 }
472 
473 //******************************************************************************
474 //
475 // ParseConfigFile ()
476 //
477 //******************************************************************************
478 
ParseConfigFile(void)479 boolean ParseConfigFile (void)
480 {
481 //   int temp;
482    boolean retval = true;
483    int version    = 0;
484 
485    ReadInt("Version",&version);
486 
487    if (version == ROTTVERSION)
488    {
489       // Read in MouseEnabled
490 
491       ReadBoolean("MouseEnabled",&mouseenabled);
492 
493       // Read in JoystickEnabled
494 
495       ReadBoolean("JoystickEnabled",&joystickenabled);
496 
497       // Read in JoypadEnabled
498 
499       ReadBoolean("JoypadEnabled",&joypadenabled);
500 
501       // Read in JoystickPort
502 
503       ReadInt("JoystickPort",&joystickport);
504 
505       // Read in ViewSize
506 
507       ReadInt("ViewSize",&viewsize);
508 
509       // Read in MouseAdjustment
510 
511       ReadInt("MouseAdjustment",&mouseadjustment);
512 
513       // Read in threshold
514 
515       ReadInt("Threshold",&threshold);
516 
517       // Read in Auto Detail
518 
519       ReadBoolean ("AutoDetail", &AutoDetailOn);
520 
521       // Read in Light Dim
522 
523       ReadInt ("LightDim", &fulllight);
524 
525       // Read in Bobbin' On
526 
527       ReadBoolean ("BobbingOn", &BobbinOn);
528 
529       // Read in Double Click Speed
530 
531       ReadInt ("DoubleClickSpeed", &DoubleClickSpeed);
532 
533       // Read in Menu Flip Speed
534 
535       ReadInt ("MenuFlipSpeed", &Menuflipspeed);
536 
537       // Read in Detail Level
538 
539       ReadInt ("DetailLevel", &DetailLevel);
540 
541       // Read in Floor and Ceiling
542 
543       ReadInt ("FloorCeiling", &fandc);
544 
545       // Read in MessagesEnabled
546 
547       ReadBoolean ("Messages", &MessagesEnabled );
548 
549       // Read in Autorun
550 
551       ReadInt ("AutoRun", &gamestate.autorun );
552 
553       // Read in GammaIndex
554 
555       ReadInt ("GammaIndex", &gammaindex);
556 
557       // Read screen blanking time
558 
559       ReadInt ("BlankTime", &blanktime);
560 
561       blanktime=blanktime*60*VBLCOUNTER;
562 
563       // Read keys
564 
565       ReadInt ("Fire",        &buttonscan[0]);
566       ReadInt ("Strafe",      &buttonscan[1]);
567       ReadInt ("Run",         &buttonscan[2]);
568       ReadInt ("Use",         &buttonscan[3]);
569       ReadInt ("LookUp",      &buttonscan[4]);
570       ReadInt ("LookDn",      &buttonscan[5]);
571       ReadInt ("Swap",        &buttonscan[6]);
572       ReadInt ("Drop",        &buttonscan[7]);
573       ReadInt ("TargetUp",    &buttonscan[8]);
574       ReadInt ("TargetDn",    &buttonscan[9]);
575       ReadInt ("SelPistol",   &buttonscan[10]);
576       ReadInt ("SelDualPistol",&buttonscan[11]);
577       ReadInt ("SelMP40",     &buttonscan[12]);
578       ReadInt ("SelMissile",  &buttonscan[13]);
579       ReadInt ("AutoRun",     &buttonscan[14]);
580       ReadInt ("LiveRemRid",  &buttonscan[15]);
581       ReadInt ("StrafeLeft",  &buttonscan[16]);
582       ReadInt ("StrafeRight", &buttonscan[17]);
583       ReadInt ("VolteFace",   &buttonscan[18]);
584       ReadInt ("Aim",         &buttonscan[19]);
585       ReadInt ("Forward",     &buttonscan[20]);
586       ReadInt ("Right",       &buttonscan[21]);
587       ReadInt ("Backward",    &buttonscan[22]);
588       ReadInt ("Left",        &buttonscan[23]);
589       ReadInt ("Map",         &buttonscan[24]);
590       ReadInt ("SendMessage", &buttonscan[25]);
591       ReadInt ("DirectMessage",&buttonscan[26]);
592 
593 
594 #ifdef DC
595      {
596 	char buf[16];
597 	int i;
598 	for(i=0;i<MAX_MOUSEBTN;i++) {
599 		sprintf(buf,"MouseButton%d",i);
600 		ReadInt(buf,&buttonmouse[i]);
601 	}
602 	for(i=0;i<MAX_MOUSEBTN;i++) {
603 		sprintf(buf,"DblClockB%d",i);
604 		ReadInt(buf,&buttonmouse[i+MAX_MOUSEBTN]);
605 	}
606 	for(i=0;i<MAX_JOYBTN;i++) {
607 		sprintf(buf,"JoyButton%d",i);
608 		ReadInt(buf,&buttonjoy[i]);
609 	}
610 	for(i=0;i<MAX_JOYBTN;i++) {
611 		sprintf(buf,"DblClickJB%d",i);
612 		ReadInt(buf,&buttonjoy[i+MAX_JOYBTN]);
613 	}
614       }
615 #else
616       ReadInt ("MouseButton0",&buttonmouse[0]);
617       ReadInt ("MouseButton1",&buttonmouse[1]);
618       ReadInt ("MouseButton2",&buttonmouse[2]);
619       ReadInt ("DblClickB0",  &buttonmouse[MAX_MOUSEBTN+0]);
620       ReadInt ("DblClickB1",  &buttonmouse[MAX_MOUSEBTN+1]);
621       ReadInt ("DblClickB2",  &buttonmouse[MAX_MOUSEBTN+2]);
622 
623       ReadInt ("JoyButton0",  &buttonjoy[0]);
624       ReadInt ("JoyButton1",  &buttonjoy[1]);
625       ReadInt ("JoyButton2",  &buttonjoy[2]);
626       ReadInt ("JoyButton3",  &buttonjoy[3]);
627       ReadInt ("DblClickJB0", &buttonjoy[MAX_JOYBTN+0]);
628       ReadInt ("DblClickJB1", &buttonjoy[MAX_JOYBTN+1]);
629       ReadInt ("DblClickJB2", &buttonjoy[MAX_JOYBTN+2]);
630       ReadInt ("DblClickJB3", &buttonjoy[MAX_JOYBTN+3]);
631 #endif
632 
633       ReadInt ("JoyMaxX",     &joyxmax);
634       ReadInt ("JoyMaxY",     &joyymax);
635       ReadInt ("JoyMinX",     &joyxmin);
636       ReadInt ("JoyMinY",     &joyymin);
637 
638       ReadInt( "DefaultDifficulty", &DefaultDifficulty );
639       ReadInt( "DefaultPlayerCharacter", &DefaultPlayerCharacter );
640       ReadInt( "DefaultPlayerColor", &DefaultPlayerColor );
641 
642       // Get Password string
643       GetToken (true);
644       if (!stricmp (token, "SecretPassword"))
645          {
646          GetTokenEOL (false);
647          ConvertStringToPasswordString ( &name[0] );
648          }
649 
650       if (!CybermanPresent)
651          cybermanenabled = false;
652 
653       if (!AssassinPresent)
654          assassinenabled = false;
655 
656       if (!SpaceBallPresent)
657          spaceballenabled = false;
658 
659       if (!MousePresent)
660          mouseenabled = false;
661 
662       if (!JoysPresent[joystickport])
663          joystickenabled = false;
664 
665       // precaution
666 
667       if (!joyxmin || !joyxmax || !joyymin || !joyymax)
668          joystickenabled = false;
669 
670       if (joystickenabled)
671          IN_SetupJoy (joystickport, joyxmin, joyxmax, joyymin, joyymax);
672    }
673    else
674       retval = false;
675 
676    return (retval);
677 }
678 
679 
680 //******************************************************************************
681 //
682 // ParseBattleFile ()
683 //
684 //******************************************************************************
ParseBattleFile(void)685 boolean ParseBattleFile (void)
686 {
687    boolean retval = true;
688    int version    = 0;
689    int index;
690    int temp;
691    extern specials BattleSpecialsTimes;
692 
693    ReadInt("Version",&version);
694    if (version != ROTTVERSION)
695       retval = false;
696    else
697       {
698       ReadBoolean( "ShowKillCount", &BATTLE_ShowKillCount );
699 
700       ReadInt( "GodModeTime",                &BattleSpecialsTimes.GodModeTime );
701       ReadInt( "DogModeTime",                &BattleSpecialsTimes.DogModeTime );
702       ReadInt( "ShroomsModeTime",            &BattleSpecialsTimes.ShroomsModeTime );
703       ReadInt( "ElastoModeTime",             &BattleSpecialsTimes.ElastoModeTime );
704       ReadInt( "AsbestosVestTime",           &BattleSpecialsTimes.AsbestosVestTime );
705       ReadInt( "BulletProofVestTime",        &BattleSpecialsTimes.BulletProofVestTime );
706       ReadInt( "GasMaskTime",                &BattleSpecialsTimes.GasMaskTime );
707       ReadInt( "MercuryModeTime",            &BattleSpecialsTimes.MercuryModeTime );
708       ReadInt( "GodModeRespawnTime",         &BattleSpecialsTimes.GodModeRespawnTime );
709       ReadInt( "DogModeRespawnTime",         &BattleSpecialsTimes.DogModeRespawnTime );
710       ReadInt( "ShroomsModeRespawnTime",     &BattleSpecialsTimes.ShroomsModeRespawnTime );
711       ReadInt( "ElastoModeRespawnTime",      &BattleSpecialsTimes.ElastoModeRespawnTime );
712       ReadInt( "AsbestosVestRespawnTime",    &BattleSpecialsTimes.AsbestosVestRespawnTime );
713       ReadInt( "BulletProofVestRespawnTime", &BattleSpecialsTimes.BulletProofVestRespawnTime );
714       ReadInt( "GasMaskRespawnTime",         &BattleSpecialsTimes.GasMaskRespawnTime );
715       ReadInt( "MercuryModeRespawnTime",     &BattleSpecialsTimes.MercuryModeRespawnTime );
716 
717       ReadBoolean( "EKG", &battlegibs );
718 
719       for( index = battle_Normal; index < battle_NumBattleModes; index++ )
720          {
721          // Read Gravity
722          temp = BATTLE_Options[ index ].Gravity;
723          ReadInt( "Gravity", &temp );
724 			BATTLE_Options[ index ].Gravity = temp;
725 
726          // Read Speed
727          temp = bo_normal_speed;
728          ReadInt( "Speed", &temp );
729          if ( ( temp >= bo_normal_speed ) &&
730             ( temp <= bo_fast_speed ) )
731             {
732             BATTLE_Options[ index ].Speed = temp;
733             }
734 
735          if ( ( index != battle_Collector ) && ( index != battle_Tag ) &&
736             ( index != battle_Eluder ) )
737             {
738             // Read Ammo
739             temp = bo_normal_shots;
740             BATTLE_Options[ index ].Ammo = bo_normal_shots;
741             ReadInt( "Ammo", &temp );
742             if ( ( temp >= bo_one_shot ) &&
743                ( temp <= bo_infinite_shots ) )
744                {
745                BATTLE_Options[ index ].Ammo = temp;
746                }
747             }
748 
749          if ( index != battle_Eluder )
750             {
751             // Read Hitpoints
752             temp = BATTLE_Options[ index ].HitPoints;
753             ReadInt( "Hitpoints", &temp );
754             BATTLE_Options[ index ].HitPoints = temp;
755             }
756 
757          // Read Spawn Dangers
758          temp = 1;
759          ReadInt( "SpawnDangers", &temp );
760          BATTLE_Options[ index ].SpawnDangers = temp;
761 
762          if ( index != battle_Eluder )
763             {
764             // Read Spawn Health
765             temp = 1;
766             ReadInt( "SpawnHealth", &temp );
767             BATTLE_Options[ index ].SpawnHealth = temp;
768 
769             // Read Spawn Mines
770             temp = 0;
771             ReadInt( "SpawnMines", &temp );
772             BATTLE_Options[ index ].SpawnMines = temp;
773             }
774 
775          if ( ( index != battle_Collector ) && ( index != battle_Tag ) &&
776             ( index != battle_Eluder ) )
777             {
778             // Read Spawn Weapons
779             temp = 1;
780             ReadInt( "SpawnWeapons", &temp );
781             BATTLE_Options[ index ].SpawnWeapons = temp;
782 
783             // Read Random Weapons
784             temp = 0;
785             ReadInt( "RandomWeapons", &temp );
786             BATTLE_Options[ index ].RandomWeapons = temp;
787 
788             // Read Weapon Persistence
789             temp = 0;
790             ReadInt( "WeaponPersistence", &temp );
791             BATTLE_Options[ index ].WeaponPersistence = temp;
792             }
793 
794          if ( ( index == battle_Normal ) || ( index == battle_ScoreMore ) ||
795             ( index == battle_Hunter ) || ( index == battle_Tag ) )
796             {
797             // Read Friendly Fire
798             temp = 1;
799             ReadInt( "FriendlyFire", &temp );
800             BATTLE_Options[ index ].FriendlyFire = temp;
801             }
802 
803          if ( index != battle_Eluder )
804             {
805             // Read Respawn Items
806             temp = 1;
807             ReadInt( "RespawnItems", &temp );
808             BATTLE_Options[ index ].RespawnItems = temp;
809             }
810 
811          // Read Light Level
812          temp = bo_light_normal;
813          ReadInt( "LightLevel", &temp );
814          if ( ( temp >= bo_light_dark ) &&
815             ( temp <= bo_light_lightning ) )
816             {
817             BATTLE_Options[ index ].LightLevel = temp;
818             }
819 
820          if ( ( index != battle_Collector ) && ( index != battle_Scavenger ) )
821             {
822             // Read Point Goal
823             temp = bo_kills_default;
824             ReadInt( "PointGoal", &temp );
825             BATTLE_Options[ index ].Kills = temp;
826             if ( temp < bo_kills_random )
827                {
828                BATTLE_Options[ index ].Kills = bo_kills_default;
829                }
830             }
831 
832          if ( index != battle_Eluder )
833             {
834             // Read Danger Damage
835             temp = bo_danger_normal;
836             ReadInt( "DangerDamage", &temp );
837             BATTLE_Options[ index ].DangerDamage = temp;
838             }
839 
840          // Read Time Limit
841          temp = bo_time_infinite;
842          ReadInt( "TimeLimit", &temp );
843          if ( ( index == battle_Hunter ) && ( temp == bo_time_infinite ) )
844             {
845             temp = 99;
846             }
847          BATTLE_Options[ index ].TimeLimit = temp;
848 
849          // Read Respawn time
850          temp = bo_normal_respawn_time;
851          ReadInt( "RespawnTime", &temp );
852          BATTLE_Options[ index ].RespawnTime = temp;
853          }
854       }
855 
856    return (retval);
857    }
858 
859 //******************************************************************************
860 //
861 // SetBattleDefaultValues ()
862 //
863 //******************************************************************************
864 
SetBattleDefaultValues(void)865 void SetBattleDefaultValues (void)
866 {
867    int index;
868 
869    //
870    //  no config file, so select default values
871    //
872    for( index = battle_StandAloneGame; index < battle_NumBattleModes;
873       index++ )
874       {
875       BATTLE_Options[ index ].Gravity      = NORMAL_GRAVITY;
876       BATTLE_Options[ index ].Speed        = bo_normal_speed;
877       BATTLE_Options[ index ].Ammo         = bo_normal_shots;
878       BATTLE_Options[ index ].HitPoints    = bo_default_hitpoints;
879       BATTLE_Options[ index ].SpawnDangers = 1;
880       BATTLE_Options[ index ].SpawnHealth  = 1;
881       BATTLE_Options[ index ].SpawnMines   = 0;
882       BATTLE_Options[ index ].SpawnWeapons = 1;
883       BATTLE_Options[ index ].RespawnItems = 1;
884       BATTLE_Options[ index ].RandomWeapons = 0;
885       BATTLE_Options[ index ].WeaponPersistence = 0;
886       BATTLE_Options[ index ].FriendlyFire = 1;
887       BATTLE_Options[ index ].LightLevel   = bo_light_normal;
888       BATTLE_Options[ index ].Kills        = bo_kills_default;
889       BATTLE_Options[ index ].DangerDamage = bo_danger_normal;
890       BATTLE_Options[ index ].TimeLimit    = bo_time_infinite;
891       BATTLE_Options[ index ].RespawnTime  = bo_normal_respawn_time;
892       }
893 
894    BATTLE_Options[ battle_CaptureTheTriad ].Kills  = 1;
895    BATTLE_Options[ battle_Hunter ].TimeLimit       = 1;
896    BATTLE_Options[ battle_Eluder ].SpawnHealth     = 0;
897    BATTLE_Options[ battle_Eluder ].RespawnItems    = 0;
898    BATTLE_Options[ battle_Eluder ].SpawnWeapons    = 0;
899    BATTLE_Options[ battle_Eluder ].FriendlyFire    = 0;
900    BATTLE_Options[ battle_Collector ].SpawnWeapons = 0;
901    BATTLE_Options[ battle_Collector ].FriendlyFire = 0;
902    BATTLE_Options[ battle_Tag ].SpawnWeapons       = 0;
903    battlegibs=false;
904    BATTLE_ShowKillCount = true;
905    }
906 
907 //******************************************************************************
908 //
909 // SetConfigDefaultValues ()
910 //
911 //******************************************************************************
912 
SetConfigDefaultValues(void)913 void SetConfigDefaultValues (void)
914 {
915    //
916    //  no config file, so select default values
917    //
918    if (MousePresent)
919       mouseenabled = true;
920 
921 #ifdef DC
922    joystickenabled = true;
923    joypadenabled   = true;
924 	joyxmin = joyymin = 1;
925 	joyxmax = joyymax = 255;
926 #else
927    joystickenabled = false;
928    joypadenabled   = false;
929 #endif
930    joystickport    = 0;
931    viewsize        = 7;
932    mouseadjustment = 5;
933    gammaindex      = 0;
934    gamestate.violence = 3;
935    passwordstring[0]=0x7d;
936    passwordstring[1]=0x7e;
937    passwordstring[2]=0x4a;
938    passwordstring[3]=0x2d;
939    passwordstring[4]=0x3b;
940    passwordstring[5]=0x6a;
941    passwordstring[6]=0x03;
942    passwordstring[7]=0x19;
943    passwordstring[8]=0x55;
944    passwordstring[9]=0x46;
945    passwordstring[10]=0x54;
946    passwordstring[11]=0x23;
947    passwordstring[12]=0x1c;
948 }
949 #endif
950 
951 //******************************************************************************
952 //
953 // DeleteSoundFile ()
954 //
955 //******************************************************************************
DeleteSoundFile(void)956 void DeleteSoundFile ( void )
957 {
958    char filename[ 128 ];
959 
960    GetPathFromEnvironment( filename, ApogeePath, SoundName );
961    unlink (filename);          // Delete SOUND.ROT
962 }
963 
964 //******************************************************************************
965 //
966 // ReadConfig ()
967 //
968 //******************************************************************************
969 
970 
ReadConfig(void)971 void ReadConfig (void)
972 {
973    char filename[ 128 ];
974 
975    GetPathFromEnvironment( filename, ApogeePath, SoundName );
976    SetSoundDefaultValues ();
977 
978    if (access (filename, F_OK) == 0)
979       {
980       LoadScriptFile (filename);
981 
982       if (ParseSoundFile () == false)
983          {
984          DeleteSoundFile();
985          }
986 
987       Z_Free (scriptbuffer);
988       }
989 #ifdef DOS
990    else if ( !SOUNDSETUP )
991       {
992       Error( "Could not find SOUND.ROT.  Please run SNDSETUP to configure "
993          "your sound hardware." );
994       }
995 #endif
996 
997 
998 #ifdef _ROTT_
999    ReadScores();
1000 
1001    GetPathFromEnvironment( filename, ApogeePath, ConfigName );
1002    SetConfigDefaultValues ();
1003    if (access(filename,F_OK)==0)
1004       {
1005       LoadScriptFile(filename);
1006 
1007       if (ParseConfigFile () == false)
1008          {
1009          unlink (filename);          // Delete CONFIG.ROT
1010          }
1011 
1012       Z_Free(scriptbuffer);
1013       }
1014 
1015    GetPathFromEnvironment( filename, ApogeePath, BattleName );
1016    SetBattleDefaultValues ();
1017    if (access(filename,F_OK)==0)
1018       {
1019       LoadScriptFile(filename);
1020 
1021       if (ParseBattleFile() == false)
1022          {
1023          unlink (filename);          // Delete BATTLE.ROT
1024          }
1025 
1026       Z_Free(scriptbuffer);
1027       }
1028 #endif
1029    ConfigLoaded = true;
1030 }
1031 
1032 //******************************************************************************
1033 //
1034 // CheckVendor ()
1035 //
1036 //******************************************************************************
1037 
1038 
CheckVendor(void)1039 void CheckVendor (void)
1040 {
1041 #ifndef DC
1042    boolean saveout=false;
1043    int wadcrc;
1044    int filecrc;
1045    int size;
1046    int lump;
1047    byte * vendor;
1048    char filename[ 128 ];
1049 #if (SHAREWARE==1)
1050  const char *VENDORDOC=("VENDOR.DOC");
1051  const char *VENDORLUMP=("VENDOR");
1052 #else
1053  const char *VENDORDOC=("LICENSE.DOC");
1054  const char *VENDORLUMP=("LICENSE");
1055 #endif
1056 
1057 
1058    GetPathFromEnvironment( filename, ApogeePath, VENDORDOC );
1059    if (access (filename, F_OK) == 0)
1060       {
1061       size = LoadFile(filename,(void **)&vendor);
1062       filecrc = CalculateCRC (vendor, size);
1063       SafeFree(vendor);
1064       lump=W_GetNumForName(VENDORLUMP);
1065       vendor = W_CacheLumpNum(lump,PU_CACHE, CvtNull, 1);
1066       size=W_LumpLength(lump);
1067       wadcrc = CalculateCRC (vendor, size);
1068       if (wadcrc != filecrc)
1069          saveout=true;
1070       }
1071    else
1072       saveout=true;
1073 
1074    if (saveout==true)
1075       {
1076       lump=W_GetNumForName(VENDORLUMP);
1077       vendor = W_CacheLumpNum(lump,PU_CACHE, CvtNull, 1);
1078       size = W_LumpLength(lump);
1079       SaveFile (filename,vendor,size);
1080       }
1081 #endif
1082 }
1083 
1084 //******************************************************************************
1085 //
1086 // WriteParameter
1087 //
1088 //******************************************************************************
1089 
WriteParameter(int file,const char * s1,int val)1090 void WriteParameter (int file, const char * s1, int val)
1091 {
1092    char s[50];
1093 
1094    // Write out Header
1095    SafeWriteString (file, (char *)s1);
1096 
1097    // Write out space character
1098    strcpy (&s[0],(const char *)"  ");
1099    SafeWriteString (file, &s[0]);
1100 
1101    // Write out value
1102    itoa(val,&s[0],10);
1103    SafeWriteString (file, &s[0]);
1104 
1105    // Write out EOL character
1106    strcpy (&s[0],(const char *)"\n");
1107    SafeWriteString (file, &s[0]);
1108 }
1109 
1110 
1111 //******************************************************************************
1112 //
1113 // WriteParameterHex
1114 //
1115 //******************************************************************************
1116 
WriteParameterHex(int file,const char * s1,int val)1117 void WriteParameterHex (int file, const char * s1, int val)
1118 {
1119    char s[50];
1120 
1121    // Write out Header
1122    SafeWriteString (file, (char *)s1);
1123 
1124    // Write out space character
1125    strcpy (&s[0],(const char *)"  $");
1126    SafeWriteString (file, &s[0]);
1127 
1128    // Write out value
1129    itoa(val,&s[0],16);
1130    SafeWriteString (file, &s[0]);
1131 
1132    // Write out EOL character
1133    strcpy (&s[0],(const char *)"\n");
1134    SafeWriteString (file, &s[0]);
1135 }
1136 
1137 
1138 
1139 #ifdef _ROTT_
1140 
1141 //******************************************************************************
1142 //
1143 // WriteScores ()
1144 //
1145 //******************************************************************************
1146 
WriteScores(void)1147 void WriteScores (void)
1148 {
1149    int file;
1150    char filename[ 128 ];
1151 
1152    GetPathFromEnvironment( filename, ApogeePath, ScoresName );
1153    file=SafeOpenWrite( filename );
1154    SafeWrite (file, &Scores, sizeof (Scores));
1155    close(file);
1156 }
1157 
1158 
1159 //******************************************************************************
1160 //
1161 // WriteBattleConfig ()
1162 //
1163 //******************************************************************************
1164 
WriteBattleConfig(void)1165 void WriteBattleConfig
1166    (
1167    void
1168    )
1169 
1170    {
1171    int  file;
1172    int  index;
1173    char filename[ 128 ];
1174    extern specials BattleSpecialsTimes;
1175 
1176    // Write Battle File
1177    GetPathFromEnvironment( filename, ApogeePath, BattleName );
1178    file = open( filename, O_RDWR | O_TEXT | O_CREAT | O_TRUNC,
1179       S_IREAD | S_IWRITE );
1180 
1181    if ( file == -1 )
1182       {
1183       Error( "Error opening %s: %s", filename, strerror( errno ) );
1184       }
1185 
1186    // Write out BATTLECONFIG header
1187    SafeWriteString( file,
1188       ";Rise of the Triad Battle Configuration File\n"
1189       ";                  (c) 1995\n"
1190       ";\n"
1191       ";You may change these options at you own risk.  Using any values\n"
1192       ";other than the ones documented may make the game unplayable.\n"
1193       ";If this happens, you may delete this file (BATTLE.ROT) and ROTT\n"
1194       ";will recreate it with the default values selected.\n"
1195       ";\n"
1196       ";With that in mind, have fun!\n"
1197       ";\n"
1198       "\n" );
1199 
1200    // Write out Version
1201    WriteParameter( file, "Version                        ", ROTTVERSION );
1202 
1203    // Write out BATTLE_ShowKillPics
1204    SafeWriteString(file, "\n;\n");
1205 	WriteParameter( file, "; Yes                        - ", 1 );
1206    WriteParameter( file, "; No                         - ", 0 );
1207    WriteParameter( file, "ShowKillCount                  ", BATTLE_ShowKillCount );
1208 
1209    // Write out specials' times
1210    SafeWriteString(file, "\n;\n"
1211       "; These are the time in seconds of the various powerups.\n"
1212       "; You could modify these to give you infinite Mercury mode,\n"
1213       "; stronger vests, or to make them persistant.\n;\n" );
1214 
1215    WriteParameter( file, "GodModeTime                ", BattleSpecialsTimes.GodModeTime );
1216    WriteParameter( file, "DogModeTime                ", BattleSpecialsTimes.DogModeTime );
1217    WriteParameter( file, "ShroomsModeTime            ", BattleSpecialsTimes.ShroomsModeTime );
1218    WriteParameter( file, "ElastoModeTime             ", BattleSpecialsTimes.ElastoModeTime );
1219    WriteParameter( file, "AsbestosVestTime           ", BattleSpecialsTimes.AsbestosVestTime );
1220    WriteParameter( file, "BulletProofVestTime        ", BattleSpecialsTimes.BulletProofVestTime );
1221    WriteParameter( file, "GasMaskTime                ", BattleSpecialsTimes.GasMaskTime );
1222    WriteParameter( file, "MercuryModeTime            ", BattleSpecialsTimes.MercuryModeTime );
1223    WriteParameter( file, "GodModeRespawnTime         ", BattleSpecialsTimes.GodModeRespawnTime );
1224    WriteParameter( file, "DogModeRespawnTime         ", BattleSpecialsTimes.DogModeRespawnTime );
1225    WriteParameter( file, "ShroomsModeRespawnTime     ", BattleSpecialsTimes.ShroomsModeRespawnTime );
1226    WriteParameter( file, "ElastoModeRespawnTime      ", BattleSpecialsTimes.ElastoModeRespawnTime );
1227    WriteParameter( file, "AsbestosVestRespawnTime    ", BattleSpecialsTimes.AsbestosVestRespawnTime );
1228    WriteParameter( file, "BulletProofVestRespawnTime ", BattleSpecialsTimes.BulletProofVestRespawnTime );
1229    WriteParameter( file, "GasMaskRespawnTime         ", BattleSpecialsTimes.GasMaskRespawnTime );
1230    WriteParameter( file, "MercuryModeRespawnTime     ", BattleSpecialsTimes.MercuryModeRespawnTime );
1231 
1232    // Write out battlegibs
1233    SafeWriteString(file, "\n;\n");
1234 	WriteParameter( file, "; Yes                        - ", 1 );
1235    WriteParameter( file, "; No                         - ", 0 );
1236    WriteParameter( file, "EKG                            ", battlegibs );
1237 
1238    // Describe options
1239 
1240    // Write out Gravity
1241    SafeWriteString(file, "\n"
1242                          ";\n"
1243                          "; Here is a description of the possible values for"
1244                          " each option:\n"
1245                          ";\n"
1246                          "; Gravity options:\n" );
1247    WriteParameter( file, ";    Low Gravity             - ", LOW_GRAVITY );
1248    WriteParameter( file, ";    Normal Gravity          - ", NORMAL_GRAVITY );
1249    WriteParameter( file, ";    High Gravity            - ", HIGH_GRAVITY );
1250 
1251    // Write out Speed
1252    SafeWriteString(file, ";\n"
1253                          "; Speed options:\n" );
1254    WriteParameter( file, ";    Normal Speed            - ", bo_normal_speed );
1255    WriteParameter( file, ";    Fast Speed              - ", bo_fast_speed );
1256 
1257    // Write out Ammo
1258    SafeWriteString(file, ";\n"
1259                          "; Ammo options:\n" );
1260    WriteParameter( file, ";    One Shot                - ", bo_one_shot );
1261    WriteParameter( file, ";    Normal Shots            - ", bo_normal_shots );
1262    WriteParameter( file, ";    Infinite Shots          - ", bo_infinite_shots );
1263 
1264    // Write out Hit Points
1265    SafeWriteString(file, ";\n"
1266                          "; Hitpoint options:\n" );
1267    WriteParameter( file, ";    Character Hitpoints     - ", bo_character_hitpoints );
1268    WriteParameter( file, ";       1 Hitpoint           - ", 1 );
1269    WriteParameter( file, ";      25 Hitpoints          - ", 25 );
1270    WriteParameter( file, ";     100 Hitpoints          - ", 100 );
1271    WriteParameter( file, ";     500 Hitpoints          - ", 500 );
1272    WriteParameter( file, ";     250 Hitpoints          - ", 250 );
1273    WriteParameter( file, ";    4000 Hitpoints          - ", 4000 );
1274 
1275    // Write out Danger Spawning
1276    SafeWriteString(file, ";\n"
1277                          "; SpawnDangers options:\n"
1278                          ";    Spawn Dangers           -   1\n"
1279                          ";    Don't Spawn Dangers     -   0\n" );
1280 
1281    // Write out Health Spawning
1282    SafeWriteString(file, ";\n"
1283                          "; SpawnHealth options:\n"
1284                          ";    Spawn Health            -   1\n"
1285                          ";    Don't Spawn Health      -   0\n" );
1286 
1287    // Write out Mine Spawning
1288    SafeWriteString(file, ";\n"
1289                          "; SpawnMines options:\n"
1290                          ";    Spawn Mines             -   1\n"
1291                          ";    Don't Spawn Mines       -   0\n" );
1292 
1293    // Write out Weapon Spawning
1294    SafeWriteString(file, ";\n"
1295                          "; SpawnWeapons options:\n"
1296                          ";    Spawn Weapons           -   1\n"
1297                          ";    Don't Spawn Weapons     -   0\n" );
1298 
1299    // Write out Random Weapons
1300    SafeWriteString(file, ";\n"
1301                          "; RandomWeapons options:\n"
1302                          ";    Randomize Weapons       -   1\n"
1303                          ";    Don't Randomize Weapons -   0\n" );
1304 
1305    // Write out Weapon Persistence
1306    SafeWriteString(file, ";\n"
1307                          "; WeaponPersistence options:\n"
1308                          ";    Weapons Persist         -   1\n"
1309                          ";    Weapons don't Persist   -   0\n" );
1310 
1311    // Write out Friendly Fire
1312    SafeWriteString(file, ";\n"
1313                          "; FriendlyFire options:\n"
1314                          ";    Penalize Friendly Fire  -   1\n"
1315                          ";    No penalty              -   0\n" );
1316 
1317    // Write out Respawn Items
1318    SafeWriteString(file, ";\n"
1319                          "; RespawnItems options:\n"
1320                          ";    Respawn Items           -   1\n"
1321                          ";    Don't Respawn Items     -   0\n" );
1322 
1323    // Write out Light Level
1324    SafeWriteString(file, ";\n"
1325                          "; LightLevel options:\n" );
1326    WriteParameter( file, ";    Dark                    - ", bo_light_dark );
1327    WriteParameter( file, ";    Normal Light Levels     - ", bo_light_normal );
1328    WriteParameter( file, ";    Bright                  - ", bo_light_bright );
1329    WriteParameter( file, ";    Fog                     - ", bo_light_fog );
1330    WriteParameter( file, ";    Periodic light          - ", bo_light_periodic );
1331    WriteParameter( file, ";    Lightning               - ", bo_light_lightning );
1332 
1333    // Write out Point Goal
1334    SafeWriteString(file, ";\n"
1335                          "; PointGoal options:\n" );
1336    WriteParameter( file, ";           1 Point          - ", 1 );
1337    WriteParameter( file, ";           5 Points         - ", 5 );
1338    WriteParameter( file, ";          11 Points         - ", 11 );
1339    WriteParameter( file, ";          21 Points         - ", 21 );
1340    WriteParameter( file, ";          50 Points         - ", 50 );
1341    WriteParameter( file, ";         100 Points         - ", 100 );
1342    WriteParameter( file, ";      Random Points         - ", bo_kills_random );
1343    WriteParameter( file, ";       Blind Points         - ", bo_kills_blind );
1344    WriteParameter( file, ";    Infinite Points         - ", bo_kills_infinite );
1345 
1346    // Write out Danger Damage
1347    SafeWriteString(file, ";\n"
1348                          "; DangerDamage options:\n" );
1349    WriteParameter( file, ";    Normal Damage           - ", bo_danger_normal );
1350    WriteParameter( file, ";    Low Damage              - ", bo_danger_low );
1351    WriteParameter( file, ";    Kill                    - ", bo_danger_kill );
1352 
1353    // Write out TimeLimit
1354    SafeWriteString(file, ";\n"
1355                          "; TimeLimit options:\n" );
1356    WriteParameter( file, ";     1 minute               - ", 1 );
1357    WriteParameter( file, ";     2 minute               - ", 2 );
1358    WriteParameter( file, ";     5 minutes              - ", 5 );
1359    WriteParameter( file, ";    10 minutes              - ", 10 );
1360    WriteParameter( file, ";    21 minutes              - ", 21 );
1361    WriteParameter( file, ";    30 minutes              - ", 30 );
1362    WriteParameter( file, ";    99 minutes              - ", 99 );
1363    WriteParameter( file, ";    No limit                - ", bo_time_infinite );
1364 
1365    // Write out RespawnTime
1366    SafeWriteString(file, ";\n"
1367                          "; RespawnTime options:\n" );
1368    WriteParameter( file, ";     1 second               - ", 1 );
1369    WriteParameter( file, ";     1 minute               - ", 60 );
1370    WriteParameter( file, ";     2 minutes              - ", 120 );
1371    WriteParameter( file, ";       normal               - ", bo_normal_respawn_time );
1372 
1373    for( index = battle_Normal; index < battle_NumBattleModes; index++ )
1374       {
1375       SafeWriteString(file, "\n;\n");
1376       switch( index )
1377          {
1378          case battle_Normal :
1379             SafeWriteString( file, "; Standard battle options\n;\n" );
1380             break;
1381 
1382          case battle_ScoreMore :
1383             SafeWriteString( file, "; Score More battle options\n;\n" );
1384             break;
1385 
1386          case battle_Collector :
1387             SafeWriteString( file, "; Collector battle options\n;\n" );
1388             break;
1389 
1390          case battle_Scavenger :
1391             SafeWriteString( file, "; Scavenger battle options\n;\n" );
1392             break;
1393 
1394          case battle_Hunter :
1395             SafeWriteString( file, "; Hunter battle options\n;\n" );
1396             break;
1397 
1398          case battle_Tag :
1399             SafeWriteString( file, "; Tag battle options\n;\n" );
1400             break;
1401 
1402          case battle_Eluder :
1403             SafeWriteString( file, "; Eluder battle options\n;\n" );
1404             break;
1405 
1406          case battle_Deluder :
1407             SafeWriteString( file, "; Deluder battle options\n;\n" );
1408             break;
1409 
1410 			case battle_CaptureTheTriad :
1411 				SafeWriteString( file, "; Capture the Triad battle options\n;\n" );
1412 				break;
1413 			}
1414 
1415 		// Write out Gravity
1416       WriteParameter( file, "Gravity          ",
1417          BATTLE_Options[ index ].Gravity );
1418 
1419       // Write out Speed
1420       WriteParameter( file, "Speed            ",
1421          BATTLE_Options[ index ].Speed );
1422 
1423       if ( ( index != battle_Collector ) && ( index != battle_Tag ) &&
1424          ( index != battle_Eluder ) )
1425          {
1426          // Write out Ammo
1427          WriteParameter( file, "Ammo             ",
1428             BATTLE_Options[ index ].Ammo );
1429          }
1430 
1431       if ( index != battle_Eluder )
1432          {
1433          // Write out Hit Points
1434          WriteParameter( file, "Hitpoints        ",
1435             BATTLE_Options[ index ].HitPoints );
1436          }
1437 
1438       // Write out Danger Spawning
1439       WriteParameter( file, "SpawnDangers     ",
1440          BATTLE_Options[ index ].SpawnDangers );
1441 
1442       if ( index != battle_Eluder )
1443          {
1444          // Write out Health Spawning
1445          WriteParameter( file, "SpawnHealth      ",
1446             BATTLE_Options[ index ].SpawnHealth );
1447 
1448          // Write out Mine Spawning
1449          WriteParameter( file, "SpawnMines       ",
1450             BATTLE_Options[ index ].SpawnMines );
1451          }
1452 
1453       if ( ( index != battle_Collector ) && ( index != battle_Tag ) &&
1454          ( index != battle_Eluder ) )
1455          {
1456          // Write out Weapon Spawning
1457          WriteParameter( file, "SpawnWeapons     ",
1458             BATTLE_Options[ index ].SpawnWeapons );
1459 
1460          // Write out Random Weapons
1461          WriteParameter( file, "RandomWeapons    ",
1462             BATTLE_Options[ index ].RandomWeapons );
1463 
1464          // Write out Weapon Persistence
1465          WriteParameter( file, "WeaponPersistence",
1466             BATTLE_Options[ index ].WeaponPersistence );
1467          }
1468 
1469       if ( ( index == battle_Normal ) || ( index == battle_ScoreMore ) ||
1470          ( index == battle_Hunter ) || ( index == battle_Tag ) )
1471          {
1472          // Write out Friendly Fire
1473          WriteParameter( file, "FriendlyFire     ",
1474             BATTLE_Options[ index ].FriendlyFire );
1475          }
1476 
1477       if ( index != battle_Eluder )
1478          {
1479          // Write out Respawn Items
1480          WriteParameter( file, "RespawnItems     ",
1481             BATTLE_Options[ index ].RespawnItems );
1482          }
1483 
1484       // Write out Light Level
1485       WriteParameter( file, "LightLevel       ",
1486          BATTLE_Options[ index ].LightLevel );
1487 
1488       if ( ( index != battle_Collector ) && ( index != battle_Scavenger ) )
1489          {
1490          // Write out Point Goal
1491          WriteParameter( file, "PointGoal        ",
1492             BATTLE_Options[ index ].Kills );
1493          }
1494 
1495       if ( index != battle_Eluder )
1496          {
1497          // Write out Danger Damage
1498          WriteParameter( file, "DangerDamage     ",
1499             BATTLE_Options[ index ].DangerDamage );
1500          }
1501 
1502       // Write out TimeLimit
1503       WriteParameter( file, "TimeLimit        ",
1504          BATTLE_Options[ index ].TimeLimit );
1505 
1506       // Write out RespawnTime
1507       WriteParameter( file, "RespawnTime      ",
1508          BATTLE_Options[ index ].RespawnTime );
1509       }
1510 
1511    close( file );
1512    }
1513 
1514 #endif
1515 
1516 //******************************************************************************
1517 //
1518 // WriteSoundConfig ()
1519 //
1520 //******************************************************************************
1521 
WriteSoundConfig(void)1522 void WriteSoundConfig
1523    (
1524    void
1525    )
1526 
1527    {
1528    int file;
1529    char filename[ 128 ];
1530 
1531    if ( !WriteSoundFile )
1532       {
1533       return;
1534       }
1535 
1536    GetPathFromEnvironment( filename, ApogeePath, SoundName );
1537    file = open ( filename, O_RDWR | O_TEXT | O_CREAT | O_TRUNC,
1538       S_IREAD | S_IWRITE);
1539 
1540    if (file == -1)
1541       Error ("Error opening %s: %s", filename, strerror(errno));
1542 
1543    // Write out ROTTSOUND header
1544 
1545    SafeWriteString (file, ";Rise of the Triad Sound File\n");
1546    SafeWriteString (file, ";                  (c) 1995\n\n");
1547 
1548    // Write out Version
1549 
1550    WriteParameter(file,"Version          ",ROTTVERSION);
1551 
1552    // Write out Music Mode
1553 
1554    SafeWriteString(file,"\n;\n");
1555    SafeWriteString(file,"; Music Modes\n");
1556    SafeWriteString(file,"; 0  -  Off\n");
1557    SafeWriteString(file,"; 1  -  UltraSound\n");
1558    SafeWriteString(file,"; 2  -  Sound Blaster\n");
1559    SafeWriteString(file,"; 3  -  Sound Man 16\n");
1560    SafeWriteString(file,"; 4  -  Pro Audio Spectrum\n");
1561    SafeWriteString(file,"; 5  -  Awe32\n");
1562    SafeWriteString(file,"; 6  -  SoundScape\n");
1563    SafeWriteString(file,"; 7  -  Wave Blaster\n");
1564    SafeWriteString(file,"; 8  -  General Midi\n");
1565    SafeWriteString(file,"; 9  -  Sound Canvas\n");
1566    SafeWriteString(file,"; 10 -  Adlib\n");
1567    WriteParameter(file,"MusicMode        ",MusicMode);
1568 
1569    // Write out FX Mode
1570 
1571    SafeWriteString(file,"\n;\n");
1572    SafeWriteString(file,"; FX Modes\n");
1573    SafeWriteString(file,"; 0  -  Off\n");
1574    SafeWriteString(file,"; 1  -  UltraSound\n");
1575    SafeWriteString(file,"; 2  -  Sound Blaster\n");
1576    SafeWriteString(file,"; 3  -  Sound Man 16\n");
1577    SafeWriteString(file,"; 4  -  Pro Audio Spectrum\n");
1578    SafeWriteString(file,"; 5  -  Awe32\n");
1579    SafeWriteString(file,"; 6  -  SoundScape\n");
1580    SafeWriteString(file,"; 7  -  Adlib\n");
1581    SafeWriteString(file,"; 8  -  Disney Sound Source\n");
1582    SafeWriteString(file,"; 9  -  Tandy Sound Source\n");
1583    SafeWriteString(file,"; 10 -  PC Speaker\n");
1584    WriteParameter(file,"FXMode           ",FXMode);
1585 
1586    // Write in Music Volume
1587 
1588    SafeWriteString(file,"\n;\n");
1589    SafeWriteString(file,"; Music Volume\n");
1590    SafeWriteString(file,"; (low) 0 - 255 (high)\n");
1591    WriteParameter (file, "MusicVolume    ", MUvolume);
1592 
1593    // Write in FX Volume
1594 
1595    SafeWriteString(file,"\n;\n");
1596    SafeWriteString(file,"; FX Volume\n");
1597    SafeWriteString(file,"; (low) 0 - 255 (high)\n");
1598    WriteParameter (file, "FXVolume       ", FXvolume);
1599 
1600    // Write out numvoices
1601 
1602    SafeWriteString(file,"\n;\n");
1603    SafeWriteString(file,"; Number of Voices\n");
1604    SafeWriteString(file,"; 1 - 8\n");
1605    WriteParameter(file,"NumVoices        ",NumVoices);
1606 
1607    // Write out numchannels
1608 
1609    SafeWriteString(file,"\n;\n");
1610    SafeWriteString(file,"; Stereo or Mono\n");
1611    SafeWriteString(file,"; 1 - Mono\n");
1612    SafeWriteString(file,"; 2 - Stereo\n");
1613    WriteParameter(file,"NumChannels      ",NumChannels);
1614 
1615    // Write out numbits
1616 
1617    SafeWriteString(file,"\n;\n");
1618    SafeWriteString(file,"; Resolution\n");
1619    SafeWriteString(file,"; 8 bit\n");
1620    SafeWriteString(file,"; 16 bit\n");
1621    WriteParameter(file,"NumBits          ",NumBits);
1622 
1623    // Write out Midi Address
1624 
1625    SafeWriteString(file,"\n;\n");
1626    SafeWriteString(file,"; Midi Addresses\n");
1627    SafeWriteString(file,"; $300\n");
1628    SafeWriteString(file,"; $310\n");
1629    SafeWriteString(file,"; $320\n");
1630    SafeWriteString(file,"; $330\n");
1631    SafeWriteString(file,"; $340\n");
1632    SafeWriteString(file,"; $350\n");
1633    SafeWriteString(file,"; $360\n");
1634    SafeWriteString(file,"; $370\n");
1635    SafeWriteString(file,"; $380\n");
1636    WriteParameterHex(file,"MidiAddress      ",MidiAddress);
1637 
1638    // Write out stereo reversal
1639 
1640    SafeWriteString(file,"\n;\n");
1641    SafeWriteString(file,"; ReverseStereo\n");
1642    SafeWriteString(file,"; 0 no reversal\n");
1643    SafeWriteString(file,"; 1 reverse stereo\n");
1644    WriteParameter (file,"StereoReverse      ",stereoreversed);
1645 
1646    // Write out Sound Blaster info
1647 
1648    SafeWriteString(file,"\n;\n");
1649    SafeWriteString(file,"; Sound Blaster Settings\n");
1650    WriteParameter(file, "SBType           ", SBSettings.Type );
1651    WriteParameterHex(file, "SBPort           ", SBSettings.Address );
1652    WriteParameter(file, "SBIrq            ", SBSettings.Interrupt );
1653    WriteParameter(file, "SBDma8           ", SBSettings.Dma8 );
1654    WriteParameter(file, "SBDma16          ", SBSettings.Dma16 );
1655    WriteParameterHex(file, "SBMidi           ", SBSettings.Midi );
1656    WriteParameterHex(file, "SBEmu            ", SBSettings.Emu );
1657 
1658    close (file);
1659    }
1660 
1661 
1662 //******************************************************************************
1663 //
1664 // WriteConfig ()
1665 //
1666 //******************************************************************************
1667 
WriteConfig(void)1668 void WriteConfig (void)
1669 {
1670    int file;
1671    char filename[ 128 ];
1672    char passwordtemp[50];
1673    static int inconfig = 0;
1674 
1675    if (inconfig > 0)
1676       return;
1677 
1678    inconfig++ ;
1679 
1680    if ( !ConfigLoaded )
1681       {
1682       return;
1683       }
1684 
1685    // Write Sound File
1686    WriteSoundConfig();
1687 
1688   // Write Config, Battle and Score files
1689 #ifdef _ROTT_
1690    WriteScores();
1691    WriteBattleConfig();
1692 
1693    GetPathFromEnvironment( filename, ApogeePath, ConfigName );
1694    file = open( filename,O_RDWR | O_TEXT | O_CREAT | O_TRUNC
1695    , S_IREAD | S_IWRITE);
1696 
1697    if (file == -1)
1698       Error ("Error opening %s: %s",filename,strerror(errno));
1699 
1700    // Write out ROTTCONFIG header
1701 
1702    SafeWriteString (file, ";Rise of the Triad Configuration File\n");
1703    SafeWriteString (file, ";                  (c) 1995\n\n");
1704 
1705    // Write out Version
1706 
1707    WriteParameter(file,"Version          ",ROTTVERSION);
1708 
1709    // Write out MouseEnabled
1710 
1711    SafeWriteString(file,"\n;\n");
1712    SafeWriteString(file,"; 1 - Mouse Enabled\n");
1713    SafeWriteString(file,"; 0 - Mouse Disabled\n");
1714    WriteParameter(file,"MouseEnabled     ",mouseenabled);
1715 
1716    // Write out JoystickEnabled
1717 
1718    SafeWriteString(file,"\n;\n");
1719    SafeWriteString(file,"; 1 - Joystick Enabled\n");
1720    SafeWriteString(file,"; 0 - Joystick Disabled\n");
1721    WriteParameter(file,"JoystickEnabled  ",joystickenabled);
1722 
1723    // Write out JoypadEnabled
1724 
1725    SafeWriteString(file,"\n;\n");
1726    SafeWriteString(file,"; 1 - Joypad Enabled\n");
1727    SafeWriteString(file,"; 0 - Joypad Disabled\n");
1728    WriteParameter(file,"JoypadEnabled    ",joypadenabled);
1729 
1730    // Write out JoystickPort
1731 
1732    SafeWriteString(file,"\n;\n");
1733    SafeWriteString(file,"; 0 - Use Joystick Port 1\n");
1734    SafeWriteString(file,"; 1 - Use Joystick Port 2\n");
1735    WriteParameter(file,"JoystickPort     ",joystickport);
1736 
1737    // Write out ViewSize
1738 
1739    SafeWriteString(file,"\n;\n");
1740    SafeWriteString(file,"; Size of View port.\n");
1741    SafeWriteString(file,"; (smallest) 0 - 10 (largest)\n");
1742    WriteParameter(file,"ViewSize         ",viewsize);
1743 
1744    // Write out MouseAdjustment
1745 
1746    SafeWriteString(file,"\n;\n");
1747    SafeWriteString(file,"; Sensitivity of Mouse\n");
1748    SafeWriteString(file,"; (lowest) 0 - 11 (highest)\n");
1749    WriteParameter(file,"MouseAdjustment  ",mouseadjustment);
1750 
1751    // Write out threshold
1752 
1753    SafeWriteString(file,"\n;\n");
1754    SafeWriteString(file,"; Threshold of Mouse and Joystick\n");
1755    SafeWriteString(file,"; (smallest) 1 - 15 (largest)\n");
1756    WriteParameter(file,"Threshold        ",threshold);
1757 
1758    // Write in Cyberman Enabled
1759 
1760 //   SafeWriteString(file,"\n;\n");
1761 //   SafeWriteString(file,"; 1 - Cyberman Enabled\n");
1762 //   SafeWriteString(file,"; 0 - Cyberman Disabled\n");
1763 //   WriteParameter(file,"CybermanEnabled  ",cybermanenabled);
1764 
1765    // Write in Spaceball Enabled
1766 
1767 //   SafeWriteString(file,"\n;\n");
1768 //   SafeWriteString(file,"; 1 - Spaceball Enabled\n");
1769 //   SafeWriteString(file,"; 0 - Spaceball Disabled\n");
1770 //   WriteParameter(file,"SpaceballEnabled ",spaceballenabled);
1771 
1772    // Write in Auto Detail
1773 
1774    SafeWriteString(file,"\n;\n");
1775    SafeWriteString(file,"; 1 - Auto Detail on\n");
1776    SafeWriteString(file,"; 0 - Auto Detail off\n");
1777    WriteParameter (file,"AutoDetail       ", AutoDetailOn);
1778 
1779    // Write in Light Dim
1780 
1781    SafeWriteString(file,"\n;\n");
1782    SafeWriteString(file,"; 1 - Light Diminishing on\n");
1783    SafeWriteString(file,"; 0 - Light Diminishing off\n");
1784    WriteParameter (file,"LightDim         ", fulllight);
1785 
1786    // Write in Bobbin' On
1787 
1788    SafeWriteString(file,"\n;\n");
1789    SafeWriteString(file,"; 1 - Bobbing on\n");
1790    SafeWriteString(file,"; 0 - Bobbing off\n");
1791    WriteParameter (file,"BobbingOn        ", BobbinOn);
1792 
1793    // Write in Double Click Speed
1794 
1795    SafeWriteString(file,"\n;\n");
1796    SafeWriteString(file,"; (slowest) 50 - 5 (fastest)\n");
1797    WriteParameter (file,"DoubleClickSpeed ", DoubleClickSpeed);
1798 
1799    // Write in Menu Flip Speed
1800 
1801    SafeWriteString(file,"\n;\n");
1802    SafeWriteString(file,"; Menu Flip Speed\n");
1803    SafeWriteString(file,"; (slowest) 100 - 5 (fastest)\n");
1804    WriteParameter (file,"MenuFlipSpeed    ", Menuflipspeed);
1805 
1806    // Write in Detail Level
1807 
1808    SafeWriteString(file,"\n;\n");
1809    SafeWriteString(file,"; 0 - Detail Level Low\n");
1810    SafeWriteString(file,"; 1 - Detail Level Medium\n");
1811    SafeWriteString(file,"; 2 - Detail Level High\n");
1812    WriteParameter (file,"DetailLevel      ", DetailLevel);
1813 
1814    // Write in Floor and Ceiling
1815 
1816    SafeWriteString(file,"\n;\n");
1817    SafeWriteString(file,"; 1 - Floor and Ceiling on\n");
1818    SafeWriteString(file,"; 0 - Floor and Ceiling off\n");
1819    WriteParameter (file,"FloorCeiling     ", fandc);
1820 
1821    // Write in DisableMessages
1822 
1823    SafeWriteString(file,"\n;\n");
1824    SafeWriteString(file,"; 1 - Messages on\n");
1825    SafeWriteString(file,"; 0 - Messages off\n");
1826    WriteParameter (file,"Messages         ", MessagesEnabled );
1827 
1828    // Write in AutoRun
1829 
1830    SafeWriteString(file,"\n;\n");
1831    SafeWriteString(file,"; 1 - AutoRun on\n");
1832    SafeWriteString(file,"; 0 - AutoRun off\n");
1833    WriteParameter (file,"AutoRun          ", gamestate.autorun );
1834 
1835    // Write in GammaIndex
1836 
1837    SafeWriteString(file,"\n;\n");
1838    SafeWriteString(file,"; 0 - Gamma Correction level 1\n");
1839    SafeWriteString(file,"; 1 - Gamma Correction level 2\n");
1840    SafeWriteString(file,"; 2 - Gamma Correction level 3\n");
1841    SafeWriteString(file,"; 3 - Gamma Correction level 4\n");
1842    SafeWriteString(file,"; 4 - Gamma Correction level 5\n");
1843    WriteParameter (file,"GammaIndex       ", gammaindex);
1844 
1845    // Write out screen saver time
1846    SafeWriteString(file,"\n;\n");
1847    SafeWriteString(file,"; Minutes before screen blanking\n");
1848    WriteParameter (file,"BlankTime        ", blanktime/(VBLCOUNTER*60));
1849 
1850 
1851    // Write out keys
1852 
1853    SafeWriteString(file,"\n;\n");
1854    SafeWriteString(file,"; Scan codes for keyboard buttons\n");
1855    WriteParameter (file,"Fire             ", buttonscan[0]);
1856    WriteParameter (file,"Strafe           ", buttonscan[1]);
1857    WriteParameter (file,"Run              ", buttonscan[2]);
1858    WriteParameter (file,"Use              ", buttonscan[3]);
1859    WriteParameter (file,"LookUp           ", buttonscan[4]);
1860    WriteParameter (file,"LookDn           ", buttonscan[5]);
1861    WriteParameter (file,"Swap             ", buttonscan[6]);
1862    WriteParameter (file,"Drop             ", buttonscan[7]);
1863    WriteParameter (file,"TargetUp         ", buttonscan[8]);
1864    WriteParameter (file,"TargetDn         ", buttonscan[9]);
1865    WriteParameter (file,"SelPistol        ", buttonscan[10]);
1866    WriteParameter (file,"SelDualPistol    ", buttonscan[11]);
1867    WriteParameter (file,"SelMP40          ", buttonscan[12]);
1868    WriteParameter (file,"SelMissile       ", buttonscan[13]);
1869    WriteParameter (file,"AutoRun          ", buttonscan[14]);
1870    WriteParameter (file,"LiveRemRid       ", buttonscan[15]);
1871    WriteParameter (file,"StrafeLeft       ", buttonscan[16]);
1872    WriteParameter (file,"StrafeRight      ", buttonscan[17]);
1873    WriteParameter (file,"VolteFace        ", buttonscan[18]);
1874    WriteParameter (file,"Aim              ", buttonscan[19]);
1875    WriteParameter (file,"Forward          ", buttonscan[20]);
1876    WriteParameter (file,"Right            ", buttonscan[21]);
1877    WriteParameter (file,"Backward         ", buttonscan[22]);
1878    WriteParameter (file,"Left             ", buttonscan[23]);
1879    WriteParameter (file,"Map              ", buttonscan[24]);
1880    WriteParameter (file,"SendMessage      ", buttonscan[25]);
1881    WriteParameter (file,"DirectMessage    ", buttonscan[26]);
1882 
1883    SafeWriteString(file,"\n;\n");
1884 #ifdef DC
1885    {
1886    SafeWriteString(file,"; Mouse buttons\n");
1887 
1888 	int i;
1889 	char buf[20];
1890 
1891 	for(i=0;i<MAX_MOUSEBTN;i++) {
1892 		sprintf(buf,"MouseButton%d     ",i);
1893 		WriteParameter(file,buf,buttonjoy[i]);
1894 	}
1895 	for(i=0;i<MAX_MOUSEBTN;i++) {
1896 		sprintf(buf,"DblClickB%d       ",i);
1897 		WriteParameter(file,buf,buttonjoy[MAX_MOUSEBTN+i]);
1898 	}
1899 
1900    SafeWriteString(file,"\n;\n");
1901    SafeWriteString(file,"; Joystick buttons\n");
1902 
1903 	for(i=0;i<MAX_JOYBTN;i++) {
1904 		sprintf(buf,"JoyButton%d       ",i);
1905 		WriteParameter(file,buf,buttonjoy[i]);
1906 	}
1907 	for(i=0;i<MAX_JOYBTN;i++) {
1908 		sprintf(buf,"DblClickJB%d      ",i);
1909 		WriteParameter(file,buf,buttonjoy[MAX_JOYBTN+i]);
1910 	}
1911    }
1912 #else
1913    SafeWriteString(file,"; Mouse buttons\n");
1914 
1915    WriteParameter (file,"MouseButton0     ", buttonmouse[0]);
1916    WriteParameter (file,"MouseButton1     ", buttonmouse[1]);
1917    WriteParameter (file,"MouseButton2     ", buttonmouse[2]);
1918    WriteParameter (file,"DblClickB0       ", buttonmouse[MAX_MOUSEBTN+0]);
1919    WriteParameter (file,"DblClickB1       ", buttonmouse[MAX_MOUSEBTN+1]);
1920    WriteParameter (file,"DblClickB2       ", buttonmouse[MAX_MOUSEBTN+2]);
1921 
1922    SafeWriteString(file,"\n;\n");
1923    SafeWriteString(file,"; Joystick buttons\n");
1924 
1925    WriteParameter (file,"JoyButton0       ", buttonjoy[0]);
1926    WriteParameter (file,"JoyButton1       ", buttonjoy[1]);
1927    WriteParameter (file,"JoyButton2       ", buttonjoy[2]);
1928    WriteParameter (file,"JoyButton3       ", buttonjoy[3]);
1929    WriteParameter (file,"DblClickJB0      ", buttonjoy[MAX_JOYBTN+0]);
1930    WriteParameter (file,"DblClickJB1      ", buttonjoy[MAX_JOYBTN+1]);
1931    WriteParameter (file,"DblClickJB2      ", buttonjoy[MAX_JOYBTN+2]);
1932    WriteParameter (file,"DblClickJB3      ", buttonjoy[MAX_JOYBTN+3]);
1933 #endif
1934 
1935    SafeWriteString(file,"\n;\n");
1936    SafeWriteString(file,"; Joystick calibration coordinates\n");
1937 
1938    WriteParameter (file,"JoyMaxX          ", joyxmax);
1939    WriteParameter (file,"JoyMaxY          ", joyymax);
1940    WriteParameter (file,"JoyMinX          ", joyxmin);
1941    WriteParameter (file,"JoyMinY          ", joyymin);
1942 
1943    // Write out DefaultDifficulty
1944    SafeWriteString(file,"\n;\n");
1945 	WriteParameter(file,"; Easy             - ", gd_baby );
1946 	WriteParameter(file,"; Medium           - ", gd_easy );
1947 	WriteParameter(file,"; Hard             - ", gd_medium );
1948 	WriteParameter(file,"; Crezzy           - ", gd_hard );
1949    WriteParameter(file,"DefaultDifficulty    ", DefaultDifficulty );
1950 
1951    // Write out DefaultPlayerCharacter
1952    SafeWriteString(file,"\n;\n");
1953 	WriteParameter(file,"; Taradino Cassatt   - ", 0 );
1954 	WriteParameter(file,"; Thi Barrett        - ", 1 );
1955 	WriteParameter(file,"; Doug Wendt         - ", 2 );
1956 	WriteParameter(file,"; Lorelei Ni         - ", 3 );
1957 	WriteParameter(file,"; Ian Paul Freeley   - ", 4 );
1958    WriteParameter(file,"DefaultPlayerCharacter ", DefaultPlayerCharacter );
1959 
1960    // Write out DefaultPlayerColor
1961    SafeWriteString(file,"\n;\n");
1962 	WriteParameter(file,"; Gray             - ", 0 );
1963 	WriteParameter(file,"; Brown            - ", 1 );
1964 	WriteParameter(file,"; Black            - ", 2 );
1965 	WriteParameter(file,"; Tan              - ", 3 );
1966 	WriteParameter(file,"; Red              - ", 4 );
1967 	WriteParameter(file,"; Olive            - ", 5 );
1968 	WriteParameter(file,"; Blue             - ", 6 );
1969 	WriteParameter(file,"; White            - ", 7 );
1970 	WriteParameter(file,"; Green            - ", 8 );
1971 	WriteParameter(file,"; Purple           - ", 9 );
1972 	WriteParameter(file,"; Orange           - ", 10 );
1973    WriteParameter(file,"DefaultPlayerColor   ", DefaultPlayerColor );
1974 
1975    // Writeout password Password string
1976    SafeWriteString(file,"\n;\nSecretPassword         ");
1977    memset(passwordtemp,0,sizeof(passwordtemp));
1978    ConvertPasswordStringToString ( &passwordtemp[0] );
1979    SafeWriteString(file,&passwordtemp[0]);
1980 
1981    close (file);
1982 #endif
1983    inconfig--;
1984 }
1985 
1986 #ifdef _ROTT_
1987 
1988 
1989 //****************************************************************************
1990 //
1991 // GetAlternatePath ()
1992 //
1993 //****************************************************************************
1994 
GetAlternatePath(char * tokenstr,AlternateInformation * info)1995 void GetAlternatePath (char * tokenstr, AlternateInformation *info)
1996 {
1997    strcpy (&info->path[0], ".\0");
1998    GetToken (true);
1999    if (!stricmp (token, tokenstr))
2000       {
2001       GetTokenEOL (false);
2002       memset (&info->path[0], 0, sizeof (info->path));
2003       strcpy (&info->path[0], &name[0]);
2004       }
2005 }
2006 
2007 
2008 //****************************************************************************
2009 //
2010 // GetAlternateFile ()
2011 //
2012 //****************************************************************************
2013 
GetAlternateFile(char * tokenstr,AlternateInformation * info)2014 void GetAlternateFile (char * tokenstr, AlternateInformation *info)
2015 {
2016    // Read in remote sound file
2017    //
2018    strcpy (&info->file[0], "foo.foo\0");
2019    GetToken (true);
2020    if (!stricmp (token, tokenstr))
2021       {
2022       if (TokenAvailable()==true)
2023          {
2024          GetToken (false);
2025          if (stricmp (token, "~"))
2026             {
2027             #if (SHAREWARE == 0)
2028             info->avail = true;
2029             memset (&info->file[0], 0, sizeof (info->file));
2030             strcpy (&info->file[0], &token[0]);
2031             #else
2032             printf("Alternate file %s ignored.\n",token);
2033             memset (&info->file[0], 0, sizeof (info->file));
2034             #endif
2035             }
2036          }
2037       }
2038 }
2039 
2040 
2041 //****************************************************************************
2042 //
2043 // ReadSETUPFiles ()
2044 //
2045 //****************************************************************************
2046 
ReadSETUPFiles(void)2047 void ReadSETUPFiles (void)
2048 {
2049    char filename[ 128 ];
2050    int i;
2051 
2052    RemoteSounds.avail   = false;
2053 //   PlayerGraphics.avail = false;
2054    GameLevels.avail     = false;
2055    BattleLevels.avail   = false;
2056 
2057    GetPathFromEnvironment( filename, ApogeePath, CONFIG );
2058    if (access (filename, F_OK) == 0)
2059    {
2060       LoadScriptFile (filename);
2061 
2062       GetTokenEOL (true);     //MODEMNAME
2063       GetTokenEOL (true);     //MODEMINITSTR
2064       GetTokenEOL (true);     //MODEMHANGUP
2065       GetTokenEOL (true);     //RATE
2066       GetTokenEOL (true);     //COMPORT
2067       GetTokenEOL (true);     //IRQ
2068       GetTokenEOL (true);     //UART
2069       GetTokenEOL (true);     //PULSE
2070       GetTokenEOL (true);     //AUTOMATICDIALOUT
2071 
2072       GetAlternatePath ("REMOTESOUNDPATH", &RemoteSounds);
2073 //      GetAlternatePath ("PLAYERGRAPHICSPATH", &PlayerGraphics);
2074       GetAlternatePath ("GAMELEVELPATH", &GameLevels);
2075       GetAlternatePath ("BATTLELEVELPATH", &BattleLevels);
2076 
2077       // Get CodeName
2078       GetToken (true);
2079       if (stricmp (token, "CODENAME"))
2080          Error ("Can't find %s token.\n", "CODENAME");
2081 
2082       GetTokenEOL (false);
2083       memset (&CodeName[0], 0, sizeof (CodeName));
2084       if (stricmp (name, "~"))
2085          {
2086 
2087          // Get First (MAXCODENAMELENGTH-1) characters
2088          for (i=0;i<MAXCODENAMELENGTH-1;i++)
2089             CodeName[i]=name[i];
2090          }
2091       GetTokenEOL (true);     //NUMPLAYERS
2092       GetTokenEOL (true);     //NETWORKSOCKET
2093       GetTokenEOL (true);     //DEFAULT
2094       for (i=0;i<14;i++)
2095          GetTokenEOL (true);  //NUMBERLIST
2096 
2097       memset (CommbatMacros, 0, sizeof(CommbatMacros) );
2098 
2099       for (i=0;i<MAXMACROS;i++)
2100          {
2101          GetToken (true);
2102 
2103          GetTokenEOL (true);
2104 
2105          if (name[0] != '~')
2106             {
2107             memcpy (&CommbatMacros[i].macro[0], &name[0], strlen (name));
2108             CommbatMacros[i].avail = 1;
2109             }
2110          }
2111 
2112       Z_Free (scriptbuffer);
2113    }
2114 
2115    GetPathFromEnvironment( filename, ApogeePath, ROTT );
2116    if (access (filename, F_OK) == 0)
2117    {
2118       LoadScriptFile (filename);
2119 
2120       GetTokenEOL (true);     //PHONENUMBER
2121 
2122       GetAlternateFile ("REMOTESOUNDFILE", &RemoteSounds);
2123 //      GetAlternateFile ("PLAYERGRAPHICSFILE", &PlayerGraphics);
2124       GetAlternateFile ("GAMELEVELFILE", &GameLevels);
2125       GetAlternateFile ("COMMBATLEVELFILE", &BattleLevels);
2126 
2127       Z_Free (scriptbuffer);
2128 
2129       unlink (filename);          // Delete ROTT.ROT
2130    }
2131 }
2132 
2133 #endif
2134 
2135