DEADSOFTWARE

2e268a0c3e69317b51a1a76bf05b607082479889
[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
152 Result := 'Player' + IntToStr(machine MOD 10000);
153 if n = 1 then
154 Result := Copy(Result, 1, 12) + ' '
155 else
156 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
157 end;
159 procedure g_Options_SetDefaultVideo;
160 var
161 target, closest, display: TSDL_DisplayMode;
162 percentage: Integer;
163 begin
164 (* Display 0 = Primary display *)
165 SDL_GetDesktopDisplayMode(0, @display);
166 {$IF DEFINED(ANDROID)}
167 gScreenWidth := display.w;
168 gScreenHeight := display.h;
169 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
170 gBPP := 32;
171 gFullScreen := True; (* rotation not allowed? *)
172 {$ELSE}
173 (* Window must be smaller than display *)
174 closest.w := display.w;
175 closest.h := display.h;
176 percentage := 75;
177 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
178 begin
179 if percentage < 25 then
180 begin
181 closest.w := display.w * 75 div 100;
182 closest.h := display.h * 75 div 100;
183 break;
184 end;
185 target.w := display.w * percentage div 100;
186 target.h := display.h * percentage div 100;
187 target.format := 0; (* didn't care *)
188 target.refresh_rate := 0; (* didn't care *)
189 target.driverdata := nil; (* init *)
190 SDL_GetClosestDisplayMode(0, @target, @closest);
191 Dec(percentage);
192 end;
193 gScreenWidth := closest.w;
194 gScreenHeight := closest.h;
195 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
196 gBPP := 32;
197 gFullScreen := False;
198 {$ENDIF}
199 (* Must be positioned on primary display *)
200 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
201 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
202 gWinMaximized := False;
203 gVSync := True;
204 gTextureFilter := True;
205 glLegacyNPOT := False;
206 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
207 end;
209 procedure g_Options_SetDefault();
210 var
211 i: Integer;
212 begin
213 (* section Sound *)
214 gNoSound := False;
215 gSoundLevel := 75;
216 gMusicLevel := 65;
217 gMaxSimSounds := 8;
218 gMuteWhenInactive := False;
219 gAnnouncer := ANNOUNCE_MEPLUS;
220 gSoundEffectsDF := True;
221 gUseChatSounds := True;
222 gsSDLSampleRate := 44100;
223 gsSDLBufferSize := 2048;
225 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
227 (* section GameControls *)
228 with gGameControls.GameControls do
229 begin
230 TakeScreenshot := SDL_SCANCODE_F12;
231 Stat := SDL_SCANCODE_TAB;
232 Chat := SDL_SCANCODE_T;
233 TeamChat := SDL_SCANCODE_Y;
234 end;
236 (* section Player1 *)
237 with gGameControls.P1Control do
238 begin
239 KeyRight := SDL_SCANCODE_KP_6;
240 KeyLeft := SDL_SCANCODE_KP_4;
241 KeyUp := SDL_SCANCODE_KP_8;
242 KeyDown := SDL_SCANCODE_KP_5;
243 KeyFire := SDL_SCANCODE_SLASH;
244 KeyJump := SDL_SCANCODE_RCTRL;
245 KeyNextWeapon := SDL_SCANCODE_KP_9;
246 KeyPrevWeapon := SDL_SCANCODE_KP_7;
247 KeyOpen := SDL_SCANCODE_RSHIFT;
248 KeyStrafe := SDL_SCANCODE_PERIOD;
250 for i := 0 to 9 do
251 begin
252 KeyWeapon[i] := SDL_SCANCODE_1 + i (* 1, ..., 9, 0 *)
253 end;
254 KeyWeapon[10] := SDL_SCANCODE_MINUS;
255 for i := 11 to High(KeyWeapon) do
256 begin
257 KeyWeapon[i] := 0
258 end;
260 KeyRight2 := VK_RIGHT;
261 KeyLeft2 := VK_LEFT;
262 KeyUp2 := VK_UP;
263 KeyDown2 := VK_DOWN;
264 KeyFire2 := VK_FIRE;
265 KeyJump2 := VK_JUMP;
266 KeyNextWeapon2 := VK_NEXT;
267 KeyPrevWeapon2 := VK_PREV;
268 KeyOpen2 := VK_OPEN;
269 KeyStrafe2 := VK_STRAFE;
271 for i := 0 to High(KeyWeapon2) do
272 begin
273 KeyWeapon2[i] := VK_0 + i
274 end;
275 end;
277 with gPlayer1Settings do
278 begin
279 Name := GenPlayerName(1);
280 Model := STD_PLAYER_MODEL;
281 Color.R := PLAYER1_DEF_COLOR.R;
282 Color.G := PLAYER1_DEF_COLOR.G;
283 Color.B := PLAYER1_DEF_COLOR.B;
284 Team := TEAM_RED;
285 end;
287 (* section Player2 *)
288 with gGameControls.P2Control do
289 begin
290 KeyRight := SDL_SCANCODE_D;
291 KeyLeft := SDL_SCANCODE_A;
292 KeyUp := SDL_SCANCODE_W;
293 KeyDown := SDL_SCANCODE_S;
294 KeyFire := SDL_SCANCODE_G;
295 KeyJump := SDL_SCANCODE_SPACE;
296 KeyNextWeapon := SDL_SCANCODE_E;
297 KeyPrevWeapon := SDL_SCANCODE_Q;
298 KeyOpen := SDL_SCANCODE_F;
299 KeyStrafe := SDL_SCANCODE_LSHIFT;
300 for i := 0 to High(KeyWeapon) do
301 begin
302 KeyWeapon[i] := 0
303 end;
305 KeyRight2 := 0;
306 KeyLeft2 := 0;
307 KeyUp2 := 0;
308 KeyDown2 := 0;
309 KeyFire2 := 0;
310 KeyJump2 := 0;
311 KeyNextWeapon2 := 0;
312 KeyPrevWeapon2 := 0;
313 KeyOpen2 := 0;
314 KeyStrafe2 := 0;
316 for i := 0 to High(KeyWeapon2) do
317 begin
318 KeyWeapon2[i] := 0;
319 end
320 end;
322 with gPlayer2Settings do
323 begin
324 Name := GenPlayerName(2);
325 Model := STD_PLAYER_MODEL;
326 Color.R := PLAYER2_DEF_COLOR.R;
327 Color.G := PLAYER2_DEF_COLOR.G;
328 Color.B := PLAYER2_DEF_COLOR.B;
329 Team := TEAM_BLUE;
330 end;
332 (* section Joysticks *)
333 for i := 0 to e_MaxJoys - 1 do
334 begin
335 e_JoystickDeadzones[i] := 8192
336 end;
338 (* section Touch *)
339 g_touch_size := 1.0;
340 g_touch_fire := True;
341 g_touch_offset := 50;
342 g_touch_alt := False;
344 (* section Game *)
345 g_GFX_SetMax(2000);
346 g_Shells_SetMax(300);
347 g_Gibs_SetMax(150);
348 g_Corpses_SetMax(20);
349 gGibsCount := 32;
350 ITEM_RESPAWNTIME := 60 * 36;
351 gBloodCount := 4;
352 gAdvBlood := True;
353 gAdvCorpses := True;
354 gAdvGibs := True;
355 gFlash := 1;
356 gDrawBackGround := True;
357 gShowMessages := True;
358 gRevertPlayers := False;
359 gChatBubble := 4;
360 gPlayerIndicator := True;
361 gSFSDebug := False;
362 gSFSFastMode := False;
363 e_FastScreenshots := True;
364 gDefaultMegawadStart := DF_Default_Megawad_Start;
365 gBerserkAutoswitch := True;
366 g_dbg_scale := 1.0;
368 gAskLanguage := True;
369 gLanguage := LANGUAGE_ENGLISH;
371 (* section GameplayCustom *)
372 gcMap := '';
373 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
374 gcTimeLimit := 0;
375 gcGoalLimit := 0;
376 gcMaxLives := 0;
377 gcPlayers := 1;
378 gcTeamDamage := False;
379 gcAllowExit := True;
380 gcWeaponStay := False;
381 gcMonsters := False;
382 gcBotsVS := 'Everybody';
384 (* section GameplayNetwork *)
385 gnMap := '';
386 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
387 gnTimeLimit := 0;
388 gnGoalLimit := 0;
389 gnMaxLives := 0;
390 gnPlayers := 1;
391 gnTeamDamage := False;
392 gnAllowExit := True;
393 gnWeaponStay := False;
394 gnMonsters := False;
395 gnBotsVS := 'Everybody';
397 (* section MasterServer *)
398 NetSlistIP := 'mpms.doom2d.org';
399 NetSlistPort := 25665;
400 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
402 (* section Server *)
403 NetServerName := 'Unnamed Server';
404 NetPassword := '';
405 NetPort := 25666;
406 NetMaxClients := 16;
407 NetAllowRCON := False;
408 NetRCONPassword := 'default';
409 NetUseMaster := True;
410 NetUpdateRate := 0;
411 NetRelupdRate := 18;
412 NetMasterRate := 60000;
413 NetForwardPorts := False;
415 (* section Client *)
416 NetInterpLevel := 2;
417 NetForcePlayerUpdate := False;
418 NetPredictSelf := True;
419 NetClientIP := '127.0.0.1';
420 NetClientPort := NetPort;
421 end;
423 procedure g_Options_Read(FileName: String);
424 var
425 i: Integer;
426 config: TConfig;
427 section: String;
429 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
430 begin
431 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
432 end;
434 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
435 begin
436 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
437 end;
439 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
440 begin
441 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
442 end;
444 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
445 begin
446 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
447 end;
449 procedure ReadBoolean (VAR v: Boolean; param: String);
450 begin
451 v := config.ReadBool(section, param, v)
452 end;
454 procedure ReadString (VAR v: String; param: String);
455 begin
456 v := config.ReadStr(section, param, v)
457 end;
459 begin
460 gAskLanguage := True;
461 e_WriteLog('Reading config', TMsgType.Notify);
462 g_Options_SetDefault;
464 if FileExists(FileName) = False then
465 begin
466 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
467 g_Options_SetDefaultVideo;
468 Exit
469 end;
471 config := TConfig.CreateFile(FileName);
473 section := 'Video';
474 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
475 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
476 ReadInteger(gWinRealPosX, 'WinPosX', 60);
477 ReadInteger(gWinRealPosY, 'WinPosY', 60);
478 ReadBoolean(gFullScreen, 'Fullscreen');
479 ReadBoolean(gWinMaximized, 'Maximized');
480 ReadInteger(gBPP, 'BPP', 0);
481 ReadInteger(gFreq, 'Freq', 0);
482 ReadBoolean(gVSync, 'VSync');
483 ReadBoolean(gTextureFilter, 'TextureFilter');
484 ReadBoolean(glLegacyNPOT, 'LegacyCompatible');
486 section := 'Sound';
487 ReadBoolean(gNoSound, 'NoSound');
488 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
489 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
490 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
491 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
492 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
493 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
494 ReadBoolean(gUseChatSounds, 'ChatSounds');
495 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
496 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
498 section := 'GameControls';
499 with gGameControls.GameControls do
500 begin
501 ReadInteger(TakeScreenshot, 'TakeScreenshot');
502 ReadInteger(Stat, 'Stat');
503 ReadInteger(Chat, 'Chat');
504 ReadInteger(TeamChat, 'TeamChat');
505 end;
507 section := 'Player1';
508 with gGameControls.P1Control do
509 begin
510 ReadInteger(KeyRight, 'KeyRight');
511 ReadInteger(KeyLeft, 'KeyLeft');
512 ReadInteger(KeyUp, 'KeyUp');
513 ReadInteger(KeyDown, 'KeyDown');
514 ReadInteger(KeyFire, 'KeyFire');
515 ReadInteger(KeyJump, 'KeyJump');
516 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
517 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
518 ReadInteger(KeyOpen, 'KeyOpen');
519 ReadInteger(KeyStrafe, 'KeyStrafe');
521 for i := 0 to High(KeyWeapon) do
522 begin
523 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
524 end;
526 ReadInteger(KeyRight2, 'KeyRight2');
527 ReadInteger(KeyLeft2, 'KeyLeft2');
528 ReadInteger(KeyUp2, 'KeyUp2');
529 ReadInteger(KeyDown2, 'KeyDown2');
530 ReadInteger(KeyFire2, 'KeyFire2');
531 ReadInteger(KeyJump2, 'KeyJump2');
532 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
533 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
534 ReadInteger(KeyOpen2, 'KeyOpen2');
535 ReadInteger(KeyStrafe2, 'KeyStrafe2');
537 for i := 0 to High(KeyWeapon2) do
538 begin
539 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
540 end;
541 end;
543 section := 'Player1';
544 with gPlayer1Settings do
545 begin
546 ReadString(Name, 'name');
547 ReadString(Model, 'model');
548 ReadInteger(Color.R, 'red', 0, 255);
549 ReadInteger(Color.G, 'green', 0, 255);
550 ReadInteger(Color.B, 'blue', 0, 255);
551 ReadInteger(Team, 'team');
552 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
553 Team := TEAM_RED;
554 end;
556 section := 'Player2';
557 with gGameControls.P2Control do
558 begin
559 ReadInteger(KeyRight, 'KeyRight');
560 ReadInteger(KeyLeft, 'KeyLeft');
561 ReadInteger(KeyUp, 'KeyUp');
562 ReadInteger(KeyDown, 'KeyDown');
563 ReadInteger(KeyFire, 'KeyFire');
564 ReadInteger(KeyJump, 'KeyJump');
565 ReadInteger(KeyNextWeapon, 'KeyNextWeapon');
566 ReadInteger(KeyPrevWeapon, 'KeyPrevWeapon');
567 ReadInteger(KeyOpen, 'KeyOpen');
568 ReadInteger(KeyStrafe, 'KeyStrafe');
570 for i := 0 to High(KeyWeapon) do
571 begin
572 ReadInteger(KeyWeapon[i], 'KeyWeapon' + IntToStr(i))
573 end;
575 ReadInteger(KeyRight2, 'KeyRight2');
576 ReadInteger(KeyLeft2, 'KeyLeft2');
577 ReadInteger(KeyUp2, 'KeyUp2');
578 ReadInteger(KeyDown2, 'KeyDown2');
579 ReadInteger(KeyFire2, 'KeyFire2');
580 ReadInteger(KeyJump2, 'KeyJump2');
581 ReadInteger(KeyNextWeapon2, 'KeyNextWeapon2');
582 ReadInteger(KeyPrevWeapon2, 'KeyPrevWeapon2');
583 ReadInteger(KeyOpen2, 'KeyOpen2');
584 ReadInteger(KeyStrafe2, 'KeyStrafe2');
586 for i := 0 to High(KeyWeapon2) do
587 begin
588 ReadInteger(KeyWeapon2[i], 'KeyWeapon2' + IntToStr(i))
589 end;
590 end;
592 section := 'Player2';
593 with gPlayer2Settings do
594 begin
595 ReadString(Name, 'name');
596 ReadString(Model, 'model');
597 ReadInteger(Color.R, 'red', 0, 255);
598 ReadInteger(Color.G, 'green', 0, 255);
599 ReadInteger(Color.B, 'blue', 0, 255);
600 ReadInteger(Team, 'team');
601 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
602 Team := TEAM_RED;
603 end;
605 section := 'Joysticks';
606 for i := 0 to e_MaxJoys - 1 do
607 begin
608 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
609 end;
611 section := 'Touch';
612 i := Trunc(g_touch_size * 10); ReadInteger(i, 'Size', 0); g_touch_size := i / 10;
613 ReadBoolean(g_touch_fire, 'Fire');
614 i := Round(g_touch_offset); ReadInteger(i, 'Offset', 0, 100); g_touch_offset := i;
615 ReadBoolean(g_touch_alt, 'Alt');
617 section := 'Game';
618 ReadInteger(i, 'MaxParticles', 0, 50000); g_GFX_SetMax(i);
619 ReadInteger(i, 'MaxShells', 0, 600); g_Shells_SetMax(i);
620 ReadInteger(i, 'MaxGibs', 0, 500); g_Gibs_SetMax(i);
621 ReadInteger(i, 'MaxCorpses', 0, 100); g_Corpses_SetMax(i);
622 ReadInteger(i, 'GibsCount');
623 case i of
624 0: gGibsCount := 0;
625 1: gGibsCount := 8;
626 2: gGibsCount := 16;
627 3: gGibsCount := 32;
628 else gGibsCount := 48;
629 end;
630 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
631 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
632 ReadBoolean(gAdvBlood, 'AdvancesBlood');
633 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
634 ReadBoolean(gAdvGibs, 'AdvancesGibs');
635 ReadInteger(gFlash, 'Flash', 0, 2);
636 ReadBoolean(gDrawBackGround, 'BackGround');
637 ReadBoolean(gShowMessages, 'Messages');
638 ReadBoolean(gRevertPlayers, 'RevertPlayers');
639 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
640 ReadBoolean(gPlayerIndicator, 'PlayerIndicator');
641 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
642 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
643 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
644 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
645 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
646 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
647 ReadString(gLanguage, 'Language');
648 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
649 gAskLanguage := False
650 else
651 gLanguage := LANGUAGE_ENGLISH;
653 section := 'GameplayCustom';
654 ReadString(gcMap, 'Map');
655 ReadString(gcGameMode, 'GameMode');
656 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
657 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
658 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
659 ReadInteger(gcPlayers, 'Players', 0, 2);
660 ReadBoolean(gcTeamDamage, 'TeamDamage');
661 ReadBoolean(gcAllowExit, 'AllowExit');
662 ReadBoolean(gcWeaponStay, 'WeaponStay');
663 ReadBoolean(gcMonsters, 'Monsters');
664 ReadString(gcBotsVS, 'BotsVS');
666 with gGameSettings do
667 begin
668 GameMode := g_Game_TextToMode(gcGameMode);
669 if GameMode = GM_NONE then
670 GameMode := GM_DM;
671 if GameMode = GM_SINGLE then
672 GameMode := GM_COOP;
673 TimeLimit := gcTimeLimit;
674 GoalLimit := gcGoalLimit;
675 MaxLives := gcMaxLives;
677 Options := 0;
678 if gcTeamDamage then
679 Options := Options or GAME_OPTION_TEAMDAMAGE;
680 if gcAllowExit then
681 Options := Options or GAME_OPTION_ALLOWEXIT;
682 if gcWeaponStay then
683 Options := Options or GAME_OPTION_WEAPONSTAY;
684 if gcMonsters then
685 Options := Options or GAME_OPTION_MONSTERS;
686 if gcBotsVS = 'Everybody' then
687 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
688 if gcBotsVS = 'Players' then
689 Options := Options or GAME_OPTION_BOTVSPLAYER;
690 if gcBotsVS = 'Monsters' then
691 Options := Options or GAME_OPTION_BOTVSMONSTER;
692 end;
694 section := 'GameplayNetwork';
695 ReadString(gnMap, 'Map');
696 ReadString(gnGameMode, 'GameMode');
697 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
698 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
699 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
700 ReadInteger(gnPlayers, 'Players', 0, 2);
701 ReadBoolean(gnTeamDamage, 'TeamDamage');
702 ReadBoolean(gnAllowExit, 'AllowExit');
703 ReadBoolean(gnWeaponStay, 'WeaponStay');
704 ReadBoolean(gnMonsters, 'Monsters');
705 ReadString(gnBotsVS, 'BotsVS');
707 section := 'MasterServer';
708 ReadString(NetSlistIP, 'IP');
709 ReadInteger(NetSlistPort, 'Port', 0, 65535);
710 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
712 section := 'Server';
713 ReadString(NetServerName, 'Name');
714 ReadString(NetPassword, 'Password');
715 ReadInteger(NetPort, 'Port', 0, 65535);
716 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
717 ReadBoolean(NetAllowRCON, 'RCON');
718 ReadString(NetRCONPassword, 'RCONPassword');
719 ReadBoolean(NetUseMaster, 'SyncWithMaster');
720 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
721 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
722 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
723 ReadBoolean(NetForwardPorts, 'ForwardPorts');
725 section := 'Client';
726 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
727 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
728 ReadBoolean(NetPredictSelf, 'PredictSelf');
729 ReadString(NetClientIP, 'LastIP');
730 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
732 config.Free();
734 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
735 end;
737 procedure g_Options_Write(FileName: String);
738 var
739 config: TConfig;
740 i: Integer;
741 begin
742 e_WriteLog('Writing config', TMsgType.Notify);
744 config := TConfig.CreateFile(FileName);
746 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
747 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
748 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
749 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
750 config.WriteBool('Video', 'Fullscreen', gFullScreen);
751 config.WriteBool('Video', 'Maximized', gWinMaximized);
752 config.WriteInt('Video', 'BPP', gBPP);
753 config.WriteBool('Video', 'VSync', gVSync);
754 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
755 config.WriteBool('Video', 'LegacyCompatible', glLegacyNPOT);
757 config.WriteBool('Sound', 'NoSound', gNoSound);
758 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
759 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
760 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
761 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
762 config.WriteInt('Sound', 'Announcer', gAnnouncer);
763 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
764 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
765 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
766 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
768 with config, gGameControls.GameControls do
769 begin
770 WriteInt('GameControls', 'TakeScreenshot', TakeScreenshot);
771 WriteInt('GameControls', 'Stat', Stat);
772 WriteInt('GameControls', 'Chat', Chat);
773 WriteInt('GameControls', 'TeamChat', TeamChat);
774 end;
776 with config, gGameControls.P1Control, gPlayer1Settings do
777 begin
778 WriteInt('Player1', 'KeyRight', KeyRight);
779 WriteInt('Player1', 'KeyLeft', KeyLeft);
780 WriteInt('Player1', 'KeyUp', KeyUp);
781 WriteInt('Player1', 'KeyDown', KeyDown);
782 WriteInt('Player1', 'KeyFire', KeyFire);
783 WriteInt('Player1', 'KeyJump', KeyJump);
784 WriteInt('Player1', 'KeyNextWeapon', KeyNextWeapon);
785 WriteInt('Player1', 'KeyPrevWeapon', KeyPrevWeapon);
786 WriteInt('Player1', 'KeyOpen', KeyOpen);
787 WriteInt('Player1', 'KeyStrafe', KeyStrafe);
788 for i := 0 to High(KeyWeapon) do
789 WriteInt('Player1', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
791 WriteInt('Player1', 'KeyRight2', KeyRight2);
792 WriteInt('Player1', 'KeyLeft2', KeyLeft2);
793 WriteInt('Player1', 'KeyUp2', KeyUp2);
794 WriteInt('Player1', 'KeyDown2', KeyDown2);
795 WriteInt('Player1', 'KeyFire2', KeyFire2);
796 WriteInt('Player1', 'KeyJump2', KeyJump2);
797 WriteInt('Player1', 'KeyNextWeapon2', KeyNextWeapon2);
798 WriteInt('Player1', 'KeyPrevWeapon2', KeyPrevWeapon2);
799 WriteInt('Player1', 'KeyOpen2', KeyOpen2);
800 WriteInt('Player1', 'KeyStrafe2', KeyStrafe2);
801 for i := 0 to High(KeyWeapon2) do
802 WriteInt('Player1', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
804 WriteStr('Player1', 'Name', Name);
805 WriteStr('Player1', 'model', Model);
806 WriteInt('Player1', 'red', Color.R);
807 WriteInt('Player1', 'green', Color.G);
808 WriteInt('Player1', 'blue', Color.B);
809 WriteInt('Player1', 'team', Team);
810 end;
812 with config, gGameControls.P2Control, gPlayer2Settings do
813 begin
814 WriteInt('Player2', 'KeyRight', KeyRight);
815 WriteInt('Player2', 'KeyLeft', KeyLeft);
816 WriteInt('Player2', 'KeyUp', KeyUp);
817 WriteInt('Player2', 'KeyDown', KeyDown);
818 WriteInt('Player2', 'KeyFire', KeyFire);
819 WriteInt('Player2', 'KeyJump', KeyJump);
820 WriteInt('Player2', 'KeyNextWeapon', KeyNextWeapon);
821 WriteInt('Player2', 'KeyPrevWeapon', KeyPrevWeapon);
822 WriteInt('Player2', 'KeyOpen', KeyOpen);
823 WriteInt('Player2', 'KeyStrafe', KeyStrafe);
824 for i := 0 to High(KeyWeapon) do
825 WriteInt('Player2', 'KeyWeapon' + IntToStr(i), KeyWeapon[i]);
827 WriteInt('Player2', 'KeyRight2', KeyRight2);
828 WriteInt('Player2', 'KeyLeft2', KeyLeft2);
829 WriteInt('Player2', 'KeyUp2', KeyUp2);
830 WriteInt('Player2', 'KeyDown2', KeyDown2);
831 WriteInt('Player2', 'KeyFire2', KeyFire2);
832 WriteInt('Player2', 'KeyJump2', KeyJump2);
833 WriteInt('Player2', 'KeyNextWeapon2', KeyNextWeapon2);
834 WriteInt('Player2', 'KeyPrevWeapon2', KeyPrevWeapon2);
835 WriteInt('Player2', 'KeyOpen2', KeyOpen2);
836 WriteInt('Player2', 'KeyStrafe2', KeyStrafe2);
837 for i := 0 to High(KeyWeapon2) do
838 WriteInt('Player2', 'KeyWeapon2' + IntToStr(i), KeyWeapon2[i]);
840 WriteStr('Player2', 'Name', Name);
841 WriteStr('Player2', 'model', Model);
842 WriteInt('Player2', 'red', Color.R);
843 WriteInt('Player2', 'green', Color.G);
844 WriteInt('Player2', 'blue', Color.B);
845 WriteInt('Player2', 'team', Team);
846 end;
848 for i := 0 to e_MaxJoys-1 do
849 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
851 config.WriteInt('Touch', 'Size', Round(g_touch_size * 10));
852 config.WriteBool('Touch', 'Fire', g_touch_fire);
853 config.WriteInt('Touch', 'Offset', Round(g_touch_offset));
854 config.WriteBool('Touch', 'Alt', g_touch_alt);
856 with config do
857 case gGibsCount of
858 0: config.WriteInt('Game', 'GibsCount', 0);
859 8: config.WriteInt('Game', 'GibsCount', 1);
860 16: config.WriteInt('Game', 'GibsCount', 2);
861 32: config.WriteInt('Game', 'GibsCount', 3);
862 else config.WriteInt('Game', 'GibsCount', 4);
863 end;
865 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
866 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
867 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
868 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
869 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
870 config.WriteInt('Game', 'BloodCount', gBloodCount);
871 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
872 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
873 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
874 config.WriteInt('Game', 'Flash', gFlash);
875 config.WriteBool('Game', 'BackGround', gDrawBackGround);
876 config.WriteBool('Game', 'Messages', gShowMessages);
877 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
878 config.WriteInt('Game', 'ChatBubble', gChatBubble);
879 config.WriteBool('Game', 'PlayerIndicator', gPlayerIndicator);
880 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
881 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
882 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
883 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
884 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
885 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
887 config.WriteStr ('GameplayCustom', 'Map', gcMap);
888 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
889 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
890 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
891 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
892 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
893 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
894 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
895 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
896 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
897 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
899 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
900 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
901 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
902 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
903 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
904 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
905 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
906 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
907 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
908 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
909 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
911 config.WriteStr('MasterServer', 'IP', NetSlistIP);
912 config.WriteInt('MasterServer', 'Port', NetSlistPort);
914 config.WriteStr ('Server', 'Name', NetServerName);
915 config.WriteStr ('Server', 'Password', NetPassword);
916 config.WriteInt ('Server', 'Port', NetPort);
917 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
918 config.WriteBool('Server', 'RCON', NetAllowRCON);
919 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
920 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
921 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
922 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
923 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
924 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
926 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
927 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
928 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
929 config.WriteStr ('Client', 'LastIP', NetClientIP);
930 config.WriteInt ('Client', 'LastPort', NetClientPort);
932 config.SaveFile(FileName);
933 config.Free();
934 end;
936 procedure g_Options_Write_Language(FileName: String);
937 var
938 config: TConfig;
939 begin
940 e_WriteLog('Writing language config', TMsgType.Notify);
942 config := TConfig.CreateFile(FileName);
943 config.WriteStr('Game', 'Language', gLanguage);
944 config.SaveFile(FileName);
945 config.Free();
946 end;
948 procedure g_Options_Write_Video(FileName: String);
949 var
950 config: TConfig;
951 sW, sH: Integer;
952 begin
953 e_WriteLog('Writing resolution to config', TMsgType.Notify);
955 config := TConfig.CreateFile(FileName);
957 if gWinMaximized and (not gFullscreen) then
958 begin
959 sW := gWinSizeX;
960 sH := gWinSizeY;
961 end
962 else
963 begin
964 sW := gScreenWidth;
965 sH := gScreenHeight;
966 end;
967 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
969 config.WriteInt('Video', 'ScreenWidth', sW);
970 config.WriteInt('Video', 'ScreenHeight', sH);
971 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
972 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
973 config.WriteBool('Video', 'Fullscreen', gFullscreen);
974 config.WriteBool('Video', 'Maximized', gWinMaximized);
976 config.WriteStr('Player1', 'Name', gPlayer1Settings.Name);
977 config.WriteStr('Player2', 'Name', gPlayer2Settings.Name);
979 config.SaveFile(FileName);
980 config.Free();
981 end;
983 procedure g_Options_Write_Gameplay_Custom(FileName: String);
984 var
985 config: TConfig;
986 begin
987 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
989 config := TConfig.CreateFile(FileName);
991 config.WriteStr ('GameplayCustom', 'Map', gcMap);
992 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
993 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
994 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
995 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
996 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
997 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
998 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
999 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
1000 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
1001 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
1003 config.SaveFile(FileName);
1004 config.Free();
1005 end;
1007 procedure g_Options_Write_Gameplay_Net(FileName: String);
1008 var
1009 config: TConfig;
1010 begin
1011 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
1013 config := TConfig.CreateFile(FileName);
1015 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
1016 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
1017 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
1018 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
1019 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
1020 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
1021 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
1022 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
1023 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
1024 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
1025 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
1027 config.SaveFile(FileName);
1028 config.Free();
1029 end;
1031 procedure g_Options_Write_Net_Server(FileName: String);
1032 var
1033 config: TConfig;
1034 begin
1035 e_WriteLog('Writing server config', TMsgType.Notify);
1037 config := TConfig.CreateFile(FileName);
1039 config.WriteStr ('Server', 'Name', NetServerName);
1040 config.WriteStr ('Server', 'Password', NetPassword);
1041 config.WriteInt ('Server', 'Port', NetPort);
1042 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
1043 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
1044 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
1046 config.SaveFile(FileName);
1047 config.Free();
1048 end;
1050 procedure g_Options_Write_Net_Client(FileName: String);
1051 var
1052 config: TConfig;
1053 begin
1054 e_WriteLog('Writing client config', TMsgType.Notify);
1056 config := TConfig.CreateFile(FileName);
1058 config.WriteStr('Client', 'LastIP', NetClientIP);
1059 config.WriteInt('Client', 'LastPort', NetClientPort);
1061 config.SaveFile(FileName);
1062 config.Free();
1063 end;
1065 initialization
1066 Randomize;
1067 machine := Random(10000)
1068 end.