1 (* Copyright (C) DooM 2D:Forever Developers
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, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
26 procedure KeyPress (K
: Word);
27 procedure CharPress (C
: AnsiChar);
40 SDL2
, GL
, GLExt
, wadreader
, e_log
, g_window
,
41 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
42 e_sound
, g_options
, g_sound
, g_player
,
43 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
44 g_menu
, g_language
, g_net
, g_holmes
,
45 utils
, conbuf
, envvars
, fui_wadread
, fui_style
,
50 charbuff
: packed array [0..15] of AnsiChar;
56 e_InitWritelnDriver();
59 MapsDir
:= GameDir
+ '/maps/';
60 DataDir
:= GameDir
+ '/data/';
61 ModelsDir
:= DataDir
+ 'models/';
62 GameWAD
:= DataDir
+ 'Game.wad';
64 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
66 e_WriteLog('Read config file', TMsgType
.Notify
);
67 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
70 conbufDumpToStdOut
:= true;
72 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
74 //GetSystemDefaultLCID()
76 //e_WriteLog('Read language file', MSG_NOTIFY);
77 //g_Language_Load(DataDir + gLanguage + '.txt');
78 e_WriteLog(gLanguage
, TMsgType
.Notify
);
79 g_Language_Set(gLanguage
);
83 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
84 // HACK: shit this into env and hope for the best
85 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
87 sdlflags
:= SDL_INIT_TIMER
or $00004000;
91 sdlflags
:= SDL_INIT_EVERYTHING
;
93 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
96 if SDL_Init(sdlflags
) < 0 then
97 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
100 SDL_StartTextInput();
104 if not fuiAddWad('flexui.wad') then
106 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
108 g_holmes_imfunctional
:= true;
110 e_LogWriteln('FlexUI: loading stylesheet...');
111 uiLoadStyles('flexui/widgets.wgs');
112 except on e
: TParserException
do
114 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
123 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
124 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
125 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
126 g_holmes_imfunctional
:= false;
127 except on e
: Exception
do
129 writeln('ERROR loading FlexUI fonts');
139 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
149 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
160 {$IFDEF USE_SDLMIXER}
161 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
163 NoSound
:= True; // FMOD backend will sort it out
169 e_WriteLog('Init Input', TMsgType
.Notify
);
172 if (e_JoysticksAvailable
> 0) then
173 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
175 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
177 if (not gNoSound
) then
179 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
180 e_InitSoundSystem(NoSound
);
183 e_WriteLog('Init game', TMsgType
.Notify
);
186 FillChar(charbuff
, sizeof(charbuff
), ' ');
192 e_WriteLog('Releasing engine', TMsgType
.Notify
);
195 e_WriteLog('Releasing Input', TMsgType
.Notify
);
200 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
201 e_ReleaseSoundSystem();
218 function Translit (const S
: AnsiString): AnsiString;
223 for i
:= 1 to Length(Result
) do
226 'É': Result
[i
] := 'Q';
227 'Ö': Result
[i
] := 'W';
228 'Ó': Result
[i
] := 'E';
229 'Ê': Result
[i
] := 'R';
230 'Å': Result
[i
] := 'T';
231 'Í': Result
[i
] := 'Y';
232 'Ã': Result
[i
] := 'U';
233 'Ø': Result
[i
] := 'I';
234 'Ù': Result
[i
] := 'O';
235 'Ç': Result
[i
] := 'P';
236 'Õ': Result
[i
] := '['; //Chr(219);
237 'Ú': Result
[i
] := ']'; //Chr(221);
238 'Ô': Result
[i
] := 'A';
239 'Û': Result
[i
] := 'S';
240 'Â': Result
[i
] := 'D';
241 'À': Result
[i
] := 'F';
242 'Ï': Result
[i
] := 'G';
243 'Ð': Result
[i
] := 'H';
244 'Î': Result
[i
] := 'J';
245 'Ë': Result
[i
] := 'K';
246 'Ä': Result
[i
] := 'L';
247 'Æ': Result
[i
] := ';'; //Chr(186);
248 'Ý': Result
[i
] := #39; //Chr(222);
249 'ß': Result
[i
] := 'Z';
250 '×': Result
[i
] := 'X';
251 'Ñ': Result
[i
] := 'C';
252 'Ì': Result
[i
] := 'V';
253 'È': Result
[i
] := 'B';
254 'Ò': Result
[i
] := 'N';
255 'Ü': Result
[i
] := 'M';
256 'Á': Result
[i
] := ','; //Chr(188);
257 'Þ': Result
[i
] := '.'; //Chr(190);
263 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
268 ls2
:= Translit(CheatRus
[ct
]);
269 if length(ls1
) = 0 then ls1
:= '~';
270 if length(ls2
) = 0 then ls2
:= '~';
272 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
273 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
274 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
275 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
277 if ct = I_GAME_CHEAT_JETPACK then
279 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
280 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
281 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
282 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
283 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
284 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
301 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
302 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
303 or g_Game_IsNet then Exit;
305 if not gGameOn
then exit
;
306 if not conIsCheatsEnabled
then exit
;
308 s
:= 'SOUND_GAME_RADIO';
311 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
313 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
314 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
318 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
320 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
321 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
325 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
327 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
328 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
332 if CheckCheat(I_GAME_CHEAT_DEATH
) then
334 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
335 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
336 s
:= 'SOUND_MONSTER_HAHA';
340 if CheckCheat(I_GAME_CHEAT_DOORS
) then
342 g_Triggers_OpenAll();
346 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
348 if gTriggers
<> nil then
349 for a
:= 0 to High(gTriggers
) do
350 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
352 gExitByTrigger
:= True;
353 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
354 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
360 s2
:= Copy(charbuff
, 15, 2);
361 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
363 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
373 if CheckCheat(I_GAME_CHEAT_FLY
) then
379 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
381 VEL_JUMP
:= 30-VEL_JUMP
;
385 if CheckCheat(I_GAME_CHEAT_SPEED
) then
387 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
391 if CheckCheat(I_GAME_CHEAT_SUIT
) then
393 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
394 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
398 if CheckCheat(I_GAME_CHEAT_AIR
) then
400 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
401 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
405 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
407 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
408 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
412 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
414 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
415 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
419 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
421 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
422 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
426 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
428 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
429 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
433 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
435 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
436 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
439 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
441 gAimLine
:= not gAimLine
;
444 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
446 gShowMap
:= not gShowMap
;
456 procedure KeyPress (K
: Word);
461 IK_PAUSE
: // <Pause/Break>:
463 if (g_ActiveWindow
= nil) then g_Game_Pause(not gPause
);
466 IK_BACKQUOTE
: // <`/~/¨/¸>:
475 g_Console_Chat_Switch();
483 else if (g_ActiveWindow
<> nil) then
485 Msg
.Msg
:= WM_KEYDOWN
;
486 Msg
.WParam
:= IK_ESCAPE
;
487 g_ActiveWindow
.OnMessage(Msg
);
488 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
490 else if (gState
<> STATE_FOLD
) then
492 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
494 g_Game_InGameMenu(True);
496 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
498 if (gState
<> STATE_MENU
) then
500 if (NetMode
<> NET_NONE
) then
502 g_Game_StopAllSounds(True);
504 gState
:= STATE_MENU
;
508 g_GUI_ShowWindow('MainMenu');
509 g_Sound_PlayEx('MENU_OPEN');
514 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
515 begin // <F2> .. <F6> � <F12>
516 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
518 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
519 if (not g_Game_IsNet
) then g_Game_Pause(True);
521 IK_F2
: g_Menu_Show_SaveMenu();
522 IK_F3
: g_Menu_Show_LoadMenu();
523 IK_F4
: g_Menu_Show_GameSetGame();
524 IK_F5
: g_Menu_Show_OptionsVideo();
525 IK_F6
: g_Menu_Show_OptionsSound();
526 IK_F7
: g_Menu_Show_EndGameMenu();
527 IK_F10
: g_Menu_Show_QuitGameMenu();
534 gJustChatted
:= False;
535 if gConsoleShow
or gChatShow
then
537 g_Console_Control(K
);
539 else if (g_ActiveWindow
<> nil) then
541 Msg
.Msg
:= WM_KEYDOWN
;
543 g_ActiveWindow
.OnMessage(Msg
);
545 else if (gState
= STATE_MENU
) then
547 g_GUI_ShowWindow('MainMenu');
548 g_Sound_PlayEx('MENU_OPEN');
555 procedure CharPress (C
: AnsiChar);
560 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then Exit
;
562 if gConsoleShow
or gChatShow
then
566 else if (g_ActiveWindow
<> nil) then
569 Msg
.WParam
:= Ord(C
);
570 g_ActiveWindow
.OnMessage(Msg
);
574 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
575 charbuff
[15] := upcase1251(C
);