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);
45 SDL2
, wadreader
, e_log
, g_window
,
46 e_graphics
, e_input
, g_game
, g_console
, g_gui
,
47 e_sound
, g_options
, g_sound
, g_player
, g_basic
,
48 g_weapons
, SysUtils
, g_triggers
, MAPDEF
, g_map
,
49 g_menu
, g_language
, g_net
, g_holmes
, g_touch
,
50 utils
, conbuf
, envvars
, fui_wadread
, fui_style
,
55 charbuff
: packed array [0..15] of AnsiChar;
64 e_InitWritelnDriver();
67 MapsDir
:= GameDir
+ '/maps/';
68 DataDir
:= GameDir
+ '/data/';
69 ModelsDir
:= DataDir
+ 'models/';
70 GameWAD
:= DataDir
+ 'Game.wad';
72 e_InitLog(GameDir
+ '/' + LOG_FILENAME
, TWriteMode
.WM_NEWFILE
);
75 'Doom 2D: Forever version ' + GAME_VERSION
+
76 ' proto ' + IntToStr(NET_PROTOCOL_VER
),
80 'Build date: ' + GAME_BUILDDATE
+ ' ' + GAME_BUILDTIME
,
84 e_WriteLog('Read config file', TMsgType
.Notify
);
85 g_Options_Read(GameDir
+ '/' + CONFIG_FILENAME
);
88 conbufDumpToStdOut
:= true;
90 e_WriteToStdOut
:= False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
92 //GetSystemDefaultLCID()
94 //e_WriteLog('Read language file', MSG_NOTIFY);
95 //g_Language_Load(DataDir + gLanguage + '.txt');
96 e_WriteLog(gLanguage
, TMsgType
.Notify
);
97 g_Language_Set(gLanguage
);
100 {$IFDEF USE_SDLMIXER}
101 sdlflags
:= SDL_INIT_TIMER
or SDL_INIT_AUDIO
or $00004000;
102 // HACK: shit this into env and hope for the best
103 SetEnvVar('SDL_AUDIODRIVER', 'dummy');
105 sdlflags
:= SDL_INIT_TIMER
or $00004000;
108 {$IFDEF USE_SDLMIXER}
109 {*sdlflags := SDL_INIT_EVERYTHING;*}
110 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
112 sdlflags
:= SDL_INIT_JOYSTICK
or SDL_INIT_TIMER
or SDL_INIT_VIDEO
;
116 SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK
, '0');
118 if SDL_Init(sdlflags
) < 0 then
119 raise Exception
.Create('SDL: Init failed: ' + SDL_GetError());
123 SDL_StartTextInput();
129 if not fuiAddWad('flexui.wad') then
131 if not fuiAddWad('./data/flexui.wad') then fuiAddWad('./flexui.wad');
134 fuiGfxLoadFont('win8', 'flexui/fonts/win8.fuifont');
135 fuiGfxLoadFont('win14', 'flexui/fonts/win14.fuifont');
136 fuiGfxLoadFont('win16', 'flexui/fonts/win16.fuifont');
137 fuiGfxLoadFont('dos8', 'flexui/fonts/dos8.fuifont');
138 fuiGfxLoadFont('msx6', 'flexui/fonts/msx6.fuifont');
139 except on e
: Exception
do
141 writeln('ERROR loading FlexUI fonts');
154 e_LogWriteln('FlexUI: loading stylesheet...');
155 uiLoadStyles('flexui/widgets.wgs');
156 except on e
: TParserException
do
158 writeln('ERROR at (', e
.tokLine
, ',', e
.tokCol
, '): ', e
.message);
169 g_holmes_imfunctional
:= not flexloaded
;
172 e_WriteLog('Entering SDLMain', TMsgType
.Notify
);
182 e_WriteLog('Releasing SDL', TMsgType
.Notify
);
193 {$IFDEF USE_SDLMIXER}
194 NoSound
:= False; // hope env has set SDL_AUDIODRIVER to dummy
196 NoSound
:= True; // FMOD backend will sort it out
202 e_WriteLog('Init Input', TMsgType
.Notify
);
206 if (e_JoysticksAvailable
> 0) then
207 e_WriteLog('Input: Joysticks available.', TMsgType
.Notify
)
209 e_WriteLog('Input: No Joysticks.', TMsgType
.Notify
);
211 if (not gNoSound
) then
213 e_WriteLog('Initializing sound system', TMsgType
.Notify
);
214 e_InitSoundSystem(NoSound
);
217 e_WriteLog('Init game', TMsgType
.Notify
);
220 FillChar(charbuff
, sizeof(charbuff
), ' ');
226 e_WriteLog('Releasing engine', TMsgType
.Notify
);
229 e_WriteLog('Releasing Input', TMsgType
.Notify
);
234 e_WriteLog('Releasing FMOD', TMsgType
.Notify
);
235 e_ReleaseSoundSystem();
252 function Translit (const S
: AnsiString): AnsiString;
257 for i
:= 1 to Length(Result
) do
260 'É': Result
[i
] := 'Q';
261 'Ö': Result
[i
] := 'W';
262 'Ó': Result
[i
] := 'E';
263 'Ê': Result
[i
] := 'R';
264 'Å': Result
[i
] := 'T';
265 'Í': Result
[i
] := 'Y';
266 'Ã': Result
[i
] := 'U';
267 'Ø': Result
[i
] := 'I';
268 'Ù': Result
[i
] := 'O';
269 'Ç': Result
[i
] := 'P';
270 'Õ': Result
[i
] := '['; //Chr(219);
271 'Ú': Result
[i
] := ']'; //Chr(221);
272 'Ô': Result
[i
] := 'A';
273 'Û': Result
[i
] := 'S';
274 'Â': Result
[i
] := 'D';
275 'À': Result
[i
] := 'F';
276 'Ï': Result
[i
] := 'G';
277 'Ð': Result
[i
] := 'H';
278 'Î': Result
[i
] := 'J';
279 'Ë': Result
[i
] := 'K';
280 'Ä': Result
[i
] := 'L';
281 'Æ': Result
[i
] := ';'; //Chr(186);
282 'Ý': Result
[i
] := #39; //Chr(222);
283 'ß': Result
[i
] := 'Z';
284 '×': Result
[i
] := 'X';
285 'Ñ': Result
[i
] := 'C';
286 'Ì': Result
[i
] := 'V';
287 'È': Result
[i
] := 'B';
288 'Ò': Result
[i
] := 'N';
289 'Ü': Result
[i
] := 'M';
290 'Á': Result
[i
] := ','; //Chr(188);
291 'Þ': Result
[i
] := '.'; //Chr(190);
297 function CheckCheat (ct
: TStrings_Locale
; eofs
: Integer=0): Boolean;
302 ls2
:= Translit(CheatRus
[ct
]);
303 if length(ls1
) = 0 then ls1
:= '~';
304 if length(ls2
) = 0 then ls2
:= '~';
306 (Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
)) = ls1
) or
307 (Translit(Copy(charbuff
, 17-Length(ls1
)-eofs
, Length(ls1
))) = ls1
) or
308 (Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
)) = ls2
) or
309 (Translit(Copy(charbuff
, 17-Length(ls2
)-eofs
, Length(ls2
))) = ls2
);
311 if ct = I_GAME_CHEAT_JETPACK then
313 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
314 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
315 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
316 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
317 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
318 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
335 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
336 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
337 or g_Game_IsNet then Exit;
339 if not gGameOn
then exit
;
340 if not conIsCheatsEnabled
then exit
;
342 s
:= 'SOUND_GAME_RADIO';
345 if CheckCheat(I_GAME_CHEAT_GODMODE
) then
347 if gPlayer1
<> nil then gPlayer1
.GodMode
:= not gPlayer1
.GodMode
;
348 if gPlayer2
<> nil then gPlayer2
.GodMode
:= not gPlayer2
.GodMode
;
352 if CheckCheat(I_GAME_CHEAT_WEAPONS
) then
354 if gPlayer1
<> nil then gPlayer1
.AllRulez(False);
355 if gPlayer2
<> nil then gPlayer2
.AllRulez(False);
359 if CheckCheat(I_GAME_CHEAT_HEALTH
) then
361 if gPlayer1
<> nil then gPlayer1
.AllRulez(True);
362 if gPlayer2
<> nil then gPlayer2
.AllRulez(True);
366 if CheckCheat(I_GAME_CHEAT_DEATH
) then
368 if gPlayer1
<> nil then gPlayer1
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
369 if gPlayer2
<> nil then gPlayer2
.Damage(CHEAT_DAMAGE
, 0, 0, 0, HIT_TRAP
);
370 s
:= 'SOUND_MONSTER_HAHA';
374 if CheckCheat(I_GAME_CHEAT_DOORS
) then
376 g_Triggers_OpenAll();
380 if CheckCheat(I_GAME_CHEAT_NEXTMAP
) then
382 if gTriggers
<> nil then
383 for a
:= 0 to High(gTriggers
) do
384 if gTriggers
[a
].TriggerType
= TRIGGER_EXIT
then
386 gExitByTrigger
:= True;
387 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
388 g_Game_ExitLevel(gTriggers
[a
].tgcMap
);
394 s2
:= Copy(charbuff
, 15, 2);
395 if CheckCheat(I_GAME_CHEAT_CHANGEMAP
, 2) and (s2
[1] >= '0') and (s2
[1] <= '9') and (s2
[2] >= '0') and (s2
[2] <= '9') then
397 if g_Map_Exist(MapsDir
+gGameSettings
.WAD
+':\MAP'+s2
) then
405 if CheckCheat(I_GAME_CHEAT_FLY
) then
411 if CheckCheat(I_GAME_CHEAT_JUMPS
) then
413 VEL_JUMP
:= 30-VEL_JUMP
;
417 if CheckCheat(I_GAME_CHEAT_SPEED
) then
419 MAX_RUNVEL
:= 32-MAX_RUNVEL
;
423 if CheckCheat(I_GAME_CHEAT_SUIT
) then
425 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_SUIT
);
426 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_SUIT
);
430 if CheckCheat(I_GAME_CHEAT_AIR
) then
432 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_OXYGEN
);
433 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_OXYGEN
);
437 if CheckCheat(I_GAME_CHEAT_BERSERK
) then
439 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_MEDKIT_BLACK
);
440 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_MEDKIT_BLACK
);
444 if CheckCheat(I_GAME_CHEAT_JETPACK
) then
446 if gPlayer1
<> nil then gPlayer1
.GiveItem(ITEM_JETPACK
);
447 if gPlayer2
<> nil then gPlayer2
.GiveItem(ITEM_JETPACK
);
451 if CheckCheat(I_GAME_CHEAT_NOCLIP
) then
453 if gPlayer1
<> nil then gPlayer1
.SwitchNoClip
;
454 if gPlayer2
<> nil then gPlayer2
.SwitchNoClip
;
458 if CheckCheat(I_GAME_CHEAT_NOTARGET
) then
460 if gPlayer1
<> nil then gPlayer1
.NoTarget
:= not gPlayer1
.NoTarget
;
461 if gPlayer2
<> nil then gPlayer2
.NoTarget
:= not gPlayer2
.NoTarget
;
465 if CheckCheat(I_GAME_CHEAT_NORELOAD
) then
467 if gPlayer1
<> nil then gPlayer1
.NoReload
:= not gPlayer1
.NoReload
;
468 if gPlayer2
<> nil then gPlayer2
.NoReload
:= not gPlayer2
.NoReload
;
471 if CheckCheat(I_GAME_CHEAT_AIMLINE
) then
473 gAimLine
:= not gAimLine
;
476 if CheckCheat(I_GAME_CHEAT_AUTOMAP
) then
478 gShowMap
:= not gShowMap
;
488 procedure KeyPress (K
: Word);
493 IK_PAUSE
: // <Pause/Break>:
495 if (g_ActiveWindow
= nil) then g_Game_Pause(not gPause
);
498 IK_BACKQUOTE
, VK_CONSOLE
: // <`/~/¨/¸>:
503 IK_ESCAPE
, VK_ESCAPE
: // <Esc>:
507 g_Console_Chat_Switch();
515 else if (g_ActiveWindow
<> nil) then
517 Msg
.Msg
:= WM_KEYDOWN
;
518 Msg
.WParam
:= IK_ESCAPE
;
519 g_ActiveWindow
.OnMessage(Msg
);
520 if (not g_Game_IsNet
) and (g_ActiveWindow
= nil) then g_Game_Pause(false); //Fn loves to do this
522 else if (gState
<> STATE_FOLD
) then
524 if gGameOn
or (gState
= STATE_INTERSINGLE
) or (gState
= STATE_INTERCUSTOM
) then
526 g_Game_InGameMenu(True);
528 else if (gExit
= 0) and (gState
<> STATE_SLIST
) then
530 if (gState
<> STATE_MENU
) then
532 if (NetMode
<> NET_NONE
) then
534 g_Game_StopAllSounds(True);
536 gState
:= STATE_MENU
;
540 g_GUI_ShowWindow('MainMenu');
541 g_Sound_PlayEx('MENU_OPEN');
546 IK_F2
, IK_F3
, IK_F4
, IK_F5
, IK_F6
, IK_F7
, IK_F10
:
547 begin // <F2> .. <F6> � <F12>
548 if gGameOn
and (not gConsoleShow
) and (not gChatShow
) then
550 while (g_ActiveWindow
<> nil) do g_GUI_HideWindow(False);
551 if (not g_Game_IsNet
) then g_Game_Pause(True);
553 IK_F2
: g_Menu_Show_SaveMenu();
554 IK_F3
: g_Menu_Show_LoadMenu();
555 IK_F4
: g_Menu_Show_GameSetGame();
556 IK_F5
: g_Menu_Show_OptionsVideo();
557 IK_F6
: g_Menu_Show_OptionsSound();
558 IK_F7
: g_Menu_Show_EndGameMenu();
559 IK_F10
: g_Menu_Show_QuitGameMenu();
566 gJustChatted
:= False;
567 if gConsoleShow
or gChatShow
then
569 g_Console_Control(K
);
571 else if (g_ActiveWindow
<> nil) then
573 Msg
.Msg
:= WM_KEYDOWN
;
575 g_ActiveWindow
.OnMessage(Msg
);
577 else if (gState
= STATE_MENU
) then
579 g_GUI_ShowWindow('MainMenu');
580 g_Sound_PlayEx('MENU_OPEN');
587 procedure CharPress (C
: AnsiChar);
592 if (not gChatShow
) and ((C
= '`') or (C
= '~') or (C
= '¸') or (C
= '¨')) then Exit
;
594 if gConsoleShow
or gChatShow
then
598 else if (g_ActiveWindow
<> nil) then
601 Msg
.WParam
:= Ord(C
);
602 g_ActiveWindow
.OnMessage(Msg
);
606 for a
:= 0 to 14 do charbuff
[a
] := charbuff
[a
+1];
607 charbuff
[15] := upcase1251(C
);