DEADSOFTWARE

fix screen size saving after first start
[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 gcMap: String;
64 gcGameMode: String;
65 gcTimeLimit: Word;
66 gcGoalLimit: Word;
67 gcMaxLives: Byte;
68 gcPlayers: Byte;
69 gcTeamDamage: Boolean;
70 gcAllowExit: Boolean;
71 gcWeaponStay: Boolean;
72 gcMonsters: Boolean;
73 gcBotsVS: String;
74 gnMap: String;
75 gnGameMode: String;
76 gnTimeLimit: Word;
77 gnGoalLimit: Word;
78 gnMaxLives: Byte;
79 gnPlayers: Byte;
80 gnTeamDamage: Boolean;
81 gnAllowExit: Boolean;
82 gnWeaponStay: Boolean;
83 gnMonsters: Boolean;
84 gnBotsVS: String;
85 gsSDLSampleRate: Integer;
86 gsSDLBufferSize: Integer;
87 gDefaultMegawadStart: AnsiString;
88 gBerserkAutoswitch: Boolean;
89 glNPOTOverride: Boolean = false;
91 implementation
93 uses
94 {$INCLUDE ../nogl/noGLuses.inc}
95 {$IFDEF USE_SDL2}
96 SDL2,
97 {$ENDIF}
98 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
99 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
100 g_items, wadreader, e_graphics, g_touch, envvars, g_system;
102 var
103 machine: Integer;
105 function GenPlayerName (n: Integer): String;
106 begin
107 ASSERT(n >= 1);
108 Result := GetUserName;
109 if Result = '' then
110 Result := 'Player' + IntToStr(machine MOD 10000);
111 if n = 1 then
112 Result := Copy(Result, 1, 12) + ' '
113 else
114 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
115 end;
117 {$IFDEF USE_SDL2}
118 procedure g_Options_SetDefaultVideo;
119 var display: TSDL_DisplayMode;
120 {$IFNDEF ANDROID}
121 var target, closest: TSDL_DisplayMode; percentage: Integer;
122 {$ENDIF}
123 begin
124 (* Display 0 = Primary display *)
125 gScreenWidth := 640;
126 gScreenHeight := 480;
127 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
128 gBPP := 32;
129 {$IFDEF ANDROID}
130 gFullScreen := True; (* rotation not allowed? *)
131 {$ELSE}
132 gFullScreen := False;
133 {$ENDIF}
134 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
135 begin
136 {$IFDEF ANDROID}
137 gScreenWidth := display.w;
138 gScreenHeight := display.h;
139 {$ELSE}
140 (* Window must be smaller than display *)
141 closest.w := display.w;
142 closest.h := display.h;
143 percentage := 75;
144 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
145 begin
146 if percentage < 25 then
147 begin
148 closest.w := display.w * 75 div 100;
149 closest.h := display.h * 75 div 100;
150 break;
151 end;
152 target.w := display.w * percentage div 100;
153 target.h := display.h * percentage div 100;
154 target.format := 0; (* didn't care *)
155 target.refresh_rate := 0; (* didn't care *)
156 target.driverdata := nil; (* init *)
157 SDL_GetClosestDisplayMode(0, @target, @closest);
158 Dec(percentage);
159 end;
160 gScreenWidth := closest.w;
161 gScreenHeight := closest.h;
162 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
163 {$ENDIF}
164 end
165 else
166 begin
167 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
168 end;
169 (* Must be positioned on primary display *)
170 gWinMaximized := False;
171 gVSync := True;
172 gTextureFilter := True;
173 glLegacyNPOT := False;
174 gRC_Width := gScreenWidth;
175 gRC_Height := gScreenHeight;
176 gRC_FullScreen := gFullScreen;
177 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
178 g_Console_ResetBinds;
179 end;
180 {$ELSE}
181 procedure g_Options_SetDefaultVideo;
182 begin
183 gScreenWidth := 640;
184 gScreenHeight := 480;
185 gBPP := 32;
186 gFullScreen := False;
187 gWinMaximized := False;
188 gVSync := True;
189 gTextureFilter := True;
190 glLegacyNPOT := False;
191 gRC_Width := gScreenWidth;
192 gRC_Height := gScreenHeight;
193 gRC_FullScreen := gFullScreen;
194 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
195 g_Console_ResetBinds;
196 end;
197 {$ENDIF}
199 procedure g_Options_SetDefault();
200 var
201 i: Integer;
202 begin
203 (* section Sound *)
204 gNoSound := False;
205 gSoundLevel := 75;
206 gMusicLevel := 65;
207 gMaxSimSounds := 8;
208 gMuteWhenInactive := False;
209 gAnnouncer := ANNOUNCE_MEPLUS;
210 gSoundEffectsDF := True;
211 gUseChatSounds := True;
212 gsSDLSampleRate := 44100;
213 gsSDLBufferSize := 2048;
215 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
217 with gPlayer1Settings do
218 begin
219 Name := GenPlayerName(1);
220 Model := STD_PLAYER_MODEL;
221 Color.R := PLAYER1_DEF_COLOR.R;
222 Color.G := PLAYER1_DEF_COLOR.G;
223 Color.B := PLAYER1_DEF_COLOR.B;
224 Team := TEAM_RED;
225 end;
227 with gPlayer2Settings do
228 begin
229 Name := GenPlayerName(2);
230 Model := STD_PLAYER_MODEL;
231 Color.R := PLAYER2_DEF_COLOR.R;
232 Color.G := PLAYER2_DEF_COLOR.G;
233 Color.B := PLAYER2_DEF_COLOR.B;
234 Team := TEAM_BLUE;
235 end;
237 (* section Joysticks *)
238 for i := 0 to e_MaxJoys - 1 do
239 begin
240 e_JoystickDeadzones[i] := 8192
241 end;
243 (* section Game *)
244 g_GFX_SetMax(2000);
245 g_Shells_SetMax(300);
246 g_Gibs_SetMax(150);
247 g_Corpses_SetMax(20);
248 gGibsCount := 32;
249 ITEM_RESPAWNTIME := 60 * 36;
250 gBloodCount := 4;
251 gAdvBlood := True;
252 gAdvCorpses := True;
253 gAdvGibs := True;
254 gFlash := 1;
255 gDrawBackGround := True;
256 gShowMessages := True;
257 gRevertPlayers := False;
258 gChatBubble := 4;
259 wadoptDebug := False;
260 wadoptFast := False;
261 e_FastScreenshots := True;
262 gDefaultMegawadStart := DF_Default_Megawad_Start;
263 gBerserkAutoswitch := True;
264 g_dbg_scale := 1.0;
266 gAskLanguage := True;
267 gLanguage := LANGUAGE_ENGLISH;
269 (* section GameplayCustom *)
270 gcMap := '';
271 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
272 gcTimeLimit := 0;
273 gcGoalLimit := 0;
274 gcMaxLives := 0;
275 gcPlayers := 1;
276 gcTeamDamage := False;
277 gcAllowExit := True;
278 gcWeaponStay := False;
279 gcMonsters := False;
280 gcBotsVS := 'Everybody';
282 (* section GameplayNetwork *)
283 gnMap := '';
284 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
285 gnTimeLimit := 0;
286 gnGoalLimit := 0;
287 gnMaxLives := 0;
288 gnPlayers := 1;
289 gnTeamDamage := False;
290 gnAllowExit := True;
291 gnWeaponStay := False;
292 gnMonsters := False;
293 gnBotsVS := 'Everybody';
295 (* section MasterServer *)
296 NetSlistIP := 'mpms.doom2d.org';
297 NetSlistPort := 25665;
298 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
300 (* section Server *)
301 NetServerName := 'Unnamed Server';
302 NetPassword := '';
303 NetPort := 25666;
304 NetMaxClients := 16;
305 NetAllowRCON := False;
306 NetRCONPassword := 'default';
307 NetUseMaster := True;
308 NetUpdateRate := 0;
309 NetRelupdRate := 18;
310 NetMasterRate := 60000;
311 NetForwardPorts := False;
313 (* section Client *)
314 NetInterpLevel := 2;
315 NetForcePlayerUpdate := False;
316 NetPredictSelf := True;
317 NetClientIP := '127.0.0.1';
318 NetClientPort := NetPort;
319 end;
321 procedure g_Options_Read(FileName: String);
322 var
323 config: TConfig;
324 section: String;
326 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
327 begin
328 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
329 end;
331 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
332 begin
333 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
334 end;
336 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
337 begin
338 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
339 end;
341 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
342 begin
343 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
344 end;
346 procedure ReadBoolean (VAR v: Boolean; param: String);
347 begin
348 v := config.ReadBool(section, param, v)
349 end;
351 procedure ReadString (VAR v: String; param: String);
352 begin
353 v := config.ReadStr(section, param, v)
354 end;
356 begin
357 gAskLanguage := True;
358 e_WriteLog('Reading config', TMsgType.Notify);
359 g_Options_SetDefault;
361 if FileExists(FileName) = False then
362 begin
363 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
364 g_Options_SetDefaultVideo;
365 Exit
366 end;
368 config := TConfig.CreateFile(FileName);
370 section := 'Player1';
371 with gPlayer1Settings do
372 begin
373 ReadString(Name, 'name');
374 ReadString(Model, 'model');
375 ReadInteger(Color.R, 'red', 0, 255);
376 ReadInteger(Color.G, 'green', 0, 255);
377 ReadInteger(Color.B, 'blue', 0, 255);
378 ReadInteger(Team, 'team');
379 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
380 Team := TEAM_RED;
381 end;
383 section := 'Player2';
384 with gPlayer2Settings do
385 begin
386 ReadString(Name, 'name');
387 ReadString(Model, 'model');
388 ReadInteger(Color.R, 'red', 0, 255);
389 ReadInteger(Color.G, 'green', 0, 255);
390 ReadInteger(Color.B, 'blue', 0, 255);
391 ReadInteger(Team, 'team');
392 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
393 Team := TEAM_RED;
394 end;
396 section := 'GameplayCustom';
397 ReadString(gcMap, 'Map');
398 ReadString(gcGameMode, 'GameMode');
399 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
400 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
401 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
402 ReadInteger(gcPlayers, 'Players', 0, 2);
403 ReadBoolean(gcTeamDamage, 'TeamDamage');
404 ReadBoolean(gcAllowExit, 'AllowExit');
405 ReadBoolean(gcWeaponStay, 'WeaponStay');
406 ReadBoolean(gcMonsters, 'Monsters');
407 ReadString(gcBotsVS, 'BotsVS');
409 with gGameSettings do
410 begin
411 GameMode := g_Game_TextToMode(gcGameMode);
412 if GameMode = GM_NONE then
413 GameMode := GM_DM;
414 if GameMode = GM_SINGLE then
415 GameMode := GM_COOP;
416 TimeLimit := gcTimeLimit;
417 GoalLimit := gcGoalLimit;
418 MaxLives := gcMaxLives;
420 Options := 0;
421 if gcTeamDamage then
422 Options := Options or GAME_OPTION_TEAMDAMAGE;
423 if gcAllowExit then
424 Options := Options or GAME_OPTION_ALLOWEXIT;
425 if gcWeaponStay then
426 Options := Options or GAME_OPTION_WEAPONSTAY;
427 if gcMonsters then
428 Options := Options or GAME_OPTION_MONSTERS;
429 if gcBotsVS = 'Everybody' then
430 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
431 if gcBotsVS = 'Players' then
432 Options := Options or GAME_OPTION_BOTVSPLAYER;
433 if gcBotsVS = 'Monsters' then
434 Options := Options or GAME_OPTION_BOTVSMONSTER;
435 end;
437 section := 'GameplayNetwork';
438 ReadString(gnMap, 'Map');
439 ReadString(gnGameMode, 'GameMode');
440 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
441 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
442 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
443 ReadInteger(gnPlayers, 'Players', 0, 2);
444 ReadBoolean(gnTeamDamage, 'TeamDamage');
445 ReadBoolean(gnAllowExit, 'AllowExit');
446 ReadBoolean(gnWeaponStay, 'WeaponStay');
447 ReadBoolean(gnMonsters, 'Monsters');
448 ReadString(gnBotsVS, 'BotsVS');
450 section := 'MasterServer';
451 ReadString(NetSlistIP, 'IP');
452 ReadInteger(NetSlistPort, 'Port', 0, 65535);
453 ReadString(NetSlistList, 'List');
454 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
456 section := 'Server';
457 ReadString(NetServerName, 'Name');
458 ReadString(NetPassword, 'Password');
459 ReadInteger(NetPort, 'Port', 0, 65535);
460 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
461 ReadBoolean(NetAllowRCON, 'RCON');
462 ReadString(NetRCONPassword, 'RCONPassword');
463 ReadBoolean(NetUseMaster, 'SyncWithMaster');
464 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
465 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
466 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
467 ReadBoolean(NetForwardPorts, 'ForwardPorts');
469 section := 'Client';
470 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
471 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
472 ReadBoolean(NetPredictSelf, 'PredictSelf');
473 ReadString(NetClientIP, 'LastIP');
474 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
476 config.Free();
478 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
479 end;
481 procedure g_Options_Write(FileName: String);
482 var config: TConfig;
483 begin
484 e_WriteLog('Writing config', TMsgType.Notify);
486 config := TConfig.CreateFile(FileName);
488 with config, gPlayer1Settings do
489 begin
490 WriteStr('Player1', 'Name', Name);
491 WriteStr('Player1', 'model', Model);
492 WriteInt('Player1', 'red', Color.R);
493 WriteInt('Player1', 'green', Color.G);
494 WriteInt('Player1', 'blue', Color.B);
495 WriteInt('Player1', 'team', Team);
496 end;
498 with config, gPlayer2Settings do
499 begin
500 WriteStr('Player2', 'Name', Name);
501 WriteStr('Player2', 'model', Model);
502 WriteInt('Player2', 'red', Color.R);
503 WriteInt('Player2', 'green', Color.G);
504 WriteInt('Player2', 'blue', Color.B);
505 WriteInt('Player2', 'team', Team);
506 end;
508 config.WriteStr ('GameplayCustom', 'Map', gcMap);
509 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
510 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
511 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
512 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
513 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
514 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
515 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
516 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
517 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
518 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
520 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
521 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
522 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
523 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
524 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
525 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
526 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
527 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
528 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
529 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
530 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
532 config.WriteStr('MasterServer', 'IP', NetSlistIP);
533 config.WriteInt('MasterServer', 'Port', NetSlistPort);
534 config.WriteStr('MasterServer', 'List', NetSlistList);
536 config.WriteStr ('Server', 'Name', NetServerName);
537 config.WriteStr ('Server', 'Password', NetPassword);
538 config.WriteInt ('Server', 'Port', NetPort);
539 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
540 config.WriteBool('Server', 'RCON', NetAllowRCON);
541 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
542 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
543 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
544 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
545 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
546 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
548 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
549 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
550 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
551 config.WriteStr ('Client', 'LastIP', NetClientIP);
552 config.WriteInt ('Client', 'LastPort', NetClientPort);
554 config.SaveFile(FileName);
555 config.Free();
556 end;
558 procedure g_Options_Write_Gameplay_Custom(FileName: String);
559 var
560 config: TConfig;
561 begin
562 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
564 config := TConfig.CreateFile(FileName);
566 config.WriteStr ('GameplayCustom', 'Map', gcMap);
567 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
568 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
569 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
570 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
571 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
572 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
573 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
574 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
575 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
576 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
578 config.SaveFile(FileName);
579 config.Free();
580 end;
582 procedure g_Options_Write_Gameplay_Net(FileName: String);
583 var
584 config: TConfig;
585 begin
586 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
588 config := TConfig.CreateFile(FileName);
590 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
591 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
592 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
593 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
594 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
595 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
596 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
597 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
598 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
599 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
600 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
602 config.SaveFile(FileName);
603 config.Free();
604 end;
606 procedure g_Options_Write_Net_Server(FileName: String);
607 var
608 config: TConfig;
609 begin
610 e_WriteLog('Writing server config', TMsgType.Notify);
612 config := TConfig.CreateFile(FileName);
614 config.WriteStr ('Server', 'Name', NetServerName);
615 config.WriteStr ('Server', 'Password', NetPassword);
616 config.WriteInt ('Server', 'Port', NetPort);
617 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
618 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
619 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
621 config.SaveFile(FileName);
622 config.Free();
623 end;
625 procedure g_Options_Write_Net_Client(FileName: String);
626 var
627 config: TConfig;
628 begin
629 e_WriteLog('Writing client config', TMsgType.Notify);
631 config := TConfig.CreateFile(FileName);
633 config.WriteStr('Client', 'LastIP', NetClientIP);
634 config.WriteInt('Client', 'LastPort', NetClientPort);
636 config.SaveFile(FileName);
637 config.Free();
638 end;
640 procedure g_Options_Commands (p: SSArray);
641 var cmd: AnsiString; i: Integer;
642 begin
643 cmd := LowerCase(p[0]);
644 case cmd of
645 'r_reset':
646 begin
647 sys_EnableVSync(gVSync);
648 gRC_Width := Max(1, gRC_Width);
649 gRC_Height := Max(1, gRC_Height);
650 gBPP := Max(1, gBPP);
651 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen) = True then
652 e_LogWriteln('resolution changed')
653 else
654 e_LogWriteln('resolution not changed')
655 end;
656 'g_language':
657 begin
658 if Length(p) = 2 then
659 begin
660 gAskLanguage := true;
661 gLanguage := LANGUAGE_ENGLISH;
662 case LowerCase(p[1]) of
663 'english':
664 begin
665 gAskLanguage := false;
666 gLanguage := LANGUAGE_ENGLISH;
667 end;
668 'russian':
669 begin
670 gAskLanguage := false;
671 gLanguage := LANGUAGE_RUSSIAN;
672 end;
673 'ask':
674 begin
675 gAskLanguage := true;
676 gLanguage := LANGUAGE_ENGLISH;
677 end;
678 end;
679 g_Language_Set(gLanguage)
680 end
681 else
682 begin
683 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd])
684 end
685 end;
686 'g_max_particles':
687 begin
688 if Length(p) = 2 then
689 begin
690 i := Max(0, StrToInt(p[1]));
691 g_GFX_SetMax(i)
692 end
693 else if Length(p) = 1 then
694 begin
695 e_LogWritefln('%s', [g_GFX_GetMax()])
696 end
697 else
698 begin
699 e_LogWritefln('usage: %s <n>', [cmd])
700 end
701 end;
702 'g_max_shells':
703 begin
704 if Length(p) = 2 then
705 begin
706 i := Max(0, StrToInt(p[1]));
707 g_Shells_SetMax(i)
708 end
709 else if Length(p) = 1 then
710 begin
711 e_LogWritefln('%s', [g_Shells_GetMax()])
712 end
713 else
714 begin
715 e_LogWritefln('usage: %s <n>', [cmd])
716 end
717 end;
718 'g_max_gibs':
719 begin
720 if Length(p) = 2 then
721 begin
722 i := Max(0, StrToInt(p[1]));
723 g_Gibs_SetMax(i)
724 end
725 else if Length(p) = 1 then
726 begin
727 e_LogWritefln('%s', [g_Gibs_GetMax()])
728 end
729 else
730 begin
731 e_LogWritefln('usage: %s <n>', [cmd])
732 end
733 end;
734 'g_max_corpses':
735 begin
736 if Length(p) = 2 then
737 begin
738 i := Max(0, StrToInt(p[1]));
739 g_Corpses_SetMax(i)
740 end
741 else if Length(p) = 1 then
742 begin
743 e_LogWritefln('%s', [g_Corpses_GetMax()])
744 end
745 else
746 begin
747 e_LogWritefln('usage: %s <n>', [cmd])
748 end
749 end;
750 'g_item_respawn_time':
751 begin
752 if Length(p) = 2 then
753 ITEM_RESPAWNTIME := Max(0, StrToInt(p[1])) * 36
754 else if Length(p) = 1 then
755 e_LogWritefln('%s', [ITEM_RESPAWNTIME div 36])
756 else
757 e_LogWritefln('usage: %s <n>', [cmd])
758 end;
759 end;
760 end;
762 initialization
763 Randomize;
764 machine := Random(10000);
766 (* Video *)
767 conRegVar('r_width', @gRC_Width, '', '');
768 conRegVar('r_height', @gRC_Height, '', '');
769 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
770 conRegVar('r_maximized', @gRC_Maximized, '', '');
771 conRegVar('r_bpp', @gBPP, '', '');
772 conRegVar('r_vsync', @gVSync, '', '');
773 conRegVar('r_texfilter', @gTextureFilter, '', '');
774 conRegVar('r_npot', @glNPOTOverride, '', '');
776 (* Sound *)
777 conRegVar('s_nosound', @gNoSound, '', '');
778 conRegVar('s_soundvolume', @gSoundLevel, '', '');
779 conRegVar('s_musicvolume', @gMusicLevel, '', '');
780 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
781 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
782 conRegVar('s_announcer', @gAnnouncer, '', '');
783 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
784 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
785 {$IFDEF USE_SDLMIXER}
786 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
787 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
788 {$ENDIF}
790 (* Game *)
791 conRegVar('g_gibs_count', @gGibsCount, '', '');
792 conRegVar('g_blood_count', @gBloodCount, '', '');
793 conRegVar('g_adv_blood', @gAdvBlood, '', '');
794 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
795 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
796 conRegVar('r_flash', @gFlash, '', '');
797 conRegVar('r_background', @gDrawBackGround, '', '');
798 conRegVar('g_show_messages', @gShowMessages, '', '');
799 conRegVar('r_revert_players', @gRevertPlayers, '', '');
800 conRegVar('r_chat_bubble', @gChatBubble, '', '');
801 conRegVar('sfs_debug', @wadoptDebug, '', '');
802 conRegVar('sfs_fastmode', @wadoptFast, '', '');
803 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
804 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
806 end.