DEADSOFTWARE

f15e7c7718e8568906c3afea23ba9ed108daf5d6
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_options;
18 interface
20 uses
21 g_language, g_weapons;
23 function GenPlayerName (n: Integer): String;
25 procedure g_Options_SetDefault;
26 procedure g_Options_SetDefaultVideo;
27 procedure g_Options_Read(FileName: String);
28 procedure g_Options_Write(FileName: String);
29 procedure g_Options_Write_Language(FileName: String);
30 procedure g_Options_Write_Video(FileName: String);
31 procedure g_Options_Write_Gameplay_Custom(FileName: String);
32 procedure g_Options_Write_Gameplay_Net(FileName: String);
33 procedure g_Options_Write_Net_Server(FileName: String);
34 procedure g_Options_Write_Net_Client(FileName: String);
36 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
38 var
39 // gGameControls: TControls;
40 gScreenWidth: Word;
41 gScreenHeight: Word;
42 gWinRealPosX: Integer;
43 gWinRealPosY: Integer;
44 gBPP: Byte;
45 gFreq: Byte;
46 gFullscreen: Boolean;
47 gWinMaximized: Boolean;
48 gVSync: Boolean;
49 glLegacyNPOT: Boolean;
50 gTextureFilter: Boolean;
51 gNoSound: Boolean;
52 gSoundLevel: Byte;
53 gMusicLevel: Byte;
54 gMaxSimSounds: Byte;
55 gMuteWhenInactive: Boolean;
56 gAdvCorpses: Boolean;
57 gAdvBlood: Boolean;
58 gAdvGibs: Boolean;
59 gGibsCount: Integer;
60 gBloodCount: Byte;
61 gFlash: Byte;
62 gDrawBackGround: Boolean;
63 gShowMessages: Boolean;
64 gRevertPlayers: Boolean;
65 gLanguage: String;
66 gAskLanguage: Boolean;
67 gcMap: String;
68 gcGameMode: String;
69 gcTimeLimit: Word;
70 gcGoalLimit: Word;
71 gcMaxLives: Byte;
72 gcPlayers: Byte;
73 gcTeamDamage: Boolean;
74 gcAllowExit: Boolean;
75 gcWeaponStay: Boolean;
76 gcMonsters: Boolean;
77 gcBotsVS: String;
78 gnMap: String;
79 gnGameMode: String;
80 gnTimeLimit: Word;
81 gnGoalLimit: Word;
82 gnMaxLives: Byte;
83 gnPlayers: Byte;
84 gnTeamDamage: Boolean;
85 gnAllowExit: Boolean;
86 gnWeaponStay: Boolean;
87 gnMonsters: Boolean;
88 gnBotsVS: String;
89 gsSDLSampleRate: Integer;
90 gsSDLBufferSize: Integer;
91 gSFSDebug: Boolean;
92 gSFSFastMode: Boolean;
93 gDefaultMegawadStart: AnsiString;
94 gBerserkAutoswitch: Boolean;
95 glNPOTOverride: Boolean = false;
97 implementation
99 uses
100 {$INCLUDE ../nogl/noGLuses.inc}
101 {$IFDEF USE_SDL2}
102 SDL2,
103 {$ENDIF}
104 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
105 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
106 g_items, wadreader, e_graphics, g_touch, envvars;
108 var
109 machine: Integer;
111 function GenPlayerName (n: Integer): String;
112 begin
113 ASSERT(n >= 1);
114 Result := GetUserName;
115 if Result = '' then
116 Result := 'Player' + IntToStr(machine MOD 10000);
117 if n = 1 then
118 Result := Copy(Result, 1, 12) + ' '
119 else
120 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
121 end;
123 {$IFDEF USE_SDL2}
124 procedure g_Options_SetDefaultVideo;
125 var
126 target, closest, display: TSDL_DisplayMode;
127 percentage: Integer;
128 begin
129 (* Display 0 = Primary display *)
130 gScreenWidth := 640;
131 gScreenHeight := 480;
132 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
133 gBPP := 32;
134 {$IFDEF ANDROID}
135 gFullScreen := True; (* rotation not allowed? *)
136 {$ELSE}
137 gFullScreen := False;
138 {$ENDIF}
139 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
140 begin
141 {$IFDEF ANDROID}
142 gScreenWidth := display.w;
143 gScreenHeight := display.h;
144 {$ELSE}
145 (* Window must be smaller than display *)
146 closest.w := display.w;
147 closest.h := display.h;
148 percentage := 75;
149 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
150 begin
151 if percentage < 25 then
152 begin
153 closest.w := display.w * 75 div 100;
154 closest.h := display.h * 75 div 100;
155 break;
156 end;
157 target.w := display.w * percentage div 100;
158 target.h := display.h * percentage div 100;
159 target.format := 0; (* didn't care *)
160 target.refresh_rate := 0; (* didn't care *)
161 target.driverdata := nil; (* init *)
162 SDL_GetClosestDisplayMode(0, @target, @closest);
163 Dec(percentage);
164 end;
165 gScreenWidth := closest.w;
166 gScreenHeight := closest.h;
167 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
168 {$ENDIF}
169 end
170 else
171 begin
172 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
173 end;
174 (* Must be positioned on primary display *)
175 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
176 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
177 gWinMaximized := False;
178 gVSync := True;
179 gTextureFilter := True;
180 glLegacyNPOT := False;
181 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
182 g_Console_ResetBinds;
183 end;
184 {$ELSE}
185 procedure g_Options_SetDefaultVideo;
186 begin
187 gScreenWidth := 640;
188 gScreenHeight := 480;
189 gBPP := 32;
190 gFullScreen := False;
191 gWinRealPosX := 0;
192 gWinRealPosY := 0;
193 gWinMaximized := False;
194 gVSync := True;
195 gTextureFilter := True;
196 glLegacyNPOT := False;
197 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
198 g_Console_ResetBinds;
199 end;
200 {$ENDIF}
202 procedure g_Options_SetDefault();
203 var
204 i: Integer;
205 begin
206 (* section Sound *)
207 gNoSound := False;
208 gSoundLevel := 75;
209 gMusicLevel := 65;
210 gMaxSimSounds := 8;
211 gMuteWhenInactive := False;
212 gAnnouncer := ANNOUNCE_MEPLUS;
213 gSoundEffectsDF := True;
214 gUseChatSounds := True;
215 gsSDLSampleRate := 44100;
216 gsSDLBufferSize := 2048;
218 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
220 with gPlayer1Settings do
221 begin
222 Name := GenPlayerName(1);
223 Model := STD_PLAYER_MODEL;
224 Color.R := PLAYER1_DEF_COLOR.R;
225 Color.G := PLAYER1_DEF_COLOR.G;
226 Color.B := PLAYER1_DEF_COLOR.B;
227 Team := TEAM_RED;
228 end;
230 with gPlayer2Settings do
231 begin
232 Name := GenPlayerName(2);
233 Model := STD_PLAYER_MODEL;
234 Color.R := PLAYER2_DEF_COLOR.R;
235 Color.G := PLAYER2_DEF_COLOR.G;
236 Color.B := PLAYER2_DEF_COLOR.B;
237 Team := TEAM_BLUE;
238 end;
240 (* section Joysticks *)
241 for i := 0 to e_MaxJoys - 1 do
242 begin
243 e_JoystickDeadzones[i] := 8192
244 end;
246 (* section Game *)
247 g_GFX_SetMax(2000);
248 g_Shells_SetMax(300);
249 g_Gibs_SetMax(150);
250 g_Corpses_SetMax(20);
251 gGibsCount := 32;
252 ITEM_RESPAWNTIME := 60 * 36;
253 gBloodCount := 4;
254 gAdvBlood := True;
255 gAdvCorpses := True;
256 gAdvGibs := True;
257 gFlash := 1;
258 gDrawBackGround := True;
259 gShowMessages := True;
260 gRevertPlayers := False;
261 gChatBubble := 4;
262 gSFSDebug := False;
263 gSFSFastMode := False;
264 e_FastScreenshots := True;
265 gDefaultMegawadStart := DF_Default_Megawad_Start;
266 gBerserkAutoswitch := True;
267 g_dbg_scale := 1.0;
269 gAskLanguage := True;
270 gLanguage := LANGUAGE_ENGLISH;
272 (* section GameplayCustom *)
273 gcMap := '';
274 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
275 gcTimeLimit := 0;
276 gcGoalLimit := 0;
277 gcMaxLives := 0;
278 gcPlayers := 1;
279 gcTeamDamage := False;
280 gcAllowExit := True;
281 gcWeaponStay := False;
282 gcMonsters := False;
283 gcBotsVS := 'Everybody';
285 (* section GameplayNetwork *)
286 gnMap := '';
287 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
288 gnTimeLimit := 0;
289 gnGoalLimit := 0;
290 gnMaxLives := 0;
291 gnPlayers := 1;
292 gnTeamDamage := False;
293 gnAllowExit := True;
294 gnWeaponStay := False;
295 gnMonsters := False;
296 gnBotsVS := 'Everybody';
298 (* section MasterServer *)
299 NetSlistIP := 'mpms.doom2d.org';
300 NetSlistPort := 25665;
301 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
303 (* section Server *)
304 NetServerName := 'Unnamed Server';
305 NetPassword := '';
306 NetPort := 25666;
307 NetMaxClients := 16;
308 NetAllowRCON := False;
309 NetRCONPassword := 'default';
310 NetUseMaster := True;
311 NetUpdateRate := 0;
312 NetRelupdRate := 18;
313 NetMasterRate := 60000;
314 NetForwardPorts := False;
316 (* section Client *)
317 NetInterpLevel := 2;
318 NetForcePlayerUpdate := False;
319 NetPredictSelf := True;
320 NetClientIP := '127.0.0.1';
321 NetClientPort := NetPort;
322 end;
324 procedure g_Options_Read(FileName: String);
325 var
326 i: Integer;
327 config: TConfig;
328 section: String;
330 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
331 begin
332 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
333 end;
335 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
336 begin
337 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
338 end;
340 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
341 begin
342 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
343 end;
345 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
346 begin
347 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
348 end;
350 procedure ReadBoolean (VAR v: Boolean; param: String);
351 begin
352 v := config.ReadBool(section, param, v)
353 end;
355 procedure ReadString (VAR v: String; param: String);
356 begin
357 v := config.ReadStr(section, param, v)
358 end;
360 begin
361 gAskLanguage := True;
362 e_WriteLog('Reading config', TMsgType.Notify);
363 g_Options_SetDefault;
365 if FileExists(FileName) = False then
366 begin
367 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
368 g_Options_SetDefaultVideo;
369 Exit
370 end;
372 config := TConfig.CreateFile(FileName);
374 section := 'Video';
375 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
376 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
377 ReadInteger(gWinRealPosX, 'WinPosX', 60);
378 ReadInteger(gWinRealPosY, 'WinPosY', 60);
379 ReadBoolean(gFullScreen, 'Fullscreen');
380 ReadBoolean(gWinMaximized, 'Maximized');
381 ReadInteger(gBPP, 'BPP', 0);
382 ReadInteger(gFreq, 'Freq', 0);
383 ReadBoolean(gVSync, 'VSync');
384 ReadBoolean(gTextureFilter, 'TextureFilter');
385 ReadBoolean(glNPOTOverride, 'LegacyCompatibleForce');
387 section := 'Sound';
388 ReadBoolean(gNoSound, 'NoSound');
389 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
390 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
391 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
392 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
393 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
394 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
395 ReadBoolean(gUseChatSounds, 'ChatSounds');
396 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
397 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
399 section := 'Player1';
400 with gPlayer1Settings do
401 begin
402 ReadString(Name, 'name');
403 ReadString(Model, 'model');
404 ReadInteger(Color.R, 'red', 0, 255);
405 ReadInteger(Color.G, 'green', 0, 255);
406 ReadInteger(Color.B, 'blue', 0, 255);
407 ReadInteger(Team, 'team');
408 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
409 Team := TEAM_RED;
410 end;
412 section := 'Player2';
413 with gPlayer2Settings do
414 begin
415 ReadString(Name, 'name');
416 ReadString(Model, 'model');
417 ReadInteger(Color.R, 'red', 0, 255);
418 ReadInteger(Color.G, 'green', 0, 255);
419 ReadInteger(Color.B, 'blue', 0, 255);
420 ReadInteger(Team, 'team');
421 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
422 Team := TEAM_RED;
423 end;
425 section := 'Joysticks';
426 for i := 0 to e_MaxJoys - 1 do
427 begin
428 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
429 end;
431 section := 'Game';
432 ReadInteger(i, 'MaxParticles', 0, 50000); g_GFX_SetMax(i);
433 ReadInteger(i, 'MaxShells', 0, 600); g_Shells_SetMax(i);
434 ReadInteger(i, 'MaxGibs', 0, 500); g_Gibs_SetMax(i);
435 ReadInteger(i, 'MaxCorpses', 0, 100); g_Corpses_SetMax(i);
436 ReadInteger(i, 'GibsCount');
437 case i of
438 0: gGibsCount := 0;
439 1: gGibsCount := 8;
440 2: gGibsCount := 16;
441 3: gGibsCount := 32;
442 else gGibsCount := 48;
443 end;
444 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
445 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
446 ReadBoolean(gAdvBlood, 'AdvancesBlood');
447 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
448 ReadBoolean(gAdvGibs, 'AdvancesGibs');
449 ReadInteger(gFlash, 'Flash', 0, 2);
450 ReadBoolean(gDrawBackGround, 'BackGround');
451 ReadBoolean(gShowMessages, 'Messages');
452 ReadBoolean(gRevertPlayers, 'RevertPlayers');
453 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
454 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
455 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
456 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
457 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
458 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
459 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
460 ReadString(gLanguage, 'Language');
461 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
462 gAskLanguage := False
463 else
464 gLanguage := LANGUAGE_ENGLISH;
466 section := 'GameplayCustom';
467 ReadString(gcMap, 'Map');
468 ReadString(gcGameMode, 'GameMode');
469 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
470 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
471 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
472 ReadInteger(gcPlayers, 'Players', 0, 2);
473 ReadBoolean(gcTeamDamage, 'TeamDamage');
474 ReadBoolean(gcAllowExit, 'AllowExit');
475 ReadBoolean(gcWeaponStay, 'WeaponStay');
476 ReadBoolean(gcMonsters, 'Monsters');
477 ReadString(gcBotsVS, 'BotsVS');
479 with gGameSettings do
480 begin
481 GameMode := g_Game_TextToMode(gcGameMode);
482 if GameMode = GM_NONE then
483 GameMode := GM_DM;
484 if GameMode = GM_SINGLE then
485 GameMode := GM_COOP;
486 TimeLimit := gcTimeLimit;
487 GoalLimit := gcGoalLimit;
488 MaxLives := gcMaxLives;
490 Options := 0;
491 if gcTeamDamage then
492 Options := Options or GAME_OPTION_TEAMDAMAGE;
493 if gcAllowExit then
494 Options := Options or GAME_OPTION_ALLOWEXIT;
495 if gcWeaponStay then
496 Options := Options or GAME_OPTION_WEAPONSTAY;
497 if gcMonsters then
498 Options := Options or GAME_OPTION_MONSTERS;
499 if gcBotsVS = 'Everybody' then
500 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
501 if gcBotsVS = 'Players' then
502 Options := Options or GAME_OPTION_BOTVSPLAYER;
503 if gcBotsVS = 'Monsters' then
504 Options := Options or GAME_OPTION_BOTVSMONSTER;
505 end;
507 section := 'GameplayNetwork';
508 ReadString(gnMap, 'Map');
509 ReadString(gnGameMode, 'GameMode');
510 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
511 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
512 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
513 ReadInteger(gnPlayers, 'Players', 0, 2);
514 ReadBoolean(gnTeamDamage, 'TeamDamage');
515 ReadBoolean(gnAllowExit, 'AllowExit');
516 ReadBoolean(gnWeaponStay, 'WeaponStay');
517 ReadBoolean(gnMonsters, 'Monsters');
518 ReadString(gnBotsVS, 'BotsVS');
520 section := 'MasterServer';
521 ReadString(NetSlistIP, 'IP');
522 ReadInteger(NetSlistPort, 'Port', 0, 65535);
523 ReadString(NetSlistList, 'List');
524 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
526 section := 'Server';
527 ReadString(NetServerName, 'Name');
528 ReadString(NetPassword, 'Password');
529 ReadInteger(NetPort, 'Port', 0, 65535);
530 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
531 ReadBoolean(NetAllowRCON, 'RCON');
532 ReadString(NetRCONPassword, 'RCONPassword');
533 ReadBoolean(NetUseMaster, 'SyncWithMaster');
534 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
535 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
536 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
537 ReadBoolean(NetForwardPorts, 'ForwardPorts');
539 section := 'Client';
540 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
541 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
542 ReadBoolean(NetPredictSelf, 'PredictSelf');
543 ReadString(NetClientIP, 'LastIP');
544 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
546 config.Free();
548 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
549 end;
551 procedure g_Options_Write(FileName: String);
552 var
553 config: TConfig;
554 i: Integer;
555 begin
556 e_WriteLog('Writing config', TMsgType.Notify);
558 config := TConfig.CreateFile(FileName);
560 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
561 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
562 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
563 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
564 config.WriteBool('Video', 'Fullscreen', gFullScreen);
565 config.WriteBool('Video', 'Maximized', gWinMaximized);
566 config.WriteInt('Video', 'BPP', gBPP);
567 config.WriteBool('Video', 'VSync', gVSync);
568 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
569 config.WriteBool('Video', 'LegacyCompatibleForce', glNPOTOverride);
571 config.WriteBool('Sound', 'NoSound', gNoSound);
572 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
573 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
574 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
575 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
576 config.WriteInt('Sound', 'Announcer', gAnnouncer);
577 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
578 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
579 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
580 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
582 with config, gPlayer1Settings do
583 begin
584 WriteStr('Player1', 'Name', Name);
585 WriteStr('Player1', 'model', Model);
586 WriteInt('Player1', 'red', Color.R);
587 WriteInt('Player1', 'green', Color.G);
588 WriteInt('Player1', 'blue', Color.B);
589 WriteInt('Player1', 'team', Team);
590 end;
592 with config, gPlayer2Settings do
593 begin
594 WriteStr('Player2', 'Name', Name);
595 WriteStr('Player2', 'model', Model);
596 WriteInt('Player2', 'red', Color.R);
597 WriteInt('Player2', 'green', Color.G);
598 WriteInt('Player2', 'blue', Color.B);
599 WriteInt('Player2', 'team', Team);
600 end;
602 for i := 0 to e_MaxJoys-1 do
603 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
605 with config do
606 case gGibsCount of
607 0: config.WriteInt('Game', 'GibsCount', 0);
608 8: config.WriteInt('Game', 'GibsCount', 1);
609 16: config.WriteInt('Game', 'GibsCount', 2);
610 32: config.WriteInt('Game', 'GibsCount', 3);
611 else config.WriteInt('Game', 'GibsCount', 4);
612 end;
614 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
615 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
616 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
617 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
618 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
619 config.WriteInt('Game', 'BloodCount', gBloodCount);
620 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
621 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
622 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
623 config.WriteInt('Game', 'Flash', gFlash);
624 config.WriteBool('Game', 'BackGround', gDrawBackGround);
625 config.WriteBool('Game', 'Messages', gShowMessages);
626 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
627 config.WriteInt('Game', 'ChatBubble', gChatBubble);
628 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
629 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
630 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
631 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
632 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
633 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
635 config.WriteStr ('GameplayCustom', 'Map', gcMap);
636 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
637 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
638 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
639 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
640 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
641 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
642 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
643 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
644 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
645 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
647 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
648 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
649 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
650 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
651 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
652 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
653 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
654 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
655 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
656 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
657 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
659 config.WriteStr('MasterServer', 'IP', NetSlistIP);
660 config.WriteInt('MasterServer', 'Port', NetSlistPort);
661 config.WriteStr('MasterServer', 'List', NetSlistList);
663 config.WriteStr ('Server', 'Name', NetServerName);
664 config.WriteStr ('Server', 'Password', NetPassword);
665 config.WriteInt ('Server', 'Port', NetPort);
666 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
667 config.WriteBool('Server', 'RCON', NetAllowRCON);
668 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
669 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
670 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
671 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
672 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
673 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
675 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
676 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
677 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
678 config.WriteStr ('Client', 'LastIP', NetClientIP);
679 config.WriteInt ('Client', 'LastPort', NetClientPort);
681 config.SaveFile(FileName);
682 config.Free();
683 end;
685 procedure g_Options_Write_Language(FileName: String);
686 var
687 config: TConfig;
688 begin
689 e_WriteLog('Writing language config', TMsgType.Notify);
691 config := TConfig.CreateFile(FileName);
692 config.WriteStr('Game', 'Language', gLanguage);
693 config.SaveFile(FileName);
694 config.Free();
695 end;
697 procedure g_Options_Write_Video(FileName: String);
698 var
699 config: TConfig;
700 sW, sH: Integer;
701 begin
702 e_WriteLog('Writing resolution to config', TMsgType.Notify);
704 config := TConfig.CreateFile(FileName);
706 if gWinMaximized and (not gFullscreen) then
707 begin
708 sW := gWinSizeX;
709 sH := gWinSizeY;
710 end
711 else
712 begin
713 sW := gScreenWidth;
714 sH := gScreenHeight;
715 end;
716 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
718 config.WriteInt('Video', 'ScreenWidth', sW);
719 config.WriteInt('Video', 'ScreenHeight', sH);
720 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
721 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
722 config.WriteBool('Video', 'Fullscreen', gFullscreen);
723 config.WriteBool('Video', 'Maximized', gWinMaximized);
725 config.WriteStr('Player1', 'Name', gPlayer1Settings.Name);
726 config.WriteStr('Player2', 'Name', gPlayer2Settings.Name);
728 config.SaveFile(FileName);
729 config.Free();
730 end;
732 procedure g_Options_Write_Gameplay_Custom(FileName: String);
733 var
734 config: TConfig;
735 begin
736 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
738 config := TConfig.CreateFile(FileName);
740 config.WriteStr ('GameplayCustom', 'Map', gcMap);
741 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
742 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
743 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
744 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
745 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
746 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
747 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
748 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
749 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
750 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
752 config.SaveFile(FileName);
753 config.Free();
754 end;
756 procedure g_Options_Write_Gameplay_Net(FileName: String);
757 var
758 config: TConfig;
759 begin
760 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
762 config := TConfig.CreateFile(FileName);
764 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
765 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
766 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
767 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
768 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
769 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
770 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
771 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
772 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
773 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
774 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
776 config.SaveFile(FileName);
777 config.Free();
778 end;
780 procedure g_Options_Write_Net_Server(FileName: String);
781 var
782 config: TConfig;
783 begin
784 e_WriteLog('Writing server config', TMsgType.Notify);
786 config := TConfig.CreateFile(FileName);
788 config.WriteStr ('Server', 'Name', NetServerName);
789 config.WriteStr ('Server', 'Password', NetPassword);
790 config.WriteInt ('Server', 'Port', NetPort);
791 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
792 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
793 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
795 config.SaveFile(FileName);
796 config.Free();
797 end;
799 procedure g_Options_Write_Net_Client(FileName: String);
800 var
801 config: TConfig;
802 begin
803 e_WriteLog('Writing client config', TMsgType.Notify);
805 config := TConfig.CreateFile(FileName);
807 config.WriteStr('Client', 'LastIP', NetClientIP);
808 config.WriteInt('Client', 'LastPort', NetClientPort);
810 config.SaveFile(FileName);
811 config.Free();
812 end;
814 initialization
815 Randomize;
816 machine := Random(10000)
817 end.