DEADSOFTWARE

Android: fix bad screen size when config not found
[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 procedure g_Options_SetDefault();
65 procedure g_Options_Read(FileName: String);
66 procedure g_Options_Write(FileName: String);
67 procedure g_Options_Write_Language(FileName: String);
68 procedure g_Options_Write_Video(FileName: String);
69 procedure g_Options_Write_Gameplay_Custom(FileName: String);
70 procedure g_Options_Write_Gameplay_Net(FileName: String);
71 procedure g_Options_Write_Net_Server(FileName: String);
72 procedure g_Options_Write_Net_Client(FileName: String);
74 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
76 var
77 gGameControls: TControls;
78 gScreenWidth: Word;
79 gScreenHeight: Word;
80 gWinRealPosX: Integer;
81 gWinRealPosY: Integer;
82 gBPP: Byte;
83 gFreq: Byte;
84 gFullscreen: Boolean;
85 gWinMaximized: Boolean;
86 gVSync: Boolean;
87 glLegacyNPOT: Boolean;
88 gTextureFilter: Boolean;
89 gNoSound: Boolean;
90 gSoundLevel: Byte;
91 gMusicLevel: Byte;
92 gMaxSimSounds: Byte;
93 gMuteWhenInactive: Boolean;
94 gAdvCorpses: Boolean;
95 gAdvBlood: Boolean;
96 gAdvGibs: Boolean;
97 gGibsCount: Integer;
98 gBloodCount: Byte;
99 gFlash: Byte;
100 gDrawBackGround: Boolean;
101 gShowMessages: Boolean;
102 gRevertPlayers: Boolean;
103 gLanguage: String;
104 gAskLanguage: Boolean;
105 gcMap: String;
106 gcGameMode: String;
107 gcTimeLimit: Word;
108 gcGoalLimit: Word;
109 gcMaxLives: Byte;
110 gcPlayers: Byte;
111 gcTeamDamage: Boolean;
112 gcAllowExit: Boolean;
113 gcWeaponStay: Boolean;
114 gcMonsters: Boolean;
115 gcBotsVS: String;
116 gnMap: String;
117 gnGameMode: String;
118 gnTimeLimit: Word;
119 gnGoalLimit: Word;
120 gnMaxLives: Byte;
121 gnPlayers: Byte;
122 gnTeamDamage: Boolean;
123 gnAllowExit: Boolean;
124 gnWeaponStay: Boolean;
125 gnMonsters: Boolean;
126 gnBotsVS: String;
127 gsSDLSampleRate: Integer;
128 gsSDLBufferSize: Integer;
129 gSFSDebug: Boolean;
130 gSFSFastMode: Boolean;
131 gDefaultMegawadStart: AnsiString;
132 gBerserkAutoswitch: Boolean;
134 implementation
136 uses
137 {$INCLUDE ../nogl/noGLuses.inc}
138 e_log, e_input, g_window, g_sound, g_gfx, g_player, Math,
139 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
140 g_items, wadreader, e_graphics, g_touch, SDL2;
142 procedure g_Options_SetDefaultVideo;
143 {$IF DEFINED(ANDROID)}
144 var
145 display: TSDL_DisplayMode;
146 {$ENDIF}
147 begin
148 {$IF DEFINED(ANDROID)}
149 (* On android set max screen size *)
150 SDL_GetCurrentDisplayMode(0, @display);
151 gScreenWidth := display.w;
152 gScreenHeight := display.h;
153 gWinRealPosX := 0;
154 gWinRealPosY := 0;
155 gWinMaximized := False;
156 gFullScreen := False; (* if True then rotation not allowed *)
157 gBPP := 32;
158 gVSync := True;
159 gTextureFilter := True;
160 glLegacyNPOT := False;
161 {$ELSE}
162 (* On other systems use default 800x600 *)
163 gScreenWidth := 800;
164 gScreenHeight := 600;
165 gWinRealPosX := 0;
166 gWinRealPosY := 0;
167 gWinMaximized := False;
168 gFullScreen := False;
169 gBPP := 32;
170 gVSync := True;
171 gTextureFilter := True;
172 glLegacyNPOT := False;
173 {$ENDIF}
174 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
175 end;
177 procedure g_Options_SetDefault();
178 var
179 i: Integer;
180 begin
181 (* section Sound *)
182 gNoSound := False;
183 gSoundLevel := 75;
184 gMusicLevel := 65;
185 gMaxSimSounds := 8;
186 gMuteWhenInactive := False;
187 gAnnouncer := ANNOUNCE_MEPLUS;
188 gSoundEffectsDF := True;
189 gUseChatSounds := True;
190 gsSDLSampleRate := 44100;
191 gsSDLBufferSize := 2048;
193 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
195 (* section GameControls *)
196 with gGameControls.GameControls do
197 begin
198 TakeScreenshot := SDL_SCANCODE_F12;
199 Stat := SDL_SCANCODE_TAB;
200 Chat := SDL_SCANCODE_T;
201 TeamChat := SDL_SCANCODE_Y;
202 end;
204 (* section Player1 *)
205 with gGameControls.P1Control do
206 begin
207 KeyRight := SDL_SCANCODE_KP_6;
208 KeyLeft := SDL_SCANCODE_KP_4;
209 KeyUp := SDL_SCANCODE_KP_8;
210 KeyDown := SDL_SCANCODE_KP_5;
211 KeyFire := SDL_SCANCODE_SLASH;
212 KeyJump := SDL_SCANCODE_RCTRL;
213 KeyNextWeapon := SDL_SCANCODE_KP_9;
214 KeyPrevWeapon := SDL_SCANCODE_KP_7;
215 KeyOpen := SDL_SCANCODE_RSHIFT;
216 KeyStrafe := SDL_SCANCODE_PERIOD;
218 for i := 0 to 9 do
219 begin
220 KeyWeapon[i] := SDL_SCANCODE_1 + i (* 1, ..., 9, 0 *)
221 end;
222 KeyWeapon[10] := SDL_SCANCODE_MINUS;
223 for i := 11 to High(KeyWeapon) do
224 begin
225 KeyWeapon[i] := 0
226 end;
228 KeyRight2 := VK_RIGHT;
229 KeyLeft2 := VK_LEFT;
230 KeyUp2 := VK_UP;
231 KeyDown2 := VK_DOWN;
232 KeyFire2 := VK_FIRE;
233 KeyJump2 := VK_JUMP;
234 KeyNextWeapon2 := VK_NEXT;
235 KeyPrevWeapon2 := VK_PREV;
236 KeyOpen2 := VK_OPEN;
237 KeyStrafe2 := VK_STRAFE;
239 for i := 0 to High(KeyWeapon2) do
240 begin
241 KeyWeapon2[i] := VK_0 + i
242 end;
243 end;
245 with gPlayer1Settings do
246 begin
247 Name := 'Player1';
248 Model := STD_PLAYER_MODEL;
249 Color.R := PLAYER1_DEF_COLOR.R;
250 Color.G := PLAYER1_DEF_COLOR.G;
251 Color.B := PLAYER1_DEF_COLOR.B;
252 Team := TEAM_RED;
253 end;
255 (* section Player2 *)
256 with gGameControls.P2Control do
257 begin
258 KeyRight := SDL_SCANCODE_D;
259 KeyLeft := SDL_SCANCODE_A;
260 KeyUp := SDL_SCANCODE_W;
261 KeyDown := SDL_SCANCODE_S;
262 KeyFire := SDL_SCANCODE_G;
263 KeyJump := SDL_SCANCODE_SPACE;
264 KeyNextWeapon := SDL_SCANCODE_E;
265 KeyPrevWeapon := SDL_SCANCODE_Q;
266 KeyOpen := SDL_SCANCODE_F;
267 KeyStrafe := SDL_SCANCODE_LSHIFT;
268 for i := 0 to High(KeyWeapon) do
269 begin
270 KeyWeapon[i] := 0
271 end;
273 KeyRight2 := 0;
274 KeyLeft2 := 0;
275 KeyUp2 := 0;
276 KeyDown2 := 0;
277 KeyFire2 := 0;
278 KeyJump2 := 0;
279 KeyNextWeapon2 := 0;
280 KeyPrevWeapon2 := 0;
281 KeyOpen2 := 0;
282 KeyStrafe2 := 0;
284 for i := 0 to High(KeyWeapon2) do
285 begin
286 KeyWeapon2[i] := 0;
287 end
288 end;
290 with gPlayer2Settings do
291 begin
292 Name := 'Player2';
293 Model := STD_PLAYER_MODEL;
294 Color.R := PLAYER2_DEF_COLOR.R;
295 Color.G := PLAYER2_DEF_COLOR.G;
296 Color.B := PLAYER2_DEF_COLOR.B;
297 Team := TEAM_BLUE;
298 end;
300 (* section Joysticks *)
301 for i := 0 to e_MaxJoys - 1 do
302 begin
303 e_JoystickDeadzones[i] := 8192
304 end;
306 (* section Touch *)
307 g_touch_size := 1.0;
308 g_touch_fire := True;
309 g_touch_offset := 50;
310 g_touch_alt := False;
312 (* section Game *)
313 g_GFX_SetMax(2000);
314 g_Shells_SetMax(300);
315 g_Gibs_SetMax(150);
316 g_Corpses_SetMax(20);
317 gGibsCount := 32;
318 ITEM_RESPAWNTIME := 60 * 36;
319 gBloodCount := 4;
320 gAdvBlood := True;
321 gAdvCorpses := True;
322 gAdvGibs := True;
323 gFlash := 1;
324 gDrawBackGround := True;
325 gShowMessages := True;
326 gRevertPlayers := False;
327 gChatBubble := 4;
328 gSFSDebug := False;
329 gSFSFastMode := False;
330 e_FastScreenshots := True;
331 gDefaultMegawadStart := DF_Default_Megawad_Start;
332 gBerserkAutoswitch := True;
333 g_dbg_scale := 1.0;
335 gAskLanguage := True;
336 gLanguage := LANGUAGE_ENGLISH;
338 (* section GameplayCustom *)
339 gcMap := '';
340 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
341 gcTimeLimit := 0;
342 gcGoalLimit := 0;
343 gcMaxLives := 0;
344 gcPlayers := 1;
345 gcTeamDamage := False;
346 gcAllowExit := True;
347 gcWeaponStay := False;
348 gcMonsters := False;
349 gcBotsVS := 'Everybody';
351 (* section GameplayNetwork *)
352 gnMap := '';
353 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
354 gnTimeLimit := 0;
355 gnGoalLimit := 0;
356 gnMaxLives := 0;
357 gnPlayers := 1;
358 gnTeamDamage := False;
359 gnAllowExit := True;
360 gnWeaponStay := False;
361 gnMonsters := False;
362 gnBotsVS := 'Everybody';
364 (* section MasterServer *)
365 NetSlistIP := 'mpms.doom2d.org';
366 NetSlistPort := 25665;
367 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
369 (* section Server *)
370 NetServerName := 'Unnamed Server';
371 NetPassword := '';
372 NetPort := 25666;
373 NetMaxClients := 16;
374 NetAllowRCON := False;
375 NetRCONPassword := 'default';
376 NetUseMaster := True;
377 NetUpdateRate := 0;
378 NetRelupdRate := 18;
379 NetMasterRate := 60000;
380 NetForwardPorts := False;
382 (* section Client *)
383 NetInterpLevel := 2;
384 NetForcePlayerUpdate := False;
385 NetPredictSelf := True;
386 NetClientIP := '127.0.0.1';
387 NetClientPort := NetPort;
388 end;
390 procedure g_Options_Read(FileName: String);
391 var
392 i: Integer;
393 config: TConfig;
394 section: String;
396 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
397 begin
398 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
399 end;
401 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
402 begin
403 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
404 end;
406 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
407 begin
408 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
409 end;
411 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
412 begin
413 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
414 end;
416 procedure ReadBoolean (VAR v: Boolean; param: String);
417 begin
418 v := config.ReadBool(section, param, v)
419 end;
421 procedure ReadString (VAR v: String; param: String);
422 begin
423 v := config.ReadStr(section, param, v)
424 end;
426 begin
427 gAskLanguage := True;
428 e_WriteLog('Reading config', TMsgType.Notify);
429 g_Options_SetDefault;
431 if FileExists(FileName) = False then
432 begin
433 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
434 g_Options_SetDefaultVideo;
435 Exit
436 end;
438 config := TConfig.CreateFile(FileName);
440 section := 'Video';
441 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
442 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
443 ReadInteger(gWinRealPosX, 'WinPosX', 60);
444 ReadInteger(gWinRealPosY, 'WinPosY', 60);
445 ReadBoolean(gFullScreen, 'Fullscreen');
446 ReadBoolean(gWinMaximized, 'Maximized');
447 ReadInteger(gBPP, 'BPP', 0);
448 ReadInteger(gFreq, 'Freq', 0);
449 ReadBoolean(gVSync, 'VSync');
450 ReadBoolean(gTextureFilter, 'TextureFilter');
451 ReadBoolean(glLegacyNPOT, 'LegacyCompatible');
453 section := 'Sound';
454 ReadBoolean(gNoSound, 'NoSound');
455 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
456 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
457 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
458 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
459 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
460 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
461 ReadBoolean(gUseChatSounds, 'ChatSounds');
462 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
463 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
465 section := 'GameControls';
466 with gGameControls.GameControls do
467 begin
468 ReadInteger(TakeScreenshot, 'TakeScreenshot');
469 ReadInteger(Stat, 'Stat');
470 ReadInteger(Chat, 'Chat');
471 ReadInteger(TeamChat, 'TeamChat');
472 end;
474 section := 'Player1';
475 with gGameControls.P1Control do
476 begin
477 ReadInteger(KeyRight, 'KeyRight');
478 ReadInteger(KeyLeft, 'KeyLeft');
479 ReadInteger(KeyUp, 'KeyUp');
480 ReadInteger(KeyDown, 'KeyDown');
481 ReadInteger(KeyFire, 'KeyFire');
482 ReadInteger(KeyJump, 'KeyJump');
483 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
484 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
485 ReadInteger(KeyOpen, 'KeyOpen');
486 ReadInteger(KeyStrafe, 'KeyStrafe');
488 for i := 0 to High(KeyWeapon) do
489 begin
490 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
491 end;
493 ReadInteger(KeyRight2, 'KeyRight2');
494 ReadInteger(KeyLeft2, 'KeyLeft2');
495 ReadInteger(KeyUp2, 'KeyUp2');
496 ReadInteger(KeyDown2, 'KeyDown2');
497 ReadInteger(KeyFire2, 'KeyFire2');
498 ReadInteger(KeyJump2, 'KeyJump2');
499 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
500 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
501 ReadInteger(KeyOpen2, 'KeyOpen2');
502 ReadInteger(KeyStrafe2, 'KeyStrafe2');
504 for i := 0 to High(KeyWeapon2) do
505 begin
506 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
507 end;
508 end;
510 section := 'Player1';
511 with gPlayer1Settings do
512 begin
513 ReadString(Name, 'name');
514 ReadString(Model, 'model');
515 ReadInteger(Color.R, 'red', 0, 255);
516 ReadInteger(Color.G, 'green', 0, 255);
517 ReadInteger(Color.B, 'blue', 0, 255);
518 ReadInteger(Team, 'team');
519 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
520 Team := TEAM_RED;
521 end;
523 section := 'Player2';
524 with gGameControls.P2Control do
525 begin
526 ReadInteger(KeyRight, 'KeyRight');
527 ReadInteger(KeyLeft, 'KeyLeft');
528 ReadInteger(KeyUp, 'KeyUp');
529 ReadInteger(KeyDown, 'KeyDown');
530 ReadInteger(KeyFire, 'KeyFire');
531 ReadInteger(KeyJump, 'KeyJump');
532 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
533 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
534 ReadInteger(KeyOpen, 'KeyOpen');
535 ReadInteger(KeyStrafe, 'KeyStrafe');
537 for i := 0 to High(KeyWeapon) do
538 begin
539 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
540 end;
542 ReadInteger(KeyRight2, 'KeyRight2');
543 ReadInteger(KeyLeft2, 'KeyLeft2');
544 ReadInteger(KeyUp2, 'KeyUp2');
545 ReadInteger(KeyDown2, 'KeyDown2');
546 ReadInteger(KeyFire2, 'KeyFire2');
547 ReadInteger(KeyJump2, 'KeyJump2');
548 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
549 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
550 ReadInteger(KeyOpen2, 'KeyOpen2');
551 ReadInteger(KeyStrafe2, 'KeyStrafe2');
553 for i := 0 to High(KeyWeapon2) do
554 begin
555 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
556 end;
557 end;
559 section := 'Player2';
560 with gPlayer2Settings do
561 begin
562 ReadString(Name, 'name');
563 ReadString(Model, 'model');
564 ReadInteger(Color.R, 'red', 0, 255);
565 ReadInteger(Color.G, 'green', 0, 255);
566 ReadInteger(Color.B, 'blue', 0, 255);
567 ReadInteger(Team, 'team');
568 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
569 Team := TEAM_RED;
570 end;
572 section := 'Joysticks';
573 for i := 0 to e_MaxJoys - 1 do
574 begin
575 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
576 end;
578 section := 'Touch';
579 i := Trunc(g_touch_size * 10); ReadInteger(i, 'Size', 0); g_touch_size := i / 10;
580 ReadBoolean(g_touch_fire, 'Fire');
581 i := Round(g_touch_offset); ReadInteger(i, 'Offset', 0, 100); g_touch_offset := i;
582 ReadBoolean(g_touch_alt, 'Alt');
584 section := 'Game';
585 ReadInteger(i, 'MaxParticles', 1000, 50000); g_GFX_SetMax(i);
586 ReadInteger(i, 'MaxShells', 300, 600); g_Shells_SetMax(i);
587 ReadInteger(i, 'MaxGibs', 150, 500); g_Gibs_SetMax(i);
588 ReadInteger(i, 'MaxCorpses', 20, 100); g_Corpses_SetMax(i);
589 ReadInteger(i, 'GibsCount');
590 case i of
591 0: gGibsCount := 0;
592 1: gGibsCount := 8;
593 2: gGibsCount := 16;
594 3: gGibsCount := 32;
595 else gGibsCount := 48;
596 end;
597 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
598 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
599 ReadBoolean(gAdvBlood, 'AdvancesBlood');
600 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
601 ReadBoolean(gAdvGibs, 'AdvancesGibs');
602 ReadInteger(gFlash, 'Flash', 0, 2);
603 ReadBoolean(gDrawBackGround, 'BackGround');
604 ReadBoolean(gShowMessages, 'Messages');
605 ReadBoolean(gRevertPlayers, 'RevertPlayers');
606 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
607 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
608 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
609 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
610 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
611 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
612 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
613 ReadString(gLanguage, 'Language');
614 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
615 gAskLanguage := False
616 else
617 gLanguage := LANGUAGE_ENGLISH;
619 section := 'GameplayCustom';
620 ReadString(gcMap, 'Map');
621 ReadString(gcGameMode, 'GameMode');
622 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
623 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
624 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
625 ReadInteger(gcPlayers, 'Players', 0, 2);
626 ReadBoolean(gcTeamDamage, 'TeamDamage');
627 ReadBoolean(gcAllowExit, 'AllowExit');
628 ReadBoolean(gcWeaponStay, 'WeaponStay');
629 ReadBoolean(gcMonsters, 'Monsters');
630 ReadString(gcBotsVS, 'BotsVS');
632 with gGameSettings do
633 begin
634 GameMode := g_Game_TextToMode(gcGameMode);
635 if GameMode = GM_NONE then
636 GameMode := GM_DM;
637 if GameMode = GM_SINGLE then
638 GameMode := GM_COOP;
639 TimeLimit := gcTimeLimit;
640 GoalLimit := gcGoalLimit;
641 MaxLives := gcMaxLives;
643 Options := 0;
644 if gcTeamDamage then
645 Options := Options or GAME_OPTION_TEAMDAMAGE;
646 if gcAllowExit then
647 Options := Options or GAME_OPTION_ALLOWEXIT;
648 if gcWeaponStay then
649 Options := Options or GAME_OPTION_WEAPONSTAY;
650 if gcMonsters then
651 Options := Options or GAME_OPTION_MONSTERS;
652 if gcBotsVS = 'Everybody' then
653 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
654 if gcBotsVS = 'Players' then
655 Options := Options or GAME_OPTION_BOTVSPLAYER;
656 if gcBotsVS = 'Monsters' then
657 Options := Options or GAME_OPTION_BOTVSMONSTER;
658 end;
660 section := 'GameplayNetwork';
661 ReadString(gnMap, 'Map');
662 ReadString(gnGameMode, 'GameMode');
663 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
664 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
665 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
666 ReadInteger(gnPlayers, 'Players', 0, 2);
667 ReadBoolean(gnTeamDamage, 'TeamDamage');
668 ReadBoolean(gnAllowExit, 'AllowExit');
669 ReadBoolean(gnWeaponStay, 'WeaponStay');
670 ReadBoolean(gnMonsters, 'Monsters');
671 ReadString(gnBotsVS, 'BotsVS');
673 section := 'MasterServer';
674 ReadString(NetSlistIP, 'IP');
675 ReadInteger(NetSlistPort, 'Port', 0, 65535);
676 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
678 section := 'Server';
679 ReadString(NetServerName, 'Name');
680 ReadString(NetPassword, 'Password');
681 ReadInteger(NetPort, 'Port', 0, 65535);
682 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
683 ReadBoolean(NetAllowRCON, 'RCON');
684 ReadString(NetRCONPassword, 'RCONPassword');
685 ReadBoolean(NetUseMaster, 'SyncWithMaster');
686 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
687 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
688 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
689 ReadBoolean(NetForwardPorts, 'ForwardPorts');
691 section := 'Client';
692 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
693 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
694 ReadBoolean(NetPredictSelf, 'PredictSelf');
695 ReadString(NetClientIP, 'LastIP');
696 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
698 config.Free();
700 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
701 end;
703 procedure g_Options_Write(FileName: String);
704 var
705 config: TConfig;
706 i: Integer;
707 begin
708 e_WriteLog('Writing config', TMsgType.Notify);
710 config := TConfig.CreateFile(FileName);
712 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
713 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
714 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
715 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
716 config.WriteBool('Video', 'Fullscreen', gFullScreen);
717 config.WriteBool('Video', 'Maximized', gWinMaximized);
718 config.WriteInt('Video', 'BPP', gBPP);
719 config.WriteBool('Video', 'VSync', gVSync);
720 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
721 config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT);
723 config.WriteBool('Sound', 'NoSound', gNoSound);
724 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
725 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
726 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
727 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
728 config.WriteInt('Sound', 'Announcer', gAnnouncer);
729 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
730 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
731 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
732 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
734 with config, gGameControls.GameControls do
735 begin
736 WriteInt('GameControls', 'TakeScreenshot', TakeScreenshot);
737 WriteInt('GameControls', 'Stat', Stat);
738 WriteInt('GameControls', 'Chat', Chat);
739 WriteInt('GameControls', 'TeamChat', TeamChat);
740 end;
742 with config, gGameControls.P1Control, gPlayer1Settings do
743 begin
744 WriteInt('Player1', 'KeyRight', KeyRight);
745 WriteInt('Player1', 'KeyLeft', KeyLeft);
746 WriteInt('Player1', 'KeyUp', KeyUp);
747 WriteInt('Player1', 'KeyDown', KeyDown);
748 WriteInt('Player1', 'KeyFire', KeyFire);
749 WriteInt('Player1', 'KeyJump', KeyJump);
750 WriteInt('Player1', 'KeyNextWeapon', KeyNextWeapon);
751 WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon);
752 WriteInt('Player1', 'KeyOpen', KeyOpen);
753 WriteInt('Player1', 'KeyStrafe', KeyStrafe);
754 for i := 0 to High(KeyWeapon) do
755 WriteInt('Player1', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
757 WriteInt('Player1', 'KeyRight2', KeyRight2);
758 WriteInt('Player1', 'KeyLeft2', KeyLeft2);
759 WriteInt('Player1', 'KeyUp2', KeyUp2);
760 WriteInt('Player1', 'KeyDown2', KeyDown2);
761 WriteInt('Player1', 'KeyFire2', KeyFire2);
762 WriteInt('Player1', 'KeyJump2', KeyJump2);
763 WriteInt('Player1', 'KeyNextWeapon2', KeyNextWeapon2);
764 WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2);
765 WriteInt('Player1', 'KeyOpen2', KeyOpen2);
766 WriteInt('Player1', 'KeyStrafe2', KeyStrafe2);
767 for i := 0 to High(KeyWeapon2) do
768 WriteInt('Player1', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
770 WriteStr('Player1', 'Name', Name);
771 WriteStr('Player1', 'model', Model);
772 WriteInt('Player1', 'red', Color.R);
773 WriteInt('Player1', 'green', Color.G);
774 WriteInt('Player1', 'blue', Color.B);
775 WriteInt('Player1', 'team', Team);
776 end;
778 with config, gGameControls.P2Control, gPlayer2Settings do
779 begin
780 WriteInt('Player2', 'KeyRight', KeyRight);
781 WriteInt('Player2', 'KeyLeft', KeyLeft);
782 WriteInt('Player2', 'KeyUp', KeyUp);
783 WriteInt('Player2', 'KeyDown', KeyDown);
784 WriteInt('Player2', 'KeyFire', KeyFire);
785 WriteInt('Player2', 'KeyJump', KeyJump);
786 WriteInt('Player2', 'KeyNextWeapon', KeyNextWeapon);
787 WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon);
788 WriteInt('Player2', 'KeyOpen', KeyOpen);
789 WriteInt('Player2', 'KeyStrafe', KeyStrafe);
790 for i := 0 to High(KeyWeapon) do
791 WriteInt('Player2', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
793 WriteInt('Player2', 'KeyRight2', KeyRight2);
794 WriteInt('Player2', 'KeyLeft2', KeyLeft2);
795 WriteInt('Player2', 'KeyUp2', KeyUp2);
796 WriteInt('Player2', 'KeyDown2', KeyDown2);
797 WriteInt('Player2', 'KeyFire2', KeyFire2);
798 WriteInt('Player2', 'KeyJump2', KeyJump2);
799 WriteInt('Player2', 'KeyNextWeapon2', KeyNextWeapon2);
800 WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2);
801 WriteInt('Player2', 'KeyOpen2', KeyOpen2);
802 WriteInt('Player2', 'KeyStrafe2', KeyStrafe2);
803 for i := 0 to High(KeyWeapon2) do
804 WriteInt('Player2', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
806 WriteStr('Player2', 'Name', Name);
807 WriteStr('Player2', 'model', Model);
808 WriteInt('Player2', 'red', Color.R);
809 WriteInt('Player2', 'green', Color.G);
810 WriteInt('Player2', 'blue', Color.B);
811 WriteInt('Player2', 'team', Team);
812 end;
814 for i := 0 to e_MaxJoys-1 do
815 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
817 config.WriteInt('Touch', 'Size', Round(g_touch_size * 10));
818 config.WriteBool('Touch', 'Fire', g_touch_fire);
819 config.WriteInt('Touch', 'Offset', Round(g_touch_offset));
820 config.WriteBool('Touch', 'Alt', g_touch_alt);
822 with config do
823 case gGibsCount of
824 0: config.WriteInt('Game', 'GibsCount', 0);
825 8: config.WriteInt('Game', 'GibsCount', 1);
826 16: config.WriteInt('Game', 'GibsCount', 2);
827 32: config.WriteInt('Game', 'GibsCount', 3);
828 else config.WriteInt('Game', 'GibsCount', 4);
829 end;
831 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
832 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
833 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
834 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
835 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
836 config.WriteInt('Game', 'BloodCount', gBloodCount);
837 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
838 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
839 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
840 config.WriteInt('Game', 'Flash', gFlash);
841 config.WriteBool('Game', 'BackGround', gDrawBackGround);
842 config.WriteBool('Game', 'Messages', gShowMessages);
843 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
844 config.WriteInt('Game', 'ChatBubble', gChatBubble);
845 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
846 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
847 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
848 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
849 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
850 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
852 config.WriteStr ('GameplayCustom', 'Map', gcMap);
853 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
854 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
855 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
856 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
857 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
858 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
859 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
860 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
861 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
862 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
864 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
865 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
866 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
867 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
868 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
869 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
870 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
871 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
872 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
873 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
874 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
876 config.WriteStr('MasterServer', 'IP', NetSlistIP);
877 config.WriteInt('MasterServer', 'Port', NetSlistPort);
879 config.WriteStr ('Server', 'Name', NetServerName);
880 config.WriteStr ('Server', 'Password', NetPassword);
881 config.WriteInt ('Server', 'Port', NetPort);
882 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
883 config.WriteBool('Server', 'RCON', NetAllowRCON);
884 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
885 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
886 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
887 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
888 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
889 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
891 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
892 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
893 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
894 config.WriteStr ('Client', 'LastIP', NetClientIP);
895 config.WriteInt ('Client', 'LastPort', NetClientPort);
897 config.SaveFile(FileName);
898 config.Free();
899 end;
901 procedure g_Options_Write_Language(FileName: String);
902 var
903 config: TConfig;
904 begin
905 e_WriteLog('Writing language config', TMsgType.Notify);
907 config := TConfig.CreateFile(FileName);
908 config.WriteStr('Game', 'Language', gLanguage);
909 config.SaveFile(FileName);
910 config.Free();
911 end;
913 procedure g_Options_Write_Video(FileName: String);
914 var
915 config: TConfig;
916 sW, sH: Integer;
917 begin
918 e_WriteLog('Writing resolution to config', TMsgType.Notify);
920 config := TConfig.CreateFile(FileName);
922 if gWinMaximized and (not gFullscreen) then
923 begin
924 sW := gWinSizeX;
925 sH := gWinSizeY;
926 end
927 else
928 begin
929 sW := gScreenWidth;
930 sH := gScreenHeight;
931 end;
932 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
934 config.WriteInt('Video', 'ScreenWidth', sW);
935 config.WriteInt('Video', 'ScreenHeight', sH);
936 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
937 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
938 config.WriteBool('Video', 'Fullscreen', gFullscreen);
939 config.WriteBool('Video', 'Maximized', gWinMaximized);
941 config.SaveFile(FileName);
942 config.Free();
943 end;
945 procedure g_Options_Write_Gameplay_Custom(FileName: String);
946 var
947 config: TConfig;
948 begin
949 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
951 config := TConfig.CreateFile(FileName);
953 config.WriteStr ('GameplayCustom', 'Map', gcMap);
954 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
955 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
956 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
957 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
958 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
959 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
960 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
961 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
962 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
963 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
965 config.SaveFile(FileName);
966 config.Free();
967 end;
969 procedure g_Options_Write_Gameplay_Net(FileName: String);
970 var
971 config: TConfig;
972 begin
973 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
975 config := TConfig.CreateFile(FileName);
977 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
978 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
979 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
980 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
981 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
982 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
983 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
984 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
985 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
986 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
987 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
989 config.SaveFile(FileName);
990 config.Free();
991 end;
993 procedure g_Options_Write_Net_Server(FileName: String);
994 var
995 config: TConfig;
996 begin
997 e_WriteLog('Writing server config', TMsgType.Notify);
999 config := TConfig.CreateFile(FileName);
1001 config.WriteStr ('Server', 'Name', NetServerName);
1002 config.WriteStr ('Server', 'Password', NetPassword);
1003 config.WriteInt ('Server', 'Port', NetPort);
1004 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
1005 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
1006 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
1008 config.SaveFile(FileName);
1009 config.Free();
1010 end;
1012 procedure g_Options_Write_Net_Client(FileName: String);
1013 var
1014 config: TConfig;
1015 begin
1016 e_WriteLog('Writing client config', TMsgType.Notify);
1018 config := TConfig.CreateFile(FileName);
1020 config.WriteStr('Client', 'LastIP', NetClientIP);
1021 config.WriteInt('Client', 'LastPort', NetClientPort);
1023 config.SaveFile(FileName);
1024 config.Free();
1025 end;
1027 end.