Subversion Repositories eduke32

Rev

Rev 5065 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5065 Rev 5070
1
//-------------------------------------------------------------------------
1
//-------------------------------------------------------------------------
2
/*
2
/*
3
Copyright (C) 2010 EDuke32 developers and contributors
3
Copyright (C) 2010 EDuke32 developers and contributors
4

4

5
This file is part of EDuke32.
5
This file is part of EDuke32.
6

6

7
EDuke32 is free software; you can redistribute it and/or
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
8
modify it under the terms of the GNU General Public License version 2
9
as published by the Free Software Foundation.
9
as published by the Free Software Foundation.
10

10

11
This program is distributed in the hope that it will be useful,
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14

14

15
See the GNU General Public License for more details.
15
See the GNU General Public License for more details.
16

16

17
You should have received a copy of the GNU General Public License
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
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
*/
20
*/
21
//-------------------------------------------------------------------------
21
//-------------------------------------------------------------------------
22
22
23
/*
23
/*
24
#include <stdio.h>
24
#include <stdio.h>
25
#include <string.h>
25
#include <string.h>
26
#include <stdlib.h>
26
#include <stdlib.h>
27
#include <ctype.h>
27
#include <ctype.h>
28
#include <time.h>
28
#include <time.h>
29
*/
29
*/
30
30
31
#include "baselayer.h"
31
#include "baselayer.h"
32
#include "duke3d.h"
32
#include "duke3d.h"
33
#include "game.h"
33
#include "game.h"
34
#include "common_game.h"
34
#include "common_game.h"
35
#include "scriplib.h"
35
#include "scriplib.h"
36
#include "osd.h"
36
#include "osd.h"
37
#include "osdcmds.h"
37
#include "osdcmds.h"
38
#include "osdfuncs.h"
38
#include "osdfuncs.h"
39
#ifdef _WIN32
39
#ifdef _WIN32
40
#include "winlayer.h"
40
#include "winlayer.h"
41
#endif
41
#endif
42
42
43
#ifdef __ANDROID__
43
#ifdef __ANDROID__
44
#include "android.h"
44
#include "android.h"
45
#endif
45
#endif
46
46
47
// we load this in to get default button and key assignments
47
// we load this in to get default button and key assignments
48
// as well as setting up function mappings
48
// as well as setting up function mappings
49
49
50
#define __SETUP__   // JBF 20031211
50
#define __SETUP__   // JBF 20031211
51
#include "_functio.h"
51
#include "_functio.h"
52
52
53
/*
53
/*
54
===================
54
===================
55
=
55
=
56
= CONFIG_FunctionNameToNum
56
= CONFIG_FunctionNameToNum
57
=
57
=
58
===================
58
===================
59
*/
59
*/
60
60
61
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
61
hashtable_t h_gamefuncs    = { NUMGAMEFUNCTIONS<<1, NULL };
62
62
63
int32_t CONFIG_FunctionNameToNum(const char *func)
63
int32_t CONFIG_FunctionNameToNum(const char *func)
64
{
64
{
65
    int32_t i;
65
    int32_t i;
66
66
67
    if (!func)
67
    if (!func)
68
        return -1;
68
        return -1;
69
69
70
    i = hash_find(&h_gamefuncs,func);
70
    i = hash_find(&h_gamefuncs,func);
71
71
72
    if (i < 0)
72
    if (i < 0)
73
    {
73
    {
74
        char *str = Bstrtolower(Xstrdup(func));
74
        char *str = Bstrtolower(Xstrdup(func));
75
        i = hash_find(&h_gamefuncs,str);
75
        i = hash_find(&h_gamefuncs,str);
76
        Bfree(str);
76
        Bfree(str);
77
77
78
        return i;
78
        return i;
79
    }
79
    }
80
80
81
    return i;
81
    return i;
82
}
82
}
83
83
84
/*
84
/*
85
===================
85
===================
86
=
86
=
87
= CONFIG_FunctionNumToName
87
= CONFIG_FunctionNumToName
88
=
88
=
89
===================
89
===================
90
*/
90
*/
91
91
92
char *CONFIG_FunctionNumToName(int32_t func)
92
char *CONFIG_FunctionNumToName(int32_t func)
93
{
93
{
94
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
94
    if ((unsigned)func >= (unsigned)NUMGAMEFUNCTIONS)
95
        return NULL;
95
        return NULL;
96
    return gamefunctions[func];
96
    return gamefunctions[func];
97
}
97
}
98
98
99
/*
99
/*
100
===================
100
===================
101
=
101
=
102
= CONFIG_AnalogNameToNum
102
= CONFIG_AnalogNameToNum
103
=
103
=
104
===================
104
===================
105
*/
105
*/
106
106
107
107
108
int32_t CONFIG_AnalogNameToNum(const char *func)
108
int32_t CONFIG_AnalogNameToNum(const char *func)
109
{
109
{
110
    if (!func)
110
    if (!func)
111
        return -1;
111
        return -1;
112
112
113
    if (!Bstrcasecmp(func,"analog_turning"))
113
    if (!Bstrcasecmp(func,"analog_turning"))
114
    {
114
    {
115
        return analog_turning;
115
        return analog_turning;
116
    }
116
    }
117
    if (!Bstrcasecmp(func,"analog_strafing"))
117
    if (!Bstrcasecmp(func,"analog_strafing"))
118
    {
118
    {
119
        return analog_strafing;
119
        return analog_strafing;
120
    }
120
    }
121
    if (!Bstrcasecmp(func,"analog_moving"))
121
    if (!Bstrcasecmp(func,"analog_moving"))
122
    {
122
    {
123
        return analog_moving;
123
        return analog_moving;
124
    }
124
    }
125
    if (!Bstrcasecmp(func,"analog_lookingupanddown"))
125
    if (!Bstrcasecmp(func,"analog_lookingupanddown"))
126
    {
126
    {
127
        return analog_lookingupanddown;
127
        return analog_lookingupanddown;
128
    }
128
    }
129
129
130
    return -1;
130
    return -1;
131
}
131
}
132
132
133
133
134
const char *CONFIG_AnalogNumToName(int32_t func)
134
const char *CONFIG_AnalogNumToName(int32_t func)
135
{
135
{
136
    switch (func)
136
    switch (func)
137
    {
137
    {
138
    case analog_turning:
138
    case analog_turning:
139
        return "analog_turning";
139
        return "analog_turning";
140
    case analog_strafing:
140
    case analog_strafing:
141
        return "analog_strafing";
141
        return "analog_strafing";
142
    case analog_moving:
142
    case analog_moving:
143
        return "analog_moving";
143
        return "analog_moving";
144
    case analog_lookingupanddown:
144
    case analog_lookingupanddown:
145
        return "analog_lookingupanddown";
145
        return "analog_lookingupanddown";
146
    }
146
    }
147
147
148
    return NULL;
148
    return NULL;
149
}
149
}
150
150
151
151
152
/*
152
/*
153
===================
153
===================
154
=
154
=
155
= CONFIG_SetDefaults
155
= CONFIG_SetDefaults
156
=
156
=
157
===================
157
===================
158
*/
158
*/
159
159
160
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN])
160
void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN])
161
{
161
{
162
    int32_t i,f;
162
    int32_t i,f;
163
163
164
    Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
164
    Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
165
165
166
    CONTROL_ClearAllBinds();
166
    CONTROL_ClearAllBinds();
167
167
168
    for (i=0; i < (int32_t)ARRAY_SIZE(keydefaults); i+=3)
168
    for (i=0; i < (int32_t)ARRAY_SIZE(keydefaults); i+=3)
169
    {
169
    {
170
        f = CONFIG_FunctionNameToNum(keyptr[i+0]);
170
        f = CONFIG_FunctionNameToNum(keyptr[i+0]);
171
        if (f == -1) continue;
171
        if (f == -1) continue;
172
        ud.config.KeyboardKeys[f][0] = KB_StringToScanCode(keyptr[i+1]);
172
        ud.config.KeyboardKeys[f][0] = KB_StringToScanCode(keyptr[i+1]);
173
        ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keyptr[i+2]);
173
        ud.config.KeyboardKeys[f][1] = KB_StringToScanCode(keyptr[i+2]);
174
174
175
        if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
175
        if (f == gamefunc_Show_Console) OSD_CaptureKey(ud.config.KeyboardKeys[f][0]);
176
        else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
176
        else CONFIG_MapKey(f, ud.config.KeyboardKeys[f][0], 0, ud.config.KeyboardKeys[f][1], 0);
177
    }
177
    }
178
}
178
}
179
179
180
void CONFIG_SetDefaults(void)
180
void CONFIG_SetDefaults(void)
181
{
181
{
182
    // JBF 20031211
182
    // JBF 20031211
183
    int32_t i;
183
    int32_t i;
184
184
185
    ud.config.scripthandle = -1;
185
    ud.config.scripthandle = -1;
186
#ifdef __ANDROID__
186
#ifdef __ANDROID__
187
    droidinput.forward_sens = 5.f;
187
    droidinput.forward_sens = 5.f;
188
    droidinput.strafe_sens = 5.f;
188
    droidinput.strafe_sens = 5.f;
189
    droidinput.pitch_sens = 5.f;
189
    droidinput.pitch_sens = 5.f;
190
    droidinput.yaw_sens = 5.f;
190
    droidinput.yaw_sens = 5.f;
191
    droidinput.hideStick = 0;
191
    droidinput.hideStick = 0;
192
    droidinput.gameControlsAlpha = 0.5;
192
    droidinput.gameControlsAlpha = 0.5;
193
    droidinput.toggleCrouch = 1;
193
    droidinput.toggleCrouch = 1;
194
    droidinput.quickSelectWeapon = 1;
194
    droidinput.quickSelectWeapon = 1;
195
195
196
    ud.config.ScreenWidth = droidinfo.screen_width;
196
    ud.config.ScreenWidth = droidinfo.screen_width;
197
    ud.config.ScreenHeight = droidinfo.screen_height;
197
    ud.config.ScreenHeight = droidinfo.screen_height;
198
#else
198
#else
199
    ud.config.ScreenWidth = 1024;
199
    ud.config.ScreenWidth = 1024;
200
    ud.config.ScreenHeight = 768;
200
    ud.config.ScreenHeight = 768;
201
#endif
201
#endif
202
202
203
    ud.config.ScreenMode = 0;
203
    ud.config.ScreenMode = 0;
204
204
205
#ifdef USE_OPENGL
205
#ifdef USE_OPENGL
206
    ud.config.ScreenBPP = 32;
206
    ud.config.ScreenBPP = 32;
207
#else
207
#else
208
    ud.config.ScreenBPP = 8;
208
    ud.config.ScreenBPP = 8;
209
#endif
209
#endif
210
    ud.config.useprecache = 1;
210
    ud.config.useprecache = 1;
211
    ud.config.ForceSetup = 1;
211
    ud.config.ForceSetup = 1;
212
    ud.config.NoAutoLoad = 1;
212
    ud.config.NoAutoLoad = 1;
213
    ud.config.AmbienceToggle = 1;
213
    ud.config.AmbienceToggle = 1;
214
    ud.config.AutoAim = 1;
214
    ud.config.AutoAim = 1;
215
    ud.config.MasterVolume = 255;
215
    ud.config.MasterVolume = 255;
216
    ud.config.FXVolume = 225;
216
    ud.config.FXVolume = 225;
217
#if defined(_WIN32)
217
#if defined(_WIN32)
218
    ud.config.MixRate = 44100;
218
    ud.config.MixRate = 44100;
219
#elif defined __ANDROID__
219
#elif defined __ANDROID__
220
    ud.config.MixRate = droidinfo.audio_sample_rate;
220
    ud.config.MixRate = droidinfo.audio_sample_rate;
221
#else
221
#else
222
    ud.config.MixRate = 48000;
222
    ud.config.MixRate = 48000;
223
#endif
223
#endif
224
    ud.config.MouseBias = 0;
224
    ud.config.MouseBias = 0;
225
    ud.config.MouseDeadZone = 0;
225
    ud.config.MouseDeadZone = 0;
226
    ud.config.MusicToggle = 1;
226
    ud.config.MusicToggle = 1;
227
    ud.config.MusicVolume = 195;
227
    ud.config.MusicVolume = 195;
228
    g_myAimMode = g_player[0].ps->aim_mode = 1;
228
    g_myAimMode = g_player[0].ps->aim_mode = 1;
229
    ud.config.NumBits = 16;
229
    ud.config.NumBits = 16;
230
    ud.config.NumChannels = 2;
230
    ud.config.NumChannels = 2;
231
    ud.config.NumVoices = 32;
231
    ud.config.NumVoices = 32;
232
    ud.config.ReverseStereo = 0;
232
    ud.config.ReverseStereo = 0;
233
    ud.auto_run = 1;
233
    ud.auto_run = 1;
234
    ud.config.ShowOpponentWeapons = 0;
234
    ud.config.ShowOpponentWeapons = 0;
235
    ud.config.SmoothInput = 1;
235
    ud.config.SmoothInput = 1;
236
    ud.config.SoundToggle = 1;
236
    ud.config.SoundToggle = 1;
237
    ud.althud = 1;
237
    ud.althud = 1;
238
    ud.automsg = 0;
238
    ud.automsg = 0;
239
    ud.autovote = 0;
239
    ud.autovote = 0;
240
    ud.brightness = 8;
240
    ud.brightness = 8;
241
    ud.camerasprite = -1;
241
    ud.camerasprite = -1;
242
242
243
#if defined GEKKO || defined __OPENDINGUX__
243
#if defined GEKKO || defined __OPENDINGUX__
244
    ud.camera_time = 11;
244
    ud.camera_time = 11;
245
#elif defined(__ANDROID__)
245
#elif defined(__ANDROID__)
246
    ud.camera_time = 7;
246
    ud.camera_time = 7;
247
#else
247
#else
248
    ud.camera_time = 4;
248
    ud.camera_time = 4;
249
#endif
249
#endif
250
250
251
    ud.color = 0;
251
    ud.color = 0;
252
    ud.crosshair = 1;
252
    ud.crosshair = 1;
253
    ud.crosshairscale = 50;
253
    ud.crosshairscale = 50;
254
    ud.obituaries = 1;
254
    ud.obituaries = 1;
255
    ud.democams = 1;
255
    ud.democams = 1;
256
    ud.detail = 1;
256
    ud.detail = 1;
257
    ud.drawweapon = 1;
257
    ud.drawweapon = 1;
258
    ud.idplayers = 1;
258
    ud.idplayers = 1;
259
    ud.levelstats = 0;
259
    ud.levelstats = 0;
260
    ud.lockout = 0;
260
    ud.lockout = 0;
261
    ud.m_ffire = 1;
261
    ud.m_ffire = 1;
262
    ud.m_marker = 1;
262
    ud.m_marker = 1;
263
    ud.mouseaiming = 0;
263
    ud.mouseaiming = 0;
264
    ud.mouseflip = 1;
264
    ud.mouseflip = 1;
265
    ud.msgdisptime = 120;
265
    ud.msgdisptime = 120;
266
    ud.pwlockout[0] = '\0';
266
    ud.pwlockout[0] = '\0';
267
    ud.runkey_mode = 0;
267
    ud.runkey_mode = 0;
268
    ud.screen_size = 4;
268
    ud.screen_size = 4;
269
    ud.screen_tilting = 1;
269
    ud.screen_tilting = 1;
270
    ud.shadows = 1;
270
    ud.shadows = 1;
271
    ud.statusbarmode = 1;
271
    ud.statusbarmode = 1;
272
    ud.statusbarscale = 100;
272
    ud.statusbarscale = 100;
273
    ud.team = 0;
273
    ud.team = 0;
274
    ud.viewbob = 1;
274
    ud.viewbob = 1;
275
    ud.weaponsway = 1;
275
    ud.weaponsway = 1;
276
    ud.weaponswitch = 3;        // new+empty
276
    ud.weaponswitch = 3;        // new+empty
277
    ud.angleinterpolation = 0;
277
    ud.angleinterpolation = 0;
278
#ifdef GEKKO
278
#ifdef GEKKO
279
    ud.config.UseJoystick = 1;
279
    ud.config.UseJoystick = 1;
280
#else
280
#else
281
    ud.config.UseJoystick = 0;
281
    ud.config.UseJoystick = 0;
282
#endif
282
#endif
283
    ud.config.UseMouse = 1;
283
    ud.config.UseMouse = 1;
284
    ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
284
    ud.config.VoiceToggle = 5; // bitfield, 1 = local, 2 = dummy, 4 = other players in DM
285
    ud.display_bonus_screen = 1;
285
    ud.display_bonus_screen = 1;
286
    ud.show_level_text = 1;
286
    ud.show_level_text = 1;
287
    ud.configversion = 0;
287
    ud.configversion = 0;
288
    ud.weaponscale = 100;
288
    ud.weaponscale = 100;
289
    ud.textscale = 100;
289
    ud.textscale = 100;
290
290
291
    ud.config.CheckForUpdates = 1;
291
    ud.config.CheckForUpdates = 1;
292
292
293
    if (g_rtsNamePtr == NULL)
293
    if (g_rtsNamePtr == NULL)
294
        Bstrcpy(ud.rtsname, G_DefaultRtsFile());
294
        Bstrcpy(ud.rtsname, G_DefaultRtsFile());
295
    Bstrcpy(szPlayerName, "Duke");
295
    Bstrcpy(szPlayerName, "Duke");
296
296
297
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
297
    Bstrcpy(ud.ridecule[0], "An inspiration for birth control.");
298
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
298
    Bstrcpy(ud.ridecule[1], "You're gonna die for that!");
299
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
299
    Bstrcpy(ud.ridecule[2], "It hurts to be you.");
300
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
300
    Bstrcpy(ud.ridecule[3], "Lucky son of a bitch.");
301
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
301
    Bstrcpy(ud.ridecule[4], "Hmmm... payback time.");
302
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
302
    Bstrcpy(ud.ridecule[5], "You bottom dwelling scum sucker.");
303
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
303
    Bstrcpy(ud.ridecule[6], "Damn, you're ugly.");
304
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
304
    Bstrcpy(ud.ridecule[7], "Ha ha ha... wasted!");
305
    Bstrcpy(ud.ridecule[8], "You suck!");
305
    Bstrcpy(ud.ridecule[8], "You suck!");
306
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
306
    Bstrcpy(ud.ridecule[9], "AARRRGHHHHH!!!");
307
307
308
    // JBF 20031211
308
    // JBF 20031211
309
309
310
    CONFIG_SetDefaultKeys((const char (*)[MAXGAMEFUNCLEN])keydefaults);
310
    CONFIG_SetDefaultKeys((const char (*)[MAXGAMEFUNCLEN])keydefaults);
311
311
312
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
312
    memset(ud.config.MouseFunctions, -1, sizeof(ud.config.MouseFunctions));
313
    for (i=0; i<MAXMOUSEBUTTONS; i++)
313
    for (i=0; i<MAXMOUSEBUTTONS; i++)
314
    {
314
    {
315
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
315
        ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(mousedefaults[i]);
316
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
316
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
317
        if (i>=4) continue;
317
        if (i>=4) continue;
318
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
318
        ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(mouseclickeddefaults[i]);
319
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
319
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1, controldevice_mouse);
320
    }
320
    }
321
321
322
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
322
    memset(ud.config.MouseDigitalFunctions, -1, sizeof(ud.config.MouseDigitalFunctions));
323
    for (i=0; i<MAXMOUSEAXES; i++)
323
    for (i=0; i<MAXMOUSEAXES; i++)
324
    {
324
    {
325
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
325
        ud.config.MouseAnalogueScale[i] = DEFAULTMOUSEANALOGUESCALE;
326
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
326
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
327
327
328
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
328
        ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2]);
329
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
329
        ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(mousedigitaldefaults[i*2+1]);
330
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
330
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0, controldevice_mouse);
331
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
331
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1, controldevice_mouse);
332
332
333
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
333
        ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(mouseanalogdefaults[i]);
334
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
334
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
335
    }
335
    }
336
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
336
    CONTROL_MouseSensitivity = DEFAULTMOUSESENSITIVITY;
337
337
338
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
338
    memset(ud.config.JoystickFunctions, -1, sizeof(ud.config.JoystickFunctions));
339
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
339
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
340
    {
340
    {
341
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
341
        ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdefaults[i]);
342
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
342
        ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(joystickclickeddefaults[i]);
343
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
343
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
344
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
344
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1, controldevice_joystick);
345
    }
345
    }
346
346
347
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
347
    memset(ud.config.JoystickDigitalFunctions, -1, sizeof(ud.config.JoystickDigitalFunctions));
348
    for (i=0; i<MAXJOYAXES; i++)
348
    for (i=0; i<MAXJOYAXES; i++)
349
    {
349
    {
350
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
350
        ud.config.JoystickAnalogueScale[i] = DEFAULTJOYSTICKANALOGUESCALE;
351
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
351
        ud.config.JoystickAnalogueDead[i] = DEFAULTJOYSTICKANALOGUEDEAD;
352
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
352
        ud.config.JoystickAnalogueSaturate[i] = DEFAULTJOYSTICKANALOGUESATURATE;
353
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
353
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
354
354
355
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
355
        ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2]);
356
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
356
        ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(joystickdigitaldefaults[i*2+1]);
357
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
357
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
358
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
358
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
359
359
360
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
360
        ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(joystickanalogdefaults[i]);
361
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
361
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
362
    }
362
    }
363
}
363
}
364
364
365
365
366
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
366
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
367
void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
367
void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
368
{
368
{
369
    int32_t i, j, k;
369
    int32_t i, j, k;
370
    int32_t ii[] = { key1, key2, oldkey1, oldkey2 };
370
    int32_t ii[] = { key1, key2, oldkey1, oldkey2 };
371
    char buf[2*MAXGAMEFUNCLEN];
371
    char buf[2*MAXGAMEFUNCLEN];
372
372
373
    UNREFERENCED_PARAMETER(which);
373
    UNREFERENCED_PARAMETER(which);
374
//    CONTROL_MapKey(which, key1, key2);
374
//    CONTROL_MapKey(which, key1, key2);
375
375
376
    if (which == gamefunc_Show_Console)
376
    if (which == gamefunc_Show_Console)
377
        OSD_CaptureKey(key1);
377
        OSD_CaptureKey(key1);
378
378
379
    for (k = 0; (unsigned)k < ARRAY_SIZE(ii); k++)
379
    for (k = 0; (unsigned)k < ARRAY_SIZE(ii); k++)
380
    {
380
    {
381
        if (ii[k] == 0xff || !ii[k])
381
        if (ii[k] == 0xff || !ii[k])
382
            continue;
382
            continue;
383
383
384
        for (j=0; ConsoleKeys[j].name; j++)
384
        for (j=0; ConsoleKeys[j].name; j++)
385
            if (ii[k] == ConsoleKeys[j].id)
385
            if (ii[k] == ConsoleKeys[j].id)
386
                break;
386
                break;
387
387
388
        tempbuf[0] = 0;
388
        tempbuf[0] = 0;
389
389
390
        for (i=NUMGAMEFUNCTIONS-1; i>=0; i--)
390
        for (i=NUMGAMEFUNCTIONS-1; i>=0; i--)
391
        {
391
        {
392
            if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
392
            if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
393
            {
393
            {
394
                Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
394
                Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
395
                Bstrcat(tempbuf,buf);
395
                Bstrcat(tempbuf,buf);
396
            }
396
            }
397
        }
397
        }
398
398
399
        i = Bstrlen(tempbuf);
399
        i = Bstrlen(tempbuf);
400
        if (i >= 2)
400
        if (i >= 2)
401
        {
401
        {
402
            tempbuf[i-2] = 0;  // cut off the trailing "; "
402
            tempbuf[i-2] = 0;  // cut off the trailing "; "
403
            CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : "<?>");
403
            CONTROL_BindKey(ii[k], tempbuf, 1, ConsoleKeys[j].name ? ConsoleKeys[j].name : "<?>");
404
        }
404
        }
405
        else
405
        else
406
        {
406
        {
407
            CONTROL_FreeKeyBind(ii[k]);
407
            CONTROL_FreeKeyBind(ii[k]);
408
        }
408
        }
409
    }
409
    }
410
}
410
}
411
411
412
/*
412
/*
413
===================
413
===================
414
=
414
=
415
= CONFIG_SetupMouse
415
= CONFIG_SetupMouse
416
=
416
=
417
===================
417
===================
418
*/
418
*/
419
419
420
void CONFIG_SetupMouse(void)
420
void CONFIG_SetupMouse(void)
421
{
421
{
422
    int32_t i;
422
    int32_t i;
423
    char str[80];
423
    char str[80];
424
    char temp[80];
424
    char temp[80];
425
    int32_t scale;
425
    int32_t scale;
426
426
427
    if (ud.config.scripthandle < 0) return;
427
    if (ud.config.scripthandle < 0) return;
428
428
429
    for (i=0; i<MAXMOUSEBUTTONS; i++)
429
    for (i=0; i<MAXMOUSEBUTTONS; i++)
430
    {
430
    {
431
        Bsprintf(str,"MouseButton%d",i);
431
        Bsprintf(str,"MouseButton%d",i);
432
        temp[0] = 0;
432
        temp[0] = 0;
433
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
433
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
434
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
434
            ud.config.MouseFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
435
435
436
        Bsprintf(str,"MouseButtonClicked%d",i);
436
        Bsprintf(str,"MouseButtonClicked%d",i);
437
        temp[0] = 0;
437
        temp[0] = 0;
438
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
438
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
439
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
439
            ud.config.MouseFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
440
    }
440
    }
441
441
442
    // map over the axes
442
    // map over the axes
443
    for (i=0; i<MAXMOUSEAXES; i++)
443
    for (i=0; i<MAXMOUSEAXES; i++)
444
    {
444
    {
445
        Bsprintf(str,"MouseAnalogAxes%d",i);
445
        Bsprintf(str,"MouseAnalogAxes%d",i);
446
        temp[0] = 0;
446
        temp[0] = 0;
447
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
447
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
448
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
448
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
449
                ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
449
                ud.config.MouseAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
450
450
451
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
451
        Bsprintf(str,"MouseDigitalAxes%d_0",i);
452
        temp[0] = 0;
452
        temp[0] = 0;
453
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
453
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
454
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
454
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
455
                ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
455
                ud.config.MouseDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
456
456
457
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
457
        Bsprintf(str,"MouseDigitalAxes%d_1",i);
458
        temp[0] = 0;
458
        temp[0] = 0;
459
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
459
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
460
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
460
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
461
                ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
461
                ud.config.MouseDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
462
462
463
        Bsprintf(str,"MouseAnalogScale%d",i);
463
        Bsprintf(str,"MouseAnalogScale%d",i);
464
        scale = ud.config.MouseAnalogueScale[i];
464
        scale = ud.config.MouseAnalogueScale[i];
465
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
465
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
466
        ud.config.MouseAnalogueScale[i] = scale;
466
        ud.config.MouseAnalogueScale[i] = scale;
467
    }
467
    }
468
468
469
    {
469
    {
470
        tempbuf[0] = 0;
470
        tempbuf[0] = 0;
471
        SCRIPT_GetString(ud.config.scripthandle, "Controls","Mouse_Sensitivity",&tempbuf[0]);
471
        SCRIPT_GetString(ud.config.scripthandle, "Controls","Mouse_Sensitivity",&tempbuf[0]);
472
        if (tempbuf[0]) CONTROL_MouseSensitivity = atof(tempbuf);
472
        if (tempbuf[0]) CONTROL_MouseSensitivity = atof(tempbuf);
473
    }
473
    }
474
474
475
    for (i=0; i<MAXMOUSEBUTTONS; i++)
475
    for (i=0; i<MAXMOUSEBUTTONS; i++)
476
    {
476
    {
477
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
477
        CONTROL_MapButton(ud.config.MouseFunctions[i][0], i, 0, controldevice_mouse);
478
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
478
        CONTROL_MapButton(ud.config.MouseFunctions[i][1], i, 1,  controldevice_mouse);
479
    }
479
    }
480
    for (i=0; i<MAXMOUSEAXES; i++)
480
    for (i=0; i<MAXMOUSEAXES; i++)
481
    {
481
    {
482
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
482
        CONTROL_MapAnalogAxis(i, ud.config.MouseAnalogueAxes[i], controldevice_mouse);
483
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
483
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][0], 0,controldevice_mouse);
484
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
484
        CONTROL_MapDigitalAxis(i, ud.config.MouseDigitalFunctions[i][1], 1,controldevice_mouse);
485
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
485
        CONTROL_SetAnalogAxisScale(i, ud.config.MouseAnalogueScale[i], controldevice_mouse);
486
    }
486
    }
487
}
487
}
488
488
489
/*
489
/*
490
===================
490
===================
491
=
491
=
492
= CONFIG_SetupJoystick
492
= CONFIG_SetupJoystick
493
=
493
=
494
===================
494
===================
495
*/
495
*/
496
496
497
void CONFIG_SetupJoystick(void)
497
void CONFIG_SetupJoystick(void)
498
{
498
{
499
    int32_t i;
499
    int32_t i;
500
    char str[80];
500
    char str[80];
501
    char temp[80];
501
    char temp[80];
502
    int32_t scale;
502
    int32_t scale;
503
503
504
    if (ud.config.scripthandle < 0) return;
504
    if (ud.config.scripthandle < 0) return;
505
505
506
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
506
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
507
    {
507
    {
508
        Bsprintf(str,"JoystickButton%d",i);
508
        Bsprintf(str,"JoystickButton%d",i);
509
        temp[0] = 0;
509
        temp[0] = 0;
510
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
510
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
511
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
511
            ud.config.JoystickFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
512
512
513
        Bsprintf(str,"JoystickButtonClicked%d",i);
513
        Bsprintf(str,"JoystickButtonClicked%d",i);
514
        temp[0] = 0;
514
        temp[0] = 0;
515
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
515
        if (!SCRIPT_GetString(ud.config.scripthandle,"Controls", str,temp))
516
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
516
            ud.config.JoystickFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
517
    }
517
    }
518
518
519
    // map over the axes
519
    // map over the axes
520
    for (i=0; i<MAXJOYAXES; i++)
520
    for (i=0; i<MAXJOYAXES; i++)
521
    {
521
    {
522
        Bsprintf(str,"JoystickAnalogAxes%d",i);
522
        Bsprintf(str,"JoystickAnalogAxes%d",i);
523
        temp[0] = 0;
523
        temp[0] = 0;
524
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
524
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
525
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
525
            if (CONFIG_AnalogNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
526
                ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
526
                ud.config.JoystickAnalogueAxes[i] = CONFIG_AnalogNameToNum(temp);
527
527
528
        Bsprintf(str,"JoystickDigitalAxes%d_0",i);
528
        Bsprintf(str,"JoystickDigitalAxes%d_0",i);
529
        temp[0] = 0;
529
        temp[0] = 0;
530
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
530
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
531
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
531
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
532
                ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
532
                ud.config.JoystickDigitalFunctions[i][0] = CONFIG_FunctionNameToNum(temp);
533
533
534
        Bsprintf(str,"JoystickDigitalAxes%d_1",i);
534
        Bsprintf(str,"JoystickDigitalAxes%d_1",i);
535
        temp[0] = 0;
535
        temp[0] = 0;
536
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
536
        if (!SCRIPT_GetString(ud.config.scripthandle, "Controls", str,temp))
537
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
537
            if (CONFIG_FunctionNameToNum(temp) != -1 || (!temp[0] && CONFIG_FunctionNameToNum(temp) != -1))
538
                ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
538
                ud.config.JoystickDigitalFunctions[i][1] = CONFIG_FunctionNameToNum(temp);
539
539
540
        Bsprintf(str,"JoystickAnalogScale%d",i);
540
        Bsprintf(str,"JoystickAnalogScale%d",i);
541
        scale = ud.config.JoystickAnalogueScale[i];
541
        scale = ud.config.JoystickAnalogueScale[i];
542
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
542
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
543
        ud.config.JoystickAnalogueScale[i] = scale;
543
        ud.config.JoystickAnalogueScale[i] = scale;
544
544
545
        Bsprintf(str,"JoystickAnalogDead%d",i);
545
        Bsprintf(str,"JoystickAnalogDead%d",i);
546
        scale = ud.config.JoystickAnalogueDead[i];
546
        scale = ud.config.JoystickAnalogueDead[i];
547
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
547
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
548
        ud.config.JoystickAnalogueDead[i] = scale;
548
        ud.config.JoystickAnalogueDead[i] = scale;
549
549
550
        Bsprintf(str,"JoystickAnalogSaturate%d",i);
550
        Bsprintf(str,"JoystickAnalogSaturate%d",i);
551
        scale = ud.config.JoystickAnalogueSaturate[i];
551
        scale = ud.config.JoystickAnalogueSaturate[i];
552
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
552
        SCRIPT_GetNumber(ud.config.scripthandle, "Controls", str,&scale);
553
        ud.config.JoystickAnalogueSaturate[i] = scale;
553
        ud.config.JoystickAnalogueSaturate[i] = scale;
554
    }
554
    }
555
555
556
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
556
    for (i=0; i<MAXJOYBUTTONSANDHATS; i++)
557
    {
557
    {
558
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
558
        CONTROL_MapButton(ud.config.JoystickFunctions[i][0], i, 0, controldevice_joystick);
559
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
559
        CONTROL_MapButton(ud.config.JoystickFunctions[i][1], i, 1,  controldevice_joystick);
560
    }
560
    }
561
    for (i=0; i<MAXJOYAXES; i++)
561
    for (i=0; i<MAXJOYAXES; i++)
562
    {
562
    {
563
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
563
        CONTROL_MapAnalogAxis(i, ud.config.JoystickAnalogueAxes[i], controldevice_joystick);
564
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
564
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][0], 0, controldevice_joystick);
565
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
565
        CONTROL_MapDigitalAxis(i, ud.config.JoystickDigitalFunctions[i][1], 1, controldevice_joystick);
566
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
566
        CONTROL_SetAnalogAxisScale(i, ud.config.JoystickAnalogueScale[i], controldevice_joystick);
567
    }
567
    }
568
}
568
}
569
569
570
/*
570
/*
571
===================
571
===================
572
=
572
=
573
= CONFIG_ReadSetup
573
= CONFIG_ReadSetup
574
=
574
=
575
===================
575
===================
576
*/
576
*/
577
extern void G_CheckPlayerColor(int32_t *color,int32_t prev_color);
577
extern void G_CheckPlayerColor(int32_t *color,int32_t prev_color);
578
extern palette_t CrosshairColors;
578
extern palette_t CrosshairColors;
579
extern palette_t DefaultCrosshairColors;
579
extern palette_t DefaultCrosshairColors;
580
extern char g_modDir[BMAX_PATH];
580
extern char g_modDir[BMAX_PATH];
581
extern int32_t r_maxfps;
581
extern int32_t r_maxfps;
582
extern int32_t g_noSetup;
582
extern int32_t g_noSetup;
583
extern int32_t demorec_diffs_cvar, demoplay_diffs;
583
extern int32_t demorec_diffs_cvar, demoplay_diffs;
584
extern int32_t demorec_difftics_cvar, demorec_diffcompress_cvar, demorec_synccompress_cvar;
584
extern int32_t demorec_difftics_cvar, demorec_diffcompress_cvar, demorec_synccompress_cvar;
585
585
586
int32_t CONFIG_ReadSetup(void)
586
int32_t CONFIG_ReadSetup(void)
587
{
587
{
588
    int32_t dummy, i = 0;
588
    int32_t dummy, i = 0;
589
    char commmacro[] = "CommbatMacro# ";
589
    char commmacro[] = "CommbatMacro# ";
590
    char tempbuf[1024];
590
    char tempbuf[1024];
591
591
592
    CONTROL_ClearAssignments();
592
    CONTROL_ClearAssignments();
593
    CONFIG_SetDefaults();
593
    CONFIG_SetDefaults();
594
594
595
    ud.config.setupread = 1;
595
    ud.config.setupread = 1;
596
596
597
    pathsearchmode = 1;
597
    pathsearchmode = 1;
598
#ifndef EDUKE32_TOUCH_DEVICES
598
#ifndef EDUKE32_TOUCH_DEVICES
599
    if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0)  // JBF 20031211
599
    if (SafeFileExists(setupfilename) && ud.config.scripthandle < 0)  // JBF 20031211
600
        ud.config.scripthandle = SCRIPT_Load(setupfilename);
600
        ud.config.scripthandle = SCRIPT_Load(setupfilename);
601
    else if (SafeFileExists(SETUPFILENAME) && ud.config.scripthandle < 0)
601
    else if (SafeFileExists(SETUPFILENAME) && ud.config.scripthandle < 0)
602
    {
602
    {
603
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
603
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
604
                   "Import configuration data from \"%s\"?",setupfilename,SETUPFILENAME);
604
                   "Import configuration data from \"%s\"?",setupfilename,SETUPFILENAME);
605
        if (i) ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
605
        if (i) ud.config.scripthandle = SCRIPT_Load(SETUPFILENAME);
606
    }
606
    }
607
    else if (SafeFileExists("duke3d.cfg") && ud.config.scripthandle < 0)
607
    else if (SafeFileExists("duke3d.cfg") && ud.config.scripthandle < 0)
608
    {
608
    {
609
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
609
        i=wm_ynbox("Import Configuration Settings", "The configuration file \"%s\" was not found. "
610
                   "Import configuration data from \"duke3d.cfg\"?",setupfilename);
610
                   "Import configuration data from \"duke3d.cfg\"?",setupfilename);
611
        if (i) ud.config.scripthandle = SCRIPT_Load("duke3d.cfg");
611
        if (i) ud.config.scripthandle = SCRIPT_Load("duke3d.cfg");
612
    }
612
    }
613
#endif
613
#endif
614
614
615
    pathsearchmode = 0;
615
    pathsearchmode = 0;
616
616
617
    if (ud.config.scripthandle < 0) return -1;
617
    if (ud.config.scripthandle < 0) return -1;
618
618
619
    if (ud.config.scripthandle >= 0)
619
    if (ud.config.scripthandle >= 0)
620
    {
620
    {
621
        char dummybuf[64];
621
        char dummybuf[64];
622
622
623
        for (dummy = 0; dummy < MAXRIDECULE; dummy++)
623
        for (dummy = 0; dummy < MAXRIDECULE; dummy++)
624
        {
624
        {
625
            commmacro[13] = dummy+'0';
625
            commmacro[13] = dummy+'0';
626
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
626
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
627
        }
627
        }
628
628
629
        Bmemset(tempbuf, 0, sizeof(tempbuf));
629
        Bmemset(tempbuf, 0, sizeof(tempbuf));
630
//        Bmemset(dummybuf, 0, sizeof(dummybuf));
630
//        Bmemset(dummybuf, 0, sizeof(dummybuf));
631
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
631
        SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","PlayerName",&tempbuf[0]);
632
632
633
        while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10)
633
        while (Bstrlen(OSD_StripColors(dummybuf,tempbuf)) > 10)
634
            tempbuf[Bstrlen(tempbuf)-1] = '\0';
634
            tempbuf[Bstrlen(tempbuf)-1] = '\0';
635
635
636
        Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
636
        Bstrncpyz(szPlayerName, tempbuf, sizeof(szPlayerName));
637
637
638
        if (g_rtsNamePtr == NULL)
638
        if (g_rtsNamePtr == NULL)
639
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
639
            SCRIPT_GetString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
640
640
641
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ConfigVersion",&ud.configversion);
641
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ConfigVersion",&ud.configversion);
642
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ForceSetup",&ud.config.ForceSetup);
642
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","ForceSetup",&ud.config.ForceSetup);
643
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","NoAutoLoad",&ud.config.NoAutoLoad);
643
        SCRIPT_GetNumber(ud.config.scripthandle, "Setup","NoAutoLoad",&ud.config.NoAutoLoad);
644
644
645
// #ifdef _WIN32
645
// #ifdef _WIN32
646
        if (g_noSetup == 0 && g_modDir[0] == '/')
646
        if (g_noSetup == 0 && g_modDir[0] == '/')
647
        {
647
        {
648
            struct Bstat st;
648
            struct Bstat st;
649
            SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
649
            SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
650
650
651
            if (Bstat(g_modDir, &st))
651
            if (Bstat(g_modDir, &st))
652
            {
652
            {
653
                if ((st.st_mode & S_IFDIR) != S_IFDIR)
653
                if ((st.st_mode & S_IFDIR) != S_IFDIR)
654
                {
654
                {
655
                    initprintf("Invalid mod dir in cfg!\n");
655
                    initprintf("Invalid mod dir in cfg!\n");
656
                    Bsprintf(g_modDir,"/");
656
                    Bsprintf(g_modDir,"/");
657
                }
657
                }
658
            }
658
            }
659
        }
659
        }
660
// #endif
660
// #endif
661
661
662
        if (g_grpNamePtr == NULL && g_usingAddon == 0)
662
        if (g_grpNamePtr == NULL && g_usingAddon == 0)
663
        {
663
        {
664
            SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr);
664
            SCRIPT_GetStringPtr(ud.config.scripthandle, "Setup","SelectedGRP",&g_grpNamePtr);
665
            if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
665
            if (g_grpNamePtr && !Bstrlen(g_grpNamePtr))
666
                g_grpNamePtr = dup_filename(G_DefaultGrpFile());
666
                g_grpNamePtr = dup_filename(G_DefaultGrpFile());
667
        }
667
        }
668
668
669
        if (!NAM)
669
        if (!NAM)
670
        {
670
        {
671
            SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout);
671
            SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Out",&ud.lockout);
672
            SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]);
672
            SCRIPT_GetString(ud.config.scripthandle, "Screen Setup","Password",&ud.pwlockout[0]);
673
        }
673
        }
674
674
675
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight);
675
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",&ud.config.ScreenHeight);
676
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode);
676
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",&ud.config.ScreenMode);
677
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth);
677
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",&ud.config.ScreenWidth);
678
678
679
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
679
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", (int32_t *)&windowpos);
680
        windowx = -1;
680
        windowx = -1;
681
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
681
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", (int32_t *)&windowx);
682
        windowy = -1;
682
        windowy = -1;
683
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
683
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", (int32_t *)&windowy);
684
684
685
#ifdef RENDERTYPEWIN
685
#ifdef RENDERTYPEWIN
686
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
686
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", (int32_t *)&maxrefreshfreq);
687
#endif
687
#endif
688
688
689
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP);
689
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP", &ud.config.ScreenBPP);
690
        if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32;
690
        if (ud.config.ScreenBPP < 8) ud.config.ScreenBPP = 32;
691
691
692
#ifdef POLYMER
692
#ifdef POLYMER
693
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy);
693
        SCRIPT_GetNumber(ud.config.scripthandle, "Screen Setup", "Polymer", &dummy);
694
        if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER;
694
        if (dummy > 0 && ud.config.ScreenBPP >= 16) glrendmode = REND_POLYMER;
695
        else glrendmode = REND_POLYMOST;
695
        else glrendmode = REND_POLYMOST;
696
#endif
696
#endif
697
697
698
        /*
698
        /*
699

699

700
                    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color);
700
                    SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Color",&ud.color);
701
                    G_CheckPlayerColor((int32_t *)&ud.color,-1);
701
                    G_CheckPlayerColor((int32_t *)&ud.color,-1);
702
                    g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
702
                    g_player[0].ps->palookup = g_player[0].pcolor = ud.color;
703
                    tempbuf[0] = 0;
703
                    tempbuf[0] = 0;
704
        */
704
        */
705
705
706
        SCRIPT_GetString(ud.config.scripthandle, "Misc", "CrosshairColor",&tempbuf[0]);
706
        SCRIPT_GetString(ud.config.scripthandle, "Misc", "CrosshairColor",&tempbuf[0]);
707
        if (tempbuf[0])
707
        if (tempbuf[0])
708
        {
708
        {
709
            char *ptr = strtok(tempbuf,",");
709
            char *ptr = strtok(tempbuf,",");
710
            palette_t temppal;
710
            palette_t temppal;
711
            char *palptr = (char *)&temppal;
711
            char *palptr = (char *)&temppal;
712
712
713
            i = 0;
713
            i = 0;
714
            while (ptr != NULL && i < 3)
714
            while (ptr != NULL && i < 3)
715
            {
715
            {
716
                palptr[i++] = Batoi(ptr);
716
                palptr[i++] = Batoi(ptr);
717
                ptr = strtok(NULL,",");
717
                ptr = strtok(NULL,",");
718
            }
718
            }
719
            if (i == 3)
719
            if (i == 3)
720
            {
720
            {
721
                Bmemcpy(&CrosshairColors,&temppal,sizeof(palette_t));
721
                Bmemcpy(&CrosshairColors,&temppal,sizeof(palette_t));
722
                DefaultCrosshairColors.f = 1;
722
                DefaultCrosshairColors.f = 1;
723
            }
723
            }
724
        }
724
        }
725
725
726
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions);
726
        SCRIPT_GetNumber(ud.config.scripthandle, "Misc", "Executions",&ud.executions);
727
727
728
#ifdef _WIN32
728
#ifdef _WIN32
729
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
729
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", &ud.config.CheckForUpdates);
730
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
730
        SCRIPT_GetNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", &ud.config.LastUpdateCheck);
731
#endif
731
#endif
732
732
733
    }
733
    }
734
734
735
    //CONFIG_SetupMouse(ud.config.scripthandle);
735
    //CONFIG_SetupMouse(ud.config.scripthandle);
736
    //CONFIG_SetupJoystick(ud.config.scripthandle);
736
    //CONFIG_SetupJoystick(ud.config.scripthandle);
737
    ud.config.setupread = 1;
737
    ud.config.setupread = 1;
738
    return 0;
738
    return 0;
739
}
739
}
740
740
741
/*
741
/*
742
===================
742
===================
743
=
743
=
744
= CONFIG_WriteSetup
744
= CONFIG_WriteSetup
745
=
745
=
746
===================
746
===================
747
*/
747
*/
748
748
749
void CONFIG_WriteBinds(void) // save binds and aliases to <cfgname>_settings.cfg
749
void CONFIG_WriteBinds(void) // save binds and aliases to <cfgname>_settings.cfg
750
{
750
{
751
    int32_t i;
751
    int32_t i;
752
    BFILE *fp;
752
    BFILE *fp;
753
    char *ptr = Xstrdup(setupfilename);
753
    char *ptr = Xstrdup(setupfilename);
754
    char tempbuf[128];
754
    char tempbuf[128];
755
755
756
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
756
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
757
        Bsprintf(tempbuf, "settings.cfg");
757
        Bsprintf(tempbuf, "settings.cfg");
758
    else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, "."));
758
    else Bsprintf(tempbuf, "%s_settings.cfg", strtok(ptr, "."));
759
759
760
    fp = Bfopen(tempbuf, "wt");
760
    fp = Bfopen(tempbuf, "wt");
761
761
762
    if (fp)
762
    if (fp)
763
    {
763
    {
764
        Bfprintf(fp,"// this file is automatically generated by EDuke32\n");
764
        Bfprintf(fp,"// this file is automatically generated by EDuke32\n");
765
        Bfprintf(fp,"// these settings take precedence over your main cfg file\n");
765
        Bfprintf(fp,"// these settings take precedence over your main cfg file\n");
766
        Bfprintf(fp,"// do not modify if you lack common sense\n");
766
        Bfprintf(fp,"// do not modify if you lack common sense\n");
767
767
768
        Bfprintf(fp,"unbindall\n");
768
        Bfprintf(fp,"unbindall\n");
769
769
770
        for (i=0; i<MAXBOUNDKEYS; i++)
770
        for (i=0; i<MAXBOUNDKEYS; i++)
771
            if (CONTROL_KeyIsBound(i))
771
            if (CONTROL_KeyIsBound(i))
772
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key,
772
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_KeyBinds[i].key,
773
                CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr);
773
                CONTROL_KeyBinds[i].repeat?"":" norepeat",CONTROL_KeyBinds[i].cmdstr);
774
774
775
        for (i=0; i<MAXMOUSEBUTTONS; i++)
775
        for (i=0; i<MAXMOUSEBUTTONS; i++)
776
            if (CONTROL_MouseIsBound(i))
776
            if (CONTROL_MouseIsBound(i))
777
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key,
777
                Bfprintf(fp,"bind \"%s\"%s \"%s\"\n",CONTROL_MouseBinds[i].key,
778
                CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr);
778
                CONTROL_MouseBinds[i].repeat?"":" norepeat",CONTROL_MouseBinds[i].cmdstr);
779
779
780
        OSD_WriteAliases(fp);
780
        OSD_WriteAliases(fp);
781
        OSD_WriteCvars(fp);
781
        OSD_WriteCvars(fp);
782
782
783
        Bfclose(fp);
783
        Bfclose(fp);
784
784
785
        if (!Bstrcmp(setupfilename, SETUPFILENAME))
785
        if (!Bstrcmp(setupfilename, SETUPFILENAME))
786
            OSD_Printf("Wrote settings.cfg\n");
786
            OSD_Printf("Wrote settings.cfg\n");
787
        else OSD_Printf("Wrote %s_settings.cfg\n",ptr);
787
        else OSD_Printf("Wrote %s_settings.cfg\n",ptr);
788
788
789
        Bfree(ptr);
789
        Bfree(ptr);
790
        return;
790
        return;
791
    }
791
    }
792
792
793
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
793
    if (!Bstrcmp(setupfilename, SETUPFILENAME))
794
        OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno));
794
        OSD_Printf("Error writing settings.cfg: %s\n", strerror(errno));
795
    else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno));
795
    else OSD_Printf("Error writing %s_settings.cfg: %s\n",ptr,strerror(errno));
796
796
797
    Bfree(ptr);
797
    Bfree(ptr);
798
}
798
}
799
799
800
void CONFIG_WriteSetup(uint32_t flags)
800
void CONFIG_WriteSetup(uint32_t flags)
801
{
801
{
802
    int32_t dummy;
802
    int32_t dummy;
803
    char tempbuf[1024];
-
 
804
803
805
    if (!ud.config.setupread) return;
804
    if (!ud.config.setupread) return;
806
805
807
    if (ud.config.scripthandle < 0)
806
    if (ud.config.scripthandle < 0)
808
        ud.config.scripthandle = SCRIPT_Init(setupfilename);
807
        ud.config.scripthandle = SCRIPT_Init(setupfilename);
809
808
810
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",++ud.executions,FALSE,FALSE);
809
    SCRIPT_PutNumber(ud.config.scripthandle, "Misc", "Executions",++ud.executions,FALSE,FALSE);
811
810
812
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup","ConfigVersion",BYTEVERSION_JF,FALSE,FALSE);
811
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup","ConfigVersion",BYTEVERSION_JF,FALSE,FALSE);
813
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup",ud.config.ForceSetup,FALSE,FALSE);
812
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "ForceSetup",ud.config.ForceSetup,FALSE,FALSE);
814
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad",ud.config.NoAutoLoad,FALSE,FALSE);
813
    SCRIPT_PutNumber(ud.config.scripthandle, "Setup", "NoAutoLoad",ud.config.NoAutoLoad,FALSE,FALSE);
815
814
816
#ifdef POLYMER
815
#ifdef POLYMER
817
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer",glrendmode == REND_POLYMER,FALSE,FALSE);
816
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Polymer",glrendmode == REND_POLYMER,FALSE,FALSE);
818
#endif
817
#endif
819
818
820
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,FALSE,FALSE);  // JBF 20040523
819
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenBPP",ud.config.ScreenBPP,FALSE,FALSE);  // JBF 20040523
821
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,FALSE,FALSE);    // JBF 20031206
820
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenHeight",ud.config.ScreenHeight,FALSE,FALSE);    // JBF 20031206
822
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,FALSE,FALSE);    // JBF 20031206
821
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenMode",ud.config.ScreenMode,FALSE,FALSE);    // JBF 20031206
823
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,FALSE,FALSE);  // JBF 20031206
822
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "ScreenWidth",ud.config.ScreenWidth,FALSE,FALSE);  // JBF 20031206
824
823
825
    if (g_grpNamePtr && !g_usingAddon)
824
    if (g_grpNamePtr && !g_usingAddon)
826
        SCRIPT_PutString(ud.config.scripthandle, "Setup","SelectedGRP",g_grpNamePtr);
825
        SCRIPT_PutString(ud.config.scripthandle, "Setup","SelectedGRP",g_grpNamePtr);
827
826
828
    // XXX: should be "if compiled without startup GUI"
827
    // XXX: should be "if compiled without startup GUI"
829
#if !defined __linux || defined HAVE_GTK2
828
#if !defined __linux || defined HAVE_GTK2
830
    if (g_noSetup == 0)
829
    if (g_noSetup == 0)
831
        SCRIPT_PutString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
830
        SCRIPT_PutString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
832
#endif
831
#endif
833
    // exit early after only updating the values that can be changed from the startup window
832
    // exit early after only updating the values that can be changed from the startup window
834
    if (flags & 1)
833
    if (flags & 1)
835
    {
834
    {
836
        SCRIPT_Save(ud.config.scripthandle, setupfilename);
835
        SCRIPT_Save(ud.config.scripthandle, setupfilename);
837
        SCRIPT_Free(ud.config.scripthandle);
836
        SCRIPT_Free(ud.config.scripthandle);
838
        OSD_Printf("Updated %s\n",setupfilename);
837
        OSD_Printf("Updated %s\n",setupfilename);
839
838
840
        return;
839
        return;
841
    }
840
    }
842
841
843
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
842
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPositioning", windowpos, FALSE, FALSE);
844
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
843
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosX", windowx, FALSE, FALSE);
845
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
844
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "WindowPosY", windowy, FALSE, FALSE);
846
#ifdef RENDERTYPEWIN
845
#ifdef RENDERTYPEWIN
847
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
846
    SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "MaxRefreshFreq", maxrefreshfreq, FALSE, FALSE);
848
#endif
847
#endif
849
848
850
    if (!NAM)
849
    if (!NAM)
851
    {
850
    {
852
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
851
        SCRIPT_PutNumber(ud.config.scripthandle, "Screen Setup", "Out",ud.lockout,FALSE,FALSE);
853
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
852
        SCRIPT_PutString(ud.config.scripthandle, "Screen Setup", "Password",ud.pwlockout);
854
    }
853
    }
855
854
856
#ifdef _WIN32
855
#ifdef _WIN32
857
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
856
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "CheckForUpdates", ud.config.CheckForUpdates, FALSE, FALSE);
858
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
857
    SCRIPT_PutNumber(ud.config.scripthandle, "Updates", "LastUpdateCheck", ud.config.LastUpdateCheck, FALSE, FALSE);
859
#endif
858
#endif
860
859
861
    if (ud.config.UseMouse)
860
    if (ud.config.UseMouse)
862
    {
861
    {
863
        for (dummy=0; dummy<MAXMOUSEBUTTONS; dummy++)
862
        for (dummy=0; dummy<MAXMOUSEBUTTONS; dummy++)
864
        {
863
        {
865
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]))
864
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]))
866
            {
865
            {
867
                Bsprintf(buf, "MouseButton%d", dummy);
866
                Bsprintf(buf, "MouseButton%d", dummy);
868
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]));
867
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][0]));
869
            }
868
            }
870
869
871
            if (dummy >= (MAXMOUSEBUTTONS-2)) continue;
870
            if (dummy >= (MAXMOUSEBUTTONS-2)) continue;
872
871
873
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]))
872
            if (CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]))
874
            {
873
            {
875
                Bsprintf(buf, "MouseButtonClicked%d", dummy);
874
                Bsprintf(buf, "MouseButtonClicked%d", dummy);
876
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]));
875
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseFunctions[dummy][1]));
877
            }
876
            }
878
        }
877
        }
879
878
880
        for (dummy=0; dummy<MAXMOUSEAXES; dummy++)
879
        for (dummy=0; dummy<MAXMOUSEAXES; dummy++)
881
        {
880
        {
882
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]))
881
            if (CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]))
883
            {
882
            {
884
                Bsprintf(buf, "MouseAnalogAxes%d", dummy);
883
                Bsprintf(buf, "MouseAnalogAxes%d", dummy);
885
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]));
884
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.MouseAnalogueAxes[dummy]));
886
            }
885
            }
887
886
888
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]))
887
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]))
889
            {
888
            {
890
                Bsprintf(buf, "MouseDigitalAxes%d_0", dummy);
889
                Bsprintf(buf, "MouseDigitalAxes%d_0", dummy);
891
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]));
890
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][0]));
892
            }
891
            }
893
892
894
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]))
893
            if (CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]))
895
            {
894
            {
896
                Bsprintf(buf, "MouseDigitalAxes%d_1", dummy);
895
                Bsprintf(buf, "MouseDigitalAxes%d_1", dummy);
897
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]));
896
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.MouseDigitalFunctions[dummy][1]));
898
            }
897
            }
899
898
900
            if (ud.config.MouseAnalogueScale[dummy] != DEFAULTMOUSEANALOGUESCALE)
899
            if (ud.config.MouseAnalogueScale[dummy] != DEFAULTMOUSEANALOGUESCALE)
901
            {
900
            {
902
                Bsprintf(buf, "MouseAnalogScale%d", dummy);
901
                Bsprintf(buf, "MouseAnalogScale%d", dummy);
903
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[dummy], FALSE, FALSE);
902
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.MouseAnalogueScale[dummy], FALSE, FALSE);
904
            }
903
            }
905
        }
904
        }
906
    }
905
    }
907
906
908
    if (ud.config.UseJoystick)
907
    if (ud.config.UseJoystick)
909
    {
908
    {
910
        for (dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
909
        for (dummy=0; dummy<MAXJOYBUTTONSANDHATS; dummy++)
911
        {
910
        {
912
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
911
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]))
913
            {
912
            {
914
                Bsprintf(buf, "JoystickButton%d", dummy);
913
                Bsprintf(buf, "JoystickButton%d", dummy);
915
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
914
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][0]));
916
            }
915
            }
917
916
918
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
917
            if (CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]))
919
            {
918
            {
920
                Bsprintf(buf, "JoystickButtonClicked%d", dummy);
919
                Bsprintf(buf, "JoystickButtonClicked%d", dummy);
921
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
920
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickFunctions[dummy][1]));
922
            }
921
            }
923
        }
922
        }
924
        for (dummy=0; dummy<MAXJOYAXES; dummy++)
923
        for (dummy=0; dummy<MAXJOYAXES; dummy++)
925
        {
924
        {
926
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
925
            if (CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]))
927
            {
926
            {
928
                Bsprintf(buf, "JoystickAnalogAxes%d", dummy);
927
                Bsprintf(buf, "JoystickAnalogAxes%d", dummy);
929
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
928
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_AnalogNumToName(ud.config.JoystickAnalogueAxes[dummy]));
930
            }
929
            }
931
930
932
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
931
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]))
933
            {
932
            {
934
                Bsprintf(buf, "JoystickDigitalAxes%d_0", dummy);
933
                Bsprintf(buf, "JoystickDigitalAxes%d_0", dummy);
935
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
934
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][0]));
936
            }
935
            }
937
936
938
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
937
            if (CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]))
939
            {
938
            {
940
                Bsprintf(buf, "JoystickDigitalAxes%d_1", dummy);
939
                Bsprintf(buf, "JoystickDigitalAxes%d_1", dummy);
941
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
940
                SCRIPT_PutString(ud.config.scripthandle, "Controls", buf, CONFIG_FunctionNumToName(ud.config.JoystickDigitalFunctions[dummy][1]));
942
            }
941
            }
943
942
944
            if (ud.config.JoystickAnalogueScale[dummy] != DEFAULTJOYSTICKANALOGUESCALE)
943
            if (ud.config.JoystickAnalogueScale[dummy] != DEFAULTJOYSTICKANALOGUESCALE)
945
            {
944
            {
946
                Bsprintf(buf, "JoystickAnalogScale%d", dummy);
945
                Bsprintf(buf, "JoystickAnalogScale%d", dummy);
947
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
946
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueScale[dummy], FALSE, FALSE);
948
            }
947
            }
949
948
950
            if (ud.config.JoystickAnalogueDead[dummy] != DEFAULTJOYSTICKANALOGUEDEAD)
949
            if (ud.config.JoystickAnalogueDead[dummy] != DEFAULTJOYSTICKANALOGUEDEAD)
951
            {
950
            {
952
                Bsprintf(buf, "JoystickAnalogDead%d", dummy);
951
                Bsprintf(buf, "JoystickAnalogDead%d", dummy);
953
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
952
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueDead[dummy], FALSE, FALSE);
954
            }
953
            }
955
954
956
            if (ud.config.JoystickAnalogueSaturate[dummy] != DEFAULTJOYSTICKANALOGUESATURATE)
955
            if (ud.config.JoystickAnalogueSaturate[dummy] != DEFAULTJOYSTICKANALOGUESATURATE)
957
            {
956
            {
958
                Bsprintf(buf, "JoystickAnalogSaturate%d", dummy);
957
                Bsprintf(buf, "JoystickAnalogSaturate%d", dummy);
959
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
958
                SCRIPT_PutNumber(ud.config.scripthandle, "Controls", buf, ud.config.JoystickAnalogueSaturate[dummy], FALSE, FALSE);
960
            }
959
            }
961
        }
960
        }
962
    }
961
    }
963
962
964
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
963
    SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","PlayerName",&szPlayerName[0]);
965
964
966
    if (g_rtsNamePtr == NULL)
965
    if (g_rtsNamePtr == NULL)
967
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
966
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup","RTSName",&ud.rtsname[0]);
968
967
969
    char commmacro[] = "CommbatMacro# ";
968
    char commmacro[] = "CommbatMacro# ";
970
969
971
    for (dummy = 0; dummy < MAXRIDECULE; dummy++)
970
    for (dummy = 0; dummy < MAXRIDECULE; dummy++)
972
    {
971
    {
973
        commmacro[13] = dummy+'0';
972
        commmacro[13] = dummy+'0';
974
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
973
        SCRIPT_PutString(ud.config.scripthandle, "Comm Setup",commmacro,&ud.ridecule[dummy][0]);
975
    }
974
    }
976
975
977
    SCRIPT_Save(ud.config.scripthandle, setupfilename);
976
    SCRIPT_Save(ud.config.scripthandle, setupfilename);
978
977
979
    if ((flags & 2) == 0)
978
    if ((flags & 2) == 0)
980
        SCRIPT_Free(ud.config.scripthandle);
979
        SCRIPT_Free(ud.config.scripthandle);
981
980
982
    OSD_Printf("Wrote %s\n",setupfilename);
981
    OSD_Printf("Wrote %s\n",setupfilename);
983
    CONFIG_WriteBinds();
982
    CONFIG_WriteBinds();
984
    Bfflush(NULL);
983
    Bfflush(NULL);
985
}
984
}
986
985
987
986
988
int32_t CONFIG_GetMapBestTime(char *mapname)
987
int32_t CONFIG_GetMapBestTime(char *mapname)
989
{
988
{
990
    int32_t t = -1;
989
    int32_t t = -1;
991
    char m[BMAX_PATH], *p;
990
    char m[BMAX_PATH], *p;
992
991
993
    strcpy(m, mapname);
992
    strcpy(m, mapname);
994
    p = strrchr(m, '/');
993
    p = strrchr(m, '/');
995
    if (!p) p = strrchr(m, '\\');
994
    if (!p) p = strrchr(m, '\\');
996
    if (p) Bmemmove(m, p, Bstrlen(p)+1);//strcpy(m, p);
995
    if (p) Bmemmove(m, p, Bstrlen(p)+1);//strcpy(m, p);
997
    for (p=m; *p; p++) *p = tolower(*p);
996
    for (p=m; *p; p++) *p = tolower(*p);
998
997
999
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
998
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1000
    p = m;
999
    p = m;
1001
    while (*p == '/') p++;
1000
    while (*p == '/') p++;
1002
1001
1003
    if (!ud.config.setupread) return -1;
1002
    if (!ud.config.setupread) return -1;
1004
    if (ud.config.scripthandle < 0) return -1;
1003
    if (ud.config.scripthandle < 0) return -1;
1005
1004
1006
    SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1005
    SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t);
1007
    return t;
1006
    return t;
1008
}
1007
}
1009
1008
1010
int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm)
1009
int32_t CONFIG_SetMapBestTime(char *mapname, int32_t tm)
1011
{
1010
{
1012
    char m[BMAX_PATH], *p;
1011
    char m[BMAX_PATH], *p;
1013
1012
1014
    strcpy(m, mapname);
1013
    strcpy(m, mapname);
1015
    p = strrchr(m, '/');
1014
    p = strrchr(m, '/');
1016
    if (!p) p = strrchr(m, '\\');
1015
    if (!p) p = strrchr(m, '\\');
1017
    if (p) strcpy(m, p);
1016
    if (p) strcpy(m, p);
1018
    for (p=m; *p; p++) *p = tolower(*p);
1017
    for (p=m; *p; p++) *p = tolower(*p);
1019
1018
1020
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1019
    // cheap hack because SCRIPT_GetNumber doesn't like the slashes
1021
    p = m;
1020
    p = m;
1022
    while (*p == '/') p++;
1021
    while (*p == '/') p++;
1023
1022
1024
    if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename);
1023
    if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename);
1025
    if (ud.config.scripthandle < 0) return -1;
1024
    if (ud.config.scripthandle < 0) return -1;
1026
1025
1027
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE);
1026
    SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE);
1028
    return 0;
1027
    return 0;
1029
}
1028
}
1030
1029
1031
/*
1030
/*
1032
 * vim:ts=4:sw=4:
1031
 * vim:ts=4:sw=4:
1033
 */
1032
 */
1034
1033
1035
 
1034