DEADSOFTWARE

game: disable shells for server
[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_ApplyGameSettings;
29 const DF_Default_Megawad_Start = 'megawads/DOOM2D.WAD:\MAP01';
31 var
32 gBPP: Integer;
33 gFreq: Byte;
34 gFullscreen: Boolean;
35 gWinSizeX, gWinSizeY: Integer;
36 gWinMaximized: Boolean;
37 gVSync: Boolean;
38 glLegacyNPOT: Boolean;
39 glRenderToFBO: Boolean = True;
40 gTextureFilter: Boolean;
41 gLerpActors: Boolean = True;
42 gFrameTime: Integer = 5;
43 gMaxFPS: Integer = 200;
44 gNoSound: Boolean;
45 gSoundLevel: Integer;
46 gMusicLevel: Integer;
47 gMaxSimSounds: Integer;
48 gMuteWhenInactive: Boolean;
49 gAdvCorpses: Boolean;
50 gAdvBlood: Boolean;
51 gAdvGibs: Boolean;
52 gBloodCount: Integer;
53 gFlash: Integer;
54 gDrawBackGround: Boolean;
55 gShowMessages: Boolean;
56 gRevertPlayers: Boolean;
57 gLanguage: String;
58 gAskLanguage: Boolean;
59 gSaveStats: Boolean = False;
60 gScreenshotStats: Boolean = False;
61 gsSDLSampleRate: Integer;
62 gsSDLBufferSize: Integer;
63 gDefaultMegawadStart: AnsiString;
64 glNPOTOverride: Boolean = false;
66 (* Latched game settings *)
67 gsMap: String;
68 gsGameMode: String;
69 gsTimeLimit: Word;
70 gsScoreLimit: Word;
71 gsMaxLives: Byte;
72 gsPlayers: Byte;
73 gsGameFlags: LongWord;
74 gsSpawnInvul: Integer = 0;
75 gsItemRespawnTime: Word = 60;
76 gsWarmupTime: Word = 30;
78 {$IFDEF HEADLESS}
79 e_NoGraphics: Boolean = True;
80 {$ELSE}
81 e_NoGraphics: Boolean = False;
82 {$ENDIF}
83 e_FastScreenshots: Boolean = true; // it's REALLY SLOW with `false`
84 g_dbg_scale: Single = 1.0;
85 r_pixel_scale: Single = 1.0;
87 gwin_has_stencil: Boolean = false;
88 gwin_k8_enable_light_experiments: Boolean = false;
89 g_dbg_aimline_on: Boolean = false;
90 g_dbg_input: Boolean = False;
92 var (* touch *)
93 g_touch_enabled: Boolean = False;
94 g_touch_size: Single = 1.0;
95 g_touch_offset: Single = 50.0;
96 g_touch_fire: Boolean = True;
97 g_touch_alt: Boolean = False;
99 {--- Read-only dirs ---}
100 GameWAD: string;
101 DataDirs: SSArray;
102 ModelDirs: SSArray;
103 MegawadDirs: SSArray;
104 MapDirs: SSArray;
105 WadDirs: SSArray;
106 AllMapDirs: SSArray; // Maps + Megawads
108 {--- Read-Write dirs ---}
109 LogFileName: string;
110 LogDirs: SSArray;
111 SaveDirs: SSArray;
112 CacheDirs: SSArray;
113 ConfigDirs: SSArray;
114 ScreenshotDirs: SSArray;
115 StatsDirs: SSArray;
116 MapDownloadDirs: SSArray;
117 WadDownloadDirs: SSArray;
119 GameWADName: string = 'GAME';
121 implementation
123 uses
124 {$IFDEF USE_SDL2}
125 SDL2,
126 {$ENDIF}
127 {$IFDEF ENABLE_GFX}
128 g_gfx,
129 {$ENDIF}
130 {$IFDEF ENABLE_GIBS}
131 g_gibs,
132 {$ENDIF}
133 {$IFDEF ENABLE_SHELLS}
134 g_shells,
135 {$ENDIF}
136 e_log, e_input, g_console, g_sound, g_player, Math,
137 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game,
138 g_items, wadreader, envvars;
140 var
141 machine: Integer;
143 function GenPlayerName (n: Integer): String;
144 begin
145 ASSERT(n >= 1);
146 Result := GetUserName;
147 if Result = '' then
148 Result := 'Player' + IntToStr(machine MOD 10000);
149 if n = 1 then
150 Result := Copy(Result, 1, 12) + ' '
151 else
152 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
153 end;
155 {$IFDEF USE_SDL2}
156 procedure g_Options_SetDefaultVideo;
157 var display: TSDL_DisplayMode;
158 {$IFNDEF ANDROID}
159 var target, closest: TSDL_DisplayMode; percentage: Integer;
160 {$ENDIF}
161 begin
162 (* Display 0 = Primary display *)
163 gScreenWidth := 640;
164 gScreenHeight := 480;
165 gWinSizeX := 640;
166 gWinSizeY := 480;
167 //gBPP := SDL_BITSPERPIXEL(display.format);
168 gBPP := 32;
169 {$IFDEF ANDROID}
170 gFullScreen := True; (* rotation not allowed? *)
171 {$ELSE}
172 gFullScreen := False;
173 {$ENDIF}
174 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
175 begin
176 {$IFDEF ANDROID}
177 gWinSizeX := display.w;
178 gWinSizeY := display.h;
179 {$ELSE}
180 (* Window must be smaller than display *)
181 closest.w := display.w;
182 closest.h := display.h;
183 percentage := 75;
184 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
185 begin
186 if percentage < 25 then
187 begin
188 closest.w := display.w * 75 div 100;
189 closest.h := display.h * 75 div 100;
190 break;
191 end;
192 target.w := display.w * percentage div 100;
193 target.h := display.h * percentage div 100;
194 target.format := 0; (* didn't care *)
195 target.refresh_rate := 0; (* didn't care *)
196 target.driverdata := nil; (* init *)
197 SDL_GetClosestDisplayMode(0, @target, @closest);
198 Dec(percentage);
199 end;
200 gWinSizeX := closest.w;
201 gWinSizeY := closest.h;
202 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
203 {$ENDIF}
204 end
205 else
206 begin
207 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
208 end;
209 (* Must be positioned on primary display *)
210 gWinMaximized := False;
211 gVSync := True;
212 gTextureFilter := True;
213 glLegacyNPOT := False;
214 gRC_Width := gWinSizeX;
215 gRC_Height := gWinSizeY;
216 gRC_FullScreen := gFullScreen;
217 gRC_Maximized := gWinMaximized;
218 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
219 g_Console_ResetBinds;
220 end;
221 {$ELSE}
222 procedure g_Options_SetDefaultVideo;
223 begin
224 gWinSizeX := 640;
225 gWinSizeY := 480;
226 gBPP := 32;
227 gFullScreen := False;
228 gWinMaximized := False;
229 gVSync := True;
230 gTextureFilter := True;
231 glLegacyNPOT := False;
232 gScreenWidth := gWinSizeX;
233 gScreenHeight := gWinSizeY;
234 gRC_Width := gWinSizeX;
235 gRC_Height := gWinSizeY;
236 gRC_FullScreen := gFullScreen;
237 gRC_Maximized := gWinMaximized;
238 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
239 g_Console_ResetBinds;
240 end;
241 {$ENDIF}
243 procedure g_Options_SetDefault();
244 var
245 i: Integer;
246 begin
247 (* section Sound *)
248 gNoSound := False;
249 gSoundLevel := 75;
250 gMusicLevel := 65;
251 gMaxSimSounds := 8;
252 gMuteWhenInactive := False;
253 gAnnouncer := ANNOUNCE_MEPLUS;
254 gSoundEffectsDF := True;
255 gUseChatSounds := True;
256 gsSDLSampleRate := 44100;
257 gsSDLBufferSize := 2048;
259 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
261 with gPlayer1Settings do
262 begin
263 Name := GenPlayerName(1);
264 Model := STD_PLAYER_MODEL;
265 Color.R := PLAYER1_DEF_COLOR.R;
266 Color.G := PLAYER1_DEF_COLOR.G;
267 Color.B := PLAYER1_DEF_COLOR.B;
268 Team := TEAM_RED;
269 end;
271 with gPlayer2Settings do
272 begin
273 Name := GenPlayerName(2);
274 Model := STD_PLAYER_MODEL;
275 Color.R := PLAYER2_DEF_COLOR.R;
276 Color.G := PLAYER2_DEF_COLOR.G;
277 Color.B := PLAYER2_DEF_COLOR.B;
278 Team := TEAM_BLUE;
279 end;
281 (* section Joysticks *)
282 for i := 0 to e_MaxJoys - 1 do
283 begin
284 e_JoystickDeadzones[i] := 8192
285 end;
287 (* section Game *)
288 {$IFDEF ENABLE_GFX}
289 g_GFX_SetMax(2000);
290 {$ENDIF}
291 {$IFDEF ENABLE_SHELLS}
292 g_Shells_SetMax(DefaultShellMax);
293 {$ENDIF}
294 g_Corpses_SetMax(20);
295 {$IFDEF ENABLE_GIBS}
296 g_Gibs_SetMax(DefaultGibsMax);
297 gGibsCount := DefaultGibsCount;
298 {$ENDIF}
299 gBloodCount := 4;
300 gAdvBlood := True;
301 gAdvCorpses := True;
302 gAdvGibs := True;
303 gFlash := 1;
304 gDrawBackGround := True;
305 gShowMessages := True;
306 gRevertPlayers := False;
307 gChatBubble := 4;
308 wadoptDebug := False;
309 wadoptFast := False;
310 e_FastScreenshots := True;
311 gDefaultMegawadStart := DF_Default_Megawad_Start;
312 g_dbg_scale := 1.0;
313 gSaveStats := False;
315 gAskLanguage := True;
316 gLanguage := LANGUAGE_ENGLISH;
318 gsMap := '';
319 gsGameMode := _lc[I_MENU_GAME_TYPE_DM];
320 gsTimeLimit := 0;
321 gsScoreLimit := 0;
322 gsMaxLives := 0;
323 gsPlayers := 1;
324 gsSpawnInvul := 0;
325 gsItemRespawnTime := 60;
326 gsGameFlags := GAME_OPTION_ALLOWEXIT or GAME_OPTION_DMKEYS or
327 GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER or
328 GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMHITPROJECTILE or
329 GAME_OPTION_ALLOWDROPFLAG;
330 gsPlayers := 1;
332 if not gGameOn then
333 g_Options_ApplyGameSettings;
335 (* section MasterServer *)
336 NetMasterList := 'mpms.doom2d.org:25665, deadsoftware.ru:25665, terminalcorner.ru:25665';
337 g_Net_Slist_Set(NetMasterList);
339 (* section Server *)
340 NetServerName := 'Unnamed Server';
341 NetPassword := '';
342 NetPort := 25666;
343 NetMaxClients := 16;
344 NetAllowRCON := False;
345 NetRCONPassword := 'default';
346 NetUseMaster := True;
347 NetUpdateRate := 0;
348 NetRelupdRate := 18;
349 NetMasterRate := 60000;
350 NetForwardPorts := False;
352 (* section Client *)
353 NetInterpLevel := 2;
354 NetForcePlayerUpdate := False;
355 NetPredictSelf := True;
356 NetClientIP := '127.0.0.1';
357 NetClientPort := NetPort;
358 end;
360 procedure g_Options_ApplyGameSettings;
361 begin
362 with gGameSettings do
363 begin
364 GameMode := g_Game_TextToMode(gsGameMode);
365 if GameMode = GM_NONE then
366 GameMode := GM_DM;
367 if GameMode = GM_SINGLE then
368 GameMode := GM_COOP;
369 TimeLimit := gsTimeLimit;
370 ScoreLimit := gsScoreLimit;
371 MaxLives := gsMaxLives;
372 SpawnInvul := gsSpawnInvul;
373 ItemRespawnTime := gsItemRespawnTime;
374 WarmupTime := gsWarmupTime;
375 Options := gsGameFlags;
376 end;
377 end;
379 initialization
380 Randomize;
381 machine := Random(10000);
383 (* Video *)
384 conRegVar('r_width', @gRC_Width, '', '');
385 conRegVar('r_height', @gRC_Height, '', '');
386 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
387 conRegVar('r_maximized', @gRC_Maximized, '', '');
388 conRegVar('r_bpp', @gBPP, '', '');
389 conRegVar('r_vsync', @gVSync, '', '');
390 conRegVar('r_texfilter', @gTextureFilter, '', '');
391 conRegVar('r_npot', @glNPOTOverride, '', '');
392 conRegVar('r_interp', @gLerpActors, '', 'interpolate actors');
393 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
394 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
396 (* Sound *)
397 conRegVar('s_nosound', @gNoSound, '', '');
398 conRegVar('s_soundvolume', @gSoundLevel, '', '');
399 conRegVar('s_musicvolume', @gMusicLevel, '', '');
400 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
401 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
402 conRegVar('s_announcer', @gAnnouncer, '', '');
403 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
404 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
405 {$IFDEF USE_SDLMIXER}
406 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
407 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
408 {$ENDIF}
410 (* Game *)
411 {$IFDEF ENABLE_GIBS}
412 conRegVar('g_gibs_count', @gGibsCount, '', '');
413 {$ENDIF}
414 conRegVar('g_blood_count', @gBloodCount, '', '');
415 conRegVar('g_adv_blood', @gAdvBlood, '', '');
416 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
417 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
418 conRegVar('r_flash', @gFlash, '', '');
419 conRegVar('r_background', @gDrawBackGround, '', '');
420 conRegVar('g_show_messages', @gShowMessages, '', '');
421 conRegVar('r_revert_players', @gRevertPlayers, '', '');
422 conRegVar('r_chat_bubble', @gChatBubble, '', '');
423 conRegVar('sfs_debug', @wadoptDebug, '', '');
424 conRegVar('sfs_fastmode', @wadoptFast, '', '');
425 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
426 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
427 conRegVar('g_save_stats', @gSaveStats, '', '');
428 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
429 conRegVar('g_lastmap', @gsMap, '', '');
431 conRegVar('d_input', @g_dbg_input, '', '');
433 (* touch *)
434 conRegVar('touch_enable', @g_touch_enabled, 'enable/disable virtual buttons', 'draw buttons');
435 conRegVar('touch_fire', @g_touch_fire, 'enable/disable fire when press virtual up/down', 'fire when press up/down');
436 conRegVar('touch_size', @g_touch_size, 0.1, 10, 'size of virtual buttons', 'button size');
437 conRegVar('touch_offset', @g_touch_offset, 0, 100, '', '');
438 conRegVar('touch_alt', @g_touch_alt, 'althernative virtual buttons layout', 'althernative layout');
439 end.