DEADSOFTWARE

add default dirs for linux and android
[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 display: TSDL_DisplayMode;
126 {$IFNDEF ANDROID}
127 var target, closest: TSDL_DisplayMode; percentage: Integer;
128 {$ENDIF}
129 begin
130 (* Display 0 = Primary display *)
131 gScreenWidth := 640;
132 gScreenHeight := 480;
133 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
134 gBPP := 32;
135 {$IFDEF ANDROID}
136 gFullScreen := True; (* rotation not allowed? *)
137 {$ELSE}
138 gFullScreen := False;
139 {$ENDIF}
140 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
141 begin
142 {$IFDEF ANDROID}
143 gScreenWidth := display.w;
144 gScreenHeight := display.h;
145 {$ELSE}
146 (* Window must be smaller than display *)
147 closest.w := display.w;
148 closest.h := display.h;
149 percentage := 75;
150 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
151 begin
152 if percentage < 25 then
153 begin
154 closest.w := display.w * 75 div 100;
155 closest.h := display.h * 75 div 100;
156 break;
157 end;
158 target.w := display.w * percentage div 100;
159 target.h := display.h * percentage div 100;
160 target.format := 0; (* didn't care *)
161 target.refresh_rate := 0; (* didn't care *)
162 target.driverdata := nil; (* init *)
163 SDL_GetClosestDisplayMode(0, @target, @closest);
164 Dec(percentage);
165 end;
166 gScreenWidth := closest.w;
167 gScreenHeight := closest.h;
168 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
169 {$ENDIF}
170 end
171 else
172 begin
173 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
174 end;
175 (* Must be positioned on primary display *)
176 gWinRealPosX := SDL_WINDOWPOS_CENTERED;
177 gWinRealPosY := SDL_WINDOWPOS_CENTERED;
178 gWinMaximized := False;
179 gVSync := True;
180 gTextureFilter := True;
181 glLegacyNPOT := False;
182 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
183 g_Console_ResetBinds;
184 end;
185 {$ELSE}
186 procedure g_Options_SetDefaultVideo;
187 begin
188 gScreenWidth := 640;
189 gScreenHeight := 480;
190 gBPP := 32;
191 gFullScreen := False;
192 gWinRealPosX := 0;
193 gWinRealPosY := 0;
194 gWinMaximized := False;
195 gVSync := True;
196 gTextureFilter := True;
197 glLegacyNPOT := False;
198 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
199 g_Console_ResetBinds;
200 end;
201 {$ENDIF}
203 procedure g_Options_SetDefault();
204 var
205 i: Integer;
206 begin
207 (* section Sound *)
208 gNoSound := False;
209 gSoundLevel := 75;
210 gMusicLevel := 65;
211 gMaxSimSounds := 8;
212 gMuteWhenInactive := False;
213 gAnnouncer := ANNOUNCE_MEPLUS;
214 gSoundEffectsDF := True;
215 gUseChatSounds := True;
216 gsSDLSampleRate := 44100;
217 gsSDLBufferSize := 2048;
219 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
221 with gPlayer1Settings do
222 begin
223 Name := GenPlayerName(1);
224 Model := STD_PLAYER_MODEL;
225 Color.R := PLAYER1_DEF_COLOR.R;
226 Color.G := PLAYER1_DEF_COLOR.G;
227 Color.B := PLAYER1_DEF_COLOR.B;
228 Team := TEAM_RED;
229 end;
231 with gPlayer2Settings do
232 begin
233 Name := GenPlayerName(2);
234 Model := STD_PLAYER_MODEL;
235 Color.R := PLAYER2_DEF_COLOR.R;
236 Color.G := PLAYER2_DEF_COLOR.G;
237 Color.B := PLAYER2_DEF_COLOR.B;
238 Team := TEAM_BLUE;
239 end;
241 (* section Joysticks *)
242 for i := 0 to e_MaxJoys - 1 do
243 begin
244 e_JoystickDeadzones[i] := 8192
245 end;
247 (* section Game *)
248 g_GFX_SetMax(2000);
249 g_Shells_SetMax(300);
250 g_Gibs_SetMax(150);
251 g_Corpses_SetMax(20);
252 gGibsCount := 32;
253 ITEM_RESPAWNTIME := 60 * 36;
254 gBloodCount := 4;
255 gAdvBlood := True;
256 gAdvCorpses := True;
257 gAdvGibs := True;
258 gFlash := 1;
259 gDrawBackGround := True;
260 gShowMessages := True;
261 gRevertPlayers := False;
262 gChatBubble := 4;
263 gSFSDebug := False;
264 gSFSFastMode := False;
265 e_FastScreenshots := True;
266 gDefaultMegawadStart := DF_Default_Megawad_Start;
267 gBerserkAutoswitch := True;
268 g_dbg_scale := 1.0;
270 gAskLanguage := True;
271 gLanguage := LANGUAGE_ENGLISH;
273 (* section GameplayCustom *)
274 gcMap := '';
275 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
276 gcTimeLimit := 0;
277 gcGoalLimit := 0;
278 gcMaxLives := 0;
279 gcPlayers := 1;
280 gcTeamDamage := False;
281 gcAllowExit := True;
282 gcWeaponStay := False;
283 gcMonsters := False;
284 gcBotsVS := 'Everybody';
286 (* section GameplayNetwork *)
287 gnMap := '';
288 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
289 gnTimeLimit := 0;
290 gnGoalLimit := 0;
291 gnMaxLives := 0;
292 gnPlayers := 1;
293 gnTeamDamage := False;
294 gnAllowExit := True;
295 gnWeaponStay := False;
296 gnMonsters := False;
297 gnBotsVS := 'Everybody';
299 (* section MasterServer *)
300 NetSlistIP := 'mpms.doom2d.org';
301 NetSlistPort := 25665;
302 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
304 (* section Server *)
305 NetServerName := 'Unnamed Server';
306 NetPassword := '';
307 NetPort := 25666;
308 NetMaxClients := 16;
309 NetAllowRCON := False;
310 NetRCONPassword := 'default';
311 NetUseMaster := True;
312 NetUpdateRate := 0;
313 NetRelupdRate := 18;
314 NetMasterRate := 60000;
315 NetForwardPorts := False;
317 (* section Client *)
318 NetInterpLevel := 2;
319 NetForcePlayerUpdate := False;
320 NetPredictSelf := True;
321 NetClientIP := '127.0.0.1';
322 NetClientPort := NetPort;
323 end;
325 procedure g_Options_Read(FileName: String);
326 var
327 i: Integer;
328 config: TConfig;
329 section: String;
331 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
332 begin
333 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
334 end;
336 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
337 begin
338 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
339 end;
341 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
342 begin
343 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
344 end;
346 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
347 begin
348 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
349 end;
351 procedure ReadBoolean (VAR v: Boolean; param: String);
352 begin
353 v := config.ReadBool(section, param, v)
354 end;
356 procedure ReadString (VAR v: String; param: String);
357 begin
358 v := config.ReadStr(section, param, v)
359 end;
361 begin
362 gAskLanguage := True;
363 e_WriteLog('Reading config', TMsgType.Notify);
364 g_Options_SetDefault;
366 if FileExists(FileName) = False then
367 begin
368 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
369 g_Options_SetDefaultVideo;
370 Exit
371 end;
373 config := TConfig.CreateFile(FileName);
375 section := 'Video';
376 ReadInteger(gScreenWidth, 'ScreenWidth', 0);
377 ReadInteger(gScreenHeight, 'ScreenHeight', 0);
378 ReadInteger(gWinRealPosX, 'WinPosX', 60);
379 ReadInteger(gWinRealPosY, 'WinPosY', 60);
380 ReadBoolean(gFullScreen, 'Fullscreen');
381 ReadBoolean(gWinMaximized, 'Maximized');
382 ReadInteger(gBPP, 'BPP', 0);
383 ReadInteger(gFreq, 'Freq', 0);
384 ReadBoolean(gVSync, 'VSync');
385 ReadBoolean(gTextureFilter, 'TextureFilter');
386 ReadBoolean(glNPOTOverride, 'LegacyCompatibleForce');
388 section := 'Sound';
389 ReadBoolean(gNoSound, 'NoSound');
390 ReadInteger(gSoundLevel, 'SoundLevel', 0, 255);
391 ReadInteger(gMusicLevel, 'MusicLevel', 0, 255);
392 ReadInteger(gMaxSimSounds, 'MaxSimSounds', 2, 66);
393 ReadBoolean(gMuteWhenInactive, 'MuteInactive');
394 ReadInteger(gAnnouncer, 'Announcer', ANNOUNCE_NONE, ANNOUNCE_ALL);
395 ReadBoolean(gSoundEffectsDF, 'SoundEffectsDF');
396 ReadBoolean(gUseChatSounds, 'ChatSounds');
397 ReadInteger(gsSDLSampleRate, 'SDLSampleRate', 11025, 96000);
398 ReadInteger(gsSDLBufferSize, 'SDLBufferSize', 64, 16384);
400 section := 'Player1';
401 with gPlayer1Settings do
402 begin
403 ReadString(Name, 'name');
404 ReadString(Model, 'model');
405 ReadInteger(Color.R, 'red', 0, 255);
406 ReadInteger(Color.G, 'green', 0, 255);
407 ReadInteger(Color.B, 'blue', 0, 255);
408 ReadInteger(Team, 'team');
409 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
410 Team := TEAM_RED;
411 end;
413 section := 'Player2';
414 with gPlayer2Settings do
415 begin
416 ReadString(Name, 'name');
417 ReadString(Model, 'model');
418 ReadInteger(Color.R, 'red', 0, 255);
419 ReadInteger(Color.G, 'green', 0, 255);
420 ReadInteger(Color.B, 'blue', 0, 255);
421 ReadInteger(Team, 'team');
422 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
423 Team := TEAM_RED;
424 end;
426 section := 'Joysticks';
427 for i := 0 to e_MaxJoys - 1 do
428 begin
429 ReadInteger(e_JoystickDeadzones[i], 'Deadzone' + IntToStr(i))
430 end;
432 section := 'Game';
433 ReadInteger(i, 'MaxParticles', 0, 50000); g_GFX_SetMax(i);
434 ReadInteger(i, 'MaxShells', 0, 600); g_Shells_SetMax(i);
435 ReadInteger(i, 'MaxGibs', 0, 500); g_Gibs_SetMax(i);
436 ReadInteger(i, 'MaxCorpses', 0, 100); g_Corpses_SetMax(i);
437 ReadInteger(i, 'GibsCount');
438 case i of
439 0: gGibsCount := 0;
440 1: gGibsCount := 8;
441 2: gGibsCount := 16;
442 3: gGibsCount := 32;
443 else gGibsCount := 48;
444 end;
445 i := ITEM_RESPAWNTIME div 36; ReadInteger(i, 'ItemRespawnTime', 0); ITEM_RESPAWNTIME := i * 36;
446 ReadInteger(gBloodCount, 'BloodCount', 0, 4);
447 ReadBoolean(gAdvBlood, 'AdvancesBlood');
448 ReadBoolean(gAdvCorpses, 'AdvancesCorpses');
449 ReadBoolean(gAdvGibs, 'AdvancesGibs');
450 ReadInteger(gFlash, 'Flash', 0, 2);
451 ReadBoolean(gDrawBackGround, 'BackGround');
452 ReadBoolean(gShowMessages, 'Messages');
453 ReadBoolean(gRevertPlayers, 'RevertPlayers');
454 ReadInteger(gChatBubble, 'ChatBubble', 0, 4);
455 ReadBoolean(gSFSDebug, 'SFSDebug'); wadoptDebug := gSFSDebug;
456 ReadBoolean(gSFSFastMode, 'SFSFastMode'); wadoptFast := gSFSFastMode;
457 ReadBoolean(e_FastScreenshots, 'FastScreenshots');
458 ReadString(gDefaultMegawadStart, 'DefaultMegawadStart');
459 ReadBoolean(gBerserkAutoswitch, 'BerserkAutoswitching');
460 i := Trunc(g_dbg_scale * 100); ReadInteger(i, 'Scale', 100); g_dbg_scale := i / 100;
461 ReadString(gLanguage, 'Language');
462 if (gLanguage = LANGUAGE_RUSSIAN) or (gLanguage = LANGUAGE_ENGLISH) then
463 gAskLanguage := False
464 else
465 gLanguage := LANGUAGE_ENGLISH;
467 section := 'GameplayCustom';
468 ReadString(gcMap, 'Map');
469 ReadString(gcGameMode, 'GameMode');
470 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
471 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
472 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
473 ReadInteger(gcPlayers, 'Players', 0, 2);
474 ReadBoolean(gcTeamDamage, 'TeamDamage');
475 ReadBoolean(gcAllowExit, 'AllowExit');
476 ReadBoolean(gcWeaponStay, 'WeaponStay');
477 ReadBoolean(gcMonsters, 'Monsters');
478 ReadString(gcBotsVS, 'BotsVS');
480 with gGameSettings do
481 begin
482 GameMode := g_Game_TextToMode(gcGameMode);
483 if GameMode = GM_NONE then
484 GameMode := GM_DM;
485 if GameMode = GM_SINGLE then
486 GameMode := GM_COOP;
487 TimeLimit := gcTimeLimit;
488 GoalLimit := gcGoalLimit;
489 MaxLives := gcMaxLives;
491 Options := 0;
492 if gcTeamDamage then
493 Options := Options or GAME_OPTION_TEAMDAMAGE;
494 if gcAllowExit then
495 Options := Options or GAME_OPTION_ALLOWEXIT;
496 if gcWeaponStay then
497 Options := Options or GAME_OPTION_WEAPONSTAY;
498 if gcMonsters then
499 Options := Options or GAME_OPTION_MONSTERS;
500 if gcBotsVS = 'Everybody' then
501 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
502 if gcBotsVS = 'Players' then
503 Options := Options or GAME_OPTION_BOTVSPLAYER;
504 if gcBotsVS = 'Monsters' then
505 Options := Options or GAME_OPTION_BOTVSMONSTER;
506 end;
508 section := 'GameplayNetwork';
509 ReadString(gnMap, 'Map');
510 ReadString(gnGameMode, 'GameMode');
511 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
512 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
513 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
514 ReadInteger(gnPlayers, 'Players', 0, 2);
515 ReadBoolean(gnTeamDamage, 'TeamDamage');
516 ReadBoolean(gnAllowExit, 'AllowExit');
517 ReadBoolean(gnWeaponStay, 'WeaponStay');
518 ReadBoolean(gnMonsters, 'Monsters');
519 ReadString(gnBotsVS, 'BotsVS');
521 section := 'MasterServer';
522 ReadString(NetSlistIP, 'IP');
523 ReadInteger(NetSlistPort, 'Port', 0, 65535);
524 ReadString(NetSlistList, 'List');
525 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
527 section := 'Server';
528 ReadString(NetServerName, 'Name');
529 ReadString(NetPassword, 'Password');
530 ReadInteger(NetPort, 'Port', 0, 65535);
531 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
532 ReadBoolean(NetAllowRCON, 'RCON');
533 ReadString(NetRCONPassword, 'RCONPassword');
534 ReadBoolean(NetUseMaster, 'SyncWithMaster');
535 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
536 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
537 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
538 ReadBoolean(NetForwardPorts, 'ForwardPorts');
540 section := 'Client';
541 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
542 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
543 ReadBoolean(NetPredictSelf, 'PredictSelf');
544 ReadString(NetClientIP, 'LastIP');
545 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
547 config.Free();
549 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
550 end;
552 procedure g_Options_Write(FileName: String);
553 var
554 config: TConfig;
555 i: Integer;
556 begin
557 e_WriteLog('Writing config', TMsgType.Notify);
559 config := TConfig.CreateFile(FileName);
561 config.WriteInt('Video', 'ScreenWidth', gScreenWidth);
562 config.WriteInt('Video', 'ScreenHeight', gScreenHeight);
563 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
564 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
565 config.WriteBool('Video', 'Fullscreen', gFullScreen);
566 config.WriteBool('Video', 'Maximized', gWinMaximized);
567 config.WriteInt('Video', 'BPP', gBPP);
568 config.WriteBool('Video', 'VSync', gVSync);
569 config.WriteBool('Video', 'TextureFilter', gTextureFilter);
570 config.WriteBool('Video', 'LegacyCompatibleForce', glNPOTOverride);
572 config.WriteBool('Sound', 'NoSound', gNoSound);
573 config.WriteInt('Sound', 'SoundLevel', gSoundLevel);
574 config.WriteInt('Sound', 'MusicLevel', gMusicLevel);
575 config.WriteInt('Sound', 'MaxSimSounds', gMaxSimSounds);
576 config.WriteBool('Sound', 'MuteInactive', gMuteWhenInactive);
577 config.WriteInt('Sound', 'Announcer', gAnnouncer);
578 config.WriteBool('Sound', 'SoundEffectsDF', gSoundEffectsDF);
579 config.WriteBool('Sound', 'ChatSounds', gUseChatSounds);
580 config.WriteInt('Sound', 'SDLSampleRate', gsSDLSampleRate);
581 config.WriteInt('Sound', 'SDLBufferSize', gsSDLBufferSize);
583 with config, gPlayer1Settings do
584 begin
585 WriteStr('Player1', 'Name', Name);
586 WriteStr('Player1', 'model', Model);
587 WriteInt('Player1', 'red', Color.R);
588 WriteInt('Player1', 'green', Color.G);
589 WriteInt('Player1', 'blue', Color.B);
590 WriteInt('Player1', 'team', Team);
591 end;
593 with config, gPlayer2Settings do
594 begin
595 WriteStr('Player2', 'Name', Name);
596 WriteStr('Player2', 'model', Model);
597 WriteInt('Player2', 'red', Color.R);
598 WriteInt('Player2', 'green', Color.G);
599 WriteInt('Player2', 'blue', Color.B);
600 WriteInt('Player2', 'team', Team);
601 end;
603 for i := 0 to e_MaxJoys-1 do
604 config.WriteInt('Joysticks', 'Deadzone' + IntToStr(i), e_JoystickDeadzones[i]);
606 with config do
607 case gGibsCount of
608 0: config.WriteInt('Game', 'GibsCount', 0);
609 8: config.WriteInt('Game', 'GibsCount', 1);
610 16: config.WriteInt('Game', 'GibsCount', 2);
611 32: config.WriteInt('Game', 'GibsCount', 3);
612 else config.WriteInt('Game', 'GibsCount', 4);
613 end;
615 config.WriteInt('Game', 'ItemRespawnTime', ITEM_RESPAWNTIME div 36);
616 config.WriteInt('Game', 'MaxParticles', g_GFX_GetMax());
617 config.WriteInt('Game', 'MaxShells', g_Shells_GetMax());
618 config.WriteInt('Game', 'MaxGibs', g_Gibs_GetMax());
619 config.WriteInt('Game', 'MaxCorpses', g_Corpses_GetMax());
620 config.WriteInt('Game', 'BloodCount', gBloodCount);
621 config.WriteBool('Game', 'AdvancesBlood', gAdvBlood);
622 config.WriteBool('Game', 'AdvancesCorpses', gAdvCorpses);
623 config.WriteBool('Game', 'AdvancesGibs', gAdvGibs);
624 config.WriteInt('Game', 'Flash', gFlash);
625 config.WriteBool('Game', 'BackGround', gDrawBackGround);
626 config.WriteBool('Game', 'Messages', gShowMessages);
627 config.WriteBool('Game', 'RevertPlayers', gRevertPlayers);
628 config.WriteInt('Game', 'ChatBubble', gChatBubble);
629 config.WriteBool('Game', 'SFSDebug', gSFSDebug);
630 config.WriteBool('Game', 'SFSFastMode', gSFSFastMode);
631 config.WriteBool('Game', 'FastScreenshots', e_FastScreenshots);
632 config.WriteStr('Game', 'DefaultMegawadStart', gDefaultMegawadStart);
633 config.WriteBool('Game', 'BerserkAutoswitching', gBerserkAutoswitch);
634 config.WriteInt('Game', 'Scale', Round(g_dbg_scale * 100));
636 config.WriteStr ('GameplayCustom', 'Map', gcMap);
637 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
638 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
639 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
640 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
641 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
642 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
643 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
644 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
645 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
646 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
648 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
649 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
650 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
651 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
652 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
653 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
654 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
655 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
656 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
657 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
658 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
660 config.WriteStr('MasterServer', 'IP', NetSlistIP);
661 config.WriteInt('MasterServer', 'Port', NetSlistPort);
662 config.WriteStr('MasterServer', 'List', NetSlistList);
664 config.WriteStr ('Server', 'Name', NetServerName);
665 config.WriteStr ('Server', 'Password', NetPassword);
666 config.WriteInt ('Server', 'Port', NetPort);
667 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
668 config.WriteBool('Server', 'RCON', NetAllowRCON);
669 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
670 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
671 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
672 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
673 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
674 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
676 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
677 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
678 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
679 config.WriteStr ('Client', 'LastIP', NetClientIP);
680 config.WriteInt ('Client', 'LastPort', NetClientPort);
682 config.SaveFile(FileName);
683 config.Free();
684 end;
686 procedure g_Options_Write_Language(FileName: String);
687 var
688 config: TConfig;
689 begin
690 e_WriteLog('Writing language config', TMsgType.Notify);
692 config := TConfig.CreateFile(FileName);
693 config.WriteStr('Game', 'Language', gLanguage);
694 config.SaveFile(FileName);
695 config.Free();
696 end;
698 procedure g_Options_Write_Video(FileName: String);
699 var
700 config: TConfig;
701 sW, sH: Integer;
702 begin
703 e_WriteLog('Writing resolution to config', TMsgType.Notify);
705 config := TConfig.CreateFile(FileName);
707 if gWinMaximized and (not gFullscreen) then
708 begin
709 sW := gWinSizeX;
710 sH := gWinSizeY;
711 end
712 else
713 begin
714 sW := gScreenWidth;
715 sH := gScreenHeight;
716 end;
717 e_LogWritefln(' (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
719 config.WriteInt('Video', 'ScreenWidth', sW);
720 config.WriteInt('Video', 'ScreenHeight', sH);
721 config.WriteInt('Video', 'WinPosX', gWinRealPosX);
722 config.WriteInt('Video', 'WinPosY', gWinRealPosY);
723 config.WriteBool('Video', 'Fullscreen', gFullscreen);
724 config.WriteBool('Video', 'Maximized', gWinMaximized);
726 config.WriteStr('Player1', 'Name', gPlayer1Settings.Name);
727 config.WriteStr('Player2', 'Name', gPlayer2Settings.Name);
729 config.SaveFile(FileName);
730 config.Free();
731 end;
733 procedure g_Options_Write_Gameplay_Custom(FileName: String);
734 var
735 config: TConfig;
736 begin
737 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
739 config := TConfig.CreateFile(FileName);
741 config.WriteStr ('GameplayCustom', 'Map', gcMap);
742 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
743 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
744 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
745 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
746 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
747 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
748 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
749 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
750 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
751 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
753 config.SaveFile(FileName);
754 config.Free();
755 end;
757 procedure g_Options_Write_Gameplay_Net(FileName: String);
758 var
759 config: TConfig;
760 begin
761 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
763 config := TConfig.CreateFile(FileName);
765 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
766 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
767 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
768 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
769 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
770 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
771 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
772 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
773 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
774 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
775 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
777 config.SaveFile(FileName);
778 config.Free();
779 end;
781 procedure g_Options_Write_Net_Server(FileName: String);
782 var
783 config: TConfig;
784 begin
785 e_WriteLog('Writing server config', TMsgType.Notify);
787 config := TConfig.CreateFile(FileName);
789 config.WriteStr ('Server', 'Name', NetServerName);
790 config.WriteStr ('Server', 'Password', NetPassword);
791 config.WriteInt ('Server', 'Port', NetPort);
792 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
793 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
794 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
796 config.SaveFile(FileName);
797 config.Free();
798 end;
800 procedure g_Options_Write_Net_Client(FileName: String);
801 var
802 config: TConfig;
803 begin
804 e_WriteLog('Writing client config', TMsgType.Notify);
806 config := TConfig.CreateFile(FileName);
808 config.WriteStr('Client', 'LastIP', NetClientIP);
809 config.WriteInt('Client', 'LastPort', NetClientPort);
811 config.SaveFile(FileName);
812 config.Free();
813 end;
815 initialization
816 Randomize;
817 machine := Random(10000)
818 end.