1 //-------------------------------------------------------------------------
2 /*
3 Copyright (C) 1997, 2005 - 3D Realms Entertainment
4
5 This file is part of Shadow Warrior version 1.2
6
7 Shadow Warrior is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
16 See the GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
22 Original Source: 1997 - Frank Maddin and Jim Norwood
23 Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
24 */
25 //-------------------------------------------------------------------------
26 #include "build.h"
27 #include "baselayer.h"
28 #include "osd.h"
29
30 #include "settings.h"
31 #include "mytypes.h"
32 #include "develop.h"
33 #include "scriplib.h"
34 #include "file_lib.h"
35 #include "gamedefs.h"
36 #include "keyboard.h"
37 #include "util_lib.h"
38 #include "function.h"
39 #include "control.h"
40 #include "fx_man.h"
41 #include "sounds.h"
42 #include "config.h"
43 #include "common.h"
44
45 // we load this in to get default button and key assignments
46 // as well as setting up function mappings
47
48 #include "_functio.h"
49 #include "_config.h"
50
51 extern void ReadGameSetup(int32 scripthandle);
52 extern void WriteGameSetup(int32 scripthandle);
53
54 //
55 // Comm variables
56 //
57
58 char CommPlayerName[MAXPLAYERNAMELENGTH];
59
60 //
61 // Sound variables
62 //
63 int32 FXDevice = 0;
64 int32 MusicDevice = 0;
65 int32 NumVoices = 32;
66 int32 NumChannels = 2;
67 int32 NumBits = 16;
68 int32 MixRate = 44100;
69 char MusicParams[BMAX_PATH] = {0};
70
71 int32 UseMouse = 1, UseJoystick = 1;
72
73 byte KeyboardKeys[NUMGAMEFUNCTIONS][2];
74 int32 MouseButtons[MAXMOUSEBUTTONS];
75 int32 MouseButtonsClicked[MAXMOUSEBUTTONS];
76 int32 MouseDigitalAxes[MAXMOUSEAXES][2];
77 int32 MouseAnalogAxes[MAXMOUSEAXES];
78 int32 MouseAnalogScale[MAXMOUSEAXES];
79 int32 JoystickButtons[MAXJOYBUTTONS];
80 int32 JoystickButtonsClicked[MAXJOYBUTTONS];
81 int32 JoystickDigitalAxes[MAXJOYAXES][2];
82 int32 JoystickAnalogAxes[MAXJOYAXES];
83 int32 JoystickAnalogScale[MAXJOYAXES];
84 int32 JoystickAnalogDead[MAXJOYAXES];
85 int32 JoystickAnalogSaturate[MAXJOYAXES];
86
87 //
88 // Screen variables
89 //
90
91 int32 ScreenMode = 1;
92 int32 ScreenWidth = 640;
93 int32 ScreenHeight = 480;
94 int32 ScreenBPP = 8;
95 int32 ForceSetup = 1;
96
97 extern char WangBangMacro[10][64];
98 char RTSName[MAXRTSNAMELENGTH] = {0};
99 //static char setupfilename[64]={SETUPFILENAME};
100 char setupfilename[64]={SETUPFILENAME};
101 static int32 scripthandle = -1;
102
103
104
105 /*
106 ===================
107 =
108 = CONFIG_FunctionNameToNum
109 =
110 ===================
111 */
112
CONFIG_FunctionNameToNum(const char * func)113 int32 CONFIG_FunctionNameToNum( const char * func )
114 {
115 int32 i;
116
117 if (!func) return -1;
118 for (i=0;i<NUMGAMEFUNCTIONS;i++)
119 {
120 if (!Bstrcasecmp(func,gamefunctions[i]))
121 {
122 return i;
123 }
124 }
125 return -1;
126 }
127
128 /*
129 ===================
130 =
131 = CONFIG_FunctionNumToName
132 =
133 ===================
134 */
135
CONFIG_FunctionNumToName(int32 func)136 const char * CONFIG_FunctionNumToName( int32 func )
137 {
138 if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
139 {
140 return NULL;
141 }
142 else
143 {
144 return gamefunctions[func];
145 }
146 }
147
148 /*
149 ===================
150 =
151 = CONFIG_AnalogNameToNum
152 =
153 ===================
154 */
CONFIG_AnalogNameToNum(const char * func)155 int32 CONFIG_AnalogNameToNum( const char * func )
156 {
157 if (!Bstrcasecmp(func,"analog_turning"))
158 {
159 return analog_turning;
160 }
161 if (!Bstrcasecmp(func,"analog_strafing"))
162 {
163 return analog_strafing;
164 }
165 if (!Bstrcasecmp(func,"analog_moving"))
166 {
167 return analog_moving;
168 }
169 if (!Bstrcasecmp(func,"analog_lookingupanddown"))
170 {
171 return analog_lookingupanddown;
172 }
173 return -1;
174 }
175
CONFIG_AnalogNumToName(int32 func)176 const char * CONFIG_AnalogNumToName( int32 func )
177 {
178 switch (func) {
179 case analog_turning:
180 return "analog_turning";
181 case analog_strafing:
182 return "analog_strafing";
183 case analog_moving:
184 return "analog_moving";
185 case analog_lookingupanddown:
186 return "analog_lookingupanddown";
187 default: break;
188 }
189
190 return NULL;
191 }
192
193 /*
194 ===================
195 =
196 = CONFIG_SetDefaults
197 =
198 ===================
199 */
200
CONFIG_SetDefaults(void)201 void CONFIG_SetDefaults( void )
202 {
203 // JBF 20031211
204 int32 i,f;
205 byte k1,k2;
206
207 ScreenMode = 1;
208 ScreenWidth = 640;
209 ScreenHeight = 480;
210 ScreenBPP = 8;
211 FXDevice = 0;
212 MusicDevice = 0;
213 NumVoices = 32;
214 NumChannels = 2;
215 NumBits = 16;
216 MixRate = 44100;
217 MusicParams[0] = 0;
218 memcpy(&gs, &gs_defaults, sizeof(gs));
219
220 Bstrcpy(RTSName, DEFAULTRTSFILE);
221 Bstrcpy(CommPlayerName, DEFAULTPLAYERNAME);
222
223 Bstrcpy(WangBangMacro[0], MACRO1);
224 Bstrcpy(WangBangMacro[1], MACRO2);
225 Bstrcpy(WangBangMacro[2], MACRO3);
226 Bstrcpy(WangBangMacro[3], MACRO4);
227 Bstrcpy(WangBangMacro[4], MACRO5);
228 Bstrcpy(WangBangMacro[5], MACRO6);
229 Bstrcpy(WangBangMacro[6], MACRO7);
230 Bstrcpy(WangBangMacro[7], MACRO8);
231 Bstrcpy(WangBangMacro[8], MACRO9);
232 Bstrcpy(WangBangMacro[9], MACRO10);
233
234 CONFIG_SetDefaultKeyDefinitions(CONFIG_DEFAULTS_CLASSIC);
235 CONFIG_SetMouseDefaults(CONFIG_DEFAULTS_CLASSIC);
236 CONFIG_SetJoystickDefaults(CONFIG_DEFAULTS_CLASSIC);
237
238 memset(MouseDigitalAxes, -1, sizeof(MouseDigitalAxes));
239 for (i=0; i<MAXMOUSEAXES; i++) {
240 MouseAnalogScale[i] = 65536;
241 CONTROL_SetAnalogAxisScale( i, MouseAnalogScale[i], controldevice_mouse );
242
243 MouseDigitalAxes[i][0] = CONFIG_FunctionNameToNum( mousedigitaldefaults[i*2] );
244 MouseDigitalAxes[i][1] = CONFIG_FunctionNameToNum( mousedigitaldefaults[i*2+1] );
245 CONTROL_MapDigitalAxis( i, MouseDigitalAxes[i][0], 0,controldevice_mouse );
246 CONTROL_MapDigitalAxis( i, MouseDigitalAxes[i][1], 1,controldevice_mouse );
247
248 MouseAnalogAxes[i] = CONFIG_AnalogNameToNum( mouseanalogdefaults[i] );
249 CONTROL_MapAnalogAxis( i, MouseAnalogAxes[i], controldevice_mouse);
250 }
251 CONTROL_SetMouseSensitivity(gs.MouseSpeed);
252
253 for (i=0; i < MAXJOYAXES; i++) {
254 JoystickAnalogScale[i] = 65536;
255 JoystickAnalogDead[i] = 1024;
256 JoystickAnalogSaturate[i] = 32767-1024;
257 CONTROL_SetAnalogAxisScale( i, JoystickAnalogScale[i], controldevice_joystick );
258 CONTROL_SetJoyAxisDead(i, JoystickAnalogDead[i]);
259 CONTROL_SetJoyAxisSaturate(i, JoystickAnalogSaturate[i]);
260 }
261 }
262
263
CONFIG_SetDefaultKeyDefinitions(int style)264 void CONFIG_SetDefaultKeyDefinitions(int style)
265 {
266 int numkeydefaults;
267 char **keydefaultset;
268 int i, f, k1, k2;
269
270 if (style) {
271 numkeydefaults = sizeof(keydefaults_modern) / sizeof(char *) / 3;
272 keydefaultset = keydefaults_modern;
273 } else {
274 numkeydefaults = sizeof(keydefaults) / sizeof(char *) / 3;
275 keydefaultset = keydefaults;
276 }
277
278 memset(KeyboardKeys, 0xff, sizeof(KeyboardKeys));
279 for (i=0; i < numkeydefaults; i++) {
280 f = CONFIG_FunctionNameToNum( keydefaultset[3*i+0] );
281 if (f == -1) continue;
282 k1 = KB_StringToScanCode( keydefaultset[3*i+1] );
283 k2 = KB_StringToScanCode( keydefaultset[3*i+2] );
284
285 CONTROL_MapKey( i, k1, k2 );
286
287 KeyboardKeys[f][0] = k1;
288 KeyboardKeys[f][1] = k2;
289 }
290 }
291
CONFIG_SetMouseDefaults(int style)292 void CONFIG_SetMouseDefaults(int style)
293 {
294 char **mousedefaultset, **mouseclickeddefaultset;
295 int i;
296
297 if (style) {
298 mousedefaultset = mousedefaults_modern;
299 mouseclickeddefaultset = mouseclickeddefaults_modern;
300 gs.MouseInvert = 1;
301 } else {
302 mousedefaultset = mousedefaults;
303 mouseclickeddefaultset = mouseclickeddefaults;
304 gs.MouseInvert = 0;
305 }
306
307 memset(MouseButtons, -1, sizeof(MouseButtons));
308 memset(MouseButtonsClicked, -1, sizeof(MouseButtonsClicked));
309 for (i=0; i < MAXMOUSEBUTTONS; i++) {
310 MouseButtons[i] = CONFIG_FunctionNameToNum( mousedefaultset[i] );
311 CONTROL_MapButton( MouseButtons[i], i, FALSE, controldevice_mouse );
312
313 if (i<4) continue;
314
315 MouseButtonsClicked[i] = CONFIG_FunctionNameToNum( mouseclickeddefaultset[i] );
316 CONTROL_MapButton( MouseButtonsClicked[i], i, TRUE, controldevice_mouse );
317 }
318 }
319
CONFIG_SetJoystickDefaults(int style)320 void CONFIG_SetJoystickDefaults(int style)
321 {
322 char **joydefaultset, **joyclickeddefaultset;
323 char **joydigitaldefaultset, **joyanalogdefaultset;
324 int i;
325
326 if (style) {
327 joydefaultset = joystickdefaults_modern;
328 joyclickeddefaultset = joystickclickeddefaults_modern;
329 joydigitaldefaultset = joystickdigitaldefaults_modern;
330 joyanalogdefaultset = joystickanalogdefaults_modern;
331 } else {
332 joydefaultset = joystickdefaults;
333 joyclickeddefaultset = joystickclickeddefaults;
334 joydigitaldefaultset = joystickdigitaldefaults;
335 joyanalogdefaultset = joystickanalogdefaults;
336 }
337
338 memset(JoystickButtons, -1, sizeof(JoystickButtons));
339 memset(JoystickButtonsClicked, -1, sizeof(JoystickButtonsClicked));
340 for (i=0; i < MAXJOYBUTTONS; i++) {
341 JoystickButtons[i] = CONFIG_FunctionNameToNum( joydefaultset[i] );
342 JoystickButtonsClicked[i] = CONFIG_FunctionNameToNum( joyclickeddefaultset[i] );
343 CONTROL_MapButton( JoystickButtons[i], i, FALSE, controldevice_joystick );
344 CONTROL_MapButton( JoystickButtonsClicked[i], i, TRUE, controldevice_joystick );
345 }
346
347 memset(JoystickDigitalAxes, -1, sizeof(JoystickDigitalAxes));
348 for (i=0; i < MAXJOYAXES; i++) {
349 JoystickDigitalAxes[i][0] = CONFIG_FunctionNameToNum( joydigitaldefaultset[i*2] );
350 JoystickDigitalAxes[i][1] = CONFIG_FunctionNameToNum( joydigitaldefaultset[i*2+1] );
351 CONTROL_MapDigitalAxis( i, JoystickDigitalAxes[i][0], 0, controldevice_joystick );
352 CONTROL_MapDigitalAxis( i, JoystickDigitalAxes[i][1], 1, controldevice_joystick );
353
354 JoystickAnalogAxes[i] = CONFIG_AnalogNameToNum( joyanalogdefaultset[i] );
355 CONTROL_MapAnalogAxis(i, JoystickAnalogAxes[i], controldevice_joystick);
356 }
357 }
358
359 /*
360 ===================
361 =
362 = CONFIG_ReadKeys
363 =
364 ===================
365 */
366
CONFIG_ReadKeys(int32 scripthandle)367 void CONFIG_ReadKeys( int32 scripthandle )
368 {
369 int32 i;
370 int32 numkeyentries;
371 int32 function;
372 char keyname1[80];
373 char keyname2[80];
374 kb_scancode key1,key2;
375
376 if (scripthandle < 0) return;
377
378 numkeyentries = SCRIPT_NumberEntries( scripthandle,"KeyDefinitions" );
379
380 for (i=0;i<numkeyentries;i++)
381 {
382 function = CONFIG_FunctionNameToNum(SCRIPT_Entry(scripthandle,"KeyDefinitions", i ));
383 if (function != -1)
384 {
385 SCRIPT_GetDoubleString
386 (
387 scripthandle,
388 "KeyDefinitions",
389 SCRIPT_Entry( scripthandle, "KeyDefinitions", i ),
390 keyname1,
391 keyname2,
392 sizeof(keyname1),
393 sizeof(keyname2)
394 );
395 key1 = 0xff;
396 key2 = 0xff;
397 if (keyname1[0])
398 {
399 key1 = (byte) KB_StringToScanCode( keyname1 );
400 }
401 if (keyname2[0])
402 {
403 key2 = (byte) KB_StringToScanCode( keyname2 );
404 }
405 KeyboardKeys[function][0] = key1;
406 KeyboardKeys[function][1] = key2;
407 }
408 }
409
410 for (i=0; i<NUMGAMEFUNCTIONS; i++)
411 {
412 if (i == gamefunc_Show_Console)
413 OSD_CaptureKey(KeyboardKeys[i][0]);
414 else
415 CONTROL_MapKey( i, KeyboardKeys[i][0], KeyboardKeys[i][1] );
416 }
417 }
418
419 /*
420 ===================
421 =
422 = CONFIG_SetupMouse
423 =
424 ===================
425 */
426
CONFIG_SetupMouse(void)427 void CONFIG_SetupMouse( void )
428 {
429 int32 i;
430 char str[80],*p;
431 char temp[80];
432 int32 function, scale;
433
434 if (scripthandle < 0) return;
435
436 for (i=0;i<MAXMOUSEBUTTONS;i++)
437 {
438 Bsprintf(str,"MouseButton%d",i);
439 if (!SCRIPT_GetString( scripthandle,"Controls", str,temp, sizeof(temp)))
440 MouseButtons[i] = CONFIG_FunctionNameToNum(temp);
441
442 Bsprintf(str,"MouseButtonClicked%d",i);
443 if (!SCRIPT_GetString( scripthandle,"Controls", str,temp, sizeof(temp)))
444 MouseButtonsClicked[i] = CONFIG_FunctionNameToNum(temp);
445 }
446
447 // map over the axes
448 for (i=0;i<MAXMOUSEAXES;i++)
449 {
450 Bsprintf(str,"MouseAnalogAxes%d",i);
451 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
452 MouseAnalogAxes[i] = CONFIG_AnalogNameToNum(temp);
453
454 Bsprintf(str,"MouseDigitalAxes%d_0",i);
455 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
456 MouseDigitalAxes[i][0] = CONFIG_FunctionNameToNum(temp);
457
458 Bsprintf(str,"MouseDigitalAxes%d_1",i);
459 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
460 MouseDigitalAxes[i][1] = CONFIG_FunctionNameToNum(temp);
461
462 Bsprintf(str,"MouseAnalogScale%d",i);
463 scale = MouseAnalogScale[i];
464 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
465 MouseAnalogScale[i] = scale;
466 }
467
468 // 0 to 65536
469 SCRIPT_GetNumber( scripthandle, "Controls","MouseSensitivity",&function);
470 gs.MouseSpeed = function;
471
472 for (i=0; i<MAXMOUSEBUTTONS; i++)
473 {
474 CONTROL_MapButton( MouseButtons[i], i, FALSE, controldevice_mouse );
475 CONTROL_MapButton( MouseButtonsClicked[i], i, TRUE, controldevice_mouse );
476 }
477 for (i=0; i<MAXMOUSEAXES; i++)
478 {
479 CONTROL_MapAnalogAxis( i, MouseAnalogAxes[i], controldevice_mouse);
480 CONTROL_MapDigitalAxis( i, MouseDigitalAxes[i][0], 0,controldevice_mouse );
481 CONTROL_MapDigitalAxis( i, MouseDigitalAxes[i][1], 1,controldevice_mouse );
482 CONTROL_SetAnalogAxisScale( i, MouseAnalogScale[i], controldevice_mouse );
483 }
484
485 CONTROL_SetMouseSensitivity(gs.MouseSpeed);
486 }
487
488 /*
489 ===================
490 =
491 = CONFIG_SetupJoystick
492 =
493 ===================
494 */
495
CONFIG_SetupJoystick(void)496 void CONFIG_SetupJoystick( void )
497 {
498 int32 i;
499 char str[80],*p;
500 char temp[80];
501 int32 function, scale;
502
503 if (scripthandle < 0) return;
504
505 for (i=0;i<MAXJOYBUTTONS;i++)
506 {
507 Bsprintf(str,"JoystickButton%d",i);
508 if (!SCRIPT_GetString( scripthandle,"Controls", str,temp, sizeof(temp)))
509 JoystickButtons[i] = CONFIG_FunctionNameToNum(temp);
510
511 Bsprintf(str,"JoystickButtonClicked%d",i);
512 if (!SCRIPT_GetString( scripthandle,"Controls", str,temp, sizeof(temp)))
513 JoystickButtonsClicked[i] = CONFIG_FunctionNameToNum(temp);
514 }
515
516 // map over the axes
517 for (i=0;i<MAXJOYAXES;i++)
518 {
519 Bsprintf(str,"JoystickAnalogAxes%d",i);
520 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
521 JoystickAnalogAxes[i] = CONFIG_AnalogNameToNum(temp);
522
523 Bsprintf(str,"JoystickDigitalAxes%d_0",i);
524 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
525 JoystickDigitalAxes[i][0] = CONFIG_FunctionNameToNum(temp);
526
527 Bsprintf(str,"JoystickDigitalAxes%d_1",i);
528 if (!SCRIPT_GetString(scripthandle, "Controls", str,temp, sizeof(temp)))
529 JoystickDigitalAxes[i][1] = CONFIG_FunctionNameToNum(temp);
530
531 Bsprintf(str,"JoystickAnalogScale%d",i);
532 scale = JoystickAnalogScale[i];
533 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
534 JoystickAnalogScale[i] = scale;
535
536 Bsprintf(str,"JoystickAnalogDead%d",i);
537 scale = JoystickAnalogDead[i];
538 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
539 JoystickAnalogDead[i] = scale;
540
541 Bsprintf(str,"JoystickAnalogSaturate%d",i);
542 scale = JoystickAnalogSaturate[i];
543 SCRIPT_GetNumber(scripthandle, "Controls", str,&scale);
544 JoystickAnalogSaturate[i] = scale;
545 }
546
547 for (i=0;i<MAXJOYBUTTONS;i++)
548 {
549 CONTROL_MapButton( JoystickButtons[i], i, FALSE, controldevice_joystick );
550 CONTROL_MapButton( JoystickButtonsClicked[i], i, TRUE, controldevice_joystick );
551 }
552 for (i=0;i<MAXJOYAXES;i++)
553 {
554 CONTROL_MapAnalogAxis(i, JoystickAnalogAxes[i], controldevice_joystick);
555 CONTROL_MapDigitalAxis( i, JoystickDigitalAxes[i][0], 0, controldevice_joystick );
556 CONTROL_MapDigitalAxis( i, JoystickDigitalAxes[i][1], 1, controldevice_joystick );
557 CONTROL_SetAnalogAxisScale( i, JoystickAnalogScale[i], controldevice_joystick );
558 CONTROL_SetJoyAxisDead(i, JoystickAnalogDead[i]);
559 CONTROL_SetJoyAxisSaturate(i, JoystickAnalogSaturate[i]);
560 }
561 }
562
563 /*
564 ===================
565 =
566 = CONFIG_ReadSetup
567 =
568 ===================
569 */
570
CONFIG_ReadSetup(void)571 int32 CONFIG_ReadSetup( void )
572 {
573 int32 dummy;
574 char ret;
575 extern char ds[];
576
577 char oggtrackname[MAXOGGTRACKLENGTH] = {0};
578
579 CONTROL_ClearAssignments();
580 CONFIG_SetDefaults();
581
582 if (SafeFileExists(setupfilename))
583 scripthandle = SCRIPT_Load(setupfilename);
584
585 if (scripthandle < 0) return -1;
586
587 SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenMode",&ScreenMode);
588 SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenWidth",&ScreenWidth);
589 SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenHeight",&ScreenHeight);
590 SCRIPT_GetNumber( scripthandle, "Screen Setup", "ScreenBPP", &ScreenBPP);
591 if (ScreenBPP < 8) ScreenBPP = 8;
592
593 #ifdef RENDERTYPEWIN
594 SCRIPT_GetNumber( scripthandle, "Screen Setup", "MaxRefreshFreq", (int32*)&maxrefreshfreq);
595 #endif
596
597 #if USE_POLYMOST && USE_OPENGL
598 SCRIPT_GetNumber( scripthandle, "Screen Setup", "GLTextureMode", &gltexfiltermode);
599 SCRIPT_GetNumber( scripthandle, "Screen Setup", "GLAnisotropy", &glanisotropy);
600 SCRIPT_GetNumber( scripthandle, "Screen Setup", "GLUseTextureCompr", &glusetexcompr);
601 #endif
602
603 SCRIPT_GetNumber( scripthandle, "Sound Setup", "FXDevice",&FXDevice);
604 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MusicDevice",&MusicDevice);
605 SCRIPT_GetNumber( scripthandle, "Sound Setup", "FXVolume",&dummy);
606 gs.SoundVolume = dummy;
607 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MusicVolume",&dummy);
608 gs.MusicVolume = dummy;
609
610 SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumVoices",&NumVoices);
611 SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumChannels",&NumChannels);
612 SCRIPT_GetNumber( scripthandle, "Sound Setup", "NumBits",&NumBits);
613 SCRIPT_GetNumber( scripthandle, "Sound Setup", "MixRate",&MixRate);
614 SCRIPT_GetNumber( scripthandle, "Sound Setup", "ReverseStereo",&dummy);
615 gs.FlipStereo = dummy;
616 if (gs.FlipStereo) gs.FlipStereo = 1;
617 SCRIPT_GetString( scripthandle, "Sound Setup", "MusicParams", MusicParams, sizeof(MusicParams));
618
619 SCRIPT_GetString( scripthandle, "Sound Setup", "OggTrackName", oggtrackname, sizeof(oggtrackname));
620 if(oggtrackname[0] != '\0')
621 memcpy(gs.OggTrackName, oggtrackname, MAXOGGTRACKLENGTH);
622
623 SCRIPT_GetNumber( scripthandle, "Setup", "ForceSetup",&ForceSetup);
624 SCRIPT_GetNumber( scripthandle, "Controls","UseMouse",&UseMouse);
625 SCRIPT_GetNumber( scripthandle, "Controls","UseJoystick",&UseJoystick);
626 SCRIPT_GetString( scripthandle, "Comm Setup", "RTSName",RTSName, sizeof(RTSName));
627
628 SCRIPT_GetString( scripthandle, "Comm Setup","PlayerName",CommPlayerName, sizeof(CommPlayerName));
629
630 ReadGameSetup(scripthandle);
631
632 CONFIG_ReadKeys(scripthandle);
633
634 //CONFIG_SetupMouse(scripthandle);
635 //CONFIG_SetupJoystick(scripthandle);
636
637 return 0;
638 }
639
640 /*
641 ===================
642 =
643 = CONFIG_WriteSetup
644 =
645 ===================
646 */
647
CONFIG_WriteSetup(void)648 void CONFIG_WriteSetup( void )
649 {
650 int32 dummy;
651 char buf[80];
652
653 if (scripthandle < 0)
654 scripthandle = SCRIPT_Init(setupfilename);
655
656 SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenWidth", ScreenWidth,FALSE,FALSE);
657 SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenHeight",ScreenHeight,FALSE,FALSE);
658 SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenMode",ScreenMode,FALSE,FALSE);
659 SCRIPT_PutNumber( scripthandle, "Screen Setup", "ScreenBPP",ScreenBPP,FALSE,FALSE);
660
661 #ifdef RENDERTYPEWIN
662 SCRIPT_PutNumber( scripthandle, "Screen Setup", "MaxRefreshFreq",maxrefreshfreq,FALSE,FALSE);
663 #endif
664
665 #if USE_POLYMOST && USE_OPENGL
666 SCRIPT_PutNumber( scripthandle, "Screen Setup", "GLTextureMode",gltexfiltermode,FALSE,FALSE);
667 SCRIPT_PutNumber( scripthandle, "Screen Setup", "GLAnisotropy",glanisotropy,FALSE,FALSE);
668 SCRIPT_PutNumber( scripthandle, "Screen Setup", "GLUseTextureCompr",glusetexcompr,FALSE,FALSE);
669 #endif
670
671 SCRIPT_PutNumber( scripthandle, "Sound Setup", "FXDevice", FXDevice, FALSE, FALSE);
672 SCRIPT_PutNumber( scripthandle, "Sound Setup", "MusicDevice", MusicDevice, FALSE, FALSE);
673 SCRIPT_PutNumber( scripthandle, "Sound Setup", "NumVoices", NumVoices, FALSE, FALSE);
674 SCRIPT_PutNumber( scripthandle, "Sound Setup", "NumChannels", NumChannels, FALSE, FALSE);
675 SCRIPT_PutNumber( scripthandle, "Sound Setup", "NumBits", NumBits, FALSE, FALSE);
676 SCRIPT_PutNumber( scripthandle, "Sound Setup", "MixRate", MixRate, FALSE, FALSE);
677 SCRIPT_PutNumber( scripthandle, "Sound Setup", "FXVolume",gs.SoundVolume,FALSE,FALSE);
678 SCRIPT_PutNumber( scripthandle, "Sound Setup", "MusicVolume",gs.MusicVolume,FALSE,FALSE);
679 dummy = gs.FlipStereo;
680 SCRIPT_PutNumber( scripthandle, "Sound Setup", "ReverseStereo",dummy,FALSE,FALSE);
681 SCRIPT_PutString( scripthandle, "Sound Setup", "OggTrackName", gs.OggTrackName);
682
683 SCRIPT_PutNumber( scripthandle, "Setup", "ForceSetup",ForceSetup,FALSE,FALSE);
684 SCRIPT_PutNumber( scripthandle, "Controls","UseMouse",UseMouse,FALSE,FALSE);
685 SCRIPT_PutNumber( scripthandle, "Controls","UseJoystick",UseJoystick,FALSE,FALSE);
686 SCRIPT_PutNumber( scripthandle, "Controls","MouseSensitivity",gs.MouseSpeed,FALSE,FALSE);
687
688 SCRIPT_PutString( scripthandle, "Comm Setup", "PlayerName", CommPlayerName);
689
690 WriteGameSetup(scripthandle);
691
692 for (dummy=0;dummy<NUMGAMEFUNCTIONS;dummy++) {
693 SCRIPT_PutDoubleString( scripthandle, "KeyDefinitions", CONFIG_FunctionNumToName(dummy),
694 KB_ScanCodeToString(KeyboardKeys[dummy][0]), KB_ScanCodeToString(KeyboardKeys[dummy][1]));
695 }
696
697 for (dummy=0;dummy<MAXMOUSEBUTTONS;dummy++) {
698 Bsprintf(buf,"MouseButton%d",dummy);
699 SCRIPT_PutString( scripthandle,"Controls", buf, CONFIG_FunctionNumToName( MouseButtons[dummy] ));
700
701 if (dummy >= (MAXMOUSEBUTTONS-2)) continue; // scroll wheel
702
703 Bsprintf(buf,"MouseButtonClicked%d",dummy);
704 SCRIPT_PutString( scripthandle,"Controls", buf, CONFIG_FunctionNumToName( MouseButtonsClicked[dummy] ));
705 }
706
707 for (dummy=0;dummy<MAXMOUSEAXES;dummy++) {
708 Bsprintf(buf,"MouseAnalogAxes%d",dummy);
709 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_AnalogNumToName( MouseAnalogAxes[dummy] ));
710
711 Bsprintf(buf,"MouseDigitalAxes%d_0",dummy);
712 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(MouseDigitalAxes[dummy][0]));
713
714 Bsprintf(buf,"MouseDigitalAxes%d_1",dummy);
715 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(MouseDigitalAxes[dummy][1]));
716
717 Bsprintf(buf,"MouseAnalogScale%d",dummy);
718 SCRIPT_PutNumber(scripthandle, "Controls", buf, MouseAnalogScale[dummy], FALSE, FALSE);
719 }
720
721 for (dummy=0;dummy<MAXJOYBUTTONS;dummy++) {
722 Bsprintf(buf,"JoystickButton%d",dummy);
723 SCRIPT_PutString( scripthandle,"Controls", buf, CONFIG_FunctionNumToName( JoystickButtons[dummy] ));
724
725 Bsprintf(buf,"JoystickButtonClicked%d",dummy);
726 SCRIPT_PutString( scripthandle,"Controls", buf, CONFIG_FunctionNumToName( JoystickButtonsClicked[dummy] ));
727 }
728
729 for (dummy=0;dummy<MAXJOYAXES;dummy++) {
730 Bsprintf(buf,"JoystickAnalogAxes%d",dummy);
731 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_AnalogNumToName( JoystickAnalogAxes[dummy] ));
732
733 Bsprintf(buf,"JoystickDigitalAxes%d_0",dummy);
734 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(JoystickDigitalAxes[dummy][0]));
735
736 Bsprintf(buf,"JoystickDigitalAxes%d_1",dummy);
737 SCRIPT_PutString(scripthandle, "Controls", buf, CONFIG_FunctionNumToName(JoystickDigitalAxes[dummy][1]));
738
739 Bsprintf(buf,"JoystickAnalogScale%d",dummy);
740 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogScale[dummy], FALSE, FALSE);
741
742 Bsprintf(buf,"JoystickAnalogDead%d",dummy);
743 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogDead[dummy], FALSE, FALSE);
744
745 Bsprintf(buf,"JoystickAnalogSaturate%d",dummy);
746 SCRIPT_PutNumber(scripthandle, "Controls", buf, JoystickAnalogSaturate[dummy], FALSE, FALSE);
747 }
748
749 SCRIPT_Save (scripthandle, setupfilename);
750 SCRIPT_Free (scripthandle);
751 }
752
753