DEADSOFTWARE

481eb70c9491c354976b8aa2475aecaf573bb308
[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 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
175 g_Console_ResetBinds;
176 end;
177 {$ELSE}
178 procedure g_Options_SetDefaultVideo;
179 begin
180 gScreenWidth := 640;
181 gScreenHeight := 480;
182 gBPP := 32;
183 gFullScreen := False;
184 gWinMaximized := False;
185 gVSync := True;
186 gTextureFilter := True;
187 glLegacyNPOT := False;
188 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gScreenWidth) + ' h = ' + IntToStr(gScreenHeight));
189 g_Console_ResetBinds;
190 end;
191 {$ENDIF}
193 procedure g_Options_SetDefault();
194 var
195 i: Integer;
196 begin
197 (* section Sound *)
198 gNoSound := False;
199 gSoundLevel := 75;
200 gMusicLevel := 65;
201 gMaxSimSounds := 8;
202 gMuteWhenInactive := False;
203 gAnnouncer := ANNOUNCE_MEPLUS;
204 gSoundEffectsDF := True;
205 gUseChatSounds := True;
206 gsSDLSampleRate := 44100;
207 gsSDLBufferSize := 2048;
209 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
211 with gPlayer1Settings do
212 begin
213 Name := GenPlayerName(1);
214 Model := STD_PLAYER_MODEL;
215 Color.R := PLAYER1_DEF_COLOR.R;
216 Color.G := PLAYER1_DEF_COLOR.G;
217 Color.B := PLAYER1_DEF_COLOR.B;
218 Team := TEAM_RED;
219 end;
221 with gPlayer2Settings do
222 begin
223 Name := GenPlayerName(2);
224 Model := STD_PLAYER_MODEL;
225 Color.R := PLAYER2_DEF_COLOR.R;
226 Color.G := PLAYER2_DEF_COLOR.G;
227 Color.B := PLAYER2_DEF_COLOR.B;
228 Team := TEAM_BLUE;
229 end;
231 (* section Joysticks *)
232 for i := 0 to e_MaxJoys - 1 do
233 begin
234 e_JoystickDeadzones[i] := 8192
235 end;
237 (* section Game *)
238 g_GFX_SetMax(2000);
239 g_Shells_SetMax(300);
240 g_Gibs_SetMax(150);
241 g_Corpses_SetMax(20);
242 gGibsCount := 32;
243 ITEM_RESPAWNTIME := 60 * 36;
244 gBloodCount := 4;
245 gAdvBlood := True;
246 gAdvCorpses := True;
247 gAdvGibs := True;
248 gFlash := 1;
249 gDrawBackGround := True;
250 gShowMessages := True;
251 gRevertPlayers := False;
252 gChatBubble := 4;
253 wadoptDebug := False;
254 wadoptFast := False;
255 e_FastScreenshots := True;
256 gDefaultMegawadStart := DF_Default_Megawad_Start;
257 gBerserkAutoswitch := True;
258 g_dbg_scale := 1.0;
260 gAskLanguage := True;
261 gLanguage := LANGUAGE_ENGLISH;
263 (* section GameplayCustom *)
264 gcMap := '';
265 gcGameMode := _lc[I_MENU_GAME_TYPE_DM];
266 gcTimeLimit := 0;
267 gcGoalLimit := 0;
268 gcMaxLives := 0;
269 gcPlayers := 1;
270 gcTeamDamage := False;
271 gcAllowExit := True;
272 gcWeaponStay := False;
273 gcMonsters := False;
274 gcBotsVS := 'Everybody';
276 (* section GameplayNetwork *)
277 gnMap := '';
278 gnGameMode := _lc[I_MENU_GAME_TYPE_DM];
279 gnTimeLimit := 0;
280 gnGoalLimit := 0;
281 gnMaxLives := 0;
282 gnPlayers := 1;
283 gnTeamDamage := False;
284 gnAllowExit := True;
285 gnWeaponStay := False;
286 gnMonsters := False;
287 gnBotsVS := 'Everybody';
289 (* section MasterServer *)
290 NetSlistIP := 'mpms.doom2d.org';
291 NetSlistPort := 25665;
292 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
294 (* section Server *)
295 NetServerName := 'Unnamed Server';
296 NetPassword := '';
297 NetPort := 25666;
298 NetMaxClients := 16;
299 NetAllowRCON := False;
300 NetRCONPassword := 'default';
301 NetUseMaster := True;
302 NetUpdateRate := 0;
303 NetRelupdRate := 18;
304 NetMasterRate := 60000;
305 NetForwardPorts := False;
307 (* section Client *)
308 NetInterpLevel := 2;
309 NetForcePlayerUpdate := False;
310 NetPredictSelf := True;
311 NetClientIP := '127.0.0.1';
312 NetClientPort := NetPort;
313 end;
315 procedure g_Options_Read(FileName: String);
316 var
317 config: TConfig;
318 section: String;
320 procedure ReadInteger (VAR v: Integer; param: String; minv: Integer = Low(Integer); maxv: Integer = High(Integer));
321 begin
322 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
323 end;
325 procedure ReadInteger (VAR v: LongWord; param: String; minv: LongWord = Low(LongWord); maxv: LongWord = High(LongWord)); overload;
326 begin
327 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
328 end;
330 procedure ReadInteger (VAR v: Word; param: String; minv: Word = Low(Word); maxv: Word = High(Word)); overload;
331 begin
332 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
333 end;
335 procedure ReadInteger (VAR v: Byte; param: String; minv: Byte = Low(Byte); maxv: Byte = High(Byte)); overload;
336 begin
337 v := Max(Min(config.ReadInt(section, param, v), maxv), minv)
338 end;
340 procedure ReadBoolean (VAR v: Boolean; param: String);
341 begin
342 v := config.ReadBool(section, param, v)
343 end;
345 procedure ReadString (VAR v: String; param: String);
346 begin
347 v := config.ReadStr(section, param, v)
348 end;
350 begin
351 gAskLanguage := True;
352 e_WriteLog('Reading config', TMsgType.Notify);
353 g_Options_SetDefault;
355 if FileExists(FileName) = False then
356 begin
357 e_WriteLog('Config file '+FileName+' not found', TMsgType.Warning);
358 g_Options_SetDefaultVideo;
359 Exit
360 end;
362 config := TConfig.CreateFile(FileName);
364 section := 'Player1';
365 with gPlayer1Settings do
366 begin
367 ReadString(Name, 'name');
368 ReadString(Model, 'model');
369 ReadInteger(Color.R, 'red', 0, 255);
370 ReadInteger(Color.G, 'green', 0, 255);
371 ReadInteger(Color.B, 'blue', 0, 255);
372 ReadInteger(Team, 'team');
373 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
374 Team := TEAM_RED;
375 end;
377 section := 'Player2';
378 with gPlayer2Settings do
379 begin
380 ReadString(Name, 'name');
381 ReadString(Model, 'model');
382 ReadInteger(Color.R, 'red', 0, 255);
383 ReadInteger(Color.G, 'green', 0, 255);
384 ReadInteger(Color.B, 'blue', 0, 255);
385 ReadInteger(Team, 'team');
386 if (Team < TEAM_RED) or (Team > TEAM_BLUE) then
387 Team := TEAM_RED;
388 end;
390 section := 'GameplayCustom';
391 ReadString(gcMap, 'Map');
392 ReadString(gcGameMode, 'GameMode');
393 ReadInteger(gcTimeLimit, 'TimeLimit', 0, 65535);
394 ReadInteger(gcGoalLimit, 'GoalLimit', 0, 65535);
395 ReadInteger(gcMaxLives, 'MaxLives', 0, 255);
396 ReadInteger(gcPlayers, 'Players', 0, 2);
397 ReadBoolean(gcTeamDamage, 'TeamDamage');
398 ReadBoolean(gcAllowExit, 'AllowExit');
399 ReadBoolean(gcWeaponStay, 'WeaponStay');
400 ReadBoolean(gcMonsters, 'Monsters');
401 ReadString(gcBotsVS, 'BotsVS');
403 with gGameSettings do
404 begin
405 GameMode := g_Game_TextToMode(gcGameMode);
406 if GameMode = GM_NONE then
407 GameMode := GM_DM;
408 if GameMode = GM_SINGLE then
409 GameMode := GM_COOP;
410 TimeLimit := gcTimeLimit;
411 GoalLimit := gcGoalLimit;
412 MaxLives := gcMaxLives;
414 Options := 0;
415 if gcTeamDamage then
416 Options := Options or GAME_OPTION_TEAMDAMAGE;
417 if gcAllowExit then
418 Options := Options or GAME_OPTION_ALLOWEXIT;
419 if gcWeaponStay then
420 Options := Options or GAME_OPTION_WEAPONSTAY;
421 if gcMonsters then
422 Options := Options or GAME_OPTION_MONSTERS;
423 if gcBotsVS = 'Everybody' then
424 Options := Options or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
425 if gcBotsVS = 'Players' then
426 Options := Options or GAME_OPTION_BOTVSPLAYER;
427 if gcBotsVS = 'Monsters' then
428 Options := Options or GAME_OPTION_BOTVSMONSTER;
429 end;
431 section := 'GameplayNetwork';
432 ReadString(gnMap, 'Map');
433 ReadString(gnGameMode, 'GameMode');
434 ReadInteger(gnTimeLimit, 'TimeLimit', 0, 65535);
435 ReadInteger(gnGoalLimit, 'GoalLimit', 0, 65535);
436 ReadInteger(gnMaxLives, 'MaxLives', 0, 255);
437 ReadInteger(gnPlayers, 'Players', 0, 2);
438 ReadBoolean(gnTeamDamage, 'TeamDamage');
439 ReadBoolean(gnAllowExit, 'AllowExit');
440 ReadBoolean(gnWeaponStay, 'WeaponStay');
441 ReadBoolean(gnMonsters, 'Monsters');
442 ReadString(gnBotsVS, 'BotsVS');
444 section := 'MasterServer';
445 ReadString(NetSlistIP, 'IP');
446 ReadInteger(NetSlistPort, 'Port', 0, 65535);
447 ReadString(NetSlistList, 'List');
448 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
450 section := 'Server';
451 ReadString(NetServerName, 'Name');
452 ReadString(NetPassword, 'Password');
453 ReadInteger(NetPort, 'Port', 0, 65535);
454 ReadInteger(NetMaxClients, 'MaxClients', 0, NET_MAXCLIENTS);
455 ReadBoolean(NetAllowRCON, 'RCON');
456 ReadString(NetRCONPassword, 'RCONPassword');
457 ReadBoolean(NetUseMaster, 'SyncWithMaster');
458 ReadInteger(NetUpdateRate, 'UpdateInterval', 0);
459 ReadInteger(NetRelupdRate, 'ReliableUpdateInterval', 0);
460 ReadInteger(NetMasterRate, 'MasterSyncInterval', 1);
461 ReadBoolean(NetForwardPorts, 'ForwardPorts');
463 section := 'Client';
464 ReadInteger(NetInterpLevel, 'InterpolationSteps', 0);
465 ReadBoolean(NetForcePlayerUpdate, 'ForcePlayerUpdate');
466 ReadBoolean(NetPredictSelf, 'PredictSelf');
467 ReadString(NetClientIP, 'LastIP');
468 ReadInteger(NetClientPort, 'LastPort', 0, 65535);
470 config.Free();
472 //if gTextureFilter then TEXTUREFILTER := GL_LINEAR else TEXTUREFILTER := GL_NEAREST;
473 end;
475 procedure g_Options_Write(FileName: String);
476 var config: TConfig;
477 begin
478 e_WriteLog('Writing config', TMsgType.Notify);
480 config := TConfig.CreateFile(FileName);
482 with config, gPlayer1Settings do
483 begin
484 WriteStr('Player1', 'Name', Name);
485 WriteStr('Player1', 'model', Model);
486 WriteInt('Player1', 'red', Color.R);
487 WriteInt('Player1', 'green', Color.G);
488 WriteInt('Player1', 'blue', Color.B);
489 WriteInt('Player1', 'team', Team);
490 end;
492 with config, gPlayer2Settings do
493 begin
494 WriteStr('Player2', 'Name', Name);
495 WriteStr('Player2', 'model', Model);
496 WriteInt('Player2', 'red', Color.R);
497 WriteInt('Player2', 'green', Color.G);
498 WriteInt('Player2', 'blue', Color.B);
499 WriteInt('Player2', 'team', Team);
500 end;
502 config.WriteStr ('GameplayCustom', 'Map', gcMap);
503 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
504 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
505 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
506 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
507 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
508 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
509 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
510 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
511 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
512 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
514 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
515 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
516 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
517 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
518 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
519 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
520 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
521 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
522 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
523 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
524 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
526 config.WriteStr('MasterServer', 'IP', NetSlistIP);
527 config.WriteInt('MasterServer', 'Port', NetSlistPort);
528 config.WriteStr('MasterServer', 'List', NetSlistList);
530 config.WriteStr ('Server', 'Name', NetServerName);
531 config.WriteStr ('Server', 'Password', NetPassword);
532 config.WriteInt ('Server', 'Port', NetPort);
533 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
534 config.WriteBool('Server', 'RCON', NetAllowRCON);
535 config.WriteStr ('Server', 'RCONPassword', NetRCONPassword);
536 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
537 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
538 config.WriteInt ('Server', 'UpdateInterval', NetUpdateRate);
539 config.WriteInt ('Server', 'ReliableUpdateInterval', NetRelupdRate);
540 config.WriteInt ('Server', 'MasterSyncInterval', NetMasterRate);
542 config.WriteInt ('Client', 'InterpolationSteps', NetInterpLevel);
543 config.WriteBool ('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
544 config.WriteBool ('Client', 'PredictSelf', NetPredictSelf);
545 config.WriteStr ('Client', 'LastIP', NetClientIP);
546 config.WriteInt ('Client', 'LastPort', NetClientPort);
548 config.SaveFile(FileName);
549 config.Free();
550 end;
552 procedure g_Options_Write_Gameplay_Custom(FileName: String);
553 var
554 config: TConfig;
555 begin
556 e_WriteLog('Writing custom gameplay config', TMsgType.Notify);
558 config := TConfig.CreateFile(FileName);
560 config.WriteStr ('GameplayCustom', 'Map', gcMap);
561 config.WriteStr ('GameplayCustom', 'GameMode', gcGameMode);
562 config.WriteInt ('GameplayCustom', 'TimeLimit', gcTimeLimit);
563 config.WriteInt ('GameplayCustom', 'GoalLimit', gcGoalLimit);
564 config.WriteInt ('GameplayCustom', 'MaxLives', gcMaxLives);
565 config.WriteInt ('GameplayCustom', 'Players', gcPlayers);
566 config.WriteBool('GameplayCustom', 'TeamDamage', gcTeamDamage);
567 config.WriteBool('GameplayCustom', 'AllowExit', gcAllowExit);
568 config.WriteBool('GameplayCustom', 'WeaponStay', gcWeaponStay);
569 config.WriteBool('GameplayCustom', 'Monsters', gcMonsters);
570 config.WriteStr ('GameplayCustom', 'BotsVS', gcBotsVS);
572 config.SaveFile(FileName);
573 config.Free();
574 end;
576 procedure g_Options_Write_Gameplay_Net(FileName: String);
577 var
578 config: TConfig;
579 begin
580 e_WriteLog('Writing network gameplay config', TMsgType.Notify);
582 config := TConfig.CreateFile(FileName);
584 config.WriteStr ('GameplayNetwork', 'Map', gnMap);
585 config.WriteStr ('GameplayNetwork', 'GameMode', gnGameMode);
586 config.WriteInt ('GameplayNetwork', 'TimeLimit', gnTimeLimit);
587 config.WriteInt ('GameplayNetwork', 'GoalLimit', gnGoalLimit);
588 config.WriteInt ('GameplayNetwork', 'MaxLives', gnMaxLives);
589 config.WriteInt ('GameplayNetwork', 'Players', gnPlayers);
590 config.WriteBool('GameplayNetwork', 'TeamDamage', gnTeamDamage);
591 config.WriteBool('GameplayNetwork', 'AllowExit', gnAllowExit);
592 config.WriteBool('GameplayNetwork', 'WeaponStay', gnWeaponStay);
593 config.WriteBool('GameplayNetwork', 'Monsters', gnMonsters);
594 config.WriteStr ('GameplayNetwork', 'BotsVS', gnBotsVS);
596 config.SaveFile(FileName);
597 config.Free();
598 end;
600 procedure g_Options_Write_Net_Server(FileName: String);
601 var
602 config: TConfig;
603 begin
604 e_WriteLog('Writing server config', TMsgType.Notify);
606 config := TConfig.CreateFile(FileName);
608 config.WriteStr ('Server', 'Name', NetServerName);
609 config.WriteStr ('Server', 'Password', NetPassword);
610 config.WriteInt ('Server', 'Port', NetPort);
611 config.WriteInt ('Server', 'MaxClients', NetMaxClients);
612 config.WriteBool('Server', 'SyncWithMaster', NetUseMaster);
613 config.WriteBool('Server', 'ForwardPorts', NetForwardPorts);
615 config.SaveFile(FileName);
616 config.Free();
617 end;
619 procedure g_Options_Write_Net_Client(FileName: String);
620 var
621 config: TConfig;
622 begin
623 e_WriteLog('Writing client config', TMsgType.Notify);
625 config := TConfig.CreateFile(FileName);
627 config.WriteStr('Client', 'LastIP', NetClientIP);
628 config.WriteInt('Client', 'LastPort', NetClientPort);
630 config.SaveFile(FileName);
631 config.Free();
632 end;
634 procedure g_Options_Commands (p: SSArray);
635 var cmd: AnsiString; i: Integer;
636 begin
637 cmd := LowerCase(p[0]);
638 case cmd of
639 'r_reset':
640 begin
641 sys_EnableVSync(gVSync);
642 gRC_Width := Max(1, gRC_Width);
643 gRC_Height := Max(1, gRC_Height);
644 gBPP := Max(1, gBPP);
645 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen) = True then
646 e_LogWriteln('resolution changed')
647 else
648 e_LogWriteln('resolution not changed')
649 end;
650 'g_language':
651 begin
652 if Length(p) = 2 then
653 begin
654 gAskLanguage := true;
655 gLanguage := LANGUAGE_ENGLISH;
656 case LowerCase(p[1]) of
657 'english':
658 begin
659 gAskLanguage := false;
660 gLanguage := LANGUAGE_ENGLISH;
661 end;
662 'russian':
663 begin
664 gAskLanguage := false;
665 gLanguage := LANGUAGE_RUSSIAN;
666 end;
667 'ask':
668 begin
669 gAskLanguage := true;
670 gLanguage := LANGUAGE_ENGLISH;
671 end;
672 end;
673 g_Language_Set(gLanguage)
674 end
675 else
676 begin
677 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd])
678 end
679 end;
680 'g_max_particles':
681 begin
682 if Length(p) = 2 then
683 begin
684 i := Max(0, StrToInt(p[1]));
685 g_GFX_SetMax(i)
686 end
687 else if Length(p) = 1 then
688 begin
689 e_LogWritefln('%s', [g_GFX_GetMax()])
690 end
691 else
692 begin
693 e_LogWritefln('usage: %s <n>', [cmd])
694 end
695 end;
696 'g_max_shells':
697 begin
698 if Length(p) = 2 then
699 begin
700 i := Max(0, StrToInt(p[1]));
701 g_Shells_SetMax(i)
702 end
703 else if Length(p) = 1 then
704 begin
705 e_LogWritefln('%s', [g_Shells_GetMax()])
706 end
707 else
708 begin
709 e_LogWritefln('usage: %s <n>', [cmd])
710 end
711 end;
712 'g_max_gibs':
713 begin
714 if Length(p) = 2 then
715 begin
716 i := Max(0, StrToInt(p[1]));
717 g_Gibs_SetMax(i)
718 end
719 else if Length(p) = 1 then
720 begin
721 e_LogWritefln('%s', [g_Gibs_GetMax()])
722 end
723 else
724 begin
725 e_LogWritefln('usage: %s <n>', [cmd])
726 end
727 end;
728 'g_max_corpses':
729 begin
730 if Length(p) = 2 then
731 begin
732 i := Max(0, StrToInt(p[1]));
733 g_Corpses_SetMax(i)
734 end
735 else if Length(p) = 1 then
736 begin
737 e_LogWritefln('%s', [g_Corpses_GetMax()])
738 end
739 else
740 begin
741 e_LogWritefln('usage: %s <n>', [cmd])
742 end
743 end;
744 'g_item_respawn_time':
745 begin
746 if Length(p) = 2 then
747 ITEM_RESPAWNTIME := Max(0, StrToInt(p[1])) * 36
748 else if Length(p) = 1 then
749 e_LogWritefln('%s', [ITEM_RESPAWNTIME div 36])
750 else
751 e_LogWritefln('usage: %s <n>', [cmd])
752 end;
753 end;
754 end;
756 initialization
757 Randomize;
758 machine := Random(10000);
760 (* Video *)
761 conRegVar('r_width', @gRC_Width, '', '');
762 conRegVar('r_height', @gRC_Height, '', '');
763 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
764 conRegVar('r_maximized', @gRC_Maximized, '', '');
765 conRegVar('r_bpp', @gBPP, '', '');
766 conRegVar('r_vsync', @gVSync, '', '');
767 conRegVar('r_texfilter', @gTextureFilter, '', '');
768 conRegVar('r_npot', @glNPOTOverride, '', '');
770 (* Sound *)
771 conRegVar('s_nosound', @gNoSound, '', '');
772 conRegVar('s_soundvolume', @gSoundLevel, '', '');
773 conRegVar('s_musicvolume', @gMusicLevel, '', '');
774 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
775 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
776 conRegVar('s_announcer', @gAnnouncer, '', '');
777 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
778 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
779 {$IFDEF USE_SDLMIXER}
780 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
781 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
782 {$ENDIF}
784 (* Game *)
785 conRegVar('g_gibs_count', @gGibsCount, '', '');
786 conRegVar('g_blood_count', @gBloodCount, '', '');
787 conRegVar('g_adv_blood', @gAdvBlood, '', '');
788 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
789 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
790 conRegVar('r_flash', @gFlash, '', '');
791 conRegVar('r_background', @gDrawBackGround, '', '');
792 conRegVar('g_show_messages', @gShowMessages, '', '');
793 conRegVar('r_revert_players', @gRevertPlayers, '', '');
794 conRegVar('r_chat_bubble', @gChatBubble, '', '');
795 conRegVar('sfs_debug', @wadoptDebug, '', '');
796 conRegVar('sfs_fastmode', @wadoptFast, '', '');
797 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
798 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
800 end.