DEADSOFTWARE

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