Subversion Repositories eduke32

Rev

Rev 883 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
484 terminx 3
Copyright (C) 1996, 2003 - 3D Realms Entertainment
4
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
5
Copyright (C) 2004, 2007 - EDuke32 developers
5 Plagman 6
 
7
This file is part of EDuke32
8
 
9
EDuke32 is free software; you can redistribute it and/or
10
modify it under the terms of the GNU General Public License version 2
11
as published by the Free Software Foundation.
12
 
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
 
17
See the GNU General Public License for more details.
18
 
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
*/
23
//-------------------------------------------------------------------------
24
 
25
/*
26
#include <stdio.h>
27
#include <string.h>
28
#include <stdlib.h>
29
#include <ctype.h>
30
#include <time.h>
31
*/
32
 
33
#include "duke3d.h"
34
#include "scriplib.h"
35
#include "osd.h"
820 terminx 36
#include "osdcmds.h"
5 Plagman 37
 
38
#include "baselayer.h"
39
 
40
// we load this in to get default button and key assignments
41
// as well as setting up function mappings
42
 
43
#define __SETUP__   // JBF 20031211
44
#include "_functio.h"
45
 
46
/*
47
===================
48
=
49
= CONFIG_FunctionNameToNum
50
=
51
===================
52
*/
53
 
333 terminx 54
int32 CONFIG_FunctionNameToNum(char * func)
5 Plagman 55
{
56
    int32 i;
57
 
58
    for (i=0;i<NUMGAMEFUNCTIONS;i++)
59
    {
60
        if (!Bstrcasecmp(func,gamefunctions[i]))
61
        {
62
            return i;
63
        }
64
    }
248 terminx 65
    for (i=0;i<NUMGAMEFUNCTIONS;i++)
66
    {
67
        if (!Bstrcasecmp(func,defaultgamefunctions[i]))
68
        {
69
            return i;
70
        }
71
    }
5 Plagman 72
    return -1;
73
}
74
 
75
/*
76
===================
77
=
78
= CONFIG_FunctionNumToName
79
=
80
===================
81
*/
82
 
333 terminx 83
char * CONFIG_FunctionNumToName(int32 func)
5 Plagman 84
{
85
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
86
        return NULL;
437 terminx 87
    return gamefunctions[func];
5 Plagman 88
}
89
 
90
/*
91
===================
92
=
93
= CONFIG_AnalogNameToNum
94
=
95
===================
96
*/
97
 
98
 
333 terminx 99
int32 CONFIG_AnalogNameToNum(char * func)
5 Plagman 100
{
101
 
102
    if (!Bstrcasecmp(func,"analog_turning"))
103
    {
104
        return analog_turning;
105
    }
106
    if (!Bstrcasecmp(func,"analog_strafing"))
107
    {
108
        return analog_strafing;
109
    }
110
    if (!Bstrcasecmp(func,"analog_moving"))
111
    {
112
        return analog_moving;
113
    }
114
    if (!Bstrcasecmp(func,"analog_lookingupanddown"))
115
    {
116
        return analog_lookingupanddown;
117
    }
118
 
119
    return -1;
120
}
121
 
122
 
333 terminx 123
char * CONFIG_AnalogNumToName(int32 func)
5 Plagman 124
{
335 terminx 125
    switch (func)
126
    {
337 terminx 127
    case analog_turning:
128
        return "analog_turning";
129
    case analog_strafing:
130
        return "analog_strafing";
131
    case analog_moving:
132
        return "analog_moving";
133
    case analog_lookingupanddown:
134
        return "analog_lookingupanddown";
5 Plagman 135
    }
136
 
137
    return NULL;
138
}
139
 
140
 
141
/*
142
===================
143
=
144
= CONFIG_SetDefaults
145
=
146
===================
147
*/
148
 
496 terminx 149
void CONFIG_SetDefaultKeys(int type)
495 terminx 150
{
151
    int32 i,f;
152
 
822 terminx 153
    Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
154
    Bmemset(&boundkeys,0,sizeof(boundkeys));
836 terminx 155
    Bmemset(&mousebind,0,sizeof(mousebind));
496 terminx 156
 
157
    if (type == 1)
158
    {
159
        for (i=0; i < (int32)(sizeof(oldkeydefaults)/sizeof(oldkeydefaults[0])); i+=3)
160
        {
500 terminx 161
            f = CONFIG_FunctionNameToNum((char *)oldkeydefaults[i+0]);
496 terminx 162
            if (f == -1) continue;
563 terminx 163
            ud.config.KeyboardKeys[f][0] = KB_StringToScanCode((char *)oldkeydefaults[i+1]);
164
            ud.config.KeyboardKeys[f][1] = KB_StringToScanCode((char *)oldkeydefaults[i+2]);
496 terminx 165
 
563 terminx 166
            if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
848 terminx 167
            else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
496 terminx 168
        }
169
        return;
170
    }
522 terminx 171
 
495 terminx 172
    for (i=0; i < (int32)(sizeof(keydefaults)/sizeof(keydefaults[0])); i+=3)
173
    {
174
        f = CONFIG_FunctionNameToNum(keydefaults[i+0]);
175
        if (f == -1) continue;
563 terminx 176
        ud.config.KeyboardKeys[f][0] = KB_StringToScanCode(keydefaults[i+1]);
177
        ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keydefaults[i+2]);
495 terminx 178
 
563 terminx 179
        if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
848 terminx 180
        else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
495 terminx 181
    }
182
}
183
 
333 terminx 184
void CONFIG_SetDefaults(void)
5 Plagman 185
{
186
    // JBF 20031211
649 terminx 187
    int32 i;
5 Plagman 188
 
563 terminx 189
    ud.config.scripthandle = -1;
622 terminx 190
    ud.config.ScreenWidth = 1024;
191
    ud.config.ScreenHeight = 768;
192
    ud.config.ScreenMode = 0;
193
#if defined(POLYMOST) && defined(USE_OPENGL)
194
    ud.config.ScreenBPP = 32;
195
#else
196
    ud.config.ScreenBPP = 8;
197
#endif
563 terminx 198
    ud.config.useprecache = 1;
199
    ud.config.ForceSetup = 1;
200
    ud.config.AmbienceToggle = 1;
201
    ud.config.AutoAim = 1;
202
    ud.config.FXDevice = 0;
203
    ud.config.FXVolume = 220;
821 terminx 204
#if defined(_WIN32)
563 terminx 205
    ud.config.MixRate = 44100;
821 terminx 206
#else
207
    ud.config.MixRate = 48000;
208
#endif
563 terminx 209
    ud.config.MouseBias = 0;
210
    ud.config.MouseFilter = 0;
211
    ud.config.MusicDevice = 0;
212
    ud.config.MusicToggle = 1;
213
    ud.config.MusicVolume = 200;
564 terminx 214
    myaimmode = g_player[0].ps->aim_mode = 1;
563 terminx 215
    ud.config.NumBits = 16;
216
    ud.config.NumChannels = 2;
217
    ud.config.NumVoices = 32;
218
    ud.config.ReverseStereo = 0;
219
    ud.config.RunMode = ud.auto_run = 1;
220
    ud.config.ShowOpponentWeapons = 0;
221
    ud.config.SmoothInput = 1;
222
    ud.config.SoundToggle = 1;
158 terminx 223
    ud.automsg = 0;
224
    ud.autovote = 0;
222 terminx 225
    ud.brightness = 8;
570 terminx 226
    ud.camerasprite = -1;
158 terminx 227
    ud.color = 0;
881 terminx 228
    ud.crosshair = 1;
229
    ud.crosshairscale = 50;
529 terminx 230
    ud.deathmsgs = 1;
158 terminx 231
    ud.democams = 1;
232
    ud.detail = 1;
233
    ud.drawweapon = 1;
234
    ud.idplayers = 1;
235
    ud.levelstats = 0;
236
    ud.lockout = 0;
237
    ud.m_ffire = 1;
238
    ud.m_marker = 1;
5 Plagman 239
    ud.mouseaiming = 0;
110 terminx 240
    ud.mouseflip = 1;
158 terminx 241
    ud.msgdisptime = 120;
242
    ud.pwlockout[0] = '\0';
5 Plagman 243
    ud.runkey_mode = 0;
110 terminx 244
    ud.screen_size = 4;
5 Plagman 245
    ud.screen_tilting = 1;
246
    ud.shadows = 1;
128 terminx 247
    ud.statusbarmode = 0;
158 terminx 248
    ud.statusbarscale = 100;
268 terminx 249
    ud.team = 0;
506 terminx 250
    ud.viewbob = 1;
251
    ud.weaponsway = 1;
158 terminx 252
    ud.weaponswitch = 3;        // new+empty
529 terminx 253
    ud.angleinterpolation = 0;
563 terminx 254
    ud.config.UseJoystick = 0;
255
    ud.config.UseMouse = 1;
256
    ud.config.VoiceToggle = 2;
131 terminx 257
 
5 Plagman 258
    Bstrcpy(ud.rtsname, "DUKE.RTS");
259
    Bstrcpy(myname, "Duke");
260
 
261
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
262
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
263
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
264
    Bstrcpy(ud.ridecule[3], "Lucky Son of a Bitch.");
265
    Bstrcpy(ud.ridecule[4], "Hmmm....Payback time.");
266
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
267
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
268
    Bstrcpy(ud.ridecule[7], "Ha ha ha...Wasted!");
269
    Bstrcpy(ud.ridecule[8], "You suck!");
270
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
271
 
272
    // JBF 20031211
273
 
522 terminx 274
    CONFIG_SetDefaultKeys(0);
506 terminx 275
 
563 terminx 276
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
335 terminx 277
    for (i=0; i<MAXMOUSEBUTTONS; i++)
278
    {
563 terminx 279
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
280
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
114 terminx 281
        if (i>=4) continue;
563 terminx 282
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
283
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
113 terminx 284
    }
5 Plagman 285
 
563 terminx 286
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
335 terminx 287
    for (i=0; i<MAXMOUSEAXES; i++)
288
    {
563 terminx 289
        ud.config.MouseAnalogueScale[i] = 65536;
290
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 291
 
563 terminx 292
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
293
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
294
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
295
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
5 Plagman 296
 
563 terminx 297
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
298
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
113 terminx 299
    }
127 terminx 300
    CONTROL_SetMouseSensitivity(DEFAULTMOUSESENSITIVITY);
5 Plagman 301
 
563 terminx 302
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
335 terminx 303
    for (i=0; i<MAXJOYBUTTONS; i++)
304
    {
563 terminx 305
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
306
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
307
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
308
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
113 terminx 309
    }
5 Plagman 310
 
563 terminx 311
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
335 terminx 312
    for (i=0; i<MAXJOYAXES; i++)
313
    {
563 terminx 314
        ud.config.JoystickAnalogueScale[i] = 65536;
315
        ud.config.JoystickAnalogueDead[i] = 1000;
316
        ud.config.JoystickAnalogueSaturate[i] = 9500;
317
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 318
 
563 terminx 319
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
320
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
321
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
322
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
112 terminx 323
 
563 terminx 324
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
325
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
113 terminx 326
    }
5 Plagman 327
}
328
/*
329
===================
330
=
331
= CONFIG_ReadKeys
332
=
333
===================
334
*/
335
 
333 terminx 336
void CONFIG_ReadKeys(void)
5 Plagman 337
{
836 terminx 338
    int32 i;
5 Plagman 339
    int32 numkeyentries;
340
    int32 function;
341
    char keyname1[80];
342
    char keyname2[80];
343
    kb_scancode key1,key2;
344
 
563 terminx 345
    if (ud.config.scripthandle < 0) return;
5 Plagman 346
 
563 terminx 347
    numkeyentries = SCRIPT_NumberEntries(ud.config.scripthandle,"KeyDefinitions");
5 Plagman 348
 
815 terminx 349
    Bmemset(&boundkeys,0,sizeof(boundkeys));
350
 
5 Plagman 351
    for (i=0;i<numkeyentries;i++)
352
    {
563 terminx 353
        function = CONFIG_FunctionNameToNum(SCRIPT_Entry(ud.config.scripthandle,"KeyDefinitions", i));
5 Plagman 354
        if (function != -1)
355
        {
356
            memset(keyname1,0,sizeof(keyname1));
357
            memset(keyname2,0,sizeof(keyname2));
358
            SCRIPT_GetDoubleString
359
            (
563 terminx 360
                ud.config.scripthandle,
5 Plagman 361
                "KeyDefinitions",
563 terminx 362
                SCRIPT_Entry(ud.config.scripthandle, "KeyDefinitions", i),
5 Plagman 363
                keyname1,
364
                keyname2
365
            );
366
            key1 = 0xff;
367
            key2 = 0xff;
368
            if (keyname1[0])
369
            {
333 terminx 370
                key1 = (byte) KB_StringToScanCode(keyname1);
5 Plagman 371
            }
372
            if (keyname2[0])
373
            {
333 terminx 374
                key2 = (byte) KB_StringToScanCode(keyname2);
5 Plagman 375
            }
563 terminx 376
            ud.config.KeyboardKeys[function][0] = key1;
377
            ud.config.KeyboardKeys[function][1] = key2;
5 Plagman 378
        }
379
    }
380
 
381
    for (i=0; i<NUMGAMEFUNCTIONS; i++)
382
    {
383
        if (i == gamefunc_Show_Console)
563 terminx 384
            OSD_CaptureKey(ud.config.KeyboardKeys[i][0]);
5 Plagman 385
        else
848 terminx 386
            CONFIG_MapKey(i, ud.config.KeyboardKeys[i][0], 0, ud.config.KeyboardKeys[i][1], 0);
5 Plagman 387
    }
388
}
389
 
836 terminx 390
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
848 terminx 391
void CONFIG_MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
822 terminx 392
{
836 terminx 393
    int i, j, k;
394
    int ii[] = { key1, key2, oldkey1, oldkey2 };
840 terminx 395
    char buf[64];
5 Plagman 396
 
822 terminx 397
    CONTROL_MapKey(which, key1, key2);
836 terminx 398
 
399
    for (k = 0; (unsigned)k < (sizeof(ii) / sizeof(ii[0])); k++)
822 terminx 400
    {
836 terminx 401
        if (ii[k] == 0xff || !ii[k]) continue;
402
 
822 terminx 403
        for (j=0;keynames[j].name;j++)
836 terminx 404
            if (ii[k] == keynames[j].id)
822 terminx 405
                break;
406
        if (keynames[j].name)
836 terminx 407
            boundkeys[ii[k]].key=Bstrdup(keynames[j].name);
824 terminx 408
 
836 terminx 409
        boundkeys[ii[k]].repeat = 1;
410
        boundkeys[ii[k]].cmd[0] = 0;
411
        tempbuf[0] = 0;
412
 
413
        for (i=0;i<NUMGAMEFUNCTIONS;i++)
824 terminx 414
        {
836 terminx 415
            if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
416
            {
417
                Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
418
                Bstrcat(tempbuf,buf);
419
            }
824 terminx 420
        }
836 terminx 421
        Bstrncpy(boundkeys[ii[k]].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
824 terminx 422
 
836 terminx 423
        i = Bstrlen(boundkeys[ii[k]].cmd);
424
        if (i)
848 terminx 425
            boundkeys[ii[k]].cmd[i-2] = 0; // cut off the trailing "; "
822 terminx 426
    }
427
}
428
 
5 Plagman 429
/*
430
===================
431
=
432
= CONFIG_SetupMouse
433
=
434
===================
435
*/
436
 
333 terminx 437
void CONFIG_SetupMouse(void)
5 Plagman 438
{
439
    int32 i;
91 terminx 440
    char str[80];
5 Plagman 441
    char temp[80];
442
    int32 function, scale;
443
 
563 terminx 444
    if (ud.config.scripthandle < 0) return;
5 Plagman 445
 
446
    for (i=0;i<MAXMOUSEBUTTONS;i++)
447
    {
584 terminx 448
        Bsprintf(str,"MouseButton%d",i);
335 terminx 449
        temp[0] = 0;
563 terminx 450
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 451
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 452
 
584 terminx 453
        Bsprintf(str,"MouseButtonClicked%d",i);
335 terminx 454
        temp[0] = 0;
563 terminx 455
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 456
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 457
    }
458
 
459
    // map over the axes
460
    for (i=0;i<MAXMOUSEAXES;i++)
461
    {
584 terminx 462
        Bsprintf(str,"MouseAnalogAxes%d",i);
335 terminx 463
        temp[0] = 0;
563 terminx 464
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 465
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 466
                ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 467
 
584 terminx 468
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
335 terminx 469
        temp[0] = 0;
563 terminx 470
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 471
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 472
                ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 473
 
584 terminx 474
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
335 terminx 475
        temp[0] = 0;
563 terminx 476
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 477
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 478
                ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 479
 
584 terminx 480
        Bsprintf(str,"MouseAnalogScale%d",i);
563 terminx 481
        scale = ud.config.MouseAnalogueScale[i];
482
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
483
        ud.config.MouseAnalogueScale[i] = scale;
5 Plagman 484
    }
485
 
127 terminx 486
    function = DEFAULTMOUSESENSITIVITY;
563 terminx 487
    SCRIPT_GetNumber(ud.config.scripthandle, "Controls","Mouse_Sensitivity",&function);
5 Plagman 488
    CONTROL_SetMouseSensitivity(function);
489
 
490
    for (i=0; i<MAXMOUSEBUTTONS; i++)
491
    {
563 terminx 492
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
493
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
5 Plagman 494
    }
495
    for (i=0; i<MAXMOUSEAXES; i++)
496
    {
563 terminx 497
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
498
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
499
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
500
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 501
    }
502
}
503
 
504
/*
505
===================
506
=
507
= CONFIG_SetupJoystick
508
=
509
===================
510
*/
511
 
333 terminx 512
void CONFIG_SetupJoystick(void)
5 Plagman 513
{
514
    int32 i;
91 terminx 515
    char str[80];
5 Plagman 516
    char temp[80];
91 terminx 517
    int32 scale;
5 Plagman 518
 
563 terminx 519
    if (ud.config.scripthandle < 0) return;
5 Plagman 520
 
521
    for (i=0;i<MAXJOYBUTTONS;i++)
522
    {
584 terminx 523
        Bsprintf(str,"JoystickButton%d",i);
335 terminx 524
        temp[0] = 0;
563 terminx 525
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 526
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 527
 
584 terminx 528
        Bsprintf(str,"JoystickButtonClicked%d",i);
335 terminx 529
        temp[0] = 0;
563 terminx 530
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 531
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 532
    }
533
 
534
    // map over the axes
535
    for (i=0;i<MAXJOYAXES;i++)
536
    {
584 terminx 537
        Bsprintf(str,"JoystickAnalogAxes%d",i);
335 terminx 538
        temp[0] = 0;
563 terminx 539
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 540
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 541
                ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 542
 
584 terminx 543
        Bsprintf(str,"JoystickDigitalAxes%d_0",i);
335 terminx 544
        temp[0] = 0;
563 terminx 545
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 546
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 547
                ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 548
 
584 terminx 549
        Bsprintf(str,"JoystickDigitalAxes%d_1",i);
335 terminx 550
        temp[0] = 0;
563 terminx 551
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 552
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 553
                ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 554
 
584 terminx 555
        Bsprintf(str,"JoystickAnalogScale%d",i);
563 terminx 556
        scale = ud.config.JoystickAnalogueScale[i];
557
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
558
        ud.config.JoystickAnalogueScale[i] = scale;
5 Plagman 559
 
584 terminx 560
        Bsprintf(str,"JoystickAnalogDead%d",i);
563 terminx 561
        scale = ud.config.JoystickAnalogueDead[i];
562
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
563
        ud.config.JoystickAnalogueDead[i] = scale;
5 Plagman 564
 
584 terminx 565
        Bsprintf(str,"JoystickAnalogSaturate%d",i);
563 terminx 566
        scale = ud.config.JoystickAnalogueSaturate[i];
567
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
568
        ud.config.JoystickAnalogueSaturate[i] = scale;
5 Plagman 569
    }
570
 
571
    for (i=0;i<MAXJOYBUTTONS;i++)
572
    {
563 terminx 573
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
574
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
5 Plagman 575
    }
576
    for (i=0;i<MAXJOYAXES;i++)
577
    {
563 terminx 578
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
579
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
580
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
581
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 582
    }
583
}
584
 
585
/*
586
===================
587
=
588
= CONFIG_ReadSetup
589
=
590
===================
591
*/
374 terminx 592
extern char *duke3dgrp;
879 terminx 593
extern void check_valid_color(int *color,int prev_color);
293 terminx 594
 
333 terminx 595
int32 CONFIG_ReadSetup(void)
5 Plagman 596
{
113 terminx 597
    int32 dummy, i;
5 Plagman 598
    char commmacro[] = "CommbatMacro# ";
113 terminx 599
    extern int32 CommandWeaponChoice;
5 Plagman 600
 
601
    CONTROL_ClearAssignments();
602
    CONFIG_SetDefaults();
603
 
563 terminx 604
    ud.config.setupread = 1;
112 terminx 605
 
466 terminx 606
    pathsearchmode = 1;
563 terminx 607
    if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0)  // JBF 20031211
608
        ud.config.scripthandle = SCRIPT_Load(setupfilename);
466 terminx 609
    pathsearchmode = 0;
5 Plagman 610
 
563 terminx 611
    if (ud.config.scripthandle < 0) return -1;
194 terminx 612
 
563 terminx 613
    if (ud.config.scripthandle >= 0)
5 Plagman 614
    {
331 terminx 615
        for (dummy = 0;dummy < 10;dummy++)
5 Plagman 616
        {
617
            commmacro[13] = dummy+'0';
563 terminx 618
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
5 Plagman 619
        }
620
 
563 terminx 621
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
5 Plagman 622
 
400 terminx 623
        while (Bstrlen(stripcolorcodes(tempbuf)) > 10)
159 terminx 624
            tempbuf[Bstrlen(tempbuf)-1] = '\0';
135 terminx 625
 
159 terminx 626
        Bstrncpy(myname,tempbuf,sizeof(myname)-1);
760 terminx 627
        myname[sizeof(myname)-1] = '\0';
159 terminx 628
 
563 terminx 629
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
5 Plagman 630
 
563 terminx 631
        SCRIPT_GetNumber(ud.config.scripthandle, "Comm Setup", "Rate",(int32 *)&packetrate);
509 terminx 632
        packetrate = min(max(packetrate,50),1000);
470 terminx 633
 
634
        {
468 terminx 635
            extern char defaultduke3dgrp[BMAX_PATH];
636
            if (!Bstrcmp(defaultduke3dgrp,"duke3d.grp"))
563 terminx 637
                SCRIPT_GetString(ud.config.scripthandle, "Misc","SelectedGRP",&duke3dgrp[0]);
495 terminx 638
        }
374 terminx 639
 
563 terminx 640
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Shadows",&ud.shadows);
245 terminx 641
 
335 terminx 642
        if (!NAM)
643
        {
563 terminx 644
            SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]);
645
            SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout);
245 terminx 646
        }
647
 
563 terminx 648
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Detail",&ud.detail);
649
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Tilt",&ud.screen_tilting);
650
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Messages",&ud.fta_on);
651
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth);
652
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight);
653
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode);
654
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenGamma",&ud.brightness);
655
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenSize",&ud.screen_size);
5 Plagman 656
 
877 terminx 657
        tempbuf[0] = 0;
658
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "VidGamma",&tempbuf[0]);
659
        if (tempbuf[0]) vid_gamma = atof(tempbuf);
660
        tempbuf[0] = 0;
661
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "VidBrightness",&tempbuf[0]);
662
        if (tempbuf[0]) vid_brightness = atof(tempbuf);
663
        tempbuf[0] = 0;
664
        SCRIPT_GetString(ud.config.scripthandle, "Screen Setup", "VidContrast",&tempbuf[0]);
665
        if (tempbuf[0]) vid_contrast = atof(tempbuf);
872 terminx 666
 
188 terminx 667
#if defined(POLYMOST) && defined(USE_OPENGL)
563 terminx 668
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP);
669
        if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32;
188 terminx 670
#endif
5 Plagman 671
 
672
#ifdef RENDERTYPEWIN
563 terminx 673
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32*)&maxrefreshfreq);
5 Plagman 674
#endif
163 terminx 675
#if defined(POLYMOST) && defined(USE_OPENGL)
563 terminx 676
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLTextureMode", &gltexfiltermode);
677
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLAnisotropy", &glanisotropy);
678
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLProjectionFix", &glprojectionhacks);
679
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLUseTextureCompr", &glusetexcompr);
680
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLWidescreen", &glwidescreen);
163 terminx 681
 
563 terminx 682
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLUseCompressedTextureCache", &glusetexcache);
683
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLUseTextureCacheCompression", &glusetexcachecompression);
259 terminx 684
 
563 terminx 685
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLDepthPeeling", &r_depthpeeling);
686
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLPeelsCount", &r_peelscount);
446 Plagman 687
 
886 terminx 688
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLFullbrights", &r_fullbrights);
563 terminx 689
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLDetailMapping", &r_detailmapping);
690
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLGlowMapping", &r_glowmapping);
691
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLVertexArrays", &r_vertexarrays);
692
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLVBOs", &r_vbos);
693
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLVBOCount", &r_vbocount);
459 Plagman 694
 
563 terminx 695
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLAnimationSmoothing", &r_animsmoothing);
525 Plagman 696
 
623 plagman 697
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyClamping", &r_parallaxskyclamping);
698
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyPanning", &r_parallaxskypanning);
882 terminx 699
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "GLCullObstructedModels", &r_cullobstructedmodels);
335 terminx 700
        dummy = usemodels;
563 terminx 701
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "UseModels",&dummy);
335 terminx 702
        usemodels = dummy != 0;
703
        dummy = usehightile;
563 terminx 704
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "UseHightile",&dummy);
335 terminx 705
        usehightile = dummy != 0;
259 terminx 706
#endif
563 terminx 707
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions);
708
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup", "ForceSetup",&ud.config.ForceSetup);
709
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "RunMode",&ud.config.RunMode);
710
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Crosshairs",&ud.crosshair);
881 terminx 711
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "CrosshairScale",&ud.crosshairscale);
563 terminx 712
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "StatusBarScale",&ud.statusbarscale);
713
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "ShowLevelStats",&ud.levelstats);
714
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "ShowOpponentWeapons",&ud.config.ShowOpponentWeapons);
715
        ud.showweapons = ud.config.ShowOpponentWeapons;
716
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "ShowViewWeapon",&ud.drawweapon);
717
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "DeathMessages",&ud.deathmsgs);
718
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "DemoCams",&ud.democams);
719
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "ShowFPS",&ud.tickrate);
720
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color);
879 terminx 721
        check_valid_color((int *)&ud.color,-1);
564 terminx 722
        g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
563 terminx 723
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Team",&dummy);
471 terminx 724
        ud.team = 0;
725
        if (dummy < 4 && dummy > -1) ud.team = dummy;
563 terminx 726
        g_player[0].pteam = ud.team;
727
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "MPMessageDisplayTime",&ud.msgdisptime);
728
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "StatusBarMode",&ud.statusbarmode);
729
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "AutoVote",&ud.autovote);
730
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "AutoMsg",&ud.automsg);
731
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "IDPlayers",&ud.automsg);
732
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "ViewBobbing",&ud.viewbob);
733
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "WeaponSway",&ud.weaponsway);
148 terminx 734
 
563 terminx 735
        dummy = ud.config.useprecache;
736
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "UsePrecache",&dummy);
737
        ud.config.useprecache = dummy != 0;
5 Plagman 738
 
563 terminx 739
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc","AngleInterpolation",&ud.angleinterpolation);
525 Plagman 740
 
113 terminx 741
        // weapon choices are defaulted in checkcommandline, which may override them
742
        if (!CommandWeaponChoice)
331 terminx 743
            for (i=0;i<10;i++)
5 Plagman 744
            {
584 terminx 745
                Bsprintf(buf,"WeaponChoice%d",i);
113 terminx 746
                dummy = -1;
563 terminx 747
                SCRIPT_GetNumber(ud.config.scripthandle, "Misc", buf, &dummy);
748
                if (dummy >= 0) g_player[0].wchoice[i] = dummy;
5 Plagman 749
            }
750
 
563 terminx 751
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "FXDevice",&ud.config.FXDevice);
752
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "MusicDevice",&ud.config.MusicDevice);
753
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "FXVolume",&ud.config.FXVolume);
754
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "MusicVolume",&ud.config.MusicVolume);
755
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "SoundToggle",&ud.config.SoundToggle);
756
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "MusicToggle",&ud.config.MusicToggle);
757
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "VoiceToggle",&ud.config.VoiceToggle);
758
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "AmbienceToggle",&ud.config.AmbienceToggle);
759
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "NumVoices",&ud.config.NumVoices);
760
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "NumChannels",&ud.config.NumChannels);
761
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "NumBits",&ud.config.NumBits);
762
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "MixRate",&ud.config.MixRate);
763
        SCRIPT_GetNumber(ud.config.scripthandle, "Sound Setup", "ReverseStereo",&ud.config.ReverseStereo);
5 Plagman 764
 
563 terminx 765
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","MouseAimingFlipped",&ud.mouseflip);  // mouse aiming inverted
766
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","MouseAiming",&ud.mouseaiming);             // 1=momentary/0=toggle
564 terminx 767
        g_player[0].ps->aim_mode = ud.mouseaiming;
563 terminx 768
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","MouseBias",&ud.config.MouseBias);
769
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","MouseFilter",&ud.config.MouseFilter);
770
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","SmoothInput",&ud.config.SmoothInput);
771
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","UseJoystick",&ud.config.UseJoystick);
772
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","UseMouse",&ud.config.UseMouse);
773
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","AimingFlag",(int32 *)&myaimmode);    // (if toggle mode) gives state
774
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","RunKeyBehaviour",&ud.runkey_mode);   // JBF 20031125
775
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","AutoAim",&ud.config.AutoAim);          // JBF 20031125
564 terminx 776
        g_player[0].ps->auto_aim = ud.config.AutoAim;
563 terminx 777
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls","WeaponSwitchMode",&ud.weaponswitch);
564 terminx 778
        g_player[0].ps->weaponswitch = ud.weaponswitch;
428 terminx 779
 
780
#ifdef _WIN32
563 terminx 781
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
782
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
783
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32 *)&windowpos);
540 terminx 784
        windowx = -1;
563 terminx 785
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32 *)&windowx);
540 terminx 786
        windowy = -1;
563 terminx 787
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32 *)&windowy);
416 terminx 788
#endif
5 Plagman 789
    }
790
 
791
    CONFIG_ReadKeys();
792
 
563 terminx 793
    //CONFIG_SetupMouse(ud.config.scripthandle);
794
    //CONFIG_SetupJoystick(ud.config.scripthandle);
795
    ud.config.setupread = 1;
194 terminx 796
    return 0;
5 Plagman 797
}
798
 
799
/*
800
===================
801
=
802
= CONFIG_WriteSetup
803
=
804
===================
805
*/
806
 
818 terminx 807
void CONFIG_WriteBinds(void) // save binds and aliases to disk
813 terminx 808
{
809
    int i;
810
    FILE *fp = fopen("binds.cfg", "wt");
811
 
812
    if (fp)
813
    {
818 terminx 814
        symbol_t *symb;
813 terminx 815
        fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n");
823 terminx 816
        for (i=0;i<MAXBOUNDKEYS;i++)
836 terminx 817
            if (boundkeys[i].cmd[0] && boundkeys[i].key)
872 terminx 818
                fprintf(fp,"bind \"%s\"%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].cmd);
818 terminx 819
 
826 terminx 820
        for (i=0;i<MAXMOUSEBUTTONS;i++)
836 terminx 821
            if (mousebind[i].cmd[0])
872 terminx 822
                fprintf(fp,"bind \"%s\"%s \"%s\"\n",mousebind[i].key,mousebind[i].repeat?"":" norepeat",mousebind[i].cmd);
826 terminx 823
 
818 terminx 824
        for (symb=symbols; symb!=NULL; symb=symb->next)
825
            if (symb->func == (void *)OSD_ALIAS)
872 terminx 826
                fprintf(fp,"alias \"%s\" \"%s\"\n", symb->name, symb->help);
818 terminx 827
 
830 terminx 828
        /*        for (i = 0; i < sizeof(cvar)/sizeof(cvarmappings); i++)
829
                    if (!(cvar[i].type&CVAR_NOSAVE))
830
                        fprintf(fp,"%s \"%d\"\n",cvar[i].name,*(int*)cvar[i].var);
831
                        */
813 terminx 832
        fclose(fp);
845 terminx 833
        OSD_Printf("Wrote binds.cfg\n");
834
        return;
813 terminx 835
    }
845 terminx 836
    OSD_Printf("Error writing binds.cfg: %s\n",strerror(errno));
813 terminx 837
}
838
 
333 terminx 839
void CONFIG_WriteSetup(void)
5 Plagman 840
{
841
    int32 dummy;
842
 
563 terminx 843
    if (!ud.config.setupread) return;
112 terminx 844
 
563 terminx 845
    if (ud.config.scripthandle < 0)
846
        ud.config.scripthandle = SCRIPT_Init(setupfilename);
5 Plagman 847
 
584 terminx 848
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","AimingFlag",(int) myaimmode,false,false);
563 terminx 849
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","AutoAim",ud.config.AutoAim,false,false);
850
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","MouseAimingFlipped",ud.mouseflip,false,false);
851
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","MouseAiming",ud.mouseaiming,false,false);
852
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","MouseBias",ud.config.MouseBias,false,false);
853
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","MouseFilter",ud.config.MouseFilter,false,false);
854
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","SmoothInput",ud.config.SmoothInput,false,false);
855
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","RunKeyBehaviour",ud.runkey_mode,false,false);
856
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","UseJoystick",ud.config.UseJoystick,false,false);
857
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","UseMouse",ud.config.UseMouse,false,false);
858
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","WeaponSwitchMode",ud.weaponswitch,false,false);
150 terminx 859
 
563 terminx 860
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "AutoMsg",ud.automsg,false,false);
861
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "AutoVote",ud.autovote,false,false);
862
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Color",ud.color,false,false);
863
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Crosshairs",ud.crosshair,false,false);
881 terminx 864
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "CrosshairScale",ud.crosshairscale,false,false);
563 terminx 865
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "DeathMessages",ud.deathmsgs,false,false);
866
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "DemoCams",ud.democams,false,false);
249 terminx 867
    ud.executions++;
563 terminx 868
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",ud.executions,false,false);
869
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup",ud.config.ForceSetup,false,false);
870
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "IDPlayers",ud.idplayers,false,false);
871
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "MPMessageDisplayTime",ud.msgdisptime,false,false);
872
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "RunMode",ud.config.RunMode,false,false);
873
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "ShowFPS",ud.tickrate,false,false);
874
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "ShowLevelStats",ud.levelstats,false,false);
875
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "ShowOpponentWeapons",ud.config.ShowOpponentWeapons,false,false);
876
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "ShowViewWeapon",ud.drawweapon,false,false);
877
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "StatusBarMode",ud.statusbarmode,false,false);
878
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "StatusBarScale",ud.statusbarscale,false,false);
879
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Team",ud.team,false,false);
880
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "UsePrecache",ud.config.useprecache,false,false);
881
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "ViewBobbing",ud.viewbob,false,false);
882
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "WeaponSway",ud.weaponsway,false,false);
883
//    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "AngleInterpolation",ud.angleinterpolation,false,false);
150 terminx 884
 
563 terminx 885
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Detail",ud.detail,false,false);
163 terminx 886
#if defined(POLYMOST) && defined(USE_OPENGL)
563 terminx 887
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLAnisotropy",glanisotropy,false,false);
888
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLProjectionFix",glprojectionhacks,false,false);
889
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLTextureMode",gltexfiltermode,false,false);
890
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLUseCompressedTextureCache", glusetexcache,false,false);
891
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLUseTextureCacheCompression", glusetexcachecompression,false,false);
892
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLUseTextureCompr",glusetexcompr,false,false);
893
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLWidescreen",glwidescreen,false,false);
459 Plagman 894
 
563 terminx 895
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLDepthPeeling",r_depthpeeling,false,false);
896
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLPeelsCount",r_peelscount,false,false);
459 Plagman 897
 
886 terminx 898
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLFullbrights", r_fullbrights,false,false);
563 terminx 899
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLDetailMapping", r_detailmapping,false,false);
900
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLGlowMapping", r_glowmapping,false,false);
901
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLVertexArrays", r_vertexarrays,false,false);
902
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLVBOs", r_vbos,false,false);
903
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLVBOCount", r_vbocount,false,false);
525 Plagman 904
 
563 terminx 905
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLAnimationSmoothing",r_animsmoothing,false,false);
623 plagman 906
 
907
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyClamping",r_parallaxskyclamping,false,false);
908
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLParallaxSkyPanning",r_parallaxskypanning,false,false);
882 terminx 909
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "GLCullObstructedModels", r_cullobstructedmodels,false,false);
163 terminx 910
#endif
150 terminx 911
#ifdef RENDERTYPEWIN
563 terminx 912
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq",maxrefreshfreq,false,false);
150 terminx 913
#endif
563 terminx 914
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Messages",ud.fta_on,false,false);
245 terminx 915
 
335 terminx 916
    if (!NAM)
917
    {
563 terminx 918
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,false,false);
919
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
245 terminx 920
    }
921
 
563 terminx 922
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,false,false);  // JBF 20040523
923
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenGamma",ud.brightness,false,false);
924
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,false,false);    // JBF 20031206
925
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,false,false);    // JBF 20031206
926
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenSize",ud.screen_size,false,false);
927
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,false,false);  // JBF 20031206
928
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Shadows",ud.shadows,false,false);
929
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Tilt",ud.screen_tilting,false,false);
259 terminx 930
#if defined(POLYMOST) && defined(USE_OPENGL)
563 terminx 931
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "UseHightile",usehightile,false,false);
932
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "UseModels",usemodels,false,false);
259 terminx 933
#endif
563 terminx 934
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "AmbienceToggle",ud.config.AmbienceToggle,false,false);
935
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "FXVolume",ud.config.FXVolume,false,false);
936
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "MusicToggle",ud.config.MusicToggle,false,false);
937
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "MusicVolume",ud.config.MusicVolume,false,false);
938
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "NumVoices",ud.config.NumVoices,false,false);
939
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "NumChannels",ud.config.NumChannels,false,false);
940
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "NumBits",ud.config.NumBits,false,false);
941
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "MixRate",ud.config.MixRate,false,false);
942
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "ReverseStereo",ud.config.ReverseStereo,false,false);
943
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "SoundToggle",ud.config.SoundToggle,false,false);
944
    SCRIPT_PutNumber(ud.config.scripthandle, "Sound Setup", "VoiceToggle",ud.config.VoiceToggle,false,false);
5 Plagman 945
 
872 terminx 946
    Bsprintf(tempbuf,"%.2f",vid_gamma);
947
    SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "VidGamma",tempbuf);
948
    Bsprintf(tempbuf,"%.2f",vid_brightness);
949
    SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "VidBrightness",tempbuf);
950
    Bsprintf(tempbuf,"%.2f",vid_contrast);
951
    SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "VidContrast",tempbuf);
952
 
416 terminx 953
#ifdef _WIN32
563 terminx 954
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, false, false);
955
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, false, false);
956
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, false, false);
957
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, false, false);
958
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, false, false);
416 terminx 959
#endif
960
 
5 Plagman 961
    // JBF 20031211
335 terminx 962
    for (dummy=0;dummy<NUMGAMEFUNCTIONS;dummy++)
963
    {
563 terminx 964
        SCRIPT_PutDoubleString(ud.config.scripthandle, "KeyDefinitions", CONFIG_FunctionNumToName(dummy),
965
                               KB_ScanCodeToString(ud.config.KeyboardKeys[dummy][0]), KB_ScanCodeToString(ud.config.KeyboardKeys[dummy][1]));
5 Plagman 966
    }
967
 
331 terminx 968
    for (dummy=0;dummy<10;dummy++)
5 Plagman 969
    {
584 terminx 970
        Bsprintf(buf,"WeaponChoice%d",dummy);
563 terminx 971
        SCRIPT_PutNumber(ud.config.scripthandle, "Misc",buf,g_player[myconnectindex].wchoice[dummy],false,false);
5 Plagman 972
    }
973
 
335 terminx 974
    for (dummy=0;dummy<MAXMOUSEBUTTONS;dummy++)
975
    {
584 terminx 976
        Bsprintf(buf,"MouseButton%d",dummy);
563 terminx 977
        SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]));
5 Plagman 978
 
979
        if (dummy >= (MAXMOUSEBUTTONS-2)) continue;
980
 
584 terminx 981
        Bsprintf(buf,"MouseButtonClicked%d",dummy);
563 terminx 982
        SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]));
5 Plagman 983
    }
606 terminx 984
 
335 terminx 985
    for (dummy=0;dummy<MAXMOUSEAXES;dummy++)
986
    {
584 terminx 987
        Bsprintf(buf,"MouseAnalogAxes%d",dummy);
563 terminx 988
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]));
5 Plagman 989
 
584 terminx 990
        Bsprintf(buf,"MouseDigitalAxes%d_0",dummy);
563 terminx 991
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]));
5 Plagman 992
 
584 terminx 993
        Bsprintf(buf,"MouseDigitalAxes%d_1",dummy);
563 terminx 994
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]));
5 Plagman 995
 
584 terminx 996
        Bsprintf(buf,"MouseAnalogScale%d",dummy);
563 terminx 997
        SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[dummy], false, false);
5 Plagman 998
    }
999
    dummy = CONTROL_GetMouseSensitivity();
563 terminx 1000
    SCRIPT_PutNumber(ud.config.scripthandle, "Controls","Mouse_Sensitivity",dummy,false,false);
5 Plagman 1001
 
335 terminx 1002
    for (dummy=0;dummy<MAXJOYBUTTONS;dummy++)
1003
    {
584 terminx 1004
        Bsprintf(buf,"JoystickButton%d",dummy);
563 terminx 1005
        SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
5 Plagman 1006
 
584 terminx 1007
        Bsprintf(buf,"JoystickButtonClicked%d",dummy);
563 terminx 1008
        SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
5 Plagman 1009
    }
335 terminx 1010
    for (dummy=0;dummy<MAXJOYAXES;dummy++)
1011
    {
584 terminx 1012
        Bsprintf(buf,"JoystickAnalogAxes%d",dummy);
563 terminx 1013
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
5 Plagman 1014
 
584 terminx 1015
        Bsprintf(buf,"JoystickDigitalAxes%d_0",dummy);
563 terminx 1016
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
5 Plagman 1017
 
584 terminx 1018
        Bsprintf(buf,"JoystickDigitalAxes%d_1",dummy);
563 terminx 1019
        SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
5 Plagman 1020
 
584 terminx 1021
        Bsprintf(buf,"JoystickAnalogScale%d",dummy);
563 terminx 1022
        SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], false, false);
5 Plagman 1023
 
584 terminx 1024
        Bsprintf(buf,"JoystickAnalogDead%d",dummy);
563 terminx 1025
        SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], false, false);
5 Plagman 1026
 
584 terminx 1027
        Bsprintf(buf,"JoystickAnalogSaturate%d",dummy);
563 terminx 1028
        SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], false, false);
5 Plagman 1029
    }
1030
 
563 terminx 1031
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&myname[0]);
1032
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
495 terminx 1033
 
563 terminx 1034
    SCRIPT_PutNumber(ud.config.scripthandle, "Comm Setup", "Rate", packetrate, false, false);
495 terminx 1035
 
1036
 
563 terminx 1037
    SCRIPT_PutString(ud.config.scripthandle, "Misc","SelectedGRP",&duke3dgrp[0]);
88 terminx 1038
    {
1039
        char commmacro[] = "CommbatMacro# ";
1040
 
331 terminx 1041
        for (dummy = 0;dummy < 10;dummy++)
88 terminx 1042
        {
1043
            commmacro[13] = dummy+'0';
563 terminx 1044
            SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
88 terminx 1045
        }
1046
    }
1047
 
563 terminx 1048
    SCRIPT_Save(ud.config.scripthandle, setupfilename);
1049
    SCRIPT_Free(ud.config.scripthandle);
845 terminx 1050
    OSD_Printf("Wrote %s\n",setupfilename);
1051
    CONFIG_WriteBinds();
5 Plagman 1052
}
1053
 
1054
 
322 terminx 1055
int32 CONFIG_GetMapBestTime(char *mapname)
1056
{
1057
    int32 t = -1;
1058
    char m[BMAX_PATH], *p;
1059
 
1060
    strcpy(m, mapname);
1061
    p = strrchr(m, '/');
1062
    if (!p) p = strrchr(m, '\\');
1063
    if (p) strcpy(m, p);
1064
    for (p=m;*p;p++) *p = tolower(*p);
1065
 
563 terminx 1066
    if (!ud.config.setupread) return -1;
1067
    if (ud.config.scripthandle < 0) return -1;
1068
    SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t);
322 terminx 1069
 
1070
    return t;
1071
}
1072
 
1073
int32 CONFIG_SetMapBestTime(char *mapname, int32 tm)
1074
{
1075
    char m[BMAX_PATH], *p;
1076
 
1077
    strcpy(m, mapname);
1078
    p = strrchr(m, '/');
1079
    if (!p) p = strrchr(m, '\\');
1080
    if (p) strcpy(m, p);
1081
    for (p=m;*p;p++) *p = tolower(*p);
1082
 
563 terminx 1083
    if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename);
1084
    if (ud.config.scripthandle < 0) return -1;
322 terminx 1085
 
563 terminx 1086
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", mapname, tm, false, false);
322 terminx 1087
    return 0;
1088
}
1089
 
5 Plagman 1090
/*
1091
 * vim:ts=4:sw=4:
1092
 */
1093