DEADSOFTWARE

System username used as player's nickname by default
[d2df-sdl.git] / src / game / g_options.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_options;
19 interface
21 uses
22 g_language, g_weapons;
24 type
25 TPlayerControl = record
26 KeyRight: Word;
27 KeyLeft: Word;
28 KeyUp: Word;
29 KeyDown: Word;
30 KeyFire: Word;
31 KeyJump: Word;
32 KeyNextWeapon: Word;
33 KeyPrevWeapon: Word;
34 KeyOpen: Word;
35 KeyStrafe: Word;
36 KeyWeapon: array [WP_FIRST..WP_LAST] of Word;
38 KeyRight2: Word;
39 KeyLeft2: Word;
40 KeyUp2: Word;
41 KeyDown2: Word;
42 KeyFire2: Word;
43 KeyJump2: Word;
44 KeyNextWeapon2: Word;
45 KeyPrevWeapon2: Word;
46 KeyOpen2: Word;
47 KeyStrafe2: Word;
48 KeyWeapon2: array [WP_FIRST..WP_LAST] of Word;
49 end;
51 TGameControls = record
52 TakeScreenshot: Word;
53 Stat: Word;
54 Chat: Word;
55 TeamChat: Word;
56 end;
58 TControls = record
59 GameControls: TGameControls;
60 P1Control: TPlayerControl;
61 P2Control: TPlayerControl;
62 end;
64 function GenPlayerName (n: Integer): String;
66 procedure g_Options_SetDefault();
67 procedure g_Options_Read(FileName: String);
68 procedure g_Options_Write(FileName: String);
69 procedure g_Options_Write_Language(FileName: String);
70 procedure g_Options_Write_Video(FileName: String);
71 procedure g_Options_Write_Gameplay_Custom(FileName: String);
72 procedure g_Options_Write_Gameplay_Net(FileName: String);
73 procedure g_Options_Write_Net_Server(FileName: String);
74 procedure g_Options_Write_Net_Client(FileName: String);
76 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
78 var
79 gGameControls: TControls;
80 gScreenWidth: Word;
81 gScreenHeight: Word;
82 gWinRealPosX: Integer;
83 gWinRealPosY: Integer;
84 gBPP: Byte;
85 gFreq: Byte;
86 gFullscreen: Boolean;
87 gWinMaximized: Boolean;
88 gVSync: Boolean;
89 glLegacyNPOT: Boolean;
90 gTextureFilter: Boolean;
91 gNoSound: Boolean;
92 gSoundLevel: Byte;
93 gMusicLevel: Byte;
94 gMaxSimSounds: Byte;
95 gMuteWhenInactive: Boolean;
96 gAdvCorpses: Boolean;
97 gAdvBlood: Boolean;
98 gAdvGibs: Boolean;
99 gGibsCount: Integer;
100 gBloodCount: Byte;
101 gFlash: Byte;
102 gDrawBackGround: Boolean;
103 gShowMessages: Boolean;
104 gRevertPlayers: Boolean;
105 gLanguage: String;
106 gAskLanguage: Boolean;
107 gcMap: String;
108 gcGameMode: String;
109 gcTimeLimit: Word;
110 gcGoalLimit: Word;
111 gcMaxLives: Byte;
112 gcPlayers: Byte;
113 gcTeamDamage: Boolean;
114 gcAllowExit: Boolean;
115 gcWeaponStay: Boolean;
116 gcMonsters: Boolean;
117 gcBotsVS: String;
118 gnMap: String;
119 gnGameMode: String;
120 gnTimeLimit: Word;
121 gnGoalLimit: Word;
122 gnMaxLives: Byte;
123 gnPlayers: Byte;
124 gnTeamDamage: Boolean;
125 gnAllowExit: Boolean;
126 gnWeaponStay: Boolean;
127 gnMonsters: Boolean;
128 gnBotsVS: String;
129 gsSDLSampleRate: Integer;
130 gsSDLBufferSize: Integer;
131 gSFSDebug: Boolean;
132 gSFSFastMode: Boolean;
133 gDefaultMegawadStart: AnsiString;
134 gBerserkAutoswitch: Boolean;
136 implementation
138 uses
139 {$INCLUDE ../nogl/noGLuses.inc}
140 e_log, e_input, g_window, g_sound, g_gfx, g_player, Math,
141 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
142 g_items, wadreader, e_graphics, g_touch, SDL2, envvars;
144 var
145 machine: Integer;
147 function GenPlayerName (n: Integer): String;
148 begin
149 ASSERT(n >= 1);
150 Result := GetUserName;
151 if Result = '' then Result := 'Player' + IntToStr(machine MOD 10000);
152 if n > 1 then Result := Copy(Result, 1, 10) + (' ' + IntToStr(n))
153 end;
155 procedure g_Options_SetDefaultVideo;
156 var
157 target, closest, display: TSDL_DisplayMode;
158 percentage: Integer;
159 begin
160 (* Display 0 = Primary display *)
161 SDL_GetDesktopDisplayMode(0, @display);
162 {$IF DEFINED(ANDROID)}
163 gScreenWidth := display.w;
164 gScreenHeight := display.h;
165 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
166 gBPP := 32;
167 gFullScreen := True; (* rotation not allowed? *)
168 {$ELSE}
169 (* Window must be smaller than display *)
170 closest.w := display.w;
171 closest.h := display.h;
172 percentage := 75;
173 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
174 begin
175 if percentage < 25 then
176 begin
177 closest.w := display.w * 75 div 100;
178 closest.h := display.h * 75 div 100;
179 break;
180 end;
181 target.w := display.w * percentage div 100;
182 target.h := display.h * percentage div 100;
183 target.format := 0; (* didn't care *)
184 target.refresh_rate := 0; (* didn't care *)
185 target.driverdata := nil; (* init *)
186 SDL_GetClosestDisplayMode(0, @target, @closest);
187 Dec(percentage);
188 end;
189 gScreenWidth := closest.w;
190 gScreenHeight := closest.h;
191 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
192 gBPP := 32;
193 gFullScreen := False;
194 {$ENDIF}
195 (* Must be positioned on primary display *)
196 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
197 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
198 gWinMaximized := False;
199 gVSync := True;
200 gTextureFilter := True;
201 glLegacyNPOT := False;
202 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
203 end;
205 procedure g_Options_SetDefault();
206 var
207 i: Integer;
208 begin
209 (* section Sound *)
210 gNoSound := False;
211 gSoundLevel := 75;
212 gMusicLevel := 65;
213 gMaxSimSounds := 8;
214 gMuteWhenInactive := False;
215 gAnnouncer := ANNOUNCE_MEPLUS;
216 gSoundEffectsDF := True;
217 gUseChatSounds := True;
218 gsSDLSampleRate := 44100;
219 gsSDLBufferSize := 2048;
221 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
223 (* section GameControls *)
224 with gGameControls.GameControls do
225 begin
226 TakeScreenshot := SDL_SCANCODE_F12;
227 Stat := SDL_SCANCODE_TAB;
228 Chat := SDL_SCANCODE_T;
229 TeamChat := SDL_SCANCODE_Y;
230 end;
232 (* section Player1 *)
233 with gGameControls.P1Control do
234 begin
235 KeyRight := SDL_SCANCODE_KP_6;
236 KeyLeft := SDL_SCANCODE_KP_4;
237 KeyUp := SDL_SCANCODE_KP_8;
238 KeyDown := SDL_SCANCODE_KP_5;
239 KeyFire := SDL_SCANCODE_SLASH;
240 KeyJump := SDL_SCANCODE_RCTRL;
241 KeyNextWeapon := SDL_SCANCODE_KP_9;
242 KeyPrevWeapon := SDL_SCANCODE_KP_7;
243 KeyOpen := SDL_SCANCODE_RSHIFT;
244 KeyStrafe := SDL_SCANCODE_PERIOD;
246 for i := 0 to 9 do
247 begin
248 KeyWeapon[i] := SDL_SCANCODE_1 + i (* 1, ..., 9, 0 *)
249 end;
250 KeyWeapon[10] := SDL_SCANCODE_MINUS;
251 for i := 11 to High(KeyWeapon) do
252 begin
253 KeyWeapon[i] := 0
254 end;
256 KeyRight2 := VK_RIGHT;
257 KeyLeft2 := VK_LEFT;
258 KeyUp2 := VK_UP;
259 KeyDown2 := VK_DOWN;
260 KeyFire2 := VK_FIRE;
261 KeyJump2 := VK_JUMP;
262 KeyNextWeapon2 := VK_NEXT;
263 KeyPrevWeapon2 := VK_PREV;
264 KeyOpen2 := VK_OPEN;
265 KeyStrafe2 := VK_STRAFE;
267 for i := 0 to High(KeyWeapon2) do
268 begin
269 KeyWeapon2[i] := VK_0 + i
270 end;
271 end;
273 with gPlayer1Settings do
274 begin
275 Name := GenPlayerName(1);
276 Model := STD_PLAYER_MODEL;
277 Color.R := PLAYER1_DEF_COLOR.R;
278 Color.G := PLAYER1_DEF_COLOR.G;
279 Color.B := PLAYER1_DEF_COLOR.B;
280 Team := TEAM_RED;
281 end;
283 (* section Player2 *)
284 with gGameControls.P2Control do
285 begin
286 KeyRight := SDL_SCANCODE_D;
287 KeyLeft := SDL_SCANCODE_A;
288 KeyUp := SDL_SCANCODE_W;
289 KeyDown := SDL_SCANCODE_S;
290 KeyFire := SDL_SCANCODE_G;
291 KeyJump := SDL_SCANCODE_SPACE;
292 KeyNextWeapon := SDL_SCANCODE_E;
293 KeyPrevWeapon := SDL_SCANCODE_Q;
294 KeyOpen := SDL_SCANCODE_F;
295 KeyStrafe := SDL_SCANCODE_LSHIFT;
296 for i := 0 to High(KeyWeapon) do
297 begin
298 KeyWeapon[i] := 0
299 end;
301 KeyRight2 := 0;
302 KeyLeft2 := 0;
303 KeyUp2 := 0;
304 KeyDown2 := 0;
305 KeyFire2 := 0;
306 KeyJump2 := 0;
307 KeyNextWeapon2 := 0;
308 KeyPrevWeapon2 := 0;
309 KeyOpen2 := 0;
310 KeyStrafe2 := 0;
312 for i := 0 to High(KeyWeapon2) do
313 begin
314 KeyWeapon2[i] := 0;
315 end
316 end;
318 with gPlayer2Settings do
319 begin
320 Name := GenPlayerName(2);
321 Model := STD_PLAYER_MODEL;
322 Color.R := PLAYER2_DEF_COLOR.R;
323 Color.G := PLAYER2_DEF_COLOR.G;
324 Color.B := PLAYER2_DEF_COLOR.B;
325 Team := TEAM_BLUE;
326 end;
328 (* section Joysticks *)
329 for i := 0 to e_MaxJoys - 1 do
330 begin
331 e_JoystickDeadzones[i] := 8192
332 end;
334 (* section Touch *)
335 g_touch_size := 1.0;
336 g_touch_fire := True;
337 g_touch_offset := 50;
338 g_touch_alt := False;
340 (* section Game *)
341 g_GFX_SetMax(2000);
342 g_Shells_SetMax(300);
343 g_Gibs_SetMax(150);
344 g_Corpses_SetMax(20);
345 gGibsCount := 32;
346 ITEM_RESPAWNTIME := 60 * 36;
347 gBloodCount := 4;
348 gAdvBlood := True;
349 gAdvCorpses := True;
350 gAdvGibs := True;
351 gFlash := 1;
352 gDrawBackGround := True;
353 gShowMessages := True;
354 gRevertPlayers := False;
355 gChatBubble := 4;
356 gSFSDebug := False;
357 gSFSFastMode := False;
358 e_FastScreenshots := True;
359 gDefaultMegawadStart := DF_Default_Megawad_Start;
360 gBerserkAutoswitch := True;
361 g_dbg_scale := 1.0;
363 gAskLanguage := True;
364 gLanguage := LANGUAGE_ENGLISH;
366 (* section GameplayCustom *)
367 gcMap := '';
368 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
369 gcTimeLimit := 0;
370 gcGoalLimit := 0;
371 gcMaxLives := 0;
372 gcPlayers := 1;
373 gcTeamDamage := False;
374 gcAllowExit := True;
375 gcWeaponStay := False;
376 gcMonsters := False;
377 gcBotsVS := 'Everybody';
379 (* section GameplayNetwork *)
380 gnMap := '';
381 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
382 gnTimeLimit := 0;
383 gnGoalLimit := 0;
384 gnMaxLives := 0;
385 gnPlayers := 1;
386 gnTeamDamage := False;
387 gnAllowExit := True;
388 gnWeaponStay := False;
389 gnMonsters := False;
390 gnBotsVS := 'Everybody';
392 (* section MasterServer *)
393 NetSlistIP := 'mpms.doom2d.org';
394 NetSlistPort := 25665;
395 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
397 (* section Server *)
398 NetServerName := 'Unnamed Server';
399 NetPassword := '';
400 NetPort := 25666;
401 NetMaxClients := 16;
402 NetAllowRCON := False;
403 NetRCONPassword := 'default';
404 NetUseMaster := True;
405 NetUpdateRate := 0;
406 NetRelupdRate := 18;
407 NetMasterRate := 60000;
408 NetForwardPorts := False;
410 (* section Client *)
411 NetInterpLevel := 2;
412 NetForcePlayerUpdate := False;
413 NetPredictSelf := True;
414 NetClientIP := '127.0.0.1';
415 NetClientPort := NetPort;
416 end;
418 procedure g_Options_Read(FileName: String);
419 var
420 i: Integer;
421 config: TConfig;
422 section: String;
424 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
425 begin
426 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
427 end;
429 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
430 begin
431 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
432 end;
434 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
435 begin
436 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
437 end;
439 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
440 begin
441 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
442 end;
444 procedure ReadBoolean (VAR v: Boolean; param: String);
445 begin
446 v := config.ReadBool(section, param, v)
447 end;
449 procedure ReadString (VAR v: String; param: String);
450 begin
451 v := config.ReadStr(section, param, v)
452 end;
454 begin
455 gAskLanguage := True;
456 e_WriteLog('Reading config', TMsgType.Notify);
457 g_Options_SetDefault;
459 if FileExists(FileName) = False then
460 begin
461 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
462 g_Options_SetDefaultVideo;
463 Exit
464 end;
466 config := TConfig.CreateFile(FileName);
468 section := 'Video';
469 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
470 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
471 ReadInteger(gWinRealPosX, 'WinPosX', 60);
472 ReadInteger(gWinRealPosY, 'WinPosY', 60);
473 ReadBoolean(gFullScreen, 'Fullscreen');
474 ReadBoolean(gWinMaximized, 'Maximized');
475 ReadInteger(gBPP, 'BPP', 0);
476 ReadInteger(gFreq, 'Freq', 0);
477 ReadBoolean(gVSync, 'VSync');
478 ReadBoolean(gTextureFilter, 'TextureFilter');
479 ReadBoolean(glLegacyNPOT, 'LegacyCompatible');
481 section := 'Sound';
482 ReadBoolean(gNoSound, 'NoSound');
483 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
484 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
485 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
486 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
487 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
488 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
489 ReadBoolean(gUseChatSounds, 'ChatSounds');
490 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
491 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
493 section := 'GameControls';
494 with gGameControls.GameControls do
495 begin
496 ReadInteger(TakeScreenshot, 'TakeScreenshot');
497 ReadInteger(Stat, 'Stat');
498 ReadInteger(Chat, 'Chat');
499 ReadInteger(TeamChat, 'TeamChat');
500 end;
502 section := 'Player1';
503 with gGameControls.P1Control do
504 begin
505 ReadInteger(KeyRight, 'KeyRight');
506 ReadInteger(KeyLeft, 'KeyLeft');
507 ReadInteger(KeyUp, 'KeyUp');
508 ReadInteger(KeyDown, 'KeyDown');
509 ReadInteger(KeyFire, 'KeyFire');
510 ReadInteger(KeyJump, 'KeyJump');
511 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
512 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
513 ReadInteger(KeyOpen, 'KeyOpen');
514 ReadInteger(KeyStrafe, 'KeyStrafe');
516 for i := 0 to High(KeyWeapon) do
517 begin
518 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
519 end;
521 ReadInteger(KeyRight2, 'KeyRight2');
522 ReadInteger(KeyLeft2, 'KeyLeft2');
523 ReadInteger(KeyUp2, 'KeyUp2');
524 ReadInteger(KeyDown2, 'KeyDown2');
525 ReadInteger(KeyFire2, 'KeyFire2');
526 ReadInteger(KeyJump2, 'KeyJump2');
527 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
528 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
529 ReadInteger(KeyOpen2, 'KeyOpen2');
530 ReadInteger(KeyStrafe2, 'KeyStrafe2');
532 for i := 0 to High(KeyWeapon2) do
533 begin
534 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
535 end;
536 end;
538 section := 'Player1';
539 with gPlayer1Settings do
540 begin
541 ReadString(Name, 'name');
542 ReadString(Model, 'model');
543 ReadInteger(Color.R, 'red', 0, 255);
544 ReadInteger(Color.G, 'green', 0, 255);
545 ReadInteger(Color.B, 'blue', 0, 255);
546 ReadInteger(Team, 'team');
547 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
548 Team := TEAM_RED;
549 end;
551 section := 'Player2';
552 with gGameControls.P2Control do
553 begin
554 ReadInteger(KeyRight, 'KeyRight');
555 ReadInteger(KeyLeft, 'KeyLeft');
556 ReadInteger(KeyUp, 'KeyUp');
557 ReadInteger(KeyDown, 'KeyDown');
558 ReadInteger(KeyFire, 'KeyFire');
559 ReadInteger(KeyJump, 'KeyJump');
560 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
561 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
562 ReadInteger(KeyOpen, 'KeyOpen');
563 ReadInteger(KeyStrafe, 'KeyStrafe');
565 for i := 0 to High(KeyWeapon) do
566 begin
567 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
568 end;
570 ReadInteger(KeyRight2, 'KeyRight2');
571 ReadInteger(KeyLeft2, 'KeyLeft2');
572 ReadInteger(KeyUp2, 'KeyUp2');
573 ReadInteger(KeyDown2, 'KeyDown2');
574 ReadInteger(KeyFire2, 'KeyFire2');
575 ReadInteger(KeyJump2, 'KeyJump2');
576 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
577 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
578 ReadInteger(KeyOpen2, 'KeyOpen2');
579 ReadInteger(KeyStrafe2, 'KeyStrafe2');
581 for i := 0 to High(KeyWeapon2) do
582 begin
583 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
584 end;
585 end;
587 section := 'Player2';
588 with gPlayer2Settings do
589 begin
590 ReadString(Name, 'name');
591 ReadString(Model, 'model');
592 ReadInteger(Color.R, 'red', 0, 255);
593 ReadInteger(Color.G, 'green', 0, 255);
594 ReadInteger(Color.B, 'blue', 0, 255);
595 ReadInteger(Team, 'team');
596 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
597 Team := TEAM_RED;
598 end;
600 section := 'Joysticks';
601 for i := 0 to e_MaxJoys - 1 do
602 begin
603 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
604 end;
606 section := 'Touch';
607 i := Trunc(g_touch_size * 10); ReadInteger(i, 'Size', 0); g_touch_size := i / 10;
608 ReadBoolean(g_touch_fire, 'Fire');
609 i := Round(g_touch_offset); ReadInteger(i, 'Offset', 0, 100); g_touch_offset := i;
610 ReadBoolean(g_touch_alt, 'Alt');
612 section := 'Game';
613 ReadInteger(i, 'MaxParticles', 1000, 50000); g_GFX_SetMax(i);
614 ReadInteger(i, 'MaxShells', 300, 600); g_Shells_SetMax(i);
615 ReadInteger(i, 'MaxGibs', 150, 500); g_Gibs_SetMax(i);
616 ReadInteger(i, 'MaxCorpses', 20, 100); g_Corpses_SetMax(i);
617 ReadInteger(i, 'GibsCount');
618 case i of
619 0: gGibsCount := 0;
620 1: gGibsCount := 8;
621 2: gGibsCount := 16;
622 3: gGibsCount := 32;
623 else gGibsCount := 48;
624 end;
625 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
626 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
627 ReadBoolean(gAdvBlood, 'AdvancesBlood');
628 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
629 ReadBoolean(gAdvGibs, 'AdvancesGibs');
630 ReadInteger(gFlash, 'Flash', 0, 2);
631 ReadBoolean(gDrawBackGround, 'BackGround');
632 ReadBoolean(gShowMessages, 'Messages');
633 ReadBoolean(gRevertPlayers, 'RevertPlayers');
634 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
635 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
636 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
637 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
638 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
639 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
640 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
641 ReadString(gLanguage, 'Language');
642 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
643 gAskLanguage := False
644 else
645 gLanguage := LANGUAGE_ENGLISH;
647 section := 'GameplayCustom';
648 ReadString(gcMap, 'Map');
649 ReadString(gcGameMode, 'GameMode');
650 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
651 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
652 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
653 ReadInteger(gcPlayers, 'Players', 0, 2);
654 ReadBoolean(gcTeamDamage, 'TeamDamage');
655 ReadBoolean(gcAllowExit, 'AllowExit');
656 ReadBoolean(gcWeaponStay, 'WeaponStay');
657 ReadBoolean(gcMonsters, 'Monsters');
658 ReadString(gcBotsVS, 'BotsVS');
660 with gGameSettings do
661 begin
662 GameMode := g_Game_TextToMode(gcGameMode);
663 if GameMode = GM_NONE then
664 GameMode := GM_DM;
665 if GameMode = GM_SINGLE then
666 GameMode := GM_COOP;
667 TimeLimit := gcTimeLimit;
668 GoalLimit := gcGoalLimit;
669 MaxLives := gcMaxLives;
671 Options := 0;
672 if gcTeamDamage then
673 Options := Options or GAME_OPTION_TEAMDAMAGE;
674 if gcAllowExit then
675 Options := Options or GAME_OPTION_ALLOWEXIT;
676 if gcWeaponStay then
677 Options := Options or GAME_OPTION_WEAPONSTAY;
678 if gcMonsters then
679 Options := Options or GAME_OPTION_MONSTERS;
680 if gcBotsVS = 'Everybody' then
681 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
682 if gcBotsVS = 'Players' then
683 Options := Options or GAME_OPTION_BOTVSPLAYER;
684 if gcBotsVS = 'Monsters' then
685 Options := Options or GAME_OPTION_BOTVSMONSTER;
686 end;
688 section := 'GameplayNetwork';
689 ReadString(gnMap, 'Map');
690 ReadString(gnGameMode, 'GameMode');
691 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
692 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
693 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
694 ReadInteger(gnPlayers, 'Players', 0, 2);
695 ReadBoolean(gnTeamDamage, 'TeamDamage');
696 ReadBoolean(gnAllowExit, 'AllowExit');
697 ReadBoolean(gnWeaponStay, 'WeaponStay');
698 ReadBoolean(gnMonsters, 'Monsters');
699 ReadString(gnBotsVS, 'BotsVS');
701 section := 'MasterServer';
702 ReadString(NetSlistIP, 'IP');
703 ReadInteger(NetSlistPort, 'Port', 0, 65535);
704 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
706 section := 'Server';
707 ReadString(NetServerName, 'Name');
708 ReadString(NetPassword, 'Password');
709 ReadInteger(NetPort, 'Port', 0, 65535);
710 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
711 ReadBoolean(NetAllowRCON, 'RCON');
712 ReadString(NetRCONPassword, 'RCONPassword');
713 ReadBoolean(NetUseMaster, 'SyncWithMaster');
714 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
715 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
716 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
717 ReadBoolean(NetForwardPorts, 'ForwardPorts');
719 section := 'Client';
720 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
721 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
722 ReadBoolean(NetPredictSelf, 'PredictSelf');
723 ReadString(NetClientIP, 'LastIP');
724 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
726 config.Free();
728 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
729 end;
731 procedure g_Options_Write(FileName: String);
732 var
733 config: TConfig;
734 i: Integer;
735 begin
736 e_WriteLog('Writing config', TMsgType.Notify);
738 config := TConfig.CreateFile(FileName);
740 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
741 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
742 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
743 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
744 config.WriteBool('Video', 'Fullscreen', gFullScreen);
745 config.WriteBool('Video', 'Maximized', gWinMaximized);
746 config.WriteInt('Video', 'BPP', gBPP);
747 config.WriteBool('Video', 'VSync', gVSync);
748 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
749 config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT);
751 config.WriteBool('Sound', 'NoSound', gNoSound);
752 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
753 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
754 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
755 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
756 config.WriteInt('Sound', 'Announcer', gAnnouncer);
757 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
758 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
759 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
760 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
762 with config, gGameControls.GameControls do
763 begin
764 WriteInt('GameControls', 'TakeScreenshot', TakeScreenshot);
765 WriteInt('GameControls', 'Stat', Stat);
766 WriteInt('GameControls', 'Chat', Chat);
767 WriteInt('GameControls', 'TeamChat', TeamChat);
768 end;
770 with config, gGameControls.P1Control, gPlayer1Settings do
771 begin
772 WriteInt('Player1', 'KeyRight', KeyRight);
773 WriteInt('Player1', 'KeyLeft', KeyLeft);
774 WriteInt('Player1', 'KeyUp', KeyUp);
775 WriteInt('Player1', 'KeyDown', KeyDown);
776 WriteInt('Player1', 'KeyFire', KeyFire);
777 WriteInt('Player1', 'KeyJump', KeyJump);
778 WriteInt('Player1', 'KeyNextWeapon', KeyNextWeapon);
779 WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon);
780 WriteInt('Player1', 'KeyOpen', KeyOpen);
781 WriteInt('Player1', 'KeyStrafe', KeyStrafe);
782 for i := 0 to High(KeyWeapon) do
783 WriteInt('Player1', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
785 WriteInt('Player1', 'KeyRight2', KeyRight2);
786 WriteInt('Player1', 'KeyLeft2', KeyLeft2);
787 WriteInt('Player1', 'KeyUp2', KeyUp2);
788 WriteInt('Player1', 'KeyDown2', KeyDown2);
789 WriteInt('Player1', 'KeyFire2', KeyFire2);
790 WriteInt('Player1', 'KeyJump2', KeyJump2);
791 WriteInt('Player1', 'KeyNextWeapon2', KeyNextWeapon2);
792 WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2);
793 WriteInt('Player1', 'KeyOpen2', KeyOpen2);
794 WriteInt('Player1', 'KeyStrafe2', KeyStrafe2);
795 for i := 0 to High(KeyWeapon2) do
796 WriteInt('Player1', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
798 WriteStr('Player1', 'Name', Name);
799 WriteStr('Player1', 'model', Model);
800 WriteInt('Player1', 'red', Color.R);
801 WriteInt('Player1', 'green', Color.G);
802 WriteInt('Player1', 'blue', Color.B);
803 WriteInt('Player1', 'team', Team);
804 end;
806 with config, gGameControls.P2Control, gPlayer2Settings do
807 begin
808 WriteInt('Player2', 'KeyRight', KeyRight);
809 WriteInt('Player2', 'KeyLeft', KeyLeft);
810 WriteInt('Player2', 'KeyUp', KeyUp);
811 WriteInt('Player2', 'KeyDown', KeyDown);
812 WriteInt('Player2', 'KeyFire', KeyFire);
813 WriteInt('Player2', 'KeyJump', KeyJump);
814 WriteInt('Player2', 'KeyNextWeapon', KeyNextWeapon);
815 WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon);
816 WriteInt('Player2', 'KeyOpen', KeyOpen);
817 WriteInt('Player2', 'KeyStrafe', KeyStrafe);
818 for i := 0 to High(KeyWeapon) do
819 WriteInt('Player2', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
821 WriteInt('Player2', 'KeyRight2', KeyRight2);
822 WriteInt('Player2', 'KeyLeft2', KeyLeft2);
823 WriteInt('Player2', 'KeyUp2', KeyUp2);
824 WriteInt('Player2', 'KeyDown2', KeyDown2);
825 WriteInt('Player2', 'KeyFire2', KeyFire2);
826 WriteInt('Player2', 'KeyJump2', KeyJump2);
827 WriteInt('Player2', 'KeyNextWeapon2', KeyNextWeapon2);
828 WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2);
829 WriteInt('Player2', 'KeyOpen2', KeyOpen2);
830 WriteInt('Player2', 'KeyStrafe2', KeyStrafe2);
831 for i := 0 to High(KeyWeapon2) do
832 WriteInt('Player2', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
834 WriteStr('Player2', 'Name', Name);
835 WriteStr('Player2', 'model', Model);
836 WriteInt('Player2', 'red', Color.R);
837 WriteInt('Player2', 'green', Color.G);
838 WriteInt('Player2', 'blue', Color.B);
839 WriteInt('Player2', 'team', Team);
840 end;
842 for i := 0 to e_MaxJoys-1 do
843 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
845 config.WriteInt('Touch', 'Size', Round(g_touch_size * 10));
846 config.WriteBool('Touch', 'Fire', g_touch_fire);
847 config.WriteInt('Touch', 'Offset', Round(g_touch_offset));
848 config.WriteBool('Touch', 'Alt', g_touch_alt);
850 with config do
851 case gGibsCount of
852 0: config.WriteInt('Game', 'GibsCount', 0);
853 8: config.WriteInt('Game', 'GibsCount', 1);
854 16: config.WriteInt('Game', 'GibsCount', 2);
855 32: config.WriteInt('Game', 'GibsCount', 3);
856 else config.WriteInt('Game', 'GibsCount', 4);
857 end;
859 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
860 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
861 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
862 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
863 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
864 config.WriteInt('Game', 'BloodCount', gBloodCount);
865 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
866 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
867 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
868 config.WriteInt('Game', 'Flash', gFlash);
869 config.WriteBool('Game', 'BackGround', gDrawBackGround);
870 config.WriteBool('Game', 'Messages', gShowMessages);
871 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
872 config.WriteInt('Game', 'ChatBubble', gChatBubble);
873 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
874 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
875 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
876 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
877 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
878 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
880 config.WriteStr ('GameplayCustom', 'Map', gcMap);
881 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
882 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
883 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
884 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
885 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
886 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
887 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
888 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
889 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
890 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
892 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
893 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
894 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
895 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
896 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
897 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
898 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
899 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
900 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
901 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
902 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
904 config.WriteStr('MasterServer', 'IP', NetSlistIP);
905 config.WriteInt('MasterServer', 'Port', NetSlistPort);
907 config.WriteStr ('Server', 'Name', NetServerName);
908 config.WriteStr ('Server', 'Password', NetPassword);
909 config.WriteInt ('Server', 'Port', NetPort);
910 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
911 config.WriteBool('Server', 'RCON', NetAllowRCON);
912 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
913 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
914 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
915 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
916 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
917 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
919 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
920 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
921 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
922 config.WriteStr ('Client', 'LastIP', NetClientIP);
923 config.WriteInt ('Client', 'LastPort', NetClientPort);
925 config.SaveFile(FileName);
926 config.Free();
927 end;
929 procedure g_Options_Write_Language(FileName: String);
930 var
931 config: TConfig;
932 begin
933 e_WriteLog('Writing language config', TMsgType.Notify);
935 config := TConfig.CreateFile(FileName);
936 config.WriteStr('Game', 'Language', gLanguage);
937 config.SaveFile(FileName);
938 config.Free();
939 end;
941 procedure g_Options_Write_Video(FileName: String);
942 var
943 config: TConfig;
944 sW, sH: Integer;
945 begin
946 e_WriteLog('Writing resolution to config', TMsgType.Notify);
948 config := TConfig.CreateFile(FileName);
950 if gWinMaximized and (not gFullscreen) then
951 begin
952 sW := gWinSizeX;
953 sH := gWinSizeY;
954 end
955 else
956 begin
957 sW := gScreenWidth;
958 sH := gScreenHeight;
959 end;
960 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
962 config.WriteInt('Video', 'ScreenWidth', sW);
963 config.WriteInt('Video', 'ScreenHeight', sH);
964 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
965 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
966 config.WriteBool('Video', 'Fullscreen', gFullscreen);
967 config.WriteBool('Video', 'Maximized', gWinMaximized);
969 config.SaveFile(FileName);
970 config.Free();
971 end;
973 procedure g_Options_Write_Gameplay_Custom(FileName: String);
974 var
975 config: TConfig;
976 begin
977 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
979 config := TConfig.CreateFile(FileName);
981 config.WriteStr ('GameplayCustom', 'Map', gcMap);
982 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
983 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
984 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
985 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
986 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
987 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
988 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
989 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
990 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
991 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
993 config.SaveFile(FileName);
994 config.Free();
995 end;
997 procedure g_Options_Write_Gameplay_Net(FileName: String);
998 var
999 config: TConfig;
1000 begin
1001 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
1003 config := TConfig.CreateFile(FileName);
1005 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
1006 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
1007 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
1008 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
1009 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
1010 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
1011 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
1012 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
1013 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
1014 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
1015 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
1017 config.SaveFile(FileName);
1018 config.Free();
1019 end;
1021 procedure g_Options_Write_Net_Server(FileName: String);
1022 var
1023 config: TConfig;
1024 begin
1025 e_WriteLog('Writing server config', TMsgType.Notify);
1027 config := TConfig.CreateFile(FileName);
1029 config.WriteStr ('Server', 'Name', NetServerName);
1030 config.WriteStr ('Server', 'Password', NetPassword);
1031 config.WriteInt ('Server', 'Port', NetPort);
1032 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
1033 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
1034 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
1036 config.SaveFile(FileName);
1037 config.Free();
1038 end;
1040 procedure g_Options_Write_Net_Client(FileName: String);
1041 var
1042 config: TConfig;
1043 begin
1044 e_WriteLog('Writing client config', TMsgType.Notify);
1046 config := TConfig.CreateFile(FileName);
1048 config.WriteStr('Client', 'LastIP', NetClientIP);
1049 config.WriteInt('Client', 'LastPort', NetClientPort);
1051 config.SaveFile(FileName);
1052 config.Free();
1053 end;
1055 initialization
1056 machine := Random(10000)
1057 end.