DEADSOFTWARE

escape strings in stat files
[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, utils;
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_Gameplay_Custom(FileName: String);
30 procedure g_Options_Write_Gameplay_Net(FileName: String);
31 procedure g_Options_Write_Net_Server(FileName: String);
32 procedure g_Options_Write_Net_Client(FileName: String);
33 procedure g_Options_Commands (p: SSArray);
35 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
37 var
38 gScreenWidth: Word;
39 gScreenHeight: Word;
40 gBPP: Integer;
41 gFreq: Byte;
42 gFullscreen: Boolean;
43 gWinMaximized: Boolean;
44 gVSync: Boolean;
45 glLegacyNPOT: Boolean;
46 gTextureFilter: Boolean;
47 gNoSound: Boolean;
48 gSoundLevel: Integer;
49 gMusicLevel: Integer;
50 gMaxSimSounds: Integer;
51 gMuteWhenInactive: Boolean;
52 gAdvCorpses: Boolean;
53 gAdvBlood: Boolean;
54 gAdvGibs: Boolean;
55 gGibsCount: Integer;
56 gBloodCount: Integer;
57 gFlash: Integer;
58 gDrawBackGround: Boolean;
59 gShowMessages: Boolean;
60 gRevertPlayers: Boolean;
61 gLanguage: String;
62 gAskLanguage: Boolean;
63 gSaveStats: Boolean = False;
64 gScreenshotStats: Boolean = False;
65 gcMap: String;
66 gcGameMode: String;
67 gcTimeLimit: Word;
68 gcGoalLimit: Word;
69 gcMaxLives: Byte;
70 gcPlayers: Byte;
71 gcTeamDamage: Boolean;
72 gcAllowExit: Boolean;
73 gcWeaponStay: Boolean;
74 gcMonsters: Boolean;
75 gcBotsVS: String;
76 gnMap: String;
77 gnGameMode: String;
78 gnTimeLimit: Word;
79 gnGoalLimit: Word;
80 gnMaxLives: Byte;
81 gnPlayers: Byte;
82 gnTeamDamage: Boolean;
83 gnAllowExit: Boolean;
84 gnWeaponStay: Boolean;
85 gnMonsters: Boolean;
86 gnBotsVS: String;
87 gsSDLSampleRate: Integer;
88 gsSDLBufferSize: Integer;
89 gDefaultMegawadStart: AnsiString;
90 gBerserkAutoswitch: Boolean;
91 glNPOTOverride: Boolean = false;
93 implementation
95 uses
96 {$INCLUDE ../nogl/noGLuses.inc}
97 {$IFDEF USE_SDL2}
98 SDL2,
99 {$ENDIF}
100 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
101 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
102 g_items, wadreader, e_graphics, g_touch, envvars, g_system;
104 var
105 machine: Integer;
107 function GenPlayerName (n: Integer): String;
108 begin
109 ASSERT(n >= 1);
110 Result := GetUserName;
111 if Result = '' then
112 Result := 'Player' + IntToStr(machine MOD 10000);
113 if n = 1 then
114 Result := Copy(Result, 1, 12) + ' '
115 else
116 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
117 end;
119 {$IFDEF USE_SDL2}
120 procedure g_Options_SetDefaultVideo;
121 var display: TSDL_DisplayMode;
122 {$IFNDEF ANDROID}
123 var target, closest: TSDL_DisplayMode; percentage: Integer;
124 {$ENDIF}
125 begin
126 (* Display 0 = Primary display *)
127 gScreenWidth := 640;
128 gScreenHeight := 480;
129 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
130 gBPP := 32;
131 {$IFDEF ANDROID}
132 gFullScreen := True; (* rotation not allowed? *)
133 {$ELSE}
134 gFullScreen := False;
135 {$ENDIF}
136 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
137 begin
138 {$IFDEF ANDROID}
139 gScreenWidth := display.w;
140 gScreenHeight := display.h;
141 {$ELSE}
142 (* Window must be smaller than display *)
143 closest.w := display.w;
144 closest.h := display.h;
145 percentage := 75;
146 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
147 begin
148 if percentage < 25 then
149 begin
150 closest.w := display.w * 75 div 100;
151 closest.h := display.h * 75 div 100;
152 break;
153 end;
154 target.w := display.w * percentage div 100;
155 target.h := display.h * percentage div 100;
156 target.format := 0; (* didn't care *)
157 target.refresh_rate := 0; (* didn't care *)
158 target.driverdata := nil; (* init *)
159 SDL_GetClosestDisplayMode(0, @target, @closest);
160 Dec(percentage);
161 end;
162 gScreenWidth := closest.w;
163 gScreenHeight := closest.h;
164 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
165 {$ENDIF}
166 end
167 else
168 begin
169 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
170 end;
171 (* Must be positioned on primary display *)
172 gWinMaximized := False;
173 gVSync := True;
174 gTextureFilter := True;
175 glLegacyNPOT := False;
176 gRC_Width := gScreenWidth;
177 gRC_Height := gScreenHeight;
178 gRC_FullScreen := gFullScreen;
179 gRC_Maximized := gWinMaximized;
180 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
181 g_Console_ResetBinds;
182 end;
183 {$ELSE}
184 procedure g_Options_SetDefaultVideo;
185 begin
186 gScreenWidth := 640;
187 gScreenHeight := 480;
188 gBPP := 32;
189 gFullScreen := False;
190 gWinMaximized := False;
191 gVSync := True;
192 gTextureFilter := True;
193 glLegacyNPOT := False;
194 gRC_Width := gScreenWidth;
195 gRC_Height := gScreenHeight;
196 gRC_FullScreen := gFullScreen;
197 gRC_Maximized := gWinMaximized;
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 wadoptDebug := False;
264 wadoptFast := False;
265 e_FastScreenshots := True;
266 gDefaultMegawadStart := DF_Default_Megawad_Start;
267 gBerserkAutoswitch := True;
268 g_dbg_scale := 1.0;
269 gSaveStats := False;
271 gAskLanguage := True;
272 gLanguage := LANGUAGE_ENGLISH;
274 (* section GameplayCustom *)
275 gcMap := '';
276 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
277 gcTimeLimit := 0;
278 gcGoalLimit := 0;
279 gcMaxLives := 0;
280 gcPlayers := 1;
281 gcTeamDamage := False;
282 gcAllowExit := True;
283 gcWeaponStay := False;
284 gcMonsters := False;
285 gcBotsVS := 'Everybody';
287 (* section GameplayNetwork *)
288 gnMap := '';
289 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
290 gnTimeLimit := 0;
291 gnGoalLimit := 0;
292 gnMaxLives := 0;
293 gnPlayers := 1;
294 gnTeamDamage := False;
295 gnAllowExit := True;
296 gnWeaponStay := False;
297 gnMonsters := False;
298 gnBotsVS := 'Everybody';
300 (* section MasterServer *)
301 NetSlistIP := 'mpms.doom2d.org';
302 NetSlistPort := 25665;
303 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
305 (* section Server *)
306 NetServerName := 'Unnamed Server';
307 NetPassword := '';
308 NetPort := 25666;
309 NetMaxClients := 16;
310 NetAllowRCON := False;
311 NetRCONPassword := 'default';
312 NetUseMaster := True;
313 NetUpdateRate := 0;
314 NetRelupdRate := 18;
315 NetMasterRate := 60000;
316 NetForwardPorts := False;
318 (* section Client *)
319 NetInterpLevel := 2;
320 NetForcePlayerUpdate := False;
321 NetPredictSelf := True;
322 NetClientIP := '127.0.0.1';
323 NetClientPort := NetPort;
324 end;
326 procedure g_Options_Read(FileName: String);
327 var
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 := 'Player1';
376 with gPlayer1Settings do
377 begin
378 ReadString(Name, 'name');
379 ReadString(Model, 'model');
380 ReadInteger(Color.R, 'red', 0, 255);
381 ReadInteger(Color.G, 'green', 0, 255);
382 ReadInteger(Color.B, 'blue', 0, 255);
383 ReadInteger(Team, 'team');
384 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
385 Team := TEAM_RED;
386 end;
388 section := 'Player2';
389 with gPlayer2Settings 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 := 'GameplayCustom';
402 ReadString(gcMap, 'Map');
403 ReadString(gcGameMode, 'GameMode');
404 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
405 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
406 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
407 ReadInteger(gcPlayers, 'Players', 0, 2);
408 ReadBoolean(gcTeamDamage, 'TeamDamage');
409 ReadBoolean(gcAllowExit, 'AllowExit');
410 ReadBoolean(gcWeaponStay, 'WeaponStay');
411 ReadBoolean(gcMonsters, 'Monsters');
412 ReadString(gcBotsVS, 'BotsVS');
414 with gGameSettings do
415 begin
416 GameMode := g_Game_TextToMode(gcGameMode);
417 if GameMode = GM_NONE then
418 GameMode := GM_DM;
419 if GameMode = GM_SINGLE then
420 GameMode := GM_COOP;
421 TimeLimit := gcTimeLimit;
422 GoalLimit := gcGoalLimit;
423 MaxLives := gcMaxLives;
425 Options := 0;
426 if gcTeamDamage then
427 Options := Options or GAME_OPTION_TEAMDAMAGE;
428 if gcAllowExit then
429 Options := Options or GAME_OPTION_ALLOWEXIT;
430 if gcWeaponStay then
431 Options := Options or GAME_OPTION_WEAPONSTAY;
432 if gcMonsters then
433 Options := Options or GAME_OPTION_MONSTERS;
434 if gcBotsVS = 'Everybody' then
435 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
436 if gcBotsVS = 'Players' then
437 Options := Options or GAME_OPTION_BOTVSPLAYER;
438 if gcBotsVS = 'Monsters' then
439 Options := Options or GAME_OPTION_BOTVSMONSTER;
440 end;
442 section := 'GameplayNetwork';
443 ReadString(gnMap, 'Map');
444 ReadString(gnGameMode, 'GameMode');
445 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
446 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
447 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
448 ReadInteger(gnPlayers, 'Players', 0, 2);
449 ReadBoolean(gnTeamDamage, 'TeamDamage');
450 ReadBoolean(gnAllowExit, 'AllowExit');
451 ReadBoolean(gnWeaponStay, 'WeaponStay');
452 ReadBoolean(gnMonsters, 'Monsters');
453 ReadString(gnBotsVS, 'BotsVS');
455 section := 'MasterServer';
456 ReadString(NetSlistIP, 'IP');
457 ReadInteger(NetSlistPort, 'Port', 0, 65535);
458 ReadString(NetSlistList, 'List');
459 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
461 section := 'Server';
462 ReadString(NetServerName, 'Name');
463 ReadString(NetPassword, 'Password');
464 ReadInteger(NetPort, 'Port', 0, 65535);
465 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
466 ReadBoolean(NetAllowRCON, 'RCON');
467 ReadString(NetRCONPassword, 'RCONPassword');
468 ReadBoolean(NetUseMaster, 'SyncWithMaster');
469 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
470 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
471 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
472 ReadBoolean(NetForwardPorts, 'ForwardPorts');
474 section := 'Client';
475 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
476 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
477 ReadBoolean(NetPredictSelf, 'PredictSelf');
478 ReadString(NetClientIP, 'LastIP');
479 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
481 config.Free();
483 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
484 end;
486 procedure g_Options_Write(FileName: String);
487 var config: TConfig;
488 begin
489 e_WriteLog('Writing config', TMsgType.Notify);
491 config := TConfig.CreateFile(FileName);
493 with config, gPlayer1Settings do
494 begin
495 WriteStr('Player1', 'Name', Name);
496 WriteStr('Player1', 'model', Model);
497 WriteInt('Player1', 'red', Color.R);
498 WriteInt('Player1', 'green', Color.G);
499 WriteInt('Player1', 'blue', Color.B);
500 WriteInt('Player1', 'team', Team);
501 end;
503 with config, gPlayer2Settings do
504 begin
505 WriteStr('Player2', 'Name', Name);
506 WriteStr('Player2', 'model', Model);
507 WriteInt('Player2', 'red', Color.R);
508 WriteInt('Player2', 'green', Color.G);
509 WriteInt('Player2', 'blue', Color.B);
510 WriteInt('Player2', 'team', Team);
511 end;
513 config.WriteStr ('GameplayCustom', 'Map', gcMap);
514 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
515 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
516 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
517 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
518 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
519 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
520 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
521 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
522 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
523 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
525 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
526 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
527 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
528 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
529 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
530 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
531 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
532 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
533 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
534 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
535 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
537 config.WriteStr('MasterServer', 'IP', NetSlistIP);
538 config.WriteInt('MasterServer', 'Port', NetSlistPort);
539 config.WriteStr('MasterServer', 'List', NetSlistList);
541 config.WriteStr ('Server', 'Name', NetServerName);
542 config.WriteStr ('Server', 'Password', NetPassword);
543 config.WriteInt ('Server', 'Port', NetPort);
544 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
545 config.WriteBool('Server', 'RCON', NetAllowRCON);
546 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
547 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
548 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
549 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
550 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
551 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
553 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
554 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
555 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
556 config.WriteStr ('Client', 'LastIP', NetClientIP);
557 config.WriteInt ('Client', 'LastPort', NetClientPort);
559 config.SaveFile(FileName);
560 config.Free();
561 end;
563 procedure g_Options_Write_Gameplay_Custom(FileName: String);
564 var
565 config: TConfig;
566 begin
567 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
569 config := TConfig.CreateFile(FileName);
571 config.WriteStr ('GameplayCustom', 'Map', gcMap);
572 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
573 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
574 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
575 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
576 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
577 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
578 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
579 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
580 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
581 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
583 config.SaveFile(FileName);
584 config.Free();
585 end;
587 procedure g_Options_Write_Gameplay_Net(FileName: String);
588 var
589 config: TConfig;
590 begin
591 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
593 config := TConfig.CreateFile(FileName);
595 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
596 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
597 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
598 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
599 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
600 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
601 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
602 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
603 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
604 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
605 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
607 config.SaveFile(FileName);
608 config.Free();
609 end;
611 procedure g_Options_Write_Net_Server(FileName: String);
612 var
613 config: TConfig;
614 begin
615 e_WriteLog('Writing server config', TMsgType.Notify);
617 config := TConfig.CreateFile(FileName);
619 config.WriteStr ('Server', 'Name', NetServerName);
620 config.WriteStr ('Server', 'Password', NetPassword);
621 config.WriteInt ('Server', 'Port', NetPort);
622 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
623 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
624 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
626 config.SaveFile(FileName);
627 config.Free();
628 end;
630 procedure g_Options_Write_Net_Client(FileName: String);
631 var
632 config: TConfig;
633 begin
634 e_WriteLog('Writing client config', TMsgType.Notify);
636 config := TConfig.CreateFile(FileName);
638 config.WriteStr('Client', 'LastIP', NetClientIP);
639 config.WriteInt('Client', 'LastPort', NetClientPort);
641 config.SaveFile(FileName);
642 config.Free();
643 end;
645 procedure g_Options_Commands (p: SSArray);
646 var cmd: AnsiString; i: Integer;
647 begin
648 cmd := LowerCase(p[0]);
649 case cmd of
650 'r_reset':
651 begin
652 sys_EnableVSync(gVSync);
653 gRC_Width := Max(1, gRC_Width);
654 gRC_Height := Max(1, gRC_Height);
655 gBPP := Max(1, gBPP);
656 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
657 e_LogWriteln('resolution changed')
658 else
659 e_LogWriteln('resolution not changed')
660 end;
661 'g_language':
662 begin
663 if Length(p) = 2 then
664 begin
665 gAskLanguage := true;
666 gLanguage := LANGUAGE_ENGLISH;
667 case LowerCase(p[1]) of
668 'english':
669 begin
670 gAskLanguage := false;
671 gLanguage := LANGUAGE_ENGLISH;
672 end;
673 'russian':
674 begin
675 gAskLanguage := false;
676 gLanguage := LANGUAGE_RUSSIAN;
677 end;
678 'ask':
679 begin
680 gAskLanguage := true;
681 gLanguage := LANGUAGE_ENGLISH;
682 end;
683 end;
684 g_Language_Set(gLanguage)
685 end
686 else
687 begin
688 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd])
689 end
690 end;
691 'g_max_particles':
692 begin
693 if Length(p) = 2 then
694 begin
695 i := Max(0, StrToInt(p[1]));
696 g_GFX_SetMax(i)
697 end
698 else if Length(p) = 1 then
699 begin
700 e_LogWritefln('%s', [g_GFX_GetMax()])
701 end
702 else
703 begin
704 e_LogWritefln('usage: %s <n>', [cmd])
705 end
706 end;
707 'g_max_shells':
708 begin
709 if Length(p) = 2 then
710 begin
711 i := Max(0, StrToInt(p[1]));
712 g_Shells_SetMax(i)
713 end
714 else if Length(p) = 1 then
715 begin
716 e_LogWritefln('%s', [g_Shells_GetMax()])
717 end
718 else
719 begin
720 e_LogWritefln('usage: %s <n>', [cmd])
721 end
722 end;
723 'g_max_gibs':
724 begin
725 if Length(p) = 2 then
726 begin
727 i := Max(0, StrToInt(p[1]));
728 g_Gibs_SetMax(i)
729 end
730 else if Length(p) = 1 then
731 begin
732 e_LogWritefln('%s', [g_Gibs_GetMax()])
733 end
734 else
735 begin
736 e_LogWritefln('usage: %s <n>', [cmd])
737 end
738 end;
739 'g_max_corpses':
740 begin
741 if Length(p) = 2 then
742 begin
743 i := Max(0, StrToInt(p[1]));
744 g_Corpses_SetMax(i)
745 end
746 else if Length(p) = 1 then
747 begin
748 e_LogWritefln('%s', [g_Corpses_GetMax()])
749 end
750 else
751 begin
752 e_LogWritefln('usage: %s <n>', [cmd])
753 end
754 end;
755 'g_item_respawn_time':
756 begin
757 if Length(p) = 2 then
758 ITEM_RESPAWNTIME := Max(0, StrToInt(p[1])) * 36
759 else if Length(p) = 1 then
760 e_LogWritefln('%s', [ITEM_RESPAWNTIME div 36])
761 else
762 e_LogWritefln('usage: %s <n>', [cmd])
763 end;
764 end;
765 end;
767 initialization
768 Randomize;
769 machine := Random(10000);
771 (* Video *)
772 conRegVar('r_width', @gRC_Width, '', '');
773 conRegVar('r_height', @gRC_Height, '', '');
774 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
775 conRegVar('r_maximized', @gRC_Maximized, '', '');
776 conRegVar('r_bpp', @gBPP, '', '');
777 conRegVar('r_vsync', @gVSync, '', '');
778 conRegVar('r_texfilter', @gTextureFilter, '', '');
779 conRegVar('r_npot', @glNPOTOverride, '', '');
781 (* Sound *)
782 conRegVar('s_nosound', @gNoSound, '', '');
783 conRegVar('s_soundvolume', @gSoundLevel, '', '');
784 conRegVar('s_musicvolume', @gMusicLevel, '', '');
785 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
786 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
787 conRegVar('s_announcer', @gAnnouncer, '', '');
788 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
789 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
790 {$IFDEF USE_SDLMIXER}
791 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
792 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
793 {$ENDIF}
795 (* Game *)
796 conRegVar('g_gibs_count', @gGibsCount, '', '');
797 conRegVar('g_blood_count', @gBloodCount, '', '');
798 conRegVar('g_adv_blood', @gAdvBlood, '', '');
799 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
800 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
801 conRegVar('r_flash', @gFlash, '', '');
802 conRegVar('r_background', @gDrawBackGround, '', '');
803 conRegVar('g_show_messages', @gShowMessages, '', '');
804 conRegVar('r_revert_players', @gRevertPlayers, '', '');
805 conRegVar('r_chat_bubble', @gChatBubble, '', '');
806 conRegVar('sfs_debug', @wadoptDebug, '', '');
807 conRegVar('sfs_fastmode', @wadoptFast, '', '');
808 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
809 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
810 conRegVar('g_save_stats', @gSaveStats, '', '');
811 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
812 end.