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
, g_basic
,
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;
59 e_InitWritelnDriver();
62 MapsDir
:= GameDir
+ '/maps/';
63 DataDir
:= GameDir
+ '/data/';
64 ModelsDir
:= DataDir
+ 'models/';
65 GameWAD
:= DataDir
+ 'Game.wad';
67 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
70 'Doom 2D: Forever version ' + GAME_VERSION
+
71 ' proto ' + IntToStr(NET_PROTOCOL_VER
),
75 'Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
,
79 e_WriteLog('Read config file', TMsgType
.Notify
);
80 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
83 conbufDumpToStdOut
:= true;
85 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
87 //GetSystemDefaultLCID()
89 //e_WriteLog('Read language file', MSG_NOTIFY);
90 //g_Language_Load(DataDir + gLanguage + '.txt');
91 e_WriteLog(gLanguage
, TMsgType
.Notify
);
92 g_Language_Set(gLanguage
);
96 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
97 // HACK: shit this into env and hope for the best
98 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
100 sdlflags
:= SDL_INIT_TIMER
or $00004000;
103 {$IFDEF USE_SDLMIXER}
104 {*sdlflags := SDL_INIT_EVERYTHING;*}
105 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
107 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
110 if SDL_Init(sdlflags
) < 0 then
111 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
114 SDL_StartTextInput();
119 if not fuiAddWad('flexui.wad') then
121 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
124 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
125 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
126 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
127 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
128 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
129 except on e
: Exception
do
131 writeln('ERROR loading FlexUI fonts');
144 e_LogWriteln('FlexUI: loading stylesheet...');
145 uiLoadStyles('flexui/widgets.wgs');
146 except on e
: TParserException
do
148 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
159 g_holmes_imfunctional
:= not flexloaded
;
162 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
172 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
183 {$IFDEF USE_SDLMIXER}
184 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
186 NoSound
:= True; // FMOD backend will sort it out
192 e_WriteLog('Init Input', TMsgType
.Notify
);
195 if (e_JoysticksAvailable
> 0) then
196 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
198 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
200 if (not gNoSound
) then
202 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
203 e_InitSoundSystem(NoSound
);
206 e_WriteLog('Init game', TMsgType
.Notify
);
209 FillChar(charbuff
, sizeof(charbuff
), ' ');
215 e_WriteLog('Releasing engine', TMsgType
.Notify
);
218 e_WriteLog('Releasing Input', TMsgType
.Notify
);
223 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
224 e_ReleaseSoundSystem();
241 function Translit (const S
: AnsiString): AnsiString;
246 for i
:= 1 to Length(Result
) do
249 'É': Result
[i
] := 'Q';
250 'Ö': Result
[i
] := 'W';
251 'Ó': Result
[i
] := 'E';
252 'Ê': Result
[i
] := 'R';
253 'Å': Result
[i
] := 'T';
254 'Í': Result
[i
] := 'Y';
255 'Ã': Result
[i
] := 'U';
256 'Ø': Result
[i
] := 'I';
257 'Ù': Result
[i
] := 'O';
258 'Ç': Result
[i
] := 'P';
259 'Õ': Result
[i
] := '['; //Chr(219);
260 'Ú': Result
[i
] := ']'; //Chr(221);
261 'Ô': Result
[i
] := 'A';
262 'Û': Result
[i
] := 'S';
263 'Â': Result
[i
] := 'D';
264 'À': Result
[i
] := 'F';
265 'Ï': Result
[i
] := 'G';
266 'Ð': Result
[i
] := 'H';
267 'Î': Result
[i
] := 'J';
268 'Ë': Result
[i
] := 'K';
269 'Ä': Result
[i
] := 'L';
270 'Æ': Result
[i
] := ';'; //Chr(186);
271 'Ý': Result
[i
] := #39; //Chr(222);
272 'ß': Result
[i
] := 'Z';
273 '×': Result
[i
] := 'X';
274 'Ñ': Result
[i
] := 'C';
275 'Ì': Result
[i
] := 'V';
276 'È': Result
[i
] := 'B';
277 'Ò': Result
[i
] := 'N';
278 'Ü': Result
[i
] := 'M';
279 'Á': Result
[i
] := ','; //Chr(188);
280 'Þ': Result
[i
] := '.'; //Chr(190);
286 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
291 ls2
:= Translit(CheatRus
[ct
]);
292 if length(ls1
) = 0 then ls1
:= '~';
293 if length(ls2
) = 0 then ls2
:= '~';
295 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
296 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
297 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
298 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
300 if ct = I_GAME_CHEAT_JETPACK then
302 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
303 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
304 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
305 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
306 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
307 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
324 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
325 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
326 or g_Game_IsNet then Exit;
328 if not gGameOn
then exit
;
329 if not conIsCheatsEnabled
then exit
;
331 s
:= 'SOUND_GAME_RADIO';
334 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
336 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
337 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
341 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
343 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
344 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
348 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
350 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
351 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
355 if CheckCheat(I_GAME_CHEAT_DEATH
) then
357 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
358 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
359 s
:= 'SOUND_MONSTER_HAHA';
363 if CheckCheat(I_GAME_CHEAT_DOORS
) then
365 g_Triggers_OpenAll();
369 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
371 if gTriggers
<> nil then
372 for a
:= 0 to High(gTriggers
) do
373 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
375 gExitByTrigger
:= True;
376 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
377 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
383 s2
:= Copy(charbuff
, 15, 2);
384 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
386 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
394 if CheckCheat(I_GAME_CHEAT_FLY
) then
400 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
402 VEL_JUMP
:= 30-VEL_JUMP
;
406 if CheckCheat(I_GAME_CHEAT_SPEED
) then
408 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
412 if CheckCheat(I_GAME_CHEAT_SUIT
) then
414 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
415 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
419 if CheckCheat(I_GAME_CHEAT_AIR
) then
421 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
422 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
426 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
428 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
429 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
433 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
435 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
436 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
440 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
442 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
443 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
447 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
449 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
450 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
454 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
456 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
457 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
460 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
462 gAimLine
:= not gAimLine
;
465 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
467 gShowMap
:= not gShowMap
;
477 procedure KeyPress (K
: Word);
482 IK_PAUSE
: // <Pause/Break>:
484 if (g_ActiveWindow
= nil) then g_Game_Pause(not gPause
);
487 IK_BACKQUOTE
: // <`/~/¨/¸>:
496 g_Console_Chat_Switch();
504 else if (g_ActiveWindow
<> nil) then
506 Msg
.Msg
:= WM_KEYDOWN
;
507 Msg
.WParam
:= IK_ESCAPE
;
508 g_ActiveWindow
.OnMessage(Msg
);
509 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
511 else if (gState
<> STATE_FOLD
) then
513 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
515 g_Game_InGameMenu(True);
517 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
519 if (gState
<> STATE_MENU
) then
521 if (NetMode
<> NET_NONE
) then
523 g_Game_StopAllSounds(True);
525 gState
:= STATE_MENU
;
529 g_GUI_ShowWindow('MainMenu');
530 g_Sound_PlayEx('MENU_OPEN');
535 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
536 begin // <F2> .. <F6> � <F12>
537 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
539 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
540 if (not g_Game_IsNet
) then g_Game_Pause(True);
542 IK_F2
: g_Menu_Show_SaveMenu();
543 IK_F3
: g_Menu_Show_LoadMenu();
544 IK_F4
: g_Menu_Show_GameSetGame();
545 IK_F5
: g_Menu_Show_OptionsVideo();
546 IK_F6
: g_Menu_Show_OptionsSound();
547 IK_F7
: g_Menu_Show_EndGameMenu();
548 IK_F10
: g_Menu_Show_QuitGameMenu();
555 gJustChatted
:= False;
556 if gConsoleShow
or gChatShow
then
558 g_Console_Control(K
);
560 else if (g_ActiveWindow
<> nil) then
562 Msg
.Msg
:= WM_KEYDOWN
;
564 g_ActiveWindow
.OnMessage(Msg
);
566 else if (gState
= STATE_MENU
) then
568 g_GUI_ShowWindow('MainMenu');
569 g_Sound_PlayEx('MENU_OPEN');
576 procedure CharPress (C
: AnsiChar);
581 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then Exit
;
583 if gConsoleShow
or gChatShow
then
587 else if (g_ActiveWindow
<> nil) then
590 Msg
.WParam
:= Ord(C
);
591 g_ActiveWindow
.OnMessage(Msg
);
595 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
596 charbuff
[15] := upcase1251(C
);