DEADSOFTWARE

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