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 {$INCLUDE ../nogl/noGLuses.inc}
41 {$IFDEF ENABLE_HOLMES}
42 g_holmes
, fui_wadread
, fui_style
, fui_gfx_gl
,
44 SDL2
, wadreader
, e_log
, g_window
,
45 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
46 e_sound
, g_options
, g_sound
, g_player
, g_basic
,
47 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
48 g_menu
, g_language
, g_net
, g_touch
,
49 utils
, conbuf
, envvars
,
54 charbuff
: packed array [0..15] of AnsiChar;
59 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
63 e_InitWritelnDriver();
66 MapsDir
:= GameDir
+ '/maps/';
67 DataDir
:= GameDir
+ '/data/';
68 ModelsDir
:= DataDir
+ 'models/';
69 GameWAD
:= DataDir
+ 'Game.wad';
71 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
74 'Doom 2D: Forever version ' + GAME_VERSION
+
75 ' proto ' + IntToStr(NET_PROTOCOL_VER
),
79 'Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
,
84 conbufDumpToStdOut
:= true;
86 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
90 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
91 // HACK: shit this into env and hope for the best
92 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
94 sdlflags
:= SDL_INIT_TIMER
or $00004000;
98 {*sdlflags := SDL_INIT_EVERYTHING;*}
99 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
101 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
105 SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK
, '0');
107 if SDL_Init(sdlflags
) < 0 then
108 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
110 e_WriteLog('Read config file', TMsgType
.Notify
);
111 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
113 //GetSystemDefaultLCID()
115 //e_WriteLog('Read language file', MSG_NOTIFY);
116 //g_Language_Load(DataDir + gLanguage + '.txt');
117 e_WriteLog(gLanguage
, TMsgType
.Notify
);
118 g_Language_Set(gLanguage
);
122 SDL_StartTextInput();
126 {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
128 if not fuiAddWad('flexui.wad') then
130 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
133 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
134 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
135 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
136 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
137 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
138 except on e
: Exception
do
140 writeln('ERROR loading FlexUI fonts');
153 e_LogWriteln('FlexUI: loading stylesheet...');
154 uiLoadStyles('flexui/widgets.wgs');
155 except on e
: TParserException
do
157 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
168 g_holmes_imfunctional
:= not flexloaded
;
171 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
181 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
192 {$IFDEF USE_SDLMIXER}
193 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
195 NoSound
:= True; // FMOD backend will sort it out
201 e_WriteLog('Init Input', TMsgType
.Notify
);
205 if (e_JoysticksAvailable
> 0) then
206 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
208 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
210 if (not gNoSound
) then
212 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
213 e_InitSoundSystem(NoSound
);
216 e_WriteLog('Init game', TMsgType
.Notify
);
219 FillChar(charbuff
, sizeof(charbuff
), ' ');
225 e_WriteLog('Releasing engine', TMsgType
.Notify
);
228 e_WriteLog('Releasing Input', TMsgType
.Notify
);
233 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
234 e_ReleaseSoundSystem();
251 function Translit (const S
: AnsiString): AnsiString;
256 for i
:= 1 to Length(Result
) do
259 'É': Result
[i
] := 'Q';
260 'Ö': Result
[i
] := 'W';
261 'Ó': Result
[i
] := 'E';
262 'Ê': Result
[i
] := 'R';
263 'Å': Result
[i
] := 'T';
264 'Í': Result
[i
] := 'Y';
265 'Ã': Result
[i
] := 'U';
266 'Ø': Result
[i
] := 'I';
267 'Ù': Result
[i
] := 'O';
268 'Ç': Result
[i
] := 'P';
269 'Õ': Result
[i
] := '['; //Chr(219);
270 'Ú': Result
[i
] := ']'; //Chr(221);
271 'Ô': Result
[i
] := 'A';
272 'Û': Result
[i
] := 'S';
273 'Â': Result
[i
] := 'D';
274 'À': Result
[i
] := 'F';
275 'Ï': Result
[i
] := 'G';
276 'Ð': Result
[i
] := 'H';
277 'Î': Result
[i
] := 'J';
278 'Ë': Result
[i
] := 'K';
279 'Ä': Result
[i
] := 'L';
280 'Æ': Result
[i
] := ';'; //Chr(186);
281 'Ý': Result
[i
] := #39; //Chr(222);
282 'ß': Result
[i
] := 'Z';
283 '×': Result
[i
] := 'X';
284 'Ñ': Result
[i
] := 'C';
285 'Ì': Result
[i
] := 'V';
286 'È': Result
[i
] := 'B';
287 'Ò': Result
[i
] := 'N';
288 'Ü': Result
[i
] := 'M';
289 'Á': Result
[i
] := ','; //Chr(188);
290 'Þ': Result
[i
] := '.'; //Chr(190);
296 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
301 ls2
:= Translit(CheatRus
[ct
]);
302 if length(ls1
) = 0 then ls1
:= '~';
303 if length(ls2
) = 0 then ls2
:= '~';
305 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
306 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
307 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
308 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
310 if ct = I_GAME_CHEAT_JETPACK then
312 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
313 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
314 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
315 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
316 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
317 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
334 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
335 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
336 or g_Game_IsNet then Exit;
338 if not gGameOn
then exit
;
339 if not conIsCheatsEnabled
then exit
;
341 s
:= 'SOUND_GAME_RADIO';
344 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
346 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
347 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
351 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
353 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
354 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
358 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
360 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
361 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
365 if CheckCheat(I_GAME_CHEAT_DEATH
) then
367 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
368 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
369 s
:= 'SOUND_MONSTER_HAHA';
373 if CheckCheat(I_GAME_CHEAT_DOORS
) then
375 g_Triggers_OpenAll();
379 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
381 if gTriggers
<> nil then
382 for a
:= 0 to High(gTriggers
) do
383 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
385 gExitByTrigger
:= True;
386 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
387 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
393 s2
:= Copy(charbuff
, 15, 2);
394 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
396 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
404 if CheckCheat(I_GAME_CHEAT_FLY
) then
410 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
412 VEL_JUMP
:= 30-VEL_JUMP
;
416 if CheckCheat(I_GAME_CHEAT_SPEED
) then
418 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
422 if CheckCheat(I_GAME_CHEAT_SUIT
) then
424 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
425 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
429 if CheckCheat(I_GAME_CHEAT_AIR
) then
431 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
432 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
436 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
438 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
439 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
443 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
445 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
446 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
450 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
452 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
453 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
457 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
459 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
460 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
464 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
466 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
467 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
470 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
472 gAimLine
:= not gAimLine
;
475 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
477 gShowMap
:= not gShowMap
;
487 procedure KeyPress (K
: Word);
492 IK_PAUSE
: // <Pause/Break>:
494 if (g_ActiveWindow
= nil) then g_Game_Pause(not gPause
);
497 IK_BACKQUOTE
, VK_CONSOLE
: // <`/~/¨/¸>:
502 IK_ESCAPE
, VK_ESCAPE
: // <Esc>:
506 g_Console_Chat_Switch();
514 else if (g_ActiveWindow
<> nil) then
516 Msg
.Msg
:= WM_KEYDOWN
;
517 Msg
.WParam
:= IK_ESCAPE
;
518 g_ActiveWindow
.OnMessage(Msg
);
519 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
521 else if (gState
<> STATE_FOLD
) then
523 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
525 g_Game_InGameMenu(True);
527 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
529 if (gState
<> STATE_MENU
) then
531 if (NetMode
<> NET_NONE
) then
533 g_Game_StopAllSounds(True);
535 gState
:= STATE_MENU
;
539 g_GUI_ShowWindow('MainMenu');
540 g_Sound_PlayEx('MENU_OPEN');
545 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
546 begin // <F2> .. <F6> � <F12>
547 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
549 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
550 if (not g_Game_IsNet
) then g_Game_Pause(True);
552 IK_F2
: g_Menu_Show_SaveMenu();
553 IK_F3
: g_Menu_Show_LoadMenu();
554 IK_F4
: g_Menu_Show_GameSetGame();
555 IK_F5
: g_Menu_Show_OptionsVideo();
556 IK_F6
: g_Menu_Show_OptionsSound();
557 IK_F7
: g_Menu_Show_EndGameMenu();
558 IK_F10
: g_Menu_Show_QuitGameMenu();
565 gJustChatted
:= False;
566 if gConsoleShow
or gChatShow
then
568 g_Console_Control(K
);
570 else if (g_ActiveWindow
<> nil) then
572 Msg
.Msg
:= WM_KEYDOWN
;
574 g_ActiveWindow
.OnMessage(Msg
);
576 else if (gState
= STATE_MENU
) then
578 g_GUI_ShowWindow('MainMenu');
579 g_Sound_PlayEx('MENU_OPEN');
586 procedure CharPress (C
: AnsiChar);
591 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then Exit
;
593 if gConsoleShow
or gChatShow
then
597 else if (g_ActiveWindow
<> nil) then
600 Msg
.WParam
:= Ord(C
);
601 g_ActiveWindow
.OnMessage(Msg
);
605 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
606 charbuff
[15] := upcase1251(C
);