Subversion Repositories eduke32

Rev

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

Rev Author Line No. Line
5 Plagman 1
//-------------------------------------------------------------------------
2
/*
1652 terminx 3
Copyright (C) 2010 EDuke32 developers and contributors
5 Plagman 4
 
1652 terminx 5
This file is part of EDuke32.
5 Plagman 6
 
7
EDuke32 is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
See the GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
*/
21
//-------------------------------------------------------------------------
22
 
23
/*
24
#include <stdio.h>
25
#include <string.h>
26
#include <stdlib.h>
27
#include <ctype.h>
28
#include <time.h>
29
*/
30
 
901 terminx 31
#include "baselayer.h"
5 Plagman 32
#include "duke3d.h"
2290 helixhorne 33
#include "game.h"
2726 hendricks2 34
#include "common_game.h"
5 Plagman 35
#include "scriplib.h"
36
#include "osd.h"
820 terminx 37
#include "osdcmds.h"
901 terminx 38
#include "osdfuncs.h"
3655 terminx 39
#ifdef _WIN32
40
#include "winlayer.h"
41
#endif
5 Plagman 42
 
4440 terminx 43
#ifdef __ANDROID__
44
#include "android.h"
45
#endif
46
 
5 Plagman 47
// we load this in to get default button and key assignments
48
// as well as setting up function mappings
49
 
50
#define __SETUP__   // JBF 20031211
51
#include "_functio.h"
52
 
53
/*
54
===================
55
=
56
= CONFIG_FunctionNameToNum
57
=
58
===================
59
*/
60
 
1625 terminx 61
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
1026 terminx 62
 
2796 helixhorne 63
int32_t CONFIG_FunctionNameToNum(const char *func)
5 Plagman 64
{
1346 terminx 65
    int32_t i;
5 Plagman 66
 
1625 terminx 67
    i = hash_find(&h_gamefuncs,func);
1197 terminx 68
 
69
    if (i < 0)
70
    {
1642 terminx 71
        char *str = Bstrtolower(Bstrdup(func));
1625 terminx 72
        i = hash_find(&h_gamefuncs,str);
1197 terminx 73
        Bfree(str);
74
 
1026 terminx 75
        return i;
1197 terminx 76
    }
77
 
78
    return i;
5 Plagman 79
}
80
 
81
/*
82
===================
83
=
84
= CONFIG_FunctionNumToName
85
=
86
===================
87
*/
88
 
1677 terminx 89
char *CONFIG_FunctionNumToName(int32_t func)
5 Plagman 90
{
91
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
92
        return NULL;
437 terminx 93
    return gamefunctions[func];
5 Plagman 94
}
95
 
96
/*
97
===================
98
=
99
= CONFIG_AnalogNameToNum
100
=
101
===================
102
*/
103
 
104
 
2796 helixhorne 105
int32_t CONFIG_AnalogNameToNum(const char *func)
5 Plagman 106
{
107
 
108
    if (!Bstrcasecmp(func,"analog_turning"))
109
    {
110
        return analog_turning;
111
    }
112
    if (!Bstrcasecmp(func,"analog_strafing"))
113
    {
114
        return analog_strafing;
115
    }
116
    if (!Bstrcasecmp(func,"analog_moving"))
117
    {
118
        return analog_moving;
119
    }
120
    if (!Bstrcasecmp(func,"analog_lookingupanddown"))
121
    {
122
        return analog_lookingupanddown;
123
    }
124
 
125
    return -1;
126
}
127
 
128
 
2796 helixhorne 129
const char *CONFIG_AnalogNumToName(int32_t func)
5 Plagman 130
{
335 terminx 131
    switch (func)
132
    {
337 terminx 133
    case analog_turning:
134
        return "analog_turning";
135
    case analog_strafing:
136
        return "analog_strafing";
137
    case analog_moving:
138
        return "analog_moving";
139
    case analog_lookingupanddown:
140
        return "analog_lookingupanddown";
5 Plagman 141
    }
142
 
143
    return NULL;
144
}
145
 
146
 
147
/*
148
===================
149
=
150
= CONFIG_SetDefaults
151
=
152
===================
153
*/
154
 
3133 terminx 155
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN])
495 terminx 156
{
1346 terminx 157
    int32_t i,f;
495 terminx 158
 
822 terminx 159
    Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
3127 helixhorne 160
 
3209 helixhorne 161
    CONTROL_ClearAllBinds();
496 terminx 162
 
4385 terminx 163
    for (i=0; i < (int32_t)ARRAY_SIZE(keydefaults); i+=3)
495 terminx 164
    {
3128 terminx 165
        f = CONFIG_FunctionNameToNum(keyptr[i+0]);
495 terminx 166
        if (f == -1) continue;
3128 terminx 167
        ud.config.KeyboardKeys[f][0] = KB_StringToScanCode(keyptr[i+1]);
168
        ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keyptr[i+2]);
495 terminx 169
 
563 terminx 170
        if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
848 terminx 171
        else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
495 terminx 172
    }
173
}
174
 
333 terminx 175
void CONFIG_SetDefaults(void)
5 Plagman 176
{
177
    // JBF 20031211
1346 terminx 178
    int32_t i;
5 Plagman 179
 
563 terminx 180
    ud.config.scripthandle = -1;
4386 terminx 181
#ifdef __ANDROID__
4436 terminx 182
    ud.config.ScreenWidth = droidinfo.screen_width;
183
    ud.config.ScreenHeight = droidinfo.screen_height;
4386 terminx 184
#else
622 terminx 185
    ud.config.ScreenWidth = 1024;
186
    ud.config.ScreenHeight = 768;
4386 terminx 187
#endif
188
 
622 terminx 189
    ud.config.ScreenMode = 0;
4386 terminx 190
 
1820 terminx 191
#ifdef USE_OPENGL
622 terminx 192
    ud.config.ScreenBPP = 32;
193
#else
194
    ud.config.ScreenBPP = 8;
195
#endif
563 terminx 196
    ud.config.useprecache = 1;
197
    ud.config.ForceSetup = 1;
1390 terminx 198
    ud.config.NoAutoLoad = 1;
563 terminx 199
    ud.config.AmbienceToggle = 1;
200
    ud.config.AutoAim = 1;
201
    ud.config.FXDevice = 0;
3993 terminx 202
    ud.config.MasterVolume = 255;
1657 terminx 203
    ud.config.FXVolume = 225;
821 terminx 204
#if defined(_WIN32)
563 terminx 205
    ud.config.MixRate = 44100;
4436 terminx 206
#elif defined __ANDROID__
207
    ud.config.MixRate = droidinfo.audio_sample_rate;
821 terminx 208
#else
209
    ud.config.MixRate = 48000;
210
#endif
563 terminx 211
    ud.config.MouseBias = 0;
1099 terminx 212
    ud.config.MouseDeadZone = 0;
563 terminx 213
    ud.config.MusicDevice = 0;
214
    ud.config.MusicToggle = 1;
1657 terminx 215
    ud.config.MusicVolume = 195;
1143 terminx 216
    g_myAimMode = g_player[0].ps->aim_mode = 1;
563 terminx 217
    ud.config.NumBits = 16;
218
    ud.config.NumChannels = 2;
219
    ud.config.NumVoices = 32;
220
    ud.config.ReverseStereo = 0;
1645 terminx 221
    ud.auto_run = 1;
563 terminx 222
    ud.config.ShowOpponentWeapons = 0;
223
    ud.config.SmoothInput = 1;
224
    ud.config.SoundToggle = 1;
934 terminx 225
    ud.althud = 1;
158 terminx 226
    ud.automsg = 0;
227
    ud.autovote = 0;
222 terminx 228
    ud.brightness = 8;
570 terminx 229
    ud.camerasprite = -1;
158 terminx 230
    ud.color = 0;
881 terminx 231
    ud.crosshair = 1;
232
    ud.crosshairscale = 50;
926 terminx 233
    ud.obituaries = 1;
158 terminx 234
    ud.democams = 1;
235
    ud.detail = 1;
236
    ud.drawweapon = 1;
237
    ud.idplayers = 1;
238
    ud.levelstats = 0;
239
    ud.lockout = 0;
240
    ud.m_ffire = 1;
241
    ud.m_marker = 1;
5 Plagman 242
    ud.mouseaiming = 0;
110 terminx 243
    ud.mouseflip = 1;
158 terminx 244
    ud.msgdisptime = 120;
245
    ud.pwlockout[0] = '\0';
5 Plagman 246
    ud.runkey_mode = 0;
110 terminx 247
    ud.screen_size = 4;
5 Plagman 248
    ud.screen_tilting = 1;
249
    ud.shadows = 1;
3402 helixhorne 250
    ud.statusbarmode = 1;
1159 terminx 251
    ud.statusbarscale = 100;
268 terminx 252
    ud.team = 0;
506 terminx 253
    ud.viewbob = 1;
254
    ud.weaponsway = 1;
158 terminx 255
    ud.weaponswitch = 3;        // new+empty
529 terminx 256
    ud.angleinterpolation = 0;
2645 helixhorne 257
#ifdef GEKKO
258
    ud.config.UseJoystick = 1;
259
#else
563 terminx 260
    ud.config.UseJoystick = 0;
2645 helixhorne 261
#endif
563 terminx 262
    ud.config.UseMouse = 1;
915 terminx 263
    ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
990 terminx 264
    ud.display_bonus_screen = 1;
1082 terminx 265
    ud.show_level_text = 1;
992 terminx 266
    ud.configversion = 0;
1090 terminx 267
    ud.weaponscale = 100;
1095 terminx 268
    ud.textscale = 100;
131 terminx 269
 
1245 terminx 270
    ud.config.CheckForUpdates = 1;
271
 
2420 hendricks2 272
    if (g_rtsNamePtr == NULL)
2726 hendricks2 273
        Bstrcpy(ud.rtsname, G_DefaultRtsFile());
1143 terminx 274
    Bstrcpy(szPlayerName, "Duke");
5 Plagman 275
 
276
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
277
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
278
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
279
    Bstrcpy(ud.ridecule[3], "Lucky Son of a Bitch.");
280
    Bstrcpy(ud.ridecule[4], "Hmmm....Payback time.");
281
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
282
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
283
    Bstrcpy(ud.ridecule[7], "Ha ha ha...Wasted!");
284
    Bstrcpy(ud.ridecule[8], "You suck!");
285
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
286
 
287
    // JBF 20031211
288
 
3133 terminx 289
    CONFIG_SetDefaultKeys((const char (*)[MAXGAMEFUNCLEN])keydefaults);
506 terminx 290
 
563 terminx 291
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
335 terminx 292
    for (i=0; i<MAXMOUSEBUTTONS; i++)
293
    {
563 terminx 294
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
295
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
114 terminx 296
        if (i>=4) continue;
563 terminx 297
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
298
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
113 terminx 299
    }
5 Plagman 300
 
563 terminx 301
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
335 terminx 302
    for (i=0; i<MAXMOUSEAXES; i++)
303
    {
2728 hendricks2 304
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
563 terminx 305
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 306
 
563 terminx 307
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
308
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
309
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
310
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
5 Plagman 311
 
563 terminx 312
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
313
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
113 terminx 314
    }
1355 terminx 315
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
5 Plagman 316
 
563 terminx 317
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
335 terminx 318
    for (i=0; i<MAXJOYBUTTONS; i++)
319
    {
563 terminx 320
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
321
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
322
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
323
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
113 terminx 324
    }
5 Plagman 325
 
563 terminx 326
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
335 terminx 327
    for (i=0; i<MAXJOYAXES; i++)
328
    {
2728 hendricks2 329
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
330
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
331
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
563 terminx 332
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 333
 
563 terminx 334
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
335
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
336
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
337
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
112 terminx 338
 
563 terminx 339
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
340
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
113 terminx 341
    }
5 Plagman 342
}
343
 
344
 
836 terminx 345
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
1346 terminx 346
void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
822 terminx 347
{
1205 terminx 348
    int32_t i, j, k;
349
    int32_t ii[] = { key1, key2, oldkey1, oldkey2 };
3209 helixhorne 350
    char buf[2*MAXGAMEFUNCLEN];
5 Plagman 351
 
3124 helixhorne 352
    UNREFERENCED_PARAMETER(which);
353
//    CONTROL_MapKey(which, key1, key2);
836 terminx 354
 
3128 terminx 355
    if (which == gamefunc_Show_Console)
356
        OSD_CaptureKey(key1);
357
 
4385 terminx 358
    for (k = 0; (unsigned)k < ARRAY_SIZE(ii); k++)
822 terminx 359
    {
3209 helixhorne 360
        if (ii[k] == 0xff || !ii[k])
361
            continue;
836 terminx 362
 
1229 terminx 363
        for (j=0; ConsoleKeys[j].name; j++)
1206 terminx 364
            if (ii[k] == ConsoleKeys[j].id)
822 terminx 365
                break;
824 terminx 366
 
836 terminx 367
        tempbuf[0] = 0;
368
 
1229 terminx 369
        for (i=NUMGAMEFUNCTIONS-1; i>=0; i--)
824 terminx 370
        {
836 terminx 371
            if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
372
            {
373
                Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
374
                Bstrcat(tempbuf,buf);
375
            }
824 terminx 376
        }
377
 
3209 helixhorne 378
        i = Bstrlen(tempbuf);
379
        if (i >= 2)
380
        {
381
            tempbuf[i-2] = 0;  // cut off the trailing "; "
382
            CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : "<?>");
383
        }
384
        else
385
        {
386
            CONTROL_FreeKeyBind(ii[k]);
387
        }
822 terminx 388
    }
389
}
390
 
5 Plagman 391
/*
392
===================
393
=
394
= CONFIG_SetupMouse
395
=
396
===================
397
*/
398
 
333 terminx 399
void CONFIG_SetupMouse(void)
5 Plagman 400
{
1346 terminx 401
    int32_t i;
91 terminx 402
    char str[80];
5 Plagman 403
    char temp[80];
1355 terminx 404
    int32_t scale;
5 Plagman 405
 
563 terminx 406
    if (ud.config.scripthandle < 0) return;
5 Plagman 407
 
1229 terminx 408
    for (i=0; i<MAXMOUSEBUTTONS; i++)
5 Plagman 409
    {
584 terminx 410
        Bsprintf(str,"MouseButton%d",i);
335 terminx 411
        temp[0] = 0;
563 terminx 412
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 413
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 414
 
584 terminx 415
        Bsprintf(str,"MouseButtonClicked%d",i);
335 terminx 416
        temp[0] = 0;
563 terminx 417
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 418
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 419
    }
420
 
421
    // map over the axes
1229 terminx 422
    for (i=0; i<MAXMOUSEAXES; i++)
5 Plagman 423
    {
584 terminx 424
        Bsprintf(str,"MouseAnalogAxes%d",i);
335 terminx 425
        temp[0] = 0;
563 terminx 426
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 427
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 428
                ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 429
 
584 terminx 430
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
335 terminx 431
        temp[0] = 0;
563 terminx 432
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 433
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 434
                ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 435
 
584 terminx 436
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
335 terminx 437
        temp[0] = 0;
563 terminx 438
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 439
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 440
                ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 441
 
584 terminx 442
        Bsprintf(str,"MouseAnalogScale%d",i);
563 terminx 443
        scale = ud.config.MouseAnalogueScale[i];
444
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
445
        ud.config.MouseAnalogueScale[i] = scale;
5 Plagman 446
    }
447
 
1355 terminx 448
    {
449
        tempbuf[0] = 0;
450
        SCRIPT_GetString(ud.config.scripthandle, "Controls","Mouse_Sensitivity",&tempbuf[0]);
451
        if (tempbuf[0]) CONTROL_MouseSensitivity = atof(tempbuf);
452
    }
5 Plagman 453
 
454
    for (i=0; i<MAXMOUSEBUTTONS; i++)
455
    {
563 terminx 456
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
457
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
5 Plagman 458
    }
459
    for (i=0; i<MAXMOUSEAXES; i++)
460
    {
563 terminx 461
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
462
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
463
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
464
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
5 Plagman 465
    }
466
}
467
 
468
/*
469
===================
470
=
471
= CONFIG_SetupJoystick
472
=
473
===================
474
*/
475
 
333 terminx 476
void CONFIG_SetupJoystick(void)
5 Plagman 477
{
1346 terminx 478
    int32_t i;
91 terminx 479
    char str[80];
5 Plagman 480
    char temp[80];
1346 terminx 481
    int32_t scale;
5 Plagman 482
 
563 terminx 483
    if (ud.config.scripthandle < 0) return;
5 Plagman 484
 
1229 terminx 485
    for (i=0; i<MAXJOYBUTTONS; i++)
5 Plagman 486
    {
584 terminx 487
        Bsprintf(str,"JoystickButton%d",i);
335 terminx 488
        temp[0] = 0;
563 terminx 489
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 490
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 491
 
584 terminx 492
        Bsprintf(str,"JoystickButtonClicked%d",i);
335 terminx 493
        temp[0] = 0;
563 terminx 494
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
753 terminx 495
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 496
    }
497
 
498
    // map over the axes
1229 terminx 499
    for (i=0; i<MAXJOYAXES; i++)
5 Plagman 500
    {
584 terminx 501
        Bsprintf(str,"JoystickAnalogAxes%d",i);
335 terminx 502
        temp[0] = 0;
563 terminx 503
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 504
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 505
                ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
5 Plagman 506
 
584 terminx 507
        Bsprintf(str,"JoystickDigitalAxes%d_0",i);
335 terminx 508
        temp[0] = 0;
563 terminx 509
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 510
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 511
                ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
5 Plagman 512
 
584 terminx 513
        Bsprintf(str,"JoystickDigitalAxes%d_1",i);
335 terminx 514
        temp[0] = 0;
563 terminx 515
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
423 terminx 516
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
563 terminx 517
                ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
5 Plagman 518
 
584 terminx 519
        Bsprintf(str,"JoystickAnalogScale%d",i);
563 terminx 520
        scale = ud.config.JoystickAnalogueScale[i];
521
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
522
        ud.config.JoystickAnalogueScale[i] = scale;
5 Plagman 523
 
584 terminx 524
        Bsprintf(str,"JoystickAnalogDead%d",i);
563 terminx 525
        scale = ud.config.JoystickAnalogueDead[i];
526
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
527
        ud.config.JoystickAnalogueDead[i] = scale;
5 Plagman 528
 
584 terminx 529
        Bsprintf(str,"JoystickAnalogSaturate%d",i);
563 terminx 530
        scale = ud.config.JoystickAnalogueSaturate[i];
531
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
532
        ud.config.JoystickAnalogueSaturate[i] = scale;
5 Plagman 533
    }
534
 
1229 terminx 535
    for (i=0; i<MAXJOYBUTTONS; i++)
5 Plagman 536
    {
563 terminx 537
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
538
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
5 Plagman 539
    }
1229 terminx 540
    for (i=0; i<MAXJOYAXES; i++)
5 Plagman 541
    {
563 terminx 542
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
543
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
544
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
545
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
5 Plagman 546
    }
547
}
548
 
549
/*
550
===================
551
=
552
= CONFIG_ReadSetup
553
=
554
===================
555
*/
1205 terminx 556
extern void G_CheckPlayerColor(int32_t *color,int32_t prev_color);
1143 terminx 557
extern palette_t CrosshairColors;
558
extern palette_t DefaultCrosshairColors;
1587 terminx 559
extern char g_modDir[BMAX_PATH];
1205 terminx 560
extern int32_t r_maxfps;
561
extern int32_t g_noSetup;
1595 helixhorne 562
extern int32_t demorec_diffs_cvar, demoplay_diffs;
563
extern int32_t demorec_difftics_cvar, demorec_diffcompress_cvar, demorec_synccompress_cvar;
293 terminx 564
 
1346 terminx 565
int32_t CONFIG_ReadSetup(void)
5 Plagman 566
{
1346 terminx 567
    int32_t dummy, i = 0;
5 Plagman 568
    char commmacro[] = "CommbatMacro# ";
1029 terminx 569
    char tempbuf[1024];
5 Plagman 570
 
571
    CONTROL_ClearAssignments();
572
    CONFIG_SetDefaults();
573
 
563 terminx 574
    ud.config.setupread = 1;
112 terminx 575
 
466 terminx 576
    pathsearchmode = 1;
4440 terminx 577
#ifndef __ANDROID__
563 terminx 578
    if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0)  // JBF 20031211
579
        ud.config.scripthandle = SCRIPT_Load(setupfilename);
1178 terminx 580
    else if (SafeFileExists(SETUPFILENAME) && ud.config.scripthandle < 0)
581
    {
1740 helixhorne 582
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
583
                   "Import configuration data from \"%s\"?",setupfilename,SETUPFILENAME);
1178 terminx 584
        if (i) ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
585
    }
972 terminx 586
    else if (SafeFileExists("duke3d.cfg") && ud.config.scripthandle < 0)
587
    {
1740 helixhorne 588
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
589
                   "Import configuration data from \"duke3d.cfg\"?",setupfilename);
972 terminx 590
        if (i) ud.config.scripthandle = SCRIPT_Load("duke3d.cfg");
591
    }
4440 terminx 592
#endif
593
 
466 terminx 594
    pathsearchmode = 0;
5 Plagman 595
 
563 terminx 596
    if (ud.config.scripthandle < 0) return -1;
194 terminx 597
 
563 terminx 598
    if (ud.config.scripthandle >= 0)
5 Plagman 599
    {
1100 terminx 600
        char dummybuf[64];
601
 
1229 terminx 602
        for (dummy = 0; dummy < 10; dummy++)
5 Plagman 603
        {
604
            commmacro[13] = dummy+'0';
563 terminx 605
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
5 Plagman 606
        }
607
 
1910 helixhorne 608
        Bmemset(tempbuf, 0, sizeof(tempbuf));
609
//        Bmemset(dummybuf, 0, sizeof(dummybuf));
563 terminx 610
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
5 Plagman 611
 
1625 terminx 612
        while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10)
159 terminx 613
            tempbuf[Bstrlen(tempbuf)-1] = '\0';
135 terminx 614
 
2559 helixhorne 615
        Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
159 terminx 616
 
2420 hendricks2 617
        if (g_rtsNamePtr == NULL)
618
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
5 Plagman 619
 
1143 terminx 620
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ConfigVersion",&ud.configversion);
621
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ForceSetup",&ud.config.ForceSetup);
1325 terminx 622
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","NoAutoLoad",&ud.config.NoAutoLoad);
1143 terminx 623
 
1393 terminx 624
// #ifdef _WIN32
1587 terminx 625
        if (g_noSetup == 0 && g_modDir[0] == '/')
1187 terminx 626
        {
3168 helixhorne 627
            struct Bstat st;
1587 terminx 628
            SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
1187 terminx 629
 
1652 terminx 630
            if (Bstat(g_modDir, &st))
1187 terminx 631
            {
632
                if ((st.st_mode & S_IFDIR) != S_IFDIR)
633
                {
634
                    initprintf("Invalid mod dir in cfg!\n");
1587 terminx 635
                    Bsprintf(g_modDir,"/");
1187 terminx 636
                }
637
            }
638
        }
1393 terminx 639
// #endif
1143 terminx 640
 
3654 terminx 641
        if (g_grpNamePtr == NULL && g_usingAddon == 0)
3705 terminx 642
        {
3617 hendricks2 643
            SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr);
3705 terminx 644
            if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
645
                g_grpNamePtr = dup_filename(G_DefaultGrpFile());
646
        }
374 terminx 647
 
335 terminx 648
        if (!NAM)
649
        {
1143 terminx 650
            SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout);
563 terminx 651
            SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]);
245 terminx 652
        }
653
 
563 terminx 654
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight);
655
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode);
1143 terminx 656
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth);
5 Plagman 657
 
3655 terminx 658
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
659
        windowx = -1;
660
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
661
        windowy = -1;
662
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
663
 
4327 terminx 664
#ifdef RENDERTYPEWIN
3655 terminx 665
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
188 terminx 666
#endif
5 Plagman 667
 
1635 terminx 668
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP);
669
        if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32;
1143 terminx 670
 
1677 terminx 671
#ifdef POLYMER
1325 terminx 672
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy);
3784 terminx 673
        if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER;
674
        else glrendmode = REND_POLYMOST;
1660 terminx 675
#endif
163 terminx 676
 
1677 terminx 677
        /*
446 Plagman 678
 
1677 terminx 679
                    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color);
680
                    G_CheckPlayerColor((int32_t *)&ud.color,-1);
681
                    g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
682
                    tempbuf[0] = 0;
683
        */
1143 terminx 684
 
2375 helixhorne 685
        SCRIPT_GetString(ud.config.scripthandle, "Misc", "CrosshairColor",&tempbuf[0]);
686
        if (tempbuf[0])
687
        {
688
            char *ptr = strtok(tempbuf,",");
689
            palette_t temppal;
690
            char *palptr = (char *)&temppal;
691
 
692
            i = 0;
693
            while (ptr != NULL && i < 3)
694
            {
695
                palptr[i++] = Batoi(ptr);
696
                ptr = strtok(NULL,",");
697
            }
698
            if (i == 3)
699
            {
700
                Bmemcpy(&CrosshairColors,&temppal,sizeof(palette_t));
701
                DefaultCrosshairColors.f = 1;
702
            }
703
        }
704
 
1143 terminx 705
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions);
148 terminx 706
 
1143 terminx 707
        // weapon choices are defaulted in G_CheckCommandLine, which may override them
1587 terminx 708
        if (!g_forceWeaponChoice)
4215 helixhorne 709
            for (i=0; i<=FREEZE_WEAPON; i++)
5 Plagman 710
            {
584 terminx 711
                Bsprintf(buf,"WeaponChoice%d",i);
113 terminx 712
                dummy = -1;
563 terminx 713
                SCRIPT_GetNumber(ud.config.scripthandle, "Misc", buf, &dummy);
4215 helixhorne 714
                if (dummy >= 0 && dummy <= FREEZE_WEAPON)
715
                    g_player[0].wchoice[i] = dummy;
5 Plagman 716
            }
717
 
428 terminx 718
#ifdef _WIN32
563 terminx 719
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
720
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
416 terminx 721
#endif
942 terminx 722
 
5 Plagman 723
    }
724
 
563 terminx 725
    //CONFIG_SetupMouse(ud.config.scripthandle);
726
    //CONFIG_SetupJoystick(ud.config.scripthandle);
727
    ud.config.setupread = 1;
194 terminx 728
    return 0;
5 Plagman 729
}
730
 
731
/*
732
===================
733
=
734
= CONFIG_WriteSetup
735
=
736
===================
737
*/
738
 
1625 terminx 739
void CONFIG_WriteBinds(void) // save binds and aliases to <cfgname>_settings.cfg
813 terminx 740
{
1205 terminx 741
    int32_t i;
2725 hendricks2 742
    BFILE *fp;
972 terminx 743
    char *ptr = Bstrdup(setupfilename);
1029 terminx 744
    char tempbuf[128];
813 terminx 745
 
1625 terminx 746
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
747
        Bsprintf(tempbuf, "settings.cfg");
748
    else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, "."));
749
 
2725 hendricks2 750
    fp = Bfopen(tempbuf, "wt");
972 terminx 751
 
813 terminx 752
    if (fp)
753
    {
4344 hendricks2 754
        Bfprintf(fp,"// this file is automatically generated by EDuke32\n");
2725 hendricks2 755
        Bfprintf(fp,"// these settings take precedence over your main cfg file\n");
756
        Bfprintf(fp,"// do not modify if you lack common sense\n");
1358 terminx 757
 
2725 hendricks2 758
        Bfprintf(fp,"unbindall\n");
1632 terminx 759
 
1229 terminx 760
        for (i=0; i<MAXBOUNDKEYS; i++)
3209 helixhorne 761
            if (CONTROL_KeyIsBound(i))
3197 terminx 762
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key,
763
                CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr);
818 terminx 764
 
1229 terminx 765
        for (i=0; i<MAXMOUSEBUTTONS; i++)
3209 helixhorne 766
            if (CONTROL_MouseIsBound(i))
3197 terminx 767
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key,
768
                CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr);
826 terminx 769
 
4213 helixhorne 770
        OSD_WriteAliases(fp);
771
        OSD_WriteCvars(fp);
818 terminx 772
 
2725 hendricks2 773
        Bfclose(fp);
4213 helixhorne 774
 
1625 terminx 775
        if (!Bstrcmp(setupfilename, SETUPFILENAME))
1740 helixhorne 776
            OSD_Printf("Wrote settings.cfg\n");
777
        else OSD_Printf("Wrote %s_settings.cfg\n",ptr);
778
 
972 terminx 779
        Bfree(ptr);
845 terminx 780
        return;
813 terminx 781
    }
1625 terminx 782
 
783
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
1740 helixhorne 784
        OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno));
785
    else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno));
1625 terminx 786
 
972 terminx 787
    Bfree(ptr);
813 terminx 788
}
789
 
1820 terminx 790
void CONFIG_WriteSetup(uint32_t flags)
5 Plagman 791
{
1346 terminx 792
    int32_t dummy;
1029 terminx 793
    char tempbuf[1024];
5 Plagman 794
 
563 terminx 795
    if (!ud.config.setupread) return;
112 terminx 796
 
563 terminx 797
    if (ud.config.scripthandle < 0)
798
        ud.config.scripthandle = SCRIPT_Init(setupfilename);
5 Plagman 799
 
1346 terminx 800
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",++ud.executions,FALSE,FALSE);
150 terminx 801
 
1346 terminx 802
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup","ConfigVersion",BYTEVERSION_JF,FALSE,FALSE);
803
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup",ud.config.ForceSetup,FALSE,FALSE);
804
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad",ud.config.NoAutoLoad,FALSE,FALSE);
1143 terminx 805
 
1660 terminx 806
#ifdef POLYMER
3784 terminx 807
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer",glrendmode == REND_POLYMER,FALSE,FALSE);
1660 terminx 808
#endif
1143 terminx 809
 
1346 terminx 810
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,FALSE,FALSE);  // JBF 20040523
811
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,FALSE,FALSE);    // JBF 20031206
812
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,FALSE,FALSE);    // JBF 20031206
813
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,FALSE,FALSE);  // JBF 20031206
1143 terminx 814
 
3707 terminx 815
    if (g_grpNamePtr && !g_usingAddon)
3624 helixhorne 816
        SCRIPT_PutString(ud.config.scripthandle, "Setup","SelectedGRP",g_grpNamePtr);
1820 terminx 817
 
2962 helixhorne 818
    // XXX: should be "if compiled without startup GUI"
819
#if !defined __linux || defined HAVE_GTK2
1820 terminx 820
    if (g_noSetup == 0)
821
        SCRIPT_PutString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
2962 helixhorne 822
#endif
1820 terminx 823
    // exit early after only updating the values that can be changed from the startup window
824
    if (flags & 1)
825
    {
826
        SCRIPT_Save(ud.config.scripthandle, setupfilename);
827
        SCRIPT_Free(ud.config.scripthandle);
828
        OSD_Printf("Updated %s\n",setupfilename);
829
 
830
        return;
831
    }
832
 
1346 terminx 833
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
834
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
835
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
4327 terminx 836
#ifdef RENDERTYPEWIN
3655 terminx 837
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
1143 terminx 838
#endif
839
 
1820 terminx 840
    for (dummy=0; dummy<10; dummy++)
841
    {
842
        Bsprintf(buf,"WeaponChoice%d",dummy);
843
        SCRIPT_PutNumber(ud.config.scripthandle, "Misc",buf,g_player[myconnectindex].wchoice[dummy],FALSE,FALSE);
844
    }
5 Plagman 845
 
1820 terminx 846
    if (!NAM)
847
    {
848
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
849
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
850
    }
851
 
416 terminx 852
#ifdef _WIN32
1346 terminx 853
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
854
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
416 terminx 855
#endif
856
 
1229 terminx 857
    for (dummy=0; dummy<MAXMOUSEBUTTONS; dummy++)
335 terminx 858
    {
1625 terminx 859
        if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]))
860
        {
861
            Bsprintf(buf,"MouseButton%d",dummy);
862
            SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]));
863
        }
5 Plagman 864
 
865
        if (dummy >= (MAXMOUSEBUTTONS-2)) continue;
866
 
1625 terminx 867
        if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]))
868
        {
869
            Bsprintf(buf,"MouseButtonClicked%d",dummy);
870
            SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]));
871
        }
5 Plagman 872
    }
606 terminx 873
 
1229 terminx 874
    for (dummy=0; dummy<MAXMOUSEAXES; dummy++)
335 terminx 875
    {
1625 terminx 876
        if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]))
877
        {
878
            Bsprintf(buf,"MouseAnalogAxes%d",dummy);
879
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]));
880
        }
5 Plagman 881
 
1625 terminx 882
        if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]))
883
        {
884
            Bsprintf(buf,"MouseDigitalAxes%d_0",dummy);
885
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]));
886
        }
5 Plagman 887
 
1625 terminx 888
        if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]))
889
        {
890
            Bsprintf(buf,"MouseDigitalAxes%d_1",dummy);
891
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]));
892
        }
5 Plagman 893
 
2728 hendricks2 894
        if (ud.config.MouseAnalogueScale[dummy] != DEFAULTMOUSEANALOGUESCALE)
1625 terminx 895
        {
896
            Bsprintf(buf,"MouseAnalogScale%d",dummy);
897
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[dummy], FALSE, FALSE);
898
        }
5 Plagman 899
    }
900
 
1355 terminx 901
    Bsprintf(tempbuf,"%.2f",CONTROL_MouseSensitivity);
902
    SCRIPT_PutString(ud.config.scripthandle,  "Controls","Mouse_Sensitivity",tempbuf);
903
 
1229 terminx 904
    for (dummy=0; dummy<MAXJOYBUTTONS; dummy++)
335 terminx 905
    {
1625 terminx 906
        if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
907
        {
908
            Bsprintf(buf,"JoystickButton%d",dummy);
909
            SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
910
        }
5 Plagman 911
 
1625 terminx 912
        if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
913
        {
914
            Bsprintf(buf,"JoystickButtonClicked%d",dummy);
915
            SCRIPT_PutString(ud.config.scripthandle,"Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
916
        }
5 Plagman 917
    }
1229 terminx 918
    for (dummy=0; dummy<MAXJOYAXES; dummy++)
335 terminx 919
    {
1625 terminx 920
        if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
921
        {
922
            Bsprintf(buf,"JoystickAnalogAxes%d",dummy);
923
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
924
        }
5 Plagman 925
 
1625 terminx 926
        if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
927
        {
928
            Bsprintf(buf,"JoystickDigitalAxes%d_0",dummy);
929
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
930
        }
5 Plagman 931
 
1625 terminx 932
        if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
933
        {
934
            Bsprintf(buf,"JoystickDigitalAxes%d_1",dummy);
935
            SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
936
        }
5 Plagman 937
 
2728 hendricks2 938
        if (ud.config.JoystickAnalogueScale[dummy] != DEFAULTJOYSTICKANALOGUESCALE)
1625 terminx 939
        {
940
            Bsprintf(buf,"JoystickAnalogScale%d",dummy);
941
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
942
        }
5 Plagman 943
 
2728 hendricks2 944
        if (ud.config.JoystickAnalogueDead[dummy] != DEFAULTJOYSTICKANALOGUEDEAD)
1625 terminx 945
        {
946
            Bsprintf(buf,"JoystickAnalogDead%d",dummy);
947
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
948
        }
5 Plagman 949
 
2728 hendricks2 950
        if (ud.config.JoystickAnalogueSaturate[dummy] != DEFAULTJOYSTICKANALOGUESATURATE)
1625 terminx 951
        {
952
            Bsprintf(buf,"JoystickAnalogSaturate%d",dummy);
953
            SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
954
        }
5 Plagman 955
    }
956
 
1143 terminx 957
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
2420 hendricks2 958
    if (g_rtsNamePtr == NULL)
959
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
495 terminx 960
 
88 terminx 961
    {
962
        char commmacro[] = "CommbatMacro# ";
963
 
1229 terminx 964
        for (dummy = 0; dummy < 10; dummy++)
88 terminx 965
        {
966
            commmacro[13] = dummy+'0';
563 terminx 967
            SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
88 terminx 968
        }
969
    }
970
 
563 terminx 971
    SCRIPT_Save(ud.config.scripthandle, setupfilename);
3636 terminx 972
 
973
    if ((flags & 2) == 0)
974
        SCRIPT_Free(ud.config.scripthandle);
975
 
845 terminx 976
    OSD_Printf("Wrote %s\n",setupfilename);
977
    CONFIG_WriteBinds();
2725 hendricks2 978
    Bfflush(NULL);
5 Plagman 979
}
980
 
981
 
1346 terminx 982
int32_t CONFIG_GetMapBestTime(char *mapname)
322 terminx 983
{
1346 terminx 984
    int32_t t = -1;
322 terminx 985
    char m[BMAX_PATH], *p;
986
 
987
    strcpy(m, mapname);
988
    p = strrchr(m, '/');
989
    if (!p) p = strrchr(m, '\\');
1657 terminx 990
    if (p) Bmemmove(m, p, Bstrlen(p)+1);//strcpy(m, p);
1229 terminx 991
    for (p=m; *p; p++) *p = tolower(*p);
322 terminx 992
 
1076 terminx 993
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
994
    p = m;
995
    while (*p == '/') p++;
996
 
563 terminx 997
    if (!ud.config.setupread) return -1;
998
    if (ud.config.scripthandle < 0) return -1;
322 terminx 999
 
1076 terminx 1000
    SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
322 terminx 1001
    return t;
1002
}
1003
 
1346 terminx 1004
int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm)
322 terminx 1005
{
1006
    char m[BMAX_PATH], *p;
1007
 
1008
    strcpy(m, mapname);
1009
    p = strrchr(m, '/');
1010
    if (!p) p = strrchr(m, '\\');
1011
    if (p) strcpy(m, p);
1229 terminx 1012
    for (p=m; *p; p++) *p = tolower(*p);
322 terminx 1013
 
1076 terminx 1014
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1015
    p = m;
1016
    while (*p == '/') p++;
1017
 
563 terminx 1018
    if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename);
1019
    if (ud.config.scripthandle < 0) return -1;
322 terminx 1020
 
1346 terminx 1021
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE);
322 terminx 1022
    return 0;
1023
}
1024
 
5 Plagman 1025
/*
1026
 * vim:ts=4:sw=4:
1027
 */
1028