DEADSOFTWARE

Game: Weapon autoswitch by travi$
[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 gGibsCount: Integer;
53 gBloodCount: Integer;
54 gFlash: Integer;
55 gDrawBackGround: Boolean;
56 gShowMessages: Boolean;
57 gRevertPlayers: Boolean;
58 gLanguage: String;
59 gAskLanguage: Boolean;
60 gSaveStats: Boolean = False;
61 gScreenshotStats: Boolean = False;
62 gsSDLSampleRate: Integer;
63 gsSDLBufferSize: Integer;
64 gDefaultMegawadStart: AnsiString;
65 gBerserkAutoswitch: Boolean;
66 gWeaponAutoswitch: Boolean;
67 glNPOTOverride: Boolean = false;
69 (* Latched game settings *)
70 gsMap: String;
71 gsGameMode: String;
72 gsTimeLimit: Word;
73 gsGoalLimit: Word;
74 gsMaxLives: Byte;
75 gsPlayers: Byte;
76 gsGameFlags: LongWord;
77 gsSpawnInvul: Integer = 0;
78 gsItemRespawnTime: Word = 60;
79 gsWarmupTime: Word = 30;
81 implementation
83 uses
84 {$INCLUDE ../nogl/noGLuses.inc}
85 {$IFDEF USE_SDL2}
86 SDL2,
87 {$ENDIF}
88 e_log, e_input, g_console, g_window, g_sound, g_gfx, g_player, Math,
89 g_map, g_net, g_netmaster, SysUtils, CONFIG, g_game, g_main, e_texture,
90 g_items, wadreader, e_graphics, g_touch, envvars, g_system;
92 var
93 machine: Integer;
95 function GenPlayerName (n: Integer): String;
96 begin
97 ASSERT(n >= 1);
98 Result := GetUserName;
99 if Result = '' then
100 Result := 'Player' + IntToStr(machine MOD 10000);
101 if n = 1 then
102 Result := Copy(Result, 1, 12) + ' '
103 else
104 Result := Copy(Result, 1, 10) + ' ' + IntToStr(n)
105 end;
107 {$IFDEF USE_SDL2}
108 procedure g_Options_SetDefaultVideo;
109 var display: TSDL_DisplayMode;
110 {$IFNDEF ANDROID}
111 var target, closest: TSDL_DisplayMode; percentage: Integer;
112 {$ENDIF}
113 begin
114 (* Display 0 = Primary display *)
115 gScreenWidth := 640;
116 gScreenHeight := 480;
117 gWinSizeX := 640;
118 gWinSizeY := 480;
119 //gBPP := SDL_BITSPERPIXEL(dispaly.format);
120 gBPP := 32;
121 {$IFDEF ANDROID}
122 gFullScreen := True; (* rotation not allowed? *)
123 {$ELSE}
124 gFullScreen := False;
125 {$ENDIF}
126 if SDL_GetDesktopDisplayMode(0, @display) = 0 then
127 begin
128 {$IFDEF ANDROID}
129 gWinSizeX := display.w;
130 gWinSizeY := display.h;
131 {$ELSE}
132 (* Window must be smaller than display *)
133 closest.w := display.w;
134 closest.h := display.h;
135 percentage := 75;
136 while (display.w - closest.w < 48) or (display.h - closest.h < 48) do
137 begin
138 if percentage < 25 then
139 begin
140 closest.w := display.w * 75 div 100;
141 closest.h := display.h * 75 div 100;
142 break;
143 end;
144 target.w := display.w * percentage div 100;
145 target.h := display.h * percentage div 100;
146 target.format := 0; (* didn't care *)
147 target.refresh_rate := 0; (* didn't care *)
148 target.driverdata := nil; (* init *)
149 SDL_GetClosestDisplayMode(0, @target, @closest);
150 Dec(percentage);
151 end;
152 gWinSizeX := closest.w;
153 gWinSizeY := closest.h;
154 //gBPP := SDL_BITSPERPIXEL(closest.format); (* Resolution list didn't work for some reason *)
155 {$ENDIF}
156 end
157 else
158 begin
159 e_LogWritefln('SDL: Failed to get desktop display mode: %s', [SDL_GetError])
160 end;
161 (* Must be positioned on primary display *)
162 gWinMaximized := False;
163 gVSync := True;
164 gTextureFilter := True;
165 glLegacyNPOT := False;
166 gRC_Width := gWinSizeX;
167 gRC_Height := gWinSizeY;
168 gRC_FullScreen := gFullScreen;
169 gRC_Maximized := gWinMaximized;
170 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
171 g_Console_ResetBinds;
172 end;
173 {$ELSE}
174 procedure g_Options_SetDefaultVideo;
175 begin
176 gWinSizeX := 640;
177 gWinSizeY := 480;
178 gBPP := 32;
179 gFullScreen := False;
180 gWinMaximized := False;
181 gVSync := True;
182 gTextureFilter := True;
183 glLegacyNPOT := False;
184 gScreenWidth := gWinSizeX;
185 gScreenHeight := gWinSizeY;
186 gRC_Width := gWinSizeX;
187 gRC_Height := gWinSizeY;
188 gRC_FullScreen := gFullScreen;
189 gRC_Maximized := gWinMaximized;
190 e_LogWriteLn('g_Options_SetDefaultVideo: w = ' + IntToStr(gWinSizeX) + ' h = ' + IntToStr(gWinSizeY));
191 g_Console_ResetBinds;
192 end;
193 {$ENDIF}
195 procedure g_Options_SetDefault();
196 var
197 i: Integer;
198 begin
199 (* section Sound *)
200 gNoSound := False;
201 gSoundLevel := 75;
202 gMusicLevel := 65;
203 gMaxSimSounds := 8;
204 gMuteWhenInactive := False;
205 gAnnouncer := ANNOUNCE_MEPLUS;
206 gSoundEffectsDF := True;
207 gUseChatSounds := True;
208 gsSDLSampleRate := 44100;
209 gsSDLBufferSize := 2048;
211 g_Sound_SetupAllVolumes(gSoundLevel, gMusicLevel);
213 with gPlayer1Settings do
214 begin
215 Name := GenPlayerName(1);
216 Model := STD_PLAYER_MODEL;
217 Color.R := PLAYER1_DEF_COLOR.R;
218 Color.G := PLAYER1_DEF_COLOR.G;
219 Color.B := PLAYER1_DEF_COLOR.B;
220 Team := TEAM_RED;
221 end;
223 with gPlayer2Settings do
224 begin
225 Name := GenPlayerName(2);
226 Model := STD_PLAYER_MODEL;
227 Color.R := PLAYER2_DEF_COLOR.R;
228 Color.G := PLAYER2_DEF_COLOR.G;
229 Color.B := PLAYER2_DEF_COLOR.B;
230 Team := TEAM_BLUE;
231 end;
233 (* section Joysticks *)
234 for i := 0 to e_MaxJoys - 1 do
235 begin
236 e_JoystickDeadzones[i] := 8192
237 end;
239 (* section Game *)
240 g_GFX_SetMax(2000);
241 g_Shells_SetMax(300);
242 g_Gibs_SetMax(150);
243 g_Corpses_SetMax(20);
244 gGibsCount := 32;
245 gBloodCount := 4;
246 gAdvBlood := True;
247 gAdvCorpses := True;
248 gAdvGibs := True;
249 gFlash := 1;
250 gDrawBackGround := True;
251 gShowMessages := True;
252 gRevertPlayers := False;
253 gChatBubble := 4;
254 wadoptDebug := False;
255 wadoptFast := False;
256 e_FastScreenshots := True;
257 gDefaultMegawadStart := DF_Default_Megawad_Start;
258 gBerserkAutoswitch := True;
259 gWeaponAutoswitch := True;
260 g_dbg_scale := 1.0;
261 gSaveStats := False;
263 gAskLanguage := True;
264 gLanguage := LANGUAGE_ENGLISH;
266 gsMap := '';
267 gsGameMode := _lc[I_MENU_GAME_TYPE_DM];
268 gsTimeLimit := 0;
269 gsGoalLimit := 0;
270 gsMaxLives := 0;
271 gsPlayers := 1;
272 gsSpawnInvul := 0;
273 gsItemRespawnTime := 60;
274 gsGameFlags := GAME_OPTION_ALLOWEXIT or GAME_OPTION_DMKEYS or
275 GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER or
276 GAME_OPTION_TEAMHITTRACE or GAME_OPTION_TEAMHITPROJECTILE or
277 GAME_OPTION_ALLOWDROPFLAG;
278 gsPlayers := 1;
280 if not gGameOn then
281 g_Options_ApplyGameSettings;
283 (* section MasterServer *)
284 NetMasterList := 'mpms.doom2d.org:25665, deadsoftware.ru:25665';
285 g_Net_Slist_Set(NetMasterList);
287 (* section Server *)
288 NetServerName := 'Unnamed Server';
289 NetPassword := '';
290 NetPort := 25666;
291 NetMaxClients := 16;
292 NetAllowRCON := False;
293 NetRCONPassword := 'default';
294 NetUseMaster := True;
295 NetUpdateRate := 0;
296 NetRelupdRate := 18;
297 NetMasterRate := 60000;
298 NetForwardPorts := False;
300 (* section Client *)
301 NetInterpLevel := 2;
302 NetForcePlayerUpdate := False;
303 NetPredictSelf := True;
304 NetClientIP := '127.0.0.1';
305 NetClientPort := NetPort;
306 end;
308 procedure g_Options_ApplyGameSettings;
309 begin
310 with gGameSettings do
311 begin
312 GameMode := g_Game_TextToMode(gsGameMode);
313 if GameMode = GM_NONE then
314 GameMode := GM_DM;
315 if GameMode = GM_SINGLE then
316 GameMode := GM_COOP;
317 TimeLimit := gsTimeLimit;
318 GoalLimit := gsGoalLimit;
319 MaxLives := gsMaxLives;
320 SpawnInvul := gsSpawnInvul;
321 ItemRespawnTime := gsItemRespawnTime;
322 WarmupTime := gsWarmupTime;
323 Options := gsGameFlags;
324 end;
325 end;
327 initialization
328 Randomize;
329 machine := Random(10000);
331 (* Video *)
332 conRegVar('r_width', @gRC_Width, '', '');
333 conRegVar('r_height', @gRC_Height, '', '');
334 conRegVar('r_fullscreen', @gRC_FullScreen, '', '');
335 conRegVar('r_maximized', @gRC_Maximized, '', '');
336 conRegVar('r_bpp', @gBPP, '', '');
337 conRegVar('r_vsync', @gVSync, '', '');
338 conRegVar('r_texfilter', @gTextureFilter, '', '');
339 conRegVar('r_npot', @glNPOTOverride, '', '');
340 conRegVar('r_interp', @gLerpActors, '', 'interpolate actors');
342 (* Sound *)
343 conRegVar('s_nosound', @gNoSound, '', '');
344 conRegVar('s_soundvolume', @gSoundLevel, '', '');
345 conRegVar('s_musicvolume', @gMusicLevel, '', '');
346 conRegVar('s_maxsim', @gMaxSimSounds, '', ''); // e_sound_fmod/sdl?
347 conRegVar('s_muteinactive', @gMuteWhenInactive, '', '');
348 conRegVar('s_announcer', @gAnnouncer, '', '');
349 conRegVar('s_sfx', @gSoundEffectsDF, '', '');
350 conRegVar('s_chatsounds', @gUseChatSounds, '', '');
351 {$IFDEF USE_SDLMIXER}
352 conRegVar('sdl_mixer_samplerate', @gsSDLSampleRate, '', '');
353 conRegVar('sdl_mixer_buffersize', @gsSDLBufferSize, '', '');
354 {$ENDIF}
356 (* Game *)
357 conRegVar('g_gibs_count', @gGibsCount, '', '');
358 conRegVar('g_blood_count', @gBloodCount, '', '');
359 conRegVar('g_adv_blood', @gAdvBlood, '', '');
360 conRegVar('g_adv_corpses', @gAdvCorpses, '', '');
361 conRegVar('g_adv_gibs', @gAdvGibs, '', '');
362 conRegVar('r_flash', @gFlash, '', '');
363 conRegVar('r_background', @gDrawBackGround, '', '');
364 conRegVar('g_show_messages', @gShowMessages, '', '');
365 conRegVar('r_revert_players', @gRevertPlayers, '', '');
366 conRegVar('r_chat_bubble', @gChatBubble, '', '');
367 conRegVar('sfs_debug', @wadoptDebug, '', '');
368 conRegVar('sfs_fastmode', @wadoptFast, '', '');
369 conRegVar('g_fast_screenshots', @e_FastScreenshots, '', '');
370 conRegVar('g_default_megawad', @gDefaultMegawadStart, '', '');
371 conRegVar('g_save_stats', @gSaveStats, '', '');
372 conRegVar('g_screenshot_stats', @gScreenshotStats, '', '');
373 conRegVar('g_lastmap', @gsMap, '', '');
374 end.