Subversion Repositories eduke32

Rev

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